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