From: Stephen Warren <swarren@nvidia.com>
To: Linus Walleij <linus.walleij@stericsson.com>
Cc: Linus Walleij <linus.walleij@linaro.org>, <B29396@freescale.com>,
<s.hauer@pengutronix.de>, <dongas86@gmail.com>,
<shawn.guo@linaro.org>, <thomas.abraham@linaro.org>,
<tony@atomide.com>, <linux-kernel@vger.kernel.org>,
Stephen Warren <swarren@nvidia.com>
Subject: [PATCH V2 3/6] pinctrl: Add usecount to pins for muxing
Date: Tue, 28 Feb 2012 13:27:29 -0700 [thread overview]
Message-ID: <1330460852-23486-4-git-send-email-swarren@nvidia.com> (raw)
In-Reply-To: <1330460852-23486-1-git-send-email-swarren@nvidia.com>
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>
---
v2: Added kerneldoc for @usecount and @owner fields - the latter was missing
from a previous patch.
drivers/pinctrl/core.h | 12 +++++++++---
drivers/pinctrl/pinmux.c | 23 +++++++++++++++++++----
2 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index de8df86..0bc52ec 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -82,9 +82,14 @@ struct pinctrl_setting {
* @name: a name for the pin, e.g. the name of the pin/pad/finger on a
* datasheet or such
* @dynamic_name: if the name of this pin was dynamically allocated
- * @mux_requested: whether the pin is already requested by pinmux or not
- * @mux_function: a named muxing function for the pin that will be passed to
- * subdrivers and shown in debugfs etc
+ * @usecount: If zero, the pin is not claimed, and @owner should be NULL.
+ * If non-zero, this pin is claimed by @owner. This field is an integer
+ * rather than a boolean, since pinctrl_get() might process multiple
+ * mapping table entries that refer to, and hence claim, the same group
+ * or pin, and each of these will increment the @usecount.
+ * @owner: The name of the entity owning the pin. Typically, this is the name
+ * of the device that called pinctrl_get(). Alternatively, it may be the
+ * name of the GPIO passed to pinctrl_request_gpio().
*/
struct pin_desc {
struct pinctrl_dev *pctldev;
@@ -92,6 +97,7 @@ struct pin_desc {
bool dynamic_name;
/* These fields only added when supporting pinmux drivers */
#ifdef CONFIG_PINMUX
+ unsigned usecount;
const char *owner;
#endif
};
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 2318d85..2d1aaf8 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.
--
1.7.0.4
next prev parent reply other threads:[~2012-02-28 20:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-28 20:27 [PATCH V2 0/6] pinctrl: API rework, pinconfig in mapping table, Stephen Warren
2012-02-28 20:27 ` [PATCH V2 1/6] pinctrl: Fix and simplify locking Stephen Warren
2012-02-28 20:27 ` [PATCH V2 2/6] pinctrl: Refactor struct pinctrl handling in core.c vs pinmux.c Stephen Warren
2012-02-28 20:27 ` Stephen Warren [this message]
2012-02-28 20:27 ` [PATCH V2 4/6] pinctrl: API changes to support multiple states per device Stephen Warren
2012-02-29 6:46 ` Dong Aisheng
2012-02-29 17:22 ` Stephen Warren
2012-03-01 3:09 ` Dong Aisheng
2012-02-28 20:27 ` [PATCH V2 5/6] pinctrl: Enhance mapping table to support pin config operations Stephen Warren
2012-03-01 8:46 ` Dong Aisheng
2012-03-01 16:52 ` Stephen Warren
2012-03-02 3:46 ` Dong Aisheng
2012-03-02 22:49 ` Stephen Warren
2012-03-05 7:58 ` Dong Aisheng
2012-02-28 20:27 ` [PATCH V2 6/6] pinctrl: fix case of Tegra30's foo_groups[] arrays Stephen Warren
2012-02-29 16:46 ` [PATCH V2 0/6] pinctrl: API rework, pinconfig in mapping table, Linus Walleij
2012-02-29 17:42 ` Stephen Warren
2012-02-29 18:09 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1330460852-23486-4-git-send-email-swarren@nvidia.com \
--to=swarren@nvidia.com \
--cc=B29396@freescale.com \
--cc=dongas86@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linus.walleij@stericsson.com \
--cc=linux-kernel@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawn.guo@linaro.org \
--cc=thomas.abraham@linaro.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).