Home | History | Annotate | Line # | Download | only in tx
tx39power.c revision 1.12.6.2
      1  1.12.6.1    skrll /*	$NetBSD: tx39power.c,v 1.12.6.2 2004/09/18 14:34:59 skrll Exp $ */
      2       1.1      uch 
      3       1.6      uch /*-
      4       1.7      uch  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5       1.7      uch  * All rights reserved.
      6       1.7      uch  *
      7       1.7      uch  * This code is derived from software contributed to The NetBSD Foundation
      8       1.7      uch  * by UCHIYAMA Yasushi.
      9       1.1      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.6      uch  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.6      uch  *    notice, this list of conditions and the following disclaimer in the
     17       1.6      uch  *    documentation and/or other materials provided with the distribution.
     18       1.7      uch  * 3. All advertising materials mentioning features or use of this software
     19       1.7      uch  *    must display the following acknowledgement:
     20       1.7      uch  *        This product includes software developed by the NetBSD
     21       1.7      uch  *        Foundation, Inc. and its contributors.
     22       1.7      uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.7      uch  *    contributors may be used to endorse or promote products derived
     24       1.7      uch  *    from this software without specific prior written permission.
     25       1.1      uch  *
     26       1.7      uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.7      uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.7      uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.7      uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.7      uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.7      uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.7      uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.7      uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.7      uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.7      uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.7      uch  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      uch  */
     38       1.6      uch 
     39  1.12.6.1    skrll #include <sys/cdefs.h>
     40  1.12.6.1    skrll __KERNEL_RCSID(0, "$NetBSD: tx39power.c,v 1.12.6.2 2004/09/18 14:34:59 skrll Exp $");
     41  1.12.6.1    skrll 
     42      1.10      uch #include "opt_tx39power_debug.h"
     43       1.8      uch #define TX39POWERDEBUG
     44       1.1      uch 
     45       1.1      uch #include <sys/param.h>
     46       1.1      uch #include <sys/systm.h>
     47       1.1      uch #include <sys/device.h>
     48       1.1      uch 
     49       1.1      uch #include <machine/bus.h>
     50       1.1      uch #include <machine/intr.h>
     51       1.7      uch #include <machine/config_hook.h>
     52       1.1      uch 
     53       1.1      uch #include <hpcmips/tx/tx39var.h>
     54       1.1      uch #include <hpcmips/tx/tx39icureg.h>
     55       1.1      uch #include <hpcmips/tx/tx39powerreg.h>
     56       1.8      uch 
     57      1.10      uch #ifdef	TX39POWER_DEBUG
     58      1.10      uch #define DPRINTF_ENABLE
     59      1.10      uch #define DPRINTF_DEBUG	tx39power_debug
     60      1.10      uch #endif
     61      1.10      uch #include <machine/debug.h>
     62      1.10      uch 
     63      1.10      uch #ifdef TX39POWER_DEBUG
     64       1.8      uch #define DUMP_REGS(x)		__tx39power_dump(x)
     65       1.8      uch #else
     66       1.8      uch #define DUMP_REGS(x)		((void)0)
     67       1.8      uch #endif
     68       1.1      uch 
     69       1.7      uch #define ISSET(x, v)		((x) & (v))
     70      1.10      uch #define ISSETPRINT(r, m)	dbg_bitmask_print(r, TX39_POWERCTRL_##m, #m)
     71       1.1      uch 
     72       1.7      uch int	tx39power_match(struct device *, struct cfdata *, void *);
     73       1.7      uch void	tx39power_attach(struct device *, struct device *, void *);
     74       1.1      uch 
     75       1.1      uch struct tx39power_softc {
     76       1.1      uch 	struct	device sc_dev;
     77       1.1      uch 	tx_chipset_tag_t sc_tc;
     78       1.7      uch 
     79       1.7      uch 	/* save interrupt status for resume */
     80       1.7      uch 	txreg_t sc_icu_state[TX39_INTRSET_MAX + 1];
     81       1.1      uch };
     82       1.1      uch 
     83      1.12  thorpej CFATTACH_DECL(tx39power, sizeof(struct tx39power_softc),
     84      1.12  thorpej     tx39power_match, tx39power_attach, NULL, NULL);
     85       1.1      uch 
     86       1.7      uch void tx39power_suspend_cpu(void); /* automatic hardware resume */
     87       1.7      uch 
     88       1.7      uch static int tx39power_intr_p(void *);
     89       1.7      uch static int tx39power_intr_n(void *);
     90       1.7      uch static int tx39power_ok_intr_p(void *);
     91       1.7      uch static int tx39power_ok_intr_n(void *);
     92       1.7      uch static int tx39power_button_intr_p(void *);
     93       1.7      uch static int tx39power_button_intr_n(void *);
     94      1.10      uch #ifdef TX39POWER_DEBUG
     95       1.8      uch static void __tx39power_dump(struct tx39power_softc *);
     96       1.7      uch #endif
     97       1.7      uch 
     98       1.1      uch int
     99       1.7      uch tx39power_match(struct device *parent, struct cfdata *cf, void *aux)
    100       1.1      uch {
    101       1.9      uch 	return (ATTACH_FIRST);
    102       1.1      uch }
    103       1.1      uch 
    104       1.1      uch void
    105       1.7      uch tx39power_attach(struct device *parent, struct device *self, void *aux)
    106       1.1      uch {
    107       1.1      uch 	struct txsim_attach_args *ta = aux;
    108       1.1      uch 	struct tx39power_softc *sc = (void*)self;
    109       1.1      uch 	tx_chipset_tag_t tc;
    110       1.1      uch 	txreg_t reg;
    111       1.1      uch 
    112       1.1      uch 	tc = sc->sc_tc = ta->ta_tc;
    113       1.4      uch 	tx_conf_register_power(tc, self);
    114       1.4      uch 
    115       1.2      uch 	printf("\n");
    116       1.8      uch 	DUMP_REGS(sc);
    117       1.8      uch 
    118       1.8      uch 	/* power button setting */
    119       1.8      uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    120       1.8      uch 	reg |= TX39_POWERCTRL_DBNCONBUTN;
    121       1.8      uch 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    122       1.8      uch 
    123       1.8      uch 	/* enable stop timer */
    124       1.2      uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    125       1.3      uch 	reg &= ~(TX39_POWERCTRL_STPTIMERVAL_MASK <<
    126       1.9      uch 	    TX39_POWERCTRL_STPTIMERVAL_SHIFT);
    127       1.8      uch 	reg = TX39_POWERCTRL_STPTIMERVAL_SET(reg,
    128       1.9      uch 	    TX39_POWERCTRL_STPTIMERVAL_MAX);
    129       1.2      uch 	reg |= TX39_POWERCTRL_ENSTPTIMER;
    130       1.2      uch 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    131       1.1      uch 
    132       1.8      uch 	/* install power event handler */
    133       1.8      uch 	/* low priority */
    134       1.1      uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWRINT),
    135       1.9      uch 	    IST_EDGE, IPL_CLOCK,
    136       1.9      uch 	    tx39power_intr_p, sc);
    137       1.1      uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWRINT),
    138       1.9      uch 	    IST_EDGE, IPL_CLOCK,
    139       1.9      uch 	    tx39power_intr_n, sc);
    140       1.8      uch 	/* high priority */
    141       1.1      uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWROKINT),
    142       1.9      uch 	    IST_EDGE, IPL_CLOCK,
    143       1.9      uch 	    tx39power_ok_intr_p, sc);
    144       1.1      uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWROKINT),
    145       1.9      uch 	    IST_EDGE, IPL_CLOCK,
    146       1.9      uch 	    tx39power_ok_intr_n, sc);
    147       1.8      uch 	/* user driven event */
    148       1.1      uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSONBUTNINT),
    149       1.9      uch 	    IST_EDGE, IPL_CLOCK,
    150       1.9      uch 	    tx39power_button_intr_p, sc);
    151       1.7      uch 	tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGONBUTNINT),
    152       1.9      uch 	    IST_EDGE, IPL_CLOCK,
    153       1.9      uch 	    tx39power_button_intr_n, sc);
    154       1.7      uch }
    155       1.7      uch 
    156       1.7      uch void
    157       1.7      uch tx39power_suspend_cpu() /* I assume already splhigh */
    158       1.7      uch {
    159       1.7      uch 	tx_chipset_tag_t tc = tx_conf_get_tag();
    160       1.7      uch 	struct tx39power_softc *sc = tc->tc_powert;
    161       1.7      uch 	txreg_t reg, *iregs = sc->sc_icu_state;
    162       1.7      uch 
    163       1.7      uch 	printf ("%s: CPU sleep\n", sc->sc_dev.dv_xname);
    164       1.7      uch 	__asm__ __volatile__(".set noreorder");
    165       1.7      uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    166       1.7      uch 	reg |= TX39_POWERCTRL_STOPCPU;
    167       1.7      uch 	/* save interrupt state */
    168       1.7      uch 	iregs[0] = tx_conf_read(tc, TX39_INTRENABLE6_REG);
    169       1.7      uch 	iregs[1] = tx_conf_read(tc, TX39_INTRENABLE1_REG);
    170       1.7      uch 	iregs[2] = tx_conf_read(tc, TX39_INTRENABLE2_REG);
    171       1.7      uch 	iregs[3] = tx_conf_read(tc, TX39_INTRENABLE3_REG);
    172       1.7      uch 	iregs[4] = tx_conf_read(tc, TX39_INTRENABLE4_REG);
    173       1.7      uch 	iregs[5] = tx_conf_read(tc, TX39_INTRENABLE5_REG);
    174       1.7      uch #ifdef TX392X
    175       1.7      uch 	iregs[7] = tx_conf_read(tc, TX39_INTRENABLE7_REG);
    176       1.7      uch 	iregs[8] = tx_conf_read(tc, TX39_INTRENABLE8_REG);
    177       1.7      uch #endif
    178       1.7      uch 	/* disable all interrupt (don't disable GLOBALEN) */
    179       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE6_REG, TX39_INTRENABLE6_GLOBALEN);
    180       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE1_REG, 0);
    181       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE2_REG, 0);
    182       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE3_REG, 0);
    183       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE4_REG, 0);
    184       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE5_REG, 0);
    185       1.7      uch #ifdef TX392X
    186       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE7_REG, 0);
    187       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE8_REG, 0);
    188       1.7      uch #endif
    189       1.7      uch 	/* enable power button interrupt only */
    190       1.7      uch 	tx_conf_write(tc, TX39_INTRCLEAR5_REG, TX39_INTRSTATUS5_NEGONBUTNINT);
    191       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE5_REG, TX39_INTRSTATUS5_NEGONBUTNINT);
    192       1.7      uch 	__asm__ __volatile__("sync");
    193       1.7      uch 
    194       1.7      uch 	/* stop CPU clock */
    195       1.7      uch 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    196       1.7      uch 	__asm__ __volatile__("sync");
    197       1.7      uch 	/* wait until power button pressed */
    198       1.7      uch 	/* clear interrupt */
    199       1.7      uch 	tx_conf_write(tc, TX39_INTRCLEAR5_REG, TX39_INTRSTATUS5_NEGONBUTNINT);
    200       1.8      uch #ifdef TX392X
    201       1.8      uch 	/* Clear WARMSTART bit to reset vector(0xbfc00000) work correctly */
    202       1.8      uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    203       1.8      uch 	reg &= ~TX39_POWERCTRL_WARMSTART;
    204       1.8      uch 	tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
    205       1.8      uch #endif
    206       1.7      uch 
    207       1.7      uch 	/* restore interrupt state */
    208       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE6_REG, iregs[0]);
    209       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE1_REG, iregs[1]);
    210       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE2_REG, iregs[2]);
    211       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE3_REG, iregs[3]);
    212       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE4_REG, iregs[4]);
    213       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE5_REG, iregs[5]);
    214       1.7      uch #ifdef TX392X
    215       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE7_REG, iregs[7]);
    216       1.7      uch 	tx_conf_write(tc, TX39_INTRENABLE8_REG, iregs[8]);
    217       1.5      uch #endif
    218       1.7      uch 	__asm__ __volatile__(".set reorder");
    219       1.1      uch 
    220       1.7      uch 	printf ("%s: CPU wakeup\n", sc->sc_dev.dv_xname);
    221       1.1      uch }
    222       1.1      uch 
    223       1.7      uch static int
    224       1.7      uch tx39power_button_intr_p(void *arg)
    225       1.1      uch {
    226       1.7      uch 	config_hook_call(CONFIG_HOOK_BUTTONEVENT,
    227       1.9      uch 	    CONFIG_HOOK_BUTTONEVENT_POWER,
    228       1.9      uch 	    (void *)1 /* on */);
    229       1.9      uch 
    230       1.9      uch 	return (0);
    231       1.7      uch }
    232       1.6      uch 
    233       1.7      uch static int
    234       1.7      uch tx39power_button_intr_n(void *arg)
    235       1.7      uch {
    236       1.7      uch 	config_hook_call(CONFIG_HOOK_BUTTONEVENT,
    237       1.9      uch 	    CONFIG_HOOK_BUTTONEVENT_POWER,
    238       1.9      uch 	    (void *)0 /* off */);
    239       1.8      uch 	DUMP_REGS(arg);
    240       1.9      uch 
    241       1.9      uch 	return (0);
    242       1.1      uch }
    243       1.1      uch 
    244       1.1      uch int
    245       1.7      uch tx39power_intr_p(void *arg)
    246       1.7      uch {
    247       1.8      uch 	/* low priority event */
    248       1.7      uch 	printf("power_p\n");
    249       1.8      uch 	DUMP_REGS(arg);
    250       1.9      uch 
    251       1.9      uch 	return (0);
    252       1.7      uch }
    253       1.7      uch 
    254       1.7      uch static int
    255       1.7      uch tx39power_intr_n(void *arg)
    256       1.1      uch {
    257       1.8      uch 	/* low priority event */
    258       1.7      uch 	printf("power_n\n");
    259       1.8      uch 	DUMP_REGS(arg);
    260       1.9      uch 
    261       1.9      uch 	return (0);
    262       1.1      uch }
    263       1.1      uch 
    264       1.7      uch static int
    265       1.7      uch tx39power_ok_intr_p(void *arg)
    266       1.1      uch {
    267       1.8      uch 	/* high priority event */
    268       1.5      uch 	printf("power NG\n");
    269       1.8      uch 	DUMP_REGS(arg);
    270       1.7      uch 	config_hook_call(CONFIG_HOOK_PMEVENT,
    271       1.9      uch 	    CONFIG_HOOK_PMEVENT_SUSPENDREQ, NULL);
    272       1.9      uch 
    273       1.9      uch 	return (0);
    274       1.1      uch }
    275       1.7      uch 
    276       1.7      uch static int
    277       1.7      uch tx39power_ok_intr_n(void *arg)
    278       1.7      uch {
    279       1.8      uch 	/* high priority event */
    280       1.7      uch 	printf("power OK\n");
    281       1.8      uch 	DUMP_REGS(arg);
    282       1.9      uch 
    283       1.9      uch 	return (0);
    284       1.7      uch }
    285       1.7      uch 
    286      1.10      uch #ifdef TX39POWER_DEBUG
    287       1.7      uch static void
    288       1.7      uch __tx39power_dump (struct tx39power_softc *sc)
    289       1.7      uch {
    290       1.7      uch 	tx_chipset_tag_t tc = sc->sc_tc;
    291       1.8      uch 	txreg_t reg;
    292       1.7      uch 
    293       1.7      uch 	reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
    294       1.7      uch 	ISSETPRINT(reg, ONBUTN);
    295       1.7      uch 	ISSETPRINT(reg, PWRINT);
    296       1.7      uch 	ISSETPRINT(reg, PWROK);
    297       1.7      uch #ifdef TX392X
    298       1.7      uch 	ISSETPRINT(reg, PWROKNMI);
    299       1.7      uch #endif /* TX392X */
    300       1.7      uch 	ISSETPRINT(reg, SLOWBUS);
    301       1.7      uch #ifdef TX391X
    302       1.7      uch 	ISSETPRINT(reg, DIVMOD);
    303       1.7      uch #endif /* TX391X */
    304       1.7      uch 	ISSETPRINT(reg, ENSTPTIMER);
    305       1.7      uch 	ISSETPRINT(reg, ENFORCESHUTDWN);
    306       1.7      uch 	ISSETPRINT(reg, FORCESHUTDWN);
    307       1.7      uch 	ISSETPRINT(reg, FORCESHUTDWNOCC);
    308       1.7      uch 	ISSETPRINT(reg, SELC2MS);
    309       1.7      uch #ifdef TX392X
    310       1.7      uch 	ISSETPRINT(reg, WARMSTART);
    311       1.7      uch #endif /* TX392X */
    312       1.7      uch 	ISSETPRINT(reg, BPDBVCC3);
    313       1.7      uch 	ISSETPRINT(reg, STOPCPU);
    314       1.7      uch 	ISSETPRINT(reg, DBNCONBUTN);
    315       1.7      uch 	ISSETPRINT(reg, COLDSTART);
    316       1.7      uch 	ISSETPRINT(reg, PWRCS);
    317       1.7      uch 	ISSETPRINT(reg, VCCON);
    318       1.7      uch #ifdef TX391X
    319       1.7      uch 	printf("VIDRF=%d ", TX39_POWERCTRL_VIDRF(reg));
    320       1.7      uch #endif /* TX391X */
    321       1.7      uch 	printf("STPTIMERVAL=%d ", TX39_POWERCTRL_STPTIMERVAL(reg));
    322       1.7      uch 	printf("\n");
    323       1.7      uch }
    324      1.10      uch #endif /* TX39POWER_DEBUG */
    325