| 1 | /*
|
|---|
| 2 | * Copyright (c) 2006 Martin Decky
|
|---|
| 3 | * Copyright (c) 2011 Jiri Svoboda
|
|---|
| 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 |
|
|---|
| 30 | /** @addtogroup kbd_port
|
|---|
| 31 | * @ingroup kbd
|
|---|
| 32 | * @{
|
|---|
| 33 | */
|
|---|
| 34 | /** @file
|
|---|
| 35 | * @brief Z8530 keyboard port driver.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <ipc/irc.h>
|
|---|
| 39 | #include <async.h>
|
|---|
| 40 | #include <async_obsolete.h>
|
|---|
| 41 | #include <sysinfo.h>
|
|---|
| 42 | #include <input.h>
|
|---|
| 43 | #include <kbd.h>
|
|---|
| 44 | #include <kbd_port.h>
|
|---|
| 45 | #include <sys/types.h>
|
|---|
| 46 | #include <ddi.h>
|
|---|
| 47 | #include <errno.h>
|
|---|
| 48 |
|
|---|
| 49 | static int z8530_port_init(kbd_dev_t *);
|
|---|
| 50 | static void z8530_port_yield(void);
|
|---|
| 51 | static void z8530_port_reclaim(void);
|
|---|
| 52 | static void z8530_port_write(uint8_t data);
|
|---|
| 53 |
|
|---|
| 54 | kbd_port_ops_t z8530_port = {
|
|---|
| 55 | .init = z8530_port_init,
|
|---|
| 56 | .yield = z8530_port_yield,
|
|---|
| 57 | .reclaim = z8530_port_reclaim,
|
|---|
| 58 | .write = z8530_port_write
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | static kbd_dev_t *kbd_dev;
|
|---|
| 62 |
|
|---|
| 63 | #define CHAN_A_STATUS 4
|
|---|
| 64 | #define CHAN_A_DATA 6
|
|---|
| 65 |
|
|---|
| 66 | #define RR0_RCA 1
|
|---|
| 67 |
|
|---|
| 68 | static irq_cmd_t z8530_cmds[] = {
|
|---|
| 69 | {
|
|---|
| 70 | .cmd = CMD_PIO_READ_8,
|
|---|
| 71 | .addr = (void *) 0, /* Will be patched in run-time */
|
|---|
| 72 | .dstarg = 1
|
|---|
| 73 | },
|
|---|
| 74 | {
|
|---|
| 75 | .cmd = CMD_BTEST,
|
|---|
| 76 | .value = RR0_RCA,
|
|---|
| 77 | .srcarg = 1,
|
|---|
| 78 | .dstarg = 3
|
|---|
| 79 | },
|
|---|
| 80 | {
|
|---|
| 81 | .cmd = CMD_PREDICATE,
|
|---|
| 82 | .value = 2,
|
|---|
| 83 | .srcarg = 3
|
|---|
| 84 | },
|
|---|
| 85 | {
|
|---|
| 86 | .cmd = CMD_PIO_READ_8,
|
|---|
| 87 | .addr = (void *) 0, /* Will be patched in run-time */
|
|---|
| 88 | .dstarg = 2
|
|---|
| 89 | },
|
|---|
| 90 | {
|
|---|
| 91 | .cmd = CMD_ACCEPT
|
|---|
| 92 | }
|
|---|
| 93 | };
|
|---|
| 94 |
|
|---|
| 95 | static irq_code_t z8530_kbd = {
|
|---|
| 96 | sizeof(z8530_cmds) / sizeof(irq_cmd_t),
|
|---|
| 97 | z8530_cmds
|
|---|
| 98 | };
|
|---|
| 99 |
|
|---|
| 100 | static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call);
|
|---|
| 101 |
|
|---|
| 102 | static int z8530_port_init(kbd_dev_t *kdev)
|
|---|
| 103 | {
|
|---|
| 104 | kbd_dev = kdev;
|
|---|
| 105 |
|
|---|
| 106 | sysarg_t z8530;
|
|---|
| 107 | if (sysinfo_get_value("kbd.type.z8530", &z8530) != EOK)
|
|---|
| 108 | return -1;
|
|---|
| 109 | if (!z8530)
|
|---|
| 110 | return -1;
|
|---|
| 111 |
|
|---|
| 112 | sysarg_t kaddr;
|
|---|
| 113 | if (sysinfo_get_value("kbd.address.kernel", &kaddr) != EOK)
|
|---|
| 114 | return -1;
|
|---|
| 115 |
|
|---|
| 116 | sysarg_t inr;
|
|---|
| 117 | if (sysinfo_get_value("kbd.inr", &inr) != EOK)
|
|---|
| 118 | return -1;
|
|---|
| 119 |
|
|---|
| 120 | z8530_cmds[0].addr = (void *) kaddr + CHAN_A_STATUS;
|
|---|
| 121 | z8530_cmds[3].addr = (void *) kaddr + CHAN_A_DATA;
|
|---|
| 122 |
|
|---|
| 123 | async_set_interrupt_received(z8530_irq_handler);
|
|---|
| 124 | register_irq(inr, device_assign_devno(), inr, &z8530_kbd);
|
|---|
| 125 |
|
|---|
| 126 | return 0;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | static void z8530_port_yield(void)
|
|---|
| 130 | {
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | static void z8530_port_reclaim(void)
|
|---|
| 134 | {
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | static void z8530_port_write(uint8_t data)
|
|---|
| 138 | {
|
|---|
| 139 | (void) data;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call)
|
|---|
| 143 | {
|
|---|
| 144 | kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
|
|---|
| 145 |
|
|---|
| 146 | if (irc_service)
|
|---|
| 147 | async_obsolete_msg_1(irc_phone, IRC_CLEAR_INTERRUPT,
|
|---|
| 148 | IPC_GET_IMETHOD(*call));
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | /** @}
|
|---|
| 152 | */
|
|---|