Ignore:
Timestamp:
2011-07-20T15:26:21Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efcebe1
Parents:
25bef0ff (diff), a701812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/port/adb_mouse.c

    r25bef0ff r6a44ee4  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup mouse
     29/** @addtogroup mouse_port
     30 * @ingroup mouse
    3031 * @{
    31  */ 
     32 */
    3233/** @file
    33  * @brief
     34 * @brief ADB mouse port driver.
    3435 */
    3536
    36 #include <ipc/char.h>
     37#include <ipc/adb.h>
    3738#include <async.h>
    38 #include <vfs/vfs.h>
    39 #include <fcntl.h>
     39#include <input.h>
     40#include <mouse_port.h>
     41#include <mouse.h>
    4042#include <errno.h>
     43#include <devmap.h>
    4144
    42 #include <char_mouse.h>
    43 #include <mouse_port.h>
     45static mouse_dev_t *mouse_dev;
     46static async_sess_t *dev_sess;
    4447
    45 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall);
    46 
    47 static int dev_phone;
    48 
    49 #define NAME "char_mouse"
    50 
    51 int mouse_port_init(void)
    52 {
    53         const char *input = "/dev/char/ps2b";
    54         int input_fd;
    55 
    56         printf(NAME ": open %s\n", input);
    57 
    58         input_fd = open(input, O_RDONLY);
    59         if (input_fd < 0) {
    60                 printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
    61                 return false;
    62         }
    63 
    64         dev_phone = fd_phone(input_fd);
    65         if (dev_phone < 0) {
    66                 printf(NAME ": Failed to connect to device\n");
    67                 return false;
    68         }
    69 
    70         /* NB: The callback connection is slotted for removal */
    71         if (async_connect_to_me(dev_phone, 0, 0, 0, chardev_events) != 0) {
    72                 printf(NAME ": Failed to create callback from device\n");
    73                 return false;
    74         }
    75 
    76         return 0;
    77 }
    78 
    79 void mouse_port_yield(void)
    80 {
    81 }
    82 
    83 void mouse_port_reclaim(void)
    84 {
    85 }
    86 
    87 void mouse_port_write(uint8_t data)
    88 {
    89         async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
    90 }
    91 
    92 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall)
     48static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    9349{
    9450        /* Ignore parameters, the connection is already opened */
    9551        while (true) {
    96 
    9752                ipc_call_t call;
    9853                ipc_callid_t callid = async_get_call(&call);
    99 
     54               
    10055                int retval;
    101 
    102                 switch (IPC_GET_IMETHOD(call)) {
    103                 case IPC_M_PHONE_HUNGUP:
     56               
     57                if (!IPC_GET_IMETHOD(call)) {
    10458                        /* TODO: Handle hangup */
    10559                        return;
    106                 case IPC_FIRST_USER_METHOD:
    107                         mouse_handle_byte(IPC_GET_ARG1(call));
     60                }
     61               
     62                switch (IPC_GET_IMETHOD(call)) {
     63                case ADB_REG_NOTIF:
     64                        mouse_push_data(mouse_dev, IPC_GET_ARG1(call));
    10865                        break;
    10966                default:
    11067                        retval = ENOENT;
    11168                }
     69               
    11270                async_answer_0(callid, retval);
    11371        }
    11472}
    11573
     74static int adb_port_init(mouse_dev_t *mdev)
     75{
     76        const char *dev = "adb/mouse";
     77       
     78        mouse_dev = mdev;
     79       
     80        devmap_handle_t handle;
     81        int rc = devmap_device_get_handle(dev, &handle, 0);
     82        if (rc != EOK)
     83                return rc;
     84       
     85        dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
     86        if (dev_sess == NULL) {
     87                printf("%s: Failed to connect to device\n", NAME);
     88                return ENOENT;
     89        }
     90       
     91        async_exch_t *exch = async_exchange_begin(dev_sess);
     92        if (exch == NULL) {
     93                printf("%s: Failed starting exchange with device\n", NAME);
     94                async_hangup(dev_sess);
     95                return ENOMEM;
     96        }
     97       
     98        /* NB: The callback connection is slotted for removal */
     99        rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL);
     100        async_exchange_end(exch);
     101        if (rc != EOK) {
     102                printf("%s: Failed to create callback from device\n", NAME);
     103                async_hangup(dev_sess);
     104                return rc;
     105        }
     106       
     107        return EOK;
     108}
     109
     110static void adb_port_yield(void)
     111{
     112}
     113
     114static void adb_port_reclaim(void)
     115{
     116}
     117
     118static void adb_port_write(uint8_t data)
     119{
     120}
     121
     122mouse_port_ops_t adb_mouse_port = {
     123        .init = adb_port_init,
     124        .yield = adb_port_yield,
     125        .reclaim = adb_port_reclaim,
     126        .write = adb_port_write
     127};
     128
    116129/**
    117130 * @}
Note: See TracChangeset for help on using the changeset viewer.