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