svn commit: r299384 - in head/sys: arm/nvidia dev/gpio
Oleksandr Tymoshenko
gonzo at FreeBSD.org
Tue May 10 20:02:05 UTC 2016
Author: gonzo
Date: Tue May 10 20:02:03 2016
New Revision: 299384
URL: https://svnweb.freebsd.org/changeset/base/299384
Log:
Pass device tree node as a part of gpio_pin_get_by_ofw_XXX API
Current API assumes that "gpios" property belongs to the device's node but for
some binding it's not true: gpiokeys has set of child nodes with this property.
Patch adds new argument instead of replacing device_t because device_t will be
used to track ownership for allocated pins
Reviewed by: mmel
Differential Revision: https://reviews.freebsd.org/D6277
Modified:
head/sys/arm/nvidia/tegra_sdhci.c
head/sys/dev/gpio/gpiobusvar.h
head/sys/dev/gpio/ofw_gpiobus.c
Modified: head/sys/arm/nvidia/tegra_sdhci.c
==============================================================================
--- head/sys/arm/nvidia/tegra_sdhci.c Tue May 10 19:11:25 2016 (r299383)
+++ head/sys/arm/nvidia/tegra_sdhci.c Tue May 10 20:02:03 2016 (r299384)
@@ -300,9 +300,9 @@ tegra_sdhci_attach(device_t dev)
goto fail;
}
- gpio_pin_get_by_ofw_property(sc->dev, "cd-gpios", &sc->gpio_cd);
- gpio_pin_get_by_ofw_property(sc->dev, "power-gpios", &sc->gpio_power);
- gpio_pin_get_by_ofw_property(sc->dev, "wp-gpios", &sc->gpio_wp);
+ gpio_pin_get_by_ofw_property(sc->dev, node, "cd-gpios", &sc->gpio_cd);
+ gpio_pin_get_by_ofw_property(sc->dev, node, "power-gpios", &sc->gpio_power);
+ gpio_pin_get_by_ofw_property(sc->dev, node, "wp-gpios", &sc->gpio_wp);
rv = clk_get_by_ofw_index(dev, 0, &sc->clk);
if (rv != 0) {
Modified: head/sys/dev/gpio/gpiobusvar.h
==============================================================================
--- head/sys/dev/gpio/gpiobusvar.h Tue May 10 19:11:25 2016 (r299383)
+++ head/sys/dev/gpio/gpiobusvar.h Tue May 10 20:02:03 2016 (r299384)
@@ -116,10 +116,12 @@ void ofw_gpiobus_register_provider(devic
void ofw_gpiobus_unregister_provider(device_t);
/* Consumers interface. */
-int gpio_pin_get_by_ofw_name(device_t consumer, char *name, gpio_pin_t *gpio);
-int gpio_pin_get_by_ofw_idx(device_t consumer, int idx, gpio_pin_t *gpio);
-int gpio_pin_get_by_ofw_property(device_t consumer, char *name,
- gpio_pin_t *gpio);
+int gpio_pin_get_by_ofw_name(device_t consumer, phandle_t node,
+ char *name, gpio_pin_t *gpio);
+int gpio_pin_get_by_ofw_idx(device_t consumer, phandle_t node,
+ int idx, gpio_pin_t *gpio);
+int gpio_pin_get_by_ofw_property(device_t consumer, phandle_t node,
+ char *name, gpio_pin_t *gpio);
void gpio_pin_release(gpio_pin_t gpio);
int gpio_pin_is_active(gpio_pin_t pin, bool *active);
int gpio_pin_set_active(gpio_pin_t pin, bool active);
Modified: head/sys/dev/gpio/ofw_gpiobus.c
==============================================================================
--- head/sys/dev/gpio/ofw_gpiobus.c Tue May 10 19:11:25 2016 (r299383)
+++ head/sys/dev/gpio/ofw_gpiobus.c Tue May 10 20:02:03 2016 (r299384)
@@ -56,21 +56,17 @@ static int ofw_gpiobus_parse_gpios_impl(
*
*/
static int
-gpio_pin_get_by_ofw_impl(device_t consumer_dev, char *prop_name, int idx,
- gpio_pin_t *out_pin)
+gpio_pin_get_by_ofw_impl(device_t consumer, phandle_t cnode,
+ char *prop_name, int idx, gpio_pin_t *out_pin)
{
- phandle_t cnode, xref;
+ phandle_t xref;
pcell_t *cells;
device_t busdev;
struct gpiobus_pin pin;
int ncells, rv;
- cnode = ofw_bus_get_node(consumer_dev);
- if (cnode <= 0) {
- device_printf(consumer_dev,
- "%s called on not ofw based device\n", __func__);
- return (ENXIO);
- }
+ KASSERT(consumer != NULL && cnode > 0,
+ ("both consumer and cnode required"));
rv = ofw_bus_parse_xref_list_alloc(cnode, prop_name, "#gpio-cells",
idx, &xref, &ncells, &cells);
@@ -95,17 +91,13 @@ gpio_pin_get_by_ofw_impl(device_t consum
rv = gpio_map_gpios(pin.dev, cnode, OF_node_from_xref(xref), ncells,
cells, &pin.pin, &pin.flags);
free(cells, M_OFWPROP);
- if (rv != 0) {
- device_printf(consumer_dev, "Cannot map the gpio property.\n");
+ if (rv != 0)
return (ENXIO);
- }
/* Reserve GPIO pin. */
rv = gpiobus_map_pin(busdev, pin.pin);
- if (rv != 0) {
- device_printf(consumer_dev, "Cannot reserve gpio pin.\n");
+ if (rv != 0)
return (EBUSY);
- }
*out_pin = malloc(sizeof(struct gpiobus_pin), M_DEVBUF,
M_WAITOK | M_ZERO);
@@ -114,35 +106,34 @@ gpio_pin_get_by_ofw_impl(device_t consum
}
int
-gpio_pin_get_by_ofw_idx(device_t consumer_dev, int idx, gpio_pin_t *pin)
+gpio_pin_get_by_ofw_idx(device_t consumer, phandle_t node,
+ int idx, gpio_pin_t *pin)
{
- return (gpio_pin_get_by_ofw_impl(consumer_dev, "gpios", idx, pin));
+ return (gpio_pin_get_by_ofw_impl(consumer, node, "gpios", idx, pin));
}
int
-gpio_pin_get_by_ofw_property(device_t consumer_dev, char *name, gpio_pin_t *pin)
+gpio_pin_get_by_ofw_property(device_t consumer, phandle_t node,
+ char *name, gpio_pin_t *pin)
{
- return (gpio_pin_get_by_ofw_impl(consumer_dev, name, 0, pin));
+ return (gpio_pin_get_by_ofw_impl(consumer, node, name, 0, pin));
}
int
-gpio_pin_get_by_ofw_name(device_t consumer_dev, char *name, gpio_pin_t *pin)
+gpio_pin_get_by_ofw_name(device_t consumer, phandle_t node,
+ char *name, gpio_pin_t *pin)
{
int rv, idx;
- phandle_t cnode;
- cnode = ofw_bus_get_node(consumer_dev);
- if (cnode <= 0) {
- device_printf(consumer_dev,
- "%s called on not ofw based device\n", __func__);
- return (ENXIO);
- }
- rv = ofw_bus_find_string_index(cnode, "gpio-names", name, &idx);
+ KASSERT(consumer != NULL && node > 0,
+ ("both consumer and node required"));
+
+ rv = ofw_bus_find_string_index(node, "gpio-names", name, &idx);
if (rv != 0)
return (rv);
- return (gpio_pin_get_by_ofw_idx(consumer_dev, idx, pin));
+ return (gpio_pin_get_by_ofw_idx(consumer, node, idx, pin));
}
void
More information about the svn-src-head
mailing list