[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>
|
---|
| 39 | #include <bool.h>
|
---|
| 40 | #include <errno.h>
|
---|
| 41 | #include <fcntl.h>
|
---|
| 42 | #include <gsp.h>
|
---|
| 43 | #include <io/console.h>
|
---|
| 44 | #include <io/keycode.h>
|
---|
| 45 | #include <ipc/kbdev.h>
|
---|
[854eddd6] | 46 | #include <input.h>
|
---|
[9c0242b] | 47 | #include <kbd.h>
|
---|
| 48 | #include <kbd_ctl.h>
|
---|
| 49 | #include <kbd_port.h>
|
---|
[cc574511] | 50 | #include <loc.h>
|
---|
[9c0242b] | 51 | #include <stdlib.h>
|
---|
| 52 | #include <vfs/vfs_sess.h>
|
---|
[6d605e6] | 53 | #include <sys/typefmt.h>
|
---|
[9c0242b] | 54 |
|
---|
| 55 | static int kbdev_ctl_init(kbd_dev_t *);
|
---|
[1875a0c] | 56 | static void kbdev_ctl_set_ind(kbd_dev_t *, unsigned int);
|
---|
[9c0242b] | 57 |
|
---|
[9934f7d] | 58 | static void kbdev_callback_conn(ipc_callid_t, ipc_call_t *, void *arg);
|
---|
[9c0242b] | 59 |
|
---|
| 60 | kbd_ctl_ops_t kbdev_ctl = {
|
---|
[1875a0c] | 61 | .parse = NULL,
|
---|
[9c0242b] | 62 | .init = kbdev_ctl_init,
|
---|
| 63 | .set_ind = kbdev_ctl_set_ind
|
---|
| 64 | };
|
---|
| 65 |
|
---|
| 66 | /** Kbdev softstate */
|
---|
| 67 | typedef 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 |
|
---|
| 75 | static kbdev_t *kbdev_new(kbd_dev_t *kdev)
|
---|
| 76 | {
|
---|
| 77 | kbdev_t *kbdev;
|
---|
| 78 |
|
---|
| 79 | kbdev = calloc(1, sizeof(kbdev_t));
|
---|
| 80 | if (kbdev == NULL)
|
---|
| 81 | return NULL;
|
---|
| 82 |
|
---|
| 83 | kbdev->kbd_dev = kdev;
|
---|
| 84 |
|
---|
| 85 | return kbdev;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | static void kbdev_destroy(kbdev_t *kbdev)
|
---|
| 89 | {
|
---|
| 90 | if (kbdev->sess != NULL)
|
---|
| 91 | async_hangup(kbdev->sess);
|
---|
| 92 | free(kbdev);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | static int kbdev_ctl_init(kbd_dev_t *kdev)
|
---|
| 96 | {
|
---|
| 97 | async_sess_t *sess;
|
---|
| 98 | async_exch_t *exch;
|
---|
| 99 | kbdev_t *kbdev;
|
---|
| 100 | int rc;
|
---|
| 101 |
|
---|
[cce8a83] | 102 | sess = loc_service_connect(EXCHANGE_SERIALIZE, kdev->svc_id, 0);
|
---|
[9c0242b] | 103 | if (sess == NULL) {
|
---|
[cc574511] | 104 | printf("%s: Failed starting session with '%s.'\n", NAME,
|
---|
[cce8a83] | 105 | kdev->svc_name);
|
---|
[9c0242b] | 106 | return -1;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | kbdev = kbdev_new(kdev);
|
---|
| 110 | if (kbdev == NULL) {
|
---|
[1875a0c] | 111 | printf("%s: Failed allocating device structure for '%s'.\n",
|
---|
[cce8a83] | 112 | NAME, kdev->svc_name);
|
---|
[9c0242b] | 113 | return -1;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | kbdev->sess = sess;
|
---|
| 117 |
|
---|
| 118 | exch = async_exchange_begin(sess);
|
---|
| 119 | if (exch == NULL) {
|
---|
[cc574511] | 120 | printf("%s: Failed starting exchange with '%s'.\n", NAME,
|
---|
[cce8a83] | 121 | kdev->svc_name);
|
---|
[9c0242b] | 122 | kbdev_destroy(kbdev);
|
---|
| 123 | return -1;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[9934f7d] | 126 | rc = async_connect_to_me(exch, 0, 0, 0, kbdev_callback_conn, kbdev);
|
---|
[9c0242b] | 127 | if (rc != EOK) {
|
---|
[1875a0c] | 128 | printf("%s: Failed creating callback connection from '%s'.\n",
|
---|
[cce8a83] | 129 | NAME, kdev->svc_name);
|
---|
[9c0242b] | 130 | async_exchange_end(exch);
|
---|
| 131 | kbdev_destroy(kbdev);
|
---|
| 132 | return -1;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | async_exchange_end(exch);
|
---|
| 136 |
|
---|
| 137 | kdev->ctl_private = (void *) kbdev;
|
---|
| 138 | return 0;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | static void kbdev_ctl_set_ind(kbd_dev_t *kdev, unsigned mods)
|
---|
| 142 | {
|
---|
| 143 | async_sess_t *sess;
|
---|
| 144 | async_exch_t *exch;
|
---|
| 145 |
|
---|
| 146 | sess = ((kbdev_t *) kdev->ctl_private)->sess;
|
---|
| 147 |
|
---|
| 148 | exch = async_exchange_begin(sess);
|
---|
| 149 | if (!exch)
|
---|
| 150 | return;
|
---|
| 151 |
|
---|
| 152 | async_msg_1(exch, KBDEV_SET_IND, mods);
|
---|
| 153 | async_exchange_end(exch);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[9934f7d] | 156 | static void kbdev_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
[9c0242b] | 157 | {
|
---|
| 158 | kbdev_t *kbdev;
|
---|
| 159 | int retval;
|
---|
| 160 | int type, key;
|
---|
| 161 |
|
---|
[9934f7d] | 162 | /* Kbdev device structure */
|
---|
| 163 | kbdev = arg;
|
---|
[9c0242b] | 164 |
|
---|
| 165 | while (true) {
|
---|
| 166 | ipc_call_t call;
|
---|
| 167 | ipc_callid_t callid;
|
---|
| 168 |
|
---|
| 169 | callid = async_get_call(&call);
|
---|
| 170 | if (!IPC_GET_IMETHOD(call)) {
|
---|
| 171 | /* XXX Handle hangup */
|
---|
| 172 | return;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | switch (IPC_GET_IMETHOD(call)) {
|
---|
| 176 | case KBDEV_EVENT:
|
---|
| 177 | /* Got event from keyboard device */
|
---|
| 178 | retval = 0;
|
---|
| 179 | type = IPC_GET_ARG1(call);
|
---|
| 180 | key = IPC_GET_ARG2(call);
|
---|
[1875a0c] | 181 | kbd_push_event(kbdev->kbd_dev, type, key);
|
---|
[9c0242b] | 182 | break;
|
---|
| 183 | default:
|
---|
| 184 | retval = ENOTSUP;
|
---|
| 185 | break;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | async_answer_0(callid, retval);
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /**
|
---|
| 193 | * @}
|
---|
| 194 | */
|
---|