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