Skip to content

Commit baf1564

Browse files
pcercueilinusw
authored andcommitted
pinctrl: ingenic: Put ingenic_chip_info pointer in match data
Instead of passing a numeric ID as match data, and retrieve a pointer to the ingenic_chip_info structure in an ugly succession of if/else in the probe function, get the pointer to the ingenic_chip_info structure directly from the match data, and store the numeric ID inside the ingenic_chip_info structure. Signed-off-by: Paul Cercueil <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 5ec008b commit baf1564

File tree

1 file changed

+45
-57
lines changed

1 file changed

+45
-57
lines changed

drivers/pinctrl/pinctrl-ingenic.c

Lines changed: 45 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum jz_version {
7373
struct ingenic_chip_info {
7474
unsigned int num_chips;
7575
unsigned int reg_offset;
76+
enum jz_version version;
7677

7778
const struct group_desc *groups;
7879
unsigned int num_groups;
@@ -88,7 +89,6 @@ struct ingenic_pinctrl {
8889
struct regmap *map;
8990
struct pinctrl_dev *pctl;
9091
struct pinctrl_pin_desc *pdesc;
91-
enum jz_version version;
9292

9393
const struct ingenic_chip_info *info;
9494
};
@@ -226,6 +226,7 @@ static const struct function_desc jz4740_functions[] = {
226226
static const struct ingenic_chip_info jz4740_chip_info = {
227227
.num_chips = 4,
228228
.reg_offset = 0x100,
229+
.version = ID_JZ4740,
229230
.groups = jz4740_groups,
230231
.num_groups = ARRAY_SIZE(jz4740_groups),
231232
.functions = jz4740_functions,
@@ -350,6 +351,7 @@ static const struct function_desc jz4725b_functions[] = {
350351
static const struct ingenic_chip_info jz4725b_chip_info = {
351352
.num_chips = 4,
352353
.reg_offset = 0x100,
354+
.version = ID_JZ4725B,
353355
.groups = jz4725b_groups,
354356
.num_groups = ARRAY_SIZE(jz4725b_groups),
355357
.functions = jz4725b_functions,
@@ -604,6 +606,7 @@ static const struct function_desc jz4760_functions[] = {
604606
static const struct ingenic_chip_info jz4760_chip_info = {
605607
.num_chips = 6,
606608
.reg_offset = 0x100,
609+
.version = ID_JZ4760,
607610
.groups = jz4760_groups,
608611
.num_groups = ARRAY_SIZE(jz4760_groups),
609612
.functions = jz4760_functions,
@@ -615,6 +618,7 @@ static const struct ingenic_chip_info jz4760_chip_info = {
615618
static const struct ingenic_chip_info jz4760b_chip_info = {
616619
.num_chips = 6,
617620
.reg_offset = 0x100,
621+
.version = ID_JZ4760B,
618622
.groups = jz4760_groups,
619623
.num_groups = ARRAY_SIZE(jz4760_groups),
620624
.functions = jz4760_functions,
@@ -894,6 +898,7 @@ static const struct function_desc jz4770_functions[] = {
894898
static const struct ingenic_chip_info jz4770_chip_info = {
895899
.num_chips = 6,
896900
.reg_offset = 0x100,
901+
.version = ID_JZ4770,
897902
.groups = jz4770_groups,
898903
.num_groups = ARRAY_SIZE(jz4770_groups),
899904
.functions = jz4770_functions,
@@ -1028,6 +1033,7 @@ static const struct function_desc jz4780_functions[] = {
10281033
static const struct ingenic_chip_info jz4780_chip_info = {
10291034
.num_chips = 6,
10301035
.reg_offset = 0x100,
1036+
.version = ID_JZ4780,
10311037
.groups = jz4780_groups,
10321038
.num_groups = ARRAY_SIZE(jz4780_groups),
10331039
.functions = jz4780_functions,
@@ -1285,6 +1291,7 @@ static const struct function_desc x1000_functions[] = {
12851291
static const struct ingenic_chip_info x1000_chip_info = {
12861292
.num_chips = 4,
12871293
.reg_offset = 0x100,
1294+
.version = ID_X1000,
12881295
.groups = x1000_groups,
12891296
.num_groups = ARRAY_SIZE(x1000_groups),
12901297
.functions = x1000_functions,
@@ -1296,6 +1303,7 @@ static const struct ingenic_chip_info x1000_chip_info = {
12961303
static const struct ingenic_chip_info x1000e_chip_info = {
12971304
.num_chips = 4,
12981305
.reg_offset = 0x100,
1306+
.version = ID_X1000E,
12991307
.groups = x1000_groups,
13001308
.num_groups = ARRAY_SIZE(x1000_groups),
13011309
.functions = x1000_functions,
@@ -1409,6 +1417,7 @@ static const struct function_desc x1500_functions[] = {
14091417
static const struct ingenic_chip_info x1500_chip_info = {
14101418
.num_chips = 4,
14111419
.reg_offset = 0x100,
1420+
.version = ID_X1500,
14121421
.groups = x1500_groups,
14131422
.num_groups = ARRAY_SIZE(x1500_groups),
14141423
.functions = x1500_functions,
@@ -1624,6 +1633,7 @@ static const struct function_desc x1830_functions[] = {
16241633
static const struct ingenic_chip_info x1830_chip_info = {
16251634
.num_chips = 4,
16261635
.reg_offset = 0x1000,
1636+
.version = ID_X1830,
16271637
.groups = x1830_groups,
16281638
.num_groups = ARRAY_SIZE(x1830_groups),
16291639
.functions = x1830_functions,
@@ -1682,7 +1692,7 @@ static inline bool ingenic_gpio_get_value(struct ingenic_gpio_chip *jzgc,
16821692
static void ingenic_gpio_set_value(struct ingenic_gpio_chip *jzgc,
16831693
u8 offset, int value)
16841694
{
1685-
if (jzgc->jzpc->version >= ID_JZ4760)
1695+
if (jzgc->jzpc->info->version >= ID_JZ4760)
16861696
ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_PAT0, offset, !!value);
16871697
else
16881698
ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, offset, !!value);
@@ -1693,7 +1703,7 @@ static void irq_set_type(struct ingenic_gpio_chip *jzgc,
16931703
{
16941704
u8 reg1, reg2;
16951705

1696-
if (jzgc->jzpc->version >= ID_JZ4760) {
1706+
if (jzgc->jzpc->info->version >= ID_JZ4760) {
16971707
reg1 = JZ4760_GPIO_PAT1;
16981708
reg2 = JZ4760_GPIO_PAT0;
16991709
} else {
@@ -1703,7 +1713,7 @@ static void irq_set_type(struct ingenic_gpio_chip *jzgc,
17031713

17041714
switch (type) {
17051715
case IRQ_TYPE_EDGE_RISING:
1706-
if (jzgc->jzpc->version >= ID_X1000) {
1716+
if (jzgc->jzpc->info->version >= ID_X1000) {
17071717
ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, true);
17081718
ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, true);
17091719
ingenic_gpio_shadow_set_bit_load(jzgc);
@@ -1713,7 +1723,7 @@ static void irq_set_type(struct ingenic_gpio_chip *jzgc,
17131723
}
17141724
break;
17151725
case IRQ_TYPE_EDGE_FALLING:
1716-
if (jzgc->jzpc->version >= ID_X1000) {
1726+
if (jzgc->jzpc->info->version >= ID_X1000) {
17171727
ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, false);
17181728
ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, true);
17191729
ingenic_gpio_shadow_set_bit_load(jzgc);
@@ -1723,7 +1733,7 @@ static void irq_set_type(struct ingenic_gpio_chip *jzgc,
17231733
}
17241734
break;
17251735
case IRQ_TYPE_LEVEL_HIGH:
1726-
if (jzgc->jzpc->version >= ID_X1000) {
1736+
if (jzgc->jzpc->info->version >= ID_X1000) {
17271737
ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, true);
17281738
ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, false);
17291739
ingenic_gpio_shadow_set_bit_load(jzgc);
@@ -1734,7 +1744,7 @@ static void irq_set_type(struct ingenic_gpio_chip *jzgc,
17341744
break;
17351745
case IRQ_TYPE_LEVEL_LOW:
17361746
default:
1737-
if (jzgc->jzpc->version >= ID_X1000) {
1747+
if (jzgc->jzpc->info->version >= ID_X1000) {
17381748
ingenic_gpio_shadow_set_bit(jzgc, reg2, offset, false);
17391749
ingenic_gpio_shadow_set_bit(jzgc, reg1, offset, false);
17401750
ingenic_gpio_shadow_set_bit_load(jzgc);
@@ -1768,7 +1778,7 @@ static void ingenic_gpio_irq_enable(struct irq_data *irqd)
17681778
struct ingenic_gpio_chip *jzgc = gpiochip_get_data(gc);
17691779
int irq = irqd->hwirq;
17701780

1771-
if (jzgc->jzpc->version >= ID_JZ4760)
1781+
if (jzgc->jzpc->info->version >= ID_JZ4760)
17721782
ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_INT, irq, true);
17731783
else
17741784
ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, true);
@@ -1784,7 +1794,7 @@ static void ingenic_gpio_irq_disable(struct irq_data *irqd)
17841794

17851795
ingenic_gpio_irq_mask(irqd);
17861796

1787-
if (jzgc->jzpc->version >= ID_JZ4760)
1797+
if (jzgc->jzpc->info->version >= ID_JZ4760)
17881798
ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_INT, irq, false);
17891799
else
17901800
ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_SELECT, irq, false);
@@ -1809,7 +1819,7 @@ static void ingenic_gpio_irq_ack(struct irq_data *irqd)
18091819
irq_set_type(jzgc, irq, IRQ_TYPE_EDGE_RISING);
18101820
}
18111821

1812-
if (jzgc->jzpc->version >= ID_JZ4760)
1822+
if (jzgc->jzpc->info->version >= ID_JZ4760)
18131823
ingenic_gpio_set_bit(jzgc, JZ4760_GPIO_FLAG, irq, false);
18141824
else
18151825
ingenic_gpio_set_bit(jzgc, JZ4740_GPIO_DATA, irq, true);
@@ -1866,7 +1876,7 @@ static void ingenic_gpio_irq_handler(struct irq_desc *desc)
18661876

18671877
chained_irq_enter(irq_chip, desc);
18681878

1869-
if (jzgc->jzpc->version >= ID_JZ4760)
1879+
if (jzgc->jzpc->info->version >= ID_JZ4760)
18701880
flag = ingenic_gpio_read_reg(jzgc, JZ4760_GPIO_FLAG);
18711881
else
18721882
flag = ingenic_gpio_read_reg(jzgc, JZ4740_GPIO_FLAG);
@@ -1948,7 +1958,7 @@ static int ingenic_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
19481958
struct ingenic_pinctrl *jzpc = jzgc->jzpc;
19491959
unsigned int pin = gc->base + offset;
19501960

1951-
if (jzpc->version >= ID_JZ4760)
1961+
if (jzpc->info->version >= ID_JZ4760)
19521962
return ingenic_get_pin_config(jzpc, pin, JZ4760_GPIO_PAT1);
19531963

19541964
if (ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_SELECT))
@@ -1974,13 +1984,13 @@ static int ingenic_pinmux_set_pin_fn(struct ingenic_pinctrl *jzpc,
19741984
dev_dbg(jzpc->dev, "set pin P%c%u to function %u\n",
19751985
'A' + offt, idx, func);
19761986

1977-
if (jzpc->version >= ID_X1000) {
1987+
if (jzpc->info->version >= ID_X1000) {
19781988
ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
19791989
ingenic_shadow_config_pin(jzpc, pin, GPIO_MSK, false);
19801990
ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, func & 0x2);
19811991
ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, func & 0x1);
19821992
ingenic_shadow_config_pin_load(jzpc, pin);
1983-
} else if (jzpc->version >= ID_JZ4760) {
1993+
} else if (jzpc->info->version >= ID_JZ4760) {
19841994
ingenic_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
19851995
ingenic_config_pin(jzpc, pin, GPIO_MSK, false);
19861996
ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, func & 0x2);
@@ -2033,12 +2043,12 @@ static int ingenic_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev,
20332043
dev_dbg(pctldev->dev, "set pin P%c%u to %sput\n",
20342044
'A' + offt, idx, input ? "in" : "out");
20352045

2036-
if (jzpc->version >= ID_X1000) {
2046+
if (jzpc->info->version >= ID_X1000) {
20372047
ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
20382048
ingenic_shadow_config_pin(jzpc, pin, GPIO_MSK, true);
20392049
ingenic_shadow_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, input);
20402050
ingenic_shadow_config_pin_load(jzpc, pin);
2041-
} else if (jzpc->version >= ID_JZ4760) {
2051+
} else if (jzpc->info->version >= ID_JZ4760) {
20422052
ingenic_config_pin(jzpc, pin, JZ4760_GPIO_INT, false);
20432053
ingenic_config_pin(jzpc, pin, GPIO_MSK, true);
20442054
ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT1, input);
@@ -2068,7 +2078,7 @@ static int ingenic_pinconf_get(struct pinctrl_dev *pctldev,
20682078
unsigned int offt = pin / PINS_PER_GPIO_CHIP;
20692079
bool pull;
20702080

2071-
if (jzpc->version >= ID_JZ4760)
2081+
if (jzpc->info->version >= ID_JZ4760)
20722082
pull = !ingenic_get_pin_config(jzpc, pin, JZ4760_GPIO_PEN);
20732083
else
20742084
pull = !ingenic_get_pin_config(jzpc, pin, JZ4740_GPIO_PULL_DIS);
@@ -2100,7 +2110,7 @@ static int ingenic_pinconf_get(struct pinctrl_dev *pctldev,
21002110
static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
21012111
unsigned int pin, unsigned int bias)
21022112
{
2103-
if (jzpc->version >= ID_X1830) {
2113+
if (jzpc->info->version >= ID_X1830) {
21042114
unsigned int idx = pin % PINS_PER_GPIO_CHIP;
21052115
unsigned int half = PINS_PER_GPIO_CHIP / 2;
21062116
unsigned int idxh = pin % half * 2;
@@ -2118,7 +2128,7 @@ static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
21182128
REG_SET(X1830_GPIO_PEH), bias << idxh);
21192129
}
21202130

2121-
} else if (jzpc->version >= ID_JZ4760) {
2131+
} else if (jzpc->info->version >= ID_JZ4760) {
21222132
ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PEN, !bias);
21232133
} else {
21242134
ingenic_config_pin(jzpc, pin, JZ4740_GPIO_PULL_DIS, !bias);
@@ -2128,7 +2138,7 @@ static void ingenic_set_bias(struct ingenic_pinctrl *jzpc,
21282138
static void ingenic_set_output_level(struct ingenic_pinctrl *jzpc,
21292139
unsigned int pin, bool high)
21302140
{
2131-
if (jzpc->version >= ID_JZ4760)
2141+
if (jzpc->info->version >= ID_JZ4760)
21322142
ingenic_config_pin(jzpc, pin, JZ4760_GPIO_PAT0, high);
21332143
else
21342144
ingenic_config_pin(jzpc, pin, JZ4740_GPIO_DATA, high);
@@ -2258,20 +2268,6 @@ static const struct regmap_config ingenic_pinctrl_regmap_config = {
22582268
.reg_stride = 4,
22592269
};
22602270

2261-
static const struct of_device_id ingenic_pinctrl_of_match[] = {
2262-
{ .compatible = "ingenic,jz4740-pinctrl", .data = (void *) ID_JZ4740 },
2263-
{ .compatible = "ingenic,jz4725b-pinctrl", .data = (void *)ID_JZ4725B },
2264-
{ .compatible = "ingenic,jz4760-pinctrl", .data = (void *) ID_JZ4760 },
2265-
{ .compatible = "ingenic,jz4760b-pinctrl", .data = (void *) ID_JZ4760B },
2266-
{ .compatible = "ingenic,jz4770-pinctrl", .data = (void *) ID_JZ4770 },
2267-
{ .compatible = "ingenic,jz4780-pinctrl", .data = (void *) ID_JZ4780 },
2268-
{ .compatible = "ingenic,x1000-pinctrl", .data = (void *) ID_X1000 },
2269-
{ .compatible = "ingenic,x1000e-pinctrl", .data = (void *) ID_X1000E },
2270-
{ .compatible = "ingenic,x1500-pinctrl", .data = (void *) ID_X1500 },
2271-
{ .compatible = "ingenic,x1830-pinctrl", .data = (void *) ID_X1830 },
2272-
{},
2273-
};
2274-
22752271
static const struct of_device_id ingenic_gpio_of_match[] __initconst = {
22762272
{ .compatible = "ingenic,jz4740-gpio", },
22772273
{ .compatible = "ingenic,jz4760-gpio", },
@@ -2391,29 +2387,7 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
23912387
}
23922388

23932389
jzpc->dev = dev;
2394-
jzpc->version = (enum jz_version)of_device_get_match_data(dev);
2395-
2396-
if (jzpc->version >= ID_X1830)
2397-
chip_info = &x1830_chip_info;
2398-
else if (jzpc->version >= ID_X1500)
2399-
chip_info = &x1500_chip_info;
2400-
else if (jzpc->version >= ID_X1000E)
2401-
chip_info = &x1000e_chip_info;
2402-
else if (jzpc->version >= ID_X1000)
2403-
chip_info = &x1000_chip_info;
2404-
else if (jzpc->version >= ID_JZ4780)
2405-
chip_info = &jz4780_chip_info;
2406-
else if (jzpc->version >= ID_JZ4770)
2407-
chip_info = &jz4770_chip_info;
2408-
else if (jzpc->version >= ID_JZ4760B)
2409-
chip_info = &jz4760b_chip_info;
2410-
else if (jzpc->version >= ID_JZ4760)
2411-
chip_info = &jz4760_chip_info;
2412-
else if (jzpc->version >= ID_JZ4725B)
2413-
chip_info = &jz4725b_chip_info;
2414-
else
2415-
chip_info = &jz4740_chip_info;
2416-
jzpc->info = chip_info;
2390+
jzpc->info = chip_info = of_device_get_match_data(dev);
24172391

24182392
pctl_desc = devm_kzalloc(&pdev->dev, sizeof(*pctl_desc), GFP_KERNEL);
24192393
if (!pctl_desc)
@@ -2482,6 +2456,20 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
24822456
return 0;
24832457
}
24842458

2459+
static const struct of_device_id ingenic_pinctrl_of_match[] = {
2460+
{ .compatible = "ingenic,jz4740-pinctrl", .data = &jz4740_chip_info },
2461+
{ .compatible = "ingenic,jz4725b-pinctrl", .data = &jz4725b_chip_info },
2462+
{ .compatible = "ingenic,jz4760-pinctrl", .data = &jz4760_chip_info },
2463+
{ .compatible = "ingenic,jz4760b-pinctrl", .data = &jz4760b_chip_info },
2464+
{ .compatible = "ingenic,jz4770-pinctrl", .data = &jz4770_chip_info },
2465+
{ .compatible = "ingenic,jz4780-pinctrl", .data = &jz4780_chip_info },
2466+
{ .compatible = "ingenic,x1000-pinctrl", .data = &x1000_chip_info },
2467+
{ .compatible = "ingenic,x1000e-pinctrl", .data = &x1000e_chip_info },
2468+
{ .compatible = "ingenic,x1500-pinctrl", .data = &x1500_chip_info },
2469+
{ .compatible = "ingenic,x1830-pinctrl", .data = &x1830_chip_info },
2470+
{},
2471+
};
2472+
24852473
static struct platform_driver ingenic_pinctrl_driver = {
24862474
.driver = {
24872475
.name = "pinctrl-ingenic",

0 commit comments

Comments
 (0)