Skip to contentSkip to conversation

pinctrl: sunxi: use automatic voltage detection on A733

PATCH In review Enzo Adriano 2 participants 2 messages Nov 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 pinctrl: sunxi: use automatic voltage detection on A733

A733 uses two-bit voltage-mode fields, but the handlers selected when v7.4-rc1 added A733 support program them as one-bit fields. The R-PIO handler also writes an A523 control register absent on A733.

Add BIAS_VOLTAGE_PIO_POW_AUTO to select auto (01) in every field of POW_MOD_SEL at controller init and skip per-pin voltage setup. Use it for both A733 controllers: the A733 User Manual v1.00 documents 01 as auto in sections 18.14.6.1 and 18.14.7.20. Give A733-R a separate descriptor so A523-R keeps its existing voltage handling.

On Orange Pi 4 Pro, the one-bit handler leaves bank H in 1.8 V mode while supplied at 3.3 V, breaking RGMII Gigabit TX. Alastair D'Silva reported that selecting auto mode restores TX.

---
Changes in v4:
- Rebase onto pinctrl fixes after the EINT-mux fix (context only).
- Carry Vinicius' and Norman's Tested-by tags from v3 (code unchanged), and credit Alastair's report.

v3: https://lore.kernel.org/r/[email protected]
v2: https://lore.kernel.org/r/[email protected]
Replaces Andre's RFT: https://lore.kernel.org/r/[email protected]

Tests: arm64 defconfig and W=1 sunxi build. Vinicius tested v3 on A7Z. Norman tested on Cubie A7S with v7.3.6 plus A733 patches, this patch and Pablo's IRQ-bank series backported, with his voltage-mode patches removed. POW_VAL matched the schematic; 3.3 V SD High Speed and GPIO IRQs on PK0, PB0 and PJ24 worked.
Not tested: v4 on hardware, 1.8 V SD switching, A523, pad voltages.

 drivers/pinctrl/sunxi/pinctrl-sun55i-a523-r.c | 19 +++++++++++++++----
 drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c   |  2 +-
 drivers/pinctrl/sunxi/pinctrl-sunxi.c         |  7 ++++++-
 drivers/pinctrl/sunxi/pinctrl-sunxi.h         |  2 ++
 4 files changed, 24 insertions(+), 6 deletions(-)
drivers/pinctrl/sunxi/pinctrl-sun55i-a523-r.c +15 -4
index cffc1e53eef1..006754c0645f 100644
@@ -30,17 +30,28 @@ static struct sunxi_pinctrl_desc a523_r_pinctrl_data = {
 	.pin_base = PL_BASE,
 };
 
+static struct sunxi_pinctrl_desc a733_r_pinctrl_data = {
+	.irq_banks = ARRAY_SIZE(a523_r_irq_bank_map),
+	.irq_bank_map = a523_r_irq_bank_map,
+	.io_bias_cfg_variant = BIAS_VOLTAGE_PIO_POW_AUTO,
+	.pin_base = PL_BASE,
+};
+
 static int a523_r_pinctrl_probe(struct platform_device *pdev)
 {
+	struct sunxi_pinctrl_desc *desc;
+
+	desc = (struct sunxi_pinctrl_desc *)of_device_get_match_data(&pdev->dev);
 	return sunxi_pinctrl_dt_table_init(pdev, a523_r_nr_bank_pins,
-					   a523_r_irq_bank_muxes,
-					   &a523_r_pinctrl_data,
+					   a523_r_irq_bank_muxes, desc,
 					   SUNXI_PINCTRL_NCAT2_REG_LAYOUT);
 }
 
 static const struct of_device_id a523_r_pinctrl_match[] = {
-	{ .compatible = "allwinner,sun55i-a523-r-pinctrl", },
-	{ .compatible = "allwinner,sun60i-a733-r-pinctrl", },
+	{ .compatible = "allwinner,sun55i-a523-r-pinctrl",
+	  .data = &a523_r_pinctrl_data },
+	{ .compatible = "allwinner,sun60i-a733-r-pinctrl",
+	  .data = &a733_r_pinctrl_data },
 	{}
 };
 
