Commit 5d421ff5 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Linus Walleij

pinctrl: berlin: Make use of struct pinfunction

Since pin control provides a generic data type for the pin function,
use it in the driver.
Signed-off-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20240530085745.1539925-2-andy.shevchenko@gmail.comSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent a8f25485
...@@ -27,7 +27,7 @@ struct berlin_pinctrl { ...@@ -27,7 +27,7 @@ struct berlin_pinctrl {
struct regmap *regmap; struct regmap *regmap;
struct device *dev; struct device *dev;
const struct berlin_pinctrl_desc *desc; const struct berlin_pinctrl_desc *desc;
struct berlin_pinctrl_function *functions; struct pinfunction *functions;
unsigned nfunctions; unsigned nfunctions;
struct pinctrl_dev *pctrl_dev; struct pinctrl_dev *pctrl_dev;
}; };
...@@ -120,12 +120,12 @@ static const char *berlin_pinmux_get_function_name(struct pinctrl_dev *pctrl_dev ...@@ -120,12 +120,12 @@ static const char *berlin_pinmux_get_function_name(struct pinctrl_dev *pctrl_dev
static int berlin_pinmux_get_function_groups(struct pinctrl_dev *pctrl_dev, static int berlin_pinmux_get_function_groups(struct pinctrl_dev *pctrl_dev,
unsigned function, unsigned function,
const char * const **groups, const char * const **groups,
unsigned * const num_groups) unsigned * const ngroups)
{ {
struct berlin_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctrl_dev); struct berlin_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctrl_dev);
*groups = pctrl->functions[function].groups; *groups = pctrl->functions[function].groups;
*num_groups = pctrl->functions[function].ngroups; *ngroups = pctrl->functions[function].ngroups;
return 0; return 0;
} }
...@@ -153,7 +153,7 @@ static int berlin_pinmux_set(struct pinctrl_dev *pctrl_dev, ...@@ -153,7 +153,7 @@ static int berlin_pinmux_set(struct pinctrl_dev *pctrl_dev,
{ {
struct berlin_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctrl_dev); struct berlin_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctrl_dev);
const struct berlin_desc_group *group_desc = pctrl->desc->groups + group; const struct berlin_desc_group *group_desc = pctrl->desc->groups + group;
struct berlin_pinctrl_function *func = pctrl->functions + function; struct pinfunction *func = pctrl->functions + function;
struct berlin_desc_function *function_desc = struct berlin_desc_function *function_desc =
berlin_pinctrl_find_function_by_name(pctrl, group_desc, berlin_pinctrl_find_function_by_name(pctrl, group_desc,
func->name); func->name);
...@@ -180,7 +180,7 @@ static const struct pinmux_ops berlin_pinmux_ops = { ...@@ -180,7 +180,7 @@ static const struct pinmux_ops berlin_pinmux_ops = {
static int berlin_pinctrl_add_function(struct berlin_pinctrl *pctrl, static int berlin_pinctrl_add_function(struct berlin_pinctrl *pctrl,
const char *name) const char *name)
{ {
struct berlin_pinctrl_function *function = pctrl->functions; struct pinfunction *function = pctrl->functions;
while (function->name) { while (function->name) {
if (!strcmp(function->name, name)) { if (!strcmp(function->name, name)) {
...@@ -214,8 +214,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) ...@@ -214,8 +214,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
} }
/* we will reallocate later */ /* we will reallocate later */
pctrl->functions = kcalloc(max_functions, pctrl->functions = kcalloc(max_functions, sizeof(*pctrl->functions), GFP_KERNEL);
sizeof(*pctrl->functions), GFP_KERNEL);
if (!pctrl->functions) if (!pctrl->functions)
return -ENOMEM; return -ENOMEM;
...@@ -242,8 +241,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) ...@@ -242,8 +241,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
desc_function = desc_group->functions; desc_function = desc_group->functions;
while (desc_function->name) { while (desc_function->name) {
struct berlin_pinctrl_function struct pinfunction *function = pctrl->functions;
*function = pctrl->functions;
const char **groups; const char **groups;
bool found = false; bool found = false;
...@@ -264,16 +262,15 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) ...@@ -264,16 +262,15 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
function->groups = function->groups =
devm_kcalloc(&pdev->dev, devm_kcalloc(&pdev->dev,
function->ngroups, function->ngroups,
sizeof(char *), sizeof(*function->groups),
GFP_KERNEL); GFP_KERNEL);
if (!function->groups) { if (!function->groups) {
kfree(pctrl->functions); kfree(pctrl->functions);
return -ENOMEM; return -ENOMEM;
} }
} }
groups = function->groups; groups = (const char **)function->groups;
while (*groups) while (*groups)
groups++; groups++;
......
...@@ -28,12 +28,6 @@ struct berlin_pinctrl_desc { ...@@ -28,12 +28,6 @@ struct berlin_pinctrl_desc {
unsigned ngroups; unsigned ngroups;
}; };
struct berlin_pinctrl_function {
const char *name;
const char **groups;
unsigned ngroups;
};
#define BERLIN_PINCTRL_GROUP(_name, _offset, _width, _lsb, ...) \ #define BERLIN_PINCTRL_GROUP(_name, _offset, _width, _lsb, ...) \
{ \ { \
.name = _name, \ .name = _name, \
......
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