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

Last change on this file was fafb8e5, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Mechanically lowercase IPC_SET_*/IPC_GET_*

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