1 | /*
|
---|
2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup kbd_port
|
---|
30 | * @ingroup kbd
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | * @brief Chardev keyboard port driver.
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <ipc/char.h>
|
---|
38 | #include <async.h>
|
---|
39 | #include <async_obsolete.h>
|
---|
40 | #include <kbd_port.h>
|
---|
41 | #include <kbd.h>
|
---|
42 | #include <devmap.h>
|
---|
43 | #include <devmap_obsolete.h>
|
---|
44 | #include <errno.h>
|
---|
45 | #include <stdio.h>
|
---|
46 |
|
---|
47 | static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
|
---|
48 |
|
---|
49 | static int chardev_port_init(kbd_dev_t *);
|
---|
50 | static void chardev_port_yield(void);
|
---|
51 | static void chardev_port_reclaim(void);
|
---|
52 | static void chardev_port_write(uint8_t data);
|
---|
53 |
|
---|
54 | kbd_port_ops_t chardev_port = {
|
---|
55 | .init = chardev_port_init,
|
---|
56 | .yield = chardev_port_yield,
|
---|
57 | .reclaim = chardev_port_reclaim,
|
---|
58 | .write = chardev_port_write
|
---|
59 | };
|
---|
60 |
|
---|
61 | static kbd_dev_t *kbd_dev;
|
---|
62 | static int dev_phone;
|
---|
63 |
|
---|
64 | /** List of devices to try connecting to. */
|
---|
65 | static const char *in_devs[] = {
|
---|
66 | "char/ps2a",
|
---|
67 | "char/s3c24ser"
|
---|
68 | };
|
---|
69 |
|
---|
70 | static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
|
---|
71 |
|
---|
72 | static int chardev_port_init(kbd_dev_t *kdev)
|
---|
73 | {
|
---|
74 | devmap_handle_t handle;
|
---|
75 | unsigned int i;
|
---|
76 | int rc;
|
---|
77 |
|
---|
78 | kbd_dev = kdev;
|
---|
79 |
|
---|
80 | for (i = 0; i < num_devs; i++) {
|
---|
81 | rc = devmap_device_get_handle(in_devs[i], &handle, 0);
|
---|
82 | if (rc == EOK)
|
---|
83 | break;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if (i >= num_devs) {
|
---|
87 | printf("%s: Could not find any suitable input device\n", NAME);
|
---|
88 | return -1;
|
---|
89 | }
|
---|
90 |
|
---|
91 | dev_phone = devmap_obsolete_device_connect(handle, IPC_FLAG_BLOCKING);
|
---|
92 | if (dev_phone < 0) {
|
---|
93 | printf("%s: Failed connecting to device\n", NAME);
|
---|
94 | return ENOENT;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /* NB: The callback connection is slotted for removal */
|
---|
98 | if (async_obsolete_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events,
|
---|
99 | NULL) != 0) {
|
---|
100 | printf(NAME ": Failed to create callback from device\n");
|
---|
101 | return -1;
|
---|
102 | }
|
---|
103 |
|
---|
104 | return 0;
|
---|
105 | }
|
---|
106 |
|
---|
107 | static void chardev_port_yield(void)
|
---|
108 | {
|
---|
109 | }
|
---|
110 |
|
---|
111 | static void chardev_port_reclaim(void)
|
---|
112 | {
|
---|
113 | }
|
---|
114 |
|
---|
115 | static void chardev_port_write(uint8_t data)
|
---|
116 | {
|
---|
117 | async_obsolete_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
|
---|
118 | }
|
---|
119 |
|
---|
120 | static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
121 | {
|
---|
122 | /* Ignore parameters, the connection is already opened */
|
---|
123 | while (true) {
|
---|
124 |
|
---|
125 | ipc_call_t call;
|
---|
126 | ipc_callid_t callid = async_get_call(&call);
|
---|
127 |
|
---|
128 | if (!IPC_GET_IMETHOD(call)) {
|
---|
129 | /* TODO: Handle hangup */
|
---|
130 | return;
|
---|
131 | }
|
---|
132 |
|
---|
133 | int retval;
|
---|
134 |
|
---|
135 | switch (IPC_GET_IMETHOD(call)) {
|
---|
136 | case CHAR_NOTIF_BYTE:
|
---|
137 | kbd_push_scancode(kbd_dev, IPC_GET_ARG1(call));
|
---|
138 | break;
|
---|
139 | default:
|
---|
140 | retval = ENOENT;
|
---|
141 | }
|
---|
142 | async_answer_0(callid, retval);
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * @}
|
---|
149 | */
|
---|