Changeset 6a44ee4 in mainline for uspace/srv/hid/input/port/chardev.c
- Timestamp:
- 2011-07-20T15:26:21Z (13 years ago)
- 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. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/port/chardev.c
r25bef0ff r6a44ee4 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 30 30 * @ingroup kbd 31 31 * @{ 32 */ 32 */ 33 33 /** @file 34 34 * @brief Chardev keyboard port driver. … … 37 37 #include <ipc/char.h> 38 38 #include <async.h> 39 #include <input.h> 39 40 #include <kbd_port.h> 40 41 #include <kbd.h> 41 #include <vfs/vfs.h> 42 #include <sys/stat.h> 43 #include <fcntl.h> 42 #include <devmap.h> 44 43 #include <errno.h> 44 #include <stdio.h> 45 45 46 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall );46 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg); 47 47 48 static int dev_phone; 48 static int chardev_port_init(kbd_dev_t *); 49 static void chardev_port_yield(void); 50 static void chardev_port_reclaim(void); 51 static void chardev_port_write(uint8_t data); 49 52 50 #define NAME "kbd" 53 kbd_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 60 static kbd_dev_t *kbd_dev; 61 static async_sess_t *dev_sess; 51 62 52 63 /** List of devices to try connecting to. */ 53 64 static const char *in_devs[] = { 54 " /dev/char/ps2a",55 " /dev/char/s3c24ser"65 "char/ps2a", 66 "char/s3c24ser" 56 67 }; 57 68 58 static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);69 static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]); 59 70 60 int kbd_port_init(void)71 static int chardev_port_init(kbd_dev_t *kdev) 61 72 { 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 66 80 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) 70 83 break; 71 84 } 72 85 73 86 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); 75 88 return -1; 76 89 } 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); 82 112 return -1; 83 113 } 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 97 115 return 0; 98 116 } 99 117 100 void kbd_port_yield(void)118 static void chardev_port_yield(void) 101 119 { 102 120 } 103 121 104 void kbd_port_reclaim(void)122 static void chardev_port_reclaim(void) 105 123 { 106 124 } 107 125 108 void kbd_port_write(uint8_t data)126 static void chardev_port_write(uint8_t data) 109 127 { 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); 111 136 } 112 137 113 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall )138 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 114 139 { 115 140 /* Ignore parameters, the connection is already opened */ … … 118 143 ipc_call_t call; 119 144 ipc_callid_t callid = async_get_call(&call); 145 146 if (!IPC_GET_IMETHOD(call)) { 147 /* TODO: Handle hangup */ 148 return; 149 } 120 150 121 151 int retval; 122 152 123 153 switch (IPC_GET_IMETHOD(call)) { 124 case IPC_M_PHONE_HUNGUP:125 /* TODO: Handle hangup */126 return;127 154 case CHAR_NOTIF_BYTE: 128 kbd_push_ scancode(IPC_GET_ARG1(call));155 kbd_push_data(kbd_dev, IPC_GET_ARG1(call)); 129 156 break; 130 157 default:
Note:
See TracChangeset
for help on using the changeset viewer.