vf_gpio.c (277968) | vf_gpio.c (277996) |
---|---|
1/*- 2 * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com> 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 --- 16 unchanged lines hidden (view full) --- 25 */ 26 27/* 28 * Vybrid Family General-Purpose Input/Output (GPIO) 29 * Chapter 7, Vybrid Reference Manual, Rev. 5, 07/2013 30 */ 31 32#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com> 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 --- 16 unchanged lines hidden (view full) --- 25 */ 26 27/* 28 * Vybrid Family General-Purpose Input/Output (GPIO) 29 * Chapter 7, Vybrid Reference Manual, Rev. 5, 07/2013 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/arm/freescale/vybrid/vf_gpio.c 277968 2015-01-31 12:17:07Z loos $"); | 33__FBSDID("$FreeBSD: head/sys/arm/freescale/vybrid/vf_gpio.c 277996 2015-01-31 19:32:14Z loos $"); |
34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/bus.h> 38#include <sys/kernel.h> 39#include <sys/module.h> 40#include <sys/malloc.h> 41#include <sys/rman.h> 42#include <sys/timeet.h> 43#include <sys/timetc.h> 44#include <sys/watchdog.h> 45#include <sys/mutex.h> 46#include <sys/gpio.h> 47 48#include <dev/fdt/fdt_common.h> | 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/bus.h> 38#include <sys/kernel.h> 39#include <sys/module.h> 40#include <sys/malloc.h> 41#include <sys/rman.h> 42#include <sys/timeet.h> 43#include <sys/timetc.h> 44#include <sys/watchdog.h> 45#include <sys/mutex.h> 46#include <sys/gpio.h> 47 48#include <dev/fdt/fdt_common.h> |
49#include <dev/gpio/gpiobusvar.h> |
|
49#include <dev/ofw/openfirm.h> 50#include <dev/ofw/ofw_bus.h> 51#include <dev/ofw/ofw_bus_subr.h> 52 53#include <machine/bus.h> 54#include <machine/fdt.h> 55#include <machine/cpu.h> 56#include <machine/intr.h> --- 12 unchanged lines hidden (view full) --- 69#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 70#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 71 72#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT) 73 74/* 75 * GPIO interface 76 */ | 50#include <dev/ofw/openfirm.h> 51#include <dev/ofw/ofw_bus.h> 52#include <dev/ofw/ofw_bus_subr.h> 53 54#include <machine/bus.h> 55#include <machine/fdt.h> 56#include <machine/cpu.h> 57#include <machine/intr.h> --- 12 unchanged lines hidden (view full) --- 70#define GPIO_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 71#define GPIO_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 72 73#define DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT) 74 75/* 76 * GPIO interface 77 */ |
78static device_t vf_gpio_get_bus(device_t); |
|
77static int vf_gpio_pin_max(device_t, int *); 78static int vf_gpio_pin_getcaps(device_t, uint32_t, uint32_t *); 79static int vf_gpio_pin_getname(device_t, uint32_t, char *); 80static int vf_gpio_pin_getflags(device_t, uint32_t, uint32_t *); 81static int vf_gpio_pin_setflags(device_t, uint32_t, uint32_t); 82static int vf_gpio_pin_set(device_t, uint32_t, unsigned int); 83static int vf_gpio_pin_get(device_t, uint32_t, unsigned int *); 84static int vf_gpio_pin_toggle(device_t, uint32_t pin); 85 86struct vf_gpio_softc { 87 struct resource *res[1]; 88 bus_space_tag_t bst; 89 bus_space_handle_t bsh; 90 | 79static int vf_gpio_pin_max(device_t, int *); 80static int vf_gpio_pin_getcaps(device_t, uint32_t, uint32_t *); 81static int vf_gpio_pin_getname(device_t, uint32_t, char *); 82static int vf_gpio_pin_getflags(device_t, uint32_t, uint32_t *); 83static int vf_gpio_pin_setflags(device_t, uint32_t, uint32_t); 84static int vf_gpio_pin_set(device_t, uint32_t, unsigned int); 85static int vf_gpio_pin_get(device_t, uint32_t, unsigned int *); 86static int vf_gpio_pin_toggle(device_t, uint32_t pin); 87 88struct vf_gpio_softc { 89 struct resource *res[1]; 90 bus_space_tag_t bst; 91 bus_space_handle_t bsh; 92 |
93 device_t sc_busdev; |
|
91 struct mtx sc_mtx; 92 int gpio_npins; 93 struct gpio_pin gpio_pins[NGPIO]; 94}; 95 96struct vf_gpio_softc *gpio_sc; 97 98static struct resource_spec vf_gpio_spec[] = { --- 43 unchanged lines hidden (view full) --- 142 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS; 143 sc->gpio_pins[i].gp_flags = 144 (READ4(sc, GPIO_PDOR(i)) & (1 << (i % 32))) ? 145 GPIO_PIN_OUTPUT: GPIO_PIN_INPUT; 146 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME, 147 "vf_gpio%d.%d", device_get_unit(dev), i); 148 } 149 | 94 struct mtx sc_mtx; 95 int gpio_npins; 96 struct gpio_pin gpio_pins[NGPIO]; 97}; 98 99struct vf_gpio_softc *gpio_sc; 100 101static struct resource_spec vf_gpio_spec[] = { --- 43 unchanged lines hidden (view full) --- 145 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS; 146 sc->gpio_pins[i].gp_flags = 147 (READ4(sc, GPIO_PDOR(i)) & (1 << (i % 32))) ? 148 GPIO_PIN_OUTPUT: GPIO_PIN_INPUT; 149 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME, 150 "vf_gpio%d.%d", device_get_unit(dev), i); 151 } 152 |
150 device_add_child(dev, "gpioc", -1); 151 device_add_child(dev, "gpiobus", -1); | 153 sc->sc_busdev = gpiobus_attach_bus(dev); 154 if (sc->sc_busdev == NULL) { 155 bus_release_resources(dev, vf_gpio_spec, sc->res); 156 mtx_destroy(&sc->sc_mtx); 157 return (ENXIO); 158 } |
152 | 159 |
153 return (bus_generic_attach(dev)); | 160 return (0); |
154} 155 | 161} 162 |
163static device_t 164vf_gpio_get_bus(device_t dev) 165{ 166 struct vf_gpio_softc *sc; 167 168 sc = device_get_softc(dev); 169 170 return (sc->sc_busdev); 171} 172 |
|
156static int 157vf_gpio_pin_max(device_t dev, int *maxpin) 158{ 159 160 *maxpin = NGPIO - 1; 161 return (0); 162} 163 --- 179 unchanged lines hidden (view full) --- 343 return (0); 344} 345 346static device_method_t vf_gpio_methods[] = { 347 DEVMETHOD(device_probe, vf_gpio_probe), 348 DEVMETHOD(device_attach, vf_gpio_attach), 349 350 /* GPIO protocol */ | 173static int 174vf_gpio_pin_max(device_t dev, int *maxpin) 175{ 176 177 *maxpin = NGPIO - 1; 178 return (0); 179} 180 --- 179 unchanged lines hidden (view full) --- 360 return (0); 361} 362 363static device_method_t vf_gpio_methods[] = { 364 DEVMETHOD(device_probe, vf_gpio_probe), 365 DEVMETHOD(device_attach, vf_gpio_attach), 366 367 /* GPIO protocol */ |
368 DEVMETHOD(gpio_get_bus, vf_gpio_get_bus), |
|
351 DEVMETHOD(gpio_pin_max, vf_gpio_pin_max), 352 DEVMETHOD(gpio_pin_getname, vf_gpio_pin_getname), 353 DEVMETHOD(gpio_pin_getcaps, vf_gpio_pin_getcaps), 354 DEVMETHOD(gpio_pin_getflags, vf_gpio_pin_getflags), 355 DEVMETHOD(gpio_pin_get, vf_gpio_pin_get), 356 DEVMETHOD(gpio_pin_toggle, vf_gpio_pin_toggle), 357 DEVMETHOD(gpio_pin_setflags, vf_gpio_pin_setflags), 358 DEVMETHOD(gpio_pin_set, vf_gpio_pin_set), --- 12 unchanged lines hidden --- | 369 DEVMETHOD(gpio_pin_max, vf_gpio_pin_max), 370 DEVMETHOD(gpio_pin_getname, vf_gpio_pin_getname), 371 DEVMETHOD(gpio_pin_getcaps, vf_gpio_pin_getcaps), 372 DEVMETHOD(gpio_pin_getflags, vf_gpio_pin_getflags), 373 DEVMETHOD(gpio_pin_get, vf_gpio_pin_get), 374 DEVMETHOD(gpio_pin_toggle, vf_gpio_pin_toggle), 375 DEVMETHOD(gpio_pin_setflags, vf_gpio_pin_setflags), 376 DEVMETHOD(gpio_pin_set, vf_gpio_pin_set), --- 12 unchanged lines hidden --- |