| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Martin Decky
|
|---|
| 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 mouse_port
|
|---|
| 30 | * @ingroup mouse
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | * @brief ADB mouse port driver.
|
|---|
| 35 | */
|
|---|
| 36 |
|
|---|
| 37 | #include <ipc/adb.h>
|
|---|
| 38 | #include <async.h>
|
|---|
| 39 | #include <input.h>
|
|---|
| 40 | #include <mouse_port.h>
|
|---|
| 41 | #include <mouse.h>
|
|---|
| 42 | #include <errno.h>
|
|---|
| 43 | #include <devmap.h>
|
|---|
| 44 |
|
|---|
| 45 | static mouse_dev_t *mouse_dev;
|
|---|
| 46 | static async_sess_t *dev_sess;
|
|---|
| 47 |
|
|---|
| 48 | static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
|---|
| 49 | {
|
|---|
| 50 | /* Ignore parameters, the connection is already opened */
|
|---|
| 51 | while (true) {
|
|---|
| 52 | ipc_call_t call;
|
|---|
| 53 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 54 |
|
|---|
| 55 | int retval;
|
|---|
| 56 |
|
|---|
| 57 | if (!IPC_GET_IMETHOD(call)) {
|
|---|
| 58 | /* TODO: Handle hangup */
|
|---|
| 59 | return;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| 63 | case ADB_REG_NOTIF:
|
|---|
| 64 | mouse_push_data(mouse_dev, IPC_GET_ARG1(call));
|
|---|
| 65 | break;
|
|---|
| 66 | default:
|
|---|
| 67 | retval = ENOENT;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | async_answer_0(callid, retval);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | static int adb_port_init(mouse_dev_t *mdev)
|
|---|
| 75 | {
|
|---|
| 76 | const char *dev = "adb/mouse";
|
|---|
| 77 |
|
|---|
| 78 | mouse_dev = mdev;
|
|---|
| 79 |
|
|---|
| 80 | devmap_handle_t handle;
|
|---|
| 81 | int rc = devmap_device_get_handle(dev, &handle, 0);
|
|---|
| 82 | if (rc != EOK)
|
|---|
| 83 | return rc;
|
|---|
| 84 |
|
|---|
| 85 | dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
|
|---|
| 86 | if (dev_sess == NULL) {
|
|---|
| 87 | printf("%s: Failed to connect to device\n", NAME);
|
|---|
| 88 | return ENOENT;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | async_exch_t *exch = async_exchange_begin(dev_sess);
|
|---|
| 92 | if (exch == NULL) {
|
|---|
| 93 | printf("%s: Failed starting exchange with device\n", NAME);
|
|---|
| 94 | async_hangup(dev_sess);
|
|---|
| 95 | return ENOMEM;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /* NB: The callback connection is slotted for removal */
|
|---|
| 99 | rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL);
|
|---|
| 100 | async_exchange_end(exch);
|
|---|
| 101 | if (rc != EOK) {
|
|---|
| 102 | printf("%s: Failed to create callback from device\n", NAME);
|
|---|
| 103 | async_hangup(dev_sess);
|
|---|
| 104 | return rc;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | return EOK;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | static void adb_port_yield(void)
|
|---|
| 111 | {
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | static void adb_port_reclaim(void)
|
|---|
| 115 | {
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | static void adb_port_write(uint8_t data)
|
|---|
| 119 | {
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | mouse_port_ops_t adb_mouse_port = {
|
|---|
| 123 | .init = adb_port_init,
|
|---|
| 124 | .yield = adb_port_yield,
|
|---|
| 125 | .reclaim = adb_port_reclaim,
|
|---|
| 126 | .write = adb_port_write
|
|---|
| 127 | };
|
|---|
| 128 |
|
|---|
| 129 | /**
|
|---|
| 130 | * @}
|
|---|
| 131 | */
|
|---|