Deleted Added
full compact
ar71xx_gpio.c (274670) ar71xx_gpio.c (277968)
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 274670 2014-11-18 17:22:08Z loos $");
34__FBSDID("$FreeBSD: head/sys/mips/atheros/ar71xx_gpio.c 277968 2015-01-31 12:17:07Z 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>

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

336 device_set_desc(dev, "Atheros AR71XX GPIO driver");
337 return (0);
338}
339
340static int
341ar71xx_gpio_attach(device_t dev)
342{
343 struct ar71xx_gpio_softc *sc = device_get_softc(dev);
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>

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

336 device_set_desc(dev, "Atheros AR71XX GPIO driver");
337 return (0);
338}
339
340static int
341ar71xx_gpio_attach(device_t dev)
342{
343 struct ar71xx_gpio_softc *sc = device_get_softc(dev);
344 int error = 0;
345 int i, j, maxpin;
346 int mask, pinon;
347 uint32_t oe;
348
349 KASSERT((device_get_unit(dev) == 0),
350 ("ar71xx_gpio: Only one gpio module supported"));
351
352 mtx_init(&sc->gpio_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
353
354 /* Map control/status registers. */
355 sc->gpio_mem_rid = 0;
356 sc->gpio_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
357 &sc->gpio_mem_rid, RF_ACTIVE);
358
359 if (sc->gpio_mem_res == NULL) {
360 device_printf(dev, "couldn't map memory\n");
344 int i, j, maxpin;
345 int mask, pinon;
346 uint32_t oe;
347
348 KASSERT((device_get_unit(dev) == 0),
349 ("ar71xx_gpio: Only one gpio module supported"));
350
351 mtx_init(&sc->gpio_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
352
353 /* Map control/status registers. */
354 sc->gpio_mem_rid = 0;
355 sc->gpio_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
356 &sc->gpio_mem_rid, RF_ACTIVE);
357
358 if (sc->gpio_mem_res == NULL) {
359 device_printf(dev, "couldn't map memory\n");
361 error = ENXIO;
362 ar71xx_gpio_detach(dev);
360 ar71xx_gpio_detach(dev);
363 return(error);
361 return (ENXIO);
364 }
365
366 if ((sc->gpio_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
367 &sc->gpio_irq_rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
368 device_printf(dev, "unable to allocate IRQ resource\n");
362 }
363
364 if ((sc->gpio_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ,
365 &sc->gpio_irq_rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
366 device_printf(dev, "unable to allocate IRQ resource\n");
367 ar71xx_gpio_detach(dev);
369 return (ENXIO);
370 }
371
372 if ((bus_setup_intr(dev, sc->gpio_irq_res, INTR_TYPE_MISC,
373 ar71xx_gpio_filter, ar71xx_gpio_intr, sc, &sc->gpio_ih))) {
374 device_printf(dev,
375 "WARNING: unable to register interrupt handler\n");
368 return (ENXIO);
369 }
370
371 if ((bus_setup_intr(dev, sc->gpio_irq_res, INTR_TYPE_MISC,
372 ar71xx_gpio_filter, ar71xx_gpio_intr, sc, &sc->gpio_ih))) {
373 device_printf(dev,
374 "WARNING: unable to register interrupt handler\n");
375 ar71xx_gpio_detach(dev);
376 return (ENXIO);
377 }
378
379 sc->dev = dev;
380
381 /* Enable function bits that are required */
382 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
383 "function_set", &mask) == 0) {

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

442static int
443ar71xx_gpio_detach(device_t dev)
444{
445 struct ar71xx_gpio_softc *sc = device_get_softc(dev);
446
447 KASSERT(mtx_initialized(&sc->gpio_mtx), ("gpio mutex not initialized"));
448
449 bus_generic_detach(dev);
376 return (ENXIO);
377 }
378
379 sc->dev = dev;
380
381 /* Enable function bits that are required */
382 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
383 "function_set", &mask) == 0) {

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

442static int
443ar71xx_gpio_detach(device_t dev)
444{
445 struct ar71xx_gpio_softc *sc = device_get_softc(dev);
446
447 KASSERT(mtx_initialized(&sc->gpio_mtx), ("gpio mutex not initialized"));
448
449 bus_generic_detach(dev);
450
450 if (sc->gpio_ih)
451 bus_teardown_intr(dev, sc->gpio_irq_res, sc->gpio_ih);
452 if (sc->gpio_irq_res)
453 bus_release_resource(dev, SYS_RES_IRQ, sc->gpio_irq_rid,
454 sc->gpio_irq_res);
451 if (sc->gpio_mem_res)
452 bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
453 sc->gpio_mem_res);
455 if (sc->gpio_mem_res)
456 bus_release_resource(dev, SYS_RES_MEMORY, sc->gpio_mem_rid,
457 sc->gpio_mem_res);
454
455 free(sc->gpio_pins, M_DEVBUF);
458 if (sc->gpio_pins)
459 free(sc->gpio_pins, M_DEVBUF);
456 mtx_destroy(&sc->gpio_mtx);
457
458 return(0);
459}
460
461static device_method_t ar71xx_gpio_methods[] = {
462 DEVMETHOD(device_probe, ar71xx_gpio_probe),
463 DEVMETHOD(device_attach, ar71xx_gpio_attach),

--- 22 unchanged lines hidden ---
460 mtx_destroy(&sc->gpio_mtx);
461
462 return(0);
463}
464
465static device_method_t ar71xx_gpio_methods[] = {
466 DEVMETHOD(device_probe, ar71xx_gpio_probe),
467 DEVMETHOD(device_attach, ar71xx_gpio_attach),

--- 22 unchanged lines hidden ---