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

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

Move receiving side of ski console support to a separate driver, ski-con. Add ski platform driver.

  • Property mode set to 100644
File size: 4.2 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 <loc.h>
40#include <errno.h>
41#include <stdio.h>
42#include "../input.h"
43#include "../kbd_port.h"
44#include "../kbd.h"
45
46static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
47
48static int chardev_port_init(kbd_dev_t *);
49static void chardev_port_write(uint8_t data);
50
51kbd_port_ops_t chardev_port = {
52 .init = chardev_port_init,
53 .write = chardev_port_write
54};
55
56static kbd_dev_t *kbd_dev;
57static async_sess_t *dev_sess;
58
59/** List of devices to try connecting to. */
60static const char *in_devs[] = {
61 /** S3C24xx UART - Openmoko debug console */
62 "char/s3c24xx_uart",
63 /** Ski console */
64 "devices/\\hw\\console\\a"
65};
66
67static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
68
69static int chardev_port_init(kbd_dev_t *kdev)
70{
71 service_id_t service_id;
72 async_exch_t *exch;
73 unsigned int i;
74 int rc;
75
76 kbd_dev = kdev;
77
78 for (i = 0; i < num_devs; i++) {
79 printf("%s: Probe service '%s'\n", NAME, in_devs[i]);
80 rc = loc_service_get_id(in_devs[i], &service_id, 0);
81 if (rc == EOK) {
82 printf("%s: success \n", NAME);
83 break;
84 }
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_sess = loc_service_connect(service_id, INTERFACE_DDF,
93 IPC_FLAG_BLOCKING);
94 if (dev_sess == NULL) {
95 printf("%s: Failed connecting to device\n", NAME);
96 return ENOENT;
97 }
98
99 exch = async_exchange_begin(dev_sess);
100 if (exch == NULL) {
101 printf("%s: Failed starting exchange with device\n", NAME);
102 async_hangup(dev_sess);
103 return ENOMEM;
104 }
105
106 port_id_t port;
107 rc = async_create_callback_port(exch, INTERFACE_CHAR_CB, 0, 0,
108 kbd_port_events, NULL, &port);
109
110 async_exchange_end(exch);
111
112 if (rc != 0) {
113 printf("%s: Failed to create callback from device\n", NAME);
114 async_hangup(dev_sess);
115 return -1;
116 }
117 printf("%s: Connected input device\n", NAME);
118
119 return 0;
120}
121
122static void chardev_port_write(uint8_t data)
123{
124 async_exch_t *exch = async_exchange_begin(dev_sess);
125 if (exch == NULL) {
126 printf("%s: Failed starting exchange with device\n", NAME);
127 return;
128 }
129
130 async_msg_1(exch, CHAR_WRITE_BYTE, data);
131 async_exchange_end(exch);
132}
133
134static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
135{
136 /* Ignore parameters, the connection is already opened */
137 while (true) {
138
139 ipc_call_t call;
140 ipc_callid_t callid = async_get_call(&call);
141
142 if (!IPC_GET_IMETHOD(call)) {
143 /* TODO: Handle hangup */
144 return;
145 }
146
147 int retval = EOK;
148
149 switch (IPC_GET_IMETHOD(call)) {
150 case CHAR_NOTIF_BYTE:
151 kbd_push_data(kbd_dev, IPC_GET_ARG1(call));
152 break;
153 default:
154 retval = ENOENT;
155 }
156 async_answer_0(callid, retval);
157 }
158}
159
160
161/**
162 * @}
163 */
Note: See TracBrowser for help on using the repository browser.