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