Changeset 89c57b6 in mainline for uspace/srv/hid/kbd/port/chardev.c


Ignore:
Timestamp:
2011-04-13T14:45:41Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
88634420
Parents:
cefb126 (diff), 17279ead (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 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/kbd/port/chardev.c

    rcefb126 r89c57b6  
    3535 */
    3636
    37 #include <ipc/ipc.h>
    3837#include <ipc/char.h>
    3938#include <async.h>
     
    4140#include <kbd.h>
    4241#include <vfs/vfs.h>
     42#include <sys/stat.h>
    4343#include <fcntl.h>
    4444#include <errno.h>
     
    5050#define NAME "kbd"
    5151
     52/** List of devices to try connecting to. */
     53static const char *in_devs[] = {
     54        "/dev/char/ps2a",
     55        "/dev/char/s3c24ser"
     56};
     57
     58static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
     59
    5260int kbd_port_init(void)
    5361{
    54         const char *input = "/dev/char/ps2a";
    5562        int input_fd;
     63        int i;
    5664
    57         printf(NAME ": open %s\n", input);
     65        input_fd = -1;
     66        for (i = 0; i < num_devs; i++) {
     67                struct stat s;
    5868
    59         input_fd = open(input, O_RDONLY);
     69                if (stat(in_devs[i], &s) == EOK)
     70                        break;
     71        }
     72
     73        if (i >= num_devs) {
     74                printf(NAME ": Could not find any suitable input device.\n");
     75                return -1;
     76        }
     77
     78        input_fd = open(in_devs[i], O_RDONLY);
    6079        if (input_fd < 0) {
    61                 printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
    62                 return false;
     80                printf(NAME ": failed opening device %s (%d).\n", in_devs[i],
     81                    input_fd);
     82                return -1;
    6383        }
    6484
    6585        dev_phone = fd_phone(input_fd);
    6686        if (dev_phone < 0) {
    67                 printf(NAME ": Failed to connect to device\n");
    68                 return false;
     87                printf(NAME ": Failed connecting to device\n");
     88                return -1;
    6989        }
    7090
    7191        /* NB: The callback connection is slotted for removal */
    72         ipcarg_t phonehash;
    73         if (ipc_connect_to_me(dev_phone, 0, 0, 0, &phonehash) != 0) {
     92        if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
    7493                printf(NAME ": Failed to create callback from device\n");
    75                 return false;
     94                return -1;
    7695        }
    77 
    78         async_new_connection(phonehash, 0, NULL, kbd_port_events);
    7996
    8097        return 0;
     
    104121                int retval;
    105122
    106                 switch (IPC_GET_METHOD(call)) {
     123                switch (IPC_GET_IMETHOD(call)) {
    107124                case IPC_M_PHONE_HUNGUP:
    108125                        /* TODO: Handle hangup */
     
    114131                        retval = ENOENT;
    115132                }
    116                 ipc_answer_0(callid, retval);
     133                async_answer_0(callid, retval);
    117134        }
    118135}
Note: See TracChangeset for help on using the changeset viewer.