Home | History | Annotate | Line # | Download | only in dev
kbd.c revision 1.1
      1  1.1  mw /*
      2  1.1  mw  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
      3  1.1  mw  * All rights reserved.
      4  1.1  mw  *
      5  1.1  mw  * Redistribution and use in source and binary forms, with or without
      6  1.1  mw  * modification, are permitted provided that the following conditions
      7  1.1  mw  * are met:
      8  1.1  mw  * 1. Redistributions of source code must retain the above copyright
      9  1.1  mw  *    notice, this list of conditions and the following disclaimer.
     10  1.1  mw  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  mw  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  mw  *    documentation and/or other materials provided with the distribution.
     13  1.1  mw  * 3. All advertising materials mentioning features or use of this software
     14  1.1  mw  *    must display the following acknowledgement:
     15  1.1  mw  *	This product includes software developed by the University of
     16  1.1  mw  *	California, Berkeley and its contributors.
     17  1.1  mw  * 4. Neither the name of the University nor the names of its contributors
     18  1.1  mw  *    may be used to endorse or promote products derived from this software
     19  1.1  mw  *    without specific prior written permission.
     20  1.1  mw  *
     21  1.1  mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1  mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  mw  * SUCH DAMAGE.
     32  1.1  mw  *
     33  1.1  mw  *	kbd.c
     34  1.1  mw  */
     35  1.1  mw 
     36  1.1  mw #include "ite.h"
     37  1.1  mw 
     38  1.1  mw #if NITE > 0
     39  1.1  mw #include "sys/param.h"
     40  1.1  mw #include "sys/systm.h"
     41  1.1  mw #include "sys/ioctl.h"
     42  1.1  mw #include "sys/tty.h"
     43  1.1  mw #include "sys/proc.h"
     44  1.1  mw #include "sys/conf.h"
     45  1.1  mw #include "sys/file.h"
     46  1.1  mw #include "sys/uio.h"
     47  1.1  mw #include "sys/kernel.h"
     48  1.1  mw #include "sys/syslog.h"
     49  1.1  mw 
     50  1.1  mw #include "device.h"
     51  1.1  mw #include "kbdreg.h"
     52  1.1  mw #include "itevar.h"
     53  1.1  mw #include "machine/cpu.h"
     54  1.1  mw 
     55  1.1  mw #include "../amiga/custom.h"
     56  1.1  mw #include "../amiga/cia.h"
     57  1.1  mw 
     58  1.1  mw void
     59  1.1  mw kbdenable ()
     60  1.1  mw {
     61  1.1  mw   int s = spltty();
     62  1.1  mw 
     63  1.1  mw   /* collides with external ints from SCSI, watch out for this when
     64  1.1  mw      enabling/disabling interrupts there !! */
     65  1.1  mw   custom.intena = INTF_SETCLR | INTF_PORTS;
     66  1.1  mw   ciaa.icr = (1<<7) | (1<<3);	/* SP interrupt enable */
     67  1.1  mw   ciaa.cra &= ~(1<<6);		/* serial line == input */
     68  1.1  mw 
     69  1.1  mw   splx (s);
     70  1.1  mw }
     71  1.1  mw 
     72  1.1  mw 
     73  1.1  mw int
     74  1.1  mw kbdintr ()
     75  1.1  mw {
     76  1.1  mw   /* THIS CLEARS ALL INTERRUPTS FROM CIAA! Will need a special cia
     77  1.1  mw      interrupt handler to be able to use the ciaa timers besides driving
     78  1.1  mw      the keyboard !! */
     79  1.1  mw   u_char ints = ciaa.icr;
     80  1.1  mw   u_char c, in;
     81  1.1  mw 
     82  1.1  mw   if (! (ints & (1<<3)))
     83  1.1  mw     return 0;
     84  1.1  mw 
     85  1.1  mw   in = ciaa.sdr;
     86  1.1  mw   /* ack */
     87  1.1  mw   ciaa.cra |= (1 << 6);	/* serial line output */
     88  1.1  mw   /* wait 85 microseconds */
     89  1.1  mw   DELAY(85);
     90  1.1  mw   ciaa.cra &= ~(1 << 6);
     91  1.1  mw 
     92  1.1  mw   c = ~in;	/* keyboard data is inverted */
     93  1.1  mw 
     94  1.1  mw   /* process the character.
     95  1.1  mw 
     96  1.1  mw      Should implement RAW mode for X11 later here !! */
     97  1.1  mw   c = (c >> 1) | (c << 7);	/* rotate right once */
     98  1.1  mw 
     99  1.1  mw   itefilter (c, ITEFILT_TTY);
    100  1.1  mw }
    101  1.1  mw 
    102  1.1  mw 
    103  1.1  mw int
    104  1.1  mw kbdbell()
    105  1.1  mw {
    106  1.1  mw 
    107  1.1  mw  /* not yet.. */
    108  1.1  mw 
    109  1.1  mw }
    110  1.1  mw 
    111  1.1  mw 
    112  1.1  mw int
    113  1.1  mw kbdgetcn ()
    114  1.1  mw {
    115  1.1  mw   int s = spltty ();
    116  1.1  mw   u_char ints, c, in;
    117  1.1  mw 
    118  1.1  mw   /* this is very very nasty... */
    119  1.1  mw   while (! (ciaa.icr & (1<<3))) ;
    120  1.1  mw 
    121  1.1  mw   in = ciaa.sdr;
    122  1.1  mw   c = ~in;
    123  1.1  mw 
    124  1.1  mw   /* ack */
    125  1.1  mw   ciaa.cra |= (1 << 6);	/* serial line output */
    126  1.1  mw   ciaa.sdr = 0xff;		/* ack */
    127  1.1  mw   /* wait 85 microseconds */
    128  1.1  mw   DELAY(85);    /* XXXX only works as long as DELAY doesn't use a timer and waits.. */
    129  1.1  mw   ciaa.cra &= ~(1 << 6);
    130  1.1  mw   ciaa.sdr = in;
    131  1.1  mw 
    132  1.1  mw   splx (s);
    133  1.1  mw   c = (c >> 1) | (c << 7);
    134  1.1  mw   return c;
    135  1.1  mw }
    136  1.1  mw 
    137  1.1  mw #endif
    138