gpiobus.c (302408) | gpiobus.c (308333) |
---|---|
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/11/sys/dev/gpio/gpiobus.c 301539 2016-06-07 05:08:24Z mmel $"); | 28__FBSDID("$FreeBSD: stable/11/sys/dev/gpio/gpiobus.c 308333 2016-11-05 10:23:02Z mmel $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/gpio.h> | 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/bus.h> 33#include <sys/gpio.h> |
34#ifdef INTRNG |
|
34#include <sys/intr.h> | 35#include <sys/intr.h> |
36#endif |
|
35#include <sys/kernel.h> 36#include <sys/malloc.h> 37#include <sys/module.h> 38 39#include <dev/gpio/gpiobusvar.h> 40 41#include "gpiobus_if.h" 42 --- 31 unchanged lines hidden (view full) --- 74static int gpiobus_pin_toggle(device_t, device_t, uint32_t); 75 76/* 77 * XXX -> Move me to better place - gpio_subr.c? 78 * Also, this function must be changed when interrupt configuration 79 * data will be moved into struct resource. 80 */ 81#ifdef INTRNG | 37#include <sys/kernel.h> 38#include <sys/malloc.h> 39#include <sys/module.h> 40 41#include <dev/gpio/gpiobusvar.h> 42 43#include "gpiobus_if.h" 44 --- 31 unchanged lines hidden (view full) --- 76static int gpiobus_pin_toggle(device_t, device_t, uint32_t); 77 78/* 79 * XXX -> Move me to better place - gpio_subr.c? 80 * Also, this function must be changed when interrupt configuration 81 * data will be moved into struct resource. 82 */ 83#ifdef INTRNG |
82static void 83gpio_destruct_map_data(struct intr_map_data *map_data) 84{ | |
85 | 84 |
86 KASSERT(map_data->type == INTR_MAP_DATA_GPIO, 87 ("%s: bad map_data type %d", __func__, map_data->type)); 88 89 free(map_data, M_DEVBUF); 90} 91 | |
92struct resource * 93gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, 94 gpio_pin_t pin, uint32_t intr_mode) 95{ | 85struct resource * 86gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, 87 gpio_pin_t pin, uint32_t intr_mode) 88{ |
96 int rv; | |
97 u_int irq; 98 struct intr_map_data_gpio *gpio_data; 99 struct resource *res; 100 | 89 u_int irq; 90 struct intr_map_data_gpio *gpio_data; 91 struct resource *res; 92 |
101 gpio_data = malloc(sizeof(*gpio_data), M_DEVBUF, M_WAITOK | M_ZERO); 102 gpio_data->hdr.type = INTR_MAP_DATA_GPIO; 103 gpio_data->hdr.destruct = gpio_destruct_map_data; | 93 gpio_data = (struct intr_map_data_gpio *)intr_alloc_map_data( 94 INTR_MAP_DATA_GPIO, sizeof(*gpio_data), M_WAITOK | M_ZERO); |
104 gpio_data->gpio_pin_num = pin->pin; 105 gpio_data->gpio_pin_flags = pin->flags; 106 gpio_data->gpio_intr_mode = intr_mode; 107 | 95 gpio_data->gpio_pin_num = pin->pin; 96 gpio_data->gpio_pin_flags = pin->flags; 97 gpio_data->gpio_intr_mode = intr_mode; 98 |
108 rv = intr_map_irq(pin->dev, 0, (struct intr_map_data *)gpio_data, 109 &irq); 110 if (rv != 0) { 111 gpio_destruct_map_data((struct intr_map_data *)gpio_data); 112 return (NULL); 113 } 114 | 99 irq = intr_map_irq(pin->dev, 0, (struct intr_map_data *)gpio_data); |
115 res = bus_alloc_resource(consumer_dev, SYS_RES_IRQ, rid, irq, irq, 1, 116 alloc_flags); 117 if (res == NULL) { | 100 res = bus_alloc_resource(consumer_dev, SYS_RES_IRQ, rid, irq, irq, 1, 101 alloc_flags); 102 if (res == NULL) { |
118 gpio_destruct_map_data((struct intr_map_data *)gpio_data); | 103 intr_free_intr_map_data((struct intr_map_data *)gpio_data); |
119 return (NULL); 120 } 121 rman_set_virtual(res, gpio_data); 122 return (res); 123} 124#else 125struct resource * 126gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, --- 748 unchanged lines hidden --- | 104 return (NULL); 105 } 106 rman_set_virtual(res, gpio_data); 107 return (res); 108} 109#else 110struct resource * 111gpio_alloc_intr_resource(device_t consumer_dev, int *rid, u_int alloc_flags, --- 748 unchanged lines hidden --- |