Move gpiobus routines to dev/gpio. Avoid polluting ofw_bus with bus
specific parts. Requested by: nwhitehorn
This commit is contained in:
parent
b79625ea0c
commit
e80f8fa589
@ -31,6 +31,32 @@
|
||||
|
||||
INTERFACE gpio;
|
||||
|
||||
CODE {
|
||||
static gpio_map_gpios_t gpio_default_map_gpios;
|
||||
|
||||
int
|
||||
gpio_default_map_gpios(device_t bus, phandle_t dev,
|
||||
phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin,
|
||||
uint32_t *flags)
|
||||
{
|
||||
/* Propagate up the bus hierarchy until someone handles it. */
|
||||
if (device_get_parent(bus) != NULL)
|
||||
return (GPIO_MAP_GPIOS(device_get_parent(bus), dev,
|
||||
gparent, gcells, gpios, pin, flags));
|
||||
|
||||
/* If that fails, then assume the FreeBSD defaults. */
|
||||
*pin = gpios[0];
|
||||
if (gcells == 2 || gcells == 3)
|
||||
*flags = gpios[gcells - 1];
|
||||
|
||||
return (0);
|
||||
}
|
||||
};
|
||||
|
||||
HEADER {
|
||||
#include <dev/ofw/openfirm.h>
|
||||
};
|
||||
|
||||
#
|
||||
# Get total number of pins
|
||||
#
|
||||
@ -100,3 +126,16 @@ METHOD int pin_setflags {
|
||||
uint32_t pin_num;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
#
|
||||
# Allow the GPIO controller to map the gpio-specifier on its own.
|
||||
#
|
||||
METHOD int map_gpios {
|
||||
device_t bus;
|
||||
phandle_t dev;
|
||||
phandle_t gparent;
|
||||
int gcells;
|
||||
pcell_t *gpios;
|
||||
uint32_t *pin;
|
||||
uint32_t *flags;
|
||||
} DEFAULT gpio_default_map_gpios;
|
||||
|
@ -36,7 +36,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <dev/gpio/gpiobusvar.h>
|
||||
|
||||
#include "gpio_if.h"
|
||||
#include "gpiobus_if.h"
|
||||
|
||||
static int gpiobus_parse_pins(struct gpiobus_softc *, device_t, int);
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include <dev/ofw/ofw_bus_subr.h>
|
||||
#endif
|
||||
|
||||
#include "gpio_if.h"
|
||||
|
||||
#define GPIOBUS_IVAR(d) (struct gpiobus_ivar *) device_get_ivars(d)
|
||||
#define GPIOBUS_SOFTC(d) (struct gpiobus_softc *) device_get_softc(d)
|
||||
#define GPIOBUS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
|
||||
@ -72,6 +74,13 @@ struct ofw_gpiobus_devinfo {
|
||||
struct ofw_bus_devinfo opd_obdinfo;
|
||||
};
|
||||
|
||||
static __inline int
|
||||
gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells,
|
||||
pcell_t *gpios, uint32_t *pin, uint32_t *flags)
|
||||
{
|
||||
return (GPIO_MAP_GPIOS(bus, dev, gparent, gcells, gpios, pin, flags));
|
||||
}
|
||||
|
||||
device_t ofw_gpiobus_add_fdt_child(device_t, phandle_t);
|
||||
#endif
|
||||
void gpiobus_print_pins(struct gpiobus_ivar *);
|
||||
|
@ -39,8 +39,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <dev/gpio/gpiobusvar.h>
|
||||
#include <dev/ofw/ofw_bus.h>
|
||||
|
||||
#include "gpio_if.h"
|
||||
|
||||
static int ofw_gpiobus_parse_gpios(struct gpiobus_softc *,
|
||||
struct gpiobus_ivar *, phandle_t);
|
||||
static struct ofw_gpiobus_devinfo *ofw_gpiobus_setup_devinfo(device_t,
|
||||
@ -180,7 +178,7 @@ ofw_gpiobus_parse_gpios(struct gpiobus_softc *sc, struct gpiobus_ivar *dinfo,
|
||||
}
|
||||
|
||||
/* Get the GPIO pin number and flags. */
|
||||
if (ofw_bus_map_gpios(sc->sc_dev, child, gpio, cells,
|
||||
if (gpio_map_gpios(sc->sc_dev, child, gpio, cells,
|
||||
&gpios[i + 1], &dinfo->pins[j], &dinfo->flags[j]) != 0) {
|
||||
ofw_gpiobus_free_ivars(dinfo);
|
||||
free(gpios, M_DEVBUF);
|
||||
|
@ -76,12 +76,4 @@ ofw_bus_map_intr(device_t dev, phandle_t iparent, int icells, pcell_t *intr)
|
||||
return (OFW_BUS_MAP_INTR(dev, dev, iparent, icells, intr));
|
||||
}
|
||||
|
||||
static __inline int
|
||||
ofw_bus_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells,
|
||||
pcell_t *gpios, uint32_t *pin, uint32_t *flags)
|
||||
{
|
||||
return (OFW_BUS_MAP_GPIOS(bus, dev, gparent, gcells, gpios, pin,
|
||||
flags));
|
||||
}
|
||||
|
||||
#endif /* !_DEV_OFW_OFW_BUS_H_ */
|
||||
|
@ -58,7 +58,6 @@ CODE {
|
||||
static ofw_bus_get_node_t ofw_bus_default_get_node;
|
||||
static ofw_bus_get_type_t ofw_bus_default_get_type;
|
||||
static ofw_bus_map_intr_t ofw_bus_default_map_intr;
|
||||
static ofw_bus_map_gpios_t ofw_bus_default_map_gpios;
|
||||
|
||||
static const struct ofw_bus_devinfo *
|
||||
ofw_bus_default_get_devinfo(device_t bus, device_t dev)
|
||||
@ -114,24 +113,6 @@ CODE {
|
||||
/* If that fails, then assume a one-domain system */
|
||||
return (interrupt[0]);
|
||||
}
|
||||
|
||||
int
|
||||
ofw_bus_default_map_gpios(device_t bus, phandle_t dev,
|
||||
phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin,
|
||||
uint32_t *flags)
|
||||
{
|
||||
/* Propagate up the bus hierarchy until someone handles it. */
|
||||
if (device_get_parent(bus) != NULL)
|
||||
return OFW_BUS_MAP_GPIOS(device_get_parent(bus), dev,
|
||||
gparent, gcells, gpios, pin, flags);
|
||||
|
||||
/* If that fails, then assume the FreeBSD defaults. */
|
||||
*pin = gpios[0];
|
||||
if (gcells == 2 || gcells == 3)
|
||||
*flags = gpios[gcells - 1];
|
||||
|
||||
return (0);
|
||||
}
|
||||
};
|
||||
|
||||
# Get the ofw_bus_devinfo struct for the device dev on the bus. Used for bus
|
||||
@ -188,14 +169,3 @@ METHOD int map_intr {
|
||||
int icells;
|
||||
pcell_t *interrupt;
|
||||
} DEFAULT ofw_bus_default_map_intr;
|
||||
|
||||
# Map the GPIO controller specific gpio-specifier to GPIO pin and flags.
|
||||
METHOD int map_gpios {
|
||||
device_t bus;
|
||||
phandle_t dev;
|
||||
phandle_t gparent;
|
||||
int gcells;
|
||||
pcell_t *gpios;
|
||||
uint32_t *pin;
|
||||
uint32_t *flags;
|
||||
} DEFAULT ofw_bus_default_map_gpios;
|
||||
|
Loading…
Reference in New Issue
Block a user