Deleted Added
full compact
gpiobus.c (256281) gpiobus.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/gpiobus.c 255254 2013-09-05 16:38:26Z sbruno $");
28__FBSDID("$FreeBSD: stable/10/sys/dev/gpio/gpiobus.c 266105 2014-05-15 01:27:53Z loos $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/module.h>
34#include <sys/kernel.h>
35#include <sys/queue.h>
36#include <sys/sysctl.h>

--- 4 unchanged lines hidden (view full) ---

41#include <sys/rman.h>
42#include <machine/resource.h>
43
44#include <sys/gpio.h>
45#include <dev/gpio/gpiobusvar.h>
46#include "gpio_if.h"
47#include "gpiobus_if.h"
48
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/module.h>
34#include <sys/kernel.h>
35#include <sys/queue.h>
36#include <sys/sysctl.h>

--- 4 unchanged lines hidden (view full) ---

41#include <sys/rman.h>
42#include <machine/resource.h>
43
44#include <sys/gpio.h>
45#include <dev/gpio/gpiobusvar.h>
46#include "gpio_if.h"
47#include "gpiobus_if.h"
48
49static void gpiobus_print_pins(struct gpiobus_ivar *);
50static int gpiobus_parse_pins(struct gpiobus_softc *, device_t, int);
51static int gpiobus_probe(device_t);
52static int gpiobus_attach(device_t);
53static int gpiobus_detach(device_t);
54static int gpiobus_suspend(device_t);
55static int gpiobus_resume(device_t);
56static int gpiobus_print_child(device_t, device_t);
57static int gpiobus_child_location_str(device_t, device_t, char *, size_t);

--- 10 unchanged lines hidden (view full) ---

68static void gpiobus_release_bus(device_t, device_t);
69static int gpiobus_pin_setflags(device_t, device_t, uint32_t, uint32_t);
70static int gpiobus_pin_getflags(device_t, device_t, uint32_t, uint32_t*);
71static int gpiobus_pin_getcaps(device_t, device_t, uint32_t, uint32_t*);
72static int gpiobus_pin_set(device_t, device_t, uint32_t, unsigned int);
73static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*);
74static int gpiobus_pin_toggle(device_t, device_t, uint32_t);
75
49static int gpiobus_parse_pins(struct gpiobus_softc *, device_t, int);
50static int gpiobus_probe(device_t);
51static int gpiobus_attach(device_t);
52static int gpiobus_detach(device_t);
53static int gpiobus_suspend(device_t);
54static int gpiobus_resume(device_t);
55static int gpiobus_print_child(device_t, device_t);
56static int gpiobus_child_location_str(device_t, device_t, char *, size_t);

--- 10 unchanged lines hidden (view full) ---

67static void gpiobus_release_bus(device_t, device_t);
68static int gpiobus_pin_setflags(device_t, device_t, uint32_t, uint32_t);
69static int gpiobus_pin_getflags(device_t, device_t, uint32_t, uint32_t*);
70static int gpiobus_pin_getcaps(device_t, device_t, uint32_t, uint32_t*);
71static int gpiobus_pin_set(device_t, device_t, uint32_t, unsigned int);
72static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*);
73static int gpiobus_pin_toggle(device_t, device_t, uint32_t);
74
76#define GPIOBUS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
77#define GPIOBUS_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
78#define GPIOBUS_LOCK_INIT(_sc) \
79 mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), \
80 "gpiobus", MTX_DEF)
81#define GPIOBUS_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx);
82#define GPIOBUS_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED);
83#define GPIOBUS_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED);
84
85
86static void
75void
87gpiobus_print_pins(struct gpiobus_ivar *devi)
88{
89 int range_start, range_stop, need_coma;
90 int i;
91
92 if (devi->npins == 0)
93 return;
94

--- 75 unchanged lines hidden (view full) ---

170
171 return (0);
172}
173
174static int
175gpiobus_probe(device_t dev)
176{
177 device_set_desc(dev, "GPIO bus");
76gpiobus_print_pins(struct gpiobus_ivar *devi)
77{
78 int range_start, range_stop, need_coma;
79 int i;
80
81 if (devi->npins == 0)
82 return;
83

--- 75 unchanged lines hidden (view full) ---

159
160 return (0);
161}
162
163static int
164gpiobus_probe(device_t dev)
165{
166 device_set_desc(dev, "GPIO bus");
178 return (0);
167
168 return (BUS_PROBE_GENERIC);
179}
180
181static int
182gpiobus_attach(device_t dev)
183{
184 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
185 int res;
186
187 sc->sc_busdev = dev;
188 sc->sc_dev = device_get_parent(dev);
189 res = GPIO_PIN_MAX(sc->sc_dev, &sc->sc_npins);
190 if (res)
191 return (ENXIO);
192
169}
170
171static int
172gpiobus_attach(device_t dev)
173{
174 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
175 int res;
176
177 sc->sc_busdev = dev;
178 sc->sc_dev = device_get_parent(dev);
179 res = GPIO_PIN_MAX(sc->sc_dev, &sc->sc_npins);
180 if (res)
181 return (ENXIO);
182
183 KASSERT(sc->sc_npins != 0, ("GPIO device with no pins"));
184
193 /*
194 * Increase to get number of pins
195 */
196 sc->sc_npins++;
197
185 /*
186 * Increase to get number of pins
187 */
188 sc->sc_npins++;
189
198 KASSERT(sc->sc_npins != 0, ("GPIO device with no pins"));
199
200 sc->sc_pins_mapped = malloc(sizeof(int) * sc->sc_npins, M_DEVBUF,
201 M_NOWAIT | M_ZERO);
202
203 if (!sc->sc_pins_mapped)
204 return (ENOMEM);
205
206 /* init bus lock */
207 GPIOBUS_LOCK_INIT(sc);
208
209 /*
210 * Get parent's pins and mark them as unmapped
211 */
190 sc->sc_pins_mapped = malloc(sizeof(int) * sc->sc_npins, M_DEVBUF,
191 M_NOWAIT | M_ZERO);
192
193 if (!sc->sc_pins_mapped)
194 return (ENOMEM);
195
196 /* init bus lock */
197 GPIOBUS_LOCK_INIT(sc);
198
199 /*
200 * Get parent's pins and mark them as unmapped
201 */
202 bus_generic_probe(dev);
212 bus_enumerate_hinted_children(dev);
203 bus_enumerate_hinted_children(dev);
204
213 return (bus_generic_attach(dev));
214}
215
216/*
217 * Since this is not a self-enumerating bus, and since we always add
218 * children in attach, we have to always delete children here.
219 */
220static int

--- 282 unchanged lines hidden ---
205 return (bus_generic_attach(dev));
206}
207
208/*
209 * Since this is not a self-enumerating bus, and since we always add
210 * children in attach, we have to always delete children here.
211 */
212static int

--- 282 unchanged lines hidden ---