summaryrefslogtreecommitdiff
path: root/sys/arch/sparc64/dev
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2004-10-01 18:18:50 +0000
committerJason Wright <jason@cvs.openbsd.org>2004-10-01 18:18:50 +0000
commit07f253751fdc947b9c4695a8e03c54642df44fea (patch)
treecb49a0bcf38166dd0f1313d3aa51d7a7ce6a97e4 /sys/arch/sparc64/dev
parent9a47a1174cb544bd7c4ab22a11f4144ef6340ab6 (diff)
add a blink_led API (shaves ~1k from GENERIC) rather than have the same
logic in 3 files. Devices register a function to be called to turn the led on and off based on load average. (Note: rerun config and make depend)
Diffstat (limited to 'sys/arch/sparc64/dev')
-rw-r--r--sys/arch/sparc64/dev/auxio.c44
-rw-r--r--sys/arch/sparc64/dev/auxiovar.h11
-rw-r--r--sys/arch/sparc64/dev/clkbrd.c43
-rw-r--r--sys/arch/sparc64/dev/clkbrdvar.h6
-rw-r--r--sys/arch/sparc64/dev/fhc.c43
-rw-r--r--sys/arch/sparc64/dev/fhcvar.h6
6 files changed, 37 insertions, 116 deletions
diff --git a/sys/arch/sparc64/dev/auxio.c b/sys/arch/sparc64/dev/auxio.c
index 1e33b7298be..daf8ee3bbe5 100644
--- a/sys/arch/sparc64/dev/auxio.c
+++ b/sys/arch/sparc64/dev/auxio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auxio.c,v 1.5 2003/02/17 01:29:19 henric Exp $ */
+/* $OpenBSD: auxio.c,v 1.6 2004/10/01 18:18:49 jason Exp $ */
/* $NetBSD: auxio.c,v 1.1 2000/04/15 03:08:13 mrg Exp $ */
/*
@@ -72,7 +72,7 @@ struct cfdriver auxio_cd = {
NULL, "auxio", DV_DULL
};
-extern int sparc_led_blink;
+void auxio_led_blink(void *, int);
int
auxio_ebus_match(parent, cf, aux)
@@ -93,8 +93,6 @@ auxio_ebus_attach(parent, self, aux)
struct auxio_softc *sc = (struct auxio_softc *)self;
struct ebus_attach_args *ea = aux;
- timeout_set(&sc->sc_to, auxio_led_blink, sc);
-
if (ea->ea_nregs < 1 || ea->ea_nvaddrs < 1) {
printf(": no registers??\n");
return;
@@ -156,8 +154,6 @@ auxio_sbus_attach(parent, self, aux)
struct auxio_softc *sc = (struct auxio_softc *)self;
struct sbus_attach_args *sa = aux;
- timeout_set(&sc->sc_to, auxio_led_blink, sc);
-
sc->sc_tag = sa->sa_bustag;
if (sa->sa_nreg < 1 || sa->sa_npromvaddrs < 1) {
@@ -185,27 +181,18 @@ void
auxio_attach_common(sc)
struct auxio_softc *sc;
{
- if (sparc_led_blink)
- auxio_led_blink(sc);
+ sc->sc_blink.bl_func = auxio_led_blink;
+ sc->sc_blink.bl_arg = sc;
+ blink_led_register(&sc->sc_blink);
printf("\n");
}
void
-auxio_led_blink(vsc)
- void *vsc;
+auxio_led_blink(void *vsc, int on)
{
struct auxio_softc *sc = vsc;
u_int32_t led;
- int i, s;
-
- if (sc == NULL) {
- for (i = 0; i < auxio_cd.cd_ndevs; i++) {
- sc = auxio_cd.cd_devs[i];
- if (sc != NULL)
- auxio_led_blink(sc);
- }
- return;
- }
+ int s;
s = splhigh();
@@ -214,10 +201,10 @@ auxio_led_blink(vsc)
else
led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0);
- if (!sparc_led_blink)
+ if (on)
led |= AUXIO_LED_LED;
else
- led ^= AUXIO_LED_LED;
+ led &= ~AUXIO_LED_LED;
if (sc->sc_flags & AUXIO_EBUS)
bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led));
@@ -225,17 +212,4 @@ auxio_led_blink(vsc)
bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led);
splx(s);
-
- if (!sparc_led_blink)
- return;
-
- /*
- * Blink rate is:
- * full cycle every second if completely idle (loadav = 0)
- * full cycle every 2 seconds if loadav = 1
- * full cycle every 3 seconds if loadav = 2
- * etc.
- */
- s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
- timeout_add(&sc->sc_to, s);
}
diff --git a/sys/arch/sparc64/dev/auxiovar.h b/sys/arch/sparc64/dev/auxiovar.h
index 56189a83e3b..2bfc1973f53 100644
--- a/sys/arch/sparc64/dev/auxiovar.h
+++ b/sys/arch/sparc64/dev/auxiovar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: auxiovar.h,v 1.5 2003/02/10 10:02:59 jason Exp $ */
+/* $OpenBSD: auxiovar.h,v 1.6 2004/10/01 18:18:49 jason Exp $ */
/* $NetBSD: auxiovar.h,v 1.4 2000/04/15 03:08:13 mrg Exp $ */
/*
@@ -51,12 +51,5 @@ struct auxio_softc {
#define AUXIO_LEDONLY 0x1
#define AUXIO_EBUS 0x2
#define AUXIO_SBUS 0x4
- struct timeout sc_to;
+ struct blink_led sc_blink;
};
-
-/*
- * XXX: old interfaces. we set auxio_reg the first auxio we attach.
- */
-#ifndef _LOCORE
-void auxio_led_blink(void *);
-#endif
diff --git a/sys/arch/sparc64/dev/clkbrd.c b/sys/arch/sparc64/dev/clkbrd.c
index 79d9823f208..559449e4cd8 100644
--- a/sys/arch/sparc64/dev/clkbrd.c
+++ b/sys/arch/sparc64/dev/clkbrd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clkbrd.c,v 1.4 2004/09/29 17:43:33 jason Exp $ */
+/* $OpenBSD: clkbrd.c,v 1.5 2004/10/01 18:18:49 jason Exp $ */
/*
* Copyright (c) 2004 Jason L. Wright (jason@thought.net)
@@ -43,10 +43,9 @@
#include <sparc64/dev/clkbrdreg.h>
#include <sparc64/dev/clkbrdvar.h>
-extern int sparc_led_blink;
-
int clkbrd_match(struct device *, void *, void *);
void clkbrd_attach(struct device *, struct device *, void *);
+void clkbrd_led_blink(void *, int);
struct cfattach clkbrd_ca = {
sizeof(struct clkbrd_softc), clkbrd_match, clkbrd_attach
@@ -80,8 +79,6 @@ clkbrd_attach(parent, self, aux)
sc->sc_bt = fa->fa_bustag;
- timeout_set(&sc->sc_to, clkbrd_led_blink, sc);
-
if (fa->fa_nreg < 2) {
printf(": no registers\n");
return;
@@ -123,43 +120,25 @@ clkbrd_attach(parent, self, aux)
printf(": %d slots\n", slots);
- if (sparc_led_blink)
- clkbrd_led_blink(sc);
+ sc->sc_blink.bl_func = clkbrd_led_blink;
+ sc->sc_blink.bl_arg = sc;
+ blink_led_register(&sc->sc_blink);
}
void
-clkbrd_led_blink(void *vsc)
+clkbrd_led_blink(void *vsc, int on)
{
struct clkbrd_softc *sc = vsc;
- int i, s;
+ int s;
u_int8_t r;
- if (sc == NULL) {
- for (i = 0; i < clkbrd_cd.cd_ndevs; i++) {
- sc = clkbrd_cd.cd_devs[i];
- if (sc != NULL)
- clkbrd_led_blink(sc);
- }
- return;
- }
-
s = splhigh();
r = bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_CTRL);
- r ^= CLK_CTRL_RLED;
+ if (on)
+ r |= CLK_CTRL_RLED;
+ else
+ r &= ~CLK_CTRL_RLED;
bus_space_write_1(sc->sc_bt, sc->sc_creg, CLK_CTRL, r);
bus_space_read_1(sc->sc_bt, sc->sc_creg, CLK_CTRL);
splx(s);
-
- if (!sparc_led_blink)
- return;
-
- /*
- * Blink rate is:
- * full cycle every second if completely idle (loadav = 0)
- * full cycle every 2 seconds if loadav = 1
- * full cycle every 3 seconds if loadav = 2
- * etc.
- */
- s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
- timeout_add(&sc->sc_to, s);
}
diff --git a/sys/arch/sparc64/dev/clkbrdvar.h b/sys/arch/sparc64/dev/clkbrdvar.h
index 9a31aa07af0..37c45db15a3 100644
--- a/sys/arch/sparc64/dev/clkbrdvar.h
+++ b/sys/arch/sparc64/dev/clkbrdvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: clkbrdvar.h,v 1.1 2004/09/28 02:06:36 jason Exp $ */
+/* $OpenBSD: clkbrdvar.h,v 1.2 2004/10/01 18:18:49 jason Exp $ */
/*
* Copyright (c) 2004 Jason L. Wright (jason@thought.net)
@@ -33,7 +33,5 @@ struct clkbrd_softc {
bus_space_handle_t sc_vreg;
int sc_node;
int sc_has_vreg;
- struct timeout sc_to;
+ struct blink_led sc_blink;
};
-
-void clkbrd_led_blink(void *);
diff --git a/sys/arch/sparc64/dev/fhc.c b/sys/arch/sparc64/dev/fhc.c
index 868d36fe8fb..970099f9ba6 100644
--- a/sys/arch/sparc64/dev/fhc.c
+++ b/sys/arch/sparc64/dev/fhc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fhc.c,v 1.11 2004/09/28 18:37:43 jason Exp $ */
+/* $OpenBSD: fhc.c,v 1.12 2004/10/01 18:18:49 jason Exp $ */
/*
* Copyright (c) 2004 Jason L. Wright (jason@thought.net)
@@ -49,8 +49,6 @@ struct cfdriver fhc_cd = {
int fhc_print(void *, const char *);
-extern int sparc_led_blink;
-
bus_space_tag_t fhc_alloc_bus_tag(struct fhc_softc *);
int _fhc_bus_map(bus_space_tag_t, bus_space_tag_t, bus_addr_t, bus_size_t,
int, bus_space_handle_t *);
@@ -59,6 +57,7 @@ void *fhc_intr_establish(bus_space_tag_t, bus_space_tag_t, int, int, int,
bus_space_handle_t *fhc_find_intr_handle(struct fhc_softc *, int);
bus_space_handle_t *fhc_try_intr_handle(struct fhc_softc *,
bus_space_handle_t *, bus_size_t, int);
+void fhc_led_blink(void *, int);
void
fhc_attach(struct fhc_softc *sc)
@@ -69,8 +68,6 @@ fhc_attach(struct fhc_softc *sc)
printf(" board %d: %s\n", sc->sc_board,
getpropstring(sc->sc_node, "board-model"));
- timeout_set(&sc->sc_to, fhc_led_blink, sc);
-
sc->sc_cbt = fhc_alloc_bus_tag(sc);
sc->sc_ign = sc->sc_board << 1;
@@ -129,8 +126,9 @@ fhc_attach(struct fhc_softc *sc)
free(fa.fa_promvaddrs, M_DEVBUF);
}
- if (sparc_led_blink)
- fhc_led_blink(sc);
+ sc->sc_blink.bl_func = fhc_led_blink;
+ sc->sc_blink.bl_arg = sc;
+ blink_led_register(&sc->sc_blink);
}
int
@@ -309,39 +307,20 @@ fhc_intr_establish(bus_space_tag_t t, bus_space_tag_t t0, int ihandle,
}
void
-fhc_led_blink(void *vsc)
+fhc_led_blink(void *vsc, int on)
{
struct fhc_softc *sc = vsc;
- int i, s;
+ int s;
u_int32_t r;
- if (sc == NULL) {
- for (i = 0; i < fhc_cd.cd_ndevs; i++) {
- sc = fhc_cd.cd_devs[i];
- if (sc != NULL)
- fhc_led_blink(sc);
- }
- return;
- }
-
s = splhigh();
r = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_CTRL);
- r ^= FHC_P_CTRL_RLED;
+ if (on)
+ r |= FHC_P_CTRL_RLED;
+ else
+ r &= ~FHC_P_CTRL_RLED;
r &= ~(FHC_P_CTRL_AOFF | FHC_P_CTRL_BOFF | FHC_P_CTRL_SLINE);
bus_space_write_4(sc->sc_bt, sc->sc_preg, FHC_P_CTRL, r);
bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_CTRL);
splx(s);
-
- if (!sparc_led_blink)
- return;
-
- /*
- * Blink rate is:
- * full cycle every second if completely idle (loadav = 0)
- * full cycle every 2 seconds if loadav = 1
- * full cycle every 3 seconds if loadav = 2
- * etc.
- */
- s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
- timeout_add(&sc->sc_to, s);
}
diff --git a/sys/arch/sparc64/dev/fhcvar.h b/sys/arch/sparc64/dev/fhcvar.h
index 2e2eb92e51a..2cffb3e3f5c 100644
--- a/sys/arch/sparc64/dev/fhcvar.h
+++ b/sys/arch/sparc64/dev/fhcvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fhcvar.h,v 1.7 2004/09/28 18:37:43 jason Exp $ */
+/* $OpenBSD: fhcvar.h,v 1.8 2004/10/01 18:18:49 jason Exp $ */
/*
* Copyright (c) 2004 Jason L. Wright (jason@thought.net).
@@ -50,13 +50,13 @@ struct fhc_softc {
bus_space_tag_t sc_cbt;
int sc_nrange;
struct fhc_range *sc_range;
- struct timeout sc_to;
bus_space_handle_t sc_preg; /* internal regs */
bus_space_handle_t sc_ireg; /* ign regs */
bus_space_handle_t sc_freg; /* fanfail regs */
bus_space_handle_t sc_sreg; /* system regs */
bus_space_handle_t sc_ureg; /* uart regs */
bus_space_handle_t sc_treg; /* tod regs */
+ struct blink_led sc_blink;
};
void fhc_attach(struct fhc_softc *);
@@ -76,5 +76,3 @@ struct fhc_attach_args {
#define fhc_bus_map(t, slot, offset, sz, flags, hp) \
bus_space_map(t, BUS_ADDR(slot, offset), sz, flags, hp)
-
-void fhc_led_blink(void *);