drivers/pinctrl/sunxi/pinctrl-sun60i-a733.c +1 -1
index 456d9170c2a2..c66f57385075 100644
@@ -23,7 +23,7 @@ static const u8 a733_irq_bank_muxes[SUNXI_PINCTRL_MAX_BANKS] =
 
 static struct sunxi_pinctrl_desc a733_pinctrl_data = {
 	.irq_banks = 10,
-	.io_bias_cfg_variant = BIAS_VOLTAGE_PIO_POW_MODE_SEL,
+	.io_bias_cfg_variant = BIAS_VOLTAGE_PIO_POW_AUTO,
 };
 
 static int a733_pinctrl_probe(struct platform_device *pdev)
drivers/pinctrl/sunxi/pinctrl-sunxi.c +6 -1
index bf4ec4665e2b..e54ed9e0b403 100644
@@ -732,7 +732,8 @@ static int sunxi_pinctrl_set_io_bias_cfg(struct sunxi_pinctrl *pctl,
 	u32 val, reg;
 	int uV;
 
-	if (!pctl->desc->io_bias_cfg_variant)
+	if (pctl->desc->io_bias_cfg_variant == BIAS_VOLTAGE_NONE ||
+	    pctl->desc->io_bias_cfg_variant == BIAS_VOLTAGE_PIO_POW_AUTO)
 		return 0;
 
 	uV = regulator_get_voltage(supply);
@@ -1655,6 +1656,10 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev,
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
 
+	/* Select auto (01) for every bank, including shared VCC-IO. */
+	if (desc->io_bias_cfg_variant == BIAS_VOLTAGE_PIO_POW_AUTO)
+		writel(0x55555555, pctl->membase + pctl->pow_mod_sel_offset);
+
 	/*
 	 * Seed the output latch shadow from the hardware so pins the
 	 * bootloader left in output mode keep their state; see
drivers/pinctrl/sunxi/pinctrl-sunxi.h +2 -0
index 7c2f29e75519..7b36c5c2263e 100644
@@ -130,6 +130,8 @@ enum sunxi_desc_bias_voltage {
 	 */
 	BIAS_VOLTAGE_PIO_POW_MODE_CTL,
 	BIAS_VOLTAGE_PIO_POW_MODE_CTL_INV,
+	/* Two-bit PIO_POW_MOD_SEL fields set to automatic voltage detection. */
+	BIAS_VOLTAGE_PIO_POW_AUTO,
 };
 
 struct sunxi_desc_function {

base-commit: 721850a3086d109c7ea5841673766a393747e4f1

Signature · 1 line
2.53.0
Reviewed-by Tested-by on v4 1/1
#1 lore raw
Quoted 14 lines · Enzo Adriano

A733 uses two-bit voltage-mode fields, but the handlers selected when v7.4-rc1 added A733 support program them as one-bit fields. The R-PIO handler also writes an A523 control register absent on A733.

Add BIAS_VOLTAGE_PIO_POW_AUTO to select auto (01) in every field of POW_MOD_SEL at controller init and skip per-pin voltage setup. Use it for both A733 controllers: the A733 User Manual v1.00 documents 01 as auto in sections 18.14.6.1 and 18.14.7.20. Give A733-R a separate descriptor so A523-R keeps its existing voltage handling.

On Orange Pi 4 Pro, the one-bit handler leaves bank H in 1.8 V mode while supplied at 3.3 V, breaking RGMII Gigabit TX. Alastair D'Silva reported that selecting auto mode restores TX.

Quoted 10 lines

Verified on Orange Pi 4 Pro: PIO_POW_MOD_SEL (0x02000040) reads 0x05555555 and 3.3 V RGMII Gigabit TX on bank H works at 1Gbps/Full (DHCP, ping, and iperf3).