Skip to contentSkip to conversation

pinctrl: ingenic: Fix regmap on X series SoCs

PATCH Superseded Aidan MacDonald 3 participants 4 messages Feb 9, 2022 – Feb 10, 2022

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: ingenic: Fix regmap on X series SoCs

The X series Ingenic SoCs have a shadow GPIO group which is at a higher offset than the other groups, and is used for all GPIO configuration. The regmap did not take this offset into account and set max_register too low. Writes to the shadow group registers were blocked, which made it impossible to change any pin configuration.

Fix this by pretending there are at least 8 chips on any 'X' SoC for the purposes of calculating max_register. This ensures the shadow group is accessible.

---
 drivers/pinctrl/pinctrl-ingenic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-ingenic.c +4 -1
index 2712f51eb238..9d2bccda50f1 100644
@@ -4168,7 +4168,10 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
 		return PTR_ERR(base);
 
 	regmap_config = ingenic_pinctrl_regmap_config;
-	regmap_config.max_register = chip_info->num_chips * chip_info->reg_offset;
+	if (chip_info->version >= ID_X1000)
+		regmap_config.max_register = MIN(8, chip_info->num_chips) * chip_info->reg_offset;
+	else
+		regmap_config.max_register = chip_info->num_chips * chip_info->reg_offset;
 
 	jzpc->map = devm_regmap_init_mmio(dev, base, &regmap_config);
 	if (IS_ERR(jzpc->map)) {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Aidan,

Quoted 7 lines · Aidan MacDonald

The X series Ingenic SoCs have a shadow GPIO group which is at a higher offset than the other groups, and is used for all GPIO configuration. The regmap did not take this offset into account and set max_register too low. Writes to the shadow group registers were blocked, which made it impossible to change any pin configuration.

Quoted 8 lines

Fix this by pretending there are at least 8 chips on any 'X' SoC for the purposes of calculating max_register. This ensures the shadow group is accessible.

---
  drivers/pinctrl/pinctrl-ingenic.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

The M200 SoC (once planned to be called JZ4785) has a different shadow register offset address,

if it needs to be supported in the future, then we need to deal with it further, but fortunately pinctrl-ingenic.c

does not involve M200 support yet, so:

Thanks and best regards!

Quoted 17 lines
drivers/pinctrl/pinctrl-ingenic.c +4 -1
index 2712f51eb238..9d2bccda50f1 100644
@@ -4168,7 +4168,10 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
  		return PTR_ERR(base);
 
  	regmap_config = ingenic_pinctrl_regmap_config;
-	regmap_config.max_register = chip_info->num_chips * chip_info->reg_offset;
+	if (chip_info->version >= ID_X1000)
+		regmap_config.max_register = MIN(8, chip_info->num_chips) * chip_info->reg_offset;
+	else
+		regmap_config.max_register = chip_info->num_chips * chip_info->reg_offset;
 
  	jzpc->map = devm_regmap_init_mmio(dev, base, &regmap_config);
  	if (IS_ERR(jzpc->map)) {
maintainer
#2 lore raw
In reply to Aidan MacDonald

Hi Aidan,

Quoted 10 lines · Aidan MacDonald

The X series Ingenic SoCs have a shadow GPIO group which is at a higher offset than the other groups, and is used for all GPIO configuration. The regmap did not take this offset into account and set max_register too low. Writes to the shadow group registers were blocked, which made it impossible to change any pin configuration.

Fix this by pretending there are at least 8 chips on any 'X' SoC for the purposes of calculating max_register. This ensures the shadow group is accessible.

I don't like your solution, it sounds very hacky. I think it would make more sense to use a dedicated x1000_pinctrl_regmap_config that would be used for the X1000 SoC. That would also allow you to express that there are no registers in the 0x400-0x700 range (through regmap_config.wr_table / .rd_table).

Cheers,
-Paul

Quoted 28 lines
---
 drivers/pinctrl/pinctrl-ingenic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-ingenic.c +4 -1
index 2712f51eb238..9d2bccda50f1 100644
@@ -4168,7 +4168,10 @@ static int __init ingenic_pinctrl_probe(struct 
 platform_device *pdev)
 		return PTR_ERR(base);
 
 	regmap_config = ingenic_pinctrl_regmap_config;
-	regmap_config.max_register = chip_info->num_chips * 
 chip_info->reg_offset;
+	if (chip_info->version >= ID_X1000)
+		regmap_config.max_register = MIN(8, chip_info->num_chips) * 
 chip_info->reg_offset;
+	else
+		regmap_config.max_register = chip_info->num_chips * 

chip_info->reg_offset;

drivers/pinctrl/pinctrl-ingenic.c +0 -1
 	jzpc->map = devm_regmap_init_mmio(dev, base, &regmap_config);
 	if (IS_ERR(jzpc->map)) {
--

2.34.1

#3 lore raw
Quoted 15 lines · Paul Cercueil

Hi Aidan,

Quoted 10 lines · Aidan MacDonald

The X series Ingenic SoCs have a shadow GPIO group which is at a higher offset than the other groups, and is used for all GPIO configuration. The regmap did not take this offset into account and set max_register too low. Writes to the shadow group registers were blocked, which made it impossible to change any pin configuration.

Fix this by pretending there are at least 8 chips on any 'X' SoC for the purposes of calculating max_register. This ensures the shadow group is accessible.

Quoted 9 lines

I don't like your solution, it sounds very hacky. I think it would make more sense to use a dedicated x1000_pinctrl_regmap_config that would be used for the X1000 SoC. That would also allow you to express that there are no registers in the 0x400-0x700 range (through regmap_config.wr_table / .rd_table).

Cheers,
-Paul

That's fine, I'll put together a v2 patch using the approach you suggest. I think all the 'X' SoCs will require a similar regmap as they're using ingenic_gpio_shadow_* functions too, but I'll check their datasheets to be sure.

Quoted 31 lines
Quoted 29 lines
---
 drivers/pinctrl/pinctrl-ingenic.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-ingenic.c +4 -1
index 2712f51eb238..9d2bccda50f1 100644
@@ -4168,7 +4168,10 @@ static int __init ingenic_pinctrl_probe(struct 
 platform_device *pdev)
 		return PTR_ERR(base);
 
 	regmap_config = ingenic_pinctrl_regmap_config;
-	regmap_config.max_register = chip_info->num_chips * 
 chip_info->reg_offset;
+	if (chip_info->version >= ID_X1000)
+		regmap_config.max_register = MIN(8, chip_info->num_chips) * 
 chip_info->reg_offset;
+	else
+		regmap_config.max_register = chip_info->num_chips * 

chip_info->reg_offset;

drivers/pinctrl/pinctrl-ingenic.c +0 -1
 	jzpc->map = devm_regmap_init_mmio(dev, base, &regmap_config);
 	if (IS_ERR(jzpc->map)) {
--

2.34.1