summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2003-11-03 11:03:40 +0000
committerphk <phk@FreeBSD.org>2003-11-03 11:03:40 +0000
commit1333a1f77f0d29c61bfa6fb3e936ca39f586c2c7 (patch)
tree9324e84f839d945bef806d521cf7268d28817ce0
parent88abb8f31b63eeebffc86b9c047a550425afd35f (diff)
downloadFreeBSD-src-1333a1f77f0d29c61bfa6fb3e936ca39f586c2c7.zip
FreeBSD-src-1333a1f77f0d29c61bfa6fb3e936ca39f586c2c7.tar.gz
Change /dev/soekris-errled to be /dev/led/error and make it conditional
on CPU_SOEKRIS. Note the subtle change in semantfics for 'f%d' flash instruction and the new morse facility (see details in dev/led/led.c)
-rw-r--r--sys/conf/files1
-rw-r--r--sys/i386/i386/elan-mmcr.c148
2 files changed, 26 insertions, 123 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 689d928..889b107 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -495,6 +495,7 @@ dev/ispfw/ispfw.c optional ispfw
dev/joy/joy.c optional joy
dev/joy/joy_isa.c optional joy isa
dev/joy/joy_pccard.c optional joy pccard
+dev/led/led.c optional cpu_soekris
dev/lge/if_lge.c optional lge
dev/lmc/if_lmc.c optional lmc nowerror
dev/lnc/if_lnc.c optional lnc
diff --git a/sys/i386/i386/elan-mmcr.c b/sys/i386/i386/elan-mmcr.c
index dd89af6..1d37299 100644
--- a/sys/i386/i386/elan-mmcr.c
+++ b/sys/i386/i386/elan-mmcr.c
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <sys/timepps.h>
#include <sys/watchdog.h>
+#include <dev/led/led.h>
#include <machine/md_var.h>
#include <vm/vm.h>
@@ -52,12 +53,6 @@ __FBSDID("$FreeBSD$");
uint16_t *elan_mmcr;
-/* Relating to the /dev/soekris-errled */
-static struct mtx errled_mtx;
-static char *errled;
-static struct callout_handle errled_h = CALLOUT_HANDLE_INITIALIZER(&errled_h);
-static void timeout_errled(void *);
-
#ifdef ELAN_PPS
/* Relating to the PPS-api */
static struct pps_state elan_pps;
@@ -160,20 +155,31 @@ init_AMD_Elan_sc520(void)
tc_init(&elan_timecounter);
}
-
-/*
- * Device driver initialization stuff
- */
-
-static d_write_t elan_write;
static d_ioctl_t elan_ioctl;
static d_mmap_t elan_mmap;
+#ifdef CPU_SOEKRIS
+/* Support for /dev/led/error */
+static u_int soekris_errled_cookie = 0x200;
+static dev_t soekris_errled_dev;
+
+static void
+gpio_led(void *cookie, int state)
+{
+ u_int u;
+
+ u = *(u_int *)cookie;
+
+ if (state)
+ elan_mmcr[0xc34 / 2] = u;
+ else
+ elan_mmcr[0xc38 / 2] = u;
+}
+#endif /* CPU_SOEKRIS */
+
#define ELAN_MMCR 0
-#define ELAN_ERRLED 1
static struct cdevsw elan_cdevsw = {
- .d_write = elan_write,
.d_ioctl = elan_ioctl,
.d_mmap = elan_mmap,
.d_name = "elan",
@@ -188,119 +194,15 @@ elan_drvinit(void)
printf("Elan-mmcr driver: MMCR at %p\n", elan_mmcr);
make_dev(&elan_cdevsw, ELAN_MMCR,
UID_ROOT, GID_WHEEL, 0600, "elan-mmcr");
- make_dev(&elan_cdevsw, ELAN_ERRLED,
- UID_ROOT, GID_WHEEL, 0600, "soekris-errled");
- mtx_init(&errled_mtx, "Elan-errled", MTX_DEF, 0);
- return;
-}
-SYSINIT(elan, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, elan_drvinit, NULL);
-
-#define LED_ON() do {elan_mmcr[0xc34 / 2] = 0x200;} while(0)
-#define LED_OFF() do {elan_mmcr[0xc38 / 2] = 0x200;} while(0)
-
-static void
-timeout_errled(void *p)
-{
- static enum {NOTHING, FLASH, DIGIT} mode;
- static int count, cnt2, state;
-
- mtx_lock(&errled_mtx);
- if (p != NULL) {
- mode = NOTHING;
- /* Our instructions changed */
- if (*errled == '1') { /* Turn LED on */
- LED_ON();
- } else if (*errled == '0') { /* Turn LED off */
- LED_OFF();
- } else if (*errled == 'f') { /* Flash */
- mode = FLASH;
- cnt2 = 10;
- if (errled[1] >= '1' && errled[1] <= '9')
- cnt2 = errled[1] - '0';
- cnt2 = hz / cnt2;
- LED_ON();
- errled_h = timeout(timeout_errled, NULL, cnt2);
- } else if (*errled == 'd') { /* Digit */
- mode = DIGIT;
- count = 0;
- cnt2 = 0;
- state = 0;
- LED_OFF();
- errled_h = timeout(timeout_errled, NULL, hz/10);
- }
- } else if (mode == FLASH) {
- if (count)
- LED_ON();
- else
- LED_OFF();
- count = !count;
- errled_h = timeout(timeout_errled, NULL, cnt2);
- } else if (mode == DIGIT) {
- if (cnt2 > 0) {
- if (state) {
- LED_OFF();
- state = 0;
- cnt2--;
- } else {
- LED_ON();
- state = 1;
- }
- errled_h = timeout(timeout_errled, NULL, hz/5);
- } else {
- do
- count++;
- while (errled[count] != '\0' &&
- (errled[count] < '0' || errled[count] > '9'));
- if (errled[count] == '\0') {
- count = 0;
- errled_h = timeout(timeout_errled, NULL, hz * 2);
- } else {
- cnt2 = errled[count] - '0';
- state = 0;
- errled_h = timeout(timeout_errled, NULL, hz);
- }
- }
- }
- mtx_unlock(&errled_mtx);
+#ifdef CPU_SOEKRIS
+ soekris_errled_dev =
+ led_create(gpio_led, &soekris_errled_cookie, "error");
+#endif /* CPU_SOEKRIS */
return;
}
-/*
- * The write function is used for the error-LED.
- */
-
-static int
-elan_write(dev_t dev, struct uio *uio, int ioflag)
-{
- int error;
- char *s, *q;
-
- if (minor(dev) != ELAN_ERRLED)
- return (EOPNOTSUPP);
-
- if (uio->uio_resid > 512)
- return (EINVAL);
- s = malloc(uio->uio_resid + 1, M_DEVBUF, M_WAITOK);
- if (s == NULL)
- return (ENOMEM);
- untimeout(timeout_errled, NULL, errled_h);
- s[uio->uio_resid] = '\0';
- error = uiomove(s, uio->uio_resid, uio);
- if (error) {
- free(s, M_DEVBUF);
- return (error);
- }
- mtx_lock(&errled_mtx);
- q = errled;
- errled = s;
- mtx_unlock(&errled_mtx);
- if (q != NULL)
- free(q, M_DEVBUF);
- timeout_errled(errled);
-
- return(0);
-}
+SYSINIT(elan, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, elan_drvinit, NULL);
static int
elan_mmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
OpenPOWER on IntegriCloud