FreeBSD Bugzilla – Attachment 221671 Details for
Bug 252777
Cleanup after gpio_alloc_intr_resource
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
example driver
gpio-int-test.c (text/plain), 2.95 KB, created by
Oskar Holmlund
on 2021-01-17 13:16:46 UTC
(
hide
)
Description:
example driver
Filename:
MIME Type:
Creator:
Oskar Holmlund
Created:
2021-01-17 13:16:46 UTC
Size:
2.95 KB
patch
obsolete
>#include <sys/param.h> >#include <sys/systm.h> >#include <sys/bus.h> >#include <sys/gpio.h> >#include <sys/kernel.h> >#include <sys/lock.h> >#include <sys/malloc.h> >#include <sys/module.h> >#include <sys/mutex.h> >#include <sys/proc.h> >#include <sys/kdb.h> > >#include <sys/ioccom.h> >#include <sys/filio.h> >#include <sys/kbio.h> > >#include <dev/kbd/kbdreg.h> >#include <dev/kbd/kbdtables.h> > >#include <dev/fdt/fdt_common.h> >#include <dev/ofw/ofw_bus.h> >#include <dev/ofw/ofw_bus_subr.h> > >#include <dev/gpio/gpiobusvar.h> > >struct gpio_int_test_softc { > device_t dev; > gpio_pin_t gpio_pin; > > int irq_rid; > struct resource *irq_res; > void *intr_hl; >}; > >static void >gpio_intr(void *arg) >{ > struct gpio_int_test_softc *sc; > sc = (struct gpio_int_test_softc *)arg; > device_printf(sc->dev, "BTN pressed\n"); >} > >static int >gpio_int_test_probe(device_t dev) >{ > if (!ofw_bus_is_compatible(dev, "gpio-int-test")) > return (ENXIO); > > device_set_desc(dev, "GPIO interrupt test attach detach"); > return (0); >} > >static int >gpio_int_test_attach(device_t dev) >{ > phandle_t node; > int err; > struct gpio_int_test_softc *sc; > > sc = device_get_softc(dev); > sc->dev = dev; > > node = ofw_bus_get_node(dev); > if (node == -1) > return (ENXIO); > > > err = gpio_pin_get_by_ofw_propidx(sc->dev, node, > "input-gpios", 0, &sc->gpio_pin); > if (err != 0) { > device_printf(sc->dev, "Failed to get gpio pin\n"); > return (ENXIO); > } > > sc->irq_res = gpio_alloc_intr_resource(sc->dev, &sc->irq_rid, > RF_ACTIVE, sc->gpio_pin, GPIO_INTR_EDGE_BOTH); > if (!sc->irq_res) { > device_printf(sc->dev, "Cannot allocate interrupt\n"); > gpio_pin_release(sc->gpio_pin); > return (ENXIO); > } > > > err = bus_setup_intr(sc->dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE, > NULL, gpio_intr, sc, &sc->intr_hl); > if (err != 0) { > device_printf(sc->dev, "unable to setup the irq handler\n"); > bus_release_resource(sc->dev, SYS_RES_IRQ, sc->irq_rid, > sc->irq_res); > gpio_pin_release(sc->gpio_pin); > return (ENXIO); > } > return (0); >} > >static int >gpio_int_test_detach(device_t dev) >{ > struct gpio_int_test_softc *sc; > sc = device_get_softc(dev); > > if (sc->intr_hl){ > device_printf(sc->dev, "bus_teardown_intr\n"); > bus_teardown_intr(sc->dev, sc->irq_res, sc->intr_hl); > } > if (sc->irq_res) { > device_printf(sc->dev, "bus_release_resource\n"); > bus_release_resource(sc->dev, SYS_RES_IRQ, > sc->irq_rid, sc->irq_res); > } > > if (sc->gpio_pin) { > gpio_pin_release(sc->gpio_pin); > } > return (0); >} > >static devclass_t gpio_int_test_devclass; > >static device_method_t gpio_int_test_methods[] = { > DEVMETHOD(device_probe, gpio_int_test_probe), > DEVMETHOD(device_attach, gpio_int_test_attach), > DEVMETHOD(device_detach, gpio_int_test_detach), > > DEVMETHOD_END >}; > >static driver_t gpio_int_test_driver = { > "gpio_int_test", > gpio_int_test_methods, > sizeof(struct gpio_int_test_softc), >}; > >DRIVER_MODULE(gpio_int_test, simplebus, gpio_int_test_driver, gpio_int_test_devclass, 0, 0); >MODULE_VERSION(gpio_int_test, 1);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 252777
:
221670
| 221671