Skip to content

Commit

Permalink
dm: core: Replace of_offset with accessor
Browse files Browse the repository at this point in the history
At present devices use a simple integer offset to record the device tree
node associated with the device. In preparation for supporting a live
device tree, which uses a node pointer instead, refactor existing code to
access this field through an inline function.

Signed-off-by: Simon Glass <[email protected]>
  • Loading branch information
sjg20 committed Feb 8, 2017
1 parent 8aa4136 commit e160f7d
Show file tree
Hide file tree
Showing 220 changed files with 445 additions and 407 deletions.
2 changes: 1 addition & 1 deletion arch/arm/mach-aspeed/ast2500/sdram_ast2500.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int ast2500_sdrammc_ofdata_to_platdata(struct udevice *dev)
priv->regs = regmap_get_range(map, 0);
priv->phy = regmap_get_range(map, 1);

priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"clock-frequency", 0);

if (!priv->clock_rate) {
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ static int rk3288_dmc_ofdata_to_platdata(struct udevice *dev)
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
struct rk3288_sdram_params *params = dev_get_platdata(dev);
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int node = dev_of_offset(dev);
int ret;

/* Rk3288 supports dual-channel, set default channel num to 2 */
Expand Down
2 changes: 1 addition & 1 deletion arch/nios2/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int altera_nios2_get_count(struct udevice *dev)
static int altera_nios2_probe(struct udevice *dev)
{
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int node = dev_of_offset(dev);

gd->cpu_clk = fdtdec_get_int(blob, node,
"clock-frequency", 0);
Expand Down
10 changes: 5 additions & 5 deletions arch/x86/cpu/broadwell/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ static void initialize_vr_config(struct udevice *dev)
/* Set the slow ramp rate */
msr.hi &= ~(0x3 << (53 - 32));
/* Configure the C-state exit ramp rate */
ramp = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "intel,slow-ramp",
-1);
ramp = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"intel,slow-ramp", -1);
if (ramp != -1) {
/* Configured slow ramp rate */
msr.hi |= ((ramp & 0x3) << (53 - 32));
Expand All @@ -271,8 +271,8 @@ static void initialize_vr_config(struct udevice *dev)
}
/* Set MIN_VID (31:24) to allow CPU to have full control */
msr.lo &= ~0xff000000;
min_vid = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "intel,min-vid",
0);
min_vid = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"intel,min-vid", 0);
msr.lo |= (min_vid & 0xff) << 24;
msr_write(MSR_VR_MISC_CONFIG, msr);

Expand Down Expand Up @@ -562,7 +562,7 @@ static void configure_thermal_target(struct udevice *dev)
int tcc_offset;
msr_t msr;

tcc_offset = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
tcc_offset = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"intel,tcc-offset", 0);

/* Set TCC activaiton offset if supported */
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/cpu/broadwell/pch.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ static int pch_power_options(struct udevice *dev)
debug("Set power %s after power failure.\n", state);

/* GPE setup based on device tree configuration */
ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
"intel,gpe0-en", enable, ARRAY_SIZE(enable));
if (ret)
return -EINVAL;
enable_all_gpe(enable[0], enable[1], enable[2], enable[3]);

