Rev 1920 | Rev 1931 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1920 | Rev 1921 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2006 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup genarch |
29 | /** @addtogroup genarch |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief NS 16550 serial port / keyboard driver. |
34 | * @brief NS 16550 serial port / keyboard driver. |
35 | */ |
35 | */ |
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 | #include <arch/drivers/ns16550.h> |
41 | #include <arch/drivers/ns16550.h> |
42 | #include <ddi/irq.h> |
42 | #include <ddi/irq.h> |
43 | #include <arch/interrupt.h> |
43 | #include <arch/interrupt.h> |
44 | #include <cpu.h> |
44 | #include <cpu.h> |
45 | #include <arch/asm.h> |
45 | #include <arch/asm.h> |
46 | #include <arch.h> |
46 | #include <arch.h> |
47 | #include <typedefs.h> |
47 | #include <typedefs.h> |
48 | #include <console/chardev.h> |
48 | #include <console/chardev.h> |
49 | #include <console/console.h> |
49 | #include <console/console.h> |
50 | #include <interrupt.h> |
50 | #include <interrupt.h> |
51 | #include <sysinfo/sysinfo.h> |
51 | #include <sysinfo/sysinfo.h> |
52 | 52 | ||
53 | #define LSR_DATA_READY 0x01 |
53 | #define LSR_DATA_READY 0x01 |
54 | 54 | ||
- | 55 | /** Structure representing the ns16550. */ |
|
- | 56 | static ns16550_t ns16550; |
|
- | 57 | ||
- | 58 | /** Structure for ns16550's IRQ. */ |
|
- | 59 | static irq_t ns16550_irq; |
|
- | 60 | ||
55 | /* |
61 | /* |
56 | * These codes read from ns16550 data register are silently ignored. |
62 | * These codes read from ns16550 data register are silently ignored. |
57 | */ |
63 | */ |
58 | #define IGNORE_CODE 0x7f /* all keys up */ |
64 | #define IGNORE_CODE 0x7f /* all keys up */ |
59 | 65 | ||
60 | static void ns16550_suspend(chardev_t *); |
66 | static void ns16550_suspend(chardev_t *); |
61 | static void ns16550_resume(chardev_t *); |
67 | static void ns16550_resume(chardev_t *); |
62 | 68 | ||
63 | static chardev_operations_t ops = { |
69 | static chardev_operations_t ops = { |
64 | .suspend = ns16550_suspend, |
70 | .suspend = ns16550_suspend, |
65 | .resume = ns16550_resume, |
71 | .resume = ns16550_resume, |
66 | .read = ns16550_key_read |
72 | .read = ns16550_key_read |
67 | }; |
73 | }; |
68 | 74 | ||
69 | void ns16550_interrupt(int n, istate_t *istate); |
75 | void ns16550_interrupt(int n, istate_t *istate); |
70 | void ns16550_wait(void); |
76 | void ns16550_wait(void); |
71 | 77 | ||
72 | /** Initialize keyboard and service interrupts using kernel routine */ |
78 | /** Initialize keyboard and service interrupts using kernel routine */ |
73 | void ns16550_grab(void) |
79 | void ns16550_grab(void) |
74 | { |
80 | { |
75 | /* TODO */ |
81 | /* TODO */ |
76 | } |
82 | } |
77 | 83 | ||
78 | /** Resume the former interrupt vector */ |
84 | /** Resume the former interrupt vector */ |
79 | void ns16550_release(void) |
85 | void ns16550_release(void) |
80 | { |
86 | { |
81 | /* TODO */ |
87 | /* TODO */ |
82 | } |
88 | } |
83 | 89 | ||
84 | /** Initialize ns16550. */ |
90 | /** Initialize ns16550. |
- | 91 | * |
|
- | 92 | * @param devno Device number. |
|
- | 93 | * @param inr Interrupt number. |
|
- | 94 | * @param vaddr Virtual address of device's registers. |
|
- | 95 | */ |
|
85 | void ns16550_init(void) |
96 | void ns16550_init(devno_t devno, inr_t inr, uintptr_t vaddr) |
86 | { |
97 | { |
87 | ns16550_grab(); |
98 | ns16550_grab(); |
88 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
99 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
89 | stdin = &kbrd; |
100 | stdin = &kbrd; |
90 | 101 | ||
- | 102 | ns16550.devno = devno; |
|
- | 103 | ns16550.reg = (uint8_t *) vaddr; |
|
- | 104 | ||
- | 105 | irq_initialize(&ns16550_irq); |
|
- | 106 | ns16550_irq.devno = devno; |
|
- | 107 | ns16550_irq.inr = inr; |
|
- | 108 | ns16550_irq.claim = ns16550_claim; |
|
- | 109 | ns16550_irq.handler = ns16550_irq_handler; |
|
- | 110 | irq_register(&ns16550_irq); |
|
- | 111 | ||
91 | sysinfo_set_item_val("kbd", NULL, true); |
112 | sysinfo_set_item_val("kbd", NULL, true); |
- | 113 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
|
92 | sysinfo_set_item_val("kbd.irq", NULL, 0); |
114 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
93 | sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address); |
115 | sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr); |
94 | 116 | ||
95 | ns16550_ier_write(IER_ERBFI); /* enable receiver interrupt */ |
117 | ns16550_ier_write(&ns16550, IER_ERBFI); /* enable receiver interrupt */ |
96 | 118 | ||
97 | while (ns16550_lsr_read() & LSR_DATA_READY) |
119 | while (ns16550_lsr_read(&ns16550) & LSR_DATA_READY) |
98 | (void) ns16550_rbr_read(); |
120 | (void) ns16550_rbr_read(&ns16550); |
99 | } |
121 | } |
100 | 122 | ||
101 | /** Process ns16550 interrupt. |
123 | /** Process ns16550 interrupt. |
102 | * |
124 | * |
103 | * @param n Interrupt vector. |
125 | * @param n Interrupt vector. |
104 | * @param istate Interrupted state. |
126 | * @param istate Interrupted state. |
105 | */ |
127 | */ |
106 | void ns16550_interrupt(int n, istate_t *istate) |
128 | void ns16550_interrupt(int n, istate_t *istate) |
107 | { |
129 | { |
108 | /* TODO */ |
130 | /* TODO */ |
109 | } |
131 | } |
110 | 132 | ||
111 | /** Wait until the controller reads its data. */ |
133 | /** Wait until the controller reads its data. */ |
112 | void ns16550_wait(void) |
134 | void ns16550_wait(void) |
113 | { |
135 | { |
114 | } |
136 | } |
115 | 137 | ||
116 | /* Called from getc(). */ |
138 | /* Called from getc(). */ |
117 | void ns16550_resume(chardev_t *d) |
139 | void ns16550_resume(chardev_t *d) |
118 | { |
140 | { |
119 | } |
141 | } |
120 | 142 | ||
121 | /* Called from getc(). */ |
143 | /* Called from getc(). */ |
122 | void ns16550_suspend(chardev_t *d) |
144 | void ns16550_suspend(chardev_t *d) |
123 | { |
145 | { |
124 | } |
146 | } |
125 | 147 | ||
126 | char ns16550_key_read(chardev_t *d) |
148 | char ns16550_key_read(chardev_t *d) |
127 | { |
149 | { |
128 | char ch; |
150 | char ch; |
129 | 151 | ||
130 | while(!(ch = active_read_buff_read())) { |
152 | while(!(ch = active_read_buff_read())) { |
131 | uint8_t x; |
153 | uint8_t x; |
132 | while (!(ns16550_lsr_read() & LSR_DATA_READY)) |
154 | while (!(ns16550_lsr_read(&ns16550) & LSR_DATA_READY)) |
133 | ; |
155 | ; |
134 | x = ns16550_rbr_read(); |
156 | x = ns16550_rbr_read(&ns16550); |
135 | if (x != IGNORE_CODE) { |
157 | if (x != IGNORE_CODE) { |
136 | if (x & KEY_RELEASE) |
158 | if (x & KEY_RELEASE) |
137 | key_released(x ^ KEY_RELEASE); |
159 | key_released(x ^ KEY_RELEASE); |
138 | else |
160 | else |
139 | active_read_key_pressed(x); |
161 | active_read_key_pressed(x); |
140 | } |
162 | } |
141 | } |
163 | } |
142 | return ch; |
164 | return ch; |
143 | } |
165 | } |
144 | 166 | ||
145 | /** Poll for key press and release events. |
167 | /** Poll for key press and release events. |
146 | * |
168 | * |
147 | * This function can be used to implement keyboard polling. |
169 | * This function can be used to implement keyboard polling. |
148 | */ |
170 | */ |
149 | void ns16550_poll(void) |
171 | void ns16550_poll(void) |
150 | { |
172 | { |
151 | uint8_t x; |
173 | uint8_t x; |
152 | 174 | ||
153 | while (ns16550_lsr_read() & LSR_DATA_READY) { |
175 | while (ns16550_lsr_read(&ns16550) & LSR_DATA_READY) { |
154 | x = ns16550_rbr_read(); |
176 | x = ns16550_rbr_read(&ns16550); |
155 | if (x != IGNORE_CODE) { |
177 | if (x != IGNORE_CODE) { |
156 | if (x & KEY_RELEASE) |
178 | if (x & KEY_RELEASE) |
157 | key_released(x ^ KEY_RELEASE); |
179 | key_released(x ^ KEY_RELEASE); |
158 | else |
180 | else |
159 | key_pressed(x); |
181 | key_pressed(x); |
160 | } |
182 | } |
161 | } |
183 | } |
162 | } |
184 | } |
163 | 185 | ||
164 | irq_ownership_t ns16550_claim(void) |
186 | irq_ownership_t ns16550_claim(void) |
165 | { |
187 | { |
166 | /* TODO */ |
188 | /* TODO */ |
167 | return IRQ_ACCEPT; |
189 | return IRQ_ACCEPT; |
168 | } |
190 | } |
169 | 191 | ||
170 | void ns16550_irq_handler(irq_t *irq, void *arg, ...) |
192 | void ns16550_irq_handler(irq_t *irq, void *arg, ...) |
171 | { |
193 | { |
172 | panic("Not yet implemented.\n"); |
194 | panic("Not yet implemented.\n"); |
173 | } |
195 | } |
174 | 196 | ||
175 | /** @} |
197 | /** @} |
176 | */ |
198 | */ |
177 | 199 |