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