Changeset ec2c55a in mainline for kernel/genarch/src/kbd/z8530.c
- Timestamp:
- 2006-08-11T09:35:01Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f9a56c0
- Parents:
- 2d99709
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/kbd/z8530.c
r2d99709 rec2c55a 33 33 * @file 34 34 * @brief Zilog 8530 serial port / keyboard driver. 35 *36 * Note that this file is derived from the i8042.c.37 * The i8042 driver could be persuaded to control38 * the z8530 at least in the polling mode.39 * As a result, this file may contain inaccurate40 * and z8530-irrelevant constants, code and comments.41 * Still it miraculously works.42 35 */ 43 36 … … 47 40 #include <genarch/kbd/scanc_sun.h> 48 41 #include <arch/drivers/z8530.h> 42 #include <arch/drivers/kbd.h> 49 43 #include <arch/interrupt.h> 50 44 #include <cpu.h> … … 55 49 #include <console/console.h> 56 50 #include <interrupt.h> 57 58 /* Keyboard commands. */59 #define KBD_ENABLE 0xf460 #define KBD_DISABLE 0xf561 #define KBD_ACK 0xfa62 63 /*64 * 60 Write 8042 Command Byte: next data byte written to port 60h is65 * placed in 8042 command register. Format:66 *67 * |7|6|5|4|3|2|1|0|8042 Command Byte68 * | | | | | | | `---- 1=enable output register full interrupt69 * | | | | | | `----- should be 070 * | | | | | `------ 1=set status register system, 0=clear71 * | | | | `------- 1=override keyboard inhibit, 0=allow inhibit72 * | | | `-------- disable keyboard I/O by driving clock line low73 * | | `--------- disable auxiliary device, drives clock line low74 * | `---------- IBM scancode translation 0=AT, 1=PC/XT75 * `----------- reserved, should be 076 */77 78 #define z8530_SET_COMMAND 0x6079 #define z8530_COMMAND 0x6980 81 #define z8530_BUFFER_FULL_MASK 0x0182 #define z8530_WAIT_MASK 0x0283 #define z8530_MOUSE_DATA 0x2084 51 85 52 /* … … 98 65 }; 99 66 100 staticvoid z8530_interrupt(int n, istate_t *istate);101 staticvoid z8530_wait(void);67 void z8530_interrupt(int n, istate_t *istate); 68 void z8530_wait(void); 102 69 103 static iroutine oldvector;104 70 /** Initialize keyboard and service interrupts using kernel routine */ 105 71 void z8530_grab(void) 106 72 { 107 oldvector = exc_register(VECTOR_KBD, "z8530_interrupt", (iroutine) z8530_interrupt);108 z8530_wait();109 z8530_command_write(z8530_SET_COMMAND);110 z8530_wait();111 z8530_data_write(z8530_COMMAND);112 z8530_wait();113 73 } 114 74 /** Resume the former interrupt vector */ 115 75 void z8530_release(void) 116 76 { 117 if (oldvector)118 exc_register(VECTOR_KBD, "user_interrupt", oldvector);119 77 } 78 79 #include <print.h> 120 80 121 81 /** Initialize z8530. */ 122 82 void z8530_init(void) 123 83 { 124 int i;125 126 z8530_grab();127 /* Prevent user from accidentaly releasing calling z8530_resume128 * and disabling keyboard129 */130 oldvector = NULL;131 132 trap_virtual_enable_irqs(1<<IRQ_KBD);133 84 chardev_initialize("z8530_kbd", &kbrd, &ops); 134 85 stdin = &kbrd; 135 86 136 /*137 * Clear input buffer.138 * Number of iterations is limited to prevent infinite looping. 139 */140 for (i = 0; (z8530_status_read() & z8530_BUFFER_FULL_MASK) && i < 100; i++) {141 z8530_data_read();142 }87 z8530_write_a(WR1, WR1_IARCSC); /* interrupt on all characters */ 88 z8530_write_a(WR2, 12); /* FIXME: IRQ12 ??? */ 89 90 /* 8 bits per character and enable receiver */ 91 z8530_write_a(WR3, WR3_RX8BITSCH | WR3_RX_ENABLE); 92 93 z8530_write_a(WR9, WR9_MIE); /* Master Interrupt Enable. */ 143 94 } 144 95 … … 150 101 void z8530_interrupt(int n, istate_t *istate) 151 102 { 152 uint8_t x;153 uint8_t status;154 155 while (((status=z8530_status_read()) & z8530_BUFFER_FULL_MASK)) {156 x = z8530_data_read();157 158 if ((status & z8530_MOUSE_DATA))159 continue;160 161 if (x & KEY_RELEASE)162 key_released(x ^ KEY_RELEASE);163 else164 key_pressed(x);165 }166 trap_virtual_eoi();167 103 } 168 104 169 105 /** Wait until the controller reads its data. */ 170 106 void z8530_wait(void) { 171 while (z8530_status_read() & z8530_WAIT_MASK) {172 /* wait */173 }174 107 } 175 108 … … 190 123 while(!(ch = active_read_buff_read())) { 191 124 uint8_t x; 192 while (!(z8530_ status_read() & z8530_BUFFER_FULL_MASK))125 while (!(z8530_read_a(RR0) & RR0_RCA)) 193 126 ; 194 x = z8530_ data_read();127 x = z8530_read_a(RR8); 195 128 if (x != IGNORE_CODE) { 196 129 if (x & KEY_RELEASE) … … 211 144 uint8_t x; 212 145 213 while ( ((x = z8530_status_read() & z8530_BUFFER_FULL_MASK))) {214 x = z8530_ data_read();146 while (z8530_read_a(RR0) & RR0_RCA) { 147 x = z8530_read_a(RR8); 215 148 if (x != IGNORE_CODE) { 216 149 if (x & KEY_RELEASE)
Note:
See TracChangeset
for help on using the changeset viewer.