treewide: convert (void *)devfdt_get_addr() to dev_read_addr_ptr()

Use the _ptr suffixed variant instead of casting. Also, convert it to
dev_read_addr_ptr(), which is safe to CONFIG_OF_LIVE.

One curious part is an error check like follows in
drivers/watchdog/omap_wdt.c:

    priv->regs = (struct wd_timer *)devfdt_get_addr(dev);
    if (!priv->regs)
            return -EINVAL;

devfdt_get_addr() returns FDT_ADDR_T_NONE (i.e. -1) on error.
So, this code does not catch any error in DT parsing.

dev_read_addr_ptr() returns NULL on error, so this error check
will work.

I generated this commit by the following command:

 $ find . -name .git -prune -o -name '*.[ch]' -type f -print | \
   xargs sed -i -e 's/([^*)]*\*)devfdt_get_addr(/dev_read_addr_ptr(/'

I manually fixed drivers/usb/host/ehci-mx6.c

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
Masahiro Yamada 2020-07-17 14:36:46 +09:00 committed by Simon Glass
parent 7d8073e7cf
commit 8613c8d897
46 changed files with 47 additions and 47 deletions

View File

@ -106,7 +106,7 @@ int exynos_adc_ofdata_to_platdata(struct udevice *dev)
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
struct exynos_adc_priv *priv = dev_get_priv(dev);
priv->regs = (struct exynos_adc_v2 *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
if (priv->regs == (struct exynos_adc_v2 *)FDT_ADDR_T_NONE) {
pr_err("Dev: %s - can't get address!", dev->name);
return -ENODATA;

View File

@ -283,7 +283,7 @@ int gen2_clk_probe(struct udevice *dev)
u32 cpg_mode;
int ret;
priv->base = (struct gen2_base *)devfdt_get_addr(dev);
priv->base = dev_read_addr_ptr(dev);
if (!priv->base)
return -EINVAL;

View File

@ -359,7 +359,7 @@ int gen3_clk_probe(struct udevice *dev)
u32 cpg_mode;
int ret;
priv->base = (struct gen3_base *)devfdt_get_addr(dev);
priv->base = dev_read_addr_ptr(dev);
if (!priv->base)
return -EINVAL;

View File

@ -148,7 +148,7 @@ static int rcar_gpio_probe(struct udevice *dev)
int node = dev_of_offset(dev);
int ret;
priv->regs = (void __iomem *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
uc_priv->bank_name = dev->name;
ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, node, "gpio-ranges",

View File

@ -90,7 +90,7 @@ static int mvebu_gpio_probe(struct udevice *dev)
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct mvebu_gpio_priv *priv = dev_get_priv(dev);
priv->regs = (struct mvebu_gpio_regs *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
uc_priv->gpio_count = MVEBU_GPIOS_PER_BANK;
priv->name[0] = 'A' + dev->req_seq;
uc_priv->bank_name = priv->name;

View File

@ -316,7 +316,7 @@ static int gpio_exynos_bind(struct udevice *parent)
if (plat)
return 0;
base = (struct s5p_gpio_bank *)devfdt_get_addr(parent);
base = dev_read_addr_ptr(parent);
for (node = fdt_first_subnode(blob, dev_of_offset(parent)), bank = base;
node > 0;
node = fdt_next_subnode(blob, node), bank++) {

View File

@ -293,7 +293,7 @@ static int gpio_sunxi_bind(struct udevice *parent)
if (plat)
return 0;
ctlr = (struct sunxi_gpio_reg *)devfdt_get_addr(parent);
ctlr = dev_read_addr_ptr(parent);
for (bank = 0; bank < soc_data->no_banks; bank++) {
struct sunxi_gpio_platdata *plat;
struct udevice *dev;

View File

@ -225,7 +225,7 @@ static int at91_i2c_ofdata_to_platdata(struct udevice *dev)
struct at91_i2c_bus *bus = dev_get_priv(dev);
int node = dev_of_offset(dev);
bus->regs = (struct at91_i2c_regs *)devfdt_get_addr(dev);
bus->regs = dev_read_addr_ptr(dev);
bus->pdata = (struct at91_i2c_pdata *)dev_get_driver_data(dev);
bus->clock_frequency = fdtdec_get_int(blob, node,
"clock-frequency", 100000);

View File

@ -471,7 +471,7 @@ static int davinci_i2c_probe(struct udevice *dev)
struct i2c_bus *i2c_bus = dev_get_priv(dev);
i2c_bus->id = dev->seq;
i2c_bus->regs = (struct i2c_regs *)devfdt_get_addr(dev);
i2c_bus->regs = dev_read_addr_ptr(dev);
i2c_bus->speed = 100000;
_davinci_i2c_init(i2c_bus->regs, i2c_bus->speed, 0);

View File

@ -525,7 +525,7 @@ static int s3c_i2c_ofdata_to_platdata(struct udevice *dev)
node = dev_of_offset(dev);
i2c_bus->hsregs = (struct exynos5_hsi2c *)devfdt_get_addr(dev);
i2c_bus->hsregs = dev_read_addr_ptr(dev);
i2c_bus->id = pinmux_decode_periph_id(blob, node);

View File

@ -310,7 +310,7 @@ static int s3c_i2c_ofdata_to_platdata(struct udevice *dev)
node = dev_of_offset(dev);
i2c_bus->regs = (struct s3c24x0_i2c *)devfdt_get_addr(dev);
i2c_bus->regs = dev_read_addr_ptr(dev);
i2c_bus->id = pinmux_decode_periph_id(blob, node);

View File

@ -291,7 +291,7 @@ static int tegra_kbd_probe(struct udevice *dev)
struct input_config *input = &uc_priv->input;
int ret;
priv->kbc = (struct kbc_tegra *)devfdt_get_addr(dev);
priv->kbc = dev_read_addr_ptr(dev);
if ((fdt_addr_t)priv->kbc == FDT_ADDR_T_NONE) {
debug("%s: No keyboard register found\n", __func__);
return -EINVAL;

View File

@ -34,7 +34,7 @@ static int aspeed_sdhci_probe(struct udevice *dev)
goto free;
host->name = dev->name;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
max_clk = clk_get_rate(&clk);
if (IS_ERR_VALUE(max_clk)) {

View File

@ -69,7 +69,7 @@ static int atmel_sdhci_probe(struct udevice *dev)
return ret;
host->name = dev->name;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),

View File

@ -395,7 +395,7 @@ static int ftsdc010_mmc_ofdata_to_platdata(struct udevice *dev)
struct ftsdc_priv *priv = dev_get_priv(dev);
struct ftsdc010_chip *chip = &priv->chip;
chip->name = dev->name;
chip->ioaddr = (void *)devfdt_get_addr(dev);
chip->ioaddr = dev_read_addr_ptr(dev);
chip->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"bus-width", 4);
chip->priv = dev;

View File

@ -33,7 +33,7 @@ static int hi6220_dwmmc_ofdata_to_platdata(struct udevice *dev)
struct dwmci_host *host = &priv->host;
host->name = dev->name;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"bus-width", 4);

View File

@ -188,7 +188,7 @@ static int iproc_sdhci_probe(struct udevice *dev)
iproc_host->shadow_blk = 0;
host->name = dev->name;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->voltages = MMC_VDD_165_195 |
MMC_VDD_32_33 | MMC_VDD_33_34;
host->quirks = SDHCI_QUIRK_BROKEN_VOLTAGE | SDHCI_QUIRK_BROKEN_R1B;

View File

@ -171,7 +171,7 @@ static int msm_ofdata_to_platdata(struct udevice *dev)
int node = dev_of_offset(dev);
host->name = strdup(dev->name);
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->bus_width = fdtdec_get_int(gd->fdt_blob, node, "bus-width", 4);
host->index = fdtdec_get_uint(gd->fdt_blob, node, "index", 0);
priv->base = (void *)fdtdec_get_addr_size_auto_parent(gd->fdt_blob,

View File

@ -112,7 +112,7 @@ static int mv_sdhci_probe(struct udevice *dev)
int ret;
host->name = MVSDH_NAME;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD;
host->mmc = &plat->mmc;
host->mmc->dev = dev;

View File

@ -109,7 +109,7 @@ static int socfpga_dwmmc_ofdata_to_platdata(struct udevice *dev)
}
host->name = dev->name;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->buswidth = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"bus-width", 4);
host->clksel = socfpga_dwmci_clksel;

View File

@ -116,7 +116,7 @@ static int sti_sdhci_ofdata_to_platdata(struct udevice *dev)
struct sdhci_host *host = dev_get_priv(dev);
host->name = strdup(dev->name);
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"bus-width", 4);

View File

@ -455,7 +455,7 @@ static int xenon_sdhci_ofdata_to_platdata(struct udevice *dev)
const char *name;
host->name = dev->name;
host->ioaddr = (void *)devfdt_get_addr(dev);
host->ioaddr = dev_read_addr_ptr(dev);
if (device_is_compatible(dev, "marvell,armada-3700-sdhci"))
priv->pad_ctrl_reg = (void *)devfdt_get_addr_index(dev, 1);

View File

@ -144,7 +144,7 @@ static int cdns_pci_ep_probe(struct udevice *dev)
{
struct cdns_pcie *pdata = dev_get_priv(dev);
pdata->reg_base = (void __iomem *)devfdt_get_addr(dev);
pdata->reg_base = dev_read_addr_ptr(dev);
if (!pdata->reg_base)
return -ENOMEM;

View File

@ -592,7 +592,7 @@ int armada_37xx_pinctrl_probe(struct udevice *dev)
info->data = (struct armada_37xx_pin_data *)dev_get_driver_data(dev);
pin_data = info->data;
info->base = (void __iomem *)devfdt_get_addr(dev);
info->base = dev_read_addr_ptr(dev);
if (!info->base) {
pr_err("unable to find regmap\n");
return -ENODEV;

View File

@ -92,7 +92,7 @@ static int exynos_pwm_ofdata_to_platdata(struct udevice *dev)
{
struct exynos_pwm_priv *priv = dev_get_priv(dev);
priv->regs = (struct s5p_timer *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
return 0;
}

View File

@ -130,7 +130,7 @@ static int imx_pwm_ofdata_to_platdata(struct udevice *dev)
{
struct imx_pwm_priv *priv = dev_get_priv(dev);
priv->regs = (struct pwm_regs *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
return 0;
}

View File

@ -130,7 +130,7 @@ static int mtk_pwm_probe(struct udevice *dev)
int i;
priv->soc = (struct mtk_pwm_soc *)dev_get_driver_data(dev);
priv->base = (void __iomem *)devfdt_get_addr(dev);
priv->base = dev_read_addr_ptr(dev);
if (!priv->base)
return -EINVAL;
ret = clk_get_by_name(dev, "top", &priv->top_clk);

View File

@ -152,7 +152,7 @@ static int sunxi_pwm_ofdata_to_platdata(struct udevice *dev)
{
struct sunxi_pwm_priv *priv = dev_get_priv(dev);
priv->regs = (struct sunxi_pwm *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
return 0;
}

View File

@ -114,7 +114,7 @@ static int arc_serial_ofdata_to_platdata(struct udevice *dev)
struct arc_serial_platdata *plat = dev_get_platdata(dev);
DECLARE_GLOBAL_DATA_PTR;
plat->reg = (struct arc_serial_regs *)devfdt_get_addr(dev);
plat->reg = dev_read_addr_ptr(dev);
plat->uartclk = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"clock-frequency", 0);

View File

@ -85,7 +85,7 @@ static int uartlite_serial_ofdata_to_platdata(struct udevice *dev)
{
struct uartlite_platdata *plat = dev_get_platdata(dev);
plat->regs = (struct uartlite *)devfdt_get_addr(dev);
plat->regs = dev_read_addr_ptr(dev);
return 0;
}

View File

@ -351,7 +351,7 @@ static int atmel_spi_probe(struct udevice *bus)
if (ret)
return ret;
bus_plat->regs = (struct at91_spi *)devfdt_get_addr(bus);
bus_plat->regs = dev_read_addr_ptr(bus);
#if CONFIG_IS_ENABLED(DM_GPIO)
struct atmel_spi_priv *priv = dev_get_priv(bus);

View File

@ -157,7 +157,7 @@ static int dw_spi_ofdata_to_platdata(struct udevice *bus)
{
struct dw_spi_platdata *plat = bus->platdata;
plat->regs = (struct dw_spi *)devfdt_get_addr(bus);
plat->regs = dev_read_addr_ptr(bus);
/* Use 500KHz as a suitable default */
plat->frequency = dev_read_u32_default(bus, "spi-max-frequency",

View File

@ -257,7 +257,7 @@ static int exynos_spi_ofdata_to_platdata(struct udevice *bus)
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
plat->regs = (struct exynos_spi *)devfdt_get_addr(bus);
plat->regs = dev_read_addr_ptr(bus);
plat->periph_id = pinmux_decode_periph_id(blob, node);
if (plat->periph_id == PERIPH_ID_NONE) {

View File

@ -236,7 +236,7 @@ static int mvebu_spi_ofdata_to_platdata(struct udevice *bus)
const struct mvebu_spi_dev *drvdata =
(struct mvebu_spi_dev *)dev_get_driver_data(bus);
plat->spireg = (struct kwspi_registers *)devfdt_get_addr(bus);
plat->spireg = dev_read_addr_ptr(bus);
plat->is_errata_50mhz_ac = drvdata->is_errata_50mhz_ac;
return 0;

View File

@ -253,7 +253,7 @@ static int mtk_snfi_spi_probe(struct udevice *bus)
struct mtk_snfi_priv *priv = dev_get_priv(bus);
int ret;
priv->base = (void __iomem *)devfdt_get_addr(bus);
priv->base = dev_read_addr_ptr(bus);
if (!priv->base)
return -EINVAL;

View File

@ -255,7 +255,7 @@ static int mvebu_spi_ofdata_to_platdata(struct udevice *bus)
struct mvebu_spi_platdata *plat = dev_get_platdata(bus);
int ret;
plat->spireg = (struct spi_reg *)devfdt_get_addr(bus);
plat->spireg = dev_read_addr_ptr(bus);
ret = clk_get_by_index(bus, 0, &plat->clk);
if (ret) {

View File

@ -77,7 +77,7 @@ static int zynq_spi_ofdata_to_platdata(struct udevice *bus)
const void *blob = gd->fdt_blob;
int node = dev_of_offset(bus);
plat->regs = (struct zynq_spi_regs *)devfdt_get_addr(bus);
plat->regs = dev_read_addr_ptr(bus);
/* FIXME: Use 250MHz as a suitable default */
plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",

View File

@ -306,7 +306,7 @@ static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
static int ehci_usb_probe(struct udevice *dev)
{
struct usb_platdata *plat = dev_get_platdata(dev);
struct usb_ehci *ehci = (struct usb_ehci *)devfdt_get_addr(dev);
struct usb_ehci *ehci = dev_read_addr_ptr(dev);
struct ehci_mx5_priv_data *priv = dev_get_priv(dev);
enum usb_init_type type = plat->init_type;
struct ehci_hccr *hccr;

View File

@ -473,7 +473,7 @@ static const struct ehci_ops mx6_ehci_ops = {
static int ehci_usb_phy_mode(struct udevice *dev)
{
struct usb_platdata *plat = dev_get_platdata(dev);
void *__iomem addr = (void *__iomem)devfdt_get_addr(dev);
void *__iomem addr = dev_read_addr_ptr(dev);
void *__iomem phy_ctrl, *__iomem phy_status;
const void *blob = gd->fdt_blob;
int offset = dev_of_offset(dev), phy_off;
@ -580,7 +580,7 @@ static int ehci_usb_bind(struct udevice *dev)
static int ehci_usb_probe(struct udevice *dev)
{
struct usb_platdata *plat = dev_get_platdata(dev);
struct usb_ehci *ehci = (struct usb_ehci *)devfdt_get_addr(dev);
struct usb_ehci *ehci = dev_read_addr_ptr(dev);
struct ehci_mx6_priv_data *priv = dev_get_priv(dev);
enum usb_init_type type = plat->init_type;
struct ehci_hccr *hccr;

View File

@ -382,7 +382,7 @@ static int omap_ehci_probe(struct udevice *dev)
struct ehci_hccr *hccr;
struct ehci_hcor *hcor;
priv->ehci = (struct omap_ehci *)devfdt_get_addr(dev);
priv->ehci = dev_read_addr_ptr(dev);
priv->portnr = dev->seq;
priv->init_type = plat->init_type;

View File

@ -224,7 +224,7 @@ static int vf_usb_ofdata_to_platdata(struct udevice *dev)
priv->portnr = dev->seq;
priv->ehci = (struct usb_ehci *)devfdt_get_addr(dev);
priv->ehci = dev_read_addr_ptr(dev);
mode = fdt_getprop(dt_blob, node, "dr_mode", NULL);
if (mode) {
if (0 == strcmp(mode, "host")) {

View File

@ -89,7 +89,7 @@ int usb_cpu_init_fail(void)
#if CONFIG_IS_ENABLED(DM_USB)
static int ohci_da8xx_probe(struct udevice *dev)
{
struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev);
struct ohci_regs *regs = dev_read_addr_ptr(dev);
struct da8xx_ohci *priv = dev_get_priv(dev);
int i, err, ret, clock_nb;

View File

@ -79,7 +79,7 @@ static int ohci_shutdown_phy(struct udevice *dev)
static int ohci_usb_probe(struct udevice *dev)
{
struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev);
struct ohci_regs *regs = dev_read_addr_ptr(dev);
struct generic_ohci *priv = dev_get_priv(dev);
int i, err, ret, clock_nb, reset_nb;

View File

@ -507,7 +507,7 @@ static int atmel_hlcdc_ofdata_to_platdata(struct udevice *dev)
const void *blob = gd->fdt_blob;
int node = dev_of_offset(dev);
priv->regs = (struct atmel_hlcd_regs *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
if (!priv->regs) {
debug("%s: No display controller address\n", __func__);
return -EINVAL;

View File

@ -346,7 +346,7 @@ static int tegra_lcd_ofdata_to_platdata(struct udevice *dev)
int rgb;
int ret;
priv->disp = (struct disp_ctlr *)devfdt_get_addr(dev);
priv->disp = dev_read_addr_ptr(dev);
if (!priv->disp) {
debug("%s: No display controller address\n", __func__);
return -EINVAL;

View File

@ -237,7 +237,7 @@ static int omap3_wdt_probe(struct udevice *dev)
{
struct omap3_wdt_priv *priv = dev_get_priv(dev);
priv->regs = (struct wd_timer *)devfdt_get_addr(dev);
priv->regs = dev_read_addr_ptr(dev);
if (!priv->regs)
return -EINVAL;