aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl
diff options
context:
space:
mode:
authorSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>2014-01-30 17:38:12 -0500
committerSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>2014-02-25 12:34:34 -0500
commit8d898fd5966caefb60aeb1ba6b33a3ff1b768db0 (patch)
treec9921a2d76fa0bf41f6f8496d87e83bdc0d17d24 /drivers/pinctrl
parent38dbfb59d1175ef458d006556061adeaa8751b72 (diff)
pinctrl: mvebu: count unnamed controls and allocate name buffer
pinctrl-mvebu allows SoCs to pass unnamed controls that will get an auto-generated name of "mpp<PIN#>". Currently, we are allocating name buffers on a per-control basis while looping over passed controls. This counts the total number of unnamed controls and allocates a global name buffer instead. The new buffer is then used while assigning controls to pinctrl groups later. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Tested-by: Andrew Lunn <andrew@lunn.ch> Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r--drivers/pinctrl/mvebu/pinctrl-mvebu.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
index 0fd1ad31fbf9..d47650fc5119 100644
--- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
+++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
@@ -598,6 +598,9 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
598 void __iomem *base; 598 void __iomem *base;
599 struct pinctrl_pin_desc *pdesc; 599 struct pinctrl_pin_desc *pdesc;
600 unsigned gid, n, k; 600 unsigned gid, n, k;
601 unsigned size, noname = 0;
602 char *noname_buf;
603 void *p;
601 int ret; 604 int ret;
602 605
603 if (!soc || !soc->controls || !soc->modes) { 606 if (!soc || !soc->controls || !soc->modes) {
@@ -660,6 +663,7 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
660 sprintf(names + 8*k, "mpp%d", ctrl->pid+k); 663 sprintf(names + 8*k, "mpp%d", ctrl->pid+k);
661 ctrl->name = names; 664 ctrl->name = names;
662 pctl->num_groups += ctrl->npins; 665 pctl->num_groups += ctrl->npins;
666 noname += ctrl->npins;
663 } 667 }
664 668
665 pdesc = devm_kzalloc(&pdev->dev, pctl->desc.npins * 669 pdesc = devm_kzalloc(&pdev->dev, pctl->desc.npins *
@@ -673,12 +677,17 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
673 pdesc[n].number = n; 677 pdesc[n].number = n;
674 pctl->desc.pins = pdesc; 678 pctl->desc.pins = pdesc;
675 679
676 pctl->groups = devm_kzalloc(&pdev->dev, pctl->num_groups * 680 /*
677 sizeof(struct mvebu_pinctrl_group), GFP_KERNEL); 681 * allocate groups and name buffers for unnamed groups.
678 if (!pctl->groups) { 682 */
679 dev_err(&pdev->dev, "failed to alloc pinctrl groups\n"); 683 size = pctl->num_groups * sizeof(*pctl->groups) + noname * 8;
684 p = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
685 if (!p) {
686 dev_err(&pdev->dev, "failed to alloc group data\n");
680 return -ENOMEM; 687 return -ENOMEM;
681 } 688 }
689 pctl->groups = p;
690 noname_buf = p + pctl->num_groups * sizeof(*pctl->groups);
682 691
683 /* assign mpp controls to groups */ 692 /* assign mpp controls to groups */
684 gid = 0; 693 gid = 0;
@@ -692,15 +701,20 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
692 701
693 /* generic mvebu register control maps to a number of groups */ 702 /* generic mvebu register control maps to a number of groups */
694 if (!ctrl->mpp_get && !ctrl->mpp_set) { 703 if (!ctrl->mpp_get && !ctrl->mpp_set) {
704 pctl->groups[gid].name = noname_buf;
695 pctl->groups[gid].npins = 1; 705 pctl->groups[gid].npins = 1;
706 sprintf(noname_buf, "mpp%d", ctrl->pid+0);
707 noname_buf += 8;
696 708
697 for (k = 1; k < ctrl->npins; k++) { 709 for (k = 1; k < ctrl->npins; k++) {
698 gid++; 710 gid++;
699 pctl->groups[gid].gid = gid; 711 pctl->groups[gid].gid = gid;
700 pctl->groups[gid].ctrl = ctrl; 712 pctl->groups[gid].ctrl = ctrl;
701 pctl->groups[gid].name = &ctrl->name[8*k]; 713 pctl->groups[gid].name = noname_buf;
702 pctl->groups[gid].pins = &ctrl->pins[k]; 714 pctl->groups[gid].pins = &ctrl->pins[k];
703 pctl->groups[gid].npins = 1; 715 pctl->groups[gid].npins = 1;
716 sprintf(noname_buf, "mpp%d", ctrl->pid+k);
717 noname_buf += 8;
704 } 718 }
705 } 719 }
706 gid++; 720 gid++;