Rev 1919 | Rev 1921 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1919 | Rev 1920 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 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 <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 | /* |
55 | /* |
56 | * These codes read from ns16550 data register are silently ignored. |
56 | * These codes read from ns16550 data register are silently ignored. |
57 | */ |
57 | */ |
58 | #define IGNORE_CODE 0x7f /* all keys up */ |
58 | #define IGNORE_CODE 0x7f /* all keys up */ |
59 | 59 | ||
60 | static void ns16550_suspend(chardev_t *); |
60 | static void ns16550_suspend(chardev_t *); |
61 | static void ns16550_resume(chardev_t *); |
61 | static void ns16550_resume(chardev_t *); |
62 | 62 | ||
63 | static chardev_operations_t ops = { |
63 | static chardev_operations_t ops = { |
64 | .suspend = ns16550_suspend, |
64 | .suspend = ns16550_suspend, |
65 | .resume = ns16550_resume, |
65 | .resume = ns16550_resume, |
66 | .read = ns16550_key_read |
66 | .read = ns16550_key_read |
67 | }; |
67 | }; |
68 | 68 | ||
69 | void ns16550_interrupt(int n, istate_t *istate); |
69 | void ns16550_interrupt(int n, istate_t *istate); |
70 | void ns16550_wait(void); |
70 | void ns16550_wait(void); |
71 | 71 | ||
72 | /** Initialize keyboard and service interrupts using kernel routine */ |
72 | /** Initialize keyboard and service interrupts using kernel routine */ |
73 | void ns16550_grab(void) |
73 | void ns16550_grab(void) |
74 | { |
74 | { |
75 | /* TODO */ |
75 | /* TODO */ |
76 | } |
76 | } |
77 | 77 | ||
78 | /** Resume the former interrupt vector */ |
78 | /** Resume the former interrupt vector */ |
79 | void ns16550_release(void) |
79 | void ns16550_release(void) |
80 | { |
80 | { |
81 | /* TODO */ |
81 | /* TODO */ |
82 | } |
82 | } |
83 | 83 | ||
84 | /** Initialize ns16550. */ |
84 | /** Initialize ns16550. */ |
85 | void ns16550_init(void) |
85 | void ns16550_init(void) |
86 | { |
86 | { |
87 | ns16550_grab(); |
87 | ns16550_grab(); |
88 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
88 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
89 | stdin = &kbrd; |
89 | stdin = &kbrd; |
90 | 90 | ||
91 | sysinfo_set_item_val("kbd", NULL, true); |
91 | sysinfo_set_item_val("kbd", NULL, true); |
92 | sysinfo_set_item_val("kbd.irq", NULL, 0); |
92 | sysinfo_set_item_val("kbd.irq", NULL, 0); |
93 | sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address); |
93 | sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address); |
94 | 94 | ||
95 | ns16550_ier_write(IER_ERBFI); /* enable receiver interrupt */ |
95 | ns16550_ier_write(IER_ERBFI); /* enable receiver interrupt */ |
96 | 96 | ||
97 | while (ns16550_lsr_read() & LSR_DATA_READY) |
97 | while (ns16550_lsr_read() & LSR_DATA_READY) |
98 | (void) ns16550_rbr_read(); |
98 | (void) ns16550_rbr_read(); |
99 | } |
99 | } |
100 | 100 | ||
101 | /** Process ns16550 interrupt. |
101 | /** Process ns16550 interrupt. |
102 | * |
102 | * |
103 | * @param n Interrupt vector. |
103 | * @param n Interrupt vector. |
104 | * @param istate Interrupted state. |
104 | * @param istate Interrupted state. |
105 | */ |
105 | */ |
106 | void ns16550_interrupt(int n, istate_t *istate) |
106 | void ns16550_interrupt(int n, istate_t *istate) |
107 | { |
107 | { |
108 | /* TODO */ |
108 | /* TODO */ |
109 | } |
109 | } |
110 | 110 | ||
111 | /** Wait until the controller reads its data. */ |
111 | /** Wait until the controller reads its data. */ |
112 | void ns16550_wait(void) |
112 | void ns16550_wait(void) |
113 | { |
113 | { |
114 | } |
114 | } |
115 | 115 | ||
116 | /* Called from getc(). */ |
116 | /* Called from getc(). */ |
117 | void ns16550_resume(chardev_t *d) |
117 | void ns16550_resume(chardev_t *d) |
118 | { |
118 | { |
119 | } |
119 | } |
120 | 120 | ||
121 | /* Called from getc(). */ |
121 | /* Called from getc(). */ |
122 | void ns16550_suspend(chardev_t *d) |
122 | void ns16550_suspend(chardev_t *d) |
123 | { |
123 | { |
124 | } |
124 | } |
125 | 125 | ||
126 | char ns16550_key_read(chardev_t *d) |
126 | char ns16550_key_read(chardev_t *d) |
127 | { |
127 | { |
128 | char ch; |
128 | char ch; |
129 | 129 | ||
130 | while(!(ch = active_read_buff_read())) { |
130 | while(!(ch = active_read_buff_read())) { |
131 | uint8_t x; |
131 | uint8_t x; |
132 | while (!(ns16550_lsr_read() & LSR_DATA_READY)) |
132 | while (!(ns16550_lsr_read() & LSR_DATA_READY)) |
133 | ; |
133 | ; |
134 | x = ns16550_rbr_read(); |
134 | x = ns16550_rbr_read(); |
135 | if (x != IGNORE_CODE) { |
135 | if (x != IGNORE_CODE) { |
136 | if (x & KEY_RELEASE) |
136 | if (x & KEY_RELEASE) |
137 | key_released(x ^ KEY_RELEASE); |
137 | key_released(x ^ KEY_RELEASE); |
138 | else |
138 | else |
139 | active_read_key_pressed(x); |
139 | active_read_key_pressed(x); |
140 | } |
140 | } |
141 | } |
141 | } |
142 | return ch; |
142 | return ch; |
143 | } |
143 | } |
144 | 144 | ||
145 | /** Poll for key press and release events. |
145 | /** Poll for key press and release events. |
146 | * |
146 | * |
147 | * This function can be used to implement keyboard polling. |
147 | * This function can be used to implement keyboard polling. |
148 | */ |
148 | */ |
149 | void ns16550_poll(void) |
149 | void ns16550_poll(void) |
150 | { |
150 | { |
151 | uint8_t x; |
151 | uint8_t x; |
152 | 152 | ||
153 | while (ns16550_lsr_read() & LSR_DATA_READY) { |
153 | while (ns16550_lsr_read() & LSR_DATA_READY) { |
154 | x = ns16550_rbr_read(); |
154 | x = ns16550_rbr_read(); |
155 | if (x != IGNORE_CODE) { |
155 | if (x != IGNORE_CODE) { |
156 | if (x & KEY_RELEASE) |
156 | if (x & KEY_RELEASE) |
157 | key_released(x ^ KEY_RELEASE); |
157 | key_released(x ^ KEY_RELEASE); |
158 | else |
158 | else |
159 | key_pressed(x); |
159 | key_pressed(x); |
160 | } |
160 | } |
161 | } |
161 | } |
162 | } |
162 | } |
163 | 163 | ||
164 | irq_ownership_t ns16550_claim(void) |
164 | irq_ownership_t ns16550_claim(void) |
165 | { |
165 | { |
166 | /* TODO */ |
166 | /* TODO */ |
167 | return IRQ_ACCEPT; |
167 | return IRQ_ACCEPT; |
168 | } |
168 | } |
169 | 169 | ||
170 | void ns16550_irq_handler(irq_t *irq, void *arg, ...) |
170 | void ns16550_irq_handler(irq_t *irq, void *arg, ...) |
171 | { |
171 | { |
172 | panic("Not yet implemented.\n"); |
172 | panic("Not yet implemented.\n"); |
173 | } |
173 | } |
174 | 174 | ||
175 | /** @} |
175 | /** @} |
176 | */ |
176 | */ |
177 | 177 |