Rev 1848 | Rev 1875 | 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> |
||
1849 | jermar | 41 | #include <arch/drivers/fhc.h> |
1842 | jermar | 42 | #include <arch/drivers/z8530.h> |
1 | jermar | 43 | #include <arch/interrupt.h> |
44 | #include <cpu.h> |
||
45 | #include <arch/asm.h> |
||
46 | #include <arch.h> |
||
508 | jermar | 47 | #include <typedefs.h> |
511 | jermar | 48 | #include <console/chardev.h> |
49 | #include <console/console.h> |
||
576 | palkovsky | 50 | #include <interrupt.h> |
1 | jermar | 51 | |
670 | vana | 52 | /* |
1842 | jermar | 53 | * These codes read from z8530 data register are silently ignored. |
895 | jermar | 54 | */ |
1842 | jermar | 55 | #define IGNORE_CODE 0x7f /* all keys up */ |
895 | jermar | 56 | |
1842 | jermar | 57 | static void z8530_suspend(chardev_t *); |
58 | static void z8530_resume(chardev_t *); |
||
511 | jermar | 59 | |
1843 | jermar | 60 | chardev_t kbrd; |
511 | jermar | 61 | static chardev_operations_t ops = { |
1842 | jermar | 62 | .suspend = z8530_suspend, |
63 | .resume = z8530_resume, |
||
878 | vana | 64 | .read = key_read |
511 | jermar | 65 | }; |
66 | |||
1848 | jermar | 67 | void z8530_wait(void); |
576 | palkovsky | 68 | |
1474 | palkovsky | 69 | /** Initialize keyboard and service interrupts using kernel routine */ |
1842 | jermar | 70 | void z8530_grab(void) |
1 | jermar | 71 | { |
1474 | palkovsky | 72 | } |
1849 | jermar | 73 | |
1474 | palkovsky | 74 | /** Resume the former interrupt vector */ |
1842 | jermar | 75 | void z8530_release(void) |
1474 | palkovsky | 76 | { |
77 | } |
||
670 | vana | 78 | |
1842 | jermar | 79 | /** Initialize z8530. */ |
80 | void z8530_init(void) |
||
1474 | palkovsky | 81 | { |
1842 | jermar | 82 | chardev_initialize("z8530_kbd", &kbrd, &ops); |
511 | jermar | 83 | stdin = &kbrd; |
1195 | jermar | 84 | |
1849 | jermar | 85 | (void) z8530_read_a(RR8); |
86 | |||
1848 | jermar | 87 | z8530_write_a(WR1, WR1_IARCSC); /* interrupt on all characters */ |
88 | |||
89 | /* 8 bits per character and enable receiver */ |
||
90 | z8530_write_a(WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); |
||
91 | |||
92 | z8530_write_a(WR9, WR9_MIE); /* Master Interrupt Enable. */ |
||
1849 | jermar | 93 | |
94 | /* |
||
95 | * We need to initialize the FireHose Controller, |
||
96 | * to which is this z8530 attached. Otherwise |
||
97 | * interrupts generated by the z8530 would not |
||
98 | * be forwarded to the CPU. |
||
99 | */ |
||
100 | fhc_init(); |
||
1 | jermar | 101 | } |
102 | |||
1842 | jermar | 103 | /** Process z8530 interrupt. |
508 | jermar | 104 | * |
105 | * @param n Interrupt vector. |
||
1708 | jermar | 106 | * @param istate Interrupted state. |
508 | jermar | 107 | */ |
1849 | jermar | 108 | void z8530_interrupt(void) |
1 | jermar | 109 | { |
1849 | jermar | 110 | z8530_poll(); |
1 | jermar | 111 | } |
508 | jermar | 112 | |
895 | jermar | 113 | /** Wait until the controller reads its data. */ |
1842 | jermar | 114 | void z8530_wait(void) { |
895 | jermar | 115 | } |
116 | |||
511 | jermar | 117 | /* Called from getc(). */ |
1842 | jermar | 118 | void z8530_resume(chardev_t *d) |
511 | jermar | 119 | { |
120 | } |
||
121 | |||
122 | /* Called from getc(). */ |
||
1842 | jermar | 123 | void z8530_suspend(chardev_t *d) |
511 | jermar | 124 | { |
125 | } |
||
878 | vana | 126 | |
1843 | jermar | 127 | char key_read(chardev_t *d) |
878 | vana | 128 | { |
129 | char ch; |
||
130 | |||
894 | jermar | 131 | while(!(ch = active_read_buff_read())) { |
1780 | jermar | 132 | uint8_t x; |
1848 | jermar | 133 | while (!(z8530_read_a(RR0) & RR0_RCA)) |
894 | jermar | 134 | ; |
1848 | jermar | 135 | x = z8530_read_a(RR8); |
895 | jermar | 136 | if (x != IGNORE_CODE) { |
137 | if (x & KEY_RELEASE) |
||
138 | key_released(x ^ KEY_RELEASE); |
||
139 | else |
||
140 | active_read_key_pressed(x); |
||
141 | } |
||
878 | vana | 142 | } |
143 | return ch; |
||
144 | } |
||
895 | jermar | 145 | |
146 | /** Poll for key press and release events. |
||
147 | * |
||
148 | * This function can be used to implement keyboard polling. |
||
149 | */ |
||
1842 | jermar | 150 | void z8530_poll(void) |
895 | jermar | 151 | { |
1780 | jermar | 152 | uint8_t x; |
895 | jermar | 153 | |
1848 | jermar | 154 | while (z8530_read_a(RR0) & RR0_RCA) { |
155 | x = z8530_read_a(RR8); |
||
895 | jermar | 156 | if (x != IGNORE_CODE) { |
157 | if (x & KEY_RELEASE) |
||
158 | key_released(x ^ KEY_RELEASE); |
||
159 | else |
||
160 | key_pressed(x); |
||
161 | } |
||
162 | } |
||
163 | } |
||
1702 | cejka | 164 | |
1754 | jermar | 165 | /** @} |
1702 | cejka | 166 | */ |