source: mainline/uspace/srv/hid/kbd/port/chardev.c@ b1bdc7a4

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

Control keyboard port modules through ops structures. Allows compiling in
all modules at the same time.

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