source: mainline/uspace/srv/hid/input/ctl/kbdev.c@ b6a088f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b6a088f was b6a088f, checked in by Martin Decky <martin@…>, 13 years ago

use local includes within the input server

  • Property mode set to 100644
File size: 4.5 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_ctl
30 * @ingroup input
31 * @{
32 */
33/**
34 * @file
35 * @brief Keyboard device connector controller driver.
36 */
37
38#include <async.h>
39#include <bool.h>
40#include <errno.h>
41#include <fcntl.h>
42#include <io/console.h>
43#include <io/keycode.h>
44#include <ipc/kbdev.h>
45#include <loc.h>
46#include <stdlib.h>
47#include <vfs/vfs_sess.h>
48#include <sys/typefmt.h>
49#include "../gsp.h"
50#include "../input.h"
51#include "../kbd.h"
52#include "../kbd_ctl.h"
53#include "../kbd_port.h"
54
55static int kbdev_ctl_init(kbd_dev_t *);
56static void kbdev_ctl_set_ind(kbd_dev_t *, unsigned int);
57
58static void kbdev_callback_conn(ipc_callid_t, ipc_call_t *, void *arg);
59
60kbd_ctl_ops_t kbdev_ctl = {
61 .parse = NULL,
62 .init = kbdev_ctl_init,
63 .set_ind = kbdev_ctl_set_ind
64};
65
66/** Kbdev softstate */
67typedef struct {
68 /** Link to generic keyboard device */
69 kbd_dev_t *kbd_dev;
70
71 /** Session with kbdev device */
72 async_sess_t *sess;
73} kbdev_t;
74
75static kbdev_t *kbdev_new(kbd_dev_t *kdev)
76{
77 kbdev_t *kbdev = calloc(1, sizeof(kbdev_t));
78 if (kbdev == NULL)
79 return NULL;
80
81 kbdev->kbd_dev = kdev;
82
83 return kbdev;
84}
85
86static void kbdev_destroy(kbdev_t *kbdev)
87{
88 if (kbdev->sess != NULL)
89 async_hangup(kbdev->sess);
90
91 free(kbdev);
92}
93
94static int kbdev_ctl_init(kbd_dev_t *kdev)
95{
96 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE,
97 kdev->svc_id, 0);
98 if (sess == NULL) {
99 printf("%s: Failed starting session with '%s.'\n", NAME,
100 kdev->svc_name);
101 return ENOENT;
102 }
103
104 kbdev_t *kbdev = kbdev_new(kdev);
105 if (kbdev == NULL) {
106 printf("%s: Failed allocating device structure for '%s'.\n",
107 NAME, kdev->svc_name);
108 async_hangup(sess);
109 return ENOMEM;
110 }
111
112 kbdev->sess = sess;
113
114 async_exch_t *exch = async_exchange_begin(sess);
115 if (exch == NULL) {
116 printf("%s: Failed starting exchange with '%s'.\n", NAME,
117 kdev->svc_name);
118 kbdev_destroy(kbdev);
119 return ENOENT;
120 }
121
122 int rc = async_connect_to_me(exch, 0, 0, 0, kbdev_callback_conn, kbdev);
123 if (rc != EOK) {
124 printf("%s: Failed creating callback connection from '%s'.\n",
125 NAME, kdev->svc_name);
126 async_exchange_end(exch);
127 kbdev_destroy(kbdev);
128 return rc;
129 }
130
131 async_exchange_end(exch);
132
133 kdev->ctl_private = (void *) kbdev;
134 return 0;
135}
136
137static void kbdev_ctl_set_ind(kbd_dev_t *kdev, unsigned mods)
138{
139 async_sess_t *sess = ((kbdev_t *) kdev->ctl_private)->sess;
140 async_exch_t *exch = async_exchange_begin(sess);
141 if (!exch)
142 return;
143
144 async_msg_1(exch, KBDEV_SET_IND, mods);
145 async_exchange_end(exch);
146}
147
148static void kbdev_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
149{
150 kbdev_t *kbdev;
151 int retval;
152 int type, key;
153
154 /* Kbdev device structure */
155 kbdev = arg;
156
157 while (true) {
158 ipc_call_t call;
159 ipc_callid_t callid;
160
161 callid = async_get_call(&call);
162 if (!IPC_GET_IMETHOD(call)) {
163 kbdev_destroy(kbdev);
164 return;
165 }
166
167 switch (IPC_GET_IMETHOD(call)) {
168 case KBDEV_EVENT:
169 /* Got event from keyboard device */
170 retval = 0;
171 type = IPC_GET_ARG1(call);
172 key = IPC_GET_ARG2(call);
173 kbd_push_event(kbdev->kbd_dev, type, key);
174 break;
175 default:
176 retval = ENOTSUP;
177 break;
178 }
179
180 async_answer_0(callid, retval);
181 }
182}
183
184/**
185 * @}
186 */
Note: See TracBrowser for help on using the repository browser.