Skip to contentSkip to conversation

sunxi: Fixes for DM I2C drivers

PATCH In review Samuel Holland 2 participants 11 messages Mar 18, 2022 – Apr 5, 2022

Subsystems (2)
lore
Share & tools
lore

Samuel Holland

author maintainer
#0 lore raw

cover sunxi: Fixes for DM I2C drivers

A while back, the sunxi-specific P2WI and RSB drivers were converted to support DM_I2C. Now they are used as non-DM drivers in SPL, and DM drivers in U-Boot proper.

However, the DM version of the code did not fully initialize either the controller or the connected chips. So the DM driver would only work if the non-DM version had previously been used in SPL.

With these bug fixes and the pinctrl series, the drivers now work on SoCs like A64 and H6, which have a PMIC but do not set it up in SPL.

Samuel Holland (4):
i2c: sun6i_p2wi: Initialize chips in .child_pre_probe
i2c: sun6i_p2wi: Add support for DM clocks and resets
i2c: sun8i_rsb: Initialize chips in .child_pre_probe
i2c: sun8i_rsb: Add support for DM clocks and resets

 drivers/i2c/sun6i_p2wi.c | 15 ++++++++++++++-
 drivers/i2c/sun8i_rsb.c  | 15 ++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)
Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH 1/4 i2c: sun6i_p2wi: Initialize chips in .child_pre_probe

Chips attached to the P2WI bus require an initialization command before they can be used. (Specifically, this switches the chip from I2C mode to P2WI mode.) The driver does this in its .probe_chip hook, under the assumption that .probe_chip is called during child probe. This is not the case; .probe_chip is only called by dm_i2c_probe, which is intended for use by board-level code, not for chips with OF nodes.

Since this initialization command must be run before a child chip can be used, do it before probing each child.

---

 drivers/i2c/sun6i_p2wi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i2c/sun6i_p2wi.c +2 -1
index c9e1b3fcd5..da7f540509 100644
@@ -191,11 +191,12 @@ static int sun6i_p2wi_probe(struct udevice *bus)
 static int sun6i_p2wi_child_pre_probe(struct udevice *child)
 {
 	struct dm_i2c_chip *chip = dev_get_parent_plat(child);
+	struct udevice *bus = child->parent;
 
 	/* Ensure each transfer is for a single register. */
 	chip->flags |= DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS;
 
-	return 0;
+	return sun6i_p2wi_probe_chip(bus, chip->chip_addr, 0);
 }
 
 static const struct dm_i2c_ops sun6i_p2wi_ops = {
Signature · 1 line
2.33.1
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] i2c: sun6i_p2wi: Initialize chips in .child_pre_probe

On Thu, 17 Mar 2022 23:52:33 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 6 lines

Chips attached to the P2WI bus require an initialization command before they can be used. (Specifically, this switches the chip from I2C mode to P2WI mode.) The driver does this in its .probe_chip hook, under the assumption that .probe_chip is called during child probe. This is not the case; .probe_chip is only called by dm_i2c_probe, which is intended for use by board-level code, not for chips with OF nodes.

Indeed, I see that code path only triggered explicitly by board specific code, none of those places being compiled for sunxi.

So without looking too deep or having the ability to test this, it looks alright to me anyway.

Cheers,
Andre

Quoted 27 lines

Since this initialization command must be run before a child chip can be used, do it before probing each child.

---

 drivers/i2c/sun6i_p2wi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i2c/sun6i_p2wi.c +2 -1
