dm: gpio: Add live tree support

Add support for requesting GPIOs with a live device tree.

This involves adjusting the function signature for the legacy function
gpio_request_by_name_nodev(), so fix up all callers.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes to stm32f746-disco.c:
Signed-off-by: Tom Rini <trini@konsulko.com>
master
Simon Glass 7 years ago
parent 95795ad6ce
commit 150c5afe5b
  1. 12
      board/qualcomm/dragonboard410c/dragonboard410c.c
  2. 4
      board/samsung/common/board.c
  3. 2
      board/samsung/common/exynos5-dt.c
  4. 6
      board/st/stm32f746-disco/stm32f746-disco.c
  5. 51
      drivers/gpio/gpio-uclass.c
  6. 12
      drivers/i2c/mxc_i2c.c
  7. 6
      drivers/mmc/fsl_esdhc.c
  8. 8
      drivers/mmc/s5p_sdhci.c
  9. 2
      drivers/mtd/nand/sunxi_nand.c
  10. 4
      drivers/mtd/nand/tegra_nand.c
  11. 3
      drivers/net/pic32_eth.c
  12. 2
      drivers/sound/max98095.c
  13. 2
      drivers/sound/wm8994.c
  14. 2
      drivers/spi/pic32_spi.c
  15. 7
      drivers/usb/host/ehci-tegra.c
  16. 5
      drivers/usb/host/ehci-vf.c
  17. 10
      include/asm-generic/gpio.h

@ -53,8 +53,8 @@ int board_prepare_usb(enum usb_init_type type)
printf("Failed to find usb_hub_reset_pm dt node.\n"); printf("Failed to find usb_hub_reset_pm dt node.\n");
return node; return node;
} }
ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
&hub_reset, 0); "gpios", 0, &hub_reset, 0);
if (ret < 0) { if (ret < 0) {
printf("Failed to request usb_hub_reset_pm gpio.\n"); printf("Failed to request usb_hub_reset_pm gpio.\n");
return ret; return ret;
@ -69,8 +69,8 @@ int board_prepare_usb(enum usb_init_type type)
printf("Failed to find usb_sw_sel_pm dt node.\n"); printf("Failed to find usb_sw_sel_pm dt node.\n");
return 0; return 0;
} }
ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
&usb_sel, 0); "gpios", 0, &usb_sel, 0);
if (ret < 0) { if (ret < 0) {
printf("Failed to request usb_sw_sel_pm gpio.\n"); printf("Failed to request usb_sw_sel_pm gpio.\n");
return ret; return ret;
@ -121,8 +121,8 @@ int misc_init_r(void)
return 0; return 0;
} }
if (gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, &resin, if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
0)) { &resin, 0)) {
printf("Failed to request key_vol_down button.\n"); printf("Failed to request key_vol_down button.\n");
return 0; return 0;
} }

