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/5] GPIO: i.MX: Rewrite driver for using generic GPIO code
Date: Sat, 20 Apr 2013 08:18:50 +0400	[thread overview]
Message-ID: <1366431532-29121-4-git-send-email-shc_work@mail.ru> (raw)
In-Reply-To: <1366431532-29121-1-git-send-email-shc_work@mail.ru>


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 arch/arm/Kconfig        |   1 -
 drivers/gpio/Kconfig    |   1 +
 drivers/gpio/gpio-imx.c | 125 ++++++++++++------------------------------------
 3 files changed, 31 insertions(+), 96 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index bb9b47b..5607754 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -72,7 +72,6 @@ config ARCH_HIGHBANK
 
 config ARCH_IMX
 	bool "Freescale iMX-based"
-	select GENERIC_GPIO
 	select GPIOLIB
 	select COMMON_CLK
 	select CLKDEV_LOOKUP
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 74a4baa..5ccd35b 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -29,6 +29,7 @@ config GPIO_GENERIC_PLATFORM
 
 config GPIO_IMX
 	def_bool ARCH_IMX
+	select GPIO_GENERIC
 
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
index 1bf4100..9dcabfc 100644
--- a/drivers/gpio/gpio-imx.c
+++ b/drivers/gpio/gpio-imx.c
@@ -20,17 +20,11 @@
  *
  */
 
-#include <common.h>
-#include <errno.h>
-#include <io.h>
-#include <gpio.h>
 #include <init.h>
+#include <common.h>
+#include <malloc.h>
 
-struct imx_gpio_chip {
-	void __iomem *base;
-	struct gpio_chip chip;
-	struct imx_gpio_regs *regs;
-};
+#include <linux/basic_mmio_gpio.h>
 
 struct imx_gpio_regs {
 	unsigned int dr;
@@ -50,104 +44,45 @@ static struct imx_gpio_regs regs_imx31 = {
 	.psr = 0x08,
 };
 
-static void imx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	if (!base)
-		return;
-
-	val = readl(base + imxgpio->regs->dr);
-
-	if (value)
-		val |= 1 << gpio;
-	else
-		val &= ~(1 << gpio);
-
-	writel(val, base + imxgpio->regs->dr);
-}
-
-static int imx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	if (!base)
-		return -EINVAL;
-
-	val = readl(base + imxgpio->regs->gdir);
-	val &= ~(1 << gpio);
-	writel(val, base + imxgpio->regs->gdir);
-
-	return 0;
-}
-
-
-static int imx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	gpio_set_value(gpio + chip->base, value);
-
-	val = readl(base + imxgpio->regs->gdir);
-	val |= 1 << gpio;
-	writel(val, base + imxgpio->regs->gdir);
-
-	return 0;
-}
-
-static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	val = readl(base + imxgpio->regs->psr);
-
-	return val & (1 << gpio) ? 1 : 0;
-}
-
-static struct gpio_ops imx_gpio_ops = {
-	.direction_input = imx_gpio_direction_input,
-	.direction_output = imx_gpio_direction_output,
-	.get = imx_gpio_get_value,
-	.set = imx_gpio_set_value,
-};
-
 static int imx_gpio_probe(struct device_d *dev)
 {
-	struct imx_gpio_chip *imxgpio;
 	struct imx_gpio_regs *regs;
+	struct bgpio_chip *bgc;
+	void __iomem *base;
 	int ret;
 
 	ret = dev_get_drvdata(dev, (unsigned long *)&regs);
 	if (ret)
 		return ret;
 
-	imxgpio = xzalloc(sizeof(*imxgpio));
-	imxgpio->base = dev_request_mem_region(dev, 0);
-	imxgpio->chip.ops = &imx_gpio_ops;
-	if (dev->id < 0) {
-		imxgpio->chip.base = of_alias_get_id(dev->device_node, "gpio");
-		if (imxgpio->chip.base < 0)
-			return imxgpio->chip.base;
-		imxgpio->chip.base *= 32;
-	} else {
-		imxgpio->chip.base = dev->id * 32;
+	bgc = xzalloc(sizeof(*bgc));
+	if (!bgc)
+		return -ENOMEM;
+
+	base = dev_request_mem_region(dev, 0);
+	if (!base) {
+		free(bgc);
+		return -EINVAL;
 	}
-	imxgpio->chip.ngpio = 32;
-	imxgpio->chip.dev = dev;
-	imxgpio->regs = regs;
-	gpiochip_add(&imxgpio->chip);
 
-	dev_dbg(dev, "probed gpiochip%d with base %d\n", dev->id, imxgpio->chip.base);
+	ret = bgpio_init(bgc, dev, 4, base + regs->psr, base + regs->dr, NULL,
+			 base + regs->gdir, NULL, 0);
+	if (ret) {
+		free(bgc);
+		return ret;
+	}
 
-	return 0;
+	if (dev->id < 0) {
+		bgc->gc.base = of_alias_get_id(dev->device_node, "gpio");
+		if (bgc->gc.base < 0) {
+			free(bgc);
+			return bgc->gc.base;
+		}
+		bgc->gc.base *= 32;
+	} else
+		bgc->gc.base = dev->id * 32;
+
+	return gpiochip_add(&bgc->gc);
 }
 
 static __maybe_unused struct of_device_id imx_gpio_dt_ids[] = {
-- 
1.8.1.5


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

  parent reply	other threads:[~2013-04-20  4:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-20  4:18 [PATCH 1/5] GPIO: Rename "drivers/gpio.c" to "drivers/gpiolib.c" Alexander Shiyan
2013-04-20  4:18 ` [PATCH] ubimkvol: Typo fix Alexander Shiyan
2013-04-20  4:18 ` [PATCH 2/5] ARM: i.MX: Move GPIO driver to drivers/gpio Alexander Shiyan
2013-04-20  4:18 ` Alexander Shiyan [this message]
2013-04-22  6:46   ` [PATCH 3/5] GPIO: i.MX: Rewrite driver for using generic GPIO code Sascha Hauer
2013-04-22  6:59     ` Re[2]: " Alexander Shiyan
2013-04-22  7:21       ` Sascha Hauer
2013-04-22  9:23         ` Re[2]: " Alexander Shiyan
2013-04-20  4:18 ` [PATCH 4/5] GPIO: i.MX: Cleanup driver code Alexander Shiyan
2013-04-20 17:04   ` Jean-Christophe PLAGNIOL-VILLARD
2013-04-22 16:58   ` Sascha Hauer
2013-04-20  4:18 ` [PATCH 5/5] Introduce coredevice_platform_driver() macro and use it for GPIO drivers Alexander Shiyan
2013-04-22 16:59 ` [PATCH 1/5] GPIO: Rename "drivers/gpio.c" to "drivers/gpiolib.c" 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=1366431532-29121-4-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