Home | History | Annotate | Line # | Download | only in tx
tx39power.c revision 1.3.2.1
      1  1.3.2.1  wrstuden /*	$NetBSD: tx39power.c,v 1.3.2.1 1999/12/27 18:32:12 wrstuden 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_tx39powerdebug.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 #include <machine/intr.h>
     37      1.1       uch 
     38      1.1       uch #include <hpcmips/tx/tx39var.h>
     39      1.1       uch #include <hpcmips/tx/tx39icureg.h>
     40      1.1       uch #include <hpcmips/tx/tx39powerreg.h>
     41      1.1       uch #include <hpcmips/tx/tx39spireg.h>
     42      1.1       uch 
     43      1.1       uch #define ISSET(x, v)	((x) & (v))
     44      1.1       uch #define ISSETPRINT(r, m) __is_set_print(r, TX39_POWERCTRL_##m, #m)
     45      1.1       uch 
     46      1.1       uch int	tx39power_match __P((struct device*, struct cfdata*, void*));
     47      1.1       uch void	tx39power_attach __P((struct device*, struct device*, void*));
     48      1.1       uch 
     49      1.1       uch int	tx39power_intr __P((void*));
     50      1.1       uch int	tx39power_ok_intr __P((void*));
     51      1.1       uch int	tx39power_button_intr __P((void*));
     52      1.1       uch 
     53      1.1       uch struct tx39power_softc {
     54      1.1       uch 	struct	device sc_dev;
     55      1.1       uch 	tx_chipset_tag_t sc_tc;
     56      1.1       uch };
     57      1.1       uch 
     58      1.1       uch struct cfattach tx39power_ca = {
     59      1.1       uch 	sizeof(struct tx39power_softc), tx39power_match, tx39power_attach
     60      1.1       uch };
     61      1.1       uch 
     62      1.1       uch int
     63      1.1       uch tx39power_match(parent, cf, aux)
     64      1.1       uch 	struct device *parent;
     65      1.1       uch 	struct cfdata *cf;
     66      1.1       uch 	void *aux;
     67      1.1       uch {
     68      1.1       uch 	return 2; /* 1st attach group of txsim */
     69      1.1       uch }
     70      1.1       uch 
     71      1.1       uch void
     72      1.1       uch tx39power_attach(parent, self, aux)
     73      1.1       uch 	struct device *parent;
     74      1.1       uch 	struct device *self;
     75      1.1       uch 	void *aux;
     76      1.1       uch {
     77      1.1       uch 	struct txsim_attach_args *ta = aux;
     78      1.1       uch 	struct tx39power_softc *sc = (void*)self;
     79      1.1       uch 	tx_chipset_tag_t tc;
     80      1.1       uch 	txreg_t reg;
     81      1.1       uch 
     82      1.1       uch 	tc = sc->sc_tc = ta->ta_tc;
     83      1.2       uch 	printf("\n");
     84      1.1       uch #ifdef TX39POWERDEBUG
     85      1.1       uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
     86      1.1       uch 	ISSETPRINT(reg, ONBUTN);
     87      1.1       uch 	ISSETPRINT(reg, PWRINT);
     88      1.1       uch 	ISSETPRINT(reg, PWROK);
     89      1.1       uch #ifdef TX392X
     90      1.1       uch 	ISSETPRINT(reg, PWROKNMI);
     91      1.1       uch #endif /* TX392X */
     92      1.1       uch 	ISSETPRINT(reg, SLOWBUS);
     93      1.1       uch #ifdef TX391X
     94      1.1       uch 	ISSETPRINT(reg, DIVMOD);
     95      1.1       uch #endif /* TX391X */
     96      1.1       uch 	ISSETPRINT(reg, ENSTPTIMER);
     97      1.1       uch 	ISSETPRINT(reg, ENFORCESHUTDWN);
     98      1.1       uch 	ISSETPRINT(reg, FORCESHUTDWN);
     99      1.1       uch 	ISSETPRINT(reg, FORCESHUTDWNOCC);
    100      1.1       uch 	ISSETPRINT(reg, SELC2MS);
    101      1.1       uch #ifdef TX392X
    102      1.1       uch 	ISSETPRINT(reg, WARMSTART);
    103      1.1       uch #endif /* TX392X */
    104      1.1       uch 	ISSETPRINT(reg, BPDBVCC3);
    105      1.1       uch 	ISSETPRINT(reg, STOPCPU);
    106      1.1       uch 	ISSETPRINT(reg, DBNCONBUTN);
    107      1.1       uch 	ISSETPRINT(reg, COLDSTART);
    108      1.1       uch 	ISSETPRINT(reg, PWRCS);
    109      1.1       uch 	ISSETPRINT(reg, VCCON);
    110      1.1       uch #ifdef TX391X
    111      1.1       uch 	printf("VIDRF=%d ", TX39_POWERCTRL_VIDRF(reg));
    112      1.1       uch #endif /* TX391X */
    113      1.1       uch 	printf("STPTIMERVAL=%d ", TX39_POWERCTRL_STPTIMERVAL(reg));
    114      1.1       uch 	printf("\n");
    115      1.1       uch #endif /* TX39POWERDEBUG */
    116      1.1       uch #ifdef DISABLE_SPI_AND_DOZE /* XXX test XXX */
    117      1.1       uch 	/*
    118      1.1       uch 	 *	Disable SPI module
    119      1.1       uch 	 */
    120      1.1       uch 	reg = tx_conf_read(tc, TX39_SPICTRL_REG);
    121      1.1       uch 	if (ISSET(reg, TX39_SPICTRL_ENSPI)) {
    122      1.1       uch 		reg &= ~TX39_SPICTRL_ENSPI;
    123      1.1       uch 	}
    124      1.1       uch 	printf("SPI module disabled\n");
    125      1.1       uch 
    126      1.1       uch 	/*
    127      1.1       uch 	 *	Disable Stop timer (Doze CPU mode)
    128      1.1       uch 	 */
    129      1.1       uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    130      1.1       uch 	printf("STPTIMER disabled.\n");
    131      1.1       uch 	reg &= ~TX39_POWERCTRL_ENSTPTIMER;
    132      1.1       uch 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    133      1.1       uch #endif /* DISABLE_SPI_AND_DOZE */
    134      1.2       uch 
    135      1.2       uch 	/*
    136      1.2       uch 	 * enable stop timer
    137      1.2       uch 	 */
    138      1.2       uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    139      1.3       uch 
    140      1.3       uch 	reg &= ~(TX39_POWERCTRL_STPTIMERVAL_MASK <<
    141      1.3       uch 		 TX39_POWERCTRL_STPTIMERVAL_SHIFT);
    142      1.3       uch 	reg = TX39_POWERCTRL_STPTIMERVAL_SET(reg, 1);
    143      1.3       uch 
    144      1.2       uch 	reg |= TX39_POWERCTRL_ENSTPTIMER;
    145      1.2       uch 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    146      1.1       uch 
    147      1.1       uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWRINT),
    148      1.1       uch 			    IST_EDGE, IPL_CLOCK,
    149      1.1       uch 			    tx39power_intr, sc);
    150      1.1       uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWRINT),
    151      1.1       uch 			    IST_EDGE, IPL_CLOCK,
    152      1.1       uch 			    tx39power_intr, sc);
    153      1.1       uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWROKINT),
    154      1.1       uch 			    IST_EDGE, IPL_CLOCK,
    155      1.1       uch 			    tx39power_ok_intr, sc);
    156      1.1       uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWROKINT),
    157      1.1       uch 			    IST_EDGE, IPL_CLOCK,
    158      1.1       uch 			    tx39power_ok_intr, sc);
    159      1.1       uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSONBUTNINT),
    160      1.1       uch 			    IST_EDGE, IPL_CLOCK,
    161      1.1       uch 			    tx39power_button_intr, sc);
    162      1.1       uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGONBUTNINT),
    163      1.1       uch 			    IST_EDGE, IPL_CLOCK,
    164      1.1       uch 			    tx39power_button_intr, sc);
    165      1.1       uch 
    166      1.1       uch }
    167      1.1       uch 
    168      1.1       uch int
    169      1.1       uch tx39power_button_intr(arg)
    170      1.1       uch 	void *arg;
    171      1.1       uch {
    172      1.1       uch 	printf("power button\n");
    173      1.1       uch 	return 0;
    174      1.1       uch }
    175      1.1       uch 
    176      1.1       uch int
    177      1.1       uch tx39power_intr(arg)
    178      1.1       uch 	void *arg;
    179      1.1       uch {
    180      1.1       uch 	printf("power\n");
    181      1.1       uch 	return 0;
    182      1.1       uch }
    183      1.1       uch 
    184      1.1       uch int
    185      1.1       uch tx39power_ok_intr(arg)
    186      1.1       uch 	void *arg;
    187      1.1       uch {
    188      1.1       uch 	printf("power ok\n");
    189      1.1       uch 	return 0;
    190      1.1       uch }
    191