/* SMI setup based on device tree configuration */
enable_alt_smi(dev, fdtdec_get_int(gd->fdt_blob, dev->of_offset,
enable_alt_smi(dev, fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"intel,alt-gp-smi-enable", 0));

return 0;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/cpu/broadwell/pinctrl_broadwell.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static int broadwell_pinctrl_read_configs(struct udevice *dev,
int node;

debug("%s: starting\n", __func__);
for (node = fdt_first_subnode(blob, dev->of_offset);
for (node = fdt_first_subnode(blob, dev_of_offset(dev));
node > 0;
node = fdt_next_subnode(blob, node)) {
int phandle = fdt_get_phandle(blob, node);
Expand Down Expand Up @@ -115,7 +115,7 @@ static int broadwell_pinctrl_read_pins(struct udevice *dev,
int count = 0;
int node;

for (node = fdt_first_subnode(blob, dev->of_offset);
for (node = fdt_first_subnode(blob, dev_of_offset(dev));
node > 0;
node = fdt_next_subnode(blob, node)) {
int len, i;
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/cpu/broadwell/sata.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static int broadwell_sata_ofdata_to_platdata(struct udevice *dev)
{
struct sata_platdata *plat = dev_get_platdata(dev);
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int node = dev_of_offset(dev);

plat->port_map = fdtdec_get_int(blob, node, "intel,sata-port-map", 0);
plat->port0_gen3_tx = fdtdec_get_int(blob, node,
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/cpu/cpu_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int cpu_x86_bind(struct udevice *dev)
struct cpu_platdata *plat = dev_get_parent_platdata(dev);
struct cpuid_result res;

plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
plat->cpu_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"intel,apic-id", -1);
plat->family = gd->arch.x86;
res = cpuid(1);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/cpu/intel_common/lpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int lpc_common_early_init(struct udevice *dev)
int count;
int i;

count = fdtdec_get_int_array_count(gd->fdt_blob, dev->of_offset,
count = fdtdec_get_int_array_count(gd->fdt_blob, dev_of_offset(dev),
"intel,gen-dec", (u32 *)values,
sizeof(values) / sizeof(u32));
if (count < 0)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/cpu/intel_common/mrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int mrc_locate_spd(struct udevice *dev, int size, const void **spd_datap)
spd_index = dm_gpio_get_values_as_int(desc, ret);
debug("spd index %d\n", spd_index);

node = fdt_first_subnode(blob, dev->of_offset);
node = fdt_first_subnode(blob, dev_of_offset(dev));
if (node < 0)
return -EINVAL;
for (spd_node = fdt_first_subnode(blob, node);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/cpu/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static int create_pirq_routing_table(struct udevice *dev)
int i;
int ret;

node = dev->of_offset;
node = dev_of_offset(dev);

/* extract the bdf from fdt_pci_addr */
priv->bdf = dm_pci_get_bdf(dev->parent);
Expand Down
6 changes: 3 additions & 3 deletions arch/x86/cpu/ivybridge/lpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int pch_pirq_init(struct udevice *pch)
{
uint8_t route[8], *ptr;

if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
if (fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(pch),
"intel,pirq-routing", route, sizeof(route)))
return -EINVAL;
ptr = route;
Expand All @@ -113,7 +113,7 @@ static int pch_gpi_routing(struct udevice *pch)
u32 reg;
int gpi;

if (fdtdec_get_byte_array(gd->fdt_blob, pch->of_offset,
if (fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(pch),
"intel,gpi-routing", route, sizeof(route)))
return -EINVAL;

Expand All @@ -128,7 +128,7 @@ static int pch_gpi_routing(struct udevice *pch)
static int pch_power_options(struct udevice *pch)
{
const void *blob = gd->fdt_blob;
int node = pch->of_offset;
int node = dev_of_offset(pch);
u8 reg8;
u16 reg16, pmbase;
u32 reg32;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/cpu/ivybridge/model_206ax.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ static int configure_thermal_target(struct udevice *dev)
int tcc_offset;
msr_t msr;

tcc_offset = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "tcc-offset",
0);
tcc_offset = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"tcc-offset", 0);

/* Set TCC activaiton offset if supported */
msr = msr_read(MSR_PLATFORM_INFO);
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/cpu/ivybridge/sata.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void bd82x6x_sata_init(struct udevice *dev, struct udevice *pch)
{
unsigned int port_map, speed_support, port_tx;
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int node = dev_of_offset(dev);
const char *mode;
u32 reg32;
u16 reg16;
Expand Down Expand Up @@ -190,7 +190,7 @@ static void bd82x6x_sata_init(struct udevice *dev, struct udevice *pch)
static void bd82x6x_sata_enable(struct udevice *dev)
{
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int node = dev_of_offset(dev);
unsigned port_map;
const char *mode;
u16 map = 0;
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/cpu/mp_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ int mp_init_cpu(struct udevice *cpu, void *unused)
* seq num in the uclass_resolve_seq() during device_probe(). To avoid
* this, set req_seq to the reg number in the device tree in advance.
*/
cpu->req_seq = fdtdec_get_int(gd->fdt_blob, cpu->of_offset, "reg", -1);
cpu->req_seq = fdtdec_get_int(gd->fdt_blob, dev_of_offset(cpu), "reg",
-1);
plat->ucode_version = microcode_read_rev();
plat->device_id = gd->arch.x86_device;

Expand Down
3 changes: 2 additions & 1 deletion arch/x86/lib/mpspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ static int mptable_add_intsrc(struct mp_config_table *mc,
}

/* Get I/O interrupt information from device tree */
cell = fdt_getprop(blob, dev->of_offset, "intel,pirq-routing", &len);
cell = fdt_getprop(blob, dev_of_offset(dev), "intel,pirq-routing",
&len);
if (!cell)
return -ENOENT;

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/lib/pinctrl_ich6.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static int ich6_pinctrl_probe(struct udevice *dev)
return -EINVAL;
}

for (pin_node = fdt_first_subnode(gd->fdt_blob, dev->of_offset);
for (pin_node = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
pin_node > 0;
pin_node = fdt_next_subnode(gd->fdt_blob, pin_node)) {
/* Configure the pin */
Expand Down
9 changes: 6 additions & 3 deletions board/qualcomm/dragonboard410c/dragonboard410c.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ int board_prepare_usb(enum usb_init_type type)

/* Try to request gpios needed to start usb host on dragonboard */
if (!dm_gpio_is_valid(&hub_reset)) {
node = fdt_subnode_offset(gd->fdt_blob, pmic_gpio->of_offset,
node = fdt_subnode_offset(gd->fdt_blob,
dev_of_offset(pmic_gpio),
"usb_hub_reset_pm");
if (node < 0) {
printf("Failed to find usb_hub_reset_pm dt node.\n");
Expand All @@ -59,7 +60,8 @@ int board_prepare_usb(enum usb_init_type type)
}

if (!dm_gpio_is_valid(&usb_sel)) {
node = fdt_subnode_offset(gd->fdt_blob, pmic_gpio->of_offset,
node = fdt_subnode_offset(gd->fdt_blob,
dev_of_offset(pmic_gpio),
"usb_sw_sel_pm");
if (node < 0) {
printf("Failed to find usb_sw_sel_pm dt node.\n");
Expand Down Expand Up @@ -110,7 +112,8 @@ int misc_init_r(void)
return 0;
}

node = fdt_subnode_offset(gd->fdt_blob, pon->of_offset, "key_vol_down");
node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
"key_vol_down");
if (node < 0) {
printf("Failed to find key_vol_down node. Check device tree\n");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion doc/driver-model/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ steps (see device_probe()):

g. If the driver provides an ofdata_to_platdata() method, then this is
called to convert the device tree data into platform data. This should
do various calls like fdtdec_get_int(gd->fdt_blob, dev->of_offset, ...)
do various calls like fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), ...)
to access the node and store the resulting information into dev->platdata.
After this point, the device works the same way whether it was bound
using a device tree node or U_BOOT_DEVICE() structure. In either case,
Expand Down
2 changes: 1 addition & 1 deletion doc/driver-model/of-plat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ For example:
/* Decode the device tree data */
struct mmc_platdata *plat = dev_get_platdata(dev);
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int node = dev_of_offset(dev);

plat->fifo_depth = fdtdec_get_int(blob, node, "fifo-depth", 0);
#endif
Expand Down
2 changes: 1 addition & 1 deletion doc/driver-model/spi-howto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static int exynos_spi_ofdata_to_platdata(struct udevice *bus)
{
struct exynos_spi_platdata *plat = bus->platdata;
const void *blob = gd->fdt_blob;
int node = bus->of_offset;
int node = dev_of_offset(bus);

plat->regs = (struct exynos_spi *)fdtdec_get_addr(blob, node, "reg");
plat->periph_id = pinmux_decode_periph_id(blob, node);
Expand Down
4 changes: 2 additions & 2 deletions drivers/adc/adc-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ int adc_vss_value(struct udevice *dev, int *uV)
static int adc_vdd_platdata_set(struct udevice *dev)
{
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
int ret, offset = dev->of_offset;
int ret, offset = dev_of_offset(dev);
const void *fdt = gd->fdt_blob;
char *prop;

Expand All @@ -366,7 +366,7 @@ static int adc_vdd_platdata_set(struct udevice *dev)
static int adc_vss_platdata_set(struct udevice *dev)
{
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
int ret, offset = dev->of_offset;
int ret, offset = dev_of_offset(dev);
const void *fdt = gd->fdt_blob;
char *prop;

Expand Down
5 changes: 2 additions & 3 deletions drivers/clk/at91/clk-generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ static int generic_clk_ofdata_to_platdata(struct udevice *dev)
u32 num_parents;

num_parents = fdtdec_get_int_array_count(gd->fdt_blob,
dev_get_parent(dev)->of_offset,
"clocks", cells,
GENERATED_SOURCE_MAX);
dev_of_offset(dev_get_parent(dev)), "clocks", cells,
GENERATED_SOURCE_MAX);

if (!num_parents)
return -1;
Expand Down
5 changes: 3 additions & 2 deletions drivers/clk/at91/pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int at91_pmc_core_probe(struct udevice *dev)
int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name)
{
const void *fdt = gd->fdt_blob;
int offset = dev->of_offset;
int offset = dev_of_offset(dev);
bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC);
const char *name;
int ret;
Expand Down Expand Up @@ -90,7 +90,8 @@ int at91_clk_of_xlate(struct clk *clk, struct fdtdec_phandle_args *args)
return -EINVAL;
}

periph = fdtdec_get_uint(gd->fdt_blob, clk->dev->of_offset, "reg", -1);
periph = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(clk->dev), "reg",
-1);
if (periph < 0)
return -EINVAL;

Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/clk-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)
debug("%s(dev=%p, index=%d, clk=%p)\n", __func__, dev, index, clk);

assert(clk);
ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev->of_offset,
ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
"clocks", "#clock-cells", 0, index,
&args);
if (ret) {
Expand Down Expand Up @@ -104,7 +104,7 @@ int clk_get_by_name(struct udevice *dev, const char *name, struct clk *clk)

debug("%s(dev=%p, name=%s, clk=%p)\n", __func__, dev, name, clk);

index = fdt_stringlist_search(gd->fdt_blob, dev->of_offset,
index = fdt_stringlist_search(gd->fdt_blob, dev_of_offset(dev),
"clock-names", name);
if (index < 0) {
debug("fdt_stringlist_search() failed: %d\n", index);
Expand Down
2 changes: 1 addition & 1 deletion drivers/clk/clk_fixed_rate.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
{
#if !CONFIG_IS_ENABLED(OF_PLATDATA)
to_clk_fixed_rate(dev)->fixed_rate =
fdtdec_get_int(gd->fdt_blob, dev->of_offset,
fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
"clock-frequency", 0);
#endif

Expand Down
5 changes: 3 additions & 2 deletions drivers/clk/clk_pic32.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ static void pic32_clk_init(struct udevice *dev)
for (i = REF1CLK; i <= REF5CLK; i++) {
snprintf(propname, sizeof(propname),
"microchip,refo%d-frequency", i - REF1CLK + 1);
rate = fdtdec_get_int(blob, dev->of_offset, propname, 0);
rate = fdtdec_get_int(blob, dev_of_offset(dev), propname, 0);
if (rate)
pic32_set_refclk(priv, i, pll_hz, rate, ROCLK_SRC_SPLL);
}
Expand Down Expand Up @@ -393,7 +393,8 @@ static int pic32_clk_probe(struct udevice *dev)
fdt_addr_t addr;
fdt_size_t size;

addr = fdtdec_get_addr_size(gd->fdt_blob, dev->of_offset, "reg", &size);
addr = fdtdec_get_addr_size(gd->fdt_blob, dev_of_offset(dev), "reg",
&size);
if (addr == FDT_ADDR_T_NONE)
return -EINVAL;

Expand Down
Loading

0 comments on commit e160f7d

Please sign in to comment.