Rev 1888 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1888 | Rev 1896 | ||
---|---|---|---|
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 <arch/interrupt.h> |
42 | #include <arch/interrupt.h> |
43 | #include <cpu.h> |
43 | #include <cpu.h> |
44 | #include <arch/asm.h> |
44 | #include <arch/asm.h> |
45 | #include <arch.h> |
45 | #include <arch.h> |
46 | #include <typedefs.h> |
46 | #include <typedefs.h> |
47 | #include <console/chardev.h> |
47 | #include <console/chardev.h> |
48 | #include <console/console.h> |
48 | #include <console/console.h> |
49 | #include <interrupt.h> |
49 | #include <interrupt.h> |
50 | #include <sysinfo/sysinfo.h> |
50 | #include <sysinfo/sysinfo.h> |
51 | 51 | ||
52 | #define LSR_DATA_READY 0x01 |
52 | #define LSR_DATA_READY 0x01 |
53 | 53 | ||
54 | /* |
54 | /* |
55 | * These codes read from ns16550 data register are silently ignored. |
55 | * These codes read from ns16550 data register are silently ignored. |
56 | */ |
56 | */ |
57 | #define IGNORE_CODE 0x7f /* all keys up */ |
57 | #define IGNORE_CODE 0x7f /* all keys up */ |
58 | 58 | ||
59 | static void ns16550_suspend(chardev_t *); |
59 | static void ns16550_suspend(chardev_t *); |
60 | static void ns16550_resume(chardev_t *); |
60 | static void ns16550_resume(chardev_t *); |
61 | 61 | ||
62 | chardev_t kbrd; |
- | |
63 | static chardev_operations_t ops = { |
62 | static chardev_operations_t ops = { |
64 | .suspend = ns16550_suspend, |
63 | .suspend = ns16550_suspend, |
65 | .resume = ns16550_resume, |
64 | .resume = ns16550_resume, |
66 | .read = key_read |
65 | .read = ns16550_key_read |
67 | }; |
66 | }; |
68 | 67 | ||
69 | void ns16550_interrupt(int n, istate_t *istate); |
68 | void ns16550_interrupt(int n, istate_t *istate); |
70 | void ns16550_wait(void); |
69 | void ns16550_wait(void); |
71 | 70 | ||
72 | /** Initialize keyboard and service interrupts using kernel routine */ |
71 | /** Initialize keyboard and service interrupts using kernel routine */ |
73 | void ns16550_grab(void) |
72 | void ns16550_grab(void) |
74 | { |
73 | { |
75 | /* TODO */ |
74 | /* TODO */ |
76 | } |
75 | } |
77 | 76 | ||
78 | /** Resume the former interrupt vector */ |
77 | /** Resume the former interrupt vector */ |
79 | void ns16550_release(void) |
78 | void ns16550_release(void) |
80 | { |
79 | { |
81 | /* TODO */ |
80 | /* TODO */ |
82 | } |
81 | } |
83 | 82 | ||
84 | /** Initialize ns16550. */ |
83 | /** Initialize ns16550. */ |
85 | void ns16550_init(void) |
84 | void ns16550_init(void) |
86 | { |
85 | { |
87 | ns16550_grab(); |
86 | ns16550_grab(); |
88 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
87 | chardev_initialize("ns16550_kbd", &kbrd, &ops); |
89 | stdin = &kbrd; |
88 | stdin = &kbrd; |
90 | 89 | ||
91 | sysinfo_set_item_val("kbd", NULL, true); |
90 | sysinfo_set_item_val("kbd", NULL, true); |
92 | sysinfo_set_item_val("kbd.irq", NULL, 0); |
91 | sysinfo_set_item_val("kbd.irq", NULL, 0); |
93 | sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address); |
92 | sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address); |
94 | } |
93 | } |
95 | 94 | ||
96 | /** Process ns16550 interrupt. |
95 | /** Process ns16550 interrupt. |
97 | * |
96 | * |
98 | * @param n Interrupt vector. |
97 | * @param n Interrupt vector. |
99 | * @param istate Interrupted state. |
98 | * @param istate Interrupted state. |
100 | */ |
99 | */ |
101 | void ns16550_interrupt(int n, istate_t *istate) |
100 | void ns16550_interrupt(int n, istate_t *istate) |
102 | { |
101 | { |
103 | /* TODO */ |
102 | /* TODO */ |
104 | } |
103 | } |
105 | 104 | ||
106 | /** Wait until the controller reads its data. */ |
105 | /** Wait until the controller reads its data. */ |
107 | void ns16550_wait(void) |
106 | void ns16550_wait(void) |
108 | { |
107 | { |
109 | } |
108 | } |
110 | 109 | ||
111 | /* Called from getc(). */ |
110 | /* Called from getc(). */ |
112 | void ns16550_resume(chardev_t *d) |
111 | void ns16550_resume(chardev_t *d) |
113 | { |
112 | { |
114 | } |
113 | } |
115 | 114 | ||
116 | /* Called from getc(). */ |
115 | /* Called from getc(). */ |
117 | void ns16550_suspend(chardev_t *d) |
116 | void ns16550_suspend(chardev_t *d) |
118 | { |
117 | { |
119 | } |
118 | } |
120 | 119 | ||
121 | char key_read(chardev_t *d) |
120 | char ns16550_key_read(chardev_t *d) |
122 | { |
121 | { |
123 | char ch; |
122 | char ch; |
124 | 123 | ||
125 | while(!(ch = active_read_buff_read())) { |
124 | while(!(ch = active_read_buff_read())) { |
126 | uint8_t x; |
125 | uint8_t x; |
127 | while (!(ns16550_lsr_read() & LSR_DATA_READY)) |
126 | while (!(ns16550_lsr_read() & LSR_DATA_READY)) |
128 | ; |
127 | ; |
129 | x = ns16550_rbr_read(); |
128 | x = ns16550_rbr_read(); |
130 | if (x != IGNORE_CODE) { |
129 | if (x != IGNORE_CODE) { |
131 | if (x & KEY_RELEASE) |
130 | if (x & KEY_RELEASE) |
132 | key_released(x ^ KEY_RELEASE); |
131 | key_released(x ^ KEY_RELEASE); |
133 | else |
132 | else |
134 | active_read_key_pressed(x); |
133 | active_read_key_pressed(x); |
135 | } |
134 | } |
136 | } |
135 | } |
137 | return ch; |
136 | return ch; |
138 | } |
137 | } |
139 | 138 | ||
140 | /** Poll for key press and release events. |
139 | /** Poll for key press and release events. |
141 | * |
140 | * |
142 | * This function can be used to implement keyboard polling. |
141 | * This function can be used to implement keyboard polling. |
143 | */ |
142 | */ |
144 | void ns16550_poll(void) |
143 | void ns16550_poll(void) |
145 | { |
144 | { |
146 | uint8_t x; |
145 | uint8_t x; |
147 | 146 | ||
148 | while (((x = ns16550_lsr_read() & LSR_DATA_READY))) { |
147 | while (((x = ns16550_lsr_read() & LSR_DATA_READY))) { |
149 | x = ns16550_rbr_read(); |
148 | x = ns16550_rbr_read(); |
150 | if (x != IGNORE_CODE) { |
149 | if (x != IGNORE_CODE) { |
151 | if (x & KEY_RELEASE) |
150 | if (x & KEY_RELEASE) |
152 | key_released(x ^ KEY_RELEASE); |
151 | key_released(x ^ KEY_RELEASE); |
153 | else |
152 | else |
154 | key_pressed(x); |
153 | key_pressed(x); |
155 | } |
154 | } |
156 | } |
155 | } |
157 | } |
156 | } |
158 | 157 | ||
159 | /** @} |
158 | /** @} |
160 | */ |
159 | */ |
161 | 160 |