Changeset ec2c55a in mainline for kernel/genarch/src/kbd/z8530.c


Ignore:
Timestamp:
2006-08-11T09:35:01Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f9a56c0
Parents:
2d99709
Message:

Rework the z8530 driver so that it is based on z8530 specification rather
than on accidental and limited "compatibility" with i8042.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/kbd/z8530.c

    r2d99709 rec2c55a  
    3333 * @file
    3434 * @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 control
    38  * the z8530 at least in the polling mode.
    39  * As a result, this file may contain inaccurate
    40  * and z8530-irrelevant constants, code and comments.
    41  * Still it miraculously works.
    4235 */
    4336
     
    4740#include <genarch/kbd/scanc_sun.h>
    4841#include <arch/drivers/z8530.h>
     42#include <arch/drivers/kbd.h>
    4943#include <arch/interrupt.h>
    5044#include <cpu.h>
     
    5549#include <console/console.h>
    5650#include <interrupt.h>
    57 
    58 /* Keyboard commands. */
    59 #define KBD_ENABLE      0xf4
    60 #define KBD_DISABLE     0xf5
    61 #define KBD_ACK         0xfa
    62 
    63 /*
    64  * 60  Write 8042 Command Byte: next data byte written to port 60h is
    65  *     placed in 8042 command register. Format:
    66  *
    67  *    |7|6|5|4|3|2|1|0|8042 Command Byte
    68  *     | | | | | | | `---- 1=enable output register full interrupt
    69  *     | | | | | | `----- should be 0
    70  *     | | | | | `------ 1=set status register system, 0=clear
    71  *     | | | | `------- 1=override keyboard inhibit, 0=allow inhibit
    72  *     | | | `-------- disable keyboard I/O by driving clock line low
    73  *     | | `--------- disable auxiliary device, drives clock line low
    74  *     | `---------- IBM scancode translation 0=AT, 1=PC/XT
    75  *     `----------- reserved, should be 0
    76  */
    77 
    78 #define z8530_SET_COMMAND       0x60
    79 #define z8530_COMMAND           0x69
    80 
    81 #define z8530_BUFFER_FULL_MASK  0x01
    82 #define z8530_WAIT_MASK         0x02
    83 #define z8530_MOUSE_DATA        0x20
    8451
    8552/*
     
    9865};
    9966
    100 static void z8530_interrupt(int n, istate_t *istate);
    101 static void z8530_wait(void);
     67void z8530_interrupt(int n, istate_t *istate);
     68void z8530_wait(void);
    10269
    103 static iroutine oldvector;
    10470/** Initialize keyboard and service interrupts using kernel routine */
    10571void z8530_grab(void)
    10672{
    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();
    11373}
    11474/** Resume the former interrupt vector */
    11575void z8530_release(void)
    11676{
    117         if (oldvector)
    118                 exc_register(VECTOR_KBD, "user_interrupt", oldvector);
    11977}
     78
     79#include <print.h>
    12080
    12181/** Initialize z8530. */
    12282void z8530_init(void)
    12383{
    124         int i;
    125 
    126         z8530_grab();
    127         /* Prevent user from accidentaly releasing calling z8530_resume
    128          * and disabling keyboard
    129          */
    130         oldvector = NULL;
    131 
    132         trap_virtual_enable_irqs(1<<IRQ_KBD);
    13384        chardev_initialize("z8530_kbd", &kbrd, &ops);
    13485        stdin = &kbrd;
    13586
    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. */
    14394}
    14495
     
    150101void z8530_interrupt(int n, istate_t *istate)
    151102{
    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                 else
    164                         key_pressed(x);
    165         }
    166         trap_virtual_eoi();
    167103}
    168104
    169105/** Wait until the controller reads its data. */
    170106void z8530_wait(void) {
    171         while (z8530_status_read() & z8530_WAIT_MASK) {
    172                 /* wait */
    173         }
    174107}
    175108
     
    190123        while(!(ch = active_read_buff_read())) {
    191124                uint8_t x;
    192                 while (!(z8530_status_read() & z8530_BUFFER_FULL_MASK))
     125                while (!(z8530_read_a(RR0) & RR0_RCA))
    193126                        ;
    194                 x = z8530_data_read();
     127                x = z8530_read_a(RR8);
    195128                if (x != IGNORE_CODE) {
    196129                        if (x & KEY_RELEASE)
     
    211144        uint8_t x;
    212145
    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);
    215148                if (x != IGNORE_CODE) {
    216149                        if (x & KEY_RELEASE)
Note: See TracChangeset for help on using the changeset viewer.