Skip to content

Commit 4b1643c

Browse files
Rafał MiłeckiLinus Walleij
authored andcommitted
pinctrl: bcm: ns: use generic groups & functions helpers
This simplifies ns driver and gets rid of ~70 lines of code. "const" had to be dropped from "struct ns_pinctrl_group" @pins to match "struct group_desc" @pins and pinctrl_generic_add_group(). Otherwise it would cause: drivers/pinctrl/bcm/pinctrl-ns.c: In function 'ns_pinctrl_probe': drivers/pinctrl/bcm/pinctrl-ns.c:277:13: warning: passing argument 3 of 'pinctrl_generic_add_group' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 277 | group->pins, group->num_pins, NULL); | ~~~~~^~~~~~ Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Link: https://lore.kernel.org/r/20211222064344.14624-1-zajec5@gmail.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent aa63e65 commit 4b1643c

2 files changed

Lines changed: 50 additions & 115 deletions

File tree

drivers/pinctrl/bcm/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ config PINCTRL_NS
146146
depends on OF && (ARCH_BCM_5301X || COMPILE_TEST)
147147
select PINMUX
148148
select GENERIC_PINCONF
149+
select GENERIC_PINCTRL_GROUPS
150+
select GENERIC_PINMUX_FUNCTIONS
149151
default ARCH_BCM_5301X
150152
help
151153
Say yes here to enable the Broadcom NS SoC pins driver.

drivers/pinctrl/bcm/pinctrl-ns.c

Lines changed: 48 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <linux/platform_device.h>
1515
#include <linux/slab.h>
1616

17+
#include "../core.h"
18+
#include "../pinmux.h"
19+
1720
#define FLAG_BCM4708 BIT(1)
1821
#define FLAG_BCM4709 BIT(2)
1922
#define FLAG_BCM53012 BIT(3)
@@ -25,10 +28,6 @@ struct ns_pinctrl {
2528
void __iomem *base;
2629

2730
struct pinctrl_desc pctldesc;
28-
struct ns_pinctrl_group *groups;
29-
unsigned int num_groups;
30-
struct ns_pinctrl_function *functions;
31-
unsigned int num_functions;
3231
};
3332

3433
/*
@@ -65,22 +64,22 @@ static const struct pinctrl_pin_desc ns_pinctrl_pins[] = {
6564

6665
struct ns_pinctrl_group {
6766
const char *name;
68-
const unsigned int *pins;
67+
unsigned int *pins;
6968
const unsigned int num_pins;
7069
unsigned int chipsets;
7170
};
7271

73-
static const unsigned int spi_pins[] = { 0, 1, 2, 3 };
74-
static const unsigned int i2c_pins[] = { 4, 5 };
75-
static const unsigned int mdio_pins[] = { 6, 7 };
76-
static const unsigned int pwm0_pins[] = { 8 };
77-
static const unsigned int pwm1_pins[] = { 9 };
78-
static const unsigned int pwm2_pins[] = { 10 };
79-
static const unsigned int pwm3_pins[] = { 11 };
80-
static const unsigned int uart1_pins[] = { 12, 13, 14, 15 };
81-
static const unsigned int uart2_pins[] = { 16, 17 };
82-
static const unsigned int sdio_pwr_pins[] = { 22 };
83-
static const unsigned int sdio_1p8v_pins[] = { 23 };
72+
static unsigned int spi_pins[] = { 0, 1, 2, 3 };
73+
static unsigned int i2c_pins[] = { 4, 5 };
74+
static unsigned int mdio_pins[] = { 6, 7 };
75+
static unsigned int pwm0_pins[] = { 8 };
76+
static unsigned int pwm1_pins[] = { 9 };
77+
static unsigned int pwm2_pins[] = { 10 };
78+
static unsigned int pwm3_pins[] = { 11 };
79+
static unsigned int uart1_pins[] = { 12, 13, 14, 15 };
80+
static unsigned int uart2_pins[] = { 16, 17 };
81+
static unsigned int sdio_pwr_pins[] = { 22 };
82+
static unsigned int sdio_1p8v_pins[] = { 23 };
8483

8584
#define NS_GROUP(_name, _pins, _chipsets) \
8685
{ \
@@ -146,38 +145,10 @@ static const struct ns_pinctrl_function ns_pinctrl_functions[] = {
146145
* Groups code
147146
*/
148147

