2 * Copyright (c) 2008 Sam Leffler. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
29 * Gateworks Cambria Octal LED Latch driver.
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
37 #include <machine/armreg.h>
39 #include <arm/xscale/ixp425/ixp425reg.h>
40 #include <arm/xscale/ixp425/ixp425var.h>
42 #include <dev/led/led.h>
46 bus_space_tag_t sc_iot;
47 bus_space_handle_t sc_ioh;
48 struct cdev *sc_leds[8];
53 update_latch(struct led_softc *sc, int bit, int onoff)
59 bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, sc->sc_latch);
61 static void led_A(void *arg, int onoff) { update_latch(arg, 1<<0, onoff); }
62 static void led_B(void *arg, int onoff) { update_latch(arg, 1<<1, onoff); }
63 static void led_C(void *arg, int onoff) { update_latch(arg, 1<<2, onoff); }
64 static void led_D(void *arg, int onoff) { update_latch(arg, 1<<3, onoff); }
65 static void led_E(void *arg, int onoff) { update_latch(arg, 1<<4, onoff); }
66 static void led_F(void *arg, int onoff) { update_latch(arg, 1<<5, onoff); }
67 static void led_G(void *arg, int onoff) { update_latch(arg, 1<<6, onoff); }
68 static void led_H(void *arg, int onoff) { update_latch(arg, 1<<7, onoff); }
71 led_probe(device_t dev)
73 device_set_desc(dev, "Gateworks Octal LED Latch");
78 led_attach(device_t dev)
80 struct led_softc *sc = device_get_softc(dev);
81 struct ixp425_softc *sa = device_get_softc(device_get_parent(dev));
84 sc->sc_iot = sa->sc_iot;
85 /* NB: write anywhere works, use first location */
86 if (bus_space_map(sc->sc_iot, CAMBRIA_OCTAL_LED_HWBASE, sizeof(uint8_t),
88 device_printf(dev, "cannot map LED latch (0x%lx)",
89 CAMBRIA_OCTAL_LED_HWBASE);
93 sc->sc_leds[0] = led_create(led_A, sc, "A");
94 sc->sc_leds[1] = led_create(led_B, sc, "B");
95 sc->sc_leds[2] = led_create(led_C, sc, "C");
96 sc->sc_leds[3] = led_create(led_D, sc, "D");
97 sc->sc_leds[4] = led_create(led_E, sc, "E");
98 sc->sc_leds[5] = led_create(led_F, sc, "F");
99 sc->sc_leds[6] = led_create(led_G, sc, "G");
100 sc->sc_leds[7] = led_create(led_H, sc, "H");
106 led_detach(device_t dev)
108 struct led_softc *sc = device_get_softc(dev);
111 for (i = 0; i < 8; i++) {
112 struct cdev *led = sc->sc_leds[i];
119 static device_method_t led_methods[] = {
120 DEVMETHOD(device_probe, led_probe),
121 DEVMETHOD(device_attach, led_attach),
122 DEVMETHOD(device_detach, led_detach),
127 static driver_t led_driver = {
130 sizeof(struct led_softc),
132 static devclass_t led_devclass;
133 DRIVER_MODULE(led_cambria, ixp, led_driver, led_devclass, 0, 0);