source: mainline/uspace/srv/hid/input/port/chardev.c@ f3a605be

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f3a605be was 854eddd6, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Route mouse input through input server. Remove device-handling code from
console server.

  • Property mode set to 100644
File size: 3.8 KB
Line 
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 <input.h>
41#include <kbd_port.h>
42#include <kbd.h>
43#include <devmap.h>
44#include <devmap_obsolete.h>
45#include <errno.h>
46#include <stdio.h>
47
48static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
49
50static int chardev_port_init(kbd_dev_t *);
51static void chardev_port_yield(void);
52static void chardev_port_reclaim(void);
53static void chardev_port_write(uint8_t data);
54
55kbd_port_ops_t chardev_port = {
56 .init = chardev_port_init,
57 .yield = chardev_port_yield,
58 .reclaim = chardev_port_reclaim,
59 .write = chardev_port_write
60};
61
62static kbd_dev_t *kbd_dev;
63static int dev_phone;
64
65/** List of devices to try connecting to. */
66static const char *in_devs[] = {
67 "char/ps2a",
68 "char/s3c24ser"
69};
70
71static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
72
73static int chardev_port_init(kbd_dev_t *kdev)
74{
75 devmap_handle_t handle;
76 unsigned int i;
77 int rc;
78
79 kbd_dev = kdev;
80
81 for (i = 0; i < num_devs; i++) {
82 rc = devmap_device_get_handle(in_devs[i], &handle, 0);
83 if (rc == EOK)
84 break;
85 }
86
87 if (i >= num_devs) {
88 printf("%s: Could not find any suitable input device\n", NAME);
89 return -1;
90 }
91
92 dev_phone = devmap_obsolete_device_connect(handle, IPC_FLAG_BLOCKING);
93 if (dev_phone < 0) {
94 printf("%s: Failed connecting to device\n", NAME);
95 return ENOENT;
96 }
97
98 /* NB: The callback connection is slotted for removal */
99 if (async_obsolete_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events,
100 NULL) != 0) {
101 printf(NAME ": Failed to create callback from device\n");
102 return -1;
103 }
104
105 return 0;
106}
107
108static void chardev_port_yield(void)
109{
110}
111
112static void chardev_port_reclaim(void)
113{
114}
115
116static void chardev_port_write(uint8_t data)
117{
118 async_obsolete_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
119}
120
121static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
122{
123 /* Ignore parameters, the connection is already opened */
124 while (true) {
125
126 ipc_call_t call;
127 ipc_callid_t callid = async_get_call(&call);
128
129 if (!IPC_GET_IMETHOD(call)) {
130 /* TODO: Handle hangup */
131 return;
132 }
133
134 int retval;
135
136 switch (IPC_GET_IMETHOD(call)) {
137 case CHAR_NOTIF_BYTE:
138 kbd_push_scancode(kbd_dev, IPC_GET_ARG1(call));
139 break;
140 default:
141 retval = ENOENT;
142 }
143 async_answer_0(callid, retval);
144 }
145}
146
147
148/**
149 * @}
150 */
Note: See TracBrowser for help on using the repository browser.