rk30xx_gpio.c (276784) | rk30xx_gpio.c (277968) |
---|---|
1/*- 2 * Copyright (c) 2013 Ganbold Tsagaankhuu <ganbold@freebsd.org> 3 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 4 * Copyright (c) 2012 Luiz Otavio O Souza. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2013 Ganbold Tsagaankhuu <ganbold@freebsd.org> 3 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org> 4 * Copyright (c) 2012 Luiz Otavio O Souza. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/sys/arm/rockchip/rk30xx_gpio.c 276784 2015-01-07 19:15:11Z loos $"); | 30__FBSDID("$FreeBSD: head/sys/arm/rockchip/rk30xx_gpio.c 277968 2015-01-31 12:17:07Z loos $"); |
31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bus.h> 35 36#include <sys/kernel.h> 37#include <sys/module.h> 38#include <sys/rman.h> --- 355 unchanged lines hidden (view full) --- 394 struct rk30_gpio_softc *sc = device_get_softc(dev); 395 int i, rid; 396 phandle_t gpio; 397 unsigned long start; 398 399 if (rk30_gpio_sc) 400 return (ENXIO); 401 sc->sc_dev = dev; | 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bus.h> 35 36#include <sys/kernel.h> 37#include <sys/module.h> 38#include <sys/rman.h> --- 355 unchanged lines hidden (view full) --- 394 struct rk30_gpio_softc *sc = device_get_softc(dev); 395 int i, rid; 396 phandle_t gpio; 397 unsigned long start; 398 399 if (rk30_gpio_sc) 400 return (ENXIO); 401 sc->sc_dev = dev; |
402 mtx_init(&sc->sc_mtx, "rk30 gpio", "gpio", MTX_DEF); |
|
402 403 rid = 0; 404 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 405 RF_ACTIVE); 406 if (!sc->sc_mem_res) { 407 device_printf(dev, "cannot allocate memory window\n"); | 403 404 rid = 0; 405 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 406 RF_ACTIVE); 407 if (!sc->sc_mem_res) { 408 device_printf(dev, "cannot allocate memory window\n"); |
408 return (ENXIO); | 409 goto fail; |
409 } 410 sc->sc_bst = rman_get_bustag(sc->sc_mem_res); 411 sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res); 412 /* Check the unit we are attaching by our base address. */ 413 sc->sc_bank = -1; 414 start = rman_get_start(sc->sc_mem_res); 415 for (i = 0; i < nitems(rk30_gpio_base_addr); i++) { 416 if (rk30_gpio_base_addr[i] == start) { 417 sc->sc_bank = i; 418 break; 419 } 420 } 421 if (sc->sc_bank == -1) { 422 device_printf(dev, 423 "unsupported device unit (only GPIO0..3 are supported)\n"); | 410 } 411 sc->sc_bst = rman_get_bustag(sc->sc_mem_res); 412 sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res); 413 /* Check the unit we are attaching by our base address. */ 414 sc->sc_bank = -1; 415 start = rman_get_start(sc->sc_mem_res); 416 for (i = 0; i < nitems(rk30_gpio_base_addr); i++) { 417 if (rk30_gpio_base_addr[i] == start) { 418 sc->sc_bank = i; 419 break; 420 } 421 } 422 if (sc->sc_bank == -1) { 423 device_printf(dev, 424 "unsupported device unit (only GPIO0..3 are supported)\n"); |
424 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); 425 return (ENXIO); | 425 goto fail; |
426 } 427 428 rid = 0; 429 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 430 RF_ACTIVE); 431 if (!sc->sc_irq_res) { | 426 } 427 428 rid = 0; 429 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, 430 RF_ACTIVE); 431 if (!sc->sc_irq_res) { |
432 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); | |
433 device_printf(dev, "cannot allocate interrupt\n"); | 432 device_printf(dev, "cannot allocate interrupt\n"); |
434 return (ENXIO); | 433 goto fail; |
435 } 436 437 /* Find our node. */ 438 gpio = ofw_bus_get_node(sc->sc_dev); 439 440 if (!OF_hasprop(gpio, "gpio-controller")) 441 /* Node is not a GPIO controller. */ 442 goto fail; 443 | 434 } 435 436 /* Find our node. */ 437 gpio = ofw_bus_get_node(sc->sc_dev); 438 439 if (!OF_hasprop(gpio, "gpio-controller")) 440 /* Node is not a GPIO controller. */ 441 goto fail; 442 |
444 mtx_init(&sc->sc_mtx, "rk30 gpio", "gpio", MTX_DEF); 445 | |
446 /* Initialize the software controlled pins. */ 447 for (i = 0; i < RK30_GPIO_PINS; i++) { 448 snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME, 449 "pin %d", i); 450 sc->sc_gpio_pins[i].gp_pin = i; 451 sc->sc_gpio_pins[i].gp_caps = RK30_GPIO_DEFAULT_CAPS; 452 sc->sc_gpio_pins[i].gp_flags = rk30_gpio_get_function(sc, i); 453 } --- 8 unchanged lines hidden (view full) --- 462 463 return (bus_generic_attach(dev)); 464 465fail: 466 if (sc->sc_irq_res) 467 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); 468 if (sc->sc_mem_res) 469 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); | 443 /* Initialize the software controlled pins. */ 444 for (i = 0; i < RK30_GPIO_PINS; i++) { 445 snprintf(sc->sc_gpio_pins[i].gp_name, GPIOMAXNAME, 446 "pin %d", i); 447 sc->sc_gpio_pins[i].gp_pin = i; 448 sc->sc_gpio_pins[i].gp_caps = RK30_GPIO_DEFAULT_CAPS; 449 sc->sc_gpio_pins[i].gp_flags = rk30_gpio_get_function(sc, i); 450 } --- 8 unchanged lines hidden (view full) --- 459 460 return (bus_generic_attach(dev)); 461 462fail: 463 if (sc->sc_irq_res) 464 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); 465 if (sc->sc_mem_res) 466 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); |
467 mtx_destroy(&sc->sc_mtx); 468 |
|
470 return (ENXIO); 471} 472 473static int 474rk30_gpio_detach(device_t dev) 475{ 476 477 return (EBUSY); --- 148 unchanged lines hidden --- | 469 return (ENXIO); 470} 471 472static int 473rk30_gpio_detach(device_t dev) 474{ 475 476 return (EBUSY); --- 148 unchanged lines hidden --- |