Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 362991
b: refs/heads/master
c: aaed651
h: refs/heads/master
i:
  362989: d8e63b8
  362987: e54269c
  362983: ce5259d
  362975: 49f9a7d
v: v3
  • Loading branch information
David Woodhouse authored and Linus Walleij committed Mar 27, 2013
1 parent e25db30 commit 66b334b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 50cf7c8ab324de348990bb028ad9ed10872d527a
refs/heads/master: aaed651ff619993fb2101a22b32dd0664e54921b
33 changes: 21 additions & 12 deletions trunk/drivers/pinctrl/mvebu/pinctrl-mvebu.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,12 @@ static const struct pinctrl_ops mvebu_pinctrl_ops = {
.dt_free_map = mvebu_pinctrl_dt_free_map,
};

static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
static int _add_function(struct mvebu_pinctrl_function *funcs, int *funcsize,
const char *name)
{
if (*funcsize <= 0)
return -EOVERFLOW;

while (funcs->num_groups) {
/* function already there */
if (strcmp(funcs->name, name) == 0) {
Expand All @@ -488,48 +492,53 @@ static int _add_function(struct mvebu_pinctrl_function *funcs, const char *name)
}
funcs++;
}

/* append new unique function */
funcs->name = name;
funcs->num_groups = 1;
(*funcsize)--;

return 0;
}

static int mvebu_pinctrl_build_functions(struct platform_device *pdev,
struct mvebu_pinctrl *pctl)
{
struct mvebu_pinctrl_function *funcs;
int num = 0;
int num = 0, funcsize = pctl->desc.npins;
int n, s;

/* we allocate functions for number of pins and hope
* there are less unique functions than pins available */
funcs = devm_kzalloc(&pdev->dev, pctl->desc.npins *
* there are fewer unique functions than pins available */
funcs = devm_kzalloc(&pdev->dev, funcsize *
sizeof(struct mvebu_pinctrl_function), GFP_KERNEL);
if (!funcs)
return -ENOMEM;

for (n = 0; n < pctl->num_groups; n++) {
struct mvebu_pinctrl_group *grp = &pctl->groups[n];
for (s = 0; s < grp->num_settings; s++) {
int ret;

/* skip unsupported settings on this variant */
if (pctl->variant &&
!(pctl->variant & grp->settings[s].variant))
continue;

/* check for unique functions and count groups */
if (_add_function(funcs, grp->settings[s].name))
ret = _add_function(funcs, &funcsize,
grp->settings[s].name);
if (ret == -EOVERFLOW)
dev_err(&pdev->dev,
"More functions than pins(%d)\n",
pctl->desc.npins);
if (ret < 0)
continue;

num++;
}
}

/* with the number of unique functions and it's groups known,
reallocate functions and assign group names */
funcs = krealloc(funcs, num * sizeof(struct mvebu_pinctrl_function),
GFP_KERNEL);
if (!funcs)
return -ENOMEM;

pctl->num_functions = num;
pctl->functions = funcs;

Expand Down

0 comments on commit 66b334b

Please sign in to comment.