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