Home | History | Annotate | Line # | Download | only in tx
tx39biu.c revision 1.5.2.2
      1  1.5.2.2  jdolecek /*	$NetBSD: tx39biu.c,v 1.5.2.2 2002/10/10 18:32:58 jdolecek Exp $ */
      2      1.1       uch 
      3      1.5       uch /*-
      4  1.5.2.1  jdolecek  * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
      5      1.1       uch  * All rights reserved.
      6      1.1       uch  *
      7      1.5       uch  * This code is derived from software contributed to The NetBSD Foundation
      8      1.5       uch  * by UCHIYAMA Yasushi.
      9      1.5       uch  *
     10      1.1       uch  * Redistribution and use in source and binary forms, with or without
     11      1.1       uch  * modification, are permitted provided that the following conditions
     12      1.1       uch  * are met:
     13      1.1       uch  * 1. Redistributions of source code must retain the above copyright
     14      1.1       uch  *    notice, this list of conditions and the following disclaimer.
     15      1.5       uch  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.5       uch  *    notice, this list of conditions and the following disclaimer in the
     17      1.5       uch  *    documentation and/or other materials provided with the distribution.
     18      1.5       uch  * 3. All advertising materials mentioning features or use of this software
     19      1.5       uch  *    must display the following acknowledgement:
     20      1.5       uch  *        This product includes software developed by the NetBSD
     21      1.5       uch  *        Foundation, Inc. and its contributors.
     22      1.5       uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.5       uch  *    contributors may be used to endorse or promote products derived
     24      1.5       uch  *    from this software without specific prior written permission.
     25      1.1       uch  *
     26      1.5       uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.5       uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.5       uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.5       uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.5       uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.5       uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.5       uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.5       uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.5       uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.5       uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.5       uch  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1       uch  */
     38      1.5       uch 
     39      1.1       uch #include "opt_tx39_watchdogtimer.h"
     40  1.5.2.1  jdolecek #include "opt_tx39biu_debug.h"
     41      1.1       uch 
     42      1.1       uch #include <sys/param.h>
     43      1.1       uch #include <sys/systm.h>
     44      1.1       uch #include <sys/device.h>
     45      1.1       uch 
     46      1.1       uch #include <machine/bus.h>
     47  1.5.2.1  jdolecek #include <machine/debug.h>
     48      1.1       uch 
     49      1.1       uch #include <hpcmips/tx/tx39var.h>
     50      1.1       uch #include <hpcmips/tx/tx39biureg.h>
     51      1.1       uch #include <hpcmips/tx/txcsbusvar.h>
     52      1.1       uch 
     53  1.5.2.1  jdolecek #ifdef	TX39BIU_DEBUG
     54  1.5.2.1  jdolecek #define DPRINTF_ENABLE
     55  1.5.2.1  jdolecek #define DPRINTF_DEBUG	tx39biu_debug
     56  1.5.2.1  jdolecek #endif
     57  1.5.2.1  jdolecek #include <machine/debug.h>
     58  1.5.2.1  jdolecek 
     59      1.1       uch #define ISSET(x, s)	((x) & (1 << (s)))
     60  1.5.2.1  jdolecek #define ISSETPRINT(r, s, m) dbg_bitmask_print((u_int32_t)(r),		\
     61  1.5.2.1  jdolecek 	TX39_MEMCONFIG ## s ## _ ##m, #m)
     62      1.1       uch 
     63      1.5       uch int	tx39biu_match(struct device *, struct cfdata *, void *);
     64      1.5       uch void	tx39biu_attach(struct device *, struct device *, void *);
     65      1.5       uch void	tx39biu_callback(struct device *);
     66      1.5       uch int	tx39biu_print(void *, const char *);
     67      1.5       uch int	tx39biu_intr(void *);
     68      1.1       uch 
     69      1.1       uch static void *__sc; /* XXX */
     70  1.5.2.1  jdolecek #ifdef TX39BIU_DEBUG
     71      1.5       uch void	tx39biu_dump(tx_chipset_tag_t);
     72  1.5.2.1  jdolecek #endif
     73      1.1       uch 
     74      1.1       uch struct tx39biu_softc {
     75      1.1       uch 	struct	device sc_dev;
     76      1.1       uch 	tx_chipset_tag_t sc_tc;
     77      1.1       uch };
     78      1.1       uch 
     79  1.5.2.2  jdolecek CFATTACH_DECL(tx39biu, sizeof(struct tx39biu_softc),
     80  1.5.2.2  jdolecek     tx39biu_match, tx39biu_attach, NULL, NULL);
     81      1.1       uch 
     82      1.1       uch int
     83      1.1       uch tx39biu_match(parent, cf, aux)
     84      1.1       uch 	struct device *parent;
     85      1.1       uch 	struct cfdata *cf;
     86      1.1       uch 	void *aux;
     87      1.1       uch {
     88      1.5       uch 	return (ATTACH_NORMAL);
     89      1.1       uch }
     90      1.1       uch 
     91      1.1       uch void
     92      1.1       uch tx39biu_attach(parent, self, aux)
     93      1.1       uch 	struct device *parent;
     94      1.1       uch 	struct device *self;
     95      1.1       uch 	void *aux;
     96      1.1       uch {
     97      1.1       uch 	struct txsim_attach_args *ta = aux;
     98      1.1       uch 	struct tx39biu_softc *sc = (void*)self;
     99      1.1       uch 	tx_chipset_tag_t tc;
    100      1.1       uch #ifdef TX39_WATCHDOGTIMER
    101      1.1       uch 	txreg_t reg;
    102      1.1       uch #endif
    103      1.1       uch 
    104      1.1       uch 	sc->sc_tc = tc = ta->ta_tc;
    105      1.1       uch 	printf("\n");
    106  1.5.2.1  jdolecek #ifdef TX39BIU_DEBUG
    107      1.1       uch 	tx39biu_dump(tc);
    108      1.1       uch #endif
    109      1.1       uch 
    110      1.1       uch #ifdef TX39_WATCHDOGTIMER
    111      1.1       uch 	/*
    112      1.1       uch 	 * CLRWRBUSERRINT Bus error connected CPU HwInt0
    113      1.1       uch 	 */
    114      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    115      1.1       uch 	reg |= TX39_MEMCONFIG4_ENWATCH;
    116      1.1       uch 	reg = TX39_MEMCONFIG4_WATCHTIMEVAL_SET(reg, 0xf);
    117      1.1       uch 	tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
    118      1.1       uch 
    119      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    120      1.1       uch 	if (reg & TX39_MEMCONFIG4_ENWATCH) {
    121      1.1       uch 		int i;
    122      1.1       uch 		i = TX39_MEMCONFIG4_WATCHTIMEVAL(reg);
    123      1.1       uch 		i = (1000 * (i + 1) * 64) / 36864;
    124      1.1       uch 		printf("WatchDogTimerRate: %dus\n", i);
    125      1.1       uch 	}
    126      1.1       uch #endif
    127      1.1       uch 	__sc = sc;
    128      1.1       uch 
    129      1.1       uch 	/*	Clear watch dog timer interrupt */
    130      1.1       uch 	tx39biu_intr(sc);
    131      1.1       uch 
    132      1.1       uch 	/*
    133      1.1       uch 	 *	Chip select virtual bridge
    134      1.1       uch 	 */
    135      1.1       uch 	config_defer(self, tx39biu_callback);
    136      1.1       uch }
    137      1.1       uch 
    138      1.1       uch void
    139      1.1       uch tx39biu_callback(self)
    140      1.1       uch 	struct device *self;
    141      1.1       uch {
    142      1.1       uch 	struct tx39biu_softc *sc = (void*)self;
    143      1.1       uch 	struct csbus_attach_args cba;
    144      1.1       uch 
    145      1.1       uch 	cba.cba_busname = "txcsbus";
    146      1.1       uch 	cba.cba_tc = sc->sc_tc;
    147      1.1       uch 	config_found(self, &cba, tx39biu_print);
    148      1.1       uch }
    149      1.1       uch 
    150      1.1       uch int
    151      1.1       uch tx39biu_print(aux, pnp)
    152      1.1       uch 	void *aux;
    153      1.1       uch 	const char *pnp;
    154      1.1       uch {
    155      1.5       uch 	return (pnp ? QUIET : UNCONF);
    156      1.1       uch }
    157      1.1       uch 
    158      1.1       uch int
    159      1.1       uch tx39biu_intr(arg)
    160      1.1       uch 	void *arg;
    161      1.1       uch {
    162      1.1       uch 	struct tx39biu_softc *sc = __sc;
    163      1.1       uch 	tx_chipset_tag_t tc;
    164      1.1       uch 	txreg_t reg;
    165      1.1       uch 
    166      1.1       uch 	if (!sc) {
    167      1.5       uch 		return (0);
    168      1.1       uch 	}
    169      1.1       uch 	tc = sc->sc_tc;
    170      1.1       uch 	/* Clear interrupt */
    171      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    172      1.1       uch 	reg |= TX39_MEMCONFIG4_CLRWRBUSERRINT;
    173      1.1       uch 	tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
    174      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    175      1.1       uch 	reg &= ~TX39_MEMCONFIG4_CLRWRBUSERRINT;
    176      1.1       uch 	tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
    177      1.1       uch 
    178      1.5       uch 	return (0);
    179      1.1       uch }
    180      1.1       uch 
    181  1.5.2.1  jdolecek #ifdef TX39BIU_DEBUG
    182      1.1       uch void
    183      1.2       uch tx39biu_dump(tc)
    184      1.1       uch 	tx_chipset_tag_t tc;
    185      1.1       uch {
    186      1.3       uch 	char *rowsel[] = {"18,17:9", "22,18,20,19,17:9", "20,22,21,19,17:9",
    187      1.3       uch 			  "22,23,21,19,17:9"};
    188      1.3       uch 	char *colsel[] = {"22,20,18,8:1", "19,18,8:2", "21,20,18,8:2",
    189      1.3       uch 			  "23,22,20,18,8:2", "24,22,20,18,8:2",
    190      1.3       uch 			  "18,p,X,8:0","22,p,X,21,8:0", "18,p,X,21,8:1",
    191      1.3       uch 			  "22,p,X,23,21,8:1", "24,23,21,8:2"};
    192      1.1       uch 	txreg_t reg;
    193      1.1       uch 	int i;
    194      1.1       uch 	/*
    195      1.1       uch 	 *	Memory config 0 register
    196      1.1       uch 	 */
    197      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
    198      1.1       uch 	printf(" config0:");
    199      1.1       uch 	ISSETPRINT(reg, 0, ENDCLKOUTTRI);
    200      1.1       uch 	ISSETPRINT(reg, 0, DISDQMINIT);
    201      1.1       uch 	ISSETPRINT(reg, 0, ENSDRAMPD);
    202      1.1       uch 	ISSETPRINT(reg, 0, SHOWDINO);
    203      1.1       uch 	ISSETPRINT(reg, 0, ENRMAP2);
    204      1.1       uch 	ISSETPRINT(reg, 0, ENRMAP1);
    205      1.1       uch 	ISSETPRINT(reg, 0, ENWRINPAGE);
    206      1.1       uch 	ISSETPRINT(reg, 0, ENCS3USER);
    207      1.1       uch 	ISSETPRINT(reg, 0, ENCS2USER);
    208      1.1       uch 	ISSETPRINT(reg, 0, ENCS1USER);
    209      1.1       uch 	ISSETPRINT(reg, 0, ENCS1DRAM);
    210      1.1       uch 	ISSETPRINT(reg, 0, CS3SIZE);
    211      1.1       uch 	ISSETPRINT(reg, 0, CS2SIZE);
    212      1.1       uch 	ISSETPRINT(reg, 0, CS1SIZE);
    213      1.1       uch 	ISSETPRINT(reg, 0, CS0SIZE);
    214      1.1       uch 	printf("\n");
    215      1.1       uch 	for (i = 0; i < 2; i++) {
    216      1.1       uch 		int r, c;
    217      1.1       uch 		printf(" BANK%d: ", i);
    218      1.1       uch 		switch (i ? TX39_MEMCONFIG0_BANK1CONF(reg)
    219      1.5       uch 		    : TX39_MEMCONFIG0_BANK0CONF(reg)) {
    220      1.1       uch 		case TX39_MEMCONFIG0_BANKCONF_16BITSDRAM:
    221      1.1       uch 			printf("16bit SDRAM");
    222      1.1       uch 			break;
    223      1.1       uch 		case TX39_MEMCONFIG0_BANKCONF_8BITSDRAM:
    224      1.1       uch 			printf("8bit SDRAM");
    225      1.1       uch 			break;
    226      1.1       uch 		case TX39_MEMCONFIG0_BANKCONF_32BITSDHDRAM:
    227      1.1       uch 			printf("32bit DRAM/HDRAM");
    228      1.1       uch 			break;
    229      1.1       uch 		case TX39_MEMCONFIG0_BANKCONF_16BITSDHDRAM:
    230      1.1       uch 			printf("16bit DRAM/HDRAM");
    231      1.1       uch 			break;
    232      1.1       uch 		}
    233      1.1       uch 		if (i == 1) {
    234      1.1       uch 			r = TX39_MEMCONFIG0_ROWSEL1(reg);
    235      1.1       uch 			c = TX39_MEMCONFIG0_COLSEL1(reg);
    236      1.1       uch 		} else {
    237      1.1       uch 			r = TX39_MEMCONFIG0_ROWSEL0(reg);
    238      1.1       uch 			c = TX39_MEMCONFIG0_COLSEL0(reg);
    239      1.1       uch 		}
    240      1.1       uch 		printf(" ROW %s COL %s\n", rowsel[r], colsel[c]);
    241      1.1       uch 	}
    242      1.1       uch 
    243      1.1       uch 	/*
    244      1.1       uch 	 *	Memory config 3 register
    245      1.1       uch 	 */
    246      1.1       uch 	printf(" config3:");
    247      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
    248      1.1       uch #ifdef TX391X
    249      1.1       uch 	ISSETPRINT(reg, 3, ENMCS3PAGE);
    250      1.1       uch 	ISSETPRINT(reg, 3, ENMCS2PAGE);
    251      1.1       uch 	ISSETPRINT(reg, 3, ENMCS1PAGE);
    252      1.1       uch 	ISSETPRINT(reg, 3, ENMCS0PAGE);
    253      1.1       uch #endif /* TX391X */
    254      1.1       uch 	ISSETPRINT(reg, 3, ENCS3PAGE);
    255      1.1       uch 	ISSETPRINT(reg, 3, ENCS2PAGE);
    256      1.1       uch 	ISSETPRINT(reg, 3, ENCS1PAGE);
    257      1.1       uch 	ISSETPRINT(reg, 3, ENCS0PAGE);
    258      1.1       uch 	ISSETPRINT(reg, 3, CARD2WAITEN);
    259      1.1       uch 	ISSETPRINT(reg, 3, CARD1WAITEN);
    260      1.1       uch 	ISSETPRINT(reg, 3, CARD2IOEN);
    261      1.1       uch 	ISSETPRINT(reg, 3, CARD1IOEN);
    262      1.1       uch #ifdef TX391X
    263      1.1       uch 	ISSETPRINT(reg, 3, PORT8SEL);
    264      1.1       uch #endif /* TX391X */
    265      1.1       uch #ifdef TX392X
    266      1.1       uch 	ISSETPRINT(reg, 3, CARD2_8SEL);
    267      1.1       uch 	ISSETPRINT(reg, 3, CARD1_8SEL);
    268      1.1       uch #endif /* TX392X */
    269      1.1       uch 
    270      1.1       uch 	printf("\n");
    271      1.1       uch 
    272      1.1       uch 	/*
    273      1.1       uch 	 *	Memory config 4 register
    274      1.1       uch 	 */
    275      1.1       uch 	reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
    276      1.1       uch 	printf(" config4:");
    277      1.1       uch 	ISSETPRINT(reg, 4, ENBANK1HDRAM);
    278      1.1       uch 	ISSETPRINT(reg, 4, ENBANK0HDRAM);
    279      1.1       uch 	ISSETPRINT(reg, 4, ENARB);
    280      1.1       uch 	ISSETPRINT(reg, 4, DISSNOOP);
    281      1.1       uch 	ISSETPRINT(reg, 4, CLRWRBUSERRINT);
    282      1.1       uch 	ISSETPRINT(reg, 4, ENBANK1OPT);
    283      1.1       uch 	ISSETPRINT(reg, 4, ENBANK0OPT);
    284      1.1       uch 	ISSETPRINT(reg, 4, ENWATCH);
    285      1.1       uch 	ISSETPRINT(reg, 4, MEMPOWERDOWN);
    286      1.1       uch 	ISSETPRINT(reg, 4, ENRFSH1);
    287      1.1       uch 	ISSETPRINT(reg, 4, ENRFSH0);
    288      1.1       uch 	if (reg & TX39_MEMCONFIG4_ENWATCH) {
    289      1.1       uch 		i = TX39_MEMCONFIG4_WATCHTIMEVAL(reg);
    290      1.1       uch 		i = (1000 * (i + 1) * 64) / 36864;
    291      1.1       uch 		printf("WatchDogTimerRate: %dus", i);
    292      1.1       uch 	}
    293      1.1       uch 	printf("\n");
    294      1.1       uch }
    295  1.5.2.1  jdolecek #endif /* TX39BIU_DEBUG */
    296