tx39power.c revision 1.5       1 /*	$NetBSD: tx39power.c,v 1.5 2000/01/16 21:47:00 uch Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1999, 2000 by UCHIYAMA Yasushi
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. The name of the developer may NOT be used to endorse or promote products
     13  *    derived from this software without specific prior written permission.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  *
     27  */
     28 #include "opt_tx39_debug.h"
     29 #include "opt_tx39powerdebug.h"
     30 #include "opt_ddb.h"
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/device.h>
     35 
     36 #include <machine/bus.h>
     37 #include <machine/intr.h>
     38 
     39 #include <hpcmips/tx/tx39var.h>
     40 #include <hpcmips/tx/tx39icureg.h>
     41 #include <hpcmips/tx/tx39powerreg.h>
     42 #include <hpcmips/tx/tx39spireg.h>
     43 
     44 #undef POWERBUTTON_IS_DEBUGGER
     45 
     46 #define ISSET(x, v)	((x) & (v))
     47 #define ISSETPRINT(r, m) __is_set_print(r, TX39_POWERCTRL_##m, #m)
     48 
     49 int	tx39power_match __P((struct device*, struct cfdata*, void*));
     50 void	tx39power_attach __P((struct device*, struct device*, void*));
     51 
     52 int	tx39power_intr __P((void*));
     53 int	tx39power_ok_intr __P((void*));
     54 int	tx39power_button_intr __P((void*));
     55 
     56 struct tx39power_softc {
     57 	struct	device sc_dev;
     58 	tx_chipset_tag_t sc_tc;
     59 };
     60 
     61 struct cfattach tx39power_ca = {
     62 	sizeof(struct tx39power_softc), tx39power_match, tx39power_attach
     63 };
     64 
     65 int
     66 tx39power_match(parent, cf, aux)
     67 	struct device *parent;
     68 	struct cfdata *cf;
     69 	void *aux;
     70 {
     71 	return 2; /* 1st attach group of txsim */
     72 }
     73 
     74 void
     75 tx39power_attach(parent, self, aux)
     76 	struct device *parent;
     77 	struct device *self;
     78 	void *aux;
     79 {
     80 	struct txsim_attach_args *ta = aux;
     81 	struct tx39power_softc *sc = (void*)self;
     82 	tx_chipset_tag_t tc;
     83 	txreg_t reg;
     84 
     85 	tc = sc->sc_tc = ta->ta_tc;
     86 	tx_conf_register_power(tc, self);
     87 
     88 	printf("\n");
     89 #ifdef TX39POWERDEBUG
     90 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
     91 	ISSETPRINT(reg, ONBUTN);
     92 	ISSETPRINT(reg, PWRINT);
     93 	ISSETPRINT(reg, PWROK);
     94 #ifdef TX392X
     95 	ISSETPRINT(reg, PWROKNMI);
     96 #endif /* TX392X */
     97 	ISSETPRINT(reg, SLOWBUS);
     98 #ifdef TX391X
     99 	ISSETPRINT(reg, DIVMOD);
    100 #endif /* TX391X */
    101 	ISSETPRINT(reg, ENSTPTIMER);
    102 	ISSETPRINT(reg, ENFORCESHUTDWN);
    103 	ISSETPRINT(reg, FORCESHUTDWN);
    104 	ISSETPRINT(reg, FORCESHUTDWNOCC);
    105 	ISSETPRINT(reg, SELC2MS);
    106 #ifdef TX392X
    107 	ISSETPRINT(reg, WARMSTART);
    108 #endif /* TX392X */
    109 	ISSETPRINT(reg, BPDBVCC3);
    110 	ISSETPRINT(reg, STOPCPU);
    111 	ISSETPRINT(reg, DBNCONBUTN);
    112 	ISSETPRINT(reg, COLDSTART);
    113 	ISSETPRINT(reg, PWRCS);
    114 	ISSETPRINT(reg, VCCON);
    115 #ifdef TX391X
    116 	printf("VIDRF=%d ", TX39_POWERCTRL_VIDRF(reg));
    117 #endif /* TX391X */
    118 	printf("STPTIMERVAL=%d ", TX39_POWERCTRL_STPTIMERVAL(reg));
    119 	printf("\n");
    120 #endif /* TX39POWERDEBUG */
    121 #ifdef DISABLE_SPI_AND_DOZE /* XXX test XXX */
    122 	/*
    123 	 *	Disable SPI module
    124 	 */
    125 	reg = tx_conf_read(tc, TX39_SPICTRL_REG);
    126 	if (ISSET(reg, TX39_SPICTRL_ENSPI)) {
    127 		reg &= ~TX39_SPICTRL_ENSPI;
    128 	}
    129 	printf("SPI module disabled\n");
    130 
    131 	/*
    132 	 *	Disable Stop timer (Doze CPU mode)
    133 	 */
    134 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    135 	printf("STPTIMER disabled.\n");
    136 	reg &= ~TX39_POWERCTRL_ENSTPTIMER;
    137 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    138 #endif /* DISABLE_SPI_AND_DOZE */
    139 
    140 	/*
    141 	 * enable stop timer
    142 	 */
    143 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    144 
    145 	reg &= ~(TX39_POWERCTRL_STPTIMERVAL_MASK <<
    146 		 TX39_POWERCTRL_STPTIMERVAL_SHIFT);
    147 	reg = TX39_POWERCTRL_STPTIMERVAL_SET(reg, 1);
    148 
    149 	reg |= TX39_POWERCTRL_ENSTPTIMER;
    150 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    151 
    152 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWRINT),
    153 			    IST_EDGE, IPL_CLOCK,
    154 			    tx39power_intr, sc);
    155 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWRINT),
    156 			    IST_EDGE, IPL_CLOCK,
    157 			    tx39power_intr, sc);
    158 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWROKINT),
    159 			    IST_EDGE, IPL_CLOCK,
    160 			    tx39power_ok_intr, sc);
    161 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWROKINT),
    162 			    IST_EDGE, IPL_CLOCK,
    163 			    tx39power_ok_intr, sc);
    164 #if 0
    165 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSONBUTNINT),
    166 			    IST_EDGE, IPL_CLOCK,
    167 			    tx39power_button_intr, sc);
    168 #endif
    169 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGONBUTNINT),
    170 			    IST_EDGE, IPL_CLOCK,
    171 			    tx39power_button_intr, sc);
    172 
    173 }
    174 
    175 int
    176 tx39power_button_intr(arg)
    177 	void *arg;
    178 {
    179 	printf("power button\n");
    180 #if defined DDB && defined POWERBUTTON_IS_DEBUGGER
    181 	cpu_Debugger();
    182 #endif
    183 	return 0;
    184 }
    185 
    186 int
    187 tx39power_intr(arg)
    188 	void *arg;
    189 {
    190 	printf("power\n");
    191 	return 0;
    192 }
    193 
    194 int
    195 tx39power_ok_intr(arg)
    196 	void *arg;
    197 {
    198 	printf("power NG\n");
    199 	return 0;
    200 }
    201