From: Grant Likely <grant.likely@secretlab.ca>
To: devicetree-discuss@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org,
Sascha Hauer <kernel@pengutronix.de>,
Rob Herring <rob.herring@calxeda.com>
Cc: linux-kernel@vger.kernel.org,
Grant Likely <grant.likely@secretlab.ca>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Kumar Gala <galak@kernel.crashing.org>
Subject: [RFC 2/8] gpio/powerpc: Eliminate duplication of of_get_named_gpio_flags()
Date: Tue, 8 Nov 2011 18:19:37 -0700 [thread overview]
Message-ID: <1320801583-12774-3-git-send-email-grant.likely@secretlab.ca> (raw)
In-Reply-To: <1320801583-12774-1-git-send-email-grant.likely@secretlab.ca>
A large chunk of qe_pin_request() is unnecessarily cut-and-paste
directly from of_get_named_gpio_flags(). This patch cuts out the
duplicate code and replaces it with a call to of_get_gpio().
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Kumar Gala <galak@kernel.crashing.org>
---
arch/powerpc/sysdev/qe_lib/gpio.c | 42 +++++++-----------------------------
1 files changed, 8 insertions(+), 34 deletions(-)
diff --git a/arch/powerpc/sysdev/qe_lib/gpio.c b/arch/powerpc/sysdev/qe_lib/gpio.c
index e23f23c..521e67a 100644
--- a/arch/powerpc/sysdev/qe_lib/gpio.c
+++ b/arch/powerpc/sysdev/qe_lib/gpio.c
@@ -139,14 +139,10 @@ struct qe_pin {
struct qe_pin *qe_pin_request(struct device_node *np, int index)
{
struct qe_pin *qe_pin;
- struct device_node *gpio_np;
struct gpio_chip *gc;
struct of_mm_gpio_chip *mm_gc;
struct qe_gpio_chip *qe_gc;
int err;
- int size;
- const void *gpio_spec;
- const u32 *gpio_cells;
unsigned long flags;
qe_pin = kzalloc(sizeof(*qe_pin), GFP_KERNEL);
@@ -155,45 +151,25 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
return ERR_PTR(-ENOMEM);
}
- err = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
- &gpio_np, &gpio_spec);
- if (err) {
- pr_debug("%s: can't parse gpios property\n", __func__);
+ err = of_get_gpio(np, index);
+ if (err < 0)
+ goto err0;
+ gc = gpio_to_chip(err);
+ if (WARN_ON(!gc))
goto err0;
- }
- if (!of_device_is_compatible(gpio_np, "fsl,mpc8323-qe-pario-bank")) {
+ if (!of_device_is_compatible(gc->of_node, "fsl,mpc8323-qe-pario-bank")) {
pr_debug("%s: tried to get a non-qe pin\n", __func__);
err = -EINVAL;
- goto err1;
- }
-
- gc = of_node_to_gpiochip(gpio_np);
- if (!gc) {
- pr_debug("%s: gpio controller %s isn't registered\n",
- np->full_name, gpio_np->full_name);
- err = -ENODEV;
- goto err1;
- }
-
- gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size);
- if (!gpio_cells || size != sizeof(*gpio_cells) ||
- *gpio_cells != gc->of_gpio_n_cells) {
- pr_debug("%s: wrong #gpio-cells for %s\n",
- np->full_name, gpio_np->full_name);
- err = -EINVAL;
- goto err1;
+ goto err0;
}
- err = gc->of_xlate(gc, np, gpio_spec, NULL);
- if (err < 0)
- goto err1;
-
mm_gc = to_of_mm_gpio_chip(gc);
qe_gc = to_qe_gpio_chip(mm_gc);
spin_lock_irqsave(&qe_gc->lock, flags);
+ err -= gc->base;
if (test_and_set_bit(QE_PIN_REQUESTED, &qe_gc->pin_flags[err]) == 0) {
qe_pin->controller = qe_gc;
qe_pin->num = err;
@@ -206,8 +182,6 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
if (!err)
return qe_pin;
-err1:
- of_node_put(gpio_np);
err0:
kfree(qe_pin);
pr_debug("%s failed with status %d\n", __func__, err);
--
1.7.5.4
next prev parent reply other threads:[~2011-11-09 1:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-09 1:19 [RFC 0/8] Initial DT clock bindings Grant Likely
2011-11-09 1:19 ` [RFC 1/8] gpio/microblaze: Eliminate duplication of of_get_named_gpio_flags() Grant Likely
2011-12-21 10:22 ` Michal Simek
2012-01-04 18:30 ` Grant Likely
2012-01-05 7:28 ` Michal Simek
2011-11-09 1:19 ` Grant Likely [this message]
2011-11-09 1:19 ` [RFC 3/8] of: create of_phandle_args to simplify return of phandle parsing data Grant Likely
2011-11-14 3:59 ` Shawn Guo
2011-11-16 18:47 ` Grant Likely
2011-11-21 15:50 ` Shawn Guo
2011-11-09 1:19 ` [RFC 4/8] of: Add device tree selftests Grant Likely
2011-11-09 1:19 ` [RFC 5/8] of: Add of_property_match_string() to find index into a string list Grant Likely
2011-11-09 1:19 ` [RFC 6/8] of: add clock providers Grant Likely
2011-11-09 2:49 ` Rob Herring
2011-11-14 2:14 ` Richard Zhao
2011-11-16 19:06 ` Grant Likely
2011-11-09 9:13 ` Sascha Hauer
2011-11-09 11:23 ` Cousson, Benoit
2011-11-09 11:49 ` Sascha Hauer
2011-11-11 19:57 ` Cousson, Benoit
2011-11-16 22:12 ` Grant Likely
2011-11-18 7:48 ` Sascha Hauer
2011-11-09 13:59 ` Rob Herring
2011-11-11 19:50 ` Cousson, Benoit
2011-11-09 13:31 ` Rob Herring
2011-11-09 18:39 ` Tony Lindgren
2011-11-21 15:37 ` Shawn Guo
2011-11-30 19:38 ` Grant Likely
2011-12-01 6:34 ` Shawn Guo
2011-11-09 1:19 ` [RFC 7/8] arm/clkdev: lookup clocks from OF " Grant Likely
2011-11-09 2:36 ` Rob Herring
2011-11-16 18:54 ` Grant Likely
2011-11-09 1:19 ` [RFC 8/8] dt/arm: versatile add clock parsing Grant Likely
2011-11-09 9:31 ` Sascha Hauer
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=1320801583-12774-3-git-send-email-grant.likely@secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=benh@kernel.crashing.org \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=galak@kernel.crashing.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rob.herring@calxeda.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
all inboxes | Powered by JetHome®