gpioled.c (256281) | gpioled.c (266105) |
---|---|
1/*- 2 * Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009 Oleksandr Tymoshenko <gonzo@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/10/sys/dev/gpio/gpioled.c 214971 2010-11-08 03:08:01Z thompsa $"); | 28__FBSDID("$FreeBSD: stable/10/sys/dev/gpio/gpioled.c 266105 2014-05-15 01:27:53Z loos $"); |
29 | 29 |
30#include "opt_platform.h" 31 |
|
30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bio.h> 33#include <sys/bus.h> 34#include <sys/conf.h> 35#include <sys/kernel.h> 36#include <sys/kthread.h> 37#include <sys/lock.h> 38#include <sys/malloc.h> 39#include <sys/module.h> 40#include <sys/mutex.h> 41 | 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bio.h> 35#include <sys/bus.h> 36#include <sys/conf.h> 37#include <sys/kernel.h> 38#include <sys/kthread.h> 39#include <sys/lock.h> 40#include <sys/malloc.h> 41#include <sys/module.h> 42#include <sys/mutex.h> 43 |
44#ifdef FDT 45#include <dev/fdt/fdt_common.h> 46#include <dev/gpio/gpiobusvar.h> 47#include <dev/ofw/ofw_bus.h> 48#endif 49 |
|
42#include <dev/led/led.h> 43#include <sys/gpio.h> 44#include "gpiobus_if.h" 45 46/* 47 * Only one pin for led 48 */ 49#define GPIOLED_PIN 0 --- 20 unchanged lines hidden (view full) --- 70 71static void 72gpioled_control(void *priv, int onoff) 73{ 74 struct gpioled_softc *sc = priv; 75 GPIOLED_LOCK(sc); 76 GPIOBUS_LOCK_BUS(sc->sc_busdev); 77 GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev); | 50#include <dev/led/led.h> 51#include <sys/gpio.h> 52#include "gpiobus_if.h" 53 54/* 55 * Only one pin for led 56 */ 57#define GPIOLED_PIN 0 --- 20 unchanged lines hidden (view full) --- 78 79static void 80gpioled_control(void *priv, int onoff) 81{ 82 struct gpioled_softc *sc = priv; 83 GPIOLED_LOCK(sc); 84 GPIOBUS_LOCK_BUS(sc->sc_busdev); 85 GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev); |
86 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, 87 GPIO_PIN_OUTPUT); |
|
78 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, 79 onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); 80 GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); 81 GPIOBUS_UNLOCK_BUS(sc->sc_busdev); 82 GPIOLED_UNLOCK(sc); 83} 84 | 88 GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, 89 onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); 90 GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); 91 GPIOBUS_UNLOCK_BUS(sc->sc_busdev); 92 GPIOLED_UNLOCK(sc); 93} 94 |
95#ifdef FDT 96static void 97gpioled_identify(driver_t *driver, device_t bus) 98{ 99 phandle_t child, leds, root; 100 101 root = OF_finddevice("/"); 102 if (root == 0) 103 return; 104 leds = fdt_find_compatible(root, "gpio-leds", 1); 105 if (leds == 0) 106 return; 107 108 /* Traverse the 'gpio-leds' node and add its children. */ 109 for (child = OF_child(leds); child != 0; child = OF_peer(child)) 110 if (ofw_gpiobus_add_fdt_child(bus, child) == NULL) 111 continue; 112} 113#endif 114 |
|
85static int 86gpioled_probe(device_t dev) 87{ | 115static int 116gpioled_probe(device_t dev) 117{ |
118#ifdef FDT 119 int match; 120 phandle_t node; 121 char *compat; 122 123 /* 124 * We can match against our own node compatible string and also against 125 * our parent node compatible string. The first is normally used to 126 * describe leds on a gpiobus and the later when there is a common node 127 * compatible with 'gpio-leds' which is used to concentrate all the 128 * leds nodes on the dts. 129 */ 130 match = 0; 131 if (ofw_bus_is_compatible(dev, "gpioled")) 132 match = 1; 133 134 if (match == 0) { 135 if ((node = ofw_bus_get_node(dev)) == -1) 136 return (ENXIO); 137 if ((node = OF_parent(node)) == -1) 138 return (ENXIO); 139 if (OF_getprop_alloc(node, "compatible", 1, 140 (void **)&compat) == -1) 141 return (ENXIO); 142 143 if (strcasecmp(compat, "gpio-leds") == 0) 144 match = 1; 145 146 free(compat, M_OFWPROP); 147 } 148 149 if (match == 0) 150 return (ENXIO); 151#endif |
|
88 device_set_desc(dev, "GPIO led"); | 152 device_set_desc(dev, "GPIO led"); |
153 |
|
89 return (0); 90} 91 92static int 93gpioled_attach(device_t dev) 94{ 95 struct gpioled_softc *sc; | 154 return (0); 155} 156 157static int 158gpioled_attach(device_t dev) 159{ 160 struct gpioled_softc *sc; |
161#ifdef FDT 162 phandle_t node; 163 char *name; 164#else |
|
96 const char *name; | 165 const char *name; |
166#endif |
|
97 98 sc = device_get_softc(dev); 99 sc->sc_dev = dev; 100 sc->sc_busdev = device_get_parent(dev); 101 GPIOLED_LOCK_INIT(sc); | 167 168 sc = device_get_softc(dev); 169 sc->sc_dev = dev; 170 sc->sc_busdev = device_get_parent(dev); 171 GPIOLED_LOCK_INIT(sc); |
172#ifdef FDT 173 name = NULL; 174 if ((node = ofw_bus_get_node(dev)) == -1) 175 return (ENXIO); 176 if (OF_getprop_alloc(node, "label", 1, (void **)&name) == -1) 177 OF_getprop_alloc(node, "name", 1, (void **)&name); 178#else |
|
102 if (resource_string_value(device_get_name(dev), 103 device_get_unit(dev), "name", &name)) 104 name = NULL; | 179 if (resource_string_value(device_get_name(dev), 180 device_get_unit(dev), "name", &name)) 181 name = NULL; |
182#endif |
|
105 | 183 |
106 GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, 107 GPIO_PIN_OUTPUT); 108 | |
109 sc->sc_leddev = led_create(gpioled_control, sc, name ? name : 110 device_get_nameunit(dev)); | 184 sc->sc_leddev = led_create(gpioled_control, sc, name ? name : 185 device_get_nameunit(dev)); |
186#ifdef FDT 187 if (name != NULL) 188 free(name, M_OFWPROP); 189#endif |
|
111 112 return (0); 113} 114 115static int 116gpioled_detach(device_t dev) 117{ 118 struct gpioled_softc *sc; --- 6 unchanged lines hidden (view full) --- 125 GPIOLED_LOCK_DESTROY(sc); 126 return (0); 127} 128 129static devclass_t gpioled_devclass; 130 131static device_method_t gpioled_methods[] = { 132 /* Device interface */ | 190 191 return (0); 192} 193 194static int 195gpioled_detach(device_t dev) 196{ 197 struct gpioled_softc *sc; --- 6 unchanged lines hidden (view full) --- 204 GPIOLED_LOCK_DESTROY(sc); 205 return (0); 206} 207 208static devclass_t gpioled_devclass; 209 210static device_method_t gpioled_methods[] = { 211 /* Device interface */ |
212#ifdef FDT 213 DEVMETHOD(device_identify, gpioled_identify), 214#endif |
|
133 DEVMETHOD(device_probe, gpioled_probe), 134 DEVMETHOD(device_attach, gpioled_attach), 135 DEVMETHOD(device_detach, gpioled_detach), 136 137 { 0, 0 } 138}; 139 140static driver_t gpioled_driver = { 141 "gpioled", 142 gpioled_methods, 143 sizeof(struct gpioled_softc), 144}; 145 146DRIVER_MODULE(gpioled, gpiobus, gpioled_driver, gpioled_devclass, 0, 0); | 215 DEVMETHOD(device_probe, gpioled_probe), 216 DEVMETHOD(device_attach, gpioled_attach), 217 DEVMETHOD(device_detach, gpioled_detach), 218 219 { 0, 0 } 220}; 221 222static driver_t gpioled_driver = { 223 "gpioled", 224 gpioled_methods, 225 sizeof(struct gpioled_softc), 226}; 227 228DRIVER_MODULE(gpioled, gpiobus, gpioled_driver, gpioled_devclass, 0, 0); |