Home | History | Annotate | Line # | Download | only in tx
tx39io.c revision 1.2
      1  1.2  uch /*	$NetBSD: tx39io.c,v 1.2 1999/12/07 17:08:11 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.1  uch 
     44  1.1  uch int	tx39io_match __P((struct device*, struct cfdata*, void*));
     45  1.1  uch void	tx39io_attach __P((struct device*, struct device*, void*));
     46  1.1  uch 
     47  1.1  uch struct tx39io_softc {
     48  1.1  uch 	struct	device sc_dev;
     49  1.1  uch 	tx_chipset_tag_t sc_tc;
     50  1.1  uch };
     51  1.1  uch 
     52  1.1  uch struct cfattach tx39io_ca = {
     53  1.1  uch 	sizeof(struct tx39io_softc), tx39io_match, tx39io_attach
     54  1.1  uch };
     55  1.1  uch 
     56  1.1  uch int	tx39io_intr __P((void*));
     57  1.1  uch int	tx39mfio_intr __P((void*));
     58  1.1  uch 
     59  1.1  uch void	tx39io_dump_and_attach_handler __P((struct tx39io_softc*, int));
     60  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*));
     61  1.1  uch 
     62  1.1  uch #define ISSET(x, s)	((x) & (1 << (s)))
     63  1.1  uch #define STD_IN		1
     64  1.1  uch #define STD_OUT		2
     65  1.1  uch #define STD_INOUT	3
     66  1.1  uch 
     67  1.1  uch struct {
     68  1.1  uch 	char *std_pin_name;
     69  1.1  uch 	int  std_type;
     70  1.1  uch } mfio_map[TX39_IO_MFIO_MAX] = {
     71  1.1  uch   [31] = {"CHIFS",	STD_INOUT},
     72  1.1  uch   [30] = {"CHICLK",	STD_INOUT},
     73  1.1  uch   [29] = {"CHIDOUT",	STD_OUT},
     74  1.1  uch   [28] = {"CHIDIN",	STD_IN},
     75  1.1  uch   [27] = {"DREQ",	STD_IN},
     76  1.1  uch   [26] = {"DGRINT",	STD_OUT},
     77  1.1  uch   [25] = {"BC32K",	STD_OUT},
     78  1.1  uch   [24] = {"TXD",	STD_OUT},
     79  1.1  uch   [23] = {"RXD",	STD_IN},
     80  1.1  uch   [22] = {"CS1",	STD_OUT},
     81  1.1  uch   [21] = {"CS2",	STD_OUT},
     82  1.1  uch   [20] = {"CS3",	STD_OUT},
     83  1.1  uch   [19] = {"MCS0",	STD_OUT},
     84  1.1  uch   [18] = {"MCS1",	STD_OUT},
     85  1.1  uch #ifdef TX391X
     86  1.1  uch   [17] = {"MCS2",	STD_OUT},
     87  1.1  uch   [16] = {"MCS3",	STD_OUT},
     88  1.1  uch #endif /* TX391X */
     89  1.1  uch #ifdef TX392X
     90  1.1  uch   [17] = {"RXPWR",	STD_OUT},
     91  1.1  uch   [16] = {"IROUT",	STD_OUT},
     92  1.1  uch #endif /* TX392X */
     93  1.1  uch   [15] = {"SPICLK",	STD_OUT},
     94  1.1  uch   [14] = {"SPIOUT",	STD_OUT},
     95  1.1  uch   [13] = {"SPIN",	STD_IN},
     96  1.1  uch   [12] = {"SIBMCLK",	STD_INOUT},
     97  1.1  uch   [11] = {"CARDREG",	STD_OUT},
     98  1.1  uch   [10] = {"CARDIOWR",	STD_OUT},
     99  1.1  uch    [9] = {"CARDIORD",	STD_OUT},
    100  1.1  uch    [8] = {"CARD1CSL",	STD_OUT},
    101  1.1  uch    [7] = {"CARD1CSH",	STD_OUT},
    102  1.1  uch    [6] = {"CARD2CSL",	STD_OUT},
    103  1.1  uch    [5] = {"CARD2CSH",	STD_OUT},
    104  1.1  uch    [4] = {"CARD1WAIT",	STD_IN},
    105  1.1  uch    [3] = {"CARD2WAIT",	STD_IN},
    106  1.1  uch    [2] = {"CARDDIR",	STD_OUT},
    107  1.1  uch #ifdef TX391X
    108  1.1  uch    [1] = {"MFIO[1]",	0},
    109  1.1  uch    [0] = {"MFIO[0]",	0}
    110  1.1  uch #endif /* TX391X */
    111  1.1  uch #ifdef TX392X
    112  1.1  uch    [1] = {"MCS1WAIT",	0},
    113  1.1  uch    [0] = {"MCS0WAIT",	0}
    114  1.1  uch #endif /* TX392X */
    115  1.1  uch };
    116  1.1  uch 
    117  1.1  uch int
    118  1.1  uch tx39io_match(parent, cf, aux)
    119  1.1  uch 	struct device *parent;
    120  1.1  uch 	struct cfdata *cf;
    121  1.1  uch 	void *aux;
    122  1.1  uch {
    123  1.1  uch 
    124  1.1  uch 	return 1;
    125  1.1  uch }
    126  1.1  uch 
    127  1.1  uch int
    128  1.1  uch tx39io_intr(arg)
    129  1.1  uch 	void *arg;
    130  1.1  uch {
    131  1.1  uch #ifdef TX39_DEBUG
    132  1.2  uch #if 0
    133  1.1  uch 	static int i;
    134  1.1  uch 	if (i ^= 1) {
    135  1.1  uch 		tx39debugflag = 1;
    136  1.1  uch 	} else {
    137  1.1  uch 		tx39debugflag = 0;
    138  1.1  uch 	}
    139  1.2  uch #endif
    140  1.1  uch 	printf("io (%d:%d)\n", (tx39intrvec >> 16) & 0xffff,
    141  1.1  uch 	       tx39intrvec & 0xfff);
    142  1.1  uch #endif
    143  1.1  uch 	return 0;
    144  1.1  uch }
    145  1.1  uch 
    146  1.1  uch int
    147  1.1  uch tx39mfio_intr(arg)
    148  1.1  uch 	void *arg;
    149  1.1  uch {
    150  1.1  uch #ifdef TX39_DEBUG
    151  1.2  uch #if 0
    152  1.1  uch 	struct tx39io_softc *sc = arg;
    153  1.1  uch 	tx39io_dump_and_attach_handler(sc, 0);
    154  1.1  uch #endif
    155  1.1  uch 	printf("mfio (%d:%d)\n", (tx39intrvec >> 16) & 0xffff,
    156  1.1  uch 	       tx39intrvec & 0xfff);
    157  1.1  uch #endif
    158  1.1  uch 	return 0;
    159  1.1  uch }
    160  1.1  uch 
    161  1.1  uch void
    162  1.1  uch tx39io_attach(parent, self, aux)
    163  1.1  uch 	struct device *parent;
    164  1.1  uch 	struct device *self;
    165  1.1  uch 	void *aux;
    166  1.1  uch {
    167  1.1  uch 	struct txsim_attach_args *ta = aux;
    168  1.1  uch 	struct tx39io_softc *sc = (void*)self;
    169  1.1  uch 	tx_chipset_tag_t tc;
    170  1.1  uch 	tc = sc->sc_tc = ta->ta_tc;
    171  1.1  uch 
    172  1.1  uch 	printf("\n");
    173  1.1  uch #ifdef COMPAQ_LOCAL_INTR
    174  1.1  uch 	/* 2010c Rec button */
    175  1.1  uch 	tx_intr_establish(tc, MAKEINTR(5, (1<<6)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    176  1.1  uch 	/* Play button */
    177  1.1  uch 	tx_intr_establish(tc, MAKEINTR(5, (1<<5)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    178  1.1  uch 	/* It seems that these interrupt arise when serial session start */
    179  1.1  uch 	tx_intr_establish(tc, MAKEINTR(3, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    180  1.1  uch 	tx_intr_establish(tc, MAKEINTR(3, (1<<5)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    181  1.1  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    182  1.1  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<5)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    183  1.2  uch #endif
    184  1.2  uch 
    185  1.2  uch #ifdef VICTOR_INTERLINK_INTR
    186  1.2  uch 	/* open panel */
    187  1.2  uch 	tx_intr_establish(tc, MAKEINTR(8, (1<<20)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    188  1.2  uch 	/* close panel */
    189  1.2  uch 	tx_intr_establish(tc, MAKEINTR(8, (1<<4)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    190  1.2  uch 	/* serial session */
    191  1.2  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<29)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    192  1.2  uch 	tx_intr_establish(tc, MAKEINTR(4, (1<<30)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    193  1.2  uch 	/* REC button */
    194  1.2  uch 	tx_intr_establish(tc, MAKEINTR(8, (1<<7)), IST_EDGE, IPL_CLOCK, tx39io_intr, sc);
    195  1.2  uch 	/* kbd */
    196  1.2  uch 	tx_intr_establish(tc, MAKEINTR(3, (1<<7)), IST_EDGE, IPL_CLOCK, tx39mfio_intr, sc);
    197  1.1  uch #endif
    198  1.1  uch 
    199  1.1  uch #ifdef TX39IODEBUG
    200  1.1  uch 	tx39io_dump_and_attach_handler(sc, TX39IO_ATTACH_DUMMYHANDLER);
    201  1.1  uch #endif /* TX39IODEBUG */
    202  1.1  uch }
    203  1.1  uch 
    204  1.1  uch #ifdef TX39IODEBUG
    205  1.1  uch void
    206  1.1  uch tx39io_dump_and_attach_handler(sc, dummy)
    207  1.1  uch 	struct tx39io_softc *sc;
    208  1.1  uch 	int dummy;
    209  1.1  uch {
    210  1.1  uch 	tx_chipset_tag_t tc;
    211  1.1  uch 	u_int32_t reg, reg_out, reg_dir, reg_in, reg_sel, reg_pwr, reg_deb;
    212  1.1  uch 	int i;
    213  1.1  uch 	int (*iointr) __P((void*));
    214  1.1  uch 	int (*mfiointr) __P((void*));
    215  1.1  uch 
    216  1.1  uch 	tc = sc->sc_tc;
    217  1.1  uch 	if (dummy) {
    218  1.1  uch 		iointr =  tx39io_intr;
    219  1.1  uch 		mfiointr = tx39mfio_intr;
    220  1.1  uch 	} else {
    221  1.1  uch 		iointr = mfiointr = 0;
    222  1.1  uch 	}
    223  1.1  uch 
    224  1.1  uch 	printf("--------------------------------------------------------------\n");
    225  1.1  uch 	printf("	 Debounce Direction DataOut DataIn PowerDown Select\n");
    226  1.1  uch 	printf("--------------------------------------------------------------\n");
    227  1.1  uch 	/* IO */
    228  1.1  uch 	reg = tx_conf_read(tc, TX39_IOCTRL_REG);
    229  1.1  uch 	reg_deb = TX39_IOCTRL_IODEBSEL(reg);
    230  1.1  uch 	reg_dir = TX39_IOCTRL_IODIREC(reg);
    231  1.1  uch #ifdef TX391X
    232  1.1  uch 	reg_out = TX39_IOCTRL_IODOUT(reg);
    233  1.1  uch 	reg_in  = TX39_IOCTRL_IODIN(reg);
    234  1.1  uch #endif /* TX391X */
    235  1.1  uch #ifdef TX392X
    236  1.1  uch 	reg = tx_conf_read(tc, TX39_IODATAINOUT_REG);
    237  1.1  uch 	reg_out = TX39_IODATAINOUT_DOUT(reg);
    238  1.1  uch 	reg_in  = TX39_IODATAINOUT_DIN(reg);
    239  1.1  uch #endif /* TX392X */
    240  1.1  uch 	reg = tx_conf_read(tc, TX39_IOIOPOWERDWN_REG);
    241  1.1  uch 	reg_pwr = TX39_IOIOPOWERDWN_IOPD(reg);
    242  1.1  uch 	for (i = TX39_IO_IO_MAX - 1; i >= 0 ; i--) {
    243  1.1  uch 		printf("IO   %2d:    ", i);
    244  1.1  uch 		printf("%s", ISSET(reg_dir, i) ? "On " : "Off");
    245  1.1  uch 		printf("      ");
    246  1.1  uch 		__dump_and_attach_handler(tc, reg_dir, reg_out, reg_in,
    247  1.1  uch 					  reg_pwr, i, 1, iointr, sc);
    248  1.1  uch 
    249  1.1  uch 		printf("    -");
    250  1.1  uch 		printf("\n");
    251  1.1  uch 	}
    252  1.1  uch 	/* MFIO */
    253  1.1  uch 	printf("--------------------------------------------------------------\n");
    254  1.1  uch 	reg_out = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
    255  1.1  uch 	reg_dir = tx_conf_read(tc, TX39_IOMFIODATADIR_REG);
    256  1.1  uch 	reg_in  = tx_conf_read(tc, TX39_IOMFIODATAIN_REG);
    257  1.1  uch 	reg_sel = tx_conf_read(tc, TX39_IOMFIODATASEL_REG);
    258  1.1  uch 	reg_pwr = tx_conf_read(tc, TX39_IOMFIOPOWERDWN_REG);
    259  1.1  uch 	for (i = TX39_IO_MFIO_MAX - 1; i >= 0 ; i--) {
    260  1.1  uch 		printf("MFIO %2d:     -       ", i);
    261  1.1  uch 		__dump_and_attach_handler(tc, reg_dir, reg_out, reg_in,
    262  1.1  uch 					  reg_pwr, i, 0, mfiointr, sc);
    263  1.1  uch 		printf("  ");
    264  1.1  uch 		printf(ISSET(reg_sel, i) ? "MFIO(%s)" : "%s",
    265  1.1  uch 		       mfio_map[i].std_pin_name);
    266  1.1  uch 		printf("\n");
    267  1.1  uch 	}
    268  1.1  uch 	printf("--------------------------------------------------------------\n");
    269  1.1  uch }
    270  1.1  uch 
    271  1.1  uch void
    272  1.1  uch __dump_and_attach_handler(tc, reg_dir, reg_out, reg_in, reg_pwr,
    273  1.1  uch 			  i, io, func, arg)
    274  1.1  uch 	tx_chipset_tag_t tc;
    275  1.1  uch 	u_int32_t reg_dir, reg_out, reg_in, reg_pwr;
    276  1.1  uch 	int i, io;
    277  1.1  uch 	int (*func) __P((void*));
    278  1.1  uch 	void *arg;
    279  1.1  uch {
    280  1.1  uch 	int pset, nset, pofs, nofs;
    281  1.1  uch 
    282  1.1  uch 	if (io) {
    283  1.1  uch #ifdef TX391X
    284  1.1  uch 		pset = nset = 5;
    285  1.1  uch 		pofs = i + 7;
    286  1.1  uch 		nofs = i;
    287  1.1  uch #endif
    288  1.1  uch #ifdef TX392X
    289  1.1  uch 		pset = nset = 8;
    290  1.1  uch 		pofs = i + 16;
    291  1.1  uch 		nofs = i;
    292  1.1  uch #endif
    293  1.1  uch 	} else {
    294  1.1  uch 		pset = 3;
    295  1.1  uch 		nset = 4;
    296  1.1  uch 		pofs = nofs = i;
    297  1.1  uch 	}
    298  1.1  uch 
    299  1.1  uch 	if (ISSET(reg_dir, i)) {
    300  1.1  uch #ifdef TX39IO_MFIOOUTPORT_ON
    301  1.1  uch 		txreg_t reg;
    302  1.1  uch 		if (io) {
    303  1.1  uch #ifdef TX392X
    304  1.1  uch 			reg = tx_conf_read(tc, TX39_IODATAINOUT_REG);
    305  1.1  uch 			reg |= (1 << (i + 16));
    306  1.1  uch 			tx_conf_write(tc, TX39_IODATAINOUT_REG, reg);
    307  1.1  uch #endif /* TX392X */
    308  1.1  uch 		} else {
    309  1.1  uch 			reg = tx_conf_read(tc, TX39_IOMFIODATAOUT_REG);
    310  1.1  uch 			reg |= (1 << i);
    311  1.1  uch 			tx_conf_write(tc, TX39_IOMFIODATAOUT_REG, reg);
    312  1.1  uch 		}
    313  1.1  uch #endif /* TX39IO_MFIOOUTPORT_ON */
    314  1.1  uch 		printf("Out");
    315  1.1  uch 	} else {
    316  1.1  uch 		printf("In ");
    317  1.1  uch 		if (func) {
    318  1.1  uch 			/* Positive Edge */
    319  1.1  uch 			tx_intr_establish(
    320  1.1  uch 				tc, MAKEINTR(pset, (1 << pofs)),
    321  1.1  uch 				IST_EDGE, IPL_TTY, func, arg);
    322  1.1  uch 			/* Negative Edge */
    323  1.1  uch 			tx_intr_establish(
    324  1.1  uch 				tc, MAKEINTR(nset, (1 << nofs)),
    325  1.1  uch 				IST_EDGE, IPL_TTY, func, arg);
    326  1.1  uch 		}
    327  1.1  uch 	}
    328  1.1  uch 	printf("       ");
    329  1.1  uch 	printf("%d", ISSET(reg_out, i) ? 1 : 0);
    330  1.1  uch 	printf("       ");
    331  1.1  uch 	printf("%d", ISSET(reg_in, i) ? 1 : 0);
    332  1.1  uch 	printf("     ");
    333  1.1  uch 	printf("%s", ISSET(reg_pwr, i) ? "Down  ": "Active");
    334  1.1  uch };
    335  1.1  uch 
    336  1.1  uch #endif /* TX39IODEBUG */
    337