]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/arm/xscale/ixp425/cambria_led.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / arm / xscale / ixp425 / cambria_led.c
1 /*-
2  * Copyright (c) 2008 Sam Leffler.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
23  */
24
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
27
28 /*
29  * Gateworks Cambria Octal LED Latch driver.
30  */
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/bus.h>
36
37 #include <machine/armreg.h>
38
39 #include <arm/xscale/ixp425/ixp425reg.h>
40 #include <arm/xscale/ixp425/ixp425var.h>
41
42 #include <dev/led/led.h>
43
44 struct led_softc {
45         device_t                sc_dev;
46         bus_space_tag_t         sc_iot;
47         bus_space_handle_t      sc_ioh;
48         struct cdev             *sc_leds[8];
49         uint8_t                 sc_latch;
50 };
51
52 static void
53 update_latch(struct led_softc *sc, int bit, int onoff)
54 {
55         if (onoff)
56                 sc->sc_latch &= ~bit;
57         else
58                 sc->sc_latch |= bit;
59         bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, sc->sc_latch);
60 }
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); }
69
70 static int
71 led_probe(device_t dev)
72 {
73         device_set_desc(dev, "Gateworks Octal LED Latch");
74         return (0);
75 }
76
77 static int
78 led_attach(device_t dev)
79 {
80         struct led_softc *sc = device_get_softc(dev);
81         struct ixp425_softc *sa = device_get_softc(device_get_parent(dev));
82
83         sc->sc_dev = 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),
87             0, &sc->sc_ioh)) {
88                 device_printf(dev, "cannot map LED latch (0x%lx)",
89                     CAMBRIA_OCTAL_LED_HWBASE);
90                 return ENXIO;
91         }
92
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");
101
102         return 0;
103 }
104
105 static int
106 led_detach(device_t dev)
107 {
108         struct led_softc *sc = device_get_softc(dev);
109         int i;
110
111         for (i = 0; i < 8; i++) {
112                 struct cdev *led = sc->sc_leds[i];
113                 if (led != NULL)
114                         led_destroy(led);
115         }
116         return (0);
117 }
118
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),
123
124         {0, 0},
125 };
126
127 static driver_t led_driver = {
128         "led_cambria",
129         led_methods,
130         sizeof(struct led_softc),
131 };
132 static devclass_t led_devclass;
133 DRIVER_MODULE(led_cambria, ixp, led_driver, led_devclass, 0, 0);