Commit 4b1643cb authored by Rafał Miłecki's avatar Rafał Miłecki Committed by Linus Walleij

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: default avatarRafał Miłecki <rafal@milecki.pl>
Link: https://lore.kernel.org/r/20211222064344.14624-1-zajec5@gmail.comSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent aa63e656
...@@ -146,6 +146,8 @@ config PINCTRL_NS ...@@ -146,6 +146,8 @@ config PINCTRL_NS
depends on OF && (ARCH_BCM_5301X || COMPILE_TEST) depends on OF && (ARCH_BCM_5301X || COMPILE_TEST)
select PINMUX select PINMUX
select GENERIC_PINCONF select GENERIC_PINCONF
select GENERIC_PINCTRL_GROUPS
select GENERIC_PINMUX_FUNCTIONS
default ARCH_BCM_5301X default ARCH_BCM_5301X
help help
Say yes here to enable the Broadcom NS SoC pins driver. Say yes here to enable the Broadcom NS SoC pins driver.
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "../core.h"
#include "../pinmux.h"
#define FLAG_BCM4708 BIT(1) #define FLAG_BCM4708 BIT(1)
#define FLAG_BCM4709 BIT(2) #define FLAG_BCM4709 BIT(2)
#define FLAG_BCM53012 BIT(3) #define FLAG_BCM53012 BIT(3)
...@@ -25,10 +28,6 @@ struct ns_pinctrl { ...@@ -25,10 +28,6 @@ struct ns_pinctrl {
void __iomem *base; void __iomem *base;
struct pinctrl_desc pctldesc; struct pinctrl_desc pctldesc;
struct ns_pinctrl_group *groups;
unsigned int num_groups;
struct ns_pinctrl_function *functions;
unsigned int num_functions;
}; };
/* /*
...@@ -65,22 +64,22 @@ static const struct pinctrl_pin_desc ns_pinctrl_pins[] = { ...@@ -65,22 +64,22 @@ static const struct pinctrl_pin_desc ns_pinctrl_pins[] = {
struct ns_pinctrl_group { struct ns_pinctrl_group {
const char *name; const char *name;
const unsigned int *pins; unsigned int *pins;
const unsigned int num_pins; const unsigned int num_pins;
unsigned int chipsets; unsigned int chipsets;
}; };
static const unsigned int spi_pins[] = { 0, 1, 2, 3 }; static unsigned int spi_pins[] = { 0, 1, 2, 3 };
static const unsigned int i2c_pins[] = { 4, 5 }; static unsigned int i2c_pins[] = { 4, 5 };
static const unsigned int mdio_pins[] = { 6, 7 }; static unsigned int mdio_pins[] = { 6, 7 };
static const unsigned int pwm0_pins[] = { 8 }; static unsigned int pwm0_pins[] = { 8 };
static const unsigned int pwm1_pins[] = { 9 }; static unsigned int pwm1_pins[] = { 9 };
static const unsigned int pwm2_pins[] = { 10 }; static unsigned int pwm2_pins[] = { 10 };
static const unsigned int pwm3_pins[] = { 11 }; static unsigned int pwm3_pins[] = { 11 };
static const unsigned int uart1_pins[] = { 12, 13, 14, 15 }; static unsigned int uart1_pins[] = { 12, 13, 14, 15 };
static const unsigned int uart2_pins[] = { 16, 17 }; static unsigned int uart2_pins[] = { 16, 17 };
static const unsigned int sdio_pwr_pins[] = { 22 }; static unsigned int sdio_pwr_pins[] = { 22 };
static const unsigned int sdio_1p8v_pins[] = { 23 }; static unsigned int sdio_1p8v_pins[] = { 23 };
#define NS_GROUP(_name, _pins, _chipsets) \ #define NS_GROUP(_name, _pins, _chipsets) \
{ \ { \
...@@ -146,38 +145,10 @@ static const struct ns_pinctrl_function ns_pinctrl_functions[] = { ...@@ -146,38 +145,10 @@ static const struct ns_pinctrl_function ns_pinctrl_functions[] = {
* Groups code * Groups code
*/ */
static int ns_pinctrl_get_groups_count(struct pinctrl_dev *pctrl_dev)
{
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
return ns_pinctrl->num_groups;
}
static const char *ns_pinctrl_get_group_name(struct pinctrl_dev *pctrl_dev,
unsigned int selector)
{
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
return ns_pinctrl->groups[selector].name;
}
static int ns_pinctrl_get_group_pins(struct pinctrl_dev *pctrl_dev,
unsigned int selector,
const unsigned int **pins,
unsigned int *num_pins)
{
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
*pins = ns_pinctrl->groups[selector].pins;
*num_pins = ns_pinctrl->groups[selector].num_pins;
return 0;
}
static const struct pinctrl_ops ns_pinctrl_ops = { static const struct pinctrl_ops ns_pinctrl_ops = {
.get_groups_count = ns_pinctrl_get_groups_count, .get_groups_count = pinctrl_generic_get_group_count,
.get_group_name = ns_pinctrl_get_group_name, .get_group_name = pinctrl_generic_get_group_name,
.get_group_pins = ns_pinctrl_get_group_pins, .get_group_pins = pinctrl_generic_get_group_pins,
.dt_node_to_map = pinconf_generic_dt_node_to_map_group, .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
.dt_free_map = pinconf_generic_dt_free_map, .dt_free_map = pinconf_generic_dt_free_map,
}; };
...@@ -186,48 +157,22 @@ static const struct pinctrl_ops ns_pinctrl_ops = { ...@@ -186,48 +157,22 @@ static const struct pinctrl_ops ns_pinctrl_ops = {
* Functions code * Functions code
*/ */
static int ns_pinctrl_get_functions_count(struct pinctrl_dev *pctrl_dev)
{
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
return ns_pinctrl->num_functions;
}
static const char *ns_pinctrl_get_function_name(struct pinctrl_dev *pctrl_dev,
unsigned int selector)
{
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
return ns_pinctrl->functions[selector].name;
}
static int ns_pinctrl_get_function_groups(struct pinctrl_dev *pctrl_dev,
unsigned int selector,
const char * const **groups,
unsigned * const num_groups)
{
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
*groups = ns_pinctrl->functions[selector].groups;
*num_groups = ns_pinctrl->functions[selector].num_groups;
return 0;
}
static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev, static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
unsigned int func_select, unsigned int func_select,
unsigned int grp_select) unsigned int group_selector)
{ {
struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
struct group_desc *group;
u32 unset = 0; u32 unset = 0;
u32 tmp; u32 tmp;
int i; int i;
for (i = 0; i < ns_pinctrl->groups[grp_select].num_pins; i++) { group = pinctrl_generic_get_group(pctrl_dev, group_selector);
int pin_number = ns_pinctrl->groups[grp_select].pins[i]; if (!group)
return -EINVAL;
unset |= BIT(pin_number); for (i = 0; i < group->num_pins; i++)
} unset |= BIT(group->pins[i]);
tmp = readl(ns_pinctrl->base); tmp = readl(ns_pinctrl->base);
tmp &= ~unset; tmp &= ~unset;
...@@ -237,9 +182,9 @@ static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev, ...@@ -237,9 +182,9 @@ static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
} }
static const struct pinmux_ops ns_pinctrl_pmxops = { static const struct pinmux_ops ns_pinctrl_pmxops = {
.get_functions_count = ns_pinctrl_get_functions_count, .get_functions_count = pinmux_generic_get_function_count,
.get_function_name = ns_pinctrl_get_function_name, .get_function_name = pinmux_generic_get_function_name,
.get_function_groups = ns_pinctrl_get_function_groups, .get_function_groups = pinmux_generic_get_function_groups,
.set_mux = ns_pinctrl_set_mux, .set_mux = ns_pinctrl_set_mux,
}; };
...@@ -267,8 +212,6 @@ static int ns_pinctrl_probe(struct platform_device *pdev) ...@@ -267,8 +212,6 @@ static int ns_pinctrl_probe(struct platform_device *pdev)
struct ns_pinctrl *ns_pinctrl; struct ns_pinctrl *ns_pinctrl;
struct pinctrl_desc *pctldesc; struct pinctrl_desc *pctldesc;
struct pinctrl_pin_desc *pin; struct pinctrl_pin_desc *pin;
struct ns_pinctrl_group *group;
struct ns_pinctrl_function *function;
struct resource *res; struct resource *res;
int i; int i;
...@@ -315,43 +258,33 @@ static int ns_pinctrl_probe(struct platform_device *pdev) ...@@ -315,43 +258,33 @@ static int ns_pinctrl_probe(struct platform_device *pdev)
} }
} }
ns_pinctrl->groups = devm_kcalloc(dev, ARRAY_SIZE(ns_pinctrl_groups), /* Register */
sizeof(struct ns_pinctrl_group),
GFP_KERNEL);
if (!ns_pinctrl->groups)
return -ENOMEM;
for (i = 0, group = &ns_pinctrl->groups[0];
i < ARRAY_SIZE(ns_pinctrl_groups); i++) {
const struct ns_pinctrl_group *src = &ns_pinctrl_groups[i];
if (src->chipsets & ns_pinctrl->chipset_flag) { ns_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, ns_pinctrl);
memcpy(group++, src, sizeof(*src)); if (IS_ERR(ns_pinctrl->pctldev)) {
ns_pinctrl->num_groups++; dev_err(dev, "Failed to register pinctrl\n");
} return PTR_ERR(ns_pinctrl->pctldev);
} }
ns_pinctrl->functions = devm_kcalloc(dev, for (i = 0; i < ARRAY_SIZE(ns_pinctrl_groups); i++) {
ARRAY_SIZE(ns_pinctrl_functions), const struct ns_pinctrl_group *group = &ns_pinctrl_groups[i];
sizeof(struct ns_pinctrl_function),
GFP_KERNEL);
if (!ns_pinctrl->functions)
return -ENOMEM;
for (i = 0, function = &ns_pinctrl->functions[0];
i < ARRAY_SIZE(ns_pinctrl_functions); i++) {
const struct ns_pinctrl_function *src = &ns_pinctrl_functions[i];
if (src->chipsets & ns_pinctrl->chipset_flag) { if (!(group->chipsets & ns_pinctrl->chipset_flag))
memcpy(function++, src, sizeof(*src)); continue;
ns_pinctrl->num_functions++;
} pinctrl_generic_add_group(ns_pinctrl->pctldev, group->name,
group->pins, group->num_pins, NULL);
} }
/* Register */ for (i = 0; i < ARRAY_SIZE(ns_pinctrl_functions); i++) {
const struct ns_pinctrl_function *function = &ns_pinctrl_functions[i];
ns_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, ns_pinctrl); if (!(function->chipsets & ns_pinctrl->chipset_flag))
if (IS_ERR(ns_pinctrl->pctldev)) { continue;
dev_err(dev, "Failed to register pinctrl\n");
return PTR_ERR(ns_pinctrl->pctldev); pinmux_generic_add_function(ns_pinctrl->pctldev, function->name,
function->groups,
function->num_groups, NULL);
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment