From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: [PATCH v2 02/11] ARM i.MX: switch to gpiolib support
Date: Mon, 3 Sep 2012 10:18:09 +0200 [thread overview]
Message-ID: <1346660298-18148-3-git-send-email-s.trumtrar@pengutronix.de> (raw)
In-Reply-To: <1346660298-18148-1-git-send-email-s.trumtrar@pengutronix.de>
From: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
arch/arm/mach-imx/gpio.c | 94 +++++++++++++++++++++++++++++-----------------
1 file changed, 59 insertions(+), 35 deletions(-)
diff --git a/arch/arm/mach-imx/gpio.c b/arch/arm/mach-imx/gpio.c
index fdee20b..8d5d4ce 100644
--- a/arch/arm/mach-imx/gpio.c
+++ b/arch/arm/mach-imx/gpio.c
@@ -27,7 +27,8 @@
#include <errno.h>
#include <io.h>
#include <mach/imx-regs.h>
-#include <mach/gpio.h>
+#include <gpio.h>
+#include <init.h>
#if defined CONFIG_ARCH_IMX1 || defined CONFIG_ARCH_IMX21 || defined CONFIG_ARCH_IMX27
#define GPIO_DR 0x1c
@@ -48,21 +49,15 @@
#define GPIO_ISR 0x18
#endif
-extern void __iomem *imx_gpio_base[];
-extern int imx_gpio_count;
+struct imx_gpio_chip {
+ void __iomem *base;
+ struct gpio_chip chip;
+};
-static void __iomem *gpio_get_base(unsigned gpio)
+static void imx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
{
- if (gpio >= imx_gpio_count)
- return NULL;
-
- return imx_gpio_base[gpio / 32];
-}
-
-void gpio_set_value(unsigned gpio, int value)
-{
- void __iomem *base = gpio_get_base(gpio);
- int shift = gpio % 32;
+ struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
+ void __iomem *base = imxgpio->base;
u32 val;
if (!base)
@@ -71,59 +66,88 @@ void gpio_set_value(unsigned gpio, int value)
val = readl(base + GPIO_DR);
if (value)
- val |= 1 << shift;
+ val |= 1 << gpio;
else
- val &= ~(1 << shift);
+ val &= ~(1 << gpio);
writel(val, base + GPIO_DR);
}
-int gpio_direction_input(unsigned gpio)
+static int imx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
{
- void __iomem *base = gpio_get_base(gpio);
- int shift = gpio % 32;
+ 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 + GPIO_GDIR);
- val &= ~(1 << shift);
+ val &= ~(1 << gpio);
writel(val, base + GPIO_GDIR);
return 0;
}
-int gpio_direction_output(unsigned gpio, int value)
+static int imx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
{
- void __iomem *base = gpio_get_base(gpio);
- int shift = gpio % 32;
+ struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
+ void __iomem *base = imxgpio->base;
u32 val;
- if (!base)
- return -EINVAL;
-
- gpio_set_value(gpio, value);
+ gpio_set_value(gpio + chip->base, value);
val = readl(base + GPIO_GDIR);
- val |= 1 << shift;
+ val |= 1 << gpio;
writel(val, base + GPIO_GDIR);
return 0;
}
-int gpio_get_value(unsigned gpio)
+static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
{
- void __iomem *base = gpio_get_base(gpio);
- int shift = gpio % 32;
+ 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 + GPIO_PSR);
- return val & (1 << shift) ? 1 : 0;
+ 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;
+
+ imxgpio = xzalloc(sizeof(*imxgpio));
+ imxgpio->base = dev_request_mem_region(dev, 0);
+ imxgpio->chip.ops = &imx_gpio_ops;
+ imxgpio->chip.base = -1;
+ imxgpio->chip.ngpio = 32;
+ imxgpio->chip.dev = dev;
+ gpiochip_add(&imxgpio->chip);
+
+ dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, imxgpio->chip.base);
+
+ return 0;
}
+static struct driver_d imx_gpio_driver = {
+ .name = "imx-gpio",
+ .probe = imx_gpio_probe,
+};
+
+static int imx_gpio_add(void)
+{
+ register_driver(&imx_gpio_driver);
+ return 0;
+}
+coredevice_initcall(imx_gpio_add);
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-09-03 8:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-03 8:18 [PATCH v2 00/11] ARM i.MX: add " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 01/11] " Steffen Trumtrar
2012-09-03 8:18 ` Steffen Trumtrar [this message]
2012-09-03 8:18 ` [PATCH v2 03/11] ARM i.MX1: add imx-gpio devices Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 04/11] ARM i.MX21: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 05/11] ARM i.MX25: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 06/11] ARM i.MX27: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 07/11] ARM i.MX31: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 08/11] ARM i.MX35: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 09/11] ARM i.MX51: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 10/11] ARM i.MX53: " Steffen Trumtrar
2012-09-03 8:18 ` [PATCH v2 11/11] ARM i.MX6: " Steffen Trumtrar
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=1346660298-18148-3-git-send-email-s.trumtrar@pengutronix.de \
--to=s.trumtrar@pengutronix.de \
--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