tx39io.c revision 1.3       1  1.3  uch /*	$NetBSD: tx39io.c,v 1.3 1999/12/23 16:58:07 uch Exp $ */
      2  1.1  uch 
      3  1.1  uch /*
      4  1.1  uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5  1.1  uch  * All rights reserved.
      6  1.1  uch  *
      7  1.1  uch  * Redistribution and use in source and binary forms, with or without
      8  1.1  uch  * modification, are permitted provided that the following conditions
      9  1.1  uch  * are met:
     10  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1  uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13  1.1  uch  *    derived from this software without specific prior written permission.
     14  1.1  uch  *
     15  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  uch  * SUCH DAMAGE.
     26  1.1  uch  *
     27  1.1  uch  */
     28  1.1  uch #include "opt_tx39_debug.h"
     29  1.1  uch #include "opt_tx39iodebug.h"
     30  1.1  uch 
     31  1.1  uch #include <sys/param.h>
     32  1.1  uch #include <sys/systm.h>
     33  1.1  uch #include <sys/device.h>
     34  1.1  uch 
     35  1.1  uch #include <machine/bus.h>
     36  1.1  uch 
     37  1.1  uch #include <hpcmips/tx/tx39var.h>
     38  1.1  uch #include <hpcmips/tx/tx39ioreg.h>
     39  1.1  uch #include <hpcmips/tx/tx39icureg.h>
     40  1.1  uch 
     41  1.1  uch #define TX39IO_ATTACH_DUMMYHANDLER 0
     42  1.1  uch #undef TX39IO_MFIOOUTPORT_ON
     43  1.3  uch #undef TX39IO_MFIOOUTPORT_OFF
     44  1.1  uch 
     45  1.1  uch int	tx39io_match __P((struct device*, struct cfdata*, void*));
     46  1.1  uch void	tx39io_attach __P((struct device*, struct device*, void*));
     47  1.1  uch 
     48  1.1  uch struct tx39io_softc {
     49  1.1  uch 	struct	device sc_dev;
     50  1.1  uch 	tx_chipset_tag_t sc_tc;
     51  1.1  uch };
     52  1.1  uch 
     53  1.1  uch struct cfattach tx39io_ca = {
     54  1.1  uch 	sizeof(struct tx39io_softc), tx39io_match, tx39io_attach
     55  1.1  uch };
     56  1.1  uch 
     57  1.1  uch int	tx39io_intr __P((void*));
     58  1.1  uch int	tx39mfio_intr __P((void*));
     59  1.1  uch 
     60  1.1  uch void	tx39io_dump_and_attach_handler __P((struct tx39io_softc*, int));
     61  1.1  uch void	__dump_and_attach_handler __P((tx_chipset_tag_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, int, int, int (*) __P((void*)), void*));
     62  1.1  uch 
     63  1.1  uch #define ISSET(x, s)	((x) & (1 << (s)))
     64  1.1  uch #define STD_IN		1
     65  1.1  uch #define STD_OUT		2
     66  1.1  uch #define STD_INOUT	3
     67  1.1  uch 
     68  1.3  uch const struct {
     69  1.1  uch 	char *std_pin_name;
     70  1.1  uch 	int  std_type;
     71  1.1  uch } mfio_map[TX39_IO_MFIO_MAX] = {
     72  1.1  uch   [31] = {"CHIFS",	STD_INOUT},
     73  1.1  uch   [30] = {"CHICLK",	STD_INOUT},
     74  1.1  uch   [29] = {"CHIDOUT",	STD_OUT},
     75  1.1  uch   [28] = {"CHIDIN",	STD_IN},
     76  1.1  uch   [27] = {"DREQ",	STD_IN},
     77  1.1  uch   [26] = {"DGRINT",	STD_OUT},
     78  1.1  uch   [25] = {"BC32K",	STD_OUT},
     79  1.1  uch   [24] = {"TXD",	STD_OUT},
     80  1.1  uch   [23] = {"RXD",	STD_IN},
     81  1.1  uch   [22] = {"CS1",	STD_OUT},
     82  1.1  uch   [21] = {"CS2",	STD_OUT},
     83  1.1  uch   [20] = {"CS3",	STD_OUT},
     84  1.1  uch   [19] = {"MCS0",	STD_OUT},
     85  1.1  uch   [18] = {"MCS1",	STD_OUT},
     86  1.1  uch #ifdef TX391X
     87  1.1  uch   [17] = {"MCS2",	STD_OUT},
     88  1.1  uch   [16] = {"MCS3",	STD_OUT},
     89  1.1  uch #endif /* TX391X */
     90  1.1  uch #ifdef TX392X
     91  1.1  uch   [17] = {"RXPWR",	STD_OUT},
     92  1.1  uch   [16] = {"IROUT",	STD_OUT},
     93  1.1  uch #endif /* TX392X */
     94  1.1  uch   [15] = {"SPICLK",	STD_OUT},
     95  1.1  uch   [14] = {"SPIOUT",	STD_OUT},
     96  1.1  uch   [13] = {"SPIN",	STD_IN},
     97  1.1  uch   [12] = {"SIBMCLK",	STD_INOUT},
     98  1.1  uch   [11] = {"CARDREG",	STD_OUT},
     99  1.1  uch   [10] = {"CARDIOWR",	STD_OUT},
    100  1.1  uch    [9] = {"CARDIORD",	STD_OUT},
    101  1.1  uch    [8] = {"CARD1CSL",	STD_OUT},
    102  1.1  uch    [7] = {"CARD1CSH",	STD_OUT},
    103  1.1  uch    [6] = {"CARD2CSL",	STD_OUT},
    104  1.1  uch    [5] = {"CARD2CSH",	STD_OUT},
    105  1.1  uch    [4] = {"CARD1WAIT",	STD_IN},
    106  1.1  uch    [3] = {"CARD2WAIT",	STD_IN},
    107  1.1  uch    [2] = {"CARDDIR",	STD_OUT},
    108  1.1  uch #ifdef TX391X
    109  1.1  uch    [1] = {"MFIO[1]",	0},
    110  1.1  uch    [0] = {"MFIO[0]",	0}
    111  1.1  uch #endif /* TX391X */
    112  1.1  uch #ifdef TX392X
    113  1.1  uch    [1] = {"MCS1WAIT",	0},
    114  1.1  uch    [0] = {"MCS0WAIT",	0}
    115  1.1  uch #endif /* TX392X */
    116  1.1  uch };
    117  1.1  uch 
    118  1.1  uch int
    119  1.1  uch tx39io_match(parent, cf, aux)
    120  1.1  uch 	struct device *parent;
    121  1.1  uch 	struct cfdata *cf;
    122  1.1  uch 	void *aux;
    123  1.1  uch {
    124  1.1  uch 
    125  1.1  uch 	return 1;
    126  1.1  uch }
    127  1.1  uch 
    128  1.1  uch int
    129  1.1  uch tx39io_intr(arg)
    130  1.1  uch 	void *arg;
    131  1.1  uch {
    132  1.1  uch #ifdef TX39_DEBUG
    133  1.2  uch #if 0
    134  1.1  uch 	static int i;
    135  1.1  uch 	if (i ^= 1) {
    136  1.1  uch 		tx39debugflag = 1;
    137  1.1  uch 	} else {
    138  1.1  uch 		tx39debugflag = 0;
    139  1.1  uch 	}
    140  1.2  uch #endif
    141  1.1  uch 	printf("io (%d:%d)\n", (tx39intrvec >> 16) & 0xffff,
    142  1.1  uch 	       tx39intrvec & 0xfff);
    143  1.1  uch #endif
    144  1.1  uch 	return 0;
    145  1.1  uch }
    146  1.1  uch 
    147  1.1  uch int
    148  1.1  uch tx39mfio_intr(arg)
    149  1.1  uch 	void *arg;
    150  1.1  uch {
    151  1.1  uch #ifdef TX39_DEBUG
    152  1.2  uch #if 0
    153  1.1  uch 	struct tx39io_softc *sc = arg;
    154  1.1  uch 	tx39io_dump_and_attach_handler(sc, 0);
    155  1.1  uch #endif
    156  1.1  uch 	printf("mfio (%d:%d)\n", (tx39intrvec >> 16) & 0xffff,
    157  1.1  uch 	       tx39intrvec & 0xfff);
    158  1.1  uch #endif
    159  1.1  uch 	return 0;
    160  1.1  uch }
    161  1.1  uch 
    162  1.1  uch void
    163  1.1  uch tx39io_attach(parent, self, aux)
    164  1.1  uch 	struct device *parent;
    165  1.1  uch 	struct device *self;
    166  1.1  uch 	void *aux;
    167  1.1  uch {
    168  1.1  uch 	struct txsim_attach_args *ta = aux;
    169  1.1  uch 	struct tx39io_softc *sc = (void*)self;
    170  1.1  uch 	tx_chipset_tag_t tc;
    171  1.1  uch 	tc = sc->sc_tc = ta->ta_tc;
    172  1.1  uch 
    173  1.1  uch 	printf("\n");
    174  1.1  uch #ifdef COMPAQ_LOCAL_INTR
    175  1.1  uch 	/* 2010c Rec button */
    176  1.1  uch 	tx_intr_establish(tc, MAKEINTR(5, (1<<6)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    177  1.1  uch 	/* Play button */
    178  1.1  uch 	tx_intr_establish(tc, MAKEINTR(5, (1<<5)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    179  1.1  uch 	/* It seems that these interrupt arise when serial session start */
    180  1.1  uch 	tx_intr_establish(tc, MAKEINTR(3, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    181  1.1  uch 	tx_intr_establish(tc, MAKEINTR(3, (1<<5)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    182  1.1  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    183  1.1  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<5)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    184  1.2  uch #endif
    185  1.2  uch 
    186  1.2  uch #ifdef VICTOR_INTERLINK_INTR
    187  1.2  uch 	/* open panel */
    188  1.2  uch 	tx_intr_establish(tc, MAKEINTR(8, (1<<20)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    189  1.2  uch 	/* close panel */
    190  1.2  uch 	tx_intr_establish(tc, MAKEINTR(8, (1<<4)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    191  1.2  uch 	/* serial session */
    192  1.2  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<29)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    193  1.2  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    194  1.2  uch 	/* REC button */
    195  1.2  uch 	tx_intr_establish(tc, MAKEINTR(8, (1<<7)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    196  1.2  uch 	/* kbd */
    197  1.2  uch 	tx_intr_establish(tc, MAKEINTR(3, (1<<7)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    198  1.1  uch #endif
    199  1.1  uch 
    200  1.1  uch #ifdef TX39IODEBUG
    201  1.1  uch 	tx39io_dump_and_attach_handler(sc, TX39IO_ATTACH_DUMMYHANDLER);
    202  1.1  uch #endif /* TX39IODEBUG */
    203  1.1  uch }
    204  1.1  uch 
    205  1.1  uch #ifdef TX39IODEBUG
    206  1.1  uch void
    207  1.1  uch tx39io_dump_and_attach_handler(sc, dummy)
    208  1.1  uch 	struct tx39io_softc *sc;
    209  1.1  uch 	int dummy;
    210  1.1  uch {
    211  1.1  uch 	tx_chipset_tag_t tc;
    212  1.1  uch 	u_int32_t reg, reg_out, reg_dir, reg_in, reg_sel, reg_pwr, reg_deb;
    213  1.1  uch 	int i;
    214  1.1  uch 	int (*iointr) __P((void*));
    215  1.1  uch 	int (*mfiointr) __P((void*));
    216  1.1  uch 
    217  1.1  uch 	tc = sc->sc_tc;
    218  1.1  uch 	if (dummy) {
    219  1.1  uch 		iointr =  tx39io_intr;
    220  1.1  uch 		mfiointr = tx39mfio_intr;
    221  1.1  uch 	} else {
    222  1.1  uch 		iointr = mfiointr = 0;
    223  1.1  uch 	}
    224  1.1  uch 
    225  1.1  uch 	printf("--------------------------------------------------------------\n");
    226  1.1  uch 	printf("	 Debounce Direction DataOut DataIn PowerDown Select\n");
    227  1.1  uch 	printf("--------------------------------------------------------------\n");
    228  1.1  uch 	/* IO */
    229  1.1  uch 	reg = tx_conf_read(tc, TX39_IOCTRL_REG);
    230  1.1  uch 	reg_deb = TX39_IOCTRL_IODEBSEL(reg);
    231  1.1  uch 	reg_dir = TX39_IOCTRL_IODIREC(reg);
    232  1.1  uch #ifdef TX391X
    233  1.1  uch 	reg_out = TX39_IOCTRL_IODOUT(reg);
    234  1.1  uch 	reg_in  = TX39_IOCTRL_IODIN(reg);
    235  1.1  uch #endif /* TX391X */
    236  1.1  uch #ifdef TX392X
    237  1.1  uch 	reg = tx_conf_read(tc, TX39_IODATAINOUT_REG);
    238  1.1  uch 	reg_out = TX39_IODATAINOUT_DOUT(reg);
    239  1.1  uch 	reg_in  = TX39_IODATAINOUT_DIN(reg);
    240  1.1  uch #endif /* TX392X */
    241  1.1  uch 	reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
    242  1.1  uch 	reg_pwr = TX39_IOIOPOWERDWN_IOPD(reg);
    243  1.1  uch 	for (i = TX39_IO_IO_MAX - 1; i >= 0 ; i--) {
    244  1.1  uch 		printf("IO   %2d:    ", i);
    245  1.1  uch 		printf("%s", ISSET(reg_dir, i) ? "On " : "Off");
    246  1.1  uch 		printf("      ");
    247  1.1  uch 		__dump_and_attach_handler(tc, reg_dir, reg_out, reg_in,
    248  1.1  uch 					  reg_pwr, i, 1, iointr, sc);
    249  1.1  uch 
    250  1.1  uch 		printf("    -");
    251  1.1  uch 		printf("\n");
    252  1.1  uch 	}
    253  1.1  uch 	/* MFIO */
    254  1.1  uch 	printf("--------------------------------------------------------------\n");
    255  1.1  uch 	reg_out = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
    256  1.1  uch 	reg_dir = tx_conf_read(tc, TX39_IOMFIODATADIR_REG);
    257  1.1  uch 	reg_in  = tx_conf_read(tc, TX39_IOMFIODATAIN_REG);
    258  1.1  uch 	reg_sel = tx_conf_read(tc, TX39_IOMFIODATASEL_REG);
    259  1.1  uch 	reg_pwr = tx_conf_read(tc, TX39_IOMFIOPOWERDWN_REG);
    260  1.1  uch 	for (i = TX39_IO_MFIO_MAX - 1; i >= 0 ; i--) {
    261  1.1  uch 		printf("MFIO %2d:     -       ", i);
    262  1.1  uch 		__dump_and_attach_handler(tc, reg_dir, reg_out, reg_in,
    263  1.1  uch 					  reg_pwr, i, 0, mfiointr, sc);
    264  1.1  uch 		printf("  ");
    265  1.1  uch 		printf(ISSET(reg_sel, i) ? "MFIO(%s)" : "%s",
    266  1.1  uch 		       mfio_map[i].std_pin_name);
    267  1.1  uch 		printf("\n");
    268  1.1  uch 	}
    269  1.1  uch 	printf("--------------------------------------------------------------\n");
    270  1.1  uch }
    271  1.1  uch 
    272  1.1  uch void
    273  1.1  uch __dump_and_attach_handler(tc, reg_dir, reg_out, reg_in, reg_pwr,
    274  1.1  uch 			  i, io, func, arg)
    275  1.1  uch 	tx_chipset_tag_t tc;
    276  1.1  uch 	u_int32_t reg_dir, reg_out, reg_in, reg_pwr;
    277  1.1  uch 	int i, io;
    278  1.1  uch 	int (*func) __P((void*));
    279  1.1  uch 	void *arg;
    280  1.1  uch {
    281  1.1  uch 	int pset, nset, pofs, nofs;
    282  1.1  uch 
    283  1.1  uch 	if (io) {
    284  1.1  uch #ifdef TX391X
    285  1.1  uch 		pset = nset = 5;
    286  1.1  uch 		pofs = i + 7;
    287  1.1  uch 		nofs = i;
    288  1.1  uch #endif
    289  1.1  uch #ifdef TX392X
    290  1.1  uch 		pset = nset = 8;
    291  1.1  uch 		pofs = i + 16;
    292  1.1  uch 		nofs = i;
    293  1.1  uch #endif
    294  1.1  uch 	} else {
    295  1.1  uch 		pset = 3;
    296  1.1  uch 		nset = 4;
    297  1.1  uch 		pofs = nofs = i;
    298  1.1  uch 	}
    299  1.1  uch 
    300  1.1  uch 	if (ISSET(reg_dir, i)) {
    301  1.3  uch #if defined TX39IO_MFIOOUTPORT_ON || defined TX39IO_MFIOOUTPORT_OFF
    302  1.1  uch 		txreg_t reg;
    303  1.1  uch 		if (io) {
    304  1.1  uch #ifdef TX392X
    305  1.1  uch 			reg = tx_conf_read(tc, TX39_IODATAINOUT_REG);
    306  1.3  uch #ifdef TX39IO_MFIOOUTPORT_ON
    307  1.1  uch 			reg |= (1 << (i + 16));
    308  1.3  uch #else
    309  1.3  uch 			reg &= ~(1 << (i + 16));
    310  1.3  uch #endif
    311  1.1  uch 			tx_conf_write(tc, TX39_IODATAINOUT_REG, reg);
    312  1.1  uch #endif /* TX392X */
    313  1.1  uch 		} else {
    314  1.1  uch 			reg = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
    315  1.3  uch #ifdef TX39IO_MFIOOUTPORT_ON
    316  1.1  uch 			reg |= (1 << i);
    317  1.3  uch #else
    318  1.3  uch 			reg &= ~(1 << i);
    319  1.3  uch #endif
    320  1.1  uch 			tx_conf_write(tc, TX39_IOMFIODATAOUT_REG, reg);
    321  1.1  uch 		}
    322  1.1  uch #endif /* TX39IO_MFIOOUTPORT_ON */
    323  1.1  uch 		printf("Out");
    324  1.1  uch 	} else {
    325  1.1  uch 		printf("In ");
    326  1.1  uch 		if (func) {
    327  1.1  uch 			/* Positive Edge */
    328  1.1  uch 			tx_intr_establish(
    329  1.1  uch 				tc, MAKEINTR(pset, (1 << pofs)),
    330  1.1  uch 				IST_EDGE, IPL_TTY, func, arg);
    331  1.1  uch 			/* Negative Edge */
    332  1.1  uch 			tx_intr_establish(
    333  1.1  uch 				tc, MAKEINTR(nset, (1 << nofs)),
    334  1.1  uch 				IST_EDGE, IPL_TTY, func, arg);
    335  1.1  uch 		}
    336  1.1  uch 	}
    337  1.1  uch 	printf("       ");
    338  1.1  uch 	printf("%d", ISSET(reg_out, i) ? 1 : 0);
    339  1.1  uch 	printf("       ");
    340  1.1  uch 	printf("%d", ISSET(reg_in, i) ? 1 : 0);
    341  1.1  uch 	printf("     ");
    342  1.1  uch 	printf("%s", ISSET(reg_pwr, i) ? "Down  ": "Active");
    343  1.1  uch };
    344  1.1  uch 
    345  1.1  uch #endif /* TX39IODEBUG */
    346