summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/pinmux.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-03-02 13:05:46 -0700
committerLinus Walleij <linus.walleij@linaro.org>2012-03-05 11:21:46 +0100
commit0e3db173e2b9fd3b82246516e72c17763eb5f98d (patch)
treece00c29c56332c925766f7f793d388b9670d802f /drivers/pinctrl/pinmux.c
parent7ecdb16fe63e5b356335ebdc236adfb48cef31e1 (diff)
downloadop-kernel-dev-0e3db173e2b9fd3b82246516e72c17763eb5f98d.zip
op-kernel-dev-0e3db173e2b9fd3b82246516e72c17763eb5f98d.tar.gz
pinctrl: add usecount to pins for muxing
Multiple mapping table entries could reference the same pin, and hence "own" it. This would be unusual now that pinctrl_get() represents a single state for a client device, but in the future when it represents all known states for a device, this is quite likely. Implement reference counting for pin ownership to handle this. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinmux.c')
-rw-r--r--drivers/pinctrl/pinmux.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index f0fb98d..56ca42e 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -83,11 +83,16 @@ static int pin_request(struct pinctrl_dev *pctldev,
goto out;
}
- if (desc->owner && strcmp(desc->owner, owner)) {
+ if (desc->usecount && strcmp(desc->owner, owner)) {
dev_err(pctldev->dev,
"pin already requested\n");
goto out;
}
+
+ desc->usecount++;
+ if (desc->usecount > 1)
+ return 0;
+
desc->owner = owner;
/* Let each pin increase references to this module */
@@ -111,12 +116,18 @@ static int pin_request(struct pinctrl_dev *pctldev,
else
status = 0;
- if (status)
+ if (status) {
dev_err(pctldev->dev, "->request on device %s failed for pin %d\n",
pctldev->desc->name, pin);
+ module_put(pctldev->owner);
+ }
+
out_free_pin:
- if (status)
- desc->owner = NULL;
+ if (status) {
+ desc->usecount--;
+ if (!desc->usecount)
+ desc->owner = NULL;
+ }
out:
if (status)
dev_err(pctldev->dev, "pin-%d (%s) status %d\n",
@@ -150,6 +161,10 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
return NULL;
}
+ desc->usecount--;
+ if (desc->usecount)
+ return NULL;
+
/*
* If there is no kind of request function for the pin we just assume
* we got it by default and proceed.
OpenPOWER on IntegriCloud