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