Rev 1932 | Rev 2071 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1932 | Rev 1944 | ||
---|---|---|---|
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 Zilog 8530 serial port / keyboard driver. |
34 | * @brief Zilog 8530 serial port / keyboard driver. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <genarch/kbd/z8530.h> |
37 | #include <genarch/kbd/z8530.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/z8530.h> |
41 | #include <arch/drivers/z8530.h> |
42 | #include <ddi/irq.h> |
42 | #include <ddi/irq.h> |
43 | #include <ipc/irq.h> |
43 | #include <ipc/irq.h> |
44 | #include <arch/interrupt.h> |
44 | #include <arch/interrupt.h> |
45 | #include <arch/drivers/kbd.h> |
45 | #include <arch/drivers/kbd.h> |
46 | #include <arch/drivers/fhc.h> |
46 | #include <arch/drivers/fhc.h> |
47 | #include <cpu.h> |
47 | #include <cpu.h> |
48 | #include <arch/asm.h> |
48 | #include <arch/asm.h> |
49 | #include <arch.h> |
49 | #include <arch.h> |
50 | #include <typedefs.h> |
50 | #include <typedefs.h> |
51 | #include <console/chardev.h> |
51 | #include <console/chardev.h> |
52 | #include <console/console.h> |
52 | #include <console/console.h> |
53 | #include <interrupt.h> |
53 | #include <interrupt.h> |
54 | #include <sysinfo/sysinfo.h> |
54 | #include <sysinfo/sysinfo.h> |
55 | #include <print.h> |
55 | #include <print.h> |
56 | 56 | ||
57 | /* |
57 | /* |
58 | * These codes read from z8530 data register are silently ignored. |
58 | * These codes read from z8530 data register are silently ignored. |
59 | */ |
59 | */ |
60 | #define IGNORE_CODE 0x7f /* all keys up */ |
60 | #define IGNORE_CODE 0x7f /* all keys up */ |
61 | 61 | ||
62 | static z8530_t z8530; /**< z8530 device structure. */ |
62 | static z8530_t z8530; /**< z8530 device structure. */ |
63 | static irq_t z8530_irq; /**< z8530's IRQ. */ |
63 | static irq_t z8530_irq; /**< z8530's IRQ. */ |
64 | 64 | ||
65 | static void z8530_suspend(chardev_t *); |
65 | static void z8530_suspend(chardev_t *); |
66 | static void z8530_resume(chardev_t *); |
66 | static void z8530_resume(chardev_t *); |
67 | 67 | ||
68 | static chardev_operations_t ops = { |
68 | static chardev_operations_t ops = { |
69 | .suspend = z8530_suspend, |
69 | .suspend = z8530_suspend, |
70 | .resume = z8530_resume, |
70 | .resume = z8530_resume, |
71 | .read = z8530_key_read |
71 | .read = z8530_key_read |
72 | }; |
72 | }; |
73 | 73 | ||
74 | /** Initialize keyboard and service interrupts using kernel routine. */ |
74 | /** Initialize keyboard and service interrupts using kernel routine. */ |
75 | void z8530_grab(void) |
75 | void z8530_grab(void) |
76 | { |
76 | { |
- | 77 | ipl_t ipl = interrupts_disable(); |
|
- | 78 | ||
77 | (void) z8530_read_a(&z8530, RR8); |
79 | (void) z8530_read_a(&z8530, RR8); |
78 | 80 | ||
79 | /* |
81 | /* |
80 | * Clear any pending TX interrupts or we never manage |
82 | * Clear any pending TX interrupts or we never manage |
81 | * to set FHC UART interrupt state to idle. |
83 | * to set FHC UART interrupt state to idle. |
82 | */ |
84 | */ |
83 | z8530_write_a(&z8530, WR0, WR0_TX_IP_RST); |
85 | z8530_write_a(&z8530, WR0, WR0_TX_IP_RST); |
84 | 86 | ||
85 | z8530_write_a(&z8530, WR1, WR1_IARCSC); /* interrupt on all characters */ |
87 | z8530_write_a(&z8530, WR1, WR1_IARCSC); /* interrupt on all characters */ |
86 | 88 | ||
87 | /* 8 bits per character and enable receiver */ |
89 | /* 8 bits per character and enable receiver */ |
88 | z8530_write_a(&z8530, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
90 | z8530_write_a(&z8530, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
89 | 91 | ||
90 | z8530_write_a(&z8530, WR9, WR9_MIE); /* Master Interrupt Enable. */ |
92 | z8530_write_a(&z8530, WR9, WR9_MIE); /* Master Interrupt Enable. */ |
91 | 93 | ||
- | 94 | spinlock_lock(&z8530_irq.lock); |
|
92 | z8530_irq.notif_cfg.notify = false; |
95 | z8530_irq.notif_cfg.notify = false; |
- | 96 | spinlock_unlock(&z8530_irq.lock); |
|
- | 97 | interrupts_restore(ipl); |
|
93 | } |
98 | } |
94 | 99 | ||
95 | /** Resume the former IPC notification behavior. */ |
100 | /** Resume the former IPC notification behavior. */ |
96 | void z8530_release(void) |
101 | void z8530_release(void) |
97 | { |
102 | { |
- | 103 | ipl_t ipl = interrupts_disable(); |
|
- | 104 | spinlock_lock(&z8530_irq.lock); |
|
98 | if (z8530_irq.notif_cfg.answerbox) |
105 | if (z8530_irq.notif_cfg.answerbox) |
99 | z8530_irq.notif_cfg.notify = true; |
106 | z8530_irq.notif_cfg.notify = true; |
- | 107 | spinlock_unlock(&z8530_irq.lock); |
|
- | 108 | interrupts_restore(ipl); |
|
100 | } |
109 | } |
101 | 110 | ||
102 | /** Initialize z8530. */ |
111 | /** Initialize z8530. */ |
103 | void z8530_init(devno_t devno, inr_t inr, uintptr_t vaddr) |
112 | void z8530_init(devno_t devno, inr_t inr, uintptr_t vaddr) |
104 | { |
113 | { |
105 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
114 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
106 | stdin = &kbrd; |
115 | stdin = &kbrd; |
107 | 116 | ||
108 | z8530.devno = devno; |
117 | z8530.devno = devno; |
109 | z8530.reg = (uint8_t *) vaddr; |
118 | z8530.reg = (uint8_t *) vaddr; |
110 | 119 | ||
111 | irq_initialize(&z8530_irq); |
120 | irq_initialize(&z8530_irq); |
112 | z8530_irq.devno = devno; |
121 | z8530_irq.devno = devno; |
113 | z8530_irq.inr = inr; |
122 | z8530_irq.inr = inr; |
114 | z8530_irq.claim = z8530_claim; |
123 | z8530_irq.claim = z8530_claim; |
115 | z8530_irq.handler = z8530_irq_handler; |
124 | z8530_irq.handler = z8530_irq_handler; |
116 | irq_register(&z8530_irq); |
125 | irq_register(&z8530_irq); |
117 | 126 | ||
118 | sysinfo_set_item_val("kbd", NULL, true); |
127 | sysinfo_set_item_val("kbd", NULL, true); |
119 | sysinfo_set_item_val("kbd.type", NULL, KBD_Z8530); |
128 | sysinfo_set_item_val("kbd.type", NULL, KBD_Z8530); |
120 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
129 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
121 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
130 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
122 | sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr); |
131 | sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr); |
123 | 132 | ||
124 | z8530_grab(); |
133 | z8530_grab(); |
125 | } |
134 | } |
126 | 135 | ||
127 | /** Process z8530 interrupt. |
136 | /** Process z8530 interrupt. |
128 | * |
137 | * |
129 | * @param n Interrupt vector. |
138 | * @param n Interrupt vector. |
130 | * @param istate Interrupted state. |
139 | * @param istate Interrupted state. |
131 | */ |
140 | */ |
132 | void z8530_interrupt(void) |
141 | void z8530_interrupt(void) |
133 | { |
142 | { |
134 | z8530_poll(); |
143 | z8530_poll(); |
135 | } |
144 | } |
136 | 145 | ||
137 | /* Called from getc(). */ |
146 | /* Called from getc(). */ |
138 | void z8530_resume(chardev_t *d) |
147 | void z8530_resume(chardev_t *d) |
139 | { |
148 | { |
140 | } |
149 | } |
141 | 150 | ||
142 | /* Called from getc(). */ |
151 | /* Called from getc(). */ |
143 | void z8530_suspend(chardev_t *d) |
152 | void z8530_suspend(chardev_t *d) |
144 | { |
153 | { |
145 | } |
154 | } |
146 | 155 | ||
147 | char z8530_key_read(chardev_t *d) |
156 | char z8530_key_read(chardev_t *d) |
148 | { |
157 | { |
149 | char ch; |
158 | char ch; |
150 | 159 | ||
151 | while(!(ch = active_read_buff_read())) { |
160 | while(!(ch = active_read_buff_read())) { |
152 | uint8_t x; |
161 | uint8_t x; |
153 | while (!(z8530_read_a(&z8530, RR0) & RR0_RCA)) |
162 | while (!(z8530_read_a(&z8530, RR0) & RR0_RCA)) |
154 | ; |
163 | ; |
155 | x = z8530_read_a(&z8530, RR8); |
164 | x = z8530_read_a(&z8530, RR8); |
156 | if (x != IGNORE_CODE) { |
165 | if (x != IGNORE_CODE) { |
157 | if (x & KEY_RELEASE) |
166 | if (x & KEY_RELEASE) |
158 | key_released(x ^ KEY_RELEASE); |
167 | key_released(x ^ KEY_RELEASE); |
159 | else |
168 | else |
160 | active_read_key_pressed(x); |
169 | active_read_key_pressed(x); |
161 | } |
170 | } |
162 | } |
171 | } |
163 | return ch; |
172 | return ch; |
164 | } |
173 | } |
165 | 174 | ||
166 | /** Poll for key press and release events. |
175 | /** Poll for key press and release events. |
167 | * |
176 | * |
168 | * This function can be used to implement keyboard polling. |
177 | * This function can be used to implement keyboard polling. |
169 | */ |
178 | */ |
170 | void z8530_poll(void) |
179 | void z8530_poll(void) |
171 | { |
180 | { |
172 | uint8_t x; |
181 | uint8_t x; |
173 | 182 | ||
174 | while (z8530_read_a(&z8530, RR0) & RR0_RCA) { |
183 | while (z8530_read_a(&z8530, RR0) & RR0_RCA) { |
175 | x = z8530_read_a(&z8530, RR8); |
184 | x = z8530_read_a(&z8530, RR8); |
176 | if (x != IGNORE_CODE) { |
185 | if (x != IGNORE_CODE) { |
177 | if (x & KEY_RELEASE) |
186 | if (x & KEY_RELEASE) |
178 | key_released(x ^ KEY_RELEASE); |
187 | key_released(x ^ KEY_RELEASE); |
179 | else |
188 | else |
180 | key_pressed(x); |
189 | key_pressed(x); |
181 | } |
190 | } |
182 | } |
191 | } |
183 | } |
192 | } |
184 | 193 | ||
185 | irq_ownership_t z8530_claim(void) |
194 | irq_ownership_t z8530_claim(void) |
186 | { |
195 | { |
187 | return (z8530_read_a(&z8530, RR0) & RR0_RCA); |
196 | return (z8530_read_a(&z8530, RR0) & RR0_RCA); |
188 | } |
197 | } |
189 | 198 | ||
190 | void z8530_irq_handler(irq_t *irq, void *arg, ...) |
199 | void z8530_irq_handler(irq_t *irq, void *arg, ...) |
191 | { |
200 | { |
192 | /* |
201 | /* |
193 | * So far, we know we got this interrupt through the FHC. |
202 | * So far, we know we got this interrupt through the FHC. |
194 | * Since we don't have enough documentation about the FHC |
203 | * Since we don't have enough documentation about the FHC |
195 | * and because the interrupt looks like level sensitive, |
204 | * and because the interrupt looks like level sensitive, |
196 | * we cannot handle it by scheduling one of the level |
205 | * we cannot handle it by scheduling one of the level |
197 | * interrupt traps. Process the interrupt directly. |
206 | * interrupt traps. Process the interrupt directly. |
198 | */ |
207 | */ |
199 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
208 | if (irq->notif_cfg.notify && irq->notif_cfg.answerbox) |
200 | ipc_irq_send_notif(irq); |
209 | ipc_irq_send_notif(irq); |
201 | else |
210 | else |
202 | z8530_interrupt(); |
211 | z8530_interrupt(); |
203 | fhc_clear_interrupt(central_fhc, irq->inr); |
212 | fhc_clear_interrupt(central_fhc, irq->inr); |
204 | } |
213 | } |
205 | 214 | ||
206 | /** @} |
215 | /** @} |
207 | */ |
216 | */ |
208 | 217 |