mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <shc_work@mail.ru>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] gpio: clps711x: Update driver
Date: Thu, 23 Jan 2014 21:22:06 +0400	[thread overview]
Message-ID: <1390497727-1625-3-git-send-email-shc_work@mail.ru> (raw)
In-Reply-To: <1390497727-1625-1-git-send-email-shc_work@mail.ru>

This patch updates the CLPS711X GPIO driver.
The update adds support for use with devicetree and
optimizes "probe" a bit.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/gpio/gpio-clps711x.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index feead51..2f12439 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru>
+ * Copyright (C) 2013-2014 Alexander Shiyan <shc_work@mail.ru>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -15,15 +15,18 @@
 
 static int clps711x_gpio_probe(struct device_d *dev)
 {
-	int err;
+	int err, id = dev->id;
 	void __iomem *dat, *dir = NULL, *dir_inv = NULL;
 	struct bgpio_chip *bgc;
 
-	if ((dev->id < 0) || (dev->id > 4))
+	if (dev->device_node)
+		id = of_alias_get_id(dev->device_node, "gpio");
+
+	if (id < 0 || id > 4)
 		return -ENODEV;
 
 	dat = dev_request_mem_region(dev, 0);
-	switch (dev->id) {
+	switch (id) {
 	case 3:
 		dir_inv = dev_request_mem_region(dev, 1);
 		break;
@@ -40,27 +43,35 @@ static int clps711x_gpio_probe(struct device_d *dev)
 		return -ENOMEM;
 
 	err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0);
-	if (err) {
-		free(bgc);
-		return err;
-	}
+	if (err)
+		goto out_err;
 
-	bgc->gc.base = dev->id * 8;
-	switch (dev->id) {
+	bgc->gc.base = id * 8;
+	switch (id) {
 	case 4:
 		bgc->gc.ngpio = 3;
 		break;
 	default:
-		bgc->gc.ngpio = 8;
 		break;
 	}
 
-	return gpiochip_add(&bgc->gc);
+	err = gpiochip_add(&bgc->gc);
+
+out_err:
+	if (err)
+		free(bgc);
+
+	return err;
 }
 
+static struct of_device_id __maybe_unused clps711x_gpio_dt_ids[] = {
+	{ .compatible = "cirrus,clps711x-gpio", },
+};
+
 static struct driver_d clps711x_gpio_driver = {
-	.name	= "clps711x-gpio",
-	.probe	= clps711x_gpio_probe,
+	.name		= "clps711x-gpio",
+	.probe		= clps711x_gpio_probe,
+	.of_compatible	= DRV_OF_COMPAT(clps711x_gpio_dt_ids),
 };
 
 static __init int clps711x_gpio_register(void)
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-01-23 17:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-23 17:22 [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Alexander Shiyan
2014-01-23 17:22 ` [PATCH 2/4] ARM: clps711x: Remove the special name for the syscon driver Alexander Shiyan
2014-01-23 17:22 ` Alexander Shiyan [this message]
2014-01-23 17:22 ` [PATCH 4/4] serial: clps711x: Update driver Alexander Shiyan
2014-01-24 22:10 ` [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function 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=1390497727-1625-3-git-send-email-shc_work@mail.ru \
    --to=shc_work@mail.ru \
    --cc=barebox@lists.infradead.org \
    /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