Rev 1919 | Rev 1921 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1754 | jermar | 29 | /** @addtogroup genarch |
1702 | cejka | 30 | * @{ |
31 | */ |
||
1754 | jermar | 32 | /** |
1757 | jermar | 33 | * @file |
1842 | jermar | 34 | * @brief Zilog 8530 serial port / keyboard driver. |
1702 | cejka | 35 | */ |
36 | |||
1842 | jermar | 37 | #include <genarch/kbd/z8530.h> |
1843 | jermar | 38 | #include <genarch/kbd/key.h> |
1842 | jermar | 39 | #include <genarch/kbd/scanc.h> |
40 | #include <genarch/kbd/scanc_sun.h> |
||
41 | #include <arch/drivers/z8530.h> |
||
1920 | jermar | 42 | #include <ddi/irq.h> |
1 | jermar | 43 | #include <arch/interrupt.h> |
1875 | jermar | 44 | #include <arch/drivers/kbd.h> |
1919 | jermar | 45 | #include <arch/drivers/fhc.h> |
1 | jermar | 46 | #include <cpu.h> |
47 | #include <arch/asm.h> |
||
48 | #include <arch.h> |
||
508 | jermar | 49 | #include <typedefs.h> |
511 | jermar | 50 | #include <console/chardev.h> |
51 | #include <console/console.h> |
||
576 | palkovsky | 52 | #include <interrupt.h> |
1875 | jermar | 53 | #include <sysinfo/sysinfo.h> |
54 | #include <print.h> |
||
1 | jermar | 55 | |
670 | vana | 56 | /* |
1842 | jermar | 57 | * These codes read from z8530 data register are silently ignored. |
895 | jermar | 58 | */ |
1842 | jermar | 59 | #define IGNORE_CODE 0x7f /* all keys up */ |
895 | jermar | 60 | |
1875 | jermar | 61 | bool z8530_belongs_to_kernel = true; |
62 | |||
1842 | jermar | 63 | static void z8530_suspend(chardev_t *); |
64 | static void z8530_resume(chardev_t *); |
||
511 | jermar | 65 | |
66 | static chardev_operations_t ops = { |
||
1842 | jermar | 67 | .suspend = z8530_suspend, |
68 | .resume = z8530_resume, |
||
1896 | jermar | 69 | .read = z8530_key_read |
511 | jermar | 70 | }; |
71 | |||
1848 | jermar | 72 | void z8530_wait(void); |
576 | palkovsky | 73 | |
1474 | palkovsky | 74 | /** Initialize keyboard and service interrupts using kernel routine */ |
1842 | jermar | 75 | void z8530_grab(void) |
1 | jermar | 76 | { |
1875 | jermar | 77 | z8530_belongs_to_kernel = true; |
1474 | palkovsky | 78 | } |
1849 | jermar | 79 | |
1474 | palkovsky | 80 | /** Resume the former interrupt vector */ |
1842 | jermar | 81 | void z8530_release(void) |
1474 | palkovsky | 82 | { |
1875 | jermar | 83 | z8530_belongs_to_kernel = false; |
1474 | palkovsky | 84 | } |
670 | vana | 85 | |
1842 | jermar | 86 | /** Initialize z8530. */ |
87 | void z8530_init(void) |
||
1474 | palkovsky | 88 | { |
1842 | jermar | 89 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
511 | jermar | 90 | stdin = &kbrd; |
1195 | jermar | 91 | |
1875 | jermar | 92 | sysinfo_set_item_val("kbd", NULL, true); |
93 | sysinfo_set_item_val("kbd.irq", NULL, 0); |
||
94 | sysinfo_set_item_val("kbd.address.virtual", NULL, (uintptr_t) kbd_virt_address); |
||
95 | |||
1849 | jermar | 96 | (void) z8530_read_a(RR8); |
97 | |||
1875 | jermar | 98 | /* |
99 | * Clear any pending TX interrupts or we never manage |
||
100 | * to set FHC UART interrupt state to idle. |
||
101 | */ |
||
102 | z8530_write_a(WR0, WR0_TX_IP_RST); |
||
1848 | jermar | 103 | |
1875 | jermar | 104 | z8530_write_a(WR1, WR1_IARCSC); /* interrupt on all characters */ |
105 | |||
1848 | jermar | 106 | /* 8 bits per character and enable receiver */ |
107 | z8530_write_a(WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
||
108 | |||
1875 | jermar | 109 | z8530_write_a(WR9, WR9_MIE); /* Master Interrupt Enable. */ |
1 | jermar | 110 | } |
111 | |||
1842 | jermar | 112 | /** Process z8530 interrupt. |
508 | jermar | 113 | * |
114 | * @param n Interrupt vector. |
||
1708 | jermar | 115 | * @param istate Interrupted state. |
508 | jermar | 116 | */ |
1849 | jermar | 117 | void z8530_interrupt(void) |
1 | jermar | 118 | { |
1849 | jermar | 119 | z8530_poll(); |
1 | jermar | 120 | } |
508 | jermar | 121 | |
895 | jermar | 122 | /** Wait until the controller reads its data. */ |
1842 | jermar | 123 | void z8530_wait(void) { |
895 | jermar | 124 | } |
125 | |||
511 | jermar | 126 | /* Called from getc(). */ |
1842 | jermar | 127 | void z8530_resume(chardev_t *d) |
511 | jermar | 128 | { |
129 | } |
||
130 | |||
131 | /* Called from getc(). */ |
||
1842 | jermar | 132 | void z8530_suspend(chardev_t *d) |
511 | jermar | 133 | { |
134 | } |
||
878 | vana | 135 | |
1896 | jermar | 136 | char z8530_key_read(chardev_t *d) |
878 | vana | 137 | { |
138 | char ch; |
||
139 | |||
894 | jermar | 140 | while(!(ch = active_read_buff_read())) { |
1780 | jermar | 141 | uint8_t x; |
1848 | jermar | 142 | while (!(z8530_read_a(RR0) & RR0_RCA)) |
894 | jermar | 143 | ; |
1848 | jermar | 144 | x = z8530_read_a(RR8); |
895 | jermar | 145 | if (x != IGNORE_CODE) { |
146 | if (x & KEY_RELEASE) |
||
147 | key_released(x ^ KEY_RELEASE); |
||
148 | else |
||
149 | active_read_key_pressed(x); |
||
150 | } |
||
878 | vana | 151 | } |
152 | return ch; |
||
153 | } |
||
895 | jermar | 154 | |
155 | /** Poll for key press and release events. |
||
156 | * |
||
157 | * This function can be used to implement keyboard polling. |
||
158 | */ |
||
1842 | jermar | 159 | void z8530_poll(void) |
895 | jermar | 160 | { |
1780 | jermar | 161 | uint8_t x; |
895 | jermar | 162 | |
1848 | jermar | 163 | while (z8530_read_a(RR0) & RR0_RCA) { |
164 | x = z8530_read_a(RR8); |
||
895 | jermar | 165 | if (x != IGNORE_CODE) { |
166 | if (x & KEY_RELEASE) |
||
167 | key_released(x ^ KEY_RELEASE); |
||
168 | else |
||
169 | key_pressed(x); |
||
170 | } |
||
171 | } |
||
172 | } |
||
1702 | cejka | 173 | |
1919 | jermar | 174 | irq_ownership_t z8530_claim(void) |
175 | { |
||
176 | return (z8530_read_a(RR0) & RR0_RCA); |
||
177 | } |
||
178 | |||
179 | void z8530_irq_handler(irq_t *irq, void *arg, ...) |
||
180 | { |
||
181 | /* |
||
182 | * So far, we know we got this interrupt through the FHC. |
||
183 | * Since we don't have enough information about the FHC and |
||
184 | * because the interrupt looks like level sensitive, |
||
185 | * we cannot handle it by scheduling one of the level |
||
186 | * interrupt traps. Process the interrupt directly. |
||
187 | */ |
||
188 | if (z8530_belongs_to_kernel) |
||
189 | z8530_interrupt(); |
||
190 | else |
||
191 | ipc_irq_send_notif(0); |
||
192 | fhc_clear_interrupt(central_fhc, irq->inr); |
||
193 | } |
||
194 | |||
1754 | jermar | 195 | /** @} |
1702 | cejka | 196 | */ |