2001-04-13 12:09:07 +04:00
|
|
|
/* $NetBSD: vrc4172pwm.c,v 1.12 2001/04/13 08:09:07 itojun Exp $ */
|
2000-11-11 07:42:08 +03:00
|
|
|
|
|
|
|
/*
|
2001-02-27 11:48:38 +03:00
|
|
|
* Copyright (c) 2000,2001 SATO Kazumi. All rights reserved.
|
2000-11-11 07:42:08 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/config_hook.h>
|
|
|
|
#include <machine/platid.h>
|
2000-12-29 14:44:44 +03:00
|
|
|
#include <machine/platid_mask.h>
|
2000-11-11 07:42:08 +03:00
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
#include <hpcmips/vr/vr.h>
|
|
|
|
#include <hpcmips/vr/vripvar.h>
|
2000-11-11 07:42:08 +03:00
|
|
|
#include <hpcmips/vr/vrc4172pwmvar.h>
|
|
|
|
#include <hpcmips/vr/vrc4172pwmreg.h>
|
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
#include "locators.h"
|
2000-11-11 07:42:08 +03:00
|
|
|
|
|
|
|
#ifdef VRC2PWMDEBUG
|
|
|
|
#ifndef VRC2PWMDEBUG_CONF
|
|
|
|
#define VRC2PWMDEBUG_CONF 0
|
|
|
|
#endif /* VRC2PWMDEBUG_CONF */
|
|
|
|
int vrc4172pwmdebug = VRC2PWMDEBUG_CONF;
|
|
|
|
#define DPRINTF(arg) if (vrc4172pwmdebug) printf arg;
|
|
|
|
#define VPRINTF(arg) if (bootverbose||vrc4172pwmdebug) printf arg;
|
2000-12-29 14:44:44 +03:00
|
|
|
#define VDUMPREG(arg) if (bootverbose||vrc4172pwmdebug) vrc4172pwm_dumpreg(arg);
|
2000-11-11 07:42:08 +03:00
|
|
|
#else /* VRC2PWMDEBUG */
|
|
|
|
#define DPRINTF(arg)
|
|
|
|
#define VPRINTF(arg) if (bootverbose) printf arg;
|
2000-12-29 14:44:44 +03:00
|
|
|
#define VDUMPREG(arg) if (bootverbose) vrc4172pwm_dumpreg(arg);
|
2000-11-11 07:42:08 +03:00
|
|
|
#endif /* VRC2PWMDEBUG */
|
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
static int vrc4172pwmprobe __P((struct device *, struct cfdata *, void *));
|
2000-11-11 07:42:08 +03:00
|
|
|
static void vrc4172pwmattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
static void vrc4172pwm_write __P((struct vrc4172pwm_softc *, int, unsigned short));
|
|
|
|
static unsigned short vrc4172pwm_read __P((struct vrc4172pwm_softc *, int));
|
|
|
|
|
|
|
|
static int vrc4172pwm_event __P((void *, int, long, void *));
|
|
|
|
static int vrc4172pwm_pmevent __P((void *, int, long, void *));
|
|
|
|
|
|
|
|
static void vrc4172pwm_dumpreg __P((struct vrc4172pwm_softc *));
|
2000-12-29 14:44:44 +03:00
|
|
|
static void vrc4172pwm_init_brightness __P((struct vrc4172pwm_softc *));
|
|
|
|
void vrc4172pwm_light __P((struct vrc4172pwm_softc *, int));
|
|
|
|
int vrc4172pwm_get_light __P((struct vrc4172pwm_softc *));
|
|
|
|
int vrc4172pwm_get_brightness __P((struct vrc4172pwm_softc *));
|
|
|
|
void vrc4172pwm_set_brightness __P((struct vrc4172pwm_softc *, int));
|
|
|
|
int vrc4172pwm_rawduty2brightness __P((struct vrc4172pwm_softc *));
|
|
|
|
int vrc4172pwm_brightness2rawduty __P((struct vrc4172pwm_softc *));
|
|
|
|
struct vrc4172pwm_param * vrc4172pwm_getparam __P((void));
|
|
|
|
void vrc4172pwm_dumpreg __P((struct vrc4172pwm_softc *));
|
2000-11-11 07:42:08 +03:00
|
|
|
|
|
|
|
struct cfattach vrc4172pwm_ca = {
|
2000-12-29 14:44:44 +03:00
|
|
|
sizeof(struct vrc4172pwm_softc), vrc4172pwmprobe, vrc4172pwmattach
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* platform related parameters
|
|
|
|
*/
|
2001-03-24 18:53:37 +03:00
|
|
|
struct vrc4172pwm_param vrc4172pwm_mcr520_param = {
|
|
|
|
1, /* probe broken */
|
|
|
|
8, /* levels */
|
|
|
|
{ 0x16, 0x1f, 0x24, 0x2a, 0x2f, 0x34, 0x3a, 0x3f }
|
|
|
|
};
|
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
struct vrc4172pwm_param vrc4172pwm_mcr530_param = {
|
2001-02-27 11:48:38 +03:00
|
|
|
0,
|
2001-03-24 18:53:37 +03:00
|
|
|
8, /* levels */
|
2000-12-29 14:44:44 +03:00
|
|
|
{ 0x16, 0x1b, 0x20, 0x25, 0x2a, 0x30, 0x37, 0x3f }
|
|
|
|
};
|
|
|
|
|
2001-02-27 11:48:38 +03:00
|
|
|
struct vrc4172pwm_param vrc4172pwm_mcr700_param = {
|
|
|
|
1, /* probe broken */
|
2001-03-24 18:53:37 +03:00
|
|
|
8, /* levels */
|
2001-02-27 11:48:38 +03:00
|
|
|
{ 0x12, 0x15, 0x18, 0x1d, 0x24, 0x2d, 0x38, 0x3f }
|
|
|
|
};
|
|
|
|
|
2001-03-06 06:14:39 +03:00
|
|
|
struct vrc4172pwm_param vrc4172pwm_sigmarion_param = {
|
|
|
|
0,
|
2001-03-24 18:53:37 +03:00
|
|
|
8, /* levels */
|
2001-03-06 06:14:39 +03:00
|
|
|
{ 0xe, 0x13, 0x18, 0x1c, 0x23, 0x29, 0x32, 0x3f }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-12-29 18:54:17 +03:00
|
|
|
struct platid_data vrc4172pwm_platid_param_table[] = {
|
2001-02-15 06:20:10 +03:00
|
|
|
{ &platid_mask_MACH_NEC_MCR_430,
|
|
|
|
&vrc4172pwm_mcr530_param},
|
2001-03-24 18:53:37 +03:00
|
|
|
{ &platid_mask_MACH_NEC_MCR_510,
|
|
|
|
&vrc4172pwm_mcr520_param},
|
|
|
|
{ &platid_mask_MACH_NEC_MCR_520,
|
|
|
|
&vrc4172pwm_mcr520_param},
|
|
|
|
{ &platid_mask_MACH_NEC_MCR_520A,
|
|
|
|
&vrc4172pwm_mcr520_param},
|
2001-02-15 06:20:10 +03:00
|
|
|
{ &platid_mask_MACH_NEC_MCR_530,
|
|
|
|
&vrc4172pwm_mcr530_param},
|
2000-12-29 14:44:44 +03:00
|
|
|
{ &platid_mask_MACH_NEC_MCR_530A,
|
|
|
|
&vrc4172pwm_mcr530_param},
|
|
|
|
{ &platid_mask_MACH_NEC_MCR_SIGMARION,
|
2001-03-06 06:14:39 +03:00
|
|
|
&vrc4172pwm_sigmarion_param},
|
2001-02-27 11:48:38 +03:00
|
|
|
{ &platid_mask_MACH_NEC_MCR_700,
|
|
|
|
&vrc4172pwm_mcr700_param},
|
|
|
|
{ &platid_mask_MACH_NEC_MCR_700A,
|
|
|
|
&vrc4172pwm_mcr700_param},
|
2000-12-29 14:44:44 +03:00
|
|
|
{ NULL, NULL}
|
2000-11-11 07:42:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct vrc4172pwm_softc *this_pwm;
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
vrc4172pwm_write(sc, port, val)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
int port;
|
|
|
|
unsigned short val;
|
|
|
|
{
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned short
|
|
|
|
vrc4172pwm_read(sc, port)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
int port;
|
|
|
|
{
|
|
|
|
return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-12-29 14:44:44 +03:00
|
|
|
vrc4172pwmprobe(parent, cf, aux)
|
2000-11-11 07:42:08 +03:00
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
2000-12-29 14:44:44 +03:00
|
|
|
platid_mask_t mask;
|
|
|
|
struct vrip_attach_args *va = aux;
|
|
|
|
bus_space_handle_t ioh;
|
2001-02-27 11:48:38 +03:00
|
|
|
#ifdef VRC4172PWM_BROKEN_PROBE
|
|
|
|
int probe = 0;
|
|
|
|
#else /* VRC4172PWM_BROKEN_PROBE */
|
|
|
|
int probe = 1;
|
|
|
|
#endif /* VRC4172PWM_BROKEN_PROBE */
|
2000-12-29 14:44:44 +03:00
|
|
|
int data;
|
2001-02-27 11:48:38 +03:00
|
|
|
int data2;
|
|
|
|
struct vrc4172pwm_param *param;
|
2000-12-29 14:44:44 +03:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (va->va_addr == VRIPCF_ADDR_DEFAULT)
|
|
|
|
return 0;
|
|
|
|
|
2001-02-15 06:20:10 +03:00
|
|
|
if (cf->cf_loc[VRIPCF_PLATFORM] == 0)
|
2000-12-29 14:44:44 +03:00
|
|
|
return 0;
|
2001-02-15 06:20:10 +03:00
|
|
|
if (cf->cf_loc[VRIPCF_PLATFORM] != -1) { /* if specify */
|
|
|
|
mask = PLATID_DEREF(cf->cf_loc[VRIPCF_PLATFORM]);
|
2001-02-27 11:48:38 +03:00
|
|
|
VPRINTF(("vrc4172pwmprobe: check platid\n"));
|
2000-12-29 14:44:44 +03:00
|
|
|
if (platid_match(&platid, &mask) == 0)
|
|
|
|
return 0;
|
2001-02-27 11:48:38 +03:00
|
|
|
param = vrc4172pwm_getparam();
|
|
|
|
if (param != NULL && param->brokenprobe)
|
|
|
|
probe = 0;
|
2000-12-29 14:44:44 +03:00
|
|
|
}
|
2001-02-27 11:48:38 +03:00
|
|
|
if (probe) {
|
|
|
|
if (bus_space_map(va->va_iot, va->va_addr, va->va_size, 0, &ioh)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
data = bus_space_read_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN);
|
|
|
|
bus_space_write_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN, 0xff);
|
|
|
|
if ((data2 = bus_space_read_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN))
|
|
|
|
== VRC2_PWM_LCDEN_MASK) {
|
|
|
|
VPRINTF(("vrc4172pwmprobe: VRC2_PWM_LCDDUTYEN found\n"));
|
|
|
|
ret = 1;
|
|
|
|
} else {
|
|
|
|
VPRINTF(("vrc4172pwmprobe: VRC2_PWM_LCDDUTYEN not found org=%x, data=%x!=%x\n", data, data2, VRC2_PWM_LCDEN_MASK));
|
|
|
|
}
|
|
|
|
bus_space_write_2(va->va_iot, ioh, VRC2_PWM_LCDDUTYEN, data);
|
|
|
|
bus_space_unmap(va->va_iot, ioh, va->va_size);
|
|
|
|
} else
|
2000-12-29 14:44:44 +03:00
|
|
|
ret = 1;
|
2001-02-27 11:48:38 +03:00
|
|
|
VPRINTF(("vrc4172pwmprobe: return %d\n", ret));
|
2000-12-29 14:44:44 +03:00
|
|
|
return ret;
|
2000-11-11 07:42:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vrc4172pwmattach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct vrc4172pwm_softc *sc = (struct vrc4172pwm_softc *)self;
|
|
|
|
struct vrip_attach_args *va = aux;
|
|
|
|
|
|
|
|
bus_space_tag_t iot = va->va_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
|
|
|
|
if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
|
|
|
|
printf(": can't map bus space\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
VDUMPREG(sc);
|
|
|
|
/* basic setup */
|
|
|
|
sc->sc_pmhook = config_hook(CONFIG_HOOK_PMEVENT,
|
2000-12-29 14:44:44 +03:00
|
|
|
CONFIG_HOOK_PMEVENT_HARDPOWER,
|
2000-11-11 07:42:08 +03:00
|
|
|
CONFIG_HOOK_SHARE,
|
|
|
|
vrc4172pwm_pmevent, sc);
|
2000-12-29 14:44:44 +03:00
|
|
|
sc->sc_lcdhook = config_hook(CONFIG_HOOK_POWERCONTROL,
|
|
|
|
CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
|
|
|
|
CONFIG_HOOK_SHARE,
|
|
|
|
vrc4172pwm_event, sc);
|
|
|
|
sc->sc_getlcdhook = config_hook(CONFIG_HOOK_GET,
|
|
|
|
CONFIG_HOOK_POWER_LCDLIGHT,
|
2000-11-11 07:42:08 +03:00
|
|
|
CONFIG_HOOK_SHARE,
|
|
|
|
vrc4172pwm_event, sc);
|
|
|
|
sc->sc_sethook = config_hook(CONFIG_HOOK_SET,
|
2000-12-29 14:44:44 +03:00
|
|
|
CONFIG_HOOK_BRIGHTNESS,
|
2000-11-11 07:42:08 +03:00
|
|
|
CONFIG_HOOK_SHARE,
|
|
|
|
vrc4172pwm_event, sc);
|
|
|
|
sc->sc_gethook = config_hook(CONFIG_HOOK_GET,
|
2000-12-29 14:44:44 +03:00
|
|
|
CONFIG_HOOK_BRIGHTNESS,
|
|
|
|
CONFIG_HOOK_SHARE,
|
|
|
|
vrc4172pwm_event, sc);
|
|
|
|
sc->sc_getmaxhook = config_hook(CONFIG_HOOK_GET,
|
|
|
|
CONFIG_HOOK_BRIGHTNESS_MAX,
|
2000-11-11 07:42:08 +03:00
|
|
|
CONFIG_HOOK_SHARE,
|
|
|
|
vrc4172pwm_event, sc);
|
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
vrc4172pwm_init_brightness(sc);
|
2001-03-24 18:53:37 +03:00
|
|
|
if (sc->sc_param == NULL)
|
|
|
|
printf("vrc4172pwm: NO parameter found. DISABLE pwm control\n");;
|
2000-11-11 07:42:08 +03:00
|
|
|
this_pwm = sc;
|
|
|
|
}
|
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
/*
|
|
|
|
* get platform related brightness paramerters
|
|
|
|
*/
|
|
|
|
struct vrc4172pwm_param *
|
|
|
|
vrc4172pwm_getparam()
|
|
|
|
{
|
2000-12-29 18:54:17 +03:00
|
|
|
struct platid_data *p;
|
2000-12-29 14:44:44 +03:00
|
|
|
|
2000-12-29 18:54:17 +03:00
|
|
|
if ((p = platid_search(&platid, vrc4172pwm_platid_param_table)))
|
|
|
|
return p->data;
|
2000-12-29 14:44:44 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-11-11 13:08:12 +03:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Initialize PWM brightness parameters
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vrc4172pwm_init_brightness(sc)
|
2000-12-29 14:44:44 +03:00
|
|
|
struct vrc4172pwm_softc *sc;
|
2000-11-11 13:08:12 +03:00
|
|
|
{
|
2000-12-29 14:44:44 +03:00
|
|
|
sc->sc_param = vrc4172pwm_getparam();
|
2000-11-11 13:08:12 +03:00
|
|
|
sc->sc_raw_freq = vrc4172pwm_read(sc, VRC2_PWM_LCDFREQ);
|
|
|
|
sc->sc_raw_duty = vrc4172pwm_read(sc, VRC2_PWM_LCDDUTY);
|
2000-12-29 14:44:44 +03:00
|
|
|
sc->sc_brightness = vrc4172pwm_rawduty2brightness(sc);
|
2001-03-12 11:46:27 +03:00
|
|
|
sc->sc_light = vrc4172pwm_get_light(sc);
|
|
|
|
DPRINTF(("vrc4172pwm_init_brightness: param=0x%x, freq=0x%x, duty=0x%x, blightness=%d light=%d\n", (int)sc->sc_param, sc->sc_raw_freq, sc->sc_raw_duty, sc->sc_brightness, sc->sc_light));
|
2000-12-29 14:44:44 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* backlight on/off
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vrc4172pwm_light(sc, on)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
int on;
|
|
|
|
{
|
2001-02-16 15:31:46 +03:00
|
|
|
int brightness;
|
|
|
|
|
2001-02-15 06:20:10 +03:00
|
|
|
DPRINTF(("vrc4172pwm_light: %s\n", on?"ON":"OFF"));
|
2001-02-16 15:31:46 +03:00
|
|
|
if (on) {
|
|
|
|
vrc4172pwm_set_brightness(sc, sc->sc_brightness);
|
2000-12-29 14:44:44 +03:00
|
|
|
vrc4172pwm_write(sc, VRC2_PWM_LCDDUTYEN, VRC2_PWM_LCD_EN);
|
2001-02-16 15:31:46 +03:00
|
|
|
} else {
|
|
|
|
brightness = sc->sc_brightness; /* save */
|
|
|
|
vrc4172pwm_set_brightness(sc, 0);
|
|
|
|
/* need this, break sc->sc_brightness */
|
|
|
|
sc->sc_brightness = brightness; /* resume */
|
2000-12-29 14:44:44 +03:00
|
|
|
vrc4172pwm_write(sc, VRC2_PWM_LCDDUTYEN, VRC2_PWM_LCD_DIS);
|
2001-02-16 15:31:46 +03:00
|
|
|
}
|
2001-03-12 11:46:27 +03:00
|
|
|
sc->sc_light = on;
|
2000-12-29 14:44:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get backlight on/off
|
|
|
|
*/
|
2001-03-12 11:46:27 +03:00
|
|
|
int
|
2000-12-29 14:44:44 +03:00
|
|
|
vrc4172pwm_get_light(sc)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
{
|
2001-03-12 11:46:27 +03:00
|
|
|
return VRC2_PWM_LCDEN_MASK&vrc4172pwm_read(sc, VRC2_PWM_LCDDUTYEN);
|
2000-12-29 14:44:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set brightness
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vrc4172pwm_set_brightness(sc, val)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
int val;
|
|
|
|
{
|
|
|
|
int raw;
|
|
|
|
|
|
|
|
if (sc->sc_param == NULL)
|
|
|
|
return;
|
2001-02-15 06:20:10 +03:00
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
2000-12-29 14:44:44 +03:00
|
|
|
if (val > VRC2_PWM_MAX_BRIGHTNESS)
|
|
|
|
val = VRC2_PWM_MAX_BRIGHTNESS;
|
|
|
|
if (val > sc->sc_param->n_brightness)
|
|
|
|
val = sc->sc_param->n_brightness;
|
|
|
|
sc->sc_brightness = val;
|
|
|
|
raw = vrc4172pwm_brightness2rawduty(sc);
|
|
|
|
vrc4172pwm_write(sc, VRC2_PWM_LCDDUTY, raw);
|
2001-02-15 06:20:10 +03:00
|
|
|
DPRINTF(("vrc4172pwm_set_brightness: val=%d raw=0x%x\n", val, raw));
|
2000-12-29 14:44:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get brightness
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vrc4172pwm_get_brightness(sc)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
{
|
|
|
|
if (sc->sc_param == NULL)
|
|
|
|
return VRC2_PWM_MAX_BRIGHTNESS;
|
|
|
|
return sc->sc_brightness;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PWM duty to brightness
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vrc4172pwm_rawduty2brightness(sc)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (sc->sc_param == NULL)
|
2001-02-15 06:20:10 +03:00
|
|
|
return VRC2_PWM_MAX_BRIGHTNESS;
|
2000-12-29 14:44:44 +03:00
|
|
|
for (i = 0; i < sc->sc_param->n_brightness; i++) {
|
2001-02-27 11:48:38 +03:00
|
|
|
if (sc->sc_raw_duty <= sc->sc_param->bvalues[i])
|
2000-12-29 14:44:44 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= sc->sc_param->n_brightness-1)
|
|
|
|
return sc->sc_param->n_brightness-1;
|
|
|
|
else
|
|
|
|
return i;
|
|
|
|
|
2000-11-11 13:08:12 +03:00
|
|
|
}
|
2000-11-11 07:42:08 +03:00
|
|
|
|
2000-12-29 14:44:44 +03:00
|
|
|
/*
|
|
|
|
* brightness to raw duty
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vrc4172pwm_brightness2rawduty(sc)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
{
|
|
|
|
if (sc->sc_param == NULL)
|
2001-02-15 06:20:10 +03:00
|
|
|
return VRC2_PWM_LCDDUTY_MASK;
|
2001-02-27 11:48:38 +03:00
|
|
|
return sc->sc_param->bvalues[sc->sc_brightness];
|
2000-12-29 14:44:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-11 07:42:08 +03:00
|
|
|
/*
|
|
|
|
* PWM config hook events
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vrc4172pwm_event(ctx, type, id, msg)
|
|
|
|
void *ctx;
|
|
|
|
int type;
|
|
|
|
long id;
|
|
|
|
void *msg;
|
|
|
|
{
|
|
|
|
struct vrc4172pwm_softc *sc = (struct vrc4172pwm_softc *)ctx;
|
|
|
|
int why =(int)msg;
|
|
|
|
|
|
|
|
if (type == CONFIG_HOOK_POWERCONTROL
|
|
|
|
&& id == CONFIG_HOOK_POWERCONTROL_LCDLIGHT) {
|
2001-02-26 12:33:03 +03:00
|
|
|
DPRINTF(("vrc4172pwm:POWERCONTROL_LCDLIGHT: %d\n", why));
|
2000-11-11 13:08:12 +03:00
|
|
|
vrc4172pwm_light(sc, why);
|
2000-11-11 07:42:08 +03:00
|
|
|
} else if (type == CONFIG_HOOK_GET
|
2000-12-29 14:44:44 +03:00
|
|
|
&& id == CONFIG_HOOK_POWER_LCDLIGHT) {
|
|
|
|
*(int *)msg = vrc4172pwm_get_light(sc);
|
2001-02-26 12:33:03 +03:00
|
|
|
DPRINTF(("vrc4172pwm:GET LCDLIGHT: %d\n", *(int *)msg));
|
2000-12-29 14:44:44 +03:00
|
|
|
} else if (type == CONFIG_HOOK_GET
|
|
|
|
&& id == CONFIG_HOOK_BRIGHTNESS) {
|
|
|
|
*(int *)msg = vrc4172pwm_get_brightness(sc);
|
2001-02-26 12:33:03 +03:00
|
|
|
DPRINTF(("vrc4172pwm:GET BRIGHTNESS: %d\n", *(int *)msg));
|
2000-12-29 14:44:44 +03:00
|
|
|
} else if (type == CONFIG_HOOK_GET
|
|
|
|
&& id == CONFIG_HOOK_BRIGHTNESS_MAX) {
|
|
|
|
if (sc->sc_param == NULL)
|
|
|
|
*(int *)msg = VRC2_PWM_MAX_BRIGHTNESS;
|
|
|
|
else
|
|
|
|
*(int *)msg = sc->sc_param->n_brightness-1;
|
2001-02-26 12:33:03 +03:00
|
|
|
DPRINTF(("vrc4172pwm:GET MAX BRIGHTNESS: %d\n", *(int *)msg));
|
2000-11-11 07:42:08 +03:00
|
|
|
} else if (type == CONFIG_HOOK_SET
|
2000-12-29 14:44:44 +03:00
|
|
|
&& id == CONFIG_HOOK_BRIGHTNESS) {
|
2001-02-26 12:33:03 +03:00
|
|
|
DPRINTF(("vrc4172pwm:SET BRIGHTNESS: %d\n", *(int *)msg));
|
2000-12-29 14:44:44 +03:00
|
|
|
vrc4172pwm_set_brightness(sc, *(int *)msg);
|
2001-02-16 15:31:46 +03:00
|
|
|
} else {
|
2001-02-26 12:33:03 +03:00
|
|
|
DPRINTF(("vrc4172pwm:unknown event: type %d id %ld\n", type, id));
|
2000-11-11 07:42:08 +03:00
|
|
|
return 1;
|
2001-02-16 15:31:46 +03:00
|
|
|
}
|
2000-11-11 07:42:08 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PWM config hook events
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
vrc4172pwm_pmevent(ctx, type, id, msg)
|
|
|
|
void *ctx;
|
|
|
|
int type;
|
|
|
|
long id;
|
|
|
|
void *msg;
|
|
|
|
{
|
|
|
|
struct vrc4172pwm_softc *sc = (struct vrc4172pwm_softc *)ctx;
|
|
|
|
int why =(int)msg;
|
|
|
|
|
|
|
|
if (type != CONFIG_HOOK_PMEVENT)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch (why) {
|
2000-12-29 14:44:44 +03:00
|
|
|
case PWR_STANDBY:
|
2000-11-11 13:08:12 +03:00
|
|
|
case PWR_SUSPEND:
|
2001-03-12 11:46:27 +03:00
|
|
|
sc->sc_light_save = sc->sc_light;
|
2000-11-11 13:08:12 +03:00
|
|
|
vrc4172pwm_light(sc, 0);
|
|
|
|
break;
|
|
|
|
case PWR_RESUME:
|
2001-03-12 11:46:27 +03:00
|
|
|
vrc4172pwm_light(sc, sc->sc_light_save);
|
2000-11-11 13:08:12 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 1;
|
2000-11-11 07:42:08 +03:00
|
|
|
}
|
2000-11-11 13:08:12 +03:00
|
|
|
|
2000-11-11 07:42:08 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dump pwm registers
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vrc4172pwm_dumpreg(sc)
|
|
|
|
struct vrc4172pwm_softc *sc;
|
|
|
|
{
|
|
|
|
int en, freq, duty;
|
|
|
|
|
|
|
|
en = vrc4172pwm_read(sc, VRC2_PWM_LCDDUTYEN);
|
|
|
|
freq = vrc4172pwm_read(sc, VRC2_PWM_LCDFREQ);
|
|
|
|
duty = vrc4172pwm_read(sc, VRC2_PWM_LCDDUTY);
|
|
|
|
|
2001-02-15 06:20:10 +03:00
|
|
|
printf("vrc4172pwm: dumpreg: lightenable = %d, freq = 0x%x, duty = 0x%x\n",
|
2000-11-11 07:42:08 +03:00
|
|
|
en, freq, duty);
|
|
|
|
}
|
2000-11-11 13:08:12 +03:00
|
|
|
|
2000-11-11 07:42:08 +03:00
|
|
|
/* end */
|