Home | History | Annotate | Line # | Download | only in dev
plumpower.c revision 1.3
      1  1.3  uch /*	$NetBSD: plumpower.c,v 1.3 2000/02/26 15:16:19 uch Exp $ */
      2  1.1  uch 
      3  1.1  uch /*
      4  1.3  uch  * Copyright (c) 1999, 2000, 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.3  uch #undef PLUMPOWERDEBUG
     29  1.1  uch #include "opt_tx39_debug.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 #include <sys/malloc.h>
     35  1.1  uch 
     36  1.1  uch #include <machine/bus.h>
     37  1.1  uch #include <machine/intr.h>
     38  1.1  uch 
     39  1.1  uch #include <hpcmips/tx/tx39var.h>
     40  1.1  uch #include <hpcmips/dev/plumvar.h>
     41  1.1  uch #include <hpcmips/dev/plumpowervar.h>
     42  1.1  uch #include <hpcmips/dev/plumpowerreg.h>
     43  1.1  uch 
     44  1.3  uch #ifdef PLUMPOWERDEBUG
     45  1.3  uch int	plumpower_debug = 1;
     46  1.3  uch #define	DPRINTF(arg) if (plumpower_debug) printf arg;
     47  1.3  uch #define	DPRINTFN(n, arg) if (plumpower_debug > (n)) printf arg;
     48  1.3  uch #else
     49  1.3  uch #define	DPRINTF(arg)
     50  1.3  uch #define DPRINTFN(n, arg)
     51  1.3  uch #endif
     52  1.3  uch 
     53  1.1  uch int	plumpower_match __P((struct device*, struct cfdata*, void*));
     54  1.1  uch void	plumpower_attach __P((struct device*, struct device*, void*));
     55  1.1  uch 
     56  1.1  uch struct plumpower_softc {
     57  1.1  uch 	struct	device		sc_dev;
     58  1.1  uch 	plum_chipset_tag_t	sc_pc;
     59  1.1  uch 	bus_space_tag_t		sc_regt;
     60  1.1  uch 	bus_space_handle_t	sc_regh;
     61  1.1  uch };
     62  1.1  uch 
     63  1.1  uch struct cfattach plumpower_ca = {
     64  1.1  uch 	sizeof(struct plumpower_softc), plumpower_match, plumpower_attach
     65  1.1  uch };
     66  1.1  uch 
     67  1.1  uch void	plumpower_dump __P((struct plumpower_softc*));
     68  1.1  uch 
     69  1.1  uch int
     70  1.1  uch plumpower_match(parent, cf, aux)
     71  1.1  uch 	struct device *parent;
     72  1.1  uch 	struct cfdata *cf;
     73  1.1  uch 	void *aux;
     74  1.1  uch {
     75  1.1  uch 	return 2; /* 1st attach group */
     76  1.1  uch }
     77  1.1  uch 
     78  1.1  uch void
     79  1.1  uch plumpower_attach(parent, self, aux)
     80  1.1  uch 	struct device *parent;
     81  1.1  uch 	struct device *self;
     82  1.1  uch 	void *aux;
     83  1.1  uch {
     84  1.1  uch 	struct plum_attach_args *pa = aux;
     85  1.1  uch 	struct plumpower_softc *sc = (void*)self;
     86  1.1  uch 
     87  1.1  uch 	printf("\n");
     88  1.1  uch 	sc->sc_pc	= pa->pa_pc;
     89  1.1  uch 	sc->sc_regt	= pa->pa_regt;
     90  1.1  uch 
     91  1.1  uch 	if (bus_space_map(sc->sc_regt, PLUM_POWER_REGBASE,
     92  1.1  uch 			  PLUM_POWER_REGSIZE, 0, &sc->sc_regh)) {
     93  1.1  uch 		printf(": register map failed\n");
     94  1.1  uch 		return;
     95  1.1  uch 	}
     96  1.1  uch 	plum_conf_register_power(sc->sc_pc, (void*)sc);
     97  1.3  uch #ifdef PLUMPOWERDEBUG
     98  1.1  uch 	plumpower_dump(sc);
     99  1.3  uch #endif
    100  1.2  uch 	/* disable all power/clock */
    101  1.2  uch 	plum_conf_write(sc->sc_regt, sc->sc_regh,
    102  1.2  uch 			PLUM_POWER_PWRCONT_REG, 0);
    103  1.2  uch 	plum_conf_write(sc->sc_regt, sc->sc_regh,
    104  1.2  uch 			PLUM_POWER_CLKCONT_REG, 0);
    105  1.2  uch 	delay(300 * 1000);
    106  1.2  uch 
    107  1.2  uch 	/* enable MCS interface from TX3922 */
    108  1.1  uch 	plum_conf_write(sc->sc_regt, sc->sc_regh, PLUM_POWER_INPENA_REG,
    109  1.1  uch 			PLUM_POWER_INPENA);
    110  1.1  uch }
    111  1.1  uch 
    112  1.1  uch void
    113  1.1  uch plum_power_ioreset(pc)
    114  1.1  uch 	plum_chipset_tag_t pc;
    115  1.1  uch {
    116  1.1  uch 	struct plumpower_softc *sc = pc->pc_powert;
    117  1.1  uch 	bus_space_tag_t regt = sc->sc_regt;
    118  1.1  uch 	bus_space_handle_t regh = sc->sc_regh;
    119  1.1  uch 
    120  1.1  uch 	plum_conf_write(regt, regh, PLUM_POWER_RESETC_REG,
    121  1.1  uch 			PLUM_POWER_RESETC_IO5CL1 |
    122  1.1  uch 			PLUM_POWER_RESETC_IO5CL1);
    123  1.1  uch 	delay(100*1000);
    124  1.1  uch 	plum_conf_write(regt, regh, PLUM_POWER_RESETC_REG, 0);
    125  1.1  uch 	delay(100*1000);
    126  1.1  uch }
    127  1.1  uch 
    128  1.1  uch void*
    129  1.1  uch plum_power_establish(pc, src)
    130  1.1  uch 	plum_chipset_tag_t pc;
    131  1.1  uch 	int src;
    132  1.1  uch {
    133  1.1  uch 	struct plumpower_softc *sc = pc->pc_powert;
    134  1.1  uch 	bus_space_tag_t regt = sc->sc_regt;
    135  1.1  uch 	bus_space_handle_t regh = sc->sc_regh;
    136  1.1  uch 	plumreg_t pwrreg, clkreg;
    137  1.1  uch 
    138  1.1  uch 	pwrreg = plum_conf_read(regt, regh, PLUM_POWER_PWRCONT_REG);
    139  1.1  uch 	clkreg = plum_conf_read(regt, regh, PLUM_POWER_CLKCONT_REG);
    140  1.1  uch 
    141  1.1  uch 	switch(src) {
    142  1.1  uch 	default:
    143  1.1  uch 		panic("plum_power_establish: unknown power source");
    144  1.1  uch 	case PLUM_PWR_LCD:
    145  1.2  uch 		pwrreg |= PLUM_POWER_PWRCONT_LCDPWR;
    146  1.2  uch 		plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
    147  1.2  uch 		pwrreg |= PLUM_POWER_PWRCONT_LCDDSP;
    148  1.2  uch 		plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
    149  1.2  uch 		pwrreg |= PLUM_POWER_PWRCONT_LCDOE;
    150  1.2  uch 		plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
    151  1.1  uch 		break;
    152  1.1  uch 	case PLUM_PWR_BKL:
    153  1.1  uch 		pwrreg |= PLUM_POWER_PWRCONT_BKLIGHT;
    154  1.1  uch 		break;
    155  1.1  uch 	case PLUM_PWR_IO5:
    156  1.2  uch 		/* reset I/O bus (High/Low) */
    157  1.2  uch 		plum_power_ioreset(pc);
    158  1.2  uch 
    159  1.2  uch 		/* supply power */
    160  1.2  uch 		pwrreg |= PLUM_POWER_PWRCONT_IO5PWR;
    161  1.2  uch 		plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
    162  1.2  uch 		delay(300*1000);
    163  1.2  uch 
    164  1.2  uch 		/* output enable & supply clock */
    165  1.2  uch 		pwrreg |= PLUM_POWER_PWRCONT_IO5OE;
    166  1.1  uch 		clkreg |= PLUM_POWER_CLKCONT_IO5CLK;
    167  1.1  uch 		break;
    168  1.1  uch 	case PLUM_PWR_EXTPW0:
    169  1.1  uch 		pwrreg |= PLUM_POWER_PWRCONT_EXTPW0;
    170  1.1  uch 		break;
    171  1.1  uch 	case PLUM_PWR_EXTPW1:
    172  1.1  uch 		pwrreg |= PLUM_POWER_PWRCONT_EXTPW1;
    173  1.1  uch 		break;
    174  1.1  uch 	case PLUM_PWR_EXTPW2:
    175  1.1  uch 		pwrreg |= PLUM_POWER_PWRCONT_EXTPW2;
    176  1.1  uch 		break;
    177  1.1  uch 	case PLUM_PWR_USB:
    178  1.2  uch 		/* output enable */
    179  1.1  uch 		pwrreg |= PLUM_POWER_PWRCONT_USBEN;
    180  1.2  uch 		/* supply clock to the USB host controller */
    181  1.2  uch 		clkreg |= PLUM_POWER_CLKCONT_USBCLK1;
    182  1.2  uch 		/* clock supply is adaptively controlled by hardware */
    183  1.2  uch 		clkreg &= ~PLUM_POWER_CLKCONT_USBCLK2;
    184  1.1  uch 		break;
    185  1.1  uch 	case PLUM_PWR_SM:
    186  1.1  uch 		clkreg |= PLUM_POWER_CLKCONT_SMCLK;
    187  1.1  uch 		break;
    188  1.1  uch 	case PLUM_PWR_PCC1:
    189  1.1  uch 		clkreg |= PLUM_POWER_CLKCONT_PCCCLK1;
    190  1.1  uch 		break;
    191  1.1  uch 	case PLUM_PWR_PCC2:
    192  1.1  uch 		clkreg |= PLUM_POWER_CLKCONT_PCCCLK2;
    193  1.1  uch 		break;
    194  1.1  uch 	}
    195  1.1  uch 
    196  1.1  uch 	plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
    197  1.2  uch 	delay(300*1000);
    198  1.2  uch 
    199  1.1  uch 	plum_conf_write(regt, regh, PLUM_POWER_CLKCONT_REG, clkreg);
    200  1.2  uch 	delay(300*1000);
    201  1.3  uch #ifdef PLUMPOWERDEBUG
    202  1.2  uch 	plumpower_dump(sc);
    203  1.3  uch #endif
    204  1.1  uch 	return (void*)src;
    205  1.1  uch }
    206  1.1  uch 
    207  1.1  uch void
    208  1.1  uch plum_power_disestablish(pc, ph)
    209  1.1  uch 	plum_chipset_tag_t pc;
    210  1.1  uch 	int ph;
    211  1.1  uch {
    212  1.1  uch 	struct plumpower_softc *sc = pc->pc_powert;
    213  1.1  uch 	bus_space_tag_t regt = sc->sc_regt;
    214  1.1  uch 	bus_space_handle_t regh = sc->sc_regh;
    215  1.1  uch 	int src = (int)ph;
    216  1.1  uch 	plumreg_t pwrreg, clkreg;
    217  1.1  uch 
    218  1.1  uch 	pwrreg = plum_conf_read(regt, regh, PLUM_POWER_PWRCONT_REG);
    219  1.1  uch 	clkreg = plum_conf_read(regt, regh, PLUM_POWER_CLKCONT_REG);
    220  1.1  uch 
    221  1.1  uch 	switch(src) {
    222  1.1  uch 	default:
    223  1.1  uch 		panic("plum_power_disestablish: unknown power source");
    224  1.1  uch 	case PLUM_PWR_LCD:
    225  1.1  uch 		pwrreg &= ~(PLUM_POWER_PWRCONT_LCDOE |
    226  1.2  uch 			    PLUM_POWER_PWRCONT_LCDPWR |
    227  1.2  uch 			    PLUM_POWER_PWRCONT_LCDDSP);
    228  1.1  uch 		break;
    229  1.1  uch 	case PLUM_PWR_BKL:
    230  1.1  uch 		pwrreg &= ~PLUM_POWER_PWRCONT_BKLIGHT;
    231  1.1  uch 		break;
    232  1.1  uch 	case PLUM_PWR_IO5:
    233  1.1  uch 		pwrreg &= ~(PLUM_POWER_PWRCONT_IO5PWR |
    234  1.1  uch 			   PLUM_POWER_PWRCONT_IO5OE);
    235  1.1  uch 		clkreg &= ~PLUM_POWER_CLKCONT_IO5CLK;
    236  1.1  uch 		break;
    237  1.1  uch 	case PLUM_PWR_EXTPW0:
    238  1.1  uch 		pwrreg &= ~PLUM_POWER_PWRCONT_EXTPW0;
    239  1.1  uch 		break;
    240  1.1  uch 	case PLUM_PWR_EXTPW1:
    241  1.1  uch 		pwrreg &= ~PLUM_POWER_PWRCONT_EXTPW1;
    242  1.1  uch 		break;
    243  1.1  uch 	case PLUM_PWR_EXTPW2:
    244  1.1  uch 		pwrreg &= ~PLUM_POWER_PWRCONT_EXTPW2;
    245  1.1  uch 		break;
    246  1.1  uch 	case PLUM_PWR_USB:
    247  1.1  uch 		pwrreg &= ~PLUM_POWER_PWRCONT_USBEN;
    248  1.1  uch 		clkreg &= ~(PLUM_POWER_CLKCONT_USBCLK1 |
    249  1.1  uch 			   PLUM_POWER_CLKCONT_USBCLK2);
    250  1.1  uch 		break;
    251  1.1  uch 	case PLUM_PWR_SM:
    252  1.1  uch 		clkreg &= ~PLUM_POWER_CLKCONT_SMCLK;
    253  1.1  uch 		break;
    254  1.1  uch 	case PLUM_PWR_PCC1:
    255  1.1  uch 		clkreg &= ~PLUM_POWER_CLKCONT_PCCCLK1;
    256  1.1  uch 		break;
    257  1.1  uch 	case PLUM_PWR_PCC2:
    258  1.1  uch 		clkreg &= ~PLUM_POWER_CLKCONT_PCCCLK2;
    259  1.1  uch 		break;
    260  1.1  uch 	}
    261  1.1  uch 
    262  1.1  uch 	plum_conf_write(regt, regh, PLUM_POWER_PWRCONT_REG, pwrreg);
    263  1.1  uch 	plum_conf_write(regt, regh, PLUM_POWER_CLKCONT_REG, clkreg);
    264  1.3  uch #ifdef PLUMPOWERDEBUG
    265  1.2  uch 	plumpower_dump(sc);
    266  1.3  uch #endif
    267  1.1  uch }
    268  1.1  uch 
    269  1.1  uch #define ISPOWERSUPPLY(r, m) __is_set_print(r, PLUM_POWER_PWRCONT_##m, #m)
    270  1.1  uch #define ISCLOCKSUPPLY(r, m) __is_set_print(r, PLUM_POWER_CLKCONT_##m, #m)
    271  1.1  uch 
    272  1.1  uch void
    273  1.1  uch plumpower_dump(sc)
    274  1.1  uch 	struct plumpower_softc *sc;
    275  1.1  uch {
    276  1.1  uch 	bus_space_tag_t regt = sc->sc_regt;
    277  1.1  uch 	bus_space_handle_t regh = sc->sc_regh;
    278  1.1  uch 	plumreg_t reg;
    279  1.1  uch 
    280  1.1  uch 	reg = plum_conf_read(regt, regh, PLUM_POWER_PWRCONT_REG);
    281  1.1  uch 	printf(" power:");
    282  1.1  uch 	ISPOWERSUPPLY(reg, USBEN);
    283  1.1  uch 	ISPOWERSUPPLY(reg, IO5OE);
    284  1.1  uch 	ISPOWERSUPPLY(reg, LCDOE);
    285  1.1  uch 	ISPOWERSUPPLY(reg, EXTPW2);
    286  1.1  uch 	ISPOWERSUPPLY(reg, EXTPW1);
    287  1.1  uch 	ISPOWERSUPPLY(reg, EXTPW0);
    288  1.1  uch 	ISPOWERSUPPLY(reg, IO5PWR);
    289  1.1  uch 	ISPOWERSUPPLY(reg, BKLIGHT);
    290  1.1  uch 	ISPOWERSUPPLY(reg, LCDPWR);
    291  1.1  uch 	ISPOWERSUPPLY(reg, LCDDSP);
    292  1.1  uch 	reg = plum_conf_read(regt, regh, PLUM_POWER_CLKCONT_REG);
    293  1.1  uch 	printf("\n clock:");
    294  1.1  uch 	ISCLOCKSUPPLY(reg, USBCLK2);
    295  1.1  uch 	ISCLOCKSUPPLY(reg, USBCLK1);
    296  1.1  uch 	ISCLOCKSUPPLY(reg, IO5CLK);
    297  1.1  uch 	ISCLOCKSUPPLY(reg, SMCLK);
    298  1.1  uch 	ISCLOCKSUPPLY(reg, PCCCLK2);
    299  1.1  uch 	ISCLOCKSUPPLY(reg, PCCCLK1);
    300  1.1  uch 	reg = plum_conf_read(regt, regh, PLUM_POWER_INPENA_REG);
    301  1.1  uch 	printf("\n MCS interface %sebled",
    302  1.1  uch 	       reg & PLUM_POWER_INPENA ? "en" : "dis");
    303  1.1  uch 	reg = plum_conf_read(regt, regh, PLUM_POWER_RESETC_REG);
    304  1.1  uch 	printf("\n IO5 reset:%s %s",
    305  1.1  uch 	       reg & PLUM_POWER_RESETC_IO5CL0 ? "CLRL" : "",
    306  1.1  uch 	       reg & PLUM_POWER_RESETC_IO5CL1 ? "CLRH" : "");
    307  1.1  uch 	printf("\n");
    308  1.1  uch }
    309  1.1  uch 
    310  1.1  uch 
    311