source: mainline/uspace/srv/hid/input/port/ns16550.c@ 17b3cc6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 17b3cc6 was f044e96, checked in by Martin Decky <martin@…>, 14 years ago

use systematic names

  • register_irq → irq_register
  • unregister_irq → irq_unregister
  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (c) 2006 Josef Cejka
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 NS16550 port driver.
36 */
37
38#include <ipc/irc.h>
39#include <async.h>
40#include <sysinfo.h>
41#include <input.h>
42#include <kbd.h>
43#include <kbd_port.h>
44#include <ddi.h>
45#include <errno.h>
46
47static int ns16550_port_init(kbd_dev_t *);
48static void ns16550_port_yield(void);
49static void ns16550_port_reclaim(void);
50static void ns16550_port_write(uint8_t data);
51
52kbd_port_ops_t ns16550_port = {
53 .init = ns16550_port_init,
54 .yield = ns16550_port_yield,
55 .reclaim = ns16550_port_reclaim,
56 .write = ns16550_port_write
57};
58
59static kbd_dev_t *kbd_dev;
60
61/* NS16550 registers */
62#define RBR_REG 0 /** Receiver Buffer Register. */
63#define IER_REG 1 /** Interrupt Enable Register. */
64#define IIR_REG 2 /** Interrupt Ident Register (read). */
65#define FCR_REG 2 /** FIFO control register (write). */
66#define LCR_REG 3 /** Line Control register. */
67#define MCR_REG 4 /** Modem Control Register. */
68#define LSR_REG 5 /** Line Status Register. */
69
70#define LSR_DATA_READY 0x01
71
72static irq_cmd_t ns16550_cmds[] = {
73 {
74 .cmd = CMD_PIO_READ_8,
75 .addr = (void *) 0, /* Will be patched in run-time */
76 .dstarg = 1
77 },
78 {
79 .cmd = CMD_BTEST,
80 .value = LSR_DATA_READY,
81 .srcarg = 1,
82 .dstarg = 3
83 },
84 {
85 .cmd = CMD_PREDICATE,
86 .value = 2,
87 .srcarg = 3
88 },
89 {
90 .cmd = CMD_PIO_READ_8,
91 .addr = (void *) 0, /* Will be patched in run-time */
92 .dstarg = 2
93 },
94 {
95 .cmd = CMD_ACCEPT
96 }
97};
98
99irq_code_t ns16550_kbd = {
100 sizeof(ns16550_cmds) / sizeof(irq_cmd_t),
101 ns16550_cmds
102};
103
104static void ns16550_irq_handler(ipc_callid_t iid, ipc_call_t *call);
105
106static uintptr_t ns16550_physical;
107static uintptr_t ns16550_kernel;
108
109static kbd_dev_t *kbd_dev;
110
111static int ns16550_port_init(kbd_dev_t *kdev)
112{
113 void *vaddr;
114
115 kbd_dev = kdev;
116
117 sysarg_t ns16550;
118 if (sysinfo_get_value("kbd.type.ns16550", &ns16550) != EOK)
119 return -1;
120 if (!ns16550)
121 return -1;
122
123 if (sysinfo_get_value("kbd.address.physical", &ns16550_physical) != EOK)
124 return -1;
125
126 if (sysinfo_get_value("kbd.address.kernel", &ns16550_kernel) != EOK)
127 return -1;
128
129 sysarg_t inr;
130 if (sysinfo_get_value("kbd.inr", &inr) != EOK)
131 return -1;
132
133 ns16550_kbd.cmds[0].addr = (void *) (ns16550_kernel + LSR_REG);
134 ns16550_kbd.cmds[3].addr = (void *) (ns16550_kernel + RBR_REG);
135
136 async_set_interrupt_received(ns16550_irq_handler);
137 irq_register(inr, device_assign_devno(), inr, &ns16550_kbd);
138
139 return pio_enable((void *) ns16550_physical, 8, &vaddr);
140}
141
142static void ns16550_port_yield(void)
143{
144}
145
146static void ns16550_port_reclaim(void)
147{
148}
149
150static void ns16550_port_write(uint8_t data)
151{
152 (void) data;
153}
154
155static void ns16550_irq_handler(ipc_callid_t iid, ipc_call_t *call)
156{
157 kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
158
159 if (irc_service) {
160 async_exch_t *exch = async_exchange_begin(irc_sess);
161 async_msg_1(exch, IRC_CLEAR_INTERRUPT, IPC_GET_IMETHOD(*call));
162 async_exchange_end(exch);
163 }
164}
165
166/**
167 * @}
168 */
Note: See TracBrowser for help on using the repository browser.