@ -351,8 +351,8 @@ void reset_misc(void)
if (node < 0) if (node < 0)
return; return;
gpio_request_by_name_nodev(gd->fdt_blob, node, "reset-gpio", 0, &gpio, gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0,
GPIOD_IS_OUT); &gpio, GPIOD_IS_OUT);
if (dm_gpio_is_valid(&gpio)) { if (dm_gpio_is_valid(&gpio)) {
/* /*

@ -45,7 +45,7 @@ static void board_enable_audio_codec(void)
if (node <= 0) if (node <= 0)
return; return;
ret = gpio_request_by_name_nodev(gd->fdt_blob, node, ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
"codec-enable-gpio", 0, &en_gpio, "codec-enable-gpio", 0, &en_gpio,
GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
if (ret == -FDT_ERR_NOTFOUND) if (ret == -FDT_ERR_NOTFOUND)

@ -101,7 +101,7 @@ int board_late_init(void)
if (node < 0) if (node < 0)
return -1; return -1;
gpio_request_by_name_nodev(gd->fdt_blob, node, "led-gpio", 0, &gpio, gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
GPIOD_IS_OUT); GPIOD_IS_OUT);
if (dm_gpio_is_valid(&gpio)) { if (dm_gpio_is_valid(&gpio)) {
@ -115,8 +115,8 @@ int board_late_init(void)
if (node < 0) if (node < 0)
return -1; return -1;
gpio_request_by_name_nodev(gd->fdt_blob, node, "button-gpio", 0, &gpio, gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
GPIOD_IS_IN); &gpio, GPIOD_IS_IN);
if (dm_gpio_is_valid(&gpio)) { if (dm_gpio_is_valid(&gpio)) {
if (dm_gpio_get_value(&gpio)) if (dm_gpio_get_value(&gpio))

@ -683,45 +683,41 @@ err:
return ret; return ret;
} }
static int _gpio_request_by_name_nodev(const void *blob, int node, static int _gpio_request_by_name_nodev(ofnode node, const char *list_name,
const char *list_name, int index, int index, struct gpio_desc *desc,
struct gpio_desc *desc, int flags, int flags, bool add_index)
bool add_index)
{ {
struct ofnode_phandle_args args; struct ofnode_phandle_args args;
int ret; int ret;
ret = ofnode_parse_phandle_with_args(offset_to_ofnode(node), list_name, ret = ofnode_parse_phandle_with_args(node, list_name, "#gpio-cells", 0,
"#gpio-cells", 0, index, &args); index, &args);
if (ret)
debug("%s: fdtdec_parse_phandle_with_args failed\n", __func__);
return gpio_request_tail(ret, offset_to_ofnode(node), &args, list_name, return gpio_request_tail(ret, node, &args, list_name, index, desc,
index, desc, flags, add_index); flags, add_index);
} }
int gpio_request_by_name_nodev(const void *blob, int node, int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,
const char *list_name, int index,
struct gpio_desc *desc, int flags) struct gpio_desc *desc, int flags)
{ {
return _gpio_request_by_name_nodev(blob, node, list_name, index, desc, return _gpio_request_by_name_nodev(node, list_name, index, desc, flags,
flags, index > 0); index > 0);
} }
int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, int gpio_request_by_name(struct udevice *dev, const char *list_name, int index,
struct gpio_desc *desc, int flags) struct gpio_desc *desc, int flags)
{ {
/* struct ofnode_phandle_args args;
* This isn't ideal since we don't use dev->name in the debug() int ret;
* calls in gpio_request_by_name(), but we can do this until
* gpio_request_by_name_nodev() can be dropped. ret = dev_read_phandle_with_args(dev, list_name, "#gpio-cells", 0,
*/ index, &args);
return gpio_request_by_name_nodev(gd->fdt_blob, dev_of_offset(dev),
list_name, index, desc, flags); return gpio_request_tail(ret, dev_ofnode(dev), &args, list_name,
index, desc, flags, index > 0);
} }
int gpio_request_list_by_name_nodev(const void *blob, int node, int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
const char *list_name,
struct gpio_desc *desc, int max_count, struct gpio_desc *desc, int max_count,
int flags) int flags)
{ {
@ -729,7 +725,7 @@ int gpio_request_list_by_name_nodev(const void *blob, int node,
int ret; int ret;
for (count = 0; count < max_count; count++) { for (count = 0; count < max_count; count++) {
ret = _gpio_request_by_name_nodev(blob, node, list_name, count, ret = _gpio_request_by_name_nodev(node, list_name, count,
&desc[count], flags, true); &desc[count], flags, true);
if (ret == -ENOENT) if (ret == -ENOENT)
break; break;
@ -755,9 +751,8 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
* calls in gpio_request_by_name(), but we can do this until * calls in gpio_request_by_name(), but we can do this until
* gpio_request_list_by_name_nodev() can be dropped. * gpio_request_list_by_name_nodev() can be dropped.
*/ */
return gpio_request_list_by_name_nodev(gd->fdt_blob, dev_of_offset(dev), return gpio_request_list_by_name_nodev(dev_ofnode(dev), list_name, desc,
list_name, desc, max_count, max_count, flags);
flags);
} }
int gpio_get_list_count(struct udevice *dev, const char *list_name) int gpio_get_list_count(struct udevice *dev, const char *list_name)

@ -773,12 +773,12 @@ static int mxc_i2c_probe(struct udevice *bus)
if (ret < 0) { if (ret < 0) {
debug("i2c bus %d at 0x%2lx, no gpio pinctrl state.\n", bus->seq, i2c_bus->base); debug("i2c bus %d at 0x%2lx, no gpio pinctrl state.\n", bus->seq, i2c_bus->base);
} else { } else {
ret = gpio_request_by_name_nodev(fdt, node, "scl-gpios", ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
0, &i2c_bus->scl_gpio, "scl-gpios", 0, &i2c_bus->scl_gpio,
GPIOD_IS_OUT); GPIOD_IS_OUT);
ret2 = gpio_request_by_name_nodev(fdt, node, "sda-gpios", ret2 = gpio_request_by_name_nodev(offset_to_ofnode(node),
0, &i2c_bus->sda_gpio, "sda-gpios", 0, &i2c_bus->sda_gpio,
GPIOD_IS_OUT); GPIOD_IS_OUT);
if (!dm_gpio_is_valid(&i2c_bus->sda_gpio) | if (!dm_gpio_is_valid(&i2c_bus->sda_gpio) |
!dm_gpio_is_valid(&i2c_bus->scl_gpio) | !dm_gpio_is_valid(&i2c_bus->scl_gpio) |
ret | ret2) { ret | ret2) {

@ -983,15 +983,15 @@ static int fsl_esdhc_probe(struct udevice *dev)
} else { } else {
priv->non_removable = 0; priv->non_removable = 0;
#ifdef CONFIG_DM_GPIO #ifdef CONFIG_DM_GPIO
gpio_request_by_name_nodev(fdt, node, "cd-gpios", 0, gpio_request_by_name_nodev(offset_to_ofnode(node), "cd-gpios",
&priv->cd_gpio, GPIOD_IS_IN); 0, &priv->cd_gpio, GPIOD_IS_IN);
#endif #endif
} }
priv->wp_enable = 1; priv->wp_enable = 1;
#ifdef CONFIG_DM_GPIO #ifdef CONFIG_DM_GPIO
ret = gpio_request_by_name_nodev(fdt, node, "wp-gpios", 0, ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "wp-gpios", 0,
&priv->wp_gpio, GPIOD_IS_IN); &priv->wp_gpio, GPIOD_IS_IN);
if (ret) if (ret)
priv->wp_enable = 0; priv->wp_enable = 0;

@ -184,10 +184,10 @@ static int sdhci_get_config(const void *blob, int node, struct sdhci_host *host)
} }
host->ioaddr = (void *)base; host->ioaddr = (void *)base;
gpio_request_by_name_nodev(blob, node, "pwr-gpios", 0, &host->pwr_gpio, gpio_request_by_name_nodev(offset_to_ofnode(node), "pwr-gpios", 0,
GPIOD_IS_OUT); &host->pwr_gpio, GPIOD_IS_OUT);
gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &host->cd_gpio, gpio_request_by_name_nodev(offset_to_ofnode(node), "cd-gpios", 0,
GPIOD_IS_IN); &host->cd_gpio, GPIOD_IS_IN);
return 0; return 0;
} }

