Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/gpio/gpiobus.c
Show All 25 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/gpio.h> | #include <sys/gpio.h> | ||||
#ifdef INTRNG | |||||
#include <sys/intr.h> | #include <sys/intr.h> | ||||
#endif | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <dev/gpio/gpiobusvar.h> | #include <dev/gpio/gpiobusvar.h> | ||||
#include "gpiobus_if.h" | #include "gpiobus_if.h" | ||||
Show All 31 Lines | |||||
static int gpiobus_pin_toggle(device_t, device_t, uint32_t); | static int gpiobus_pin_toggle(device_t, device_t, uint32_t); | ||||
/* | /* | ||||
* XXX -> Move me to better place - gpio_subr.c? | * XXX -> Move me to better place - gpio_subr.c? | ||||
* Also, this function must be changed when interrupt configuration | * Also, this function must be changed when interrupt configuration | ||||
* data will be moved into struct resource. | * data will be moved into struct resource. | ||||
*/ | */ | ||||
#ifdef INTRNG | #ifdef INTRNG | ||||
static void | |||||
gpio_destruct_map_data(struct intr_map_data *map_data) | |||||
{ | |||||
KASSERT(map_data->type == INTR_MAP_DATA_GPIO, | |||||
("%s: bad map_data type %d", __func__, map_data->type)); | |||||
free(map_data, M_DEVBUF); | |||||
} | |||||
struct resource * | struct resource * | ||||
gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, | gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, | ||||
gpio_pin_t pin, uint32_t intr_mode) | gpio_pin_t pin, uint32_t intr_mode) | ||||
{ | { | ||||
int rv; | |||||
u_int irq; | u_int irq; | ||||
struct intr_map_data_gpio *gpio_data; | struct intr_map_data_gpio *gpio_data; | ||||
struct resource *res; | struct resource *res; | ||||
gpio_data = malloc(sizeof(*gpio_data), M_DEVBUF, M_WAITOK | M_ZERO); | gpio_data = (struct intr_map_data_gpio *)intr_alloc_map_data( | ||||
gpio_data->hdr.type = INTR_MAP_DATA_GPIO; | INTR_MAP_DATA_GPIO, sizeof(*gpio_data), M_WAITOK | M_ZERO); | ||||
gpio_data->hdr.destruct = gpio_destruct_map_data; | |||||
gpio_data->gpio_pin_num = pin->pin; | gpio_data->gpio_pin_num = pin->pin; | ||||
gpio_data->gpio_pin_flags = pin->flags; | gpio_data->gpio_pin_flags = pin->flags; | ||||
gpio_data->gpio_intr_mode = intr_mode; | gpio_data->gpio_intr_mode = intr_mode; | ||||
rv = intr_map_irq(pin->dev, 0, (struct intr_map_data *)gpio_data, | irq = intr_map_irq(pin->dev, 0, (struct intr_map_data *)gpio_data); | ||||
&irq); | |||||
if (rv != 0) { | |||||
gpio_destruct_map_data((struct intr_map_data *)gpio_data); | |||||
return (NULL); | |||||
} | |||||
res = bus_alloc_resource(consumer_dev, SYS_RES_IRQ, rid, irq, irq, 1, | res = bus_alloc_resource(consumer_dev, SYS_RES_IRQ, rid, irq, irq, 1, | ||||
alloc_flags); | alloc_flags); | ||||
if (res == NULL) { | if (res == NULL) { | ||||
gpio_destruct_map_data((struct intr_map_data *)gpio_data); | intr_free_intr_map_data((struct intr_map_data *)gpio_data); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
rman_set_virtual(res, gpio_data); | rman_set_virtual(res, gpio_data); | ||||
return (res); | return (res); | ||||
} | } | ||||
#else | #else | ||||
struct resource * | struct resource * | ||||
gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, | gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, | ||||
▲ Show 20 Lines • Show All 748 Lines • Show Last 20 Lines |