Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/evbmips add poweroff support, make sure we actually...
details: https://anonhg.NetBSD.org/src/rev/dcd673fe4abb
branches: trunk
changeset: 785165:dcd673fe4abb
user: macallan <macallan%NetBSD.org@localhost>
date: Thu Feb 28 13:21:15 2013 +0000
description:
add poweroff support, make sure we actually charge the battery
diffstat:
sys/arch/evbmips/conf/files.loongson | 4 +-
sys/arch/evbmips/loongson/dev/stvii.c | 82 ++++++++++++++++++++++++++--------
2 files changed, 65 insertions(+), 21 deletions(-)
diffs (192 lines):
diff -r 7fd3f1cbd5ee -r dcd673fe4abb sys/arch/evbmips/conf/files.loongson
--- a/sys/arch/evbmips/conf/files.loongson Thu Feb 28 13:02:20 2013 +0000
+++ b/sys/arch/evbmips/conf/files.loongson Thu Feb 28 13:21:15 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.loongson,v 1.3 2012/03/02 13:20:57 nonaka Exp $
+# $NetBSD: files.loongson,v 1.4 2013/02/28 13:21:15 macallan Exp $
# Standard stanzas config(8) can't run without
maxpartitions 16
@@ -77,7 +77,7 @@
# Gdium ST7 controller
device stvii
attach stvii at iic
-file arch/evbmips/loongson/dev/stvii.c stvii
+file arch/evbmips/loongson/dev/stvii.c stvii needs-flag
defflag opt_stvii.h STVII_DEBUG
# SM502 OHCI
diff -r 7fd3f1cbd5ee -r dcd673fe4abb sys/arch/evbmips/loongson/dev/stvii.c
--- a/sys/arch/evbmips/loongson/dev/stvii.c Thu Feb 28 13:02:20 2013 +0000
+++ b/sys/arch/evbmips/loongson/dev/stvii.c Thu Feb 28 13:21:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: stvii.c,v 1.3 2011/09/15 19:29:23 macallan Exp $ */
+/* $NetBSD: stvii.c,v 1.4 2013/02/28 13:21:15 macallan Exp $ */
/*-
* Copyright (C) 2011 Michael Lorenz.
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: stvii.c,v 1.3 2011/09/15 19:29:23 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: stvii.c,v 1.4 2013/02/28 13:21:15 macallan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -94,7 +94,8 @@
i2c_tag_t sc_i2c;
int sc_address, sc_version;
int sc_sleep;
- int sc_flags, sc_charge;
+ int sc_flags, sc_charge, sc_bat_level;
+ uint8_t sc_control;
struct sysmon_envsys *sc_sme;
envsys_data_t sc_sensor[BAT_NSENSORS];
struct sysmon_pswitch sc_sm_acpower;
@@ -109,10 +110,17 @@
static void stvii_worker(void *);
static void stvii_setup_envsys(struct stvii_softc *);
static void stvii_refresh(struct sysmon_envsys *, envsys_data_t *);
+static int stvii_battery_level(struct stvii_softc *);
CFATTACH_DECL_NEW(stvii, sizeof(struct stvii_softc),
stvii_match, stvii_attach, NULL, NULL);
+void stvii_poweroff(void);
+static device_t stvii_dev = NULL;
+
+#define BAT_FULL 8000000
+#define BAT_LOW 7100000
+
static int
stvii_match(device_t parent, cfdata_t cf, void *aux)
{
@@ -139,6 +147,7 @@
uint8_t ver, reg;
sc->sc_dev = self;
+ stvii_dev = self;
sc->sc_address = args->ia_addr;
aprint_normal(": ST7 Microcontroller\n");
sc->sc_i2c = args->ia_tag;
@@ -155,12 +164,15 @@
printf("\n");
}
#endif
- stvii_writereg(sc, ST7_SIGNATURE, STSIG_EC_CONTROL);
+ stvii_writereg(sc, ST7_SIGNATURE, STSIG_OS_CONTROL);
reg = stvii_readreg(sc, ST7_CONTROL);
reg |= STC_RADIO_ENABLE;
stvii_writereg(sc, ST7_CONTROL, reg);
+ sc->sc_control = reg;
reg = stvii_readreg(sc, ST7_CONTROL);
+ sc->sc_bat_level = stvii_battery_level(sc);
+
if (kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL, stvii_worker, sc,
NULL, "stvii") != 0) {
aprint_error_dev(sc->sc_dev, "Failed to start kernel thread\n");
@@ -239,9 +251,15 @@
stvii_worker(void *cookie)
{
struct stvii_softc *sc = cookie;
- int status = 0, st;
- int battery_level = 0, bl;
+ int status = 0, st, cnt = 4;
+ int bl;
+ int charging = 0;
int ok = TRUE;
+ uint8_t nctrl;
+
+ /* if we were charging when we took over, keep charging */
+ if (sc->sc_control & STC_CHARGE_ENABLE)
+ charging = 1;
while (ok) {
st = stvii_readreg(sc, ST7_STATUS);
@@ -281,13 +299,29 @@
status = st;
}
sc->sc_flags = status;
- if (0) {
+ if (cnt >= 4) {
+ nctrl = sc->sc_control & ~(STC_TRICKLE | STC_CHARGE_ENABLE);
bl = stvii_battery_level(sc);
- if (bl != battery_level) {
- printf("battery: %d\n", bl);
- battery_level = bl;
+ sc->sc_bat_level = bl;
+ if (charging & (bl > BAT_FULL)) {
+ /* stop charging, we're full */
+ charging = 0;
+ } else if (!charging & (bl < BAT_LOW)) {
+ charging = 1;
}
- }
+ if (st & STS_AC_AVAILABLE) {
+ if (charging) {
+ nctrl |= STC_CHARGE_ENABLE;
+ } else
+ nctrl |= STC_TRICKLE;
+ }
+ if (nctrl != sc->sc_control) {
+ sc->sc_control = nctrl;
+ stvii_writereg(sc, ST7_CONTROL, sc->sc_control);
+ }
+ cnt = 0;
+ } else
+ cnt++;
tsleep(&sc->sc_sleep, 0, "stvii", hz / 2);
}
}
@@ -335,7 +369,7 @@
stvii_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
{
struct stvii_softc *sc = sme->sme_cookie;
- int which = edata->sensor, ctl, bat;
+ int which = edata->sensor;
edata->state = ENVSYS_SINVALID;
switch (which) {
@@ -349,23 +383,33 @@
break;
case BAT_CHARGE:
if (sc->sc_flags & STS_BATTERY_PRESENT) {
- bat = stvii_battery_level(sc);
- edata->value_cur = bat;
+ edata->value_cur = sc->sc_bat_level;
edata->state = ENVSYS_SVALID;
}
break;
case BAT_MAX_CHARGE:
if (sc->sc_flags & STS_BATTERY_PRESENT) {
- edata->value_cur = 8300000;
+ edata->value_cur = 8000000;
/*edata->state = ENVSYS_SVALID;*/
}
break;
case BAT_CHARGING:
- ctl = stvii_readreg(sc, ST7_CONTROL);
- if (ctl != -1) {
- edata->value_cur = ctl & STC_CHARGE_ENABLE;
- }
+ edata->value_cur = sc->sc_control & STC_CHARGE_ENABLE;
edata->state = ENVSYS_SVALID;
break;
}
}
+
+void
+stvii_poweroff(void)
+{
+ struct stvii_softc *sc = device_private(stvii_dev);
+ int ctl;
+
+ if (sc == NULL)
+ return;
+ ctl = stvii_readreg(sc, ST7_CONTROL);
+ if (ctl == -1)
+ return;
+ stvii_writereg(sc, ST7_CONTROL, ctl & ~(STC_MAIN_POWER | STC_DDR_POWER));
+}
Home |
Main Index |
Thread Index |
Old Index