tx39biu.c revision 1.1       1  1.1  uch /*	$NetBSD: tx39biu.c,v 1.1 1999/11/20 19:56:32 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_tx39_watchdogtimer.h"
     30  1.1  uch #include "opt_tx39biudebug.h"
     31  1.1  uch 
     32  1.1  uch #include <sys/param.h>
     33  1.1  uch #include <sys/systm.h>
     34  1.1  uch #include <sys/device.h>
     35  1.1  uch 
     36  1.1  uch #include <machine/bus.h>
     37  1.1  uch 
     38  1.1  uch #include <hpcmips/tx/tx39var.h>
     39  1.1  uch #include <hpcmips/tx/tx39biureg.h>
     40  1.1  uch 
     41  1.1  uch #include <hpcmips/tx/txcsbusvar.h>
     42  1.1  uch 
     43  1.1  uch #define ISSET(x, s)	((x) & (1 << (s)))
     44  1.1  uch #define ISSETPRINT(r, s, m) __is_set_print((u_int32_t)(r), \
     45  1.1  uch 	TX39_MEMCONFIG##s##_##m, #m)
     46  1.1  uch 
     47  1.1  uch int	tx39biu_match __P((struct device*, struct cfdata*, void*));
     48  1.1  uch void	tx39biu_attach __P((struct device*, struct device*, void*));
     49  1.1  uch void	tx39biu_callback __P((struct device*));
     50  1.1  uch int	tx39biu_print __P((void*, const char*));
     51  1.1  uch int	tx39biu_intr __P((void*));
     52  1.1  uch 
     53  1.1  uch static void *__sc; /* XXX */
     54  1.1  uch 
     55  1.1  uch void	tx39biu_dump __P((tx_chipset_tag_t));
     56  1.1  uch 
     57  1.1  uch struct tx39biu_softc {
     58  1.1  uch 	struct	device sc_dev;
     59  1.1  uch 	tx_chipset_tag_t sc_tc;
     60  1.1  uch };
     61  1.1  uch 
     62  1.1  uch struct cfattach tx39biu_ca = {
     63  1.1  uch 	sizeof(struct tx39biu_softc), tx39biu_match, tx39biu_attach
     64  1.1  uch };
     65  1.1  uch 
     66  1.1  uch int
     67  1.1  uch tx39biu_match(parent, cf, aux)
     68  1.1  uch 	struct device *parent;
     69  1.1  uch 	struct cfdata *cf;
     70  1.1  uch 	void *aux;
     71  1.1  uch {
     72  1.1  uch 	return 1;
     73  1.1  uch }
     74  1.1  uch 
     75  1.1  uch void
     76  1.1  uch tx39biu_attach(parent, self, aux)
     77  1.1  uch 	struct device *parent;
     78  1.1  uch 	struct device *self;
     79  1.1  uch 	void *aux;
     80  1.1  uch {
     81  1.1  uch 	struct txsim_attach_args *ta = aux;
     82  1.1  uch 	struct tx39biu_softc *sc = (void*)self;
     83  1.1  uch 	tx_chipset_tag_t tc;
     84  1.1  uch #ifdef TX39_WATCHDOGTIMER
     85  1.1  uch 	txreg_t reg;
     86  1.1  uch #endif
     87  1.1  uch 
     88  1.1  uch 	sc->sc_tc = tc = ta->ta_tc;
     89  1.1  uch 	printf("\n");
     90  1.1  uch #ifdef TX39BIUDEBUG
     91  1.1  uch 	tx39biu_dump(tc);
     92  1.1  uch #endif
     93  1.1  uch 
     94  1.1  uch #ifdef TX39_WATCHDOGTIMER
     95  1.1  uch 	/*
     96  1.1  uch 	 * CLRWRBUSERRINT Bus error connected CPU HwInt0
     97  1.1  uch 	 */
     98  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
     99  1.1  uch 	reg |= TX39_MEMCONFIG4_ENWATCH;
    100  1.1  uch 	reg = TX39_MEMCONFIG4_WATCHTIMEVAL_SET(reg, 0xf);
    101  1.1  uch 	tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
    102  1.1  uch 
    103  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    104  1.1  uch 	if (reg & TX39_MEMCONFIG4_ENWATCH) {
    105  1.1  uch 		int i;
    106  1.1  uch 		i = TX39_MEMCONFIG4_WATCHTIMEVAL(reg);
    107  1.1  uch 		i = (1000 * (i + 1) * 64) / 36864;
    108  1.1  uch 		printf("WatchDogTimerRate: %dus\n", i);
    109  1.1  uch 	}
    110  1.1  uch #endif
    111  1.1  uch 	__sc = sc;
    112  1.1  uch 
    113  1.1  uch 	/*	Clear watch dog timer interrupt */
    114  1.1  uch 	tx39biu_intr(sc);
    115  1.1  uch 
    116  1.1  uch 	/*
    117  1.1  uch 	 *	Chip select virtual bridge
    118  1.1  uch 	 */
    119  1.1  uch 	config_defer(self, tx39biu_callback);
    120  1.1  uch }
    121  1.1  uch 
    122  1.1  uch void
    123  1.1  uch tx39biu_callback(self)
    124  1.1  uch 	struct device *self;
    125  1.1  uch {
    126  1.1  uch 	struct tx39biu_softc *sc = (void*)self;
    127  1.1  uch 	struct csbus_attach_args cba;
    128  1.1  uch 
    129  1.1  uch 	cba.cba_busname = "txcsbus";
    130  1.1  uch 	cba.cba_tc = sc->sc_tc;
    131  1.1  uch 	config_found(self, &cba, tx39biu_print);
    132  1.1  uch }
    133  1.1  uch 
    134  1.1  uch int
    135  1.1  uch tx39biu_print(aux, pnp)
    136  1.1  uch 	void *aux;
    137  1.1  uch 	const char *pnp;
    138  1.1  uch {
    139  1.1  uch 	return pnp ? QUIET : UNCONF;
    140  1.1  uch }
    141  1.1  uch 
    142  1.1  uch int
    143  1.1  uch tx39biu_intr(arg)
    144  1.1  uch 	void *arg;
    145  1.1  uch {
    146  1.1  uch 	struct tx39biu_softc *sc = __sc;
    147  1.1  uch 	tx_chipset_tag_t tc;
    148  1.1  uch 	txreg_t reg;
    149  1.1  uch 
    150  1.1  uch 	if (!sc) {
    151  1.1  uch 		return 0;
    152  1.1  uch 	}
    153  1.1  uch 	tc = sc->sc_tc;
    154  1.1  uch 	/* Clear interrupt */
    155  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    156  1.1  uch 	reg |= TX39_MEMCONFIG4_CLRWRBUSERRINT;
    157  1.1  uch 	tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
    158  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    159  1.1  uch 	reg &= ~TX39_MEMCONFIG4_CLRWRBUSERRINT;
    160  1.1  uch 	tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
    161  1.1  uch 
    162  1.1  uch 	return 0;
    163  1.1  uch }
    164  1.1  uch 
    165  1.1  uch void
    166  1.1  uch tx39biu_dump(tc) /* XXX 3912 only. 3922 has something different register map.*/
    167  1.1  uch 	tx_chipset_tag_t tc;
    168  1.1  uch {
    169  1.1  uch 	char *rowsel[] = {"18,17:9", "22,18,20,19,17:9", "20,22,21,19,17:9", "22,23,21,19,17:9"};
    170  1.1  uch 	char *colsel[] = {"22,20,18,8:1", "19,18,8:2", "21,20,18,8:2", "23,22,20,18,8:2",
    171  1.1  uch 			 "24,22,20,18,8:2", "18,p,X,8:0","22,p,X,21,8:0", "18,p,X,21,8:1",
    172  1.1  uch 			 "22,p,X,23,21,8:1", "24,23,21,8:2"};
    173  1.1  uch 	txreg_t reg;
    174  1.1  uch 	int i;
    175  1.1  uch 	/*
    176  1.1  uch 	 *	Memory config 0 register
    177  1.1  uch 	 */
    178  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
    179  1.1  uch 	printf(" config0:");
    180  1.1  uch 	ISSETPRINT(reg, 0, ENDCLKOUTTRI);
    181  1.1  uch 	ISSETPRINT(reg, 0, DISDQMINIT);
    182  1.1  uch 	ISSETPRINT(reg, 0, ENSDRAMPD);
    183  1.1  uch 	ISSETPRINT(reg, 0, SHOWDINO);
    184  1.1  uch 	ISSETPRINT(reg, 0, ENRMAP2);
    185  1.1  uch 	ISSETPRINT(reg, 0, ENRMAP1);
    186  1.1  uch 	ISSETPRINT(reg, 0, ENWRINPAGE);
    187  1.1  uch 	ISSETPRINT(reg, 0, ENCS3USER);
    188  1.1  uch 	ISSETPRINT(reg, 0, ENCS2USER);
    189  1.1  uch 	ISSETPRINT(reg, 0, ENCS1USER);
    190  1.1  uch 	ISSETPRINT(reg, 0, ENCS1DRAM);
    191  1.1  uch 	ISSETPRINT(reg, 0, CS3SIZE);
    192  1.1  uch 	ISSETPRINT(reg, 0, CS2SIZE);
    193  1.1  uch 	ISSETPRINT(reg, 0, CS1SIZE);
    194  1.1  uch 	ISSETPRINT(reg, 0, CS0SIZE);
    195  1.1  uch 	printf("\n");
    196  1.1  uch 	for (i = 0; i < 2; i++) {
    197  1.1  uch 		int r, c;
    198  1.1  uch 		printf(" BANK%d: ", i);
    199  1.1  uch 		switch (i ? TX39_MEMCONFIG0_BANK1CONF(reg)
    200  1.1  uch 			: TX39_MEMCONFIG0_BANK0CONF(reg)) {
    201  1.1  uch 		case TX39_MEMCONFIG0_BANKCONF_16BITSDRAM:
    202  1.1  uch 			printf("16bit SDRAM");
    203  1.1  uch 			break;
    204  1.1  uch 		case TX39_MEMCONFIG0_BANKCONF_8BITSDRAM:
    205  1.1  uch 			printf("8bit SDRAM");
    206  1.1  uch 			break;
    207  1.1  uch 		case TX39_MEMCONFIG0_BANKCONF_32BITSDHDRAM:
    208  1.1  uch 			printf("32bit DRAM/HDRAM");
    209  1.1  uch 			break;
    210  1.1  uch 		case TX39_MEMCONFIG0_BANKCONF_16BITSDHDRAM:
    211  1.1  uch 			printf("16bit DRAM/HDRAM");
    212  1.1  uch 			break;
    213  1.1  uch 		}
    214  1.1  uch 		if (i == 1) {
    215  1.1  uch 			r = TX39_MEMCONFIG0_ROWSEL1(reg);
    216  1.1  uch 			c = TX39_MEMCONFIG0_COLSEL1(reg);
    217  1.1  uch 		} else {
    218  1.1  uch 			r = TX39_MEMCONFIG0_ROWSEL0(reg);
    219  1.1  uch 			c = TX39_MEMCONFIG0_COLSEL0(reg);
    220  1.1  uch 		}
    221  1.1  uch 		printf(" ROW %s COL %s\n", rowsel[r], colsel[c]);
    222  1.1  uch 	}
    223  1.1  uch 
    224  1.1  uch 	/*
    225  1.1  uch 	 *	Memory config 3 register
    226  1.1  uch 	 */
    227  1.1  uch 	printf(" config3:");
    228  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
    229  1.1  uch #ifdef TX391X
    230  1.1  uch 	ISSETPRINT(reg, 3, ENMCS3PAGE);
    231  1.1  uch 	ISSETPRINT(reg, 3, ENMCS2PAGE);
    232  1.1  uch 	ISSETPRINT(reg, 3, ENMCS1PAGE);
    233  1.1  uch 	ISSETPRINT(reg, 3, ENMCS0PAGE);
    234  1.1  uch #endif /* TX391X */
    235  1.1  uch 	ISSETPRINT(reg, 3, ENCS3PAGE);
    236  1.1  uch 	ISSETPRINT(reg, 3, ENCS2PAGE);
    237  1.1  uch 	ISSETPRINT(reg, 3, ENCS1PAGE);
    238  1.1  uch 	ISSETPRINT(reg, 3, ENCS0PAGE);
    239  1.1  uch 	ISSETPRINT(reg, 3, CARD2WAITEN);
    240  1.1  uch 	ISSETPRINT(reg, 3, CARD1WAITEN);
    241  1.1  uch 	ISSETPRINT(reg, 3, CARD2IOEN);
    242  1.1  uch 	ISSETPRINT(reg, 3, CARD1IOEN);
    243  1.1  uch #ifdef TX391X
    244  1.1  uch 	ISSETPRINT(reg, 3, PORT8SEL);
    245  1.1  uch #endif /* TX391X */
    246  1.1  uch #ifdef TX392X
    247  1.1  uch 	ISSETPRINT(reg, 3, CARD2_8SEL);
    248  1.1  uch 	ISSETPRINT(reg, 3, CARD1_8SEL);
    249  1.1  uch #endif /* TX392X */
    250  1.1  uch 
    251  1.1  uch 	printf("\n");
    252  1.1  uch 
    253  1.1  uch 	/*
    254  1.1  uch 	 *	Memory config 4 register
    255  1.1  uch 	 */
    256  1.1  uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    257  1.1  uch 	printf(" config4:");
    258  1.1  uch 	ISSETPRINT(reg, 4, ENBANK1HDRAM);
    259  1.1  uch 	ISSETPRINT(reg, 4, ENBANK0HDRAM);
    260  1.1  uch 	ISSETPRINT(reg, 4, ENARB);
    261  1.1  uch 	ISSETPRINT(reg, 4, DISSNOOP);
    262  1.1  uch 	ISSETPRINT(reg, 4, CLRWRBUSERRINT);
    263  1.1  uch 	ISSETPRINT(reg, 4, ENBANK1OPT);
    264  1.1  uch 	ISSETPRINT(reg, 4, ENBANK0OPT);
    265  1.1  uch 	ISSETPRINT(reg, 4, ENWATCH);
    266  1.1  uch 	ISSETPRINT(reg, 4, MEMPOWERDOWN);
    267  1.1  uch 	ISSETPRINT(reg, 4, ENRFSH1);
    268  1.1  uch 	ISSETPRINT(reg, 4, ENRFSH0);
    269  1.1  uch 	if (reg & TX39_MEMCONFIG4_ENWATCH) {
    270  1.1  uch 		i = TX39_MEMCONFIG4_WATCHTIMEVAL(reg);
    271  1.1  uch 		i = (1000 * (i + 1) * 64) / 36864;
    272  1.1  uch 		printf("WatchDogTimerRate: %dus", i);
    273  1.1  uch 	}
    274  1.1  uch 	printf("\n");
    275  1.1  uch }
    276  1.1  uch 
    277