Home | History | Annotate | Line # | Download | only in vr
vrc4172pwm.c revision 1.8
      1  1.8  sato /*	$Id: vrc4172pwm.c,v 1.8 2001/02/27 08:48:38 sato Exp $	*/
      2  1.1  sato 
      3  1.1  sato /*
      4  1.8  sato  * Copyright (c) 2000,2001 SATO Kazumi. All rights reserved.
      5  1.1  sato  *
      6  1.1  sato  * Redistribution and use in source and binary forms, with or without
      7  1.1  sato  * modification, are permitted provided that the following conditions
      8  1.1  sato  * are met:
      9  1.1  sato  * 1. Redistributions of source code must retain the above copyright
     10  1.1  sato  *    notice, this list of conditions and the following disclaimer.
     11  1.1  sato  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  sato  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  sato  *    documentation and/or other materials provided with the distribution.
     14  1.1  sato  *
     15  1.1  sato  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  sato  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  sato  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  sato  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  sato  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  sato  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  sato  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  sato  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  sato  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  sato  * SUCH DAMAGE.
     26  1.1  sato  */
     27  1.1  sato 
     28  1.1  sato #include <sys/param.h>
     29  1.1  sato #include <sys/systm.h>
     30  1.1  sato #include <sys/device.h>
     31  1.1  sato #include <sys/reboot.h>
     32  1.1  sato 
     33  1.1  sato #include <machine/bus.h>
     34  1.1  sato #include <machine/config_hook.h>
     35  1.1  sato #include <machine/platid.h>
     36  1.3  sato #include <machine/platid_mask.h>
     37  1.1  sato 
     38  1.3  sato #include <hpcmips/vr/vr.h>
     39  1.3  sato #include <hpcmips/vr/vripvar.h>
     40  1.1  sato #include <hpcmips/vr/vrc4172pwmvar.h>
     41  1.1  sato #include <hpcmips/vr/vrc4172pwmreg.h>
     42  1.1  sato 
     43  1.3  sato #include "locators.h"
     44  1.1  sato 
     45  1.1  sato #ifdef VRC2PWMDEBUG
     46  1.1  sato #ifndef VRC2PWMDEBUG_CONF
     47  1.1  sato #define VRC2PWMDEBUG_CONF 0
     48  1.1  sato #endif /* VRC2PWMDEBUG_CONF */
     49  1.1  sato int vrc4172pwmdebug = VRC2PWMDEBUG_CONF;
     50  1.1  sato #define DPRINTF(arg) if (vrc4172pwmdebug) printf arg;
     51  1.1  sato #define VPRINTF(arg) if (bootverbose||vrc4172pwmdebug) printf arg;
     52  1.3  sato #define VDUMPREG(arg) if (bootverbose||vrc4172pwmdebug) vrc4172pwm_dumpreg(arg);
     53  1.1  sato #else /* VRC2PWMDEBUG */
     54  1.1  sato #define DPRINTF(arg)
     55  1.1  sato #define VPRINTF(arg) if (bootverbose) printf arg;
     56  1.3  sato #define VDUMPREG(arg) if (bootverbose) vrc4172pwm_dumpreg(arg);
     57  1.1  sato #endif /* VRC2PWMDEBUG */
     58  1.1  sato 
     59  1.3  sato static int vrc4172pwmprobe __P((struct device *, struct cfdata *, void *));
     60  1.1  sato static void vrc4172pwmattach __P((struct device *, struct device *, void *));
     61  1.1  sato 
     62  1.1  sato static void vrc4172pwm_write __P((struct vrc4172pwm_softc *, int, unsigned short));
     63  1.1  sato static unsigned short vrc4172pwm_read __P((struct vrc4172pwm_softc *, int));
     64  1.1  sato 
     65  1.1  sato static int vrc4172pwm_event __P((void *, int, long, void *));
     66  1.1  sato static int vrc4172pwm_pmevent __P((void *, int, long, void *));
     67  1.1  sato 
     68  1.1  sato static void vrc4172pwm_dumpreg __P((struct vrc4172pwm_softc *));
     69  1.3  sato static void vrc4172pwm_init_brightness __P((struct vrc4172pwm_softc *));
     70  1.3  sato void vrc4172pwm_light __P((struct vrc4172pwm_softc *, int));
     71  1.3  sato int vrc4172pwm_get_light __P((struct vrc4172pwm_softc *));
     72  1.3  sato int vrc4172pwm_get_brightness __P((struct vrc4172pwm_softc *));
     73  1.3  sato void vrc4172pwm_set_brightness __P((struct vrc4172pwm_softc *, int));
     74  1.3  sato int vrc4172pwm_rawduty2brightness __P((struct vrc4172pwm_softc *));
     75  1.3  sato int vrc4172pwm_brightness2rawduty __P((struct vrc4172pwm_softc *));
     76  1.3  sato struct vrc4172pwm_param * vrc4172pwm_getparam __P((void));
     77  1.3  sato void vrc4172pwm_dumpreg __P((struct vrc4172pwm_softc *));
     78  1.1  sato 
     79  1.3  sato struct cfattach vrc4172pwm_ca = {
     80  1.3  sato 	sizeof(struct vrc4172pwm_softc), vrc4172pwmprobe, vrc4172pwmattach
     81  1.3  sato };
     82  1.3  sato 
     83  1.3  sato /*
     84  1.3  sato  * platform related parameters
     85  1.3  sato  */
     86  1.3  sato struct vrc4172pwm_param vrc4172pwm_mcr530_param = {
     87  1.8  sato 	0,
     88  1.3  sato 	8,
     89  1.3  sato 	{ 0x16, 0x1b, 0x20, 0x25, 0x2a, 0x30, 0x37, 0x3f }
     90  1.3  sato };
     91  1.1  sato 
     92  1.8  sato struct vrc4172pwm_param vrc4172pwm_mcr700_param = {
     93  1.8  sato 	1, /* probe broken */
     94  1.8  sato 	8,
     95  1.8  sato 	{ 0x12, 0x15, 0x18, 0x1d, 0x24, 0x2d, 0x38, 0x3f }
     96  1.8  sato };
     97  1.8  sato 
     98  1.4  sato struct platid_data vrc4172pwm_platid_param_table[] = {
     99  1.5  sato 	{ &platid_mask_MACH_NEC_MCR_430,
    100  1.5  sato 		&vrc4172pwm_mcr530_param},
    101  1.5  sato 	{ &platid_mask_MACH_NEC_MCR_530,
    102  1.5  sato 		&vrc4172pwm_mcr530_param},
    103  1.3  sato 	{ &platid_mask_MACH_NEC_MCR_530A,
    104  1.3  sato 		&vrc4172pwm_mcr530_param},
    105  1.3  sato 	{ &platid_mask_MACH_NEC_MCR_SIGMARION,
    106  1.3  sato 		&vrc4172pwm_mcr530_param},
    107  1.8  sato 	{ &platid_mask_MACH_NEC_MCR_700,
    108  1.8  sato 		&vrc4172pwm_mcr700_param},
    109  1.8  sato 	{ &platid_mask_MACH_NEC_MCR_700A,
    110  1.8  sato 		&vrc4172pwm_mcr700_param},
    111  1.3  sato 	{ NULL, NULL}
    112  1.1  sato };
    113  1.1  sato 
    114  1.1  sato struct vrc4172pwm_softc *this_pwm;
    115  1.1  sato 
    116  1.1  sato static inline void
    117  1.1  sato vrc4172pwm_write(sc, port, val)
    118  1.1  sato 	struct vrc4172pwm_softc *sc;
    119  1.1  sato 	int port;
    120  1.1  sato 	unsigned short val;
    121  1.1  sato {
    122  1.1  sato 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
    123  1.1  sato }
    124  1.1  sato 
    125  1.1  sato static inline unsigned short
    126  1.1  sato vrc4172pwm_read(sc, port)
    127  1.1  sato 	struct vrc4172pwm_softc *sc;
    128  1.1  sato 	int port;
    129  1.1  sato {
    130  1.1  sato 	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
    131  1.1  sato }
    132  1.1  sato 
    133  1.1  sato static int
    134  1.3  sato vrc4172pwmprobe(parent, cf, aux)
    135  1.1  sato 	struct device *parent;
    136  1.1  sato 	struct cfdata *cf;
    137  1.1  sato 	void *aux;
    138  1.1  sato {
    139  1.3  sato 	platid_mask_t mask;
    140  1.3  sato 	struct vrip_attach_args *va = aux;
    141  1.3  sato 	bus_space_handle_t ioh;
    142  1.8  sato #ifdef VRC4172PWM_BROKEN_PROBE
    143  1.8  sato 	int probe = 0;
    144  1.8  sato #else /* VRC4172PWM_BROKEN_PROBE */
    145  1.8  sato 	int probe = 1;
    146  1.8  sato #endif /* VRC4172PWM_BROKEN_PROBE */
    147  1.3  sato 	int data;
    148  1.8  sato 	int data2;
    149  1.8  sato 	struct vrc4172pwm_param *param;
    150  1.3  sato 	int ret = 0;
    151  1.3  sato 
    152  1.3  sato 	if (va->va_addr == VRIPCF_ADDR_DEFAULT)
    153  1.3  sato 		return 0;
    154  1.3  sato 
    155  1.5  sato 	if (cf->cf_loc[VRIPCF_PLATFORM] == 0)
    156  1.3  sato 		return 0;
    157  1.5  sato 	if (cf->cf_loc[VRIPCF_PLATFORM] != -1) { /* if specify */
    158  1.5  sato 		mask = PLATID_DEREF(cf->cf_loc[VRIPCF_PLATFORM]);
    159  1.8  sato 		VPRINTF(("vrc4172pwmprobe: check platid\n"));
    160  1.3  sato 		if (platid_match(&platid, &mask) == 0)
    161  1.3  sato 			return 0;
    162  1.8  sato 		param = vrc4172pwm_getparam();
    163  1.8  sato 		if (param != NULL && param->brokenprobe)
    164  1.8  sato 			probe = 0;
    165  1.3  sato 	}
    166  1.8  sato 	if (probe) {
    167  1.8  sato 		if (bus_space_map(va->va_iot, va->va_addr, va->va_size, 0, &ioh)) {
    168  1.8  sato 			return 0;
    169  1.8  sato 		}
    170  1.8  sato 		data =  bus_space_read_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN);
    171  1.8  sato 		bus_space_write_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN, 0xff);
    172  1.8  sato 		if ((data2 = bus_space_read_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN))
    173  1.8  sato 			== VRC2_PWM_LCDEN_MASK) {
    174  1.8  sato 			VPRINTF(("vrc4172pwmprobe: VRC2_PWM_LCDDUTYEN found\n"));
    175  1.8  sato 			ret = 1;
    176  1.8  sato 		} else {
    177  1.8  sato 			VPRINTF(("vrc4172pwmprobe: VRC2_PWM_LCDDUTYEN not found org=%x, data=%x!=%x\n", data, data2, VRC2_PWM_LCDEN_MASK));
    178  1.8  sato 		}
    179  1.8  sato 		bus_space_write_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN, data);
    180  1.8  sato 		bus_space_unmap(va->va_iot, ioh, va->va_size);
    181  1.8  sato 	} else
    182  1.3  sato 		ret = 1;
    183  1.8  sato 	VPRINTF(("vrc4172pwmprobe: return %d\n", ret));
    184  1.3  sato 	return ret;
    185  1.1  sato }
    186  1.1  sato 
    187  1.1  sato static void
    188  1.1  sato vrc4172pwmattach(parent, self, aux)
    189  1.1  sato 	struct device *parent;
    190  1.1  sato 	struct device *self;
    191  1.1  sato 	void *aux;
    192  1.1  sato {
    193  1.1  sato 	struct vrc4172pwm_softc *sc = (struct vrc4172pwm_softc *)self;
    194  1.1  sato 	struct vrip_attach_args *va = aux;
    195  1.1  sato 
    196  1.1  sato 	bus_space_tag_t iot = va->va_iot;
    197  1.1  sato 	bus_space_handle_t ioh;
    198  1.1  sato 
    199  1.1  sato 	if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
    200  1.1  sato 		printf(": can't map bus space\n");
    201  1.1  sato 		return;
    202  1.1  sato 	}
    203  1.1  sato 
    204  1.1  sato 	sc->sc_iot = iot;
    205  1.1  sato 	sc->sc_ioh = ioh;
    206  1.1  sato 
    207  1.1  sato 	printf("\n");
    208  1.1  sato 
    209  1.1  sato 	VDUMPREG(sc);
    210  1.1  sato 	/* basic setup */
    211  1.1  sato 	sc->sc_pmhook = config_hook(CONFIG_HOOK_PMEVENT,
    212  1.3  sato 					CONFIG_HOOK_PMEVENT_HARDPOWER,
    213  1.1  sato 					CONFIG_HOOK_SHARE,
    214  1.1  sato 					vrc4172pwm_pmevent, sc);
    215  1.3  sato 	sc->sc_lcdhook = config_hook(CONFIG_HOOK_POWERCONTROL,
    216  1.3  sato 					CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    217  1.3  sato 					CONFIG_HOOK_SHARE,
    218  1.3  sato 					vrc4172pwm_event, sc);
    219  1.3  sato 	sc->sc_getlcdhook = config_hook(CONFIG_HOOK_GET,
    220  1.3  sato 					CONFIG_HOOK_POWER_LCDLIGHT,
    221  1.1  sato 					CONFIG_HOOK_SHARE,
    222  1.1  sato 					vrc4172pwm_event, sc);
    223  1.1  sato 	sc->sc_sethook = config_hook(CONFIG_HOOK_SET,
    224  1.3  sato 					CONFIG_HOOK_BRIGHTNESS,
    225  1.1  sato 					CONFIG_HOOK_SHARE,
    226  1.1  sato 					vrc4172pwm_event, sc);
    227  1.1  sato 	sc->sc_gethook = config_hook(CONFIG_HOOK_GET,
    228  1.3  sato 					CONFIG_HOOK_BRIGHTNESS,
    229  1.3  sato 					CONFIG_HOOK_SHARE,
    230  1.3  sato 					vrc4172pwm_event, sc);
    231  1.3  sato 	sc->sc_getmaxhook = config_hook(CONFIG_HOOK_GET,
    232  1.3  sato 					CONFIG_HOOK_BRIGHTNESS_MAX,
    233  1.1  sato 					CONFIG_HOOK_SHARE,
    234  1.1  sato 					vrc4172pwm_event, sc);
    235  1.1  sato 
    236  1.3  sato 	vrc4172pwm_init_brightness(sc);
    237  1.1  sato 	this_pwm = sc;
    238  1.1  sato }
    239  1.1  sato 
    240  1.3  sato /*
    241  1.3  sato  * get platform related brightness paramerters
    242  1.3  sato  */
    243  1.3  sato struct vrc4172pwm_param *
    244  1.3  sato vrc4172pwm_getparam()
    245  1.3  sato {
    246  1.4  sato 	struct platid_data *p;
    247  1.3  sato 
    248  1.4  sato 	if ((p = platid_search(&platid, vrc4172pwm_platid_param_table)))
    249  1.4  sato 		return p->data;
    250  1.3  sato 	return NULL;
    251  1.3  sato }
    252  1.3  sato 
    253  1.2  sato /*
    254  1.2  sato  *
    255  1.2  sato  * Initialize PWM brightness parameters
    256  1.2  sato  *
    257  1.2  sato  */
    258  1.2  sato void
    259  1.2  sato vrc4172pwm_init_brightness(sc)
    260  1.3  sato struct vrc4172pwm_softc *sc;
    261  1.2  sato {
    262  1.3  sato 	sc->sc_param = vrc4172pwm_getparam();
    263  1.2  sato 	sc->sc_raw_freq = vrc4172pwm_read(sc, VRC2_PWM_LCDFREQ);
    264  1.2  sato 	sc->sc_raw_duty = vrc4172pwm_read(sc, VRC2_PWM_LCDDUTY);
    265  1.3  sato 	sc->sc_brightness = vrc4172pwm_rawduty2brightness(sc);
    266  1.5  sato 	DPRINTF(("vrc4172pwm_init_brightness: param=0x%x, freq=0x%x, duty=0x%x, blightness=%d\n", (int)sc->sc_param, sc->sc_raw_freq, sc->sc_raw_duty, sc->sc_brightness));
    267  1.3  sato }
    268  1.3  sato /*
    269  1.3  sato  * backlight on/off
    270  1.3  sato  */
    271  1.3  sato void
    272  1.3  sato vrc4172pwm_light(sc, on)
    273  1.3  sato 	struct vrc4172pwm_softc *sc;
    274  1.3  sato 	int on;
    275  1.3  sato {
    276  1.6  sato 	int brightness;
    277  1.6  sato 
    278  1.5  sato 	DPRINTF(("vrc4172pwm_light: %s\n", on?"ON":"OFF"));
    279  1.6  sato 	if (on) {
    280  1.6  sato 		vrc4172pwm_set_brightness(sc, sc->sc_brightness);
    281  1.3  sato 		vrc4172pwm_write(sc, VRC2_PWM_LCDDUTYEN, VRC2_PWM_LCD_EN);
    282  1.6  sato 	} else {
    283  1.6  sato 		brightness = sc->sc_brightness; /* save */
    284  1.6  sato 		vrc4172pwm_set_brightness(sc, 0);
    285  1.6  sato 			/* need this, break sc->sc_brightness */
    286  1.6  sato 		sc->sc_brightness = brightness; /* resume */
    287  1.3  sato 		vrc4172pwm_write(sc, VRC2_PWM_LCDDUTYEN, VRC2_PWM_LCD_DIS);
    288  1.6  sato 	}
    289  1.3  sato }
    290  1.3  sato 
    291  1.3  sato /*
    292  1.3  sato  * get backlight on/off
    293  1.3  sato  */
    294  1.3  sato inline int
    295  1.3  sato vrc4172pwm_get_light(sc)
    296  1.3  sato 	struct vrc4172pwm_softc *sc;
    297  1.3  sato {
    298  1.5  sato 	return vrc4172pwm_read(sc, VRC2_PWM_LCDDUTYEN);
    299  1.3  sato }
    300  1.3  sato 
    301  1.3  sato /*
    302  1.3  sato  * set brightness
    303  1.3  sato  */
    304  1.3  sato void
    305  1.3  sato vrc4172pwm_set_brightness(sc, val)
    306  1.3  sato 	struct vrc4172pwm_softc *sc;
    307  1.3  sato 	int val;
    308  1.3  sato {
    309  1.3  sato 	int raw;
    310  1.3  sato 
    311  1.3  sato 	if (sc->sc_param == NULL)
    312  1.3  sato 		return;
    313  1.5  sato 	if (val < 0)
    314  1.5  sato 		val = 0;
    315  1.3  sato 	if (val > VRC2_PWM_MAX_BRIGHTNESS)
    316  1.3  sato 		val = VRC2_PWM_MAX_BRIGHTNESS;
    317  1.3  sato 	if (val > sc->sc_param->n_brightness)
    318  1.3  sato 		val = sc->sc_param->n_brightness;
    319  1.3  sato 	sc->sc_brightness = val;
    320  1.3  sato 	raw = vrc4172pwm_brightness2rawduty(sc);
    321  1.3  sato 	vrc4172pwm_write(sc, VRC2_PWM_LCDDUTY, raw);
    322  1.5  sato 	DPRINTF(("vrc4172pwm_set_brightness: val=%d raw=0x%x\n", val, raw));
    323  1.3  sato }
    324  1.3  sato 
    325  1.3  sato /*
    326  1.3  sato  * get brightness
    327  1.3  sato  */
    328  1.3  sato int
    329  1.3  sato vrc4172pwm_get_brightness(sc)
    330  1.3  sato 	struct vrc4172pwm_softc *sc;
    331  1.3  sato {
    332  1.3  sato 	if (sc->sc_param == NULL)
    333  1.3  sato 		return VRC2_PWM_MAX_BRIGHTNESS;
    334  1.3  sato 	return sc->sc_brightness;
    335  1.3  sato }
    336  1.3  sato 
    337  1.3  sato /*
    338  1.3  sato  * PWM duty to brightness
    339  1.3  sato  */
    340  1.3  sato int
    341  1.3  sato vrc4172pwm_rawduty2brightness(sc)
    342  1.3  sato struct vrc4172pwm_softc *sc;
    343  1.3  sato {
    344  1.3  sato 	int i;
    345  1.3  sato 
    346  1.3  sato 	if (sc->sc_param == NULL)
    347  1.5  sato 		return VRC2_PWM_MAX_BRIGHTNESS;
    348  1.3  sato 	for (i = 0; i < sc->sc_param->n_brightness; i++) {
    349  1.8  sato 		if (sc->sc_raw_duty <= sc->sc_param->bvalues[i])
    350  1.3  sato 			break;
    351  1.3  sato 	}
    352  1.3  sato 	if (i >= sc->sc_param->n_brightness-1)
    353  1.3  sato 		return sc->sc_param->n_brightness-1;
    354  1.3  sato 	else
    355  1.3  sato 		return i;
    356  1.3  sato 
    357  1.3  sato }
    358  1.3  sato 
    359  1.3  sato /*
    360  1.3  sato  * brightness to raw duty
    361  1.3  sato  */
    362  1.3  sato int
    363  1.3  sato vrc4172pwm_brightness2rawduty(sc)
    364  1.3  sato struct vrc4172pwm_softc *sc;
    365  1.3  sato {
    366  1.3  sato 	if (sc->sc_param == NULL)
    367  1.5  sato 		return VRC2_PWM_LCDDUTY_MASK;
    368  1.8  sato 	return sc->sc_param->bvalues[sc->sc_brightness];
    369  1.2  sato }
    370  1.1  sato 
    371  1.3  sato 
    372  1.1  sato /*
    373  1.1  sato  * PWM config hook events
    374  1.1  sato  *
    375  1.1  sato  */
    376  1.1  sato int
    377  1.1  sato vrc4172pwm_event(ctx, type, id, msg)
    378  1.1  sato 	void *ctx;
    379  1.1  sato         int type;
    380  1.1  sato         long id;
    381  1.1  sato         void *msg;
    382  1.1  sato {
    383  1.1  sato 	struct vrc4172pwm_softc *sc = (struct vrc4172pwm_softc *)ctx;
    384  1.1  sato         int why =(int)msg;
    385  1.1  sato 
    386  1.1  sato 	if (type == CONFIG_HOOK_POWERCONTROL
    387  1.1  sato 		&& id == CONFIG_HOOK_POWERCONTROL_LCDLIGHT) {
    388  1.7  sato 		DPRINTF(("vrc4172pwm:POWERCONTROL_LCDLIGHT: %d\n", why));
    389  1.2  sato 		vrc4172pwm_light(sc, why);
    390  1.1  sato 	} else if (type == CONFIG_HOOK_GET
    391  1.3  sato 		&& id == CONFIG_HOOK_POWER_LCDLIGHT) {
    392  1.3  sato 		*(int *)msg = vrc4172pwm_get_light(sc);
    393  1.7  sato 		DPRINTF(("vrc4172pwm:GET LCDLIGHT: %d\n", *(int *)msg));
    394  1.3  sato 	} else if (type == CONFIG_HOOK_GET
    395  1.3  sato 		&& id == CONFIG_HOOK_BRIGHTNESS) {
    396  1.3  sato 		*(int *)msg = vrc4172pwm_get_brightness(sc);
    397  1.7  sato 		DPRINTF(("vrc4172pwm:GET BRIGHTNESS: %d\n", *(int *)msg));
    398  1.3  sato 	} else if (type == CONFIG_HOOK_GET
    399  1.3  sato 		&& id == CONFIG_HOOK_BRIGHTNESS_MAX) {
    400  1.3  sato 		if (sc->sc_param == NULL)
    401  1.3  sato 			*(int *)msg = VRC2_PWM_MAX_BRIGHTNESS;
    402  1.3  sato 		else
    403  1.3  sato 			*(int *)msg = sc->sc_param->n_brightness-1;
    404  1.7  sato 		DPRINTF(("vrc4172pwm:GET MAX BRIGHTNESS: %d\n", *(int *)msg));
    405  1.1  sato 	} else if (type == CONFIG_HOOK_SET
    406  1.3  sato 		&& id == CONFIG_HOOK_BRIGHTNESS) {
    407  1.7  sato 		DPRINTF(("vrc4172pwm:SET BRIGHTNESS: %d\n", *(int *)msg));
    408  1.3  sato 		vrc4172pwm_set_brightness(sc, *(int *)msg);
    409  1.6  sato 	} else {
    410  1.7  sato 		DPRINTF(("vrc4172pwm:unknown event: type %d id %ld\n", type, id));
    411  1.1  sato 		return 1;
    412  1.6  sato 	}
    413  1.1  sato 
    414  1.1  sato         return (0);
    415  1.1  sato }
    416  1.1  sato 
    417  1.1  sato 
    418  1.1  sato /*
    419  1.1  sato  * PWM config hook events
    420  1.1  sato  *
    421  1.1  sato  */
    422  1.1  sato int
    423  1.1  sato vrc4172pwm_pmevent(ctx, type, id, msg)
    424  1.1  sato 	void *ctx;
    425  1.1  sato         int type;
    426  1.1  sato         long id;
    427  1.1  sato         void *msg;
    428  1.1  sato {
    429  1.1  sato 	struct vrc4172pwm_softc *sc = (struct vrc4172pwm_softc *)ctx;
    430  1.1  sato         int why =(int)msg;
    431  1.1  sato 
    432  1.1  sato 	if (type != CONFIG_HOOK_PMEVENT)
    433  1.1  sato 		return 1;
    434  1.1  sato 
    435  1.1  sato         switch (why) {
    436  1.3  sato 	case PWR_STANDBY:
    437  1.2  sato 	case PWR_SUSPEND:
    438  1.2  sato 		vrc4172pwm_light(sc, 0);
    439  1.2  sato 		break;
    440  1.2  sato 	case PWR_RESUME:
    441  1.2  sato 		vrc4172pwm_light(sc, 1);
    442  1.2  sato 		break;
    443  1.2  sato 	default:
    444  1.2  sato 		return 1;
    445  1.1  sato         }
    446  1.2  sato 
    447  1.1  sato         return (0);
    448  1.2  sato }
    449  1.2  sato 
    450  1.2  sato /*
    451  1.1  sato  * dump pwm registers
    452  1.1  sato  */
    453  1.1  sato void
    454  1.1  sato vrc4172pwm_dumpreg(sc)
    455  1.1  sato 	struct vrc4172pwm_softc *sc;
    456  1.1  sato {
    457  1.1  sato 	int en, freq, duty;
    458  1.1  sato 
    459  1.1  sato 	en = vrc4172pwm_read(sc, VRC2_PWM_LCDDUTYEN);
    460  1.1  sato 	freq = vrc4172pwm_read(sc, VRC2_PWM_LCDFREQ);
    461  1.1  sato 	duty = vrc4172pwm_read(sc, VRC2_PWM_LCDDUTY);
    462  1.1  sato 
    463  1.5  sato 	printf("vrc4172pwm: dumpreg: lightenable = %d, freq = 0x%x, duty = 0x%x\n",
    464  1.1  sato 		en, freq, duty);
    465  1.1  sato }
    466  1.2  sato 
    467  1.1  sato /* end */
    468