Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/gpio/ofw_gpiobus.c
Show All 33 Lines | |||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <dev/gpio/gpiobusvar.h> | #include <dev/gpio/gpiobusvar.h> | ||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include "gpiobus_if.h" | |||||
static struct ofw_gpiobus_devinfo *ofw_gpiobus_setup_devinfo(device_t, | static struct ofw_gpiobus_devinfo *ofw_gpiobus_setup_devinfo(device_t, | ||||
device_t, phandle_t); | device_t, phandle_t); | ||||
static void ofw_gpiobus_destroy_devinfo(device_t, struct ofw_gpiobus_devinfo *); | static void ofw_gpiobus_destroy_devinfo(device_t, struct ofw_gpiobus_devinfo *); | ||||
static int ofw_gpiobus_parse_gpios_impl(device_t, phandle_t, char *, | static int ofw_gpiobus_parse_gpios_impl(device_t, phandle_t, char *, | ||||
struct gpiobus_softc *, struct gpiobus_pin **); | struct gpiobus_softc *, struct gpiobus_pin **); | ||||
device_t | device_t | ||||
ofw_gpiobus_add_fdt_child(device_t bus, const char *drvname, phandle_t child) | ofw_gpiobus_add_fdt_child(device_t bus, const char *drvname, phandle_t child) | ||||
{ | { | ||||
device_t childdev; | device_t childdev; | ||||
int i; | |||||
struct gpiobus_ivar *devi; | |||||
struct ofw_gpiobus_devinfo *dinfo; | struct ofw_gpiobus_devinfo *dinfo; | ||||
/* | /* | ||||
* Set up the GPIO child and OFW bus layer devinfo and add it to bus. | * Set up the GPIO child and OFW bus layer devinfo and add it to bus. | ||||
*/ | */ | ||||
childdev = device_add_child(bus, drvname, -1); | childdev = device_add_child(bus, drvname, -1); | ||||
if (childdev == NULL) | if (childdev == NULL) | ||||
return (NULL); | return (NULL); | ||||
dinfo = ofw_gpiobus_setup_devinfo(bus, childdev, child); | dinfo = ofw_gpiobus_setup_devinfo(bus, childdev, child); | ||||
if (dinfo == NULL) { | if (dinfo == NULL) { | ||||
device_delete_child(bus, childdev); | device_delete_child(bus, childdev); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
if (device_probe_and_attach(childdev) != 0) { | if (device_probe_and_attach(childdev) != 0) { | ||||
ofw_gpiobus_destroy_devinfo(bus, dinfo); | ofw_gpiobus_destroy_devinfo(bus, dinfo); | ||||
device_delete_child(bus, childdev); | device_delete_child(bus, childdev); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* Use the child name as pin name. */ | |||||
devi = &dinfo->opd_dinfo; | |||||
for (i = 0; i < devi->npins; i++) | |||||
GPIOBUS_PIN_SETNAME(bus, devi->pins[i], | |||||
device_get_nameunit(childdev)); | |||||
return (childdev); | return (childdev); | ||||
} | } | ||||
int | int | ||||
ofw_gpiobus_parse_gpios(device_t consumer, char *pname, | ofw_gpiobus_parse_gpios(device_t consumer, char *pname, | ||||
struct gpiobus_pin **pins) | struct gpiobus_pin **pins) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | ofw_gpiobus_destroy_devinfo(device_t bus, struct ofw_gpiobus_devinfo *dinfo) | ||||
struct gpiobus_ivar *devi; | struct gpiobus_ivar *devi; | ||||
struct gpiobus_softc *sc; | struct gpiobus_softc *sc; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
devi = &dinfo->opd_dinfo; | devi = &dinfo->opd_dinfo; | ||||
for (i = 0; i < devi->npins; i++) { | for (i = 0; i < devi->npins; i++) { | ||||
if (devi->pins[i] > sc->sc_npins) | if (devi->pins[i] > sc->sc_npins) | ||||
continue; | continue; | ||||
sc->sc_pins_mapped[devi->pins[i]] = 0; | sc->sc_pins[devi->pins[i]].mapped = 0; | ||||
} | } | ||||
gpiobus_free_ivars(devi); | gpiobus_free_ivars(devi); | ||||
resource_list_free(&dinfo->opd_dinfo.rl); | resource_list_free(&dinfo->opd_dinfo.rl); | ||||
ofw_bus_gen_destroy_devinfo(&dinfo->opd_obdinfo); | ofw_bus_gen_destroy_devinfo(&dinfo->opd_obdinfo); | ||||
free(dinfo, M_DEVBUF); | free(dinfo, M_DEVBUF); | ||||
} | } | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |