1*6d3ceb1dSskrll /* $NetBSD: itecons.c,v 1.1 2014/02/24 07:23:43 skrll Exp $ */
2*6d3ceb1dSskrll
3*6d3ceb1dSskrll /* $OpenBSD: itecons.c,v 1.6 1999/04/20 20:01:02 mickey Exp $ */
4*6d3ceb1dSskrll
5*6d3ceb1dSskrll /*
6*6d3ceb1dSskrll * Copyright (c) 1998-2004 Michael Shalayeff
7*6d3ceb1dSskrll * All rights reserved.
8*6d3ceb1dSskrll *
9*6d3ceb1dSskrll * Redistribution and use in source and binary forms, with or without
10*6d3ceb1dSskrll * modification, are permitted provided that the following conditions
11*6d3ceb1dSskrll * are met:
12*6d3ceb1dSskrll * 1. Redistributions of source code must retain the above copyright
13*6d3ceb1dSskrll * notice, this list of conditions and the following disclaimer.
14*6d3ceb1dSskrll * 2. Redistributions in binary form must reproduce the above copyright
15*6d3ceb1dSskrll * notice, this list of conditions and the following disclaimer in the
16*6d3ceb1dSskrll * documentation and/or other materials provided with the distribution.
17*6d3ceb1dSskrll *
18*6d3ceb1dSskrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*6d3ceb1dSskrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*6d3ceb1dSskrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*6d3ceb1dSskrll * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22*6d3ceb1dSskrll * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23*6d3ceb1dSskrll * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24*6d3ceb1dSskrll * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*6d3ceb1dSskrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26*6d3ceb1dSskrll * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27*6d3ceb1dSskrll * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28*6d3ceb1dSskrll * THE POSSIBILITY OF SUCH DAMAGE.
29*6d3ceb1dSskrll */
30*6d3ceb1dSskrll /*
31*6d3ceb1dSskrll * Copyright 1996 1995 by Open Software Foundation, Inc.
32*6d3ceb1dSskrll * All Rights Reserved
33*6d3ceb1dSskrll *
34*6d3ceb1dSskrll * Permission to use, copy, modify, and distribute this software and
35*6d3ceb1dSskrll * its documentation for any purpose and without fee is hereby granted,
36*6d3ceb1dSskrll * provided that the above copyright notice appears in all copies and
37*6d3ceb1dSskrll * that both the copyright notice and this permission notice appear in
38*6d3ceb1dSskrll * supporting documentation.
39*6d3ceb1dSskrll *
40*6d3ceb1dSskrll * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
41*6d3ceb1dSskrll * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42*6d3ceb1dSskrll * FOR A PARTICULAR PURPOSE.
43*6d3ceb1dSskrll *
44*6d3ceb1dSskrll * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
45*6d3ceb1dSskrll * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
46*6d3ceb1dSskrll * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
47*6d3ceb1dSskrll * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
48*6d3ceb1dSskrll * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49*6d3ceb1dSskrll *
50*6d3ceb1dSskrll */
51*6d3ceb1dSskrll
52*6d3ceb1dSskrll #include "libsa.h"
53*6d3ceb1dSskrll
54*6d3ceb1dSskrll #include <sys/param.h>
55*6d3ceb1dSskrll #include <sys/disklabel.h>
56*6d3ceb1dSskrll #include <machine/pdc.h>
57*6d3ceb1dSskrll #include <machine/iomod.h>
58*6d3ceb1dSskrll #include <dev/cons.h>
59*6d3ceb1dSskrll
60*6d3ceb1dSskrll #include "dev_hppa.h"
61*6d3ceb1dSskrll
62*6d3ceb1dSskrll iodcio_t cniodc; /* console IODC entry point */
63*6d3ceb1dSskrll iodcio_t kyiodc; /* keyboard IODC entry point */
64*6d3ceb1dSskrll pz_device_t *cons_pzdev, *kbd_pzdev;
65*6d3ceb1dSskrll
66*6d3ceb1dSskrll /*
67*6d3ceb1dSskrll * Console.
68*6d3ceb1dSskrll */
69*6d3ceb1dSskrll
70*6d3ceb1dSskrll char cnbuf[IODC_MINIOSIZ] __attribute__ ((aligned (IODC_MINIOSIZ)));
71*6d3ceb1dSskrll int kycode[IODC_MAXSIZE/sizeof(int)];
72*6d3ceb1dSskrll
73*6d3ceb1dSskrll #if 0
74*6d3ceb1dSskrll int
75*6d3ceb1dSskrll cnspeed(dev_t dev, int sp)
76*6d3ceb1dSskrll {
77*6d3ceb1dSskrll return 9600;
78*6d3ceb1dSskrll }
79*6d3ceb1dSskrll #endif
80*6d3ceb1dSskrll
81*6d3ceb1dSskrll void
ite_probe(struct consdev * cn)82*6d3ceb1dSskrll ite_probe(struct consdev *cn)
83*6d3ceb1dSskrll {
84*6d3ceb1dSskrll cniodc = (iodcio_t)PAGE0->mem_free;
85*6d3ceb1dSskrll cons_pzdev = &PAGE0->mem_cons;
86*6d3ceb1dSskrll kbd_pzdev = &PAGE0->mem_kbd;
87*6d3ceb1dSskrll
88*6d3ceb1dSskrll if ((*pdc) (PDC_IODC, PDC_IODC_READ, pdcbuf, cons_pzdev->pz_hpa,
89*6d3ceb1dSskrll IODC_INIT, cniodc, IODC_MAXSIZE) < 0 ||
90*6d3ceb1dSskrll (*cniodc)(cons_pzdev->pz_hpa,
91*6d3ceb1dSskrll (cons_pzdev->pz_hpa==PAGE0->mem_boot.pz_hpa)?
92*6d3ceb1dSskrll IODC_INIT_DEV: IODC_INIT_ALL, cons_pzdev->pz_spa,
93*6d3ceb1dSskrll cons_pzdev->pz_layers, pdcbuf, 0,0,0,0) < 0 ||
94*6d3ceb1dSskrll (*pdc) (PDC_IODC, PDC_IODC_READ, pdcbuf, cons_pzdev->pz_hpa,
95*6d3ceb1dSskrll IODC_IO, cniodc, IODC_MAXSIZE) < 0) {
96*6d3ceb1dSskrll /* morse code with the LED's?!! */
97*6d3ceb1dSskrll cons_pzdev->pz_iodc_io = kbd_pzdev->pz_iodc_io = NULL;
98*6d3ceb1dSskrll } else {
99*6d3ceb1dSskrll cn->cn_pri = CN_INTERNAL;
100*6d3ceb1dSskrll cn->cn_dev = makedev(0, 0);
101*6d3ceb1dSskrll }
102*6d3ceb1dSskrll }
103*6d3ceb1dSskrll
104*6d3ceb1dSskrll void
ite_init(struct consdev * cn)105*6d3ceb1dSskrll ite_init(struct consdev *cn)
106*6d3ceb1dSskrll {
107*6d3ceb1dSskrll /*
108*6d3ceb1dSskrll * If the keyboard is separate from the console output device,
109*6d3ceb1dSskrll * we load the keyboard code at `kycode'.
110*6d3ceb1dSskrll *
111*6d3ceb1dSskrll * N.B. In this case, since the keyboard code is part of the
112*6d3ceb1dSskrll * boot code, it will be overwritten when we load a kernel.
113*6d3ceb1dSskrll */
114*6d3ceb1dSskrll if (cons_pzdev->pz_class != PCL_DUPLEX ||
115*6d3ceb1dSskrll kbd_pzdev->pz_class == PCL_KEYBD) {
116*6d3ceb1dSskrll
117*6d3ceb1dSskrll kyiodc = (iodcio_t)kycode;
118*6d3ceb1dSskrll
119*6d3ceb1dSskrll if ((*pdc) (PDC_IODC, PDC_IODC_READ, pdcbuf, kbd_pzdev->pz_hpa,
120*6d3ceb1dSskrll IODC_INIT, kyiodc, IODC_MAXSIZE) < 0 ||
121*6d3ceb1dSskrll (*kyiodc)(kbd_pzdev->pz_hpa,
122*6d3ceb1dSskrll (kbd_pzdev->pz_hpa == PAGE0->mem_boot.pz_hpa ||
123*6d3ceb1dSskrll kbd_pzdev->pz_hpa == cons_pzdev->pz_hpa)?
124*6d3ceb1dSskrll IODC_INIT_DEV: IODC_INIT_ALL, kbd_pzdev->pz_spa,
125*6d3ceb1dSskrll kbd_pzdev->pz_layers, pdcbuf, 0, 0, 0, 0) < 0 ||
126*6d3ceb1dSskrll (*pdc) (PDC_IODC, PDC_IODC_READ, pdcbuf, kbd_pzdev->pz_hpa,
127*6d3ceb1dSskrll IODC_IO, kyiodc, IODC_MAXSIZE))
128*6d3ceb1dSskrll kyiodc = NULL;
129*6d3ceb1dSskrll } else {
130*6d3ceb1dSskrll kyiodc = cniodc;
131*6d3ceb1dSskrll
132*6d3ceb1dSskrll memcpy((char *)&PAGE0->mem_kbd, (char *)&PAGE0->mem_cons,
133*6d3ceb1dSskrll sizeof(struct pz_device));
134*6d3ceb1dSskrll }
135*6d3ceb1dSskrll
136*6d3ceb1dSskrll cons_pzdev->pz_iodc_io = cniodc;
137*6d3ceb1dSskrll kbd_pzdev->pz_iodc_io = kyiodc;
138*6d3ceb1dSskrll #ifdef DEBUG
139*6d3ceb1dSskrll if (!kyiodc)
140*6d3ceb1dSskrll printf("ite_init: no kbd\n");
141*6d3ceb1dSskrll #endif
142*6d3ceb1dSskrll }
143*6d3ceb1dSskrll
144*6d3ceb1dSskrll void
ite_putc(dev_t dev,int c)145*6d3ceb1dSskrll ite_putc(dev_t dev, int c)
146*6d3ceb1dSskrll {
147*6d3ceb1dSskrll if (cniodc == NULL)
148*6d3ceb1dSskrll return;
149*6d3ceb1dSskrll
150*6d3ceb1dSskrll *cnbuf = c;
151*6d3ceb1dSskrll
152*6d3ceb1dSskrll (*cniodc)(cons_pzdev->pz_hpa, IODC_IO_CONSOUT, cons_pzdev->pz_spa,
153*6d3ceb1dSskrll cons_pzdev->pz_layers, pdcbuf, 0, cnbuf, 1, 0);
154*6d3ceb1dSskrll }
155*6d3ceb1dSskrll
156*6d3ceb1dSskrll /*
157*6d3ceb1dSskrll * since i don't know how to 'just check the char available'
158*6d3ceb1dSskrll * i store the key into the stash removing on read op later;
159*6d3ceb1dSskrll */
160*6d3ceb1dSskrll int
ite_getc(dev_t dev)161*6d3ceb1dSskrll ite_getc(dev_t dev)
162*6d3ceb1dSskrll {
163*6d3ceb1dSskrll static int stash = 0;
164*6d3ceb1dSskrll int err __debugused, c, l, i;
165*6d3ceb1dSskrll
166*6d3ceb1dSskrll if (kyiodc == NULL)
167*6d3ceb1dSskrll return(0x100);
168*6d3ceb1dSskrll
169*6d3ceb1dSskrll if (stash) {
170*6d3ceb1dSskrll c = stash;
171*6d3ceb1dSskrll if (!(dev & 0x80))
172*6d3ceb1dSskrll stash = 0;
173*6d3ceb1dSskrll return c;
174*6d3ceb1dSskrll }
175*6d3ceb1dSskrll
176*6d3ceb1dSskrll i = 16;
177*6d3ceb1dSskrll do {
178*6d3ceb1dSskrll err = (*kyiodc)(kbd_pzdev->pz_hpa, IODC_IO_CONSIN,
179*6d3ceb1dSskrll kbd_pzdev->pz_spa, kbd_pzdev->pz_layers,
180*6d3ceb1dSskrll pdcbuf, 0, cnbuf, 1, 0);
181*6d3ceb1dSskrll l = pdcbuf[0];
182*6d3ceb1dSskrll c = cnbuf[0];
183*6d3ceb1dSskrll #ifdef DEBUG
184*6d3ceb1dSskrll if (debug && err < 0)
185*6d3ceb1dSskrll printf("KBD input error: %d", err);
186*6d3ceb1dSskrll #endif
187*6d3ceb1dSskrll
188*6d3ceb1dSskrll /* if we are doing ischar() report immidiatelly */
189*6d3ceb1dSskrll if (!i-- && (dev & 0x80) && l == 0) {
190*6d3ceb1dSskrll #ifdef DEBUG
191*6d3ceb1dSskrll if (debug > 2)
192*6d3ceb1dSskrll printf("ite_getc(%llx): no char %d(%x)\n",
193*6d3ceb1dSskrll dev, l, c);
194*6d3ceb1dSskrll #endif
195*6d3ceb1dSskrll return (0);
196*6d3ceb1dSskrll }
197*6d3ceb1dSskrll } while(!l);
198*6d3ceb1dSskrll
199*6d3ceb1dSskrll #if DEBUG
200*6d3ceb1dSskrll if (debug && l > 1)
201*6d3ceb1dSskrll printf("KBD input got too much (%d)\n", l);
202*6d3ceb1dSskrll
203*6d3ceb1dSskrll if (debug > 3)
204*6d3ceb1dSskrll printf("kbd: \'%c\' (0x%x)\n", c, c);
205*6d3ceb1dSskrll #endif
206*6d3ceb1dSskrll if (dev & 0x80)
207*6d3ceb1dSskrll stash = c;
208*6d3ceb1dSskrll
209*6d3ceb1dSskrll return (c);
210*6d3ceb1dSskrll }
211*6d3ceb1dSskrll
212*6d3ceb1dSskrll void
ite_pollc(dev_t dev,int on)213*6d3ceb1dSskrll ite_pollc(dev_t dev, int on)
214*6d3ceb1dSskrll {
215*6d3ceb1dSskrll }
216