diff --git a/drivers/clk/clk_bcm6345.c b/drivers/clk/clk_bcm6345.c index 91c86a9..f01ec9a 100644 --- a/drivers/clk/clk_bcm6345.c +++ b/drivers/clk/clk_bcm6345.c @@ -55,15 +55,11 @@ static const struct udevice_id bcm6345_clk_ids[] = { static int bcm63xx_clk_probe(struct udevice *dev) { struct bcm6345_clk_priv *priv = dev_get_priv(dev); - fdt_addr_t addr; - fdt_size_t size; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - return 0; } diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c index 528cf47..f8cdbd6 100644 --- a/drivers/core/fdtaddr.c +++ b/drivers/core/fdtaddr.c @@ -136,6 +136,21 @@ void *devfdt_get_addr_ptr(struct udevice *dev) return (void *)(uintptr_t)devfdt_get_addr_index(dev, 0); } +void *devfdt_remap_addr_index(struct udevice *dev, int index) +{ + fdt_addr_t addr = devfdt_get_addr(dev); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_physmem(addr, 0, MAP_NOCACHE); +} + +void *devfdt_remap_addr(struct udevice *dev) +{ + return devfdt_remap_addr_index(dev, 0); +} + void *devfdt_map_physmem(struct udevice *dev, unsigned long size) { fdt_addr_t addr = devfdt_get_addr(dev); diff --git a/drivers/core/read.c b/drivers/core/read.c index 0322cbf..96766c7 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -4,6 +4,8 @@ * Written by Simon Glass */ +#include +#include #include #include #include @@ -57,6 +59,16 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) return devfdt_get_addr_index(dev, index); } +void *dev_remap_addr_index(struct udevice *dev, int index) +{ + fdt_addr_t addr = dev_read_addr_index(dev, index); + + if (addr == FDT_ADDR_T_NONE) + return NULL; + + return map_physmem(addr, 0, MAP_NOCACHE); +} + fdt_addr_t dev_read_addr(struct udevice *dev) { return dev_read_addr_index(dev, 0); @@ -69,6 +81,11 @@ void *dev_read_addr_ptr(struct udevice *dev) return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0); } +void *dev_remap_addr(struct udevice *dev) +{ + return dev_remap_addr_index(dev, 0); +} + fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property, fdt_size_t *sizep) { diff --git a/drivers/cpu/bmips_cpu.c b/drivers/cpu/bmips_cpu.c index 7ed4bc7..f5bacd2 100644 --- a/drivers/cpu/bmips_cpu.c +++ b/drivers/cpu/bmips_cpu.c @@ -13,8 +13,6 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; - #define REV_CHIPID_SHIFT 16 #define REV_CHIPID_MASK (0xffff << REV_CHIPID_SHIFT) #define REV_LONG_CHIPID_SHIFT 12 @@ -397,8 +395,7 @@ int bmips_cpu_bind(struct udevice *dev) { struct cpu_platdata *plat = dev_get_parent_platdata(dev); - plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), - "reg", -1); + plat->cpu_id = dev_read_u32_default(dev, "reg", -1); plat->device_id = read_c0_prid(); return 0; @@ -409,14 +406,11 @@ int bmips_cpu_probe(struct udevice *dev) struct bmips_cpu_priv *priv = dev_get_priv(dev); const struct bmips_cpu_hw *hw = (const struct bmips_cpu_hw *)dev_get_driver_data(dev); - fdt_addr_t addr; - fdt_size_t size; - addr = devfdt_get_addr_size_index(dev_get_parent(dev), 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); priv->hw = hw; return 0; diff --git a/drivers/gpio/bcm6345_gpio.c b/drivers/gpio/bcm6345_gpio.c index 1a507fc..d1f6cfa 100644 --- a/drivers/gpio/bcm6345_gpio.c +++ b/drivers/gpio/bcm6345_gpio.c @@ -13,8 +13,6 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; - struct bcm6345_gpio_priv { void __iomem *reg_dirout; void __iomem *reg_data; @@ -90,22 +88,16 @@ static int bcm6345_gpio_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); struct bcm6345_gpio_priv *priv = dev_get_priv(dev); - fdt_addr_t data_addr, dirout_addr; - fdt_size_t data_size, dirout_size; - dirout_addr = devfdt_get_addr_size_index(dev, 0, &dirout_size); - if (dirout_addr == FDT_ADDR_T_NONE) + priv->reg_dirout = dev_remap_addr_index(dev, 0); + if (!priv->reg_dirout) return -EINVAL; - data_addr = devfdt_get_addr_size_index(dev, 1, &data_size); - if (data_addr == FDT_ADDR_T_NONE) + priv->reg_data = dev_remap_addr_index(dev, 1); + if (!priv->reg_data) return -EINVAL; - priv->reg_data = ioremap(data_addr, data_size); - priv->reg_dirout = ioremap(dirout_addr, dirout_size); - - uc_priv->gpio_count = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), - "ngpios", 32); + uc_priv->gpio_count = dev_read_u32_default(dev, "ngpios", 32); uc_priv->bank_name = dev->name; return 0; diff --git a/drivers/led/led_bcm6328.c b/drivers/led/led_bcm6328.c index a1bf44c..a29e5a0 100644 --- a/drivers/led/led_bcm6328.c +++ b/drivers/led/led_bcm6328.c @@ -37,8 +37,6 @@ #define LED_MODE_OFF 3 #define LED_MODE_MASK 0x3 -DECLARE_GLOBAL_DATA_PTR; - struct bcm6328_led_priv { void __iomem *regs; void __iomem *mode; @@ -149,34 +147,25 @@ static const struct led_ops bcm6328_led_ops = { static int bcm6328_led_probe(struct udevice *dev) { struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev); - fdt_addr_t addr; - fdt_size_t size; /* Top-level LED node */ if (!uc_plat->label) { void __iomem *regs; u32 set_bits = 0; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + regs = dev_remap_addr(dev); + if (!regs) return -EINVAL; - regs = ioremap(addr, size); - - if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "brcm,serial-leds")) + if (dev_read_bool(dev, "brcm,serial-leds")) set_bits |= LED_INIT_SLEDEN_MASK; - if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "brcm,serial-mux")) + if (dev_read_bool(dev, "brcm,serial-mux")) set_bits |= LED_INIT_SLEDMUX_MASK; - if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "brcm,serial-clk-low")) + if (dev_read_bool(dev, "brcm,serial-clk-low")) set_bits |= LED_INIT_SLEDCLKNPOL_MASK; - if (!fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "brcm,serial-dat-low")) + if (!dev_read_bool(dev, "brcm,serial-dat-low")) set_bits |= LED_INIT_SLEDDATANPOL_MASK; - if (!fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "brcm,serial-shift-inv")) + if (!dev_read_bool(dev, "brcm,serial-shift-inv")) set_bits |= LED_INIT_SLEDSHIFTDIR_MASK; clrsetbits_be32(regs + LED_INIT_REG, ~0, set_bits); @@ -184,17 +173,14 @@ static int bcm6328_led_probe(struct udevice *dev) struct bcm6328_led_priv *priv = dev_get_priv(dev); unsigned int pin; - addr = devfdt_get_addr_size_index(dev_get_parent(dev), 0, - &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - pin = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), "reg", - LEDS_MAX); + pin = dev_read_u32_default(dev, "reg", LEDS_MAX); if (pin >= LEDS_MAX) return -EINVAL; - priv->regs = ioremap(addr, size); if (pin < 8) { /* LEDs 0-7 (bits 47:32) */ priv->mode = priv->regs + LED_MODE_REG_HI; @@ -205,8 +191,7 @@ static int bcm6328_led_probe(struct udevice *dev) priv->shift = ((pin - 8) << 1); } - if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "active-low")) + if (dev_read_bool(dev, "active-low")) priv->active_low = true; } @@ -215,27 +200,24 @@ static int bcm6328_led_probe(struct udevice *dev) static int bcm6328_led_bind(struct udevice *parent) { - const void *blob = gd->fdt_blob; - int node; + ofnode node; - for (node = fdt_first_subnode(blob, dev_of_offset(parent)); - node > 0; - node = fdt_next_subnode(blob, node)) { + dev_for_each_subnode(node, parent) { struct led_uc_plat *uc_plat; struct udevice *dev; const char *label; int ret; - label = fdt_getprop(blob, node, "label", NULL); + label = ofnode_read_string(node, "label"); if (!label) { debug("%s: node %s has no label\n", __func__, - fdt_get_name(blob, node, NULL)); + ofnode_get_name(node)); return -EINVAL; } ret = device_bind_driver_to_node(parent, "bcm6328-led", - fdt_get_name(blob, node, NULL), - offset_to_ofnode(node), &dev); + ofnode_get_name(node), + node, &dev); if (ret) return ret; diff --git a/drivers/led/led_bcm6358.c b/drivers/led/led_bcm6358.c index 4b1c24b..01b86b7 100644 --- a/drivers/led/led_bcm6358.c +++ b/drivers/led/led_bcm6358.c @@ -31,8 +31,6 @@ #define LED_CTRL_BUSY_SHIFT 3 #define LED_CTRL_BUSY_MASK (1 << LED_CTRL_BUSY_SHIFT) -DECLARE_GLOBAL_DATA_PTR; - struct bcm6358_led_priv { void __iomem *regs; uint8_t pin; @@ -114,8 +112,6 @@ static const struct led_ops bcm6358_led_ops = { static int bcm6358_led_probe(struct udevice *dev) { struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev); - fdt_addr_t addr; - fdt_size_t size; /* Top-level LED node */ if (!uc_plat->label) { @@ -123,17 +119,14 @@ static int bcm6358_led_probe(struct udevice *dev) unsigned int clk_div; u32 set_bits = 0; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + regs = dev_remap_addr(dev); + if (!regs) return -EINVAL; - regs = ioremap(addr, size); - - if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "brcm,clk-dat-low")) + if (dev_read_bool(dev, "brcm,clk-dat-low")) set_bits |= LED_CTRL_POL_MASK; - clk_div = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), - "brcm,clk-div", LED_CTRL_CLK_1); + clk_div = dev_read_u32_default(dev, "brcm,clk-div", + LED_CTRL_CLK_1); switch (clk_div) { case 8: set_bits |= LED_CTRL_CLK_8; @@ -157,21 +150,17 @@ static int bcm6358_led_probe(struct udevice *dev) struct bcm6358_led_priv *priv = dev_get_priv(dev); unsigned int pin; - addr = devfdt_get_addr_size_index(dev_get_parent(dev), 0, - &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - pin = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), "reg", - LEDS_MAX); + pin = dev_read_u32_default(dev, "reg", LEDS_MAX); if (pin >= LEDS_MAX) return -EINVAL; - priv->regs = ioremap(addr, size); priv->pin = pin; - if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), - "active-low")) + if (dev_read_bool(dev, "active-low")) priv->active_low = true; } @@ -180,27 +169,24 @@ static int bcm6358_led_probe(struct udevice *dev) static int bcm6358_led_bind(struct udevice *parent) { - const void *blob = gd->fdt_blob; - int node; + ofnode node; - for (node = fdt_first_subnode(blob, dev_of_offset(parent)); - node > 0; - node = fdt_next_subnode(blob, node)) { + dev_for_each_subnode(node, parent) { struct led_uc_plat *uc_plat; struct udevice *dev; const char *label; int ret; - label = fdt_getprop(blob, node, "label", NULL); + label = ofnode_read_string(node, "label"); if (!label) { debug("%s: node %s has no label\n", __func__, - fdt_get_name(blob, node, NULL)); + ofnode_get_name(node)); return -EINVAL; } ret = device_bind_driver_to_node(parent, "bcm6358-led", - fdt_get_name(blob, node, NULL), - offset_to_ofnode(node), &dev); + ofnode_get_name(node), + node, &dev); if (ret) return ret; diff --git a/drivers/phy/bcm6318-usbh-phy.c b/drivers/phy/bcm6318-usbh-phy.c index f5bcf18..de055a3 100644 --- a/drivers/phy/bcm6318-usbh-phy.c +++ b/drivers/phy/bcm6318-usbh-phy.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2018 Álvaro Fernández Rojas + * Copyright (C) 2018 Álvaro Fernández Rojas * * Derived from linux/arch/mips/bcm63xx/usb-common.c: * Copyright 2008 Maxime Bizon @@ -79,16 +79,12 @@ static int bcm6318_usbh_probe(struct udevice *dev) struct power_domain pwr_dom; struct reset_ctl rst_ctl; struct clk clk; - fdt_addr_t addr; - fdt_size_t size; int ret; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - /* enable usbh clock */ ret = clk_get_by_name(dev, "usbh", &clk); if (ret < 0) diff --git a/drivers/phy/bcm6348-usbh-phy.c b/drivers/phy/bcm6348-usbh-phy.c index f305738..e7761e3 100644 --- a/drivers/phy/bcm6348-usbh-phy.c +++ b/drivers/phy/bcm6348-usbh-phy.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2018 Álvaro Fernández Rojas + * Copyright (C) 2018 Álvaro Fernández Rojas * * Derived from linux/arch/mips/bcm63xx/usb-common.c: * Copyright 2008 Maxime Bizon @@ -44,16 +44,12 @@ static int bcm6348_usbh_probe(struct udevice *dev) struct bcm6348_usbh_priv *priv = dev_get_priv(dev); struct reset_ctl rst_ctl; struct clk clk; - fdt_addr_t addr; - fdt_size_t size; int ret; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - /* enable usbh clock */ ret = clk_get_by_name(dev, "usbh", &clk); if (ret < 0) diff --git a/drivers/phy/bcm6358-usbh-phy.c b/drivers/phy/bcm6358-usbh-phy.c index 9eb641a..189a1c1 100644 --- a/drivers/phy/bcm6358-usbh-phy.c +++ b/drivers/phy/bcm6358-usbh-phy.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2018 Álvaro Fernández Rojas + * Copyright (C) 2018 Álvaro Fernández Rojas * * Derived from linux/arch/mips/bcm63xx/usb-common.c: * Copyright 2008 Maxime Bizon @@ -57,16 +57,12 @@ static int bcm6358_usbh_probe(struct udevice *dev) { struct bcm6358_usbh_priv *priv = dev_get_priv(dev); struct reset_ctl rst_ctl; - fdt_addr_t addr; - fdt_size_t size; int ret; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - /* perform reset */ ret = reset_get_by_index(dev, 0, &rst_ctl); if (ret < 0) diff --git a/drivers/phy/bcm6368-usbh-phy.c b/drivers/phy/bcm6368-usbh-phy.c index 02197ed..99da97a 100644 --- a/drivers/phy/bcm6368-usbh-phy.c +++ b/drivers/phy/bcm6368-usbh-phy.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ /* - * Copyright (C) 2018 Álvaro Fernández Rojas + * Copyright (C) 2018 Álvaro Fernández Rojas * * Derived from linux/arch/mips/bcm63xx/usb-common.c: * Copyright 2008 Maxime Bizon @@ -116,15 +116,12 @@ static int bcm6368_usbh_probe(struct udevice *dev) #endif struct reset_ctl rst_ctl; struct clk clk; - fdt_addr_t addr; - fdt_size_t size; int ret; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); priv->hw = hw; /* enable usbh clock */ diff --git a/drivers/power/domain/bcm6328-power-domain.c b/drivers/power/domain/bcm6328-power-domain.c index f9276e6..a90b2c8 100644 --- a/drivers/power/domain/bcm6328-power-domain.c +++ b/drivers/power/domain/bcm6328-power-domain.c @@ -48,15 +48,11 @@ static int bcm6328_power_domain_off(struct power_domain *power_domain) static int bcm6328_power_domain_probe(struct udevice *dev) { struct bcm6328_power_domain *priv = dev_get_priv(dev); - fdt_addr_t addr; - fdt_size_t size; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - return 0; } diff --git a/drivers/ram/bmips_ram.c b/drivers/ram/bmips_ram.c index ad2f0ac..cc37dfa 100644 --- a/drivers/ram/bmips_ram.c +++ b/drivers/ram/bmips_ram.c @@ -150,14 +150,11 @@ static int bmips_ram_probe(struct udevice *dev) struct bmips_ram_priv *priv = dev_get_priv(dev); const struct bmips_ram_hw *hw = (const struct bmips_ram_hw *)dev_get_driver_data(dev); - fdt_addr_t addr; - fdt_size_t size; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); priv->hw = hw; return 0; diff --git a/drivers/reset/reset-bcm6345.c b/drivers/reset/reset-bcm6345.c index 62b9563..753c110 100644 --- a/drivers/reset/reset-bcm6345.c +++ b/drivers/reset/reset-bcm6345.c @@ -66,15 +66,11 @@ static const struct udevice_id bcm6345_reset_ids[] = { static int bcm6345_reset_probe(struct udevice *dev) { struct bcm6345_reset_priv *priv = dev_get_priv(dev); - fdt_addr_t addr; - fdt_size_t size; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - return 0; } diff --git a/drivers/serial/serial_bcm6345.c b/drivers/serial/serial_bcm6345.c index 8838c41..ee5d561 100644 --- a/drivers/serial/serial_bcm6345.c +++ b/drivers/serial/serial_bcm6345.c @@ -227,17 +227,13 @@ static int bcm6345_serial_probe(struct udevice *dev) { struct bcm6345_serial_priv *priv = dev_get_priv(dev); struct clk clk; - fdt_addr_t addr; - fdt_size_t size; int ret; /* get address */ - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->base = dev_remap_addr(dev); + if (!priv->base) return -EINVAL; - priv->base = ioremap(addr, size); - /* get clock rate */ ret = clk_get_by_index(dev, 0, &clk); if (ret < 0) diff --git a/drivers/spi/bcm63xx_hsspi.c b/drivers/spi/bcm63xx_hsspi.c index 262ed62..4f527fa7 100644 --- a/drivers/spi/bcm63xx_hsspi.c +++ b/drivers/spi/bcm63xx_hsspi.c @@ -15,8 +15,6 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; - #define HSSPI_PP 0 #define SPI_MAX_SYNC_CLOCK 30000000 @@ -337,17 +335,13 @@ static int bcm63xx_hsspi_probe(struct udevice *dev) struct bcm63xx_hsspi_priv *priv = dev_get_priv(dev); struct reset_ctl rst_ctl; struct clk clk; - fdt_addr_t addr; - fdt_size_t size; int ret; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - priv->num_cs = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), - "num-cs", 8); + priv->num_cs = dev_read_u32_default(dev, "num-cs", 8); /* enable clock */ ret = clk_get_by_name(dev, "hsspi", &clk); diff --git a/drivers/spi/bcm63xx_spi.c b/drivers/spi/bcm63xx_spi.c index 473f002..4d19e03 100644 --- a/drivers/spi/bcm63xx_spi.c +++ b/drivers/spi/bcm63xx_spi.c @@ -15,8 +15,6 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; - /* BCM6348 SPI core */ #define SPI_6348_CLK 0x06 #define SPI_6348_CMD 0x00 @@ -373,18 +371,14 @@ static int bcm63xx_spi_probe(struct udevice *dev) (const unsigned long *)dev_get_driver_data(dev); struct reset_ctl rst_ctl; struct clk clk; - fdt_addr_t addr; - fdt_size_t size; int ret; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->base = dev_remap_addr(dev); + if (!priv->base) return -EINVAL; priv->regs = regs; - priv->base = ioremap(addr, size); - priv->num_cs = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev), - "num-cs", 8); + priv->num_cs = dev_read_u32_default(dev, "num-cs", 8); /* enable clock */ ret = clk_get_by_index(dev, 0, &clk); diff --git a/drivers/watchdog/bcm6345_wdt.c b/drivers/watchdog/bcm6345_wdt.c index 54b02fa..e1bd73d 100644 --- a/drivers/watchdog/bcm6345_wdt.c +++ b/drivers/watchdog/bcm6345_wdt.c @@ -85,15 +85,11 @@ static const struct udevice_id bcm6345_wdt_ids[] = { static int bcm6345_wdt_probe(struct udevice *dev) { struct bcm6345_wdt_priv *priv = dev_get_priv(dev); - fdt_addr_t addr; - fdt_size_t size; - addr = devfdt_get_addr_size_index(dev, 0, &size); - if (addr == FDT_ADDR_T_NONE) + priv->regs = dev_remap_addr(dev); + if (!priv->regs) return -EINVAL; - priv->regs = ioremap(addr, size); - bcm6345_wdt_stop(dev); return 0; diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index db4c11e..49a6ffd 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -34,6 +34,28 @@ fdt_addr_t devfdt_get_addr(struct udevice *dev); void *devfdt_get_addr_ptr(struct udevice *dev); /** + * devfdt_remap_addr() - Return pointer to the memory-mapped I/O address + * of the reg property of a device + * + * @dev: Pointer to a device + * + * @return Pointer to addr, or NULL if there is no such property + */ +void *devfdt_remap_addr(struct udevice *dev); + +/** + * devfdt_remap_addr_index() - Return indexed pointer to the memory-mapped + * I/O address of the reg property of a device + * @index: the 'reg' property can hold a list of pairs + * and @index is used to select which one is required + * + * @dev: Pointer to a device + * + * @return Pointer to addr, or NULL if there is no such property + */ +void *devfdt_remap_addr_index(struct udevice *dev, int index); + +/** * devfdt_map_physmem() - Read device address from reg property of the * device node and map the address into CPU address * space. diff --git a/include/dm/read.h b/include/dm/read.h index 4a725bc..a27b855 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -113,6 +113,18 @@ int dev_read_size(struct udevice *dev, const char *propname); fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); /** + * dev_remap_addr_index() - Get the indexed reg property of a device + * as a memory-mapped I/O pointer + * + * @dev: Device to read from + * @index: the 'reg' property can hold a list of pairs + * and @index is used to select which one is required + * + * @return pointer or NULL if not found + */ +void *dev_remap_addr_index(struct udevice *dev, int index); + +/** * dev_read_addr() - Get the reg property of a device * * @dev: Device to read from @@ -132,6 +144,16 @@ fdt_addr_t dev_read_addr(struct udevice *dev); void *dev_read_addr_ptr(struct udevice *dev); /** + * dev_remap_addr() - Get the reg property of a device as a + * memory-mapped I/O pointer + * + * @dev: Device to read from + * + * @return pointer or NULL if not found + */ +void *dev_remap_addr(struct udevice *dev); + +/** * dev_read_addr_size() - get address and size from a device property * * This does no address translation. It simply reads an property that contains @@ -482,6 +504,16 @@ static inline void *dev_read_addr_ptr(struct udevice *dev) return devfdt_get_addr_ptr(dev); } +static inline void *dev_remap_addr(struct udevice *dev) +{ + return devfdt_remap_addr(dev); +} + +static inline void *dev_remap_addr_index(struct udevice *dev, int index) +{ + return devfdt_remap_addr_index(dev, index); +} + static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, fdt_size_t *sizep) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 66d0df5..8b72fe4 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -461,3 +461,45 @@ static int dm_test_fdt_translation(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test devfdt_remap_addr_index() */ +static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = devfdt_get_addr(dev); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, devfdt_remap_addr(dev)); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_flat, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); + +/* Test dev_remap_addr_index() */ +static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts) +{ + struct udevice *dev; + fdt_addr_t addr; + void *paddr; + + ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev)); + + addr = dev_read_addr(dev); + ut_asserteq(0x8000, addr); + + paddr = map_physmem(addr, 0, MAP_NOCACHE); + ut_assertnonnull(paddr); + ut_asserteq_ptr(paddr, dev_remap_addr(dev)); + + return 0; +} +DM_TEST(dm_test_fdt_remap_addr_live, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);