Rev 3593 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3593 | Rev 3665 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | 36 | ||
37 | #include <genarch/kbd/ns16550.h> |
37 | #include <genarch/kbd/ns16550.h> |
38 | #include <genarch/kbd/key.h> |
38 | #include <genarch/kbd/key.h> |
39 | #include <genarch/kbd/scanc.h> |
39 | #include <genarch/kbd/scanc.h> |
40 | #include <genarch/kbd/scanc_sun.h> |
40 | #include <genarch/kbd/scanc_sun.h> |
41 | #ifndef ia64 |
- | |
42 | #include <arch/drivers/kbd.h> |
41 | #include <arch/drivers/kbd.h> |
- | 42 | #ifndef ia64 |
|
43 | #include <arch/drivers/ns16550.h> |
43 | #include <arch/drivers/ns16550.h> |
44 | #endif |
44 | #endif |
45 | #include <ddi/irq.h> |
45 | #include <ddi/irq.h> |
46 | #include <ipc/irq.h> |
46 | #include <ipc/irq.h> |
47 | #include <cpu.h> |
47 | #include <cpu.h> |
Line 105... | Line 105... | ||
105 | interrupts_restore(ipl); |
105 | interrupts_restore(ipl); |
106 | } |
106 | } |
107 | 107 | ||
108 | /** Initialize ns16550. |
108 | /** Initialize ns16550. |
109 | * |
109 | * |
110 | * @param devno Device number. |
110 | * @param devno Device number. |
- | 111 | * @param port Virtual/IO address of device's registers. |
|
111 | * @param inr Interrupt number. |
112 | * @param inr Interrupt number. |
- | 113 | * @param cir Clear interrupt function. |
|
112 | * @param vaddr Virtual address of device's registers. |
114 | * @param cir_arg First argument to cir. |
113 | */ |
115 | */ |
- | 116 | void |
|
114 | void ns16550_init(devno_t devno, inr_t inr, ioport_t port) |
117 | ns16550_init(devno_t devno, ioport_t port, inr_t inr, cir_t cir, void *cir_arg) |
115 | { |
118 | { |
116 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
119 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
117 | stdin = &kbrd; |
120 | stdin = &kbrd; |
118 | 121 | ||
119 | ns16550.devno = devno; |
122 | ns16550.devno = devno; |
Line 122... | Line 125... | ||
122 | irq_initialize(&ns16550_irq); |
125 | irq_initialize(&ns16550_irq); |
123 | ns16550_irq.devno = devno; |
126 | ns16550_irq.devno = devno; |
124 | ns16550_irq.inr = inr; |
127 | ns16550_irq.inr = inr; |
125 | ns16550_irq.claim = ns16550_claim; |
128 | ns16550_irq.claim = ns16550_claim; |
126 | ns16550_irq.handler = ns16550_irq_handler; |
129 | ns16550_irq.handler = ns16550_irq_handler; |
- | 130 | ns16550_irq.cir = cir; |
|
- | 131 | ns16550_irq.cir_arg = cir_arg; |
|
127 | irq_register(&ns16550_irq); |
132 | irq_register(&ns16550_irq); |
- | 133 | ||
- | 134 | ||
- | 135 | while ((ns16550_lsr_read(&ns16550) & LSR_DATA_READY)) |
|
- | 136 | ns16550_rbr_read(&ns16550); |
|
- | 137 | ||
128 | 138 | ||
129 | sysinfo_set_item_val("kbd", NULL, true); |
139 | sysinfo_set_item_val("kbd", NULL, true); |
130 | #ifndef ia64 |
- | |
131 | sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550); |
140 | sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550); |
132 | #endif |
- | |
133 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
141 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
134 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
142 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
135 | sysinfo_set_item_val("kbd.address.virtual", NULL, port); |
143 | sysinfo_set_item_val("kbd.address.virtual", NULL, port); |
- | 144 | sysinfo_set_item_val("kbd.port", NULL, port); |
|
- | 145 | ||
- | 146 | #ifdef CONFIG_NS16550_INTERRUPT_DRIVEN |
|
- | 147 | /* Enable interrupts */ |
|
- | 148 | ns16550_ier_write(&ns16550, IER_ERBFI); |
|
- | 149 | ns16550_mcr_write(&ns16550, MCR_OUT2); |
|
- | 150 | #endif |
|
136 | 151 | ||
137 | #ifdef ia64 |
152 | #ifdef ia64 |
138 | uint8_t c; |
153 | uint8_t c; |
- | 154 | // This switches rbr & ier to mode when accept baudrate constant |
|
139 | c = ns16550_lcr_read(&ns16550); |
155 | c = ns16550_lcr_read(&ns16550); |
140 | ns16550_lcr_write(&ns16550, 0x80 | c); |
156 | ns16550_lcr_write(&ns16550, 0x80 | c); |
141 | ns16550_rbr_write(&ns16550, 0x0c); |
157 | ns16550_rbr_write(&ns16550, 0x0c); |
142 | ns16550_ier_write(&ns16550, 0x00); |
158 | ns16550_ier_write(&ns16550, 0x00); |
143 | ns16550_lcr_write(&ns16550, c); |
159 | ns16550_lcr_write(&ns16550, c); |
Line 147... | Line 163... | ||
147 | } |
163 | } |
148 | 164 | ||
149 | /** Process ns16550 interrupt. */ |
165 | /** Process ns16550 interrupt. */ |
150 | void ns16550_interrupt(void) |
166 | void ns16550_interrupt(void) |
151 | { |
167 | { |
152 | /* TODO |
- | |
153 | * |
- | |
154 | * ns16550 works in the polled mode so far. |
168 | ns16550_poll(); |
155 | */ |
- | |
156 | } |
169 | } |
157 | 170 | ||
158 | /* Called from getc(). */ |
171 | /* Called from getc(). */ |
159 | void ns16550_resume(chardev_t *d) |
172 | void ns16550_resume(chardev_t *d) |
160 | { |
173 | { |
Line 199... | Line 212... | ||
199 | * |
212 | * |
200 | * This function can be used to implement keyboard polling. |
213 | * This function can be used to implement keyboard polling. |
201 | */ |
214 | */ |
202 | void ns16550_poll(void) |
215 | void ns16550_poll(void) |
203 | { |
216 | { |
- | 217 | #ifndef CONFIG_NS16550_INTERRUPT_DRIVEN |
|
204 | ipl_t ipl; |
218 | ipl_t ipl; |
205 | 219 | ||
206 | ipl = interrupts_disable(); |
220 | ipl = interrupts_disable(); |
207 | spinlock_lock(&ns16550_irq.lock); |
221 | spinlock_lock(&ns16550_irq.lock); |
208 | 222 | ||
Line 218... | Line 232... | ||
218 | } |
232 | } |
219 | } |
233 | } |
220 | 234 | ||
221 | spinlock_unlock(&ns16550_irq.lock); |
235 | spinlock_unlock(&ns16550_irq.lock); |
222 | interrupts_restore(ipl); |
236 | interrupts_restore(ipl); |
- | 237 | #endif |
|
223 | 238 | ||
224 | while (ns16550_lsr_read(&ns16550) & LSR_DATA_READY) { |
239 | while (ns16550_lsr_read(&ns16550) & LSR_DATA_READY) { |
225 | uint8_t x; |
240 | uint8_t x; |
226 | 241 | ||
227 | x = ns16550_rbr_read(&ns16550); |
242 | x = ns16550_rbr_read(&ns16550); |
Line 249... | Line 264... | ||
249 | return (ns16550_lsr_read(&ns16550) & LSR_DATA_READY); |
264 | return (ns16550_lsr_read(&ns16550) & LSR_DATA_READY); |
250 | } |
265 | } |
251 | 266 | ||
252 | void ns16550_irq_handler(irq_t *irq, void *arg, ...) |
267 | void ns16550_irq_handler(irq_t *irq, void *arg, ...) |
253 | { |
268 | { |
254 | panic("Not yet implemented, ns16550 works in polled mode.\n"); |
269 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
- | 270 | ipc_irq_send_notif(irq); |
|
- | 271 | else |
|
- | 272 | ns16550_interrupt(); |
|
255 | } |
273 | } |
256 | 274 | ||
257 | /** @} |
275 | /** @} |
258 | */ |
276 | */ |