index c9e1b3fcd5..da7f540509 100644
@@ -191,11 +191,12 @@ static int sun6i_p2wi_probe(struct udevice *bus)
 static int sun6i_p2wi_child_pre_probe(struct udevice *child)
 {
 	struct dm_i2c_chip *chip = dev_get_parent_plat(child);
+	struct udevice *bus = child->parent;
 
 	/* Ensure each transfer is for a single register. */
 	chip->flags |= DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS;
 
-	return 0;
+	return sun6i_p2wi_probe_chip(bus, chip->chip_addr, 0);
 }
 
 static const struct dm_i2c_ops sun6i_p2wi_ops = {
author maintainer
#3 lore raw

PATCH 2/4 i2c: sun6i_p2wi: Add support for DM clocks and resets

In reply to Samuel Holland

Currently, clock/reset setup for this device is handled by a platform-specific function and is intermixed with non-DM pinctrl setup. Use the devicetree to get clocks/resets, which disentagles it from the pinctrl setup in preparation for moving to DM_PINCTRL.

---

 drivers/i2c/sun6i_p2wi.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/i2c/sun6i_p2wi.c +12 -0
index da7f540509..087c682a50 100644
@@ -14,10 +14,12 @@
  */
 
 #include <axp_pmic.h>
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
+#include <reset.h>
 #include <time.h>
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
@@ -180,9 +182,19 @@ static int sun6i_p2wi_probe_chip(struct udevice *bus, uint chip_addr,
 static int sun6i_p2wi_probe(struct udevice *bus)
 {
 	struct sun6i_p2wi_priv *priv = dev_get_priv(bus);
+	struct reset_ctl *reset;
+	struct clk *clk;
 
 	priv->base = dev_read_addr_ptr(bus);
 
+	reset = devm_reset_control_get(bus, NULL);
+	if (!IS_ERR(reset))
+		reset_deassert(reset);
+
+	clk = devm_clk_get(bus, NULL);
+	if (!IS_ERR(clk))
+		clk_enable(clk);
+
 	sun6i_p2wi_init(priv->base);
 
 	return 0;
Signature · 1 line
2.33.1
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] i2c: sun6i_p2wi: Add support for DM clocks and resets

On Thu, 17 Mar 2022 23:52:34 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 6 lines

Currently, clock/reset setup for this device is handled by a platform-specific function and is intermixed with non-DM pinctrl setup. Use the devicetree to get clocks/resets, which disentagles it from the pinctrl setup in preparation for moving to DM_PINCTRL.

No ability to test this, but it looks alright, and is robust against failures. Also we support the required clocks and resets in our clock driver, AFAICS. So:

Cheers,
Andre

Quoted 42 lines

---

 drivers/i2c/sun6i_p2wi.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/i2c/sun6i_p2wi.c +12 -0
index da7f540509..087c682a50 100644
@@ -14,10 +14,12 @@
  */
 
 #include <axp_pmic.h>
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
+#include <reset.h>
 #include <time.h>
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
@@ -180,9 +182,19 @@ static int sun6i_p2wi_probe_chip(struct udevice *bus, uint chip_addr,
 static int sun6i_p2wi_probe(struct udevice *bus)
 {
 	struct sun6i_p2wi_priv *priv = dev_get_priv(bus);
+	struct reset_ctl *reset;
+	struct clk *clk;
 
 	priv->base = dev_read_addr_ptr(bus);
 
+	reset = devm_reset_control_get(bus, NULL);
+	if (!IS_ERR(reset))
+		reset_deassert(reset);
+
+	clk = devm_clk_get(bus, NULL);
+	if (!IS_ERR(clk))
+		clk_enable(clk);
+
 	sun6i_p2wi_init(priv->base);
 
 	return 0;
author maintainer
#5 lore raw

PATCH 3/4 i2c: sun8i_rsb: Initialize chips in .child_pre_probe

In reply to Samuel Holland

Chips attached to the RSB bus require an initialization command before they can be used. (Specifically, this command programs the chip's runtime address.) The driver does this in its .probe_chip hook, under the assumption that .probe_chip is called during child probe. This is not the case; .probe_chip is only called by dm_i2c_probe, which is intended for use by board-level code, not for chips with OF nodes.

Since this initialization command must be run before a child chip can be used, do it before probing each child.

---

 drivers/i2c/sun8i_rsb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i2c/sun8i_rsb.c +2 -1
index 716b245a00..0681e398f7 100644
@@ -252,11 +252,12 @@ static int sun8i_rsb_probe(struct udevice *bus)
 static int sun8i_rsb_child_pre_probe(struct udevice *child)
 {
 	struct dm_i2c_chip *chip = dev_get_parent_plat(child);
+	struct udevice *bus = child->parent;
 
 	/* Ensure each transfer is for a single register. */
 	chip->flags |= DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS;
 
-	return 0;
+	return sun8i_rsb_probe_chip(bus, chip->chip_addr, 0);
 }
 
 static const struct dm_i2c_ops sun8i_rsb_ops = {
Signature · 1 line
2.33.1
Acked-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] i2c: sun8i_rsb: Initialize chips in .child_pre_probe

On Thu, 17 Mar 2022 23:52:35 -0500
Samuel Holland <[email protected]> wrote:

Hi,

Quoted 11 lines

Chips attached to the RSB bus require an initialization command before they can be used. (Specifically, this command programs the chip's runtime address.) The driver does this in its .probe_chip hook, under the assumption that .probe_chip is called during child probe. This is not the case; .probe_chip is only called by dm_i2c_probe, which is intended for use by board-level code, not for chips with OF nodes.

Since this initialization command must be run before a child chip can be used, do it before probing each child.

Same as for patch 1/4:
currently that code path is not called by any sunxi code, so without looking too deep or having the ability to test this, it looks alright to me:

Cheers,
Andre

Quoted 23 lines

---

 drivers/i2c/sun8i_rsb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i2c/sun8i_rsb.c +2 -1
index 716b245a00..0681e398f7 100644
@@ -252,11 +252,12 @@ static int sun8i_rsb_probe(struct udevice *bus)
 static int sun8i_rsb_child_pre_probe(struct udevice *child)
 {
 	struct dm_i2c_chip *chip = dev_get_parent_plat(child);
+	struct udevice *bus = child->parent;
 
 	/* Ensure each transfer is for a single register. */
 	chip->flags |= DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS;
 
-	return 0;
+	return sun8i_rsb_probe_chip(bus, chip->chip_addr, 0);
 }
 
 static const struct dm_i2c_ops sun8i_rsb_ops = {
author maintainer
#7 lore raw

PATCH 4/4 i2c: sun8i_rsb: Add support for DM clocks and resets

In reply to Samuel Holland

Currently, clock/reset setup for this device is handled by a platform-specific function and is intermixed with non-DM pinctrl setup. Use the devicetree to get clocks/resets, which disentagles it from the pinctrl setup in preparation for moving to DM_PINCTRL.

This also has the added benefit of picking the right clock/reset bits for H6 and new SoCs that have a rearranged PRCM MMIO space.

---

 drivers/i2c/sun8i_rsb.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/i2c/sun8i_rsb.c +12 -0
index 0681e398f7..e3a44e6a1b 100644
@@ -9,10 +9,12 @@
  */
 
 #include <axp_pmic.h>
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
+#include <reset.h>
 #include <time.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/gpio.h>
@@ -243,9 +245,19 @@ static int sun8i_rsb_probe_chip(struct udevice *bus, uint chip_addr,
 static int sun8i_rsb_probe(struct udevice *bus)
 {
 	struct sun8i_rsb_priv *priv = dev_get_priv(bus);
+	struct reset_ctl *reset;
+	struct clk *clk;
 
 	priv->base = dev_read_addr_ptr(bus);
 
+	reset = devm_reset_control_get(bus, NULL);
+	if (!IS_ERR(reset))
+		reset_deassert(reset);
+
+	clk = devm_clk_get(bus, NULL);
+	if (!IS_ERR(clk))
+		clk_enable(clk);
+
 	return sun8i_rsb_init(priv->base);
 }
 
Signature · 1 line
2.33.1
#8 lore raw

Re: [PATCH 4/4] i2c: sun8i_rsb: Add support for DM clocks and resets

Quoted 7 lines · On Thu, 17 Mar 2022 23:52:36 -0500 Samuel Holland <[email protected]> wrote:

Currently, clock/reset setup for this device is handled by a platform-specific function and is intermixed with non-DM pinctrl setup. Use the devicetree to get clocks/resets, which disentagles it from the pinctrl setup in preparation for moving to DM_PINCTRL.

This also has the added benefit of picking the right clock/reset bits for H6 and new SoCs that have a rearranged PRCM MMIO space.

So does this actually work right now with the A23/A33? They have specific clocks for the RSB gates/resets, and I don't see support for that in the tree right now? Or this is just fine because those clocks are treated optional and their enabling is actually redundant, in practice?

Cheers,
Andre

Quoted 44 lines

---

 drivers/i2c/sun8i_rsb.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/i2c/sun8i_rsb.c +12 -0
index 0681e398f7..e3a44e6a1b 100644
@@ -9,10 +9,12 @@
  */
 
 #include <axp_pmic.h>
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
+#include <reset.h>
 #include <time.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/gpio.h>
@@ -243,9 +245,19 @@ static int sun8i_rsb_probe_chip(struct udevice *bus, uint chip_addr,
 static int sun8i_rsb_probe(struct udevice *bus)
 {
 	struct sun8i_rsb_priv *priv = dev_get_priv(bus);
+	struct reset_ctl *reset;
+	struct clk *clk;
 
 	priv->base = dev_read_addr_ptr(bus);
 
+	reset = devm_reset_control_get(bus, NULL);
+	if (!IS_ERR(reset))
+		reset_deassert(reset);
+
+	clk = devm_clk_get(bus, NULL);
+	if (!IS_ERR(clk))
+		clk_enable(clk);
+
 	return sun8i_rsb_init(priv->base);
 }
 
author maintainer
#9 lore raw

Re: [PATCH 4/4] i2c: sun8i_rsb: Add support for DM clocks and resets

Hi Andre,

Quoted 8 lines · Andre Przywara
Quoted 5 lines · On Thu, 17 Mar 2022 23:52:36 -0500 Samuel Holland <[email protected]> wrote:

Currently, clock/reset setup for this device is handled by a platform-specific function and is intermixed with non-DM pinctrl setup. Use the devicetree to get clocks/resets, which disentagles it from the pinctrl setup in preparation for moving to DM_PINCTRL.

Quoted 7 lines
Quoted 2 lines

This also has the added benefit of picking the right clock/reset bits for H6 and new SoCs that have a rearranged PRCM MMIO space.

So does this actually work right now with the A23/A33? They have specific clocks for the RSB gates/resets, and I don't see support for that in the tree right now? Or this is just fine because those clocks are treated optional and their enabling is actually redundant, in practice?

Yes, A23/A33 work right now because the clocks are already enabled in SPL. So this change does nothing (positive or negative) on those SoCs, because as you note we are missing the A23/A33 DM clock driver.

For 64-bit SoCs, where RSB is not used in SPL, this change is not redundant. With this series plus the pinctrl series, you should now have working RSB in U-Boot proper on A64/H6/H616. I have been testing this with the i2c and pmic commands.

Regards,
Samuel

Quoted 48 lines

Cheers,
Andre

Quoted 44 lines

---

 drivers/i2c/sun8i_rsb.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/i2c/sun8i_rsb.c +12 -0
index 0681e398f7..e3a44e6a1b 100644
@@ -9,10 +9,12 @@
  */
 
 #include <axp_pmic.h>
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
 #include <i2c.h>
+#include <reset.h>
 #include <time.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/gpio.h>
@@ -243,9 +245,19 @@ static int sun8i_rsb_probe_chip(struct udevice *bus, uint chip_addr,
 static int sun8i_rsb_probe(struct udevice *bus)
 {
 	struct sun8i_rsb_priv *priv = dev_get_priv(bus);
+	struct reset_ctl *reset;
+	struct clk *clk;
 
 	priv->base = dev_read_addr_ptr(bus);
 
+	reset = devm_reset_control_get(bus, NULL);
+	if (!IS_ERR(reset))
+		reset_deassert(reset);
+
+	clk = devm_clk_get(bus, NULL);
+	if (!IS_ERR(clk))
+		clk_enable(clk);
+
 	return sun8i_rsb_init(priv->base);
 }
 
#10 lore raw
In reply to Samuel Holland
Quoted 11 lines · On Thu, 17 Mar 2022 23:52:32 -0500 Samuel Holland <[email protected]> wrote:

A while back, the sunxi-specific P2WI and RSB drivers were converted to support DM_I2C. Now they are used as non-DM drivers in SPL, and DM drivers in U-Boot proper.

However, the DM version of the code did not fully initialize either the controller or the connected chips. So the DM driver would only work if the non-DM version had previously been used in SPL.

With these bug fixes and the pinctrl series, the drivers now work on SoCs like A64 and H6, which have a PMIC but do not set it up in SPL.

All merged into sunxi/master, which already landed in mainline.

Thanks!
Andre

Quoted 11 lines

Samuel Holland (4):
i2c: sun6i_p2wi: Initialize chips in .child_pre_probe
i2c: sun6i_p2wi: Add support for DM clocks and resets
i2c: sun8i_rsb: Initialize chips in .child_pre_probe
i2c: sun8i_rsb: Add support for DM clocks and resets

 drivers/i2c/sun6i_p2wi.c | 15 ++++++++++++++-
 drivers/i2c/sun8i_rsb.c  | 15 ++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)