@ -1663,7 +1663,7 @@ static int sunxi_nand_chip_init(int node, struct sunxi_nfc *nfc, int devnum)
chip->sels[i].rb.type = RB_NATIVE; chip->sels[i].rb.type = RB_NATIVE;
chip->sels[i].rb.info.nativeid = tmp; chip->sels[i].rb.info.nativeid = tmp;
} else { } else {
ret = gpio_request_by_name_nodev(blob, node, ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
"rb-gpios", i, "rb-gpios", i,
&chip->sels[i].rb.info.gpio, &chip->sels[i].rb.info.gpio,
GPIOD_IS_IN); GPIOD_IS_IN);

@ -894,8 +894,8 @@ static int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config)
config->reg = (struct nand_ctlr *)fdtdec_get_addr(blob, node, "reg"); config->reg = (struct nand_ctlr *)fdtdec_get_addr(blob, node, "reg");
config->enabled = fdtdec_get_is_enabled(blob, node); config->enabled = fdtdec_get_is_enabled(blob, node);
config->width = fdtdec_get_int(blob, node, "nvidia,nand-width", 8); config->width = fdtdec_get_int(blob, node, "nvidia,nand-width", 8);
err = gpio_request_by_name_nodev(blob, node, "nvidia,wp-gpios", 0, err = gpio_request_by_name_nodev(offset_to_ofnode(node),
&config->wp_gpio, GPIOD_IS_OUT); "nvidia,wp-gpios", 0, &config->wp_gpio, GPIOD_IS_OUT);
if (err) if (err)
return err; return err;
err = fdtdec_get_int_array(blob, node, "nvidia,timing", err = fdtdec_get_int_array(blob, node, "nvidia,timing",

@ -561,8 +561,7 @@ static int pic32_eth_probe(struct udevice *dev)
phy_addr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1); phy_addr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
/* phy reset gpio */ /* phy reset gpio */
gpio_request_by_name_nodev(gd->fdt_blob, dev_of_offset(dev), gpio_request_by_name_nodev(dev_ofnode(dev), "reset-gpios", 0,
"reset-gpios", 0,
&priv->rst_gpio, GPIOD_IS_OUT); &priv->rst_gpio, GPIOD_IS_OUT);
priv->phyif = pdata->phy_interface; priv->phyif = pdata->phy_interface;

@ -9,6 +9,8 @@
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include <common.h>
#include <asm/arch/clk.h> #include <asm/arch/clk.h>
#include <asm/arch/cpu.h> #include <asm/arch/cpu.h>
#include <asm/arch/power.h> #include <asm/arch/power.h>

@ -4,11 +4,11 @@
* *
* SPDX-License-Identifier: GPL-2.0+ * SPDX-License-Identifier: GPL-2.0+
*/ */
#include <common.h>
#include <asm/arch/clk.h> #include <asm/arch/clk.h>
#include <asm/arch/cpu.h> #include <asm/arch/cpu.h>
#include <asm/gpio.h> #include <asm/gpio.h>
#include <asm/io.h> #include <asm/io.h>
#include <common.h>
#include <div64.h> #include <div64.h>
#include <fdtdec.h> #include <fdtdec.h>
#include <i2c.h> #include <i2c.h>

@ -414,7 +414,7 @@ static int pic32_spi_probe(struct udevice *bus)
* of the ongoing transfer. To avoid this sort of error we will drive * of the ongoing transfer. To avoid this sort of error we will drive
* /CS manually by toggling cs-gpio pins. * /CS manually by toggling cs-gpio pins.
*/ */
ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "cs-gpios", 0, ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "cs-gpios", 0,
&priv->cs_gpio, GPIOD_IS_OUT); &priv->cs_gpio, GPIOD_IS_OUT);
if (ret) { if (ret) {
printf("pic32-spi: error, cs-gpios not found\n"); printf("pic32-spi: error, cs-gpios not found\n");

@ -728,9 +728,10 @@ static int fdt_decode_usb(struct udevice *dev, struct fdt_usb *config)
debug("%s: Missing/invalid peripheral ID\n", __func__); debug("%s: Missing/invalid peripheral ID\n", __func__);
return -EINVAL; return -EINVAL;
} }
gpio_request_by_name_nodev(blob, node, "nvidia,vbus-gpio", 0, gpio_request_by_name_nodev(offset_to_ofnode(node), "nvidia,vbus-gpio",
&config->vbus_gpio, GPIOD_IS_OUT); 0, &config->vbus_gpio, GPIOD_IS_OUT);
gpio_request_by_name_nodev(blob, node, "nvidia,phy-reset-gpio", 0, gpio_request_by_name_nodev(offset_to_ofnode(node),
"nvidia,phy-reset-gpio", 0,
&config->phy_reset_gpio, GPIOD_IS_OUT); &config->phy_reset_gpio, GPIOD_IS_OUT);
debug("enabled=%d, legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, " debug("enabled=%d, legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, "
"vbus=%d, phy_reset=%d, dr_mode=%d\n", "vbus=%d, phy_reset=%d, dr_mode=%d\n",

@ -252,8 +252,9 @@ static int vf_usb_ofdata_to_platdata(struct udevice *dev)
} }
if (priv->dr_mode == DR_MODE_OTG) { if (priv->dr_mode == DR_MODE_OTG) {
gpio_request_by_name_nodev(dt_blob, node, "fsl,cdet-gpio", 0, gpio_request_by_name_nodev(offset_to_ofnode(node),
&priv->cdet_gpio, GPIOD_IS_IN); "fsl,cdet-gpio", 0, &priv->cdet_gpio,
GPIOD_IS_IN);
if (dm_gpio_is_valid(&priv->cdet_gpio)) { if (dm_gpio_is_valid(&priv->cdet_gpio)) {
if (dm_gpio_get_value(&priv->cdet_gpio)) if (dm_gpio_get_value(&priv->cdet_gpio))
priv->init_type = USB_INIT_DEVICE; priv->init_type = USB_INIT_DEVICE;

@ -7,6 +7,8 @@
#ifndef _ASM_GENERIC_GPIO_H_ #ifndef _ASM_GENERIC_GPIO_H_
#define _ASM_GENERIC_GPIO_H_ #define _ASM_GENERIC_GPIO_H_
#include <dm/ofnode.h>
struct ofnode_phandle_args; struct ofnode_phandle_args;
/* /*
@ -488,9 +490,8 @@ int gpio_get_list_count(struct udevice *dev, const char *list_name);
* This is a version of gpio_request_list_by_name() that does not use a * This is a version of gpio_request_list_by_name() that does not use a
* device. Avoid it unless the caller is not yet using driver model * device. Avoid it unless the caller is not yet using driver model
*/ */
int gpio_request_by_name_nodev(const void *blob, int node, int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,
const char *list_name, struct gpio_desc *desc, int flags);
int index, struct gpio_desc *desc, int flags);
/** /**
* gpio_request_list_by_name_nodev() - request GPIOs without a device * gpio_request_list_by_name_nodev() - request GPIOs without a device
@ -498,8 +499,7 @@ int gpio_request_by_name_nodev(const void *blob, int node,
* This is a version of gpio_request_list_by_name() that does not use a * This is a version of gpio_request_list_by_name() that does not use a
* device. Avoid it unless the caller is not yet using driver model * device. Avoid it unless the caller is not yet using driver model
*/ */
int gpio_request_list_by_name_nodev(const void *blob, int node, int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,
const char *list_name,
struct gpio_desc *desc_list, int max_count, struct gpio_desc *desc_list, int max_count,
int flags); int flags);

Loading…
Cancel
Save