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