Rev 1923 | Rev 1931 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1923 | Rev 1925 | ||
---|---|---|---|
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 ipc_notif_cfg_t saved_notif_cfg; |
|
- | 66 | ||
65 | static void z8530_suspend(chardev_t *); |
67 | static void z8530_suspend(chardev_t *); |
66 | static void z8530_resume(chardev_t *); |
68 | static void z8530_resume(chardev_t *); |
67 | 69 | ||
68 | static chardev_operations_t ops = { |
70 | static chardev_operations_t ops = { |
69 | .suspend = z8530_suspend, |
71 | .suspend = z8530_suspend, |
70 | .resume = z8530_resume, |
72 | .resume = z8530_resume, |
71 | .read = z8530_key_read |
73 | .read = z8530_key_read |
72 | }; |
74 | }; |
73 | 75 | ||
74 | /** Initialize keyboard and service interrupts using kernel routine. */ |
76 | /** Initialize keyboard and service interrupts using kernel routine. */ |
75 | void z8530_grab(void) |
77 | void z8530_grab(void) |
76 | { |
78 | { |
- | 79 | (void) z8530_read_a(&z8530, RR8); |
|
- | 80 | ||
- | 81 | /* |
|
- | 82 | * Clear any pending TX interrupts or we never manage |
|
- | 83 | * to set FHC UART interrupt state to idle. |
|
- | 84 | */ |
|
- | 85 | z8530_write_a(&z8530, WR0, WR0_TX_IP_RST); |
|
- | 86 | ||
- | 87 | z8530_write_a(&z8530, WR1, WR1_IARCSC); /* interrupt on all characters */ |
|
- | 88 | ||
- | 89 | /* 8 bits per character and enable receiver */ |
|
- | 90 | z8530_write_a(&z8530, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
|
- | 91 | ||
- | 92 | z8530_write_a(&z8530, WR9, WR9_MIE); /* Master Interrupt Enable. */ |
|
- | 93 | ||
- | 94 | if (z8530_irq.notif_cfg.answerbox) { |
|
- | 95 | saved_notif_cfg = z8530_irq.notif_cfg; |
|
- | 96 | z8530_irq.notif_cfg.answerbox = NULL; |
|
- | 97 | z8530_irq.notif_cfg.code = NULL; |
|
- | 98 | z8530_irq.notif_cfg.method = 0; |
|
- | 99 | z8530_irq.notif_cfg.counter = 0; |
|
- | 100 | } |
|
77 | } |
101 | } |
78 | 102 | ||
79 | /** Resume the former IPC notification behavior. */ |
103 | /** Resume the former IPC notification behavior. */ |
80 | void z8530_release(void) |
104 | void z8530_release(void) |
81 | { |
105 | { |
- | 106 | if (saved_notif_cfg.answerbox) |
|
- | 107 | z8530_irq.notif_cfg = saved_notif_cfg; |
|
82 | } |
108 | } |
83 | 109 | ||
84 | /** Initialize z8530. */ |
110 | /** Initialize z8530. */ |
85 | void z8530_init(devno_t devno, inr_t inr, uintptr_t vaddr) |
111 | void z8530_init(devno_t devno, inr_t inr, uintptr_t vaddr) |
86 | { |
112 | { |
87 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
113 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
88 | stdin = &kbrd; |
114 | stdin = &kbrd; |
89 | 115 | ||
90 | z8530.devno = devno; |
116 | z8530.devno = devno; |
91 | z8530.reg = (uint8_t *) vaddr; |
117 | z8530.reg = (uint8_t *) vaddr; |
92 | 118 | ||
93 | irq_initialize(&z8530_irq); |
119 | irq_initialize(&z8530_irq); |
94 | z8530_irq.devno = devno; |
120 | z8530_irq.devno = devno; |
95 | z8530_irq.inr = inr; |
121 | z8530_irq.inr = inr; |
96 | z8530_irq.claim = z8530_claim; |
122 | z8530_irq.claim = z8530_claim; |
97 | z8530_irq.handler = z8530_irq_handler; |
123 | z8530_irq.handler = z8530_irq_handler; |
98 | irq_register(&z8530_irq); |
124 | irq_register(&z8530_irq); |
99 | 125 | ||
100 | sysinfo_set_item_val("kbd", NULL, true); |
126 | sysinfo_set_item_val("kbd", NULL, true); |
101 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
127 | sysinfo_set_item_val("kbd.devno", NULL, devno); |
102 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
128 | sysinfo_set_item_val("kbd.inr", NULL, inr); |
103 | sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr); |
129 | sysinfo_set_item_val("kbd.address.virtual", NULL, vaddr); |
104 | 130 | ||
105 | (void) z8530_read_a(&z8530, RR8); |
131 | z8530_grab(); |
106 | - | ||
107 | /* |
- | |
108 | * Clear any pending TX interrupts or we never manage |
- | |
109 | * to set FHC UART interrupt state to idle. |
- | |
110 | */ |
- | |
111 | z8530_write_a(&z8530, WR0, WR0_TX_IP_RST); |
- | |
112 | - | ||
113 | z8530_write_a(&z8530, WR1, WR1_IARCSC); /* interrupt on all characters */ |
- | |
114 | - | ||
115 | /* 8 bits per character and enable receiver */ |
- | |
116 | z8530_write_a(&z8530, WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
- | |
117 | - | ||
118 | z8530_write_a(&z8530, WR9, WR9_MIE); /* Master Interrupt Enable. */ |
- | |
119 | } |
132 | } |
120 | 133 | ||
121 | /** Process z8530 interrupt. |
134 | /** Process z8530 interrupt. |
122 | * |
135 | * |
123 | * @param n Interrupt vector. |
136 | * @param n Interrupt vector. |
124 | * @param istate Interrupted state. |
137 | * @param istate Interrupted state. |
125 | */ |
138 | */ |
126 | void z8530_interrupt(void) |
139 | void z8530_interrupt(void) |
127 | { |
140 | { |
128 | z8530_poll(); |
141 | z8530_poll(); |
129 | } |
142 | } |
130 | 143 | ||
131 | /* Called from getc(). */ |
144 | /* Called from getc(). */ |
132 | void z8530_resume(chardev_t *d) |
145 | void z8530_resume(chardev_t *d) |
133 | { |
146 | { |
134 | } |
147 | } |
135 | 148 | ||
136 | /* Called from getc(). */ |
149 | /* Called from getc(). */ |
137 | void z8530_suspend(chardev_t *d) |
150 | void z8530_suspend(chardev_t *d) |
138 | { |
151 | { |
139 | } |
152 | } |
140 | 153 | ||
141 | char z8530_key_read(chardev_t *d) |
154 | char z8530_key_read(chardev_t *d) |
142 | { |
155 | { |
143 | char ch; |
156 | char ch; |
144 | 157 | ||
145 | while(!(ch = active_read_buff_read())) { |
158 | while(!(ch = active_read_buff_read())) { |
146 | uint8_t x; |
159 | uint8_t x; |
147 | while (!(z8530_read_a(&z8530, RR0) & RR0_RCA)) |
160 | while (!(z8530_read_a(&z8530, RR0) & RR0_RCA)) |
148 | ; |
161 | ; |
149 | x = z8530_read_a(&z8530, RR8); |
162 | x = z8530_read_a(&z8530, RR8); |
150 | if (x != IGNORE_CODE) { |
163 | if (x != IGNORE_CODE) { |
151 | if (x & KEY_RELEASE) |
164 | if (x & KEY_RELEASE) |
152 | key_released(x ^ KEY_RELEASE); |
165 | key_released(x ^ KEY_RELEASE); |
153 | else |
166 | else |
154 | active_read_key_pressed(x); |
167 | active_read_key_pressed(x); |
155 | } |
168 | } |
156 | } |
169 | } |
157 | return ch; |
170 | return ch; |
158 | } |
171 | } |
159 | 172 | ||
160 | /** Poll for key press and release events. |
173 | /** Poll for key press and release events. |
161 | * |
174 | * |
162 | * This function can be used to implement keyboard polling. |
175 | * This function can be used to implement keyboard polling. |
163 | */ |
176 | */ |
164 | void z8530_poll(void) |
177 | void z8530_poll(void) |
165 | { |
178 | { |
166 | uint8_t x; |
179 | uint8_t x; |
167 | 180 | ||
168 | while (z8530_read_a(&z8530, RR0) & RR0_RCA) { |
181 | while (z8530_read_a(&z8530, RR0) & RR0_RCA) { |
169 | x = z8530_read_a(&z8530, RR8); |
182 | x = z8530_read_a(&z8530, RR8); |
170 | if (x != IGNORE_CODE) { |
183 | if (x != IGNORE_CODE) { |
171 | if (x & KEY_RELEASE) |
184 | if (x & KEY_RELEASE) |
172 | key_released(x ^ KEY_RELEASE); |
185 | key_released(x ^ KEY_RELEASE); |
173 | else |
186 | else |
174 | key_pressed(x); |
187 | key_pressed(x); |
175 | } |
188 | } |
176 | } |
189 | } |
177 | } |
190 | } |
178 | 191 | ||
179 | irq_ownership_t z8530_claim(void) |
192 | irq_ownership_t z8530_claim(void) |
180 | { |
193 | { |
181 | return (z8530_read_a(&z8530, RR0) & RR0_RCA); |
194 | return (z8530_read_a(&z8530, RR0) & RR0_RCA); |
182 | } |
195 | } |
183 | 196 | ||
184 | void z8530_irq_handler(irq_t *irq, void *arg, ...) |
197 | void z8530_irq_handler(irq_t *irq, void *arg, ...) |
185 | { |
198 | { |
186 | /* |
199 | /* |
187 | * So far, we know we got this interrupt through the FHC. |
200 | * So far, we know we got this interrupt through the FHC. |
188 | * Since we don't have enough documentation about the FHC |
201 | * Since we don't have enough documentation about the FHC |
189 | * and because the interrupt looks like level sensitive, |
202 | * and because the interrupt looks like level sensitive, |
190 | * we cannot handle it by scheduling one of the level |
203 | * we cannot handle it by scheduling one of the level |
191 | * interrupt traps. Process the interrupt directly. |
204 | * interrupt traps. Process the interrupt directly. |
192 | */ |
205 | */ |
193 | if (irq->notif_cfg.answerbox) |
206 | if (irq->notif_cfg.answerbox) |
194 | ipc_irq_send_notif(irq); |
207 | ipc_irq_send_notif(irq); |
195 | else |
208 | else |
196 | z8530_interrupt(); |
209 | z8530_interrupt(); |
197 | fhc_clear_interrupt(central_fhc, irq->inr); |
210 | fhc_clear_interrupt(central_fhc, irq->inr); |
198 | } |
211 | } |
199 | 212 | ||
200 | /** @} |
213 | /** @} |
201 | */ |
214 | */ |
202 | 215 |