tx39io.c revision 1.5 1 /* $NetBSD: tx39io.c,v 1.5 2000/01/16 21:47:00 uch Exp $ */
2
3 /*
4 * Copyright (c) 1999, 2000, by UCHIYAMA Yasushi
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. The name of the developer may NOT be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28 #include "opt_tx39_debug.h"
29 #include "opt_tx39iodebug.h"
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34
35 #include <machine/bus.h>
36
37 #include <hpcmips/tx/tx39var.h>
38 #include <hpcmips/tx/tx39iovar.h>
39 #include <hpcmips/tx/tx39ioreg.h>
40 #include <hpcmips/tx/tx39icureg.h>
41
42 #include <hpcmips/tx/txiomanvar.h>
43
44 #define TX39IO_ATTACH_DUMMYHANDLER 0
45 #undef TX39IO_MFIOOUTPORT_ON
46 #undef TX39IO_MFIOOUTPORT_OFF
47
48 int tx39io_match __P((struct device*, struct cfdata*, void*));
49 void tx39io_attach __P((struct device*, struct device*, void*));
50 int tx39io_print __P((void*, const char*));
51
52 struct tx39io_softc {
53 struct device sc_dev;
54 tx_chipset_tag_t sc_tc;
55 };
56
57 struct cfattach tx39io_ca = {
58 sizeof(struct tx39io_softc), tx39io_match, tx39io_attach
59 };
60
61 #ifdef TX39IODEBUG
62 int tx39io_intr __P((void*));
63 int tx39mfio_intr __P((void*));
64 void tx39io_dump __P((struct tx39io_softc*));
65 void tx39io_dump_and_attach_handler __P((struct tx39io_softc*, int));
66 void __dump_and_attach_handler __P((tx_chipset_tag_t, u_int32_t,
67 u_int32_t, u_int32_t, u_int32_t,
68 int, int, int (*) __P((void*)),
69 void*, int));
70 #endif /* TX39IODEBUG */
71
72 #define ISSET(x, s) ((x) & (1 << (s)))
73 #define STD_IN 1
74 #define STD_OUT 2
75 #define STD_INOUT 3
76
77 const struct {
78 char *std_pin_name;
79 int std_type;
80 } mfio_map[TX39_IO_MFIO_MAX] = {
81 [31] = {"CHIFS", STD_INOUT},
82 [30] = {"CHICLK", STD_INOUT},
83 [29] = {"CHIDOUT", STD_OUT},
84 [28] = {"CHIDIN", STD_IN},
85 [27] = {"DREQ", STD_IN},
86 [26] = {"DGRINT", STD_OUT},
87 [25] = {"BC32K", STD_OUT},
88 [24] = {"TXD", STD_OUT},
89 [23] = {"RXD", STD_IN},
90 [22] = {"CS1", STD_OUT},
91 [21] = {"CS2", STD_OUT},
92 [20] = {"CS3", STD_OUT},
93 [19] = {"MCS0", STD_OUT},
94 [18] = {"MCS1", STD_OUT},
95 #ifdef TX391X
96 [17] = {"MCS2", STD_OUT},
97 [16] = {"MCS3", STD_OUT},
98 #endif /* TX391X */
99 #ifdef TX392X
100 [17] = {"RXPWR", STD_OUT},
101 [16] = {"IROUT", STD_OUT},
102 #endif /* TX392X */
103 [15] = {"SPICLK", STD_OUT},
104 [14] = {"SPIOUT", STD_OUT},
105 [13] = {"SPIN", STD_IN},
106 [12] = {"SIBMCLK", STD_INOUT},
107 [11] = {"CARDREG", STD_OUT},
108 [10] = {"CARDIOWR", STD_OUT},
109 [9] = {"CARDIORD", STD_OUT},
110 [8] = {"CARD1CSL", STD_OUT},
111 [7] = {"CARD1CSH", STD_OUT},
112 [6] = {"CARD2CSL", STD_OUT},
113 [5] = {"CARD2CSH", STD_OUT},
114 [4] = {"CARD1WAIT", STD_IN},
115 [3] = {"CARD2WAIT", STD_IN},
116 [2] = {"CARDDIR", STD_OUT},
117 #ifdef TX391X
118 [1] = {"MFIO[1]", 0},
119 [0] = {"MFIO[0]", 0}
120 #endif /* TX391X */
121 #ifdef TX392X
122 [1] = {"MCS1WAIT", 0},
123 [0] = {"MCS0WAIT", 0}
124 #endif /* TX392X */
125 };
126
127 int
128 tx39io_match(parent, cf, aux)
129 struct device *parent;
130 struct cfdata *cf;
131 void *aux;
132 {
133 return 2; /* 1st attach group of txsim */
134 }
135
136 void
137 tx39io_attach(parent, self, aux)
138 struct device *parent;
139 struct device *self;
140 void *aux;
141 {
142 struct txsim_attach_args *ta = aux;
143 struct tx39io_softc *sc = (void*)self;
144 struct txioman_attach_args tia;
145
146 sc->sc_tc = ta->ta_tc;
147
148 printf("\n");
149 #ifdef TX39IODEBUG
150 tx39io_dump(sc);
151 #endif /* TX39IODEBUG */
152
153 /*
154 * attach platform dependent io manager
155 */
156 tia.tia_tc = sc->sc_tc;
157 config_found(self, &tia, tx39io_print);
158 }
159
160 int
161 tx39io_print(aux, pnp)
162 void *aux;
163 const char *pnp;
164 {
165 return pnp ? QUIET : UNCONF;
166 }
167
168 void
169 tx39io_portout(tc, port, onoff)
170 tx_chipset_tag_t tc;
171 int port, onoff;
172 {
173 txreg_t reg;
174
175 /* XXX check port is output or not */
176
177 if (port >= TXIO) { /* XXX TX3922 case */
178 #ifdef TX391X
179 txreg_t iostat;
180 /* IO */
181 reg = tx_conf_read(tc, TX39_IOCTRL_REG);
182 iostat = TX39_IOCTRL_IODOUT(reg);
183 if (onoff)
184 iostat |= (1 << (port - TXIO));
185 else
186 iostat &= ~(1 << (port - TXIO));
187
188 TX39_IOCTRL_IODOUT_CLR(reg);
189 reg = TX39_IOCTRL_IODOUT_SET(reg, iostat);
190 tx_conf_write(tc, TX39_IOCTRL_REG, reg);
191 #endif /* TX391X */
192 } else {
193 /* MFIO */
194 reg = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
195 if (onoff)
196 reg |= (1 << port);
197 else
198 reg &= ~(1 << port);
199
200 tx_conf_write(tc, TX39_IOMFIODATAOUT_REG, reg);
201 }
202 }
203
204 #ifdef TX39IODEBUG
205 int
206 tx39io_intr(arg)
207 void *arg;
208 {
209 printf("io (%d:%d)\n", (tx39intrvec >> 16) & 0xffff,
210 tx39intrvec & 0xfff);
211
212 return 0;
213 }
214
215 int
216 tx39mfio_intr(arg)
217 void *arg;
218 {
219 printf("mfio (%d:%d)\n", (tx39intrvec >> 16) & 0xffff,
220 tx39intrvec & 0xfff);
221
222 return 0;
223 }
224
225 void
226 tx39io_dump(sc)
227 struct tx39io_softc *sc;
228 {
229 #ifdef COMPAQ_LOCAL_INTR /* for debug */
230 /* 2010c Rec button */
231 tx_intr_establish(tc, MAKEINTR(5, (1<<6)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
232 /* Play button */
233 tx_intr_establish(tc, MAKEINTR(5, (1<<5)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
234 /* Power connector */
235 tx_intr_establish(tc, MAKEINTR(3, (1<<28)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
236 tx_intr_establish(tc, MAKEINTR(4, (1<<28)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
237 /* UARTA carrier */
238 tx_intr_establish(tc, MAKEINTR(3, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
239 tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
240 /* --> then turn off MFIO 31 */
241 tx_intr_establish(tc, MAKEINTR(3, (1<<5)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
242 tx_intr_establish(tc, MAKEINTR(4, (1<<5)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
243 /* --> then turn off MFIO 6 */
244 /* green LED: MFIO 3 off */
245 /* orange LED: not connected to TX39IO ??? */
246 /* Backlight: UCB1200 GPIO port ??? */
247 #endif
248 #ifdef MOBILON_LOCAL_INTR /* for debug */
249 /* Rec button */
250 tx_intr_establish(tc, MAKEINTR(5, (1<<0)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
251 /* Play button */
252 tx_intr_establish(tc, MAKEINTR(3, (1<<31)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
253 /* Battery cover open */
254 tx_intr_establish(tc, MAKEINTR(3, (1<<29)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
255 /* Serial DCD */
256 tx_intr_establish(tc, MAKEINTR(5, (1<<4)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
257 /* --> then turn off IO 3 ??? */
258 tx_intr_establish(tc, MAKEINTR(5, (1<<6)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
259 /* --> then turn off IO 5 ??? */
260 /* keyboard */
261 tx_intr_establish(tc, MAKEINTR(5, (1<<13)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
262 /* Back light: MFIO 14 on */
263 #endif
264 #ifdef VICTOR_INTERLINK_INTR /* for debug */
265 /* open panel */
266 tx_intr_establish(tc, MAKEINTR(8, (1<<20)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
267 /* close panel */
268 tx_intr_establish(tc, MAKEINTR(8, (1<<4)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
269 /* serial session */
270 tx_intr_establish(tc, MAKEINTR(4, (1<<29)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
271 tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
272 /* REC button */
273 tx_intr_establish(tc, MAKEINTR(8, (1<<7)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
274 /* kbd */
275 tx_intr_establish(tc, MAKEINTR(3, (1<<7)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
276 #endif
277
278 tx39io_dump_and_attach_handler(sc, TX39IO_ATTACH_DUMMYHANDLER);
279 }
280
281 void
282 tx39io_dump_and_attach_handler(sc, dummy)
283 struct tx39io_softc *sc;
284 int dummy;
285 {
286 tx_chipset_tag_t tc;
287 u_int32_t reg, reg_out, reg_dir, reg_in, reg_sel, reg_pwr, reg_deb;
288 int i;
289 int (*iointr) __P((void*));
290 int (*mfiointr) __P((void*));
291
292 tc = sc->sc_tc;
293 if (dummy) {
294 iointr = tx39io_intr;
295 mfiointr = tx39mfio_intr;
296 } else {
297 iointr = mfiointr = 0;
298 }
299
300 printf("--------------------------------------------------------------\n");
301 printf(" Debounce Direction DataOut DataIn PowerDown Select\n");
302 printf("--------------------------------------------------------------\n");
303 /* IO */
304 reg = tx_conf_read(tc, TX39_IOCTRL_REG);
305 reg_deb = TX39_IOCTRL_IODEBSEL(reg);
306 reg_dir = TX39_IOCTRL_IODIREC(reg);
307 #ifdef TX391X
308 reg_out = TX39_IOCTRL_IODOUT(reg);
309 reg_in = TX39_IOCTRL_IODIN(reg);
310 #endif /* TX391X */
311 #ifdef TX392X
312 reg = tx_conf_read(tc, TX39_IODATAINOUT_REG);
313 reg_out = TX39_IODATAINOUT_DOUT(reg);
314 reg_in = TX39_IODATAINOUT_DIN(reg);
315 #endif /* TX392X */
316 reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
317 reg_pwr = TX39_IOIOPOWERDWN_IOPD(reg);
318 for (i = TX39_IO_IO_MAX - 1; i >= 0 ; i--) {
319 printf("IO %2d: ", i);
320 printf("%s", ISSET(reg_dir, i) ? "On " : "Off");
321 printf(" ");
322 __dump_and_attach_handler(tc, reg_dir, reg_out, reg_in,
323 reg_pwr, i, 1, iointr, sc, 1);
324
325 printf(" -");
326 printf("\n");
327 }
328 /* MFIO */
329 printf("--------------------------------------------------------------\n");
330 reg_out = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
331 reg_dir = tx_conf_read(tc, TX39_IOMFIODATADIR_REG);
332 reg_in = tx_conf_read(tc, TX39_IOMFIODATAIN_REG);
333 reg_sel = tx_conf_read(tc, TX39_IOMFIODATASEL_REG);
334 reg_pwr = tx_conf_read(tc, TX39_IOMFIOPOWERDWN_REG);
335 for (i = TX39_IO_MFIO_MAX - 1; i >= 0 ; i--) {
336 printf("MFIO %2d: - ", i);
337 __dump_and_attach_handler(tc, reg_dir, reg_out, reg_in,
338 reg_pwr, i, 0, mfiointr, sc,
339 ISSET(reg_sel, i));
340 printf(" ");
341 printf(ISSET(reg_sel, i) ? "MFIO(%s)" : "%s",
342 mfio_map[i].std_pin_name);
343 printf("\n");
344 }
345 printf("--------------------------------------------------------------\n");
346 }
347
348 void
349 __dump_and_attach_handler(tc, reg_dir, reg_out, reg_in, reg_pwr,
350 i, io, func, arg, mf)
351 tx_chipset_tag_t tc;
352 u_int32_t reg_dir, reg_out, reg_in, reg_pwr;
353 int i, io;
354 int (*func) __P((void*));
355 void *arg;
356 int mf;
357 {
358 int pset, nset, pofs, nofs;
359
360 if (io) {
361 #ifdef TX391X
362 pset = nset = 5;
363 pofs = i + 7;
364 nofs = i;
365 #endif
366 #ifdef TX392X
367 pset = nset = 8;
368 pofs = i + 16;
369 nofs = i;
370 #endif
371 } else {
372 pset = 3;
373 nset = 4;
374 pofs = nofs = i;
375 }
376
377 if (ISSET(reg_dir, i)) {
378 #if defined TX39IO_MFIOOUTPORT_ON || defined TX39IO_MFIOOUTPORT_OFF
379 txreg_t reg;
380 #ifdef TX392X
381 if (io) {
382 reg = tx_conf_read(tc, TX39_IODATAINOUT_REG);
383 #ifdef TX39IO_MFIOOUTPORT_ON
384 reg |= (1 << (i + 16));
385 printf("on.");
386 #else
387 reg &= ~(1 << (i + 16));
388 printf("off.");
389 #endif
390 tx_conf_write(tc, TX39_IODATAINOUT_REG, reg);
391 } else
392 #endif /* TX392X */
393 {
394 reg = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
395 #ifdef TX39IO_MFIOOUTPORT_ON
396 reg |= (1 << i);
397 printf("on.");
398 #else
399 reg &= ~(1 << i);
400 printf("off.");
401 #endif
402 tx_conf_write(tc, TX39_IOMFIODATAOUT_REG, reg);
403 }
404 #endif /* TX39IO_MFIOOUTPORT_ON */
405 printf("Out");
406 } else {
407 printf("In ");
408 if (mf && func) {
409 /* Positive Edge */
410 tx_intr_establish(
411 tc, MAKEINTR(pset, (1 << pofs)),
412 IST_EDGE, IPL_TTY, func, arg);
413 /* Negative Edge */
414 tx_intr_establish(
415 tc, MAKEINTR(nset, (1 << nofs)),
416 IST_EDGE, IPL_TTY, func, arg);
417 }
418 }
419 printf(" ");
420 printf("%d", ISSET(reg_out, i) ? 1 : 0);
421 printf(" ");
422 printf("%d", ISSET(reg_in, i) ? 1 : 0);
423 printf(" ");
424 printf("%s", ISSET(reg_pwr, i) ? "Down ": "Active");
425 };
426
427 #endif /* TX39IODEBUG */
428