Deleted Added
full compact
ar71xx_gpio.c (255334) ar71xx_gpio.c (255335)
1/*-
2 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3 * Copyright (c) 2009, Luiz Otavio O Souza.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

26 * SUCH DAMAGE.
27 */
28
29/*
30 * GPIO driver for AR71xx
31 */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3 * Copyright (c) 2009, Luiz Otavio O Souza.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

26 * SUCH DAMAGE.
27 */
28
29/*
30 * GPIO driver for AR71xx
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/mips/atheros/ar71xx_gpio.c 255334 2013-09-06 23:39:56Z loos $");
34__FBSDID("$FreeBSD: head/sys/mips/atheros/ar71xx_gpio.c 255335 2013-09-06 23:47:50Z loos $");
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/bus.h>
39
40#include <sys/kernel.h>
41#include <sys/module.h>
42#include <sys/rman.h>
43#include <sys/lock.h>
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/bus.h>
39
40#include <sys/kernel.h>
41#include <sys/module.h>
42#include <sys/rman.h>
43#include <sys/lock.h>
44#include <sys/malloc.h>
44#include <sys/mutex.h>
45#include <sys/gpio.h>
46
47#include <machine/bus.h>
48#include <machine/resource.h>
49#include <mips/atheros/ar71xxreg.h>
50#include <mips/atheros/ar71xx_setup.h>
51#include <mips/atheros/ar71xx_gpiovar.h>

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

413 (void) ar71xx_gpio_pin_max(dev, &maxpin);
414 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
415 "pinmask", &mask) != 0)
416 mask = 0;
417 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
418 "pinon", &pinon) != 0)
419 pinon = 0;
420 device_printf(dev, "gpio pinmask=0x%x\n", mask);
45#include <sys/mutex.h>
46#include <sys/gpio.h>
47
48#include <machine/bus.h>
49#include <machine/resource.h>
50#include <mips/atheros/ar71xxreg.h>
51#include <mips/atheros/ar71xx_setup.h>
52#include <mips/atheros/ar71xx_gpiovar.h>

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

414 (void) ar71xx_gpio_pin_max(dev, &maxpin);
415 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
416 "pinmask", &mask) != 0)
417 mask = 0;
418 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
419 "pinon", &pinon) != 0)
420 pinon = 0;
421 device_printf(dev, "gpio pinmask=0x%x\n", mask);
422 for (j = 0; j <= maxpin; j++) {
423 if ((mask & (1 << j)) == 0)
424 continue;
425 sc->gpio_npins++;
426 }
427 sc->gpio_pins = malloc(sizeof(*sc->gpio_pins) * sc->gpio_npins,
428 M_DEVBUF, M_WAITOK | M_ZERO);
421 for (i = 0, j = 0; j <= maxpin; j++) {
422 if ((mask & (1 << j)) == 0)
423 continue;
424 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME,
425 "pin %d", j);
426 sc->gpio_pins[i].gp_pin = j;
427 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
428 sc->gpio_pins[i].gp_flags = 0;
429 ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], DEFAULT_CAPS);
430 i++;
431 }
429 for (i = 0, j = 0; j <= maxpin; j++) {
430 if ((mask & (1 << j)) == 0)
431 continue;
432 snprintf(sc->gpio_pins[i].gp_name, GPIOMAXNAME,
433 "pin %d", j);
434 sc->gpio_pins[i].gp_pin = j;
435 sc->gpio_pins[i].gp_caps = DEFAULT_CAPS;
436 sc->gpio_pins[i].gp_flags = 0;
437 ar71xx_gpio_pin_configure(sc, &sc->gpio_pins[i], DEFAULT_CAPS);
438 i++;
439 }
432 sc->gpio_npins = i;
433 for (i = 0; i < sc->gpio_npins; i++) {
434 j = sc->gpio_pins[i].gp_pin;
435 if ((pinon & (1 << j)) != 0)
436 ar71xx_gpio_pin_set(dev, j, 1);
437 }
438 device_add_child(dev, "gpioc", device_get_unit(dev));
439 device_add_child(dev, "gpiobus", device_get_unit(dev));
440 return (bus_generic_attach(dev));

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

450 ar71xx_gpio_function_disable(sc, GPIO_FUNC_SPI_CS1_EN);
451 ar71xx_gpio_function_disable(sc, GPIO_FUNC_SPI_CS2_EN);
452 bus_generic_detach(dev);
453
454 if (sc->gpio_mem_res)
455 bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
456 sc->gpio_mem_res);
457
440 for (i = 0; i < sc->gpio_npins; i++) {
441 j = sc->gpio_pins[i].gp_pin;
442 if ((pinon & (1 << j)) != 0)
443 ar71xx_gpio_pin_set(dev, j, 1);
444 }
445 device_add_child(dev, "gpioc", device_get_unit(dev));
446 device_add_child(dev, "gpiobus", device_get_unit(dev));
447 return (bus_generic_attach(dev));

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

457 ar71xx_gpio_function_disable(sc, GPIO_FUNC_SPI_CS1_EN);
458 ar71xx_gpio_function_disable(sc, GPIO_FUNC_SPI_CS2_EN);
459 bus_generic_detach(dev);
460
461 if (sc->gpio_mem_res)
462 bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
463 sc->gpio_mem_res);
464
465 free(sc->gpio_pins, M_DEVBUF);
458 mtx_destroy(&sc->gpio_mtx);
459
460 return(0);
461}
462
463static device_method_t ar71xx_gpio_methods[] = {
464 DEVMETHOD(device_probe, ar71xx_gpio_probe),
465 DEVMETHOD(device_attach, ar71xx_gpio_attach),

--- 22 unchanged lines hidden ---
466 mtx_destroy(&sc->gpio_mtx);
467
468 return(0);
469}
470
471static device_method_t ar71xx_gpio_methods[] = {
472 DEVMETHOD(device_probe, ar71xx_gpio_probe),
473 DEVMETHOD(device_attach, ar71xx_gpio_attach),

--- 22 unchanged lines hidden ---