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