Deleted Added
full compact
gpiobus.c (279620) gpiobus.c (279622)
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 279620 2015-03-05 01:49:58Z loos $");
28__FBSDID("$FreeBSD: head/sys/dev/gpio/gpiobus.c 279622 2015-03-05 03:11:47Z loos $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/gpio.h>
34#include <sys/kernel.h>
35#include <sys/malloc.h>
36#include <sys/module.h>

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

225 }
226 if (devi->pins) {
227 free(devi->pins, M_DEVBUF);
228 devi->pins = NULL;
229 }
230}
231
232int
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/gpio.h>
34#include <sys/kernel.h>
35#include <sys/malloc.h>
36#include <sys/module.h>

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

225 }
226 if (devi->pins) {
227 free(devi->pins, M_DEVBUF);
228 devi->pins = NULL;
229 }
230}
231
232int
233gpiobus_map_pin(device_t bus, device_t child, uint32_t pin)
233gpiobus_map_pin(device_t bus, uint32_t pin)
234{
235 struct gpiobus_softc *sc;
236
237 sc = device_get_softc(bus);
238 /* Consistency check. */
239 if (pin >= sc->sc_npins) {
234{
235 struct gpiobus_softc *sc;
236
237 sc = device_get_softc(bus);
238 /* Consistency check. */
239 if (pin >= sc->sc_npins) {
240 device_printf(child,
240 device_printf(bus,
241 "invalid pin %d, max: %d\n", pin, sc->sc_npins - 1);
242 return (-1);
243 }
244 /* Mark pin as mapped and give warning if it's already mapped. */
245 if (sc->sc_pins_mapped[pin]) {
241 "invalid pin %d, max: %d\n", pin, sc->sc_npins - 1);
242 return (-1);
243 }
244 /* Mark pin as mapped and give warning if it's already mapped. */
245 if (sc->sc_pins_mapped[pin]) {
246 device_printf(child,
247 "warning: pin %d is already mapped\n", pin);
246 device_printf(bus, "warning: pin %d is already mapped\n", pin);
248 return (-1);
249 }
250 sc->sc_pins_mapped[pin] = 1;
251
252 return (0);
253}
254
255static int

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

272 device_printf(child, "cannot allocate device ivars\n");
273 return (EINVAL);
274 }
275 npins = 0;
276 for (i = 0; i < 32; i++) {
277 if ((mask & (1 << i)) == 0)
278 continue;
279 /* Reserve the GPIO pin. */
247 return (-1);
248 }
249 sc->sc_pins_mapped[pin] = 1;
250
251 return (0);
252}
253
254static int

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

271 device_printf(child, "cannot allocate device ivars\n");
272 return (EINVAL);
273 }
274 npins = 0;
275 for (i = 0; i < 32; i++) {
276 if ((mask & (1 << i)) == 0)
277 continue;
278 /* Reserve the GPIO pin. */
280 if (gpiobus_map_pin(sc->sc_busdev, child, i) != 0) {
279 if (gpiobus_map_pin(sc->sc_busdev, i) != 0) {
281 gpiobus_free_ivars(devi);
282 return (EINVAL);
283 }
284 devi->pins[npins++] = i;
285 }
286
287 return (0);
288}

--- 428 unchanged lines hidden ---
280 gpiobus_free_ivars(devi);
281 return (EINVAL);
282 }
283 devi->pins[npins++] = i;
284 }
285
286 return (0);
287}

--- 428 unchanged lines hidden ---