Changeset 6a44ee4 in mainline for uspace/srv/hid/input/port/chardev.c


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/chardev.c

    r25bef0ff r6a44ee4  
    11/*
    2  * Copyright (c) 2009 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3030 * @ingroup kbd
    3131 * @{
    32  */ 
     32 */
    3333/** @file
    3434 * @brief Chardev keyboard port driver.
     
    3737#include <ipc/char.h>
    3838#include <async.h>
     39#include <input.h>
    3940#include <kbd_port.h>
    4041#include <kbd.h>
    41 #include <vfs/vfs.h>
    42 #include <sys/stat.h>
    43 #include <fcntl.h>
     42#include <devmap.h>
    4443#include <errno.h>
     44#include <stdio.h>
    4545
    46 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
     46static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    4747
    48 static int dev_phone;
     48static int chardev_port_init(kbd_dev_t *);
     49static void chardev_port_yield(void);
     50static void chardev_port_reclaim(void);
     51static void chardev_port_write(uint8_t data);
    4952
    50 #define NAME "kbd"
     53kbd_port_ops_t chardev_port = {
     54        .init = chardev_port_init,
     55        .yield = chardev_port_yield,
     56        .reclaim = chardev_port_reclaim,
     57        .write = chardev_port_write
     58};
     59
     60static kbd_dev_t *kbd_dev;
     61static async_sess_t *dev_sess;
    5162
    5263/** List of devices to try connecting to. */
    5364static const char *in_devs[] = {
    54         "/dev/char/ps2a",
    55         "/dev/char/s3c24ser"
     65        "char/ps2a",
     66        "char/s3c24ser"
    5667};
    5768
    58 static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
     69static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
    5970
    60 int kbd_port_init(void)
     71static int chardev_port_init(kbd_dev_t *kdev)
    6172{
    62         int input_fd;
    63         int i;
    64 
    65         input_fd = -1;
     73        devmap_handle_t handle;
     74        async_exch_t *exch;
     75        unsigned int i;
     76        int rc;
     77       
     78        kbd_dev = kdev;
     79       
    6680        for (i = 0; i < num_devs; i++) {
    67                 struct stat s;
    68 
    69                 if (stat(in_devs[i], &s) == EOK)
     81                rc = devmap_device_get_handle(in_devs[i], &handle, 0);
     82                if (rc == EOK)
    7083                        break;
    7184        }
    72 
     85       
    7386        if (i >= num_devs) {
    74                 printf(NAME ": Could not find any suitable input device.\n");
     87                printf("%s: Could not find any suitable input device\n", NAME);
    7588                return -1;
    7689        }
    77 
    78         input_fd = open(in_devs[i], O_RDONLY);
    79         if (input_fd < 0) {
    80                 printf(NAME ": failed opening device %s (%d).\n", in_devs[i],
    81                     input_fd);
     90       
     91        dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle,
     92            IPC_FLAG_BLOCKING);
     93        if (dev_sess == NULL) {
     94                printf("%s: Failed connecting to device\n", NAME);
     95                return ENOENT;
     96        }
     97       
     98        exch = async_exchange_begin(dev_sess);
     99        if (exch == NULL) {
     100                printf("%s: Failed starting exchange with device\n", NAME);
     101                async_hangup(dev_sess);
     102                return ENOMEM;
     103        }
     104       
     105        /* NB: The callback connection is slotted for removal */
     106        rc = async_connect_to_me(exch, 0, 0, 0, kbd_port_events, NULL);
     107        async_exchange_end(exch);
     108       
     109        if (rc != 0) {
     110                printf("%s: Failed to create callback from device\n", NAME);
     111                async_hangup(dev_sess);
    82112                return -1;
    83113        }
    84 
    85         dev_phone = fd_phone(input_fd);
    86         if (dev_phone < 0) {
    87                 printf(NAME ": Failed connecting to device\n");
    88                 return -1;
    89         }
    90 
    91         /* NB: The callback connection is slotted for removal */
    92         if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
    93                 printf(NAME ": Failed to create callback from device\n");
    94                 return -1;
    95         }
    96 
     114       
    97115        return 0;
    98116}
    99117
    100 void kbd_port_yield(void)
     118static void chardev_port_yield(void)
    101119{
    102120}
    103121
    104 void kbd_port_reclaim(void)
     122static void chardev_port_reclaim(void)
    105123{
    106124}
    107125
    108 void kbd_port_write(uint8_t data)
     126static void chardev_port_write(uint8_t data)
    109127{
    110         async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
     128        async_exch_t *exch = async_exchange_begin(dev_sess);
     129        if (exch == NULL) {
     130                printf("%s: Failed starting exchange with device\n", NAME);
     131                return;
     132        }
     133
     134        async_msg_1(exch, CHAR_WRITE_BYTE, data);
     135        async_exchange_end(exch);
    111136}
    112137
    113 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall)
     138static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    114139{
    115140        /* Ignore parameters, the connection is already opened */
     
    118143                ipc_call_t call;
    119144                ipc_callid_t callid = async_get_call(&call);
     145               
     146                if (!IPC_GET_IMETHOD(call)) {
     147                        /* TODO: Handle hangup */
     148                        return;
     149                }
    120150
    121151                int retval;
    122152
    123153                switch (IPC_GET_IMETHOD(call)) {
    124                 case IPC_M_PHONE_HUNGUP:
    125                         /* TODO: Handle hangup */
    126                         return;
    127154                case CHAR_NOTIF_BYTE:
    128                         kbd_push_scancode(IPC_GET_ARG1(call));
     155                        kbd_push_data(kbd_dev, IPC_GET_ARG1(call));
    129156                        break;
    130157                default:
Note: See TracChangeset for help on using the changeset viewer.