dm: core: Replace of_offset with accessor

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 <sjg@chromium.org>
diff --git a/drivers/power/domain/power-domain-uclass.c b/drivers/power/domain/power-domain-uclass.c
index 1bb6262..3dabbe4 100644
--- a/drivers/power/domain/power-domain-uclass.c
+++ b/drivers/power/domain/power-domain-uclass.c
@@ -41,7 +41,7 @@
 
 	debug("%s(dev=%p, power_domain=%p)\n", __func__, dev, power_domain);
 
-	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),
 					     "power-domains",
 					     "#power-domain-cells", 0, 0,
 					     &args);
diff --git a/drivers/power/pmic/act8846.c b/drivers/power/pmic/act8846.c
index e8164bf..15da12e 100644
--- a/drivers/power/pmic/act8846.c
+++ b/drivers/power/pmic/act8846.c
@@ -52,7 +52,7 @@
 	int regulators_node;
 	int children;
 
-	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
+	regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
 					     "regulators");
 	if (regulators_node <= 0) {
 		debug("%s: %s regulators subnode not found!", __func__,
diff --git a/drivers/power/pmic/i2c_pmic_emul.c b/drivers/power/pmic/i2c_pmic_emul.c
index aeab5c9..4f92e3d 100644
--- a/drivers/power/pmic/i2c_pmic_emul.c
+++ b/drivers/power/pmic/i2c_pmic_emul.c
@@ -108,9 +108,9 @@
 
 	debug("%s:%d Setting PMIC default registers\n", __func__, __LINE__);
 
-	reg_defaults = fdtdec_locate_byte_array(gd->fdt_blob, emul->of_offset,
-						"reg-defaults",
-						SANDBOX_PMIC_REG_COUNT);
+	reg_defaults = fdtdec_locate_byte_array(gd->fdt_blob,
+			dev_of_offset(emul), "reg-defaults",
+			SANDBOX_PMIC_REG_COUNT);
 
 	if (!reg_defaults) {
 		error("Property \"reg-defaults\" not found for device: %s!",
diff --git a/drivers/power/pmic/lp873x.c b/drivers/power/pmic/lp873x.c
index 307f96b..d8f30df 100644
--- a/drivers/power/pmic/lp873x.c
+++ b/drivers/power/pmic/lp873x.c
@@ -49,7 +49,7 @@
 	int regulators_node;
 	const void *blob = gd->fdt_blob;
 	int children;
-	int node = dev->of_offset;
+	int node = dev_of_offset(dev);
 
 	regulators_node = fdt_subnode_offset(blob, node, "regulators");
 
diff --git a/drivers/power/pmic/max77686.c b/drivers/power/pmic/max77686.c
index dc5a54a..8295fab 100644
--- a/drivers/power/pmic/max77686.c
+++ b/drivers/power/pmic/max77686.c
@@ -54,7 +54,7 @@
 	const void *blob = gd->fdt_blob;
 	int children;
 
-	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
+	regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
 					     "voltage-regulators");
 	if (regulators_node <= 0) {
 		debug("%s: %s regulators subnode not found!", __func__,
diff --git a/drivers/power/pmic/palmas.c b/drivers/power/pmic/palmas.c
index 0ab425e..f5a2307 100644
--- a/drivers/power/pmic/palmas.c
+++ b/drivers/power/pmic/palmas.c
@@ -49,7 +49,7 @@
 	int pmic_node = -1, regulators_node;
 	const void *blob = gd->fdt_blob;
 	int children;
-	int node = dev->of_offset;
+	int node = dev_of_offset(dev);
 	int subnode, len;
 
 	fdt_for_each_subnode(subnode, blob, node) {
diff --git a/drivers/power/pmic/pfuze100.c b/drivers/power/pmic/pfuze100.c
index 3beb48e..90a43f2 100644
--- a/drivers/power/pmic/pfuze100.c
+++ b/drivers/power/pmic/pfuze100.c
@@ -56,7 +56,7 @@
 	int regulators_node;
 	const void *blob = gd->fdt_blob;
 
-	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
+	regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
 					     "regulators");
 	if (regulators_node <= 0) {
 		debug("%s: %s regulators subnode not found!", __func__,
diff --git a/drivers/power/pmic/pmic-uclass.c b/drivers/power/pmic/pmic-uclass.c
index 7211026..0f7fa51 100644
--- a/drivers/power/pmic/pmic-uclass.c
+++ b/drivers/power/pmic/pmic-uclass.c
@@ -33,7 +33,7 @@
 	int ret;
 
 	debug("%s for '%s' at node offset: %d\n", __func__, pmic->name,
-	      pmic->of_offset);
+	      dev_of_offset(pmic));
 
 	for (node = fdt_first_subnode(blob, offset);
 	     node > 0;
diff --git a/drivers/power/pmic/rk808.c b/drivers/power/pmic/rk808.c
index 770f471..3f5f316 100644
--- a/drivers/power/pmic/rk808.c
+++ b/drivers/power/pmic/rk808.c
@@ -61,7 +61,7 @@
 	int regulators_node;
 	int children;
 
-	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
+	regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
 					     "regulators");
 	if (regulators_node <= 0) {
 		debug("%s: %s regulators subnode not found!", __func__,
diff --git a/drivers/power/pmic/s5m8767.c b/drivers/power/pmic/s5m8767.c
index 075fe7e..25d673b 100644
--- a/drivers/power/pmic/s5m8767.c
+++ b/drivers/power/pmic/s5m8767.c
@@ -58,7 +58,7 @@
 	const void *blob = gd->fdt_blob;
 	int children;
 
-	node = fdt_subnode_offset(blob, dev->of_offset, "regulators");
+	node = fdt_subnode_offset(blob, dev_of_offset(dev), "regulators");
 	if (node <= 0) {
 		debug("%s: %s regulators subnode not found!", __func__,
 		      dev->name);
diff --git a/drivers/power/pmic/sandbox.c b/drivers/power/pmic/sandbox.c
index 3e56acd..b4e412e 100644
--- a/drivers/power/pmic/sandbox.c
+++ b/drivers/power/pmic/sandbox.c
@@ -51,7 +51,7 @@
 
 static int sandbox_pmic_bind(struct udevice *dev)
 {
-	if (!pmic_bind_children(dev, dev->of_offset, pmic_children_info))
+	if (!pmic_bind_children(dev, dev_of_offset(dev), pmic_children_info))
 		error("%s:%d PMIC: %s - no child found!", __func__, __LINE__,
 							  dev->name);
 
diff --git a/drivers/power/pmic/tps65090.c b/drivers/power/pmic/tps65090.c
index 4797f32..b30a7f0 100644
--- a/drivers/power/pmic/tps65090.c
+++ b/drivers/power/pmic/tps65090.c
@@ -56,7 +56,7 @@
 	const void *blob = gd->fdt_blob;
 	int children;
 
-	regulators_node = fdt_subnode_offset(blob, dev->of_offset,
+	regulators_node = fdt_subnode_offset(blob, dev_of_offset(dev),
 					     "regulators");
 	if (regulators_node <= 0) {
 		debug("%s: %s regulators subnode not found!", __func__,
diff --git a/drivers/power/regulator/fixed.c b/drivers/power/regulator/fixed.c
index 3d2d908..cd52137 100644
--- a/drivers/power/regulator/fixed.c
+++ b/drivers/power/regulator/fixed.c
@@ -28,7 +28,7 @@
 	struct fixed_regulator_platdata *dev_pdata;
 	struct gpio_desc *gpio;
 	const void *blob = gd->fdt_blob;
-	int node = dev->of_offset, flags = GPIOD_IS_OUT;
+	int node = dev_of_offset(dev), flags = GPIOD_IS_OUT;
 	int ret;
 
 	dev_pdata = dev_get_platdata(dev);
@@ -54,7 +54,7 @@
 
 	/* Get optional ramp up delay */
 	dev_pdata->startup_delay_us = fdtdec_get_uint(gd->fdt_blob,
-						      dev->of_offset,
+						      dev_of_offset(dev),
 						      "startup-delay-us", 0);
 
 	return 0;
diff --git a/drivers/power/regulator/gpio-regulator.c b/drivers/power/regulator/gpio-regulator.c
index 0a60a9c..42391c6 100644
--- a/drivers/power/regulator/gpio-regulator.c
+++ b/drivers/power/regulator/gpio-regulator.c
@@ -30,7 +30,7 @@
 	struct gpio_regulator_platdata *dev_pdata;
 	struct gpio_desc *gpio;
 	const void *blob = gd->fdt_blob;
-	int node = dev->of_offset;
+	int node = dev_of_offset(dev);
 	int ret, count, i, j;
 	u32 states_array[8];
 
diff --git a/drivers/power/regulator/pwm_regulator.c b/drivers/power/regulator/pwm_regulator.c
index b0a4c5d..4875238 100644
--- a/drivers/power/regulator/pwm_regulator.c
+++ b/drivers/power/regulator/pwm_regulator.c
@@ -88,7 +88,7 @@
 	struct pwm_regulator_info *priv = dev_get_priv(dev);
 	struct fdtdec_phandle_args args;
 	const void *blob = gd->fdt_blob;
-	int node = dev->of_offset;
+	int node = dev_of_offset(dev);
 	int ret;
 
 	ret = fdtdec_parse_phandle_with_args(blob, node, "pwms", "#pwm-cells",
diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 52a1070..2e0b5ed 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -278,7 +278,7 @@
 static int regulator_post_bind(struct udevice *dev)
 {
 	struct dm_regulator_uclass_platdata *uc_pdata;
-	int offset = dev->of_offset;
+	int offset = dev_of_offset(dev);
 	const void *blob = gd->fdt_blob;
 	const char *property = "regulator-name";
 
@@ -308,7 +308,7 @@
 static int regulator_pre_probe(struct udevice *dev)
 {
 	struct dm_regulator_uclass_platdata *uc_pdata;
-	int offset = dev->of_offset;
+	int offset = dev_of_offset(dev);
 
 	uc_pdata = dev_get_uclass_platdata(dev);
 	if (!uc_pdata)