149-
static int ns_pinctrl_get_groups_count(struct pinctrl_dev *pctrl_dev)
150-
{
151-
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
152-
153-
return ns_pinctrl->num_groups;
154-
}
155-
156-
static const char *ns_pinctrl_get_group_name(struct pinctrl_dev *pctrl_dev,
157-
unsigned int selector)
158-
{
159-
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
160-
161-
return ns_pinctrl->groups[selector].name;
162-
}
163-
164-
static int ns_pinctrl_get_group_pins(struct pinctrl_dev *pctrl_dev,
165-
unsigned int selector,
166-
const unsigned int **pins,
167-
unsigned int *num_pins)
168-
{
169-
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
170-
171-
*pins = ns_pinctrl->groups[selector].pins;
172-
*num_pins = ns_pinctrl->groups[selector].num_pins;
173-
174-
return 0;
175-
}
176-
177148
static const struct pinctrl_ops ns_pinctrl_ops = {
178-
.get_groups_count = ns_pinctrl_get_groups_count,
179-
.get_group_name = ns_pinctrl_get_group_name,
180-
.get_group_pins = ns_pinctrl_get_group_pins,
149+
.get_groups_count = pinctrl_generic_get_group_count,
150+
.get_group_name = pinctrl_generic_get_group_name,
151+
.get_group_pins = pinctrl_generic_get_group_pins,
181152
.dt_node_to_map = pinconf_generic_dt_node_to_map_group,
182153
.dt_free_map = pinconf_generic_dt_free_map,
183154
};
@@ -186,48 +157,22 @@ static const struct pinctrl_ops ns_pinctrl_ops = {
186157
* Functions code
187158
*/
188159

189-
static int ns_pinctrl_get_functions_count(struct pinctrl_dev *pctrl_dev)
190-
{
191-
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
192-
193-
return ns_pinctrl->num_functions;
194-
}
195-
196-
static const char *ns_pinctrl_get_function_name(struct pinctrl_dev *pctrl_dev,
197-
unsigned int selector)
198-
{
199-
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
200-
201-
return ns_pinctrl->functions[selector].name;
202-
}
203-
204-
static int ns_pinctrl_get_function_groups(struct pinctrl_dev *pctrl_dev,
205-
unsigned int selector,
206-
const char * const **groups,
207-
unsigned * const num_groups)
208-
{
209-
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
210-
211-
*groups = ns_pinctrl->functions[selector].groups;
212-
*num_groups = ns_pinctrl->functions[selector].num_groups;
213-
214-
return 0;
215-
}
216-
217160
static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
218161
unsigned int func_select,
219-
unsigned int grp_select)
162+
unsigned int group_selector)
220163
{
221164
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
165+
struct group_desc *group;
222166
u32 unset = 0;
223167
u32 tmp;
224168
int i;
225169

226-
for (i = 0; i < ns_pinctrl->groups[grp_select].num_pins; i++) {
227-
int pin_number = ns_pinctrl->groups[grp_select].pins[i];
170+
group = pinctrl_generic_get_group(pctrl_dev, group_selector);
171+
if (!group)
172+
return -EINVAL;
228173

229-
unset |= BIT(pin_number);
230-
}
174+
for (i = 0; i < group->num_pins; i++)
175+
unset |= BIT(group->pins[i]);
231176

232177
tmp = readl(ns_pinctrl->base);
233178
tmp &= ~unset;
@@ -237,9 +182,9 @@ static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
237182
}
238183

