gpiobus.c (278781) | gpiobus.c (278783) |
---|---|
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 278781 2015-02-14 20:32:24Z loos $"); | 28__FBSDID("$FreeBSD: stable/10/sys/dev/gpio/gpiobus.c 278783 2015-02-14 20:50:38Z loos $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/kernel.h> 34#include <sys/malloc.h> 35#include <sys/module.h> 36 --- 11 unchanged lines hidden (view full) --- 48static int gpiobus_child_location_str(device_t, device_t, char *, size_t); 49static int gpiobus_child_pnpinfo_str(device_t, device_t, char *, size_t); 50static device_t gpiobus_add_child(device_t, u_int, const char *, int); 51static void gpiobus_hinted_child(device_t, const char *, int); 52 53/* 54 * GPIOBUS interface 55 */ | 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/kernel.h> 34#include <sys/malloc.h> 35#include <sys/module.h> 36 --- 11 unchanged lines hidden (view full) --- 48static int gpiobus_child_location_str(device_t, device_t, char *, size_t); 49static int gpiobus_child_pnpinfo_str(device_t, device_t, char *, size_t); 50static device_t gpiobus_add_child(device_t, u_int, const char *, int); 51static void gpiobus_hinted_child(device_t, const char *, int); 52 53/* 54 * GPIOBUS interface 55 */ |
56static void gpiobus_lock_bus(device_t); 57static void gpiobus_unlock_bus(device_t); 58static void gpiobus_acquire_bus(device_t, device_t); | 56static int gpiobus_acquire_bus(device_t, device_t, int); |
59static void gpiobus_release_bus(device_t, device_t); 60static int gpiobus_pin_setflags(device_t, device_t, uint32_t, uint32_t); 61static int gpiobus_pin_getflags(device_t, device_t, uint32_t, uint32_t*); 62static int gpiobus_pin_getcaps(device_t, device_t, uint32_t, uint32_t*); 63static int gpiobus_pin_set(device_t, device_t, uint32_t, unsigned int); 64static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*); 65static int gpiobus_pin_toggle(device_t, device_t, uint32_t); 66 --- 254 unchanged lines hidden (view full) --- 321 322 child = BUS_ADD_CHILD(bus, 0, dname, dunit); 323 devi = GPIOBUS_IVAR(child); 324 resource_int_value(dname, dunit, "pins", &pins); 325 if (gpiobus_parse_pins(sc, child, pins)) 326 device_delete_child(bus, child); 327} 328 | 57static void gpiobus_release_bus(device_t, device_t); 58static int gpiobus_pin_setflags(device_t, device_t, uint32_t, uint32_t); 59static int gpiobus_pin_getflags(device_t, device_t, uint32_t, uint32_t*); 60static int gpiobus_pin_getcaps(device_t, device_t, uint32_t, uint32_t*); 61static int gpiobus_pin_set(device_t, device_t, uint32_t, unsigned int); 62static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*); 63static int gpiobus_pin_toggle(device_t, device_t, uint32_t); 64 --- 254 unchanged lines hidden (view full) --- 319 320 child = BUS_ADD_CHILD(bus, 0, dname, dunit); 321 devi = GPIOBUS_IVAR(child); 322 resource_int_value(dname, dunit, "pins", &pins); 323 if (gpiobus_parse_pins(sc, child, pins)) 324 device_delete_child(bus, child); 325} 326 |
329static void 330gpiobus_lock_bus(device_t busdev) | 327static int 328gpiobus_acquire_bus(device_t busdev, device_t child, int how) |
331{ 332 struct gpiobus_softc *sc; 333 334 sc = device_get_softc(busdev); 335 GPIOBUS_ASSERT_UNLOCKED(sc); 336 GPIOBUS_LOCK(sc); | 329{ 330 struct gpiobus_softc *sc; 331 332 sc = device_get_softc(busdev); 333 GPIOBUS_ASSERT_UNLOCKED(sc); 334 GPIOBUS_LOCK(sc); |
337} 338 339static void 340gpiobus_unlock_bus(device_t busdev) 341{ 342 struct gpiobus_softc *sc; 343 344 sc = device_get_softc(busdev); 345 GPIOBUS_ASSERT_LOCKED(sc); | 335 if (sc->sc_owner != NULL) { 336 if (how == GPIOBUS_DONTWAIT) { 337 GPIOBUS_UNLOCK(sc); 338 return (EWOULDBLOCK); 339 } 340 while (sc->sc_owner != NULL) 341 mtx_sleep(sc, &sc->sc_mtx, 0, "gpiobuswait", 0); 342 } 343 sc->sc_owner = child; |
346 GPIOBUS_UNLOCK(sc); | 344 GPIOBUS_UNLOCK(sc); |
347} | |
348 | 345 |
349static void 350gpiobus_acquire_bus(device_t busdev, device_t child) 351{ 352 struct gpiobus_softc *sc; 353 354 sc = device_get_softc(busdev); 355 GPIOBUS_ASSERT_LOCKED(sc); 356 357 if (sc->sc_owner) 358 panic("gpiobus: cannot serialize the access to device."); 359 sc->sc_owner = child; | 346 return (0); |
360} 361 362static void 363gpiobus_release_bus(device_t busdev, device_t child) 364{ 365 struct gpiobus_softc *sc; 366 367 sc = device_get_softc(busdev); | 347} 348 349static void 350gpiobus_release_bus(device_t busdev, device_t child) 351{ 352 struct gpiobus_softc *sc; 353 354 sc = device_get_softc(busdev); |
368 GPIOBUS_ASSERT_LOCKED(sc); 369 370 if (!sc->sc_owner) | 355 GPIOBUS_ASSERT_UNLOCKED(sc); 356 GPIOBUS_LOCK(sc); 357 if (sc->sc_owner == NULL) |
371 panic("gpiobus: releasing unowned bus."); 372 if (sc->sc_owner != child) 373 panic("gpiobus: you don't own the bus. game over."); | 358 panic("gpiobus: releasing unowned bus."); 359 if (sc->sc_owner != child) 360 panic("gpiobus: you don't own the bus. game over."); |
374 | |
375 sc->sc_owner = NULL; | 361 sc->sc_owner = NULL; |
362 wakeup(sc); 363 GPIOBUS_UNLOCK(sc); |
|
376} 377 378static int 379gpiobus_pin_setflags(device_t dev, device_t child, uint32_t pin, 380 uint32_t flags) 381{ 382 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev); 383 struct gpiobus_ivar *devi = GPIOBUS_IVAR(child); --- 80 unchanged lines hidden (view full) --- 464 /* Bus interface */ 465 DEVMETHOD(bus_add_child, gpiobus_add_child), 466 DEVMETHOD(bus_print_child, gpiobus_print_child), 467 DEVMETHOD(bus_child_pnpinfo_str, gpiobus_child_pnpinfo_str), 468 DEVMETHOD(bus_child_location_str, gpiobus_child_location_str), 469 DEVMETHOD(bus_hinted_child, gpiobus_hinted_child), 470 471 /* GPIO protocol */ | 364} 365 366static int 367gpiobus_pin_setflags(device_t dev, device_t child, uint32_t pin, 368 uint32_t flags) 369{ 370 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev); 371 struct gpiobus_ivar *devi = GPIOBUS_IVAR(child); --- 80 unchanged lines hidden (view full) --- 452 /* Bus interface */ 453 DEVMETHOD(bus_add_child, gpiobus_add_child), 454 DEVMETHOD(bus_print_child, gpiobus_print_child), 455 DEVMETHOD(bus_child_pnpinfo_str, gpiobus_child_pnpinfo_str), 456 DEVMETHOD(bus_child_location_str, gpiobus_child_location_str), 457 DEVMETHOD(bus_hinted_child, gpiobus_hinted_child), 458 459 /* GPIO protocol */ |
472 DEVMETHOD(gpiobus_lock_bus, gpiobus_lock_bus), 473 DEVMETHOD(gpiobus_unlock_bus, gpiobus_unlock_bus), | |
474 DEVMETHOD(gpiobus_acquire_bus, gpiobus_acquire_bus), 475 DEVMETHOD(gpiobus_release_bus, gpiobus_release_bus), 476 DEVMETHOD(gpiobus_pin_getflags, gpiobus_pin_getflags), 477 DEVMETHOD(gpiobus_pin_getcaps, gpiobus_pin_getcaps), 478 DEVMETHOD(gpiobus_pin_setflags, gpiobus_pin_setflags), 479 DEVMETHOD(gpiobus_pin_get, gpiobus_pin_get), 480 DEVMETHOD(gpiobus_pin_set, gpiobus_pin_set), 481 DEVMETHOD(gpiobus_pin_toggle, gpiobus_pin_toggle), --- 14 unchanged lines hidden --- | 460 DEVMETHOD(gpiobus_acquire_bus, gpiobus_acquire_bus), 461 DEVMETHOD(gpiobus_release_bus, gpiobus_release_bus), 462 DEVMETHOD(gpiobus_pin_getflags, gpiobus_pin_getflags), 463 DEVMETHOD(gpiobus_pin_getcaps, gpiobus_pin_getcaps), 464 DEVMETHOD(gpiobus_pin_setflags, gpiobus_pin_setflags), 465 DEVMETHOD(gpiobus_pin_get, gpiobus_pin_get), 466 DEVMETHOD(gpiobus_pin_set, gpiobus_pin_set), 467 DEVMETHOD(gpiobus_pin_toggle, gpiobus_pin_toggle), --- 14 unchanged lines hidden --- |