[51d6f80] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Josef Cejka
|
---|
[4f3f9659] | 3 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[51d6f80] | 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
|
---|
[ce5bcb4] | 31 | * @ingroup kbd
|
---|
| 32 | * @{
|
---|
[d9fae235] | 33 | */
|
---|
[ce5bcb4] | 34 | /** @file
|
---|
[d9fae235] | 35 | * @brief NS16550 port driver.
|
---|
[ce5bcb4] | 36 | */
|
---|
| 37 |
|
---|
[acc7ce4] | 38 | #include <ipc/irc.h>
|
---|
[24ff4df] | 39 | #include <async.h>
|
---|
| 40 | #include <sysinfo.h>
|
---|
[15039b67] | 41 | #include <ddi.h>
|
---|
[d9fae235] | 42 | #include <errno.h>
|
---|
[b6a088f] | 43 | #include "../input.h"
|
---|
| 44 | #include "../kbd_port.h"
|
---|
| 45 | #include "../kbd.h"
|
---|
[15039b67] | 46 |
|
---|
[4f3f9659] | 47 | static int ns16550_port_init(kbd_dev_t *);
|
---|
| 48 | static void ns16550_port_write(uint8_t data);
|
---|
| 49 |
|
---|
| 50 | kbd_port_ops_t ns16550_port = {
|
---|
| 51 | .init = ns16550_port_init,
|
---|
| 52 | .write = ns16550_port_write
|
---|
| 53 | };
|
---|
| 54 |
|
---|
| 55 | static kbd_dev_t *kbd_dev;
|
---|
| 56 |
|
---|
[24ff4df] | 57 | /* NS16550 registers */
|
---|
[d9fae235] | 58 | #define RBR_REG 0 /** Receiver Buffer Register. */
|
---|
| 59 | #define IER_REG 1 /** Interrupt Enable Register. */
|
---|
| 60 | #define IIR_REG 2 /** Interrupt Ident Register (read). */
|
---|
| 61 | #define FCR_REG 2 /** FIFO control register (write). */
|
---|
| 62 | #define LCR_REG 3 /** Line Control register. */
|
---|
| 63 | #define MCR_REG 4 /** Modem Control Register. */
|
---|
| 64 | #define LSR_REG 5 /** Line Status Register. */
|
---|
[15039b67] | 65 |
|
---|
[d9fae235] | 66 | #define LSR_DATA_READY 0x01
|
---|
[21df2e5] | 67 |
|
---|
[a31aad1] | 68 | static irq_pio_range_t ns16550_ranges[] = {
|
---|
| 69 | {
|
---|
| 70 | .base = 0,
|
---|
| 71 | .size = 8
|
---|
| 72 | }
|
---|
| 73 | };
|
---|
| 74 |
|
---|
[21df2e5] | 75 | static irq_cmd_t ns16550_cmds[] = {
|
---|
| 76 | {
|
---|
| 77 | .cmd = CMD_PIO_READ_8,
|
---|
[d9fae235] | 78 | .addr = (void *) 0, /* Will be patched in run-time */
|
---|
[21df2e5] | 79 | .dstarg = 1
|
---|
| 80 | },
|
---|
| 81 | {
|
---|
[8486c07] | 82 | .cmd = CMD_AND,
|
---|
[21df2e5] | 83 | .value = LSR_DATA_READY,
|
---|
| 84 | .srcarg = 1,
|
---|
| 85 | .dstarg = 3
|
---|
| 86 | },
|
---|
| 87 | {
|
---|
| 88 | .cmd = CMD_PREDICATE,
|
---|
| 89 | .value = 2,
|
---|
| 90 | .srcarg = 3
|
---|
| 91 | },
|
---|
| 92 | {
|
---|
| 93 | .cmd = CMD_PIO_READ_8,
|
---|
[d9fae235] | 94 | .addr = (void *) 0, /* Will be patched in run-time */
|
---|
[21df2e5] | 95 | .dstarg = 2
|
---|
| 96 | },
|
---|
| 97 | {
|
---|
| 98 | .cmd = CMD_ACCEPT
|
---|
| 99 | }
|
---|
[24ff4df] | 100 | };
|
---|
[15039b67] | 101 |
|
---|
[24ff4df] | 102 | irq_code_t ns16550_kbd = {
|
---|
[a31aad1] | 103 | sizeof(ns16550_ranges) / sizeof(irq_pio_range_t),
|
---|
| 104 | ns16550_ranges,
|
---|
[21df2e5] | 105 | sizeof(ns16550_cmds) / sizeof(irq_cmd_t),
|
---|
[24ff4df] | 106 | ns16550_cmds
|
---|
| 107 | };
|
---|
[15039b67] | 108 |
|
---|
[ff685c9] | 109 | static uintptr_t ns16550_physical;
|
---|
[9be360ee] | 110 | static kbd_dev_t *kbd_dev;
|
---|
[8820544] | 111 | static sysarg_t inr;
|
---|
[9be360ee] | 112 |
|
---|
[8820544] | 113 | static void ns16550_irq_handler(ipc_callid_t iid, ipc_call_t *call, void *arg)
|
---|
[15039b67] | 114 | {
|
---|
[8820544] | 115 | kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
|
---|
[4f3f9659] | 116 |
|
---|
[8820544] | 117 | if (irc_service) {
|
---|
| 118 | async_exch_t *exch = async_exchange_begin(irc_sess);
|
---|
| 119 | async_msg_1(exch, IRC_CLEAR_INTERRUPT, inr);
|
---|
| 120 | async_exchange_end(exch);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | static int ns16550_port_init(kbd_dev_t *kdev)
|
---|
| 125 | {
|
---|
[9be360ee] | 126 | kbd_dev = kdev;
|
---|
[4f3f9659] | 127 |
|
---|
| 128 | sysarg_t ns16550;
|
---|
| 129 | if (sysinfo_get_value("kbd.type.ns16550", &ns16550) != EOK)
|
---|
| 130 | return -1;
|
---|
| 131 | if (!ns16550)
|
---|
| 132 | return -1;
|
---|
| 133 |
|
---|
[d9fae235] | 134 | if (sysinfo_get_value("kbd.address.physical", &ns16550_physical) != EOK)
|
---|
| 135 | return -1;
|
---|
| 136 |
|
---|
| 137 | if (sysinfo_get_value("kbd.inr", &inr) != EOK)
|
---|
| 138 | return -1;
|
---|
| 139 |
|
---|
[a31aad1] | 140 | ns16550_kbd.ranges[0].base = ns16550_physical;
|
---|
| 141 | ns16550_kbd.cmds[0].addr = (void *) (ns16550_physical + LSR_REG);
|
---|
| 142 | ns16550_kbd.cmds[3].addr = (void *) (ns16550_physical + RBR_REG);
|
---|
[d9fae235] | 143 |
|
---|
[8820544] | 144 | async_irq_subscribe(inr, device_assign_devno(), ns16550_irq_handler, NULL,
|
---|
| 145 | &ns16550_kbd);
|
---|
[d9fae235] | 146 |
|
---|
[8820544] | 147 | void *vaddr;
|
---|
[ff685c9] | 148 | return pio_enable((void *) ns16550_physical, 8, &vaddr);
|
---|
[15039b67] | 149 | }
|
---|
| 150 |
|
---|
[4f3f9659] | 151 | static void ns16550_port_write(uint8_t data)
|
---|
| 152 | {
|
---|
| 153 | (void) data;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[ce5bcb4] | 156 | /**
|
---|
| 157 | * @}
|
---|
[24ff4df] | 158 | */
|
---|