Deleted Added
full compact
gpiobus.c (274643) gpiobus.c (274670)
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: head/sys/dev/gpio/gpiobus.c 274643 2014-11-18 02:41:35Z loos $");
28__FBSDID("$FreeBSD: head/sys/dev/gpio/gpiobus.c 274670 2014-11-18 17:22:08Z loos $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/gpio.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/module.h>
36
37#include <dev/gpio/gpiobusvar.h>
38
39#include "gpiobus_if.h"
40

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

65static void gpiobus_release_bus(device_t, device_t);
66static int gpiobus_pin_setflags(device_t, device_t, uint32_t, uint32_t);
67static int gpiobus_pin_getflags(device_t, device_t, uint32_t, uint32_t*);
68static int gpiobus_pin_getcaps(device_t, device_t, uint32_t, uint32_t*);
69static int gpiobus_pin_set(device_t, device_t, uint32_t, unsigned int);
70static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*);
71static int gpiobus_pin_toggle(device_t, device_t, uint32_t);
72
34#include <sys/kernel.h>
35#include <sys/malloc.h>
36#include <sys/module.h>
37
38#include <dev/gpio/gpiobusvar.h>
39
40#include "gpiobus_if.h"
41

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

66static void gpiobus_release_bus(device_t, device_t);
67static int gpiobus_pin_setflags(device_t, device_t, uint32_t, uint32_t);
68static int gpiobus_pin_getflags(device_t, device_t, uint32_t, uint32_t*);
69static int gpiobus_pin_getcaps(device_t, device_t, uint32_t, uint32_t*);
70static int gpiobus_pin_set(device_t, device_t, uint32_t, unsigned int);
71static int gpiobus_pin_get(device_t, device_t, uint32_t, unsigned int*);
72static int gpiobus_pin_toggle(device_t, device_t, uint32_t);
73
74int
75gpio_check_flags(uint32_t caps, uint32_t flags)
76{
77
78 /* Check for unwanted flags. */
79 if ((flags & caps) == 0 || (flags & caps) != flags)
80 return (EINVAL);
81 /* Cannot mix input/output together. */
82 if (flags & GPIO_PIN_INPUT && flags & GPIO_PIN_OUTPUT)
83 return (EINVAL);
84 /* Cannot mix pull-up/pull-down together. */
85 if (flags & GPIO_PIN_PULLUP && flags & GPIO_PIN_PULLDOWN)
86 return (EINVAL);
87
88 return (0);
89}
90
73static void
74gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
75{
76 char tmp[128];
77 int i, range_start, range_stop, need_coma;
78
79 if (devi->npins == 0)
80 return;

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

485}
486
487static int
488gpiobus_pin_setflags(device_t dev, device_t child, uint32_t pin,
489 uint32_t flags)
490{
491 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
492 struct gpiobus_ivar *devi = GPIOBUS_IVAR(child);
91static void
92gpiobus_print_pins(struct gpiobus_ivar *devi, char *buf, size_t buflen)
93{
94 char tmp[128];
95 int i, range_start, range_stop, need_coma;
96
97 if (devi->npins == 0)
98 return;

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

503}
504
505static int
506gpiobus_pin_setflags(device_t dev, device_t child, uint32_t pin,
507 uint32_t flags)
508{
509 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
510 struct gpiobus_ivar *devi = GPIOBUS_IVAR(child);
511 uint32_t caps;
493
494 if (pin >= devi->npins)
495 return (EINVAL);
512
513 if (pin >= devi->npins)
514 return (EINVAL);
515 if (GPIO_PIN_GETCAPS(sc->sc_dev, devi->pins[pin], &caps) != 0)
516 return (EINVAL);
517 if (gpio_check_flags(caps, flags) != 0)
518 return (EINVAL);
496
519
497 return GPIO_PIN_SETFLAGS(sc->sc_dev, devi->pins[pin], flags);
520 return (GPIO_PIN_SETFLAGS(sc->sc_dev, devi->pins[pin], flags));
498}
499
500static int
501gpiobus_pin_getflags(device_t dev, device_t child, uint32_t pin,
502 uint32_t *flags)
503{
504 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
505 struct gpiobus_ivar *devi = GPIOBUS_IVAR(child);

--- 106 unchanged lines hidden ---
521}
522
523static int
524gpiobus_pin_getflags(device_t dev, device_t child, uint32_t pin,
525 uint32_t *flags)
526{
527 struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev);
528 struct gpiobus_ivar *devi = GPIOBUS_IVAR(child);

--- 106 unchanged lines hidden ---