[f89979b] | 1 | /*
|
---|
| 2 | * Copyright (c) 2007 Michal Kebrt
|
---|
[9be360ee] | 3 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[f89979b] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[24ff4df] | 30 | /** @addtogroup kbd_port
|
---|
[f89979b] | 31 | * @{
|
---|
[24ff4df] | 32 | * @ingroup kbd
|
---|
[f89979b] | 33 | */
|
---|
| 34 | /** @file
|
---|
| 35 | * @brief GXEmul keyboard port driver.
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <async.h>
|
---|
| 39 | #include <sysinfo.h>
|
---|
| 40 | #include <kbd_port.h>
|
---|
| 41 | #include <kbd.h>
|
---|
[84afc7b] | 42 | #include <ddi.h>
|
---|
[d9fae235] | 43 | #include <errno.h>
|
---|
[f89979b] | 44 |
|
---|
[9be360ee] | 45 | static int gxemul_port_init(kbd_dev_t *);
|
---|
[b1bdc7a4] | 46 | static void gxemul_port_yield(void);
|
---|
| 47 | static void gxemul_port_reclaim(void);
|
---|
| 48 | static void gxemul_port_write(uint8_t data);
|
---|
| 49 |
|
---|
| 50 | kbd_port_ops_t gxemul_port = {
|
---|
| 51 | .init = gxemul_port_init,
|
---|
| 52 | .yield = gxemul_port_yield,
|
---|
| 53 | .reclaim = gxemul_port_reclaim,
|
---|
| 54 | .write = gxemul_port_write
|
---|
| 55 | };
|
---|
| 56 |
|
---|
[9be360ee] | 57 | static kbd_dev_t *kbd_dev;
|
---|
| 58 |
|
---|
[f89979b] | 59 | static irq_cmd_t gxemul_cmds[] = {
|
---|
| 60 | {
|
---|
[9446f39] | 61 | .cmd = CMD_PIO_READ_8,
|
---|
| 62 | .addr = (void *) 0, /* will be patched in run-time */
|
---|
| 63 | .dstarg = 2,
|
---|
| 64 | },
|
---|
| 65 | {
|
---|
| 66 | .cmd = CMD_ACCEPT
|
---|
[f89979b] | 67 | }
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | static irq_code_t gxemul_kbd = {
|
---|
[9446f39] | 71 | sizeof(gxemul_cmds) / sizeof(irq_cmd_t),
|
---|
[f89979b] | 72 | gxemul_cmds
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | static void gxemul_irq_handler(ipc_callid_t iid, ipc_call_t *call);
|
---|
| 76 |
|
---|
| 77 | /** Initializes keyboard handler. */
|
---|
[9be360ee] | 78 | static int gxemul_port_init(kbd_dev_t *kdev)
|
---|
[f89979b] | 79 | {
|
---|
[9be360ee] | 80 | kbd_dev = kdev;
|
---|
| 81 |
|
---|
[d9fae235] | 82 | sysarg_t addr;
|
---|
| 83 | if (sysinfo_get_value("kbd.address.virtual", &addr) != EOK)
|
---|
| 84 | return -1;
|
---|
| 85 |
|
---|
| 86 | sysarg_t inr;
|
---|
| 87 | if (sysinfo_get_value("kbd.inr", &inr) != EOK)
|
---|
| 88 | return -1;
|
---|
| 89 |
|
---|
[f89979b] | 90 | async_set_interrupt_received(gxemul_irq_handler);
|
---|
[d9fae235] | 91 | gxemul_cmds[0].addr = (void *) addr;
|
---|
[8add9ca5] | 92 | register_irq(inr, device_assign_devno(), 0, &gxemul_kbd);
|
---|
[f89979b] | 93 | return 0;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[b1bdc7a4] | 96 | static void gxemul_port_yield(void)
|
---|
[ccd1a14] | 97 | {
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[b1bdc7a4] | 100 | static void gxemul_port_reclaim(void)
|
---|
[ccd1a14] | 101 | {
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[b1bdc7a4] | 104 | static void gxemul_port_write(uint8_t data)
|
---|
[c145bc2] | 105 | {
|
---|
| 106 | (void) data;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[f89979b] | 109 | /** Process data sent when a key is pressed.
|
---|
| 110 | *
|
---|
| 111 | * @param keybuffer Buffer of pressed keys.
|
---|
| 112 | * @param call IPC call.
|
---|
| 113 | *
|
---|
| 114 | * @return Always 1.
|
---|
| 115 | */
|
---|
| 116 | static void gxemul_irq_handler(ipc_callid_t iid, ipc_call_t *call)
|
---|
| 117 | {
|
---|
| 118 | int scan_code = IPC_GET_ARG2(*call);
|
---|
| 119 |
|
---|
[9be360ee] | 120 | kbd_push_scancode(kbd_dev, scan_code);
|
---|
[f89979b] | 121 | }
|
---|
| 122 |
|
---|
| 123 | /** @}
|
---|
| 124 | */
|
---|