[18/21] sandbox: pmic: Correct i2c pmic emulator platdata method
diff mbox series

Message ID 20200127084920.18.I296e8199523e08dced6bb64d6984b84753ec64c6@changeid
State Accepted
Commit eb7387ae14ef88ecba85d569de978da776ea4f09
Delegated to: Simon Glass
Headers show
Series
  • dm: Various enhancements to prepare for ACPI
Related show

Commit Message

Simon Glass Jan. 27, 2020, 3:49 p.m. UTC
This currently reads the uclass's private data in the ofdata_to_platdata
method which is not allowed, since the uclass has not read it from the
device tree. This happens in the probe method.

Fix it by adding a probe() method and moving the code there.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/power/pmic/i2c_pmic_emul.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

Simon Glass Feb. 5, 2020, 5:55 p.m. UTC | #1
This currently reads the uclass's private data in the ofdata_to_platdata
method which is not allowed, since the uclass has not read it from the
device tree. This happens in the probe method.

Fix it by adding a probe() method and moving the code there.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/power/pmic/i2c_pmic_emul.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!

Patch
diff mbox series

diff --git a/drivers/power/pmic/i2c_pmic_emul.c b/drivers/power/pmic/i2c_pmic_emul.c
index 80efc0265d..b58c8302cf 100644
--- a/drivers/power/pmic/i2c_pmic_emul.c
+++ b/drivers/power/pmic/i2c_pmic_emul.c
@@ -105,12 +105,21 @@  static int sandbox_i2c_pmic_ofdata_to_platdata(struct udevice *emul)
 {
 	struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul);
 	struct udevice *pmic_dev = i2c_emul_get_device(emul);
-	struct uc_pmic_priv *priv = dev_get_uclass_priv(pmic_dev);
-	const u8 *reg_defaults;
 
 	debug("%s:%d Setting PMIC default registers\n", __func__, __LINE__);
 	plat->reg_count = pmic_reg_count(pmic_dev);
-	plat->trans_len = priv->trans_len;
+
+	return 0;
+}
+
+static int sandbox_i2c_pmic_probe(struct udevice *emul)
+{
+	struct sandbox_i2c_pmic_plat_data *plat = dev_get_platdata(emul);
+	struct udevice *pmic_dev = i2c_emul_get_device(emul);
+	struct uc_pmic_priv *upriv = dev_get_uclass_priv(pmic_dev);
+	const u8 *reg_defaults;
+
+	plat->trans_len = upriv->trans_len;
 	plat->buf_size = plat->reg_count * plat->trans_len;
 
 	plat->reg = calloc(1, plat->buf_size);
@@ -149,6 +158,7 @@  U_BOOT_DRIVER(sandbox_i2c_pmic_emul) = {
 	.id		= UCLASS_I2C_EMUL,
 	.of_match	= sandbox_i2c_pmic_ids,
 	.ofdata_to_platdata = sandbox_i2c_pmic_ofdata_to_platdata,
+	.probe		= sandbox_i2c_pmic_probe,
 	.platdata_auto_alloc_size = sizeof(struct sandbox_i2c_pmic_plat_data),
 	.ops		= &sandbox_i2c_pmic_emul_ops,
 };