Skip to content

Commit 12966fd

Browse files
Andre-ARMlinusw
authored andcommitted
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 <[email protected]> Reviewed-by: Jernej Skrabec <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent bc9527f commit 12966fd

File tree

7 files changed

+36
-34
lines changed

7 files changed

+36
-34
lines changed

drivers/pinctrl/sunxi/pinctrl-sun20i-d1.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,15 +820,13 @@ static const struct sunxi_pinctrl_desc d1_pinctrl_data = {
820820

821821
static int d1_pinctrl_probe(struct platform_device *pdev)
822822
{
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);
826825
}
827826

828827
static const struct of_device_id d1_pinctrl_match[] = {
829828
{
830829
.compatible = "allwinner,sun20i-d1-pinctrl",
831-
.data = (void *)PINCTRL_SUN20I_D1
832830
},
833831
{}
834832
};

drivers/pinctrl/sunxi/pinctrl-sun4i-a10.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
#include "pinctrl-sunxi.h"
1919

20+
#define PINCTRL_SUN4I_A10 BIT(0)
21+
#define PINCTRL_SUN7I_A20 BIT(1)
22+
#define PINCTRL_SUN8I_R40 BIT(2)
23+
2024
static const struct sunxi_desc_pin sun4i_a10_pins[] = {
2125
SUNXI_PIN(SUNXI_PINCTRL_PIN(A, 0),
2226
SUNXI_FUNCTION(0x0, "gpio_in"),
@@ -1295,8 +1299,8 @@ static int sun4i_a10_pinctrl_probe(struct platform_device *pdev)
12951299
{
12961300
unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev);
12971301

1298-
return sunxi_pinctrl_init_with_variant(pdev, &sun4i_a10_pinctrl_data,
1299-
variant);
1302+
return sunxi_pinctrl_init_with_flags(pdev, &sun4i_a10_pinctrl_data,
1303+
variant);
13001304
}
13011305

13021306
static const struct of_device_id sun4i_a10_pinctrl_match[] = {

drivers/pinctrl/sunxi/pinctrl-sun5i.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#include "pinctrl-sunxi.h"
1818

19+
#define PINCTRL_SUN5I_A10S BIT(0)
20+
#define PINCTRL_SUN5I_A13 BIT(1)
21+
#define PINCTRL_SUN5I_GR8 BIT(2)
22+
1923
static const struct sunxi_desc_pin sun5i_pins[] = {
2024
SUNXI_PIN_VARIANT(SUNXI_PINCTRL_PIN(A, 0),
2125
PINCTRL_SUN5I_A10S,
@@ -719,8 +723,8 @@ static int sun5i_pinctrl_probe(struct platform_device *pdev)
719723
{
720724
unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev);
721725

722-
return sunxi_pinctrl_init_with_variant(pdev, &sun5i_pinctrl_data,
723-
variant);
726+
return sunxi_pinctrl_init_with_flags(pdev, &sun5i_pinctrl_data,
727+
variant);
724728
}
725729

726730
static const struct of_device_id sun5i_pinctrl_match[] = {

drivers/pinctrl/sunxi/pinctrl-sun6i-a31.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include "pinctrl-sunxi.h"
1919

20+
#define PINCTRL_SUN6I_A31 BIT(0)
21+
#define PINCTRL_SUN6I_A31S BIT(1)
22+
2023
static const struct sunxi_desc_pin sun6i_a31_pins[] = {
2124
SUNXI_PIN(SUNXI_PINCTRL_PIN(A, 0),
2225
SUNXI_FUNCTION(0x0, "gpio_in"),
@@ -972,9 +975,8 @@ static int sun6i_a31_pinctrl_probe(struct platform_device *pdev)
972975
unsigned long variant =
973976
(unsigned long)of_device_get_match_data(&pdev->dev);
974977

975-
return sunxi_pinctrl_init_with_variant(pdev,
976-
&sun6i_a31_pinctrl_data,
977-
variant);
978+
return sunxi_pinctrl_init_with_flags(pdev, &sun6i_a31_pinctrl_data,
979+
variant);
978980
}
979981

980982
static const struct of_device_id sun6i_a31_pinctrl_match[] = {

drivers/pinctrl/sunxi/pinctrl-sun8i-v3s.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include "pinctrl-sunxi.h"
2424

25+
#define PINCTRL_SUN8I_V3 BIT(0)
26+
#define PINCTRL_SUN8I_V3S BIT(1)
27+
2528
static const struct sunxi_desc_pin sun8i_v3s_pins[] = {
2629
/* Hole */
2730
SUNXI_PIN(SUNXI_PINCTRL_PIN(B, 0),
@@ -552,8 +555,8 @@ static int sun8i_v3s_pinctrl_probe(struct platform_device *pdev)
552555
{
553556
unsigned long variant = (unsigned long)of_device_get_match_data(&pdev->dev);
554557

555-
return sunxi_pinctrl_init_with_variant(pdev, &sun8i_v3s_pinctrl_data,
556-
variant);
558+
return sunxi_pinctrl_init_with_flags(pdev, &sun8i_v3s_pinctrl_data,
559+
variant);
557560
}
558561

559562
static const struct of_device_id sun8i_v3s_pinctrl_match[] = {

drivers/pinctrl/sunxi/pinctrl-sunxi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,9 +1472,9 @@ static int sunxi_pinctrl_setup_debounce(struct sunxi_pinctrl *pctl,
14721472
return 0;
14731473
}
14741474

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)
14781478
{
14791479
struct device_node *node = pdev->dev.of_node;
14801480
struct pinctrl_desc *pctrl_desc;
@@ -1497,8 +1497,8 @@ int sunxi_pinctrl_init_with_variant(struct platform_device *pdev,
14971497

14981498
pctl->dev = &pdev->dev;
14991499
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) {
15021502
pctl->bank_mem_size = D1_BANK_MEM_SIZE;
15031503
pctl->pull_regs_offset = D1_PULL_REGS_OFFSET;
15041504
pctl->dlevel_field_width = D1_DLEVEL_FIELD_WIDTH;

drivers/pinctrl/sunxi/pinctrl-sunxi.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,9 @@
8282
#define SUN4I_FUNC_INPUT 0
8383
#define SUN4I_FUNC_IRQ 6
8484

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)
9788

9889
#define PIO_POW_MOD_SEL_REG 0x340
9990
#define PIO_POW_MOD_CTL_REG 0x344
@@ -299,11 +290,11 @@ static inline u32 sunxi_grp_config_reg(u16 pin)
299290
return GRP_CFG_REG + bank * 0x4;
300291
}
301292

302-
int sunxi_pinctrl_init_with_variant(struct platform_device *pdev,
303-
const struct sunxi_pinctrl_desc *desc,
304-
unsigned long variant);
293+
int sunxi_pinctrl_init_with_flags(struct platform_device *pdev,
294+
const struct sunxi_pinctrl_desc *desc,
295+
unsigned long flags);
305296

306297
#define sunxi_pinctrl_init(_dev, _desc) \
307-
sunxi_pinctrl_init_with_variant(_dev, _desc, 0)
298+
sunxi_pinctrl_init_with_flags(_dev, _desc, 0)
308299

309300
#endif /* __PINCTRL_SUNXI_H */

0 commit comments

Comments
 (0)