00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <ipc/char.h>
00038 #include <async.h>
00039 #include <kbd_port.h>
00040 #include <kbd.h>
00041 #include <vfs/vfs.h>
00042 #include <sys/stat.h>
00043 #include <fcntl.h>
00044 #include <errno.h>
00045
00046 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
00047
00048 static int dev_phone;
00049
00050 #define NAME "kbd"
00051
00053 static const char *in_devs[] = {
00054 "/dev/char/ps2a",
00055 "/dev/char/s3c24ser"
00056 };
00057
00058 static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
00059
00060 int kbd_port_init(void)
00061 {
00062 int input_fd;
00063 int i;
00064
00065 input_fd = -1;
00066 for (i = 0; i < num_devs; i++) {
00067 struct stat s;
00068
00069 if (stat(in_devs[i], &s) == EOK)
00070 break;
00071 }
00072
00073 if (i >= num_devs) {
00074 printf(NAME ": Could not find any suitable input device.\n");
00075 return -1;
00076 }
00077
00078 input_fd = open(in_devs[i], O_RDONLY);
00079 if (input_fd < 0) {
00080 printf(NAME ": failed opening device %s (%d).\n", in_devs[i],
00081 input_fd);
00082 return -1;
00083 }
00084
00085 dev_phone = fd_phone(input_fd);
00086 if (dev_phone < 0) {
00087 printf(NAME ": Failed connecting to device\n");
00088 return -1;
00089 }
00090
00091
00092 if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
00093 printf(NAME ": Failed to create callback from device\n");
00094 return -1;
00095 }
00096
00097 return 0;
00098 }
00099
00100 void kbd_port_yield(void)
00101 {
00102 }
00103
00104 void kbd_port_reclaim(void)
00105 {
00106 }
00107
00108 void kbd_port_write(uint8_t data)
00109 {
00110 async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
00111 }
00112
00113 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall)
00114 {
00115
00116 while (true) {
00117
00118 ipc_call_t call;
00119 ipc_callid_t callid = async_get_call(&call);
00120
00121 int retval;
00122
00123 switch (IPC_GET_IMETHOD(call)) {
00124 case IPC_M_PHONE_HUNGUP:
00125
00126 return;
00127 case CHAR_NOTIF_BYTE:
00128 kbd_push_scancode(IPC_GET_ARG1(call));
00129 break;
00130 default:
00131 retval = ENOENT;
00132 }
00133 async_answer_0(callid, retval);
00134 }
00135 }
00136
00137