239184
static const struct pinmux_ops ns_pinctrl_pmxops = {
240-
.get_functions_count = ns_pinctrl_get_functions_count,
241-
.get_function_name = ns_pinctrl_get_function_name,
242-
.get_function_groups = ns_pinctrl_get_function_groups,
185+
.get_functions_count = pinmux_generic_get_function_count,
186+
.get_function_name = pinmux_generic_get_function_name,
187+
.get_function_groups = pinmux_generic_get_function_groups,
243188
.set_mux = ns_pinctrl_set_mux,
244189
};
245190

@@ -267,8 +212,6 @@ static int ns_pinctrl_probe(struct platform_device *pdev)
267212
struct ns_pinctrl *ns_pinctrl;
268213
struct pinctrl_desc *pctldesc;
269214
struct pinctrl_pin_desc *pin;
270-
struct ns_pinctrl_group *group;
271-
struct ns_pinctrl_function *function;
272215
struct resource *res;
273216
int i;
274217

@@ -315,43 +258,33 @@ static int ns_pinctrl_probe(struct platform_device *pdev)
315258
}
316259
}
317260

318-
ns_pinctrl->groups = devm_kcalloc(dev, ARRAY_SIZE(ns_pinctrl_groups),
319-
sizeof(struct ns_pinctrl_group),
320-
GFP_KERNEL);
321-
if (!ns_pinctrl->groups)
322-
return -ENOMEM;
323-
for (i = 0, group = &ns_pinctrl->groups[0];
324-
i < ARRAY_SIZE(ns_pinctrl_groups); i++) {
325-
const struct ns_pinctrl_group *src = &ns_pinctrl_groups[i];
261+
/* Register */
326262

327-
if (src->chipsets & ns_pinctrl->chipset_flag) {
328-
memcpy(group++, src, sizeof(*src));
329-
ns_pinctrl->num_groups++;
330-
}
263+
ns_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, ns_pinctrl);
264+
if (IS_ERR(ns_pinctrl->pctldev)) {
265+
dev_err(dev, "Failed to register pinctrl\n");
266+
return PTR_ERR(ns_pinctrl->pctldev);
331267
}
332268

333-
ns_pinctrl->functions = devm_kcalloc(dev,
334-
ARRAY_SIZE(ns_pinctrl_functions),
335-
sizeof(struct ns_pinctrl_function),
336-
GFP_KERNEL);
337-
if (!ns_pinctrl->functions)
338-
return -ENOMEM;
339-
for (i = 0, function = &ns_pinctrl->functions[0];
340-
i < ARRAY_SIZE(ns_pinctrl_functions); i++) {
341-
const struct ns_pinctrl_function *src = &ns_pinctrl_functions[i];
269+
for (i = 0; i < ARRAY_SIZE(ns_pinctrl_groups); i++) {
270+
const struct ns_pinctrl_group *group = &ns_pinctrl_groups[i];
342271

343-
if (src->chipsets & ns_pinctrl->chipset_flag) {
344-
memcpy(function++, src, sizeof(*src));
345-
ns_pinctrl->num_functions++;
346-
}
272+
if (!(group->chipsets & ns_pinctrl->chipset_flag))
273+
continue;
274+
275+
pinctrl_generic_add_group(ns_pinctrl->pctldev, group->name,
276+
group->pins, group->num_pins, NULL);
347277
}
348278

349-
/* Register */
279+
for (i = 0; i < ARRAY_SIZE(ns_pinctrl_functions); i++) {
280+
const struct ns_pinctrl_function *function = &ns_pinctrl_functions[i];
350281

351-
ns_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, ns_pinctrl);
352-
if (IS_ERR(ns_pinctrl->pctldev)) {
353-
dev_err(dev, "Failed to register pinctrl\n");
354-
return PTR_ERR(ns_pinctrl->pctldev);
282+
if (!(function->chipsets & ns_pinctrl->chipset_flag))
283+
continue;
284+
285+
pinmux_generic_add_function(ns_pinctrl->pctldev, function->name,
286+
function->groups,
287+
function->num_groups, NULL);
355288
}
356289

357290
return 0;

0 commit comments

Comments
 (0)