Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: sunxi: refactor pinctrl variants into flags

For some Allwinner SoCs we have one pinctrl driver caring for multiple
very similar chips, and are tagging certain pins with a variant bitmask.
The Allwinner D1 introduced a slightly extended register layout, and we
were abusing this variant mask to convey this bit of information into
the common code part.
Now there will be more pinctrl device properties to consider (has PortF
voltage switch, for instance), so shoehorning this into the variant
bitmask will not fly anymore.

Refactor the "variant" field into a more generic "flags" field. It turns
out that we don't need the variant bits to be unique across all SoCs,
but only among those SoCs that share one driver (table), of which there
are at most three variants at the moment. So the actual variant field can
be limited to say 8 bits, and the other bits in the flag register can be
re-purposed to hold other information, like this extended register
layout.
As a side effect we can move the variant definition into the per-SoC
pinctrl driver file, which makes it more obvious that this is just a
private definition, only relevant for this particular table.
This also changes the artificial sun20i-d1 "variant" into the actual
flag bit that we are after.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Link: https://lore.kernel.org/20250306235827.4895-2-andre.przywara@arm.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Andre Przywara and committed by
Linus Walleij
12966fdf bc9527fb

+36 -34
+2 -4
drivers/pinctrl/sunxi/pinctrl-sun20i-d1.c
··· 820 820 821 821 static int d1_pinctrl_probe(struct platform_device *pdev) 822 822 { 823 - unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev); 824 - 825 - return sunxi_pinctrl_init_with_variant(pdev, &d1_pinctrl_data, variant); 823 + return sunxi_pinctrl_init_with_flags(pdev, &d1_pinctrl_data, 824 + SUNXI_PINCTRL_NEW_REG_LAYOUT); 826 825 } 827 826 828 827 static const struct of_device_id d1_pinctrl_match[] = { 829 828 { 830 829 .compatible = "allwinner,sun20i-d1-pinctrl", 831 - .data = (void *)PINCTRL_SUN20I_D1 832 830 }, 833 831 {} 834 832 };
+6 -2
drivers/pinctrl/sunxi/pinctrl-sun4i-a10.c
··· 17 17 18 18 #include "pinctrl-sunxi.h" 19 19 20 + #define PINCTRL_SUN4I_A10 BIT(0) 21 + #define PINCTRL_SUN7I_A20 BIT(1) 22 + #define PINCTRL_SUN8I_R40 BIT(2) 23 + 20 24 static const struct sunxi_desc_pin sun4i_a10_pins[] = { 21 25 SUNXI_PIN(SUNXI_PINCTRL_PIN(A, 0), 22 26 SUNXI_FUNCTION(0x0, "gpio_in"), ··· 1299 1295 { 1300 1296 unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev); 1301 1297 1302 - return sunxi_pinctrl_init_with_variant(pdev, &sun4i_a10_pinctrl_data, 1303 - variant); 1298 + return sunxi_pinctrl_init_with_flags(pdev, &sun4i_a10_pinctrl_data, 1299 + variant); 1304 1300 } 1305 1301 1306 1302 static const struct of_device_id sun4i_a10_pinctrl_match[] = {
+6 -2
drivers/pinctrl/sunxi/pinctrl-sun5i.c
··· 16 16 17 17 #include "pinctrl-sunxi.h" 18 18 19 + #define PINCTRL_SUN5I_A10S BIT(0) 20 + #define PINCTRL_SUN5I_A13 BIT(1) 21 + #define PINCTRL_SUN5I_GR8 BIT(2) 22 + 19 23 static const struct sunxi_desc_pin sun5i_pins[] = { 20 24 SUNXI_PIN_VARIANT(SUNXI_PINCTRL_PIN(A, 0), 21 25 PINCTRL_SUN5I_A10S, ··· 723 719 { 724 720 unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev); 725 721 726 - return sunxi_pinctrl_init_with_variant(pdev, &sun5i_pinctrl_data, 727 - variant); 722 + return sunxi_pinctrl_init_with_flags(pdev, &sun5i_pinctrl_data, 723 + variant); 728 724 } 729 725 730 726 static const struct of_device_id sun5i_pinctrl_match[] = {
+5 -3
drivers/pinctrl/sunxi/pinctrl-sun6i-a31.c
··· 17 17 18 18 #include "pinctrl-sunxi.h" 19 19 20 + #define PINCTRL_SUN6I_A31 BIT(0) 21 + #define PINCTRL_SUN6I_A31S BIT(1) 22 + 20 23 static const struct sunxi_desc_pin sun6i_a31_pins[] = { 21 24 SUNXI_PIN(SUNXI_PINCTRL_PIN(A, 0), 22 25 SUNXI_FUNCTION(0x0, "gpio_in"), ··· 975 972 unsigned long variant = 976 973 (unsigned long)of_device_get_match_data(&pdev->dev); 977 974 978 - return sunxi_pinctrl_init_with_variant(pdev, 979 - &sun6i_a31_pinctrl_data, 980 - variant); 975 + return sunxi_pinctrl_init_with_flags(pdev, &sun6i_a31_pinctrl_data, 976 + variant); 981 977 } 982 978 983 979 static const struct of_device_id sun6i_a31_pinctrl_match[] = {
+5 -2
drivers/pinctrl/sunxi/pinctrl-sun8i-v3s.c
··· 22 22 23 23 #include "pinctrl-sunxi.h" 24 24 25 + #define PINCTRL_SUN8I_V3 BIT(0) 26 + #define PINCTRL_SUN8I_V3S BIT(1) 27 + 25 28 static const struct sunxi_desc_pin sun8i_v3s_pins[] = { 26 29 /* Hole */ 27 30 SUNXI_PIN(SUNXI_PINCTRL_PIN(B, 0), ··· 555 552 { 556 553 unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev); 557 554 558 - return sunxi_pinctrl_init_with_variant(pdev, &sun8i_v3s_pinctrl_data, 559 - variant); 555 + return sunxi_pinctrl_init_with_flags(pdev, &sun8i_v3s_pinctrl_data, 556 + variant); 560 557 } 561 558 562 559 static const struct of_device_id sun8i_v3s_pinctrl_match[] = {
+5 -5
drivers/pinctrl/sunxi/pinctrl-sunxi.c
··· 1472 1472 return 0; 1473 1473 } 1474 1474 1475 - int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, 1476 - const struct sunxi_pinctrl_desc *desc, 1477 - unsigned long variant) 1475 + int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, 1476 + const struct sunxi_pinctrl_desc *desc, 1477 + unsigned long flags) 1478 1478 { 1479 1479 struct device_node *node = pdev->dev.of_node; 1480 1480 struct pinctrl_desc *pctrl_desc; ··· 1497 1497 1498 1498 pctl->dev = &pdev->dev; 1499 1499 pctl->desc = desc; 1500 - pctl->variant = variant; 1501 - if (pctl->variant >= PINCTRL_SUN20I_D1) { 1500 + pctl->variant = flags & SUNXI_PINCTRL_VARIANT_MASK; 1501 + if (flags & SUNXI_PINCTRL_NEW_REG_LAYOUT) { 1502 1502 pctl->bank_mem_size = D1_BANK_MEM_SIZE; 1503 1503 pctl->pull_regs_offset = D1_PULL_REGS_OFFSET; 1504 1504 pctl->dlevel_field_width = D1_DLEVEL_FIELD_WIDTH;
+7 -16
drivers/pinctrl/sunxi/pinctrl-sunxi.h
··· 82 82 #define SUN4I_FUNC_INPUT 0 83 83 #define SUN4I_FUNC_IRQ 6 84 84 85 - #define PINCTRL_SUN5I_A10S BIT(1) 86 - #define PINCTRL_SUN5I_A13 BIT(2) 87 - #define PINCTRL_SUN5I_GR8 BIT(3) 88 - #define PINCTRL_SUN6I_A31 BIT(4) 89 - #define PINCTRL_SUN6I_A31S BIT(5) 90 - #define PINCTRL_SUN4I_A10 BIT(6) 91 - #define PINCTRL_SUN7I_A20 BIT(7) 92 - #define PINCTRL_SUN8I_R40 BIT(8) 93 - #define PINCTRL_SUN8I_V3 BIT(9) 94 - #define PINCTRL_SUN8I_V3S BIT(10) 95 - /* Variants below here have an updated register layout. */ 96 - #define PINCTRL_SUN20I_D1 BIT(11) 85 + #define SUNXI_PINCTRL_VARIANT_MASK GENMASK(7, 0) 86 + #define SUNXI_PINCTRL_NEW_REG_LAYOUT BIT(8) 87 + #define SUNXI_PINCTRL_PORTF_SWITCH BIT(9) 97 88 98 89 #define PIO_POW_MOD_SEL_REG 0x340 99 90 #define PIO_POW_MOD_CTL_REG 0x344 ··· 290 299 return GRP_CFG_REG + bank * 0x4; 291 300 } 292 301 293 - int sunxi_pinctrl_init_with_variant(struct platform_device *pdev, 294 - const struct sunxi_pinctrl_desc *desc, 295 - unsigned long variant); 302 + int sunxi_pinctrl_init_with_flags(struct platform_device *pdev, 303 + const struct sunxi_pinctrl_desc *desc, 304 + unsigned long flags); 296 305 297 306 #define sunxi_pinctrl_init(_dev, _desc) \ 298 - sunxi_pinctrl_init_with_variant(_dev, _desc, 0) 307 + sunxi_pinctrl_init_with_flags(_dev, _desc, 0) 299 308 300 309 #endif /* __PINCTRL_SUNXI_H */