* [PATCH 0/5] convert to use basic mmio gpio library
@ 2014-10-29 13:56 kamlakant.patel
2014-10-29 13:56 ` [PATCH 1/5] gpio: moxart: " kamlakant.patel
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: kamlakant.patel @ 2014-10-29 13:56 UTC (permalink / raw)
To: Linus Walleij, Alexandre Courbot; +Cc: Kamlakant Patel, linux-gpio
From: Kamlakant Patel <kamlakant.patel@linaro.org>
This patch converts GPIO drivers to use BASIC MMIO GPIO library
(i.e GPIO GENERIC library) which makes drivers smaller and simpler.
This patch needs to be tested on different platforms.
Kamlakant Patel (5):
gpio: moxart: convert to use basic mmio gpio library
gpio: timberdale: convert to use basic mmio gpio library
gpio: iop: convert to use basic mmio gpio library
gpio: ge: convert to use basic mmio gpio library
gpio: document basic mmio gpio library
Documentation/gpio/driver.txt | 50 ++++++++++++++++++++++
drivers/gpio/Kconfig | 4 ++
drivers/gpio/gpio-ge.c | 96 +++++++++++++++++-------------------------
drivers/gpio/gpio-iop.c | 96 ++++++++----------------------------------
drivers/gpio/gpio-moxart.c | 76 ++++++++++++---------------------
drivers/gpio/gpio-timberdale.c | 90 ++++++++++++---------------------------
6 files changed, 162 insertions(+), 250 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/5] gpio: moxart: convert to use basic mmio gpio library
2014-10-29 13:56 [PATCH 0/5] convert to use basic mmio gpio library kamlakant.patel
@ 2014-10-29 13:56 ` kamlakant.patel
2014-11-03 14:08 ` Jonas Jensen
2014-10-29 13:56 ` [PATCH 2/5] gpio: timberdale: " kamlakant.patel
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: kamlakant.patel @ 2014-10-29 13:56 UTC (permalink / raw)
To: Linus Walleij, Alexandre Courbot
Cc: Kamlakant Patel, linux-gpio, Jonas Jensen
From: Kamlakant Patel <kamlakant.patel@linaro.org>
This patch converts MOXART GPIO driver to use basic_mmio_gpio
generic library.
Signed-off-by: Kamlakant Patel <kamlakant.patel@linaro.org>
---
drivers/gpio/Kconfig | 1 +
drivers/gpio/gpio-moxart.c | 76 ++++++++++++++++------------------------------
2 files changed, 27 insertions(+), 50 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 0959ca9..3bd4d63 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -184,6 +184,7 @@ config GPIO_F7188X
config GPIO_MOXART
bool "MOXART GPIO support"
depends on ARCH_MOXART
+ select GPIO_GENERIC
help
Select this option to enable GPIO driver for
MOXA ART SoC devices.
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index 4661e18..c06fdcf 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -23,6 +23,7 @@
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/bitops.h>
+#include <linux/basic_mmio_gpio.h>
#define GPIO_DATA_OUT 0x00
#define GPIO_DATA_IN 0x04
@@ -48,20 +49,6 @@ static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
pinctrl_free_gpio(offset);
}
-static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_DATA_OUT;
- u32 reg = readl(ioaddr);
-
- if (value)
- reg = reg | BIT(offset);
- else
- reg = reg & ~BIT(offset);
-
- writel(reg, ioaddr);
-}
-
static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
{
struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
@@ -73,65 +60,54 @@ static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset));
}
-static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
-
- writel(readl(ioaddr) & ~BIT(offset), ioaddr);
- return 0;
-}
-
-static int moxart_gpio_direction_output(struct gpio_chip *chip,
- unsigned offset, int value)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
-
- moxart_gpio_set(chip, offset, value);
- writel(readl(ioaddr) | BIT(offset), ioaddr);
- return 0;
-}
-
-static struct gpio_chip moxart_template_chip = {
- .label = "moxart-gpio",
- .request = moxart_gpio_request,
- .free = moxart_gpio_free,
- .direction_input = moxart_gpio_direction_input,
- .direction_output = moxart_gpio_direction_output,
- .set = moxart_gpio_set,
- .get = moxart_gpio_get,
- .ngpio = 32,
- .owner = THIS_MODULE,
-};
-
static int moxart_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
+ struct bgpio_chip *bgc;
struct moxart_gpio_chip *mgc;
int ret;
mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
if (!mgc)
return -ENOMEM;
- mgc->gpio = moxart_template_chip;
+
+ bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
+ if (!bgc)
+ return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mgc->base = devm_ioremap_resource(dev, res);
if (IS_ERR(mgc->base))
return PTR_ERR(mgc->base);
- mgc->gpio.dev = dev;
+ ret = bgpio_init(bgc, dev, 4, mgc->base + GPIO_PIN_DIRECTION,
+ mgc->base + GPIO_DATA_OUT, NULL,
+ mgc->base + GPIO_PIN_DIRECTION, NULL, 0);
+
+ if (ret) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return ret;
+ }
+
+ bgc->gc.label = "moxart-gpio";
+ bgc->gc.request = moxart_gpio_request;
+ bgc->gc.free = moxart_gpio_free,
+ bgc->gc.get = moxart_gpio_get,
+ bgc->gc.ngpio = 32;
+ bgc->gc.dev = dev;
+ bgc->gc.owner = THIS_MODULE;
+
+ mgc->gpio = bgc->gc;
- ret = gpiochip_add(&mgc->gpio);
+ ret = gpiochip_add(&bgc->gc);
if (ret) {
dev_err(dev, "%s: gpiochip_add failed\n",
dev->of_node->full_name);
return ret;
}
- return 0;
+ return ret;
}
static const struct of_device_id moxart_gpio_match[] = {
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/5] gpio: timberdale: convert to use basic mmio gpio library
2014-10-29 13:56 [PATCH 0/5] convert to use basic mmio gpio library kamlakant.patel
2014-10-29 13:56 ` [PATCH 1/5] gpio: moxart: " kamlakant.patel
@ 2014-10-29 13:56 ` kamlakant.patel
2014-10-29 13:56 ` [PATCH 3/5] gpio: iop: " kamlakant.patel
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: kamlakant.patel @ 2014-10-29 13:56 UTC (permalink / raw)
To: Linus Walleij, Alexandre Courbot
Cc: Kamlakant Patel, linux-gpio, Grant Likely
From: Kamlakant Patel <kamlakant.patel@linaro.org>
This patch converts TIMBERDALE GPIO driver to use basic_mmio_gpio
generic library.
Signed-off-by: Kamlakant Patel <kamlakant.patel@linaro.org>
---
drivers/gpio/Kconfig | 1 +
drivers/gpio/gpio-timberdale.c | 90 ++++++++++++------------------------------
2 files changed, 27 insertions(+), 64 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 3bd4d63..875d312 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -783,6 +783,7 @@ config GPIO_SODAVILLE
config GPIO_TIMBERDALE
bool "Support for timberdale GPIO IP"
depends on MFD_TIMBERDALE
+ select GPIO_GENERIC
---help---
Add support for the GPIO IP in the timberdale FPGA.
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index a685a3c..363ede8 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -28,7 +28,7 @@
#include <linux/timb_gpio.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
-
+#include <linux/basic_mmio_gpio.h>
#define DRIVER_NAME "timb-gpio"
#define TGPIOVAL 0x00
@@ -50,52 +50,6 @@ struct timbgpio {
unsigned long last_ier;
};
-static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index,
- unsigned offset, bool enabled)
-{
- struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
- u32 reg;
-
- spin_lock(&tgpio->lock);
- reg = ioread32(tgpio->membase + offset);
-
- if (enabled)
- reg |= (1 << index);
- else
- reg &= ~(1 << index);
-
- iowrite32(reg, tgpio->membase + offset);
- spin_unlock(&tgpio->lock);
-
- return 0;
-}
-
-static int timbgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
-{
- return timbgpio_update_bit(gpio, nr, TGPIODIR, true);
-}
-
-static int timbgpio_gpio_get(struct gpio_chip *gpio, unsigned nr)
-{
- struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
- u32 value;
-
- value = ioread32(tgpio->membase + TGPIOVAL);
- return (value & (1 << nr)) ? 1 : 0;
-}
-
-static int timbgpio_gpio_direction_output(struct gpio_chip *gpio,
- unsigned nr, int val)
-{
- return timbgpio_update_bit(gpio, nr, TGPIODIR, false);
-}
-
-static void timbgpio_gpio_set(struct gpio_chip *gpio,
- unsigned nr, int val)
-{
- timbgpio_update_bit(gpio, nr, TGPIOVAL, val != 0);
-}
-
static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset)
{
struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio);
@@ -225,7 +179,7 @@ static int timbgpio_probe(struct platform_device *pdev)
{
int err, i;
struct device *dev = &pdev->dev;
- struct gpio_chip *gc;
+ struct bgpio_chip *bgc;
struct timbgpio *tgpio;
struct resource *iomem;
struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
@@ -247,6 +201,11 @@ static int timbgpio_probe(struct platform_device *pdev)
dev_err(dev, "Memory alloc failed\n");
return -EINVAL;
}
+
+ bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
+ if (!bgc)
+ return -EINVAL;
+
tgpio->irq_base = pdata->irq_base;
spin_lock_init(&tgpio->lock);
@@ -263,22 +222,25 @@ static int timbgpio_probe(struct platform_device *pdev)
return -ENOMEM;
}
- gc = &tgpio->gpio;
-
- gc->label = dev_name(&pdev->dev);
- gc->owner = THIS_MODULE;
- gc->dev = &pdev->dev;
- gc->direction_input = timbgpio_gpio_direction_input;
- gc->get = timbgpio_gpio_get;
- gc->direction_output = timbgpio_gpio_direction_output;
- gc->set = timbgpio_gpio_set;
- gc->to_irq = (irq >= 0 && tgpio->irq_base > 0) ? timbgpio_to_irq : NULL;
- gc->dbg_show = NULL;
- gc->base = pdata->gpio_base;
- gc->ngpio = pdata->nr_pins;
- gc->can_sleep = false;
-
- err = gpiochip_add(gc);
+ err = bgpio_init(bgc, dev, 4, tgpio->membase + TGPIOVAL,
+ NULL, NULL, tgpio->membase + TGPIODIR, NULL, 0);
+
+ if (err) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return err;
+ }
+ bgc->gc.label = dev_name(&pdev->dev);
+ bgc->gc.owner = THIS_MODULE;
+ bgc->gc.dev = &pdev->dev;
+ bgc->gc.to_irq = (irq >= 0 && tgpio->irq_base > 0) ?
+ timbgpio_to_irq : NULL;
+ bgc->gc.dbg_show = NULL;
+ bgc->gc.base = pdata->gpio_base;
+ bgc->gc.ngpio = pdata->nr_pins;
+ bgc->gc.can_sleep = false;
+
+ tgpio->gpio = bgc->gc;
+ err = gpiochip_add(&bgc->gc);
if (err)
return err;
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/5] gpio: iop: convert to use basic mmio gpio library
2014-10-29 13:56 [PATCH 0/5] convert to use basic mmio gpio library kamlakant.patel
2014-10-29 13:56 ` [PATCH 1/5] gpio: moxart: " kamlakant.patel
2014-10-29 13:56 ` [PATCH 2/5] gpio: timberdale: " kamlakant.patel
@ 2014-10-29 13:56 ` kamlakant.patel
2014-10-29 13:56 ` [PATCH 4/5] gpio: ge: " kamlakant.patel
2014-11-07 9:10 ` [PATCH 0/5] " Alexandre Courbot
4 siblings, 0 replies; 12+ messages in thread
From: kamlakant.patel @ 2014-10-29 13:56 UTC (permalink / raw)
To: Linus Walleij, Alexandre Courbot
Cc: Kamlakant Patel, linux-gpio, Lennert Buytenhek, Dan Williams,
Mikael Pettersson
From: Kamlakant Patel <kamlakant.patel@linaro.org>
This patch converts IOP GPIO driver to use basic_mmio_gpio
generic library.
Signed-off-by: Kamlakant Patel <kamlakant.patel@linaro.org>
---
drivers/gpio/Kconfig | 1 +
drivers/gpio/gpio-iop.c | 96 +++++++++----------------------------------------
2 files changed, 18 insertions(+), 79 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 875d312..8cbc3ab 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -407,6 +407,7 @@ config GPIO_ICH
config GPIO_IOP
tristate "Intel IOP GPIO"
depends on ARM && (ARCH_IOP32X || ARCH_IOP33X)
+ select GPIO_GENERIC
help
Say yes here to support the GPIO functionality of a number of Intel
IOP32X or IOP33X.
diff --git a/drivers/gpio/gpio-iop.c b/drivers/gpio/gpio-iop.c
index 0a5e9d3..c7bbc73 100644
--- a/drivers/gpio/gpio-iop.c
+++ b/drivers/gpio/gpio-iop.c
@@ -14,19 +14,12 @@
#include <linux/init.h>
#include <linux/types.h>
#include <linux/errno.h>
-#include <linux/gpio.h>
#include <linux/export.h>
#include <linux/platform_device.h>
-#include <linux/bitops.h>
-#include <linux/io.h>
+#include <linux/basic_mmio_gpio.h>
#define IOP3XX_N_GPIOS 8
-#define GPIO_IN 0
-#define GPIO_OUT 1
-#define GPIO_LOW 0
-#define GPIO_HIGH 1
-
/* Memory base offset */
static void __iomem *base;
@@ -35,86 +28,31 @@ static void __iomem *base;
#define IOP3XX_GPID IOP3XX_GPIO_REG(0x0004)
#define IOP3XX_GPOD IOP3XX_GPIO_REG(0x0008)
-static void gpio_line_config(int line, int direction)
-{
- unsigned long flags;
- u32 val;
-
- local_irq_save(flags);
- val = readl(IOP3XX_GPOE);
- if (direction == GPIO_IN) {
- val |= BIT(line);
- } else if (direction == GPIO_OUT) {
- val &= ~BIT(line);
- }
- writel(val, IOP3XX_GPOE);
- local_irq_restore(flags);
-}
-
-static int gpio_line_get(int line)
-{
- return !!(readl(IOP3XX_GPID) & BIT(line));
-}
-
-static void gpio_line_set(int line, int value)
-{
- unsigned long flags;
- u32 val;
-
- local_irq_save(flags);
- val = readl(IOP3XX_GPOD);
- if (value == GPIO_LOW) {
- val &= ~BIT(line);
- } else if (value == GPIO_HIGH) {
- val |= BIT(line);
- }
- writel(val, IOP3XX_GPOD);
- local_irq_restore(flags);
-}
-
-static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
-{
- gpio_line_config(gpio, GPIO_IN);
- return 0;
-}
-
-static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
-{
- gpio_line_set(gpio, level);
- gpio_line_config(gpio, GPIO_OUT);
- return 0;
-}
-
-static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
-{
- return gpio_line_get(gpio);
-}
-
-static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
-{
- gpio_line_set(gpio, value);
-}
-
-static struct gpio_chip iop3xx_chip = {
- .label = "iop3xx",
- .direction_input = iop3xx_gpio_direction_input,
- .get = iop3xx_gpio_get_value,
- .direction_output = iop3xx_gpio_direction_output,
- .set = iop3xx_gpio_set_value,
- .base = 0,
- .ngpio = IOP3XX_N_GPIOS,
-};
-
static int iop3xx_gpio_probe(struct platform_device *pdev)
{
struct resource *res;
+ struct bgpio_chip *bgc;
+ int ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base))
return PTR_ERR(base);
+ bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
+ if (!bgc)
+ return -EINVAL;
+
+ ret = bgpio_init(bgc, &pdev->dev, 4, IOP3XX_GPID,
+ IOP3XX_GPOD, NULL, IOP3XX_GPOE, NULL, 0);
+ if (ret) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return ret;
+ }
+ bgc->gc.label = "iop3xx";
+ bgc->gc.base = 0;
+ bgc->gc.ngpio = IOP3XX_N_GPIOS;
- return gpiochip_add(&iop3xx_chip);
+ return gpiochip_add(&bgc->gc);
}
static struct platform_driver iop3xx_gpio_driver = {
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/5] gpio: ge: convert to use basic mmio gpio library
2014-10-29 13:56 [PATCH 0/5] convert to use basic mmio gpio library kamlakant.patel
` (2 preceding siblings ...)
2014-10-29 13:56 ` [PATCH 3/5] gpio: iop: " kamlakant.patel
@ 2014-10-29 13:56 ` kamlakant.patel
2014-11-07 9:10 ` [PATCH 0/5] " Alexandre Courbot
4 siblings, 0 replies; 12+ messages in thread
From: kamlakant.patel @ 2014-10-29 13:56 UTC (permalink / raw)
To: Linus Walleij, Alexandre Courbot
Cc: Kamlakant Patel, linux-gpio, Martyn Welch
From: Kamlakant Patel <kamlakant.patel@linaro.org>
This patch converts GE GPIO driver to use basic_mmio_gpio
generic library.
Signed-off-by: Kamlakant Patel <kamlakant.patel@linaro.org>
---
drivers/gpio/Kconfig | 1 +
drivers/gpio/gpio-ge.c | 96 ++++++++++++++++++++------------------------------
2 files changed, 40 insertions(+), 57 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 8cbc3ab..35a315d 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -429,6 +429,7 @@ config GPIO_VX855
config GPIO_GE_FPGA
bool "GE FPGA based GPIO"
depends on GE_FPGA
+ select GPIO_GENERIC
help
Support for common GPIO functionality provided on some GE Single Board
Computers.
diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c
index 1237a73..7579d2e 100644
--- a/drivers/gpio/gpio-ge.c
+++ b/drivers/gpio/gpio-ge.c
@@ -21,7 +21,9 @@
#include <linux/io.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
+#include <linux/of_address.h>
#include <linux/module.h>
+#include <linux/basic_mmio_gpio.h>
#define GEF_GPIO_DIRECT 0x00
#define GEF_GPIO_IN 0x04
@@ -33,53 +35,6 @@
#define GEF_GPIO_OVERRUN 0x1C
#define GEF_GPIO_MODE 0x20
-static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
-{
- struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
- unsigned int data;
-
- data = ioread32be(mmchip->regs + GEF_GPIO_OUT);
- if (value)
- data = data | BIT(offset);
- else
- data = data & ~BIT(offset);
- iowrite32be(data, mmchip->regs + GEF_GPIO_OUT);
-}
-
-static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset)
-{
- unsigned int data;
- struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
-
- data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT);
- data = data | BIT(offset);
- iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT);
-
- return 0;
-}
-
-static int gef_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value)
-{
- unsigned int data;
- struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
-
- /* Set value before switching to output */
- gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value);
-
- data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT);
- data = data & ~BIT(offset);
- iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT);
-
- return 0;
-}
-
-static int gef_gpio_get(struct gpio_chip *chip, unsigned offset)
-{
- struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
-
- return !!(ioread32be(mmchip->regs + GEF_GPIO_IN) & BIT(offset));
-}
-
static const struct of_device_id gef_gpio_ids[] = {
{
.compatible = "gef,sbc610-gpio",
@@ -99,22 +54,49 @@ static int __init gef_gpio_probe(struct platform_device *pdev)
{
const struct of_device_id *of_id =
of_match_device(gef_gpio_ids, &pdev->dev);
- struct of_mm_gpio_chip *mmchip;
+ struct bgpio_chip *bgc;
+ void __iomem *regs;
+ int ret;
- mmchip = devm_kzalloc(&pdev->dev, sizeof(*mmchip), GFP_KERNEL);
- if (!mmchip)
+ bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
+ if (!bgc)
return -ENOMEM;
+ regs = of_iomap(pdev->dev.of_node, 0);
+ if (!regs)
+ return -ENOMEM;
+
+ ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN,
+ regs + GEF_GPIO_OUT, NULL, NULL,
+ regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
+ if (ret) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ goto err0;
+ }
+
/* Setup pointers to chip functions */
- mmchip->gc.ngpio = (u16)(uintptr_t)of_id->data;
- mmchip->gc.of_gpio_n_cells = 2;
- mmchip->gc.direction_input = gef_gpio_dir_in;
- mmchip->gc.direction_output = gef_gpio_dir_out;
- mmchip->gc.get = gef_gpio_get;
- mmchip->gc.set = gef_gpio_set;
+ bgc->gc.label = kstrdup(pdev->dev.of_node->full_name, GFP_KERNEL);
+ if (!bgc->gc.label)
+ goto err0;
+
+ bgc->gc.base = -1;
+ bgc->gc.ngpio = (u16)(uintptr_t)of_id->data;
+ bgc->gc.of_gpio_n_cells = 2;
+ bgc->gc.of_node = pdev->dev.of_node;
/* This function adds a memory mapped GPIO chip */
- return of_mm_gpiochip_add(pdev->dev.of_node, mmchip);
+ ret = gpiochip_add(&bgc->gc);
+ if (ret)
+ goto err1;
+
+ return 0;
+err1:
+ kfree(bgc->gc.label);
+err0:
+ iounmap(regs);
+ pr_err("%s: GPIO chip registration failed\n",
+ pdev->dev.of_node->full_name);
+ return ret;
};
static struct platform_driver gef_gpio_driver = {
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] gpio: moxart: convert to use basic mmio gpio library
2014-10-29 13:56 ` [PATCH 1/5] gpio: moxart: " kamlakant.patel
@ 2014-11-03 14:08 ` Jonas Jensen
2014-11-07 4:31 ` Kamlakant Patel
2014-11-12 12:00 ` Kamlakant Patel
0 siblings, 2 replies; 12+ messages in thread
From: Jonas Jensen @ 2014-11-03 14:08 UTC (permalink / raw)
To: kamlakant.patel
Cc: Linus Walleij, Alexandre Courbot, linux-gpio@vger.kernel.org
Thanks for keeping this maintained.
I think there's a problem..
RTC is not read on boot: "hctosys: invalid date/time".
hwclock result in: "Timed out waiting for time change."
Comments and patch suggestion below.
On 29 October 2014 14:56, <kamlakant.patel@linaro.org> wrote:
> static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
> {
> struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
to_moxart_gpio() helper is no longer valid here, since bgpio_chip is
the new container.
> static int moxart_gpio_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct resource *res;
> + struct bgpio_chip *bgc;
> struct moxart_gpio_chip *mgc;
> int ret;
>
> mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
> if (!mgc)
> return -ENOMEM;
> - mgc->gpio = moxart_template_chip;
> +
> + bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
> + if (!bgc)
> + return -ENOMEM;
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> mgc->base = devm_ioremap_resource(dev, res);
> if (IS_ERR(mgc->base))
> return PTR_ERR(mgc->base);
>
> - mgc->gpio.dev = dev;
> + ret = bgpio_init(bgc, dev, 4, mgc->base + GPIO_PIN_DIRECTION,
> + mgc->base + GPIO_DATA_OUT, NULL,
> + mgc->base + GPIO_PIN_DIRECTION, NULL, 0);
> +
> + if (ret) {
> + dev_err(&pdev->dev, "bgpio_init failed\n");
> + return ret;
> + }
> +
> + bgc->gc.label = "moxart-gpio";
> + bgc->gc.request = moxart_gpio_request;
> + bgc->gc.free = moxart_gpio_free,
> + bgc->gc.get = moxart_gpio_get,
End with semicolon?
drivers/gpio/Kconfig | 1 +
drivers/gpio/gpio-moxart.c | 84 ++++++++++++++++------------------------------
2 files changed, 29 insertions(+), 56 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 9de1515..c1b8a90 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -185,6 +185,7 @@ config GPIO_F7188X
config GPIO_MOXART
bool "MOXART GPIO support"
depends on ARCH_MOXART
+ select GPIO_GENERIC
help
Select this option to enable GPIO driver for
MOXA ART SoC devices.
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index 4661e18..50278b6 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -23,21 +23,23 @@
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/bitops.h>
+#include <linux/basic_mmio_gpio.h>
#define GPIO_DATA_OUT 0x00
#define GPIO_DATA_IN 0x04
#define GPIO_PIN_DIRECTION 0x08
-struct moxart_gpio_chip {
- struct gpio_chip gpio;
+struct moxart_bgpio_chip {
+ struct bgpio_chip gpio;
void __iomem *base;
};
-static inline struct moxart_gpio_chip *to_moxart_gpio(struct gpio_chip *chip)
+static inline struct moxart_bgpio_chip *to_moxart_bgpio(struct
bgpio_chip *chip)
{
- return container_of(chip, struct moxart_gpio_chip, gpio);
+ return container_of(chip, struct moxart_bgpio_chip, gpio);
}
+
static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
{
return pinctrl_request_gpio(offset);
@@ -48,23 +50,11 @@ static void moxart_gpio_free(struct gpio_chip
*chip, unsigned offset)
pinctrl_free_gpio(offset);
}
-static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_DATA_OUT;
- u32 reg = readl(ioaddr);
-
- if (value)
- reg = reg | BIT(offset);
- else
- reg = reg & ~BIT(offset);
-
- writel(reg, ioaddr);
-}
-
static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
+ struct bgpio_chip *bgc = to_bgpio_chip(chip);
+ struct moxart_bgpio_chip *gc = to_moxart_bgpio(bgc);
+
u32 ret = readl(gc->base + GPIO_PIN_DIRECTION);
if (ret & BIT(offset))
@@ -73,65 +63,47 @@ static int moxart_gpio_get(struct gpio_chip *chip,
unsigned offset)
return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset));
}
-static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
-
- writel(readl(ioaddr) & ~BIT(offset), ioaddr);
- return 0;
-}
-
-static int moxart_gpio_direction_output(struct gpio_chip *chip,
- unsigned offset, int value)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
-
- moxart_gpio_set(chip, offset, value);
- writel(readl(ioaddr) | BIT(offset), ioaddr);
- return 0;
-}
-
-static struct gpio_chip moxart_template_chip = {
- .label = "moxart-gpio",
- .request = moxart_gpio_request,
- .free = moxart_gpio_free,
- .direction_input = moxart_gpio_direction_input,
- .direction_output = moxart_gpio_direction_output,
- .set = moxart_gpio_set,
- .get = moxart_gpio_get,
- .ngpio = 32,
- .owner = THIS_MODULE,
-};
-
static int moxart_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
- struct moxart_gpio_chip *mgc;
+ struct moxart_bgpio_chip *mgc;
int ret;
mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
if (!mgc)
return -ENOMEM;
- mgc->gpio = moxart_template_chip;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mgc->base = devm_ioremap_resource(dev, res);
if (IS_ERR(mgc->base))
return PTR_ERR(mgc->base);
- mgc->gpio.dev = dev;
+ ret = bgpio_init(&mgc->gpio, dev, 4, mgc->base + GPIO_PIN_DIRECTION,
+ mgc->base + GPIO_DATA_OUT, NULL,
+ mgc->base + GPIO_PIN_DIRECTION, NULL, 0);
+
+ if (ret) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return ret;
+ }
+
+ mgc->gpio.gc.label = "moxart-gpio";
+ mgc->gpio.gc.request = moxart_gpio_request;
+ mgc->gpio.gc.free = moxart_gpio_free;
+ mgc->gpio.gc.get = moxart_gpio_get;
+ mgc->gpio.gc.ngpio = 32;
+ mgc->gpio.gc.dev = dev;
+ mgc->gpio.gc.owner = THIS_MODULE;
- ret = gpiochip_add(&mgc->gpio);
+ ret = gpiochip_add(&mgc->gpio.gc);
if (ret) {
dev_err(dev, "%s: gpiochip_add failed\n",
dev->of_node->full_name);
return ret;
}
- return 0;
+ return ret;
}
static const struct of_device_id moxart_gpio_match[] = {
Regards,
Jonas
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] gpio: moxart: convert to use basic mmio gpio library
2014-11-03 14:08 ` Jonas Jensen
@ 2014-11-07 4:31 ` Kamlakant Patel
2014-11-12 12:00 ` Kamlakant Patel
1 sibling, 0 replies; 12+ messages in thread
From: Kamlakant Patel @ 2014-11-07 4:31 UTC (permalink / raw)
To: Jonas Jensen; +Cc: Linus Walleij, Alexandre Courbot, linux-gpio@vger.kernel.org
Hi Jonas,
On 3 November 2014 19:38, Jonas Jensen <jonas.jensen@gmail.com> wrote:
> Thanks for keeping this maintained.
>
> I think there's a problem..
>
> RTC is not read on boot: "hctosys: invalid date/time".
> hwclock result in: "Timed out waiting for time change."
>
> Comments and patch suggestion below.
>
>
> On 29 October 2014 14:56, <kamlakant.patel@linaro.org> wrote:
>> static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
>> {
>> struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
>
> to_moxart_gpio() helper is no longer valid here, since bgpio_chip is
> the new container.
>
>
>> static int moxart_gpio_probe(struct platform_device *pdev)
>> {
>> struct device *dev = &pdev->dev;
>> struct resource *res;
>> + struct bgpio_chip *bgc;
>> struct moxart_gpio_chip *mgc;
>> int ret;
>>
>> mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
>> if (!mgc)
>> return -ENOMEM;
>> - mgc->gpio = moxart_template_chip;
>> +
>> + bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
>> + if (!bgc)
>> + return -ENOMEM;
>>
>> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> mgc->base = devm_ioremap_resource(dev, res);
>> if (IS_ERR(mgc->base))
>> return PTR_ERR(mgc->base);
>>
>> - mgc->gpio.dev = dev;
>> + ret = bgpio_init(bgc, dev, 4, mgc->base + GPIO_PIN_DIRECTION,
>> + mgc->base + GPIO_DATA_OUT, NULL,
>> + mgc->base + GPIO_PIN_DIRECTION, NULL, 0);
>> +
>> + if (ret) {
>> + dev_err(&pdev->dev, "bgpio_init failed\n");
>> + return ret;
>> + }
>> +
>> + bgc->gc.label = "moxart-gpio";
>> + bgc->gc.request = moxart_gpio_request;
>> + bgc->gc.free = moxart_gpio_free,
>> + bgc->gc.get = moxart_gpio_get,
>
> End with semicolon?
>
>
>
> drivers/gpio/Kconfig | 1 +
> drivers/gpio/gpio-moxart.c | 84 ++++++++++++++++------------------------------
> 2 files changed, 29 insertions(+), 56 deletions(-)
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 9de1515..c1b8a90 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -185,6 +185,7 @@ config GPIO_F7188X
> config GPIO_MOXART
> bool "MOXART GPIO support"
> depends on ARCH_MOXART
> + select GPIO_GENERIC
> help
> Select this option to enable GPIO driver for
> MOXA ART SoC devices.
> diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
> index 4661e18..50278b6 100644
> --- a/drivers/gpio/gpio-moxart.c
> +++ b/drivers/gpio/gpio-moxart.c
> @@ -23,21 +23,23 @@
> #include <linux/delay.h>
> #include <linux/timer.h>
> #include <linux/bitops.h>
> +#include <linux/basic_mmio_gpio.h>
>
> #define GPIO_DATA_OUT 0x00
> #define GPIO_DATA_IN 0x04
> #define GPIO_PIN_DIRECTION 0x08
>
> -struct moxart_gpio_chip {
> - struct gpio_chip gpio;
> +struct moxart_bgpio_chip {
> + struct bgpio_chip gpio;
> void __iomem *base;
> };
>
> -static inline struct moxart_gpio_chip *to_moxart_gpio(struct gpio_chip *chip)
> +static inline struct moxart_bgpio_chip *to_moxart_bgpio(struct
> bgpio_chip *chip)
> {
> - return container_of(chip, struct moxart_gpio_chip, gpio);
> + return container_of(chip, struct moxart_bgpio_chip, gpio);
> }
>
> +
> static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
> {
> return pinctrl_request_gpio(offset);
> @@ -48,23 +50,11 @@ static void moxart_gpio_free(struct gpio_chip
> *chip, unsigned offset)
> pinctrl_free_gpio(offset);
> }
>
> -static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
> -{
> - struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
> - void __iomem *ioaddr = gc->base + GPIO_DATA_OUT;
> - u32 reg = readl(ioaddr);
> -
> - if (value)
> - reg = reg | BIT(offset);
> - else
> - reg = reg & ~BIT(offset);
> -
> - writel(reg, ioaddr);
> -}
> -
> static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
> {
> - struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
> + struct bgpio_chip *bgc = to_bgpio_chip(chip);
> + struct moxart_bgpio_chip *gc = to_moxart_bgpio(bgc);
> +
> u32 ret = readl(gc->base + GPIO_PIN_DIRECTION);
>
> if (ret & BIT(offset))
> @@ -73,65 +63,47 @@ static int moxart_gpio_get(struct gpio_chip *chip,
> unsigned offset)
> return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset));
> }
>
> -static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
> -{
> - struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
> - void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
> -
> - writel(readl(ioaddr) & ~BIT(offset), ioaddr);
> - return 0;
> -}
> -
> -static int moxart_gpio_direction_output(struct gpio_chip *chip,
> - unsigned offset, int value)
> -{
> - struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
> - void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
> -
> - moxart_gpio_set(chip, offset, value);
> - writel(readl(ioaddr) | BIT(offset), ioaddr);
> - return 0;
> -}
> -
> -static struct gpio_chip moxart_template_chip = {
> - .label = "moxart-gpio",
> - .request = moxart_gpio_request,
> - .free = moxart_gpio_free,
> - .direction_input = moxart_gpio_direction_input,
> - .direction_output = moxart_gpio_direction_output,
> - .set = moxart_gpio_set,
> - .get = moxart_gpio_get,
> - .ngpio = 32,
> - .owner = THIS_MODULE,
> -};
> -
> static int moxart_gpio_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct resource *res;
> - struct moxart_gpio_chip *mgc;
> + struct moxart_bgpio_chip *mgc;
> int ret;
>
> mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
> if (!mgc)
> return -ENOMEM;
> - mgc->gpio = moxart_template_chip;
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> mgc->base = devm_ioremap_resource(dev, res);
> if (IS_ERR(mgc->base))
> return PTR_ERR(mgc->base);
>
> - mgc->gpio.dev = dev;
> + ret = bgpio_init(&mgc->gpio, dev, 4, mgc->base + GPIO_PIN_DIRECTION,
> + mgc->base + GPIO_DATA_OUT, NULL,
> + mgc->base + GPIO_PIN_DIRECTION, NULL, 0);
> +
> + if (ret) {
> + dev_err(&pdev->dev, "bgpio_init failed\n");
> + return ret;
> + }
> +
> + mgc->gpio.gc.label = "moxart-gpio";
> + mgc->gpio.gc.request = moxart_gpio_request;
> + mgc->gpio.gc.free = moxart_gpio_free;
> + mgc->gpio.gc.get = moxart_gpio_get;
> + mgc->gpio.gc.ngpio = 32;
> + mgc->gpio.gc.dev = dev;
> + mgc->gpio.gc.owner = THIS_MODULE;
>
> - ret = gpiochip_add(&mgc->gpio);
> + ret = gpiochip_add(&mgc->gpio.gc);
> if (ret) {
> dev_err(dev, "%s: gpiochip_add failed\n",
> dev->of_node->full_name);
> return ret;
> }
>
> - return 0;
> + return ret;
> }
>
> static const struct of_device_id moxart_gpio_match[] = {
>
Thanks for the review and comments, I will fix and send a second patch on this.
Thanks,
Kamlakant Patel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] convert to use basic mmio gpio library
2014-10-29 13:56 [PATCH 0/5] convert to use basic mmio gpio library kamlakant.patel
` (3 preceding siblings ...)
2014-10-29 13:56 ` [PATCH 4/5] gpio: ge: " kamlakant.patel
@ 2014-11-07 9:10 ` Alexandre Courbot
2014-11-13 9:48 ` Linus Walleij
4 siblings, 1 reply; 12+ messages in thread
From: Alexandre Courbot @ 2014-11-07 9:10 UTC (permalink / raw)
To: Kamlakant Patel; +Cc: Linus Walleij, linux-gpio@vger.kernel.org
On Wed, Oct 29, 2014 at 10:56 PM, <kamlakant.patel@linaro.org> wrote:
> From: Kamlakant Patel <kamlakant.patel@linaro.org>
>
> This patch converts GPIO drivers to use BASIC MMIO GPIO library
> (i.e GPIO GENERIC library) which makes drivers smaller and simpler.
>
> This patch needs to be tested on different platforms.
This sounds like a good idea, but we will need to get a couple of
Tested-by for each patch.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] gpio: moxart: convert to use basic mmio gpio library
2014-11-03 14:08 ` Jonas Jensen
2014-11-07 4:31 ` Kamlakant Patel
@ 2014-11-12 12:00 ` Kamlakant Patel
[not found] ` <CACmBeS1Gf4U-A_-HHy-c+iDRqt81vTaMxjKsekcjnVMvTxTBuw@mail.gmail.com>
1 sibling, 1 reply; 12+ messages in thread
From: Kamlakant Patel @ 2014-11-12 12:00 UTC (permalink / raw)
To: Jonas Jensen; +Cc: Linus Walleij, Alexandre Courbot, linux-gpio@vger.kernel.org
Hi Jonas,
This is an updated version of the previous patch with some fixes.
Could you please try it out.
drivers/gpio/Kconfig | 1 +
drivers/gpio/gpio-moxart.c | 101 ++++++++++++++-------------------------------
2 files changed, 32 insertions(+), 70 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 0959ca9..3bd4d63 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -184,6 +184,7 @@ config GPIO_F7188X
config GPIO_MOXART
bool "MOXART GPIO support"
depends on ARCH_MOXART
+ select GPIO_GENERIC
help
Select this option to enable GPIO driver for
MOXA ART SoC devices.
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index 4661e18..c2690e6 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -23,21 +23,12 @@
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/bitops.h>
+#include <linux/basic_mmio_gpio.h>
#define GPIO_DATA_OUT 0x00
#define GPIO_DATA_IN 0x04
#define GPIO_PIN_DIRECTION 0x08
-struct moxart_gpio_chip {
- struct gpio_chip gpio;
- void __iomem *base;
-};
-
-static inline struct moxart_gpio_chip *to_moxart_gpio(struct gpio_chip *chip)
-{
- return container_of(chip, struct moxart_gpio_chip, gpio);
-}
-
static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
{
return pinctrl_request_gpio(offset);
@@ -48,90 +39,60 @@ static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
pinctrl_free_gpio(offset);
}
-static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_DATA_OUT;
- u32 reg = readl(ioaddr);
-
- if (value)
- reg = reg | BIT(offset);
- else
- reg = reg & ~BIT(offset);
-
- writel(reg, ioaddr);
-}
-
static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- u32 ret = readl(gc->base + GPIO_PIN_DIRECTION);
+ struct bgpio_chip *bgc = to_bgpio_chip(chip);
+ u32 ret = bgc->read_reg(bgc->reg_dir);
if (ret & BIT(offset))
- return !!(readl(gc->base + GPIO_DATA_OUT) & BIT(offset));
+ return !!(bgc->read_reg(bgc->reg_set) & BIT(offset));
else
- return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset));
-}
-
-static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
-
- writel(readl(ioaddr) & ~BIT(offset), ioaddr);
- return 0;
+ return !!(bgc->read_reg(bgc->reg_dat) & BIT(offset));
}
-static int moxart_gpio_direction_output(struct gpio_chip *chip,
- unsigned offset, int value)
-{
- struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
- void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
-
- moxart_gpio_set(chip, offset, value);
- writel(readl(ioaddr) | BIT(offset), ioaddr);
- return 0;
-}
-
-static struct gpio_chip moxart_template_chip = {
- .label = "moxart-gpio",
- .request = moxart_gpio_request,
- .free = moxart_gpio_free,
- .direction_input = moxart_gpio_direction_input,
- .direction_output = moxart_gpio_direction_output,
- .set = moxart_gpio_set,
- .get = moxart_gpio_get,
- .ngpio = 32,
- .owner = THIS_MODULE,
-};
-
static int moxart_gpio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
- struct moxart_gpio_chip *mgc;
+ struct bgpio_chip *bgc;
+ void __iomem *base;
int ret;
- mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
- if (!mgc)
+ bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
+ if (!bgc)
return -ENOMEM;
- mgc->gpio = moxart_template_chip;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- mgc->base = devm_ioremap_resource(dev, res);
- if (IS_ERR(mgc->base))
- return PTR_ERR(mgc->base);
+ base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN,
+ base + GPIO_DATA_OUT, NULL,
+ base + GPIO_PIN_DIRECTION, NULL, 0);
+
+ if (ret) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return ret;
+ }
- mgc->gpio.dev = dev;
+ bgc->gc.label = "moxart-gpio";
+ bgc->gc.request = moxart_gpio_request;
+ bgc->gc.free = moxart_gpio_free;
+ bgc->gc.get = moxart_gpio_get;
+ bgc->data = bgc->read_reg(bgc->reg_set);
+ bgc->gc.ngpio = 32;
+ bgc->gc.dev = dev;
+ bgc->gc.owner = THIS_MODULE;
- ret = gpiochip_add(&mgc->gpio);
+ ret = gpiochip_add(&bgc->gc);
if (ret) {
dev_err(dev, "%s: gpiochip_add failed\n",
dev->of_node->full_name);
return ret;
}
- return 0;
+ return ret;
}
static const struct of_device_id moxart_gpio_match[] = {
--
1.9.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/5] convert to use basic mmio gpio library
2014-11-07 9:10 ` [PATCH 0/5] " Alexandre Courbot
@ 2014-11-13 9:48 ` Linus Walleij
0 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2014-11-13 9:48 UTC (permalink / raw)
To: Alexandre Courbot; +Cc: Kamlakant Patel, linux-gpio@vger.kernel.org
On Fri, Nov 7, 2014 at 10:10 AM, Alexandre Courbot <gnurou@gmail.com> wrote:
> On Wed, Oct 29, 2014 at 10:56 PM, <kamlakant.patel@linaro.org> wrote:
>> From: Kamlakant Patel <kamlakant.patel@linaro.org>
>>
>> This patch converts GPIO drivers to use BASIC MMIO GPIO library
>> (i.e GPIO GENERIC library) which makes drivers smaller and simpler.
>>
>> This patch needs to be tested on different platforms.
>
> This sounds like a good idea, but we will need to get a couple of
> Tested-by for each patch.
Any single Tested-by is enough for me. If it works for someone on
the real hardware I'll apply it ... testing resources are scarce.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] gpio: moxart: convert to use basic mmio gpio library
[not found] ` <CA+aN+yvwDtsm5g2o4mQPUBgzjtkJMUu-DXzXfZKzFyGg-C0PJw@mail.gmail.com>
@ 2014-11-28 8:02 ` Linus Walleij
2014-12-02 12:03 ` Kamlakant Patel
0 siblings, 1 reply; 12+ messages in thread
From: Linus Walleij @ 2014-11-28 8:02 UTC (permalink / raw)
To: Kamlakant Patel
Cc: Jonas Jensen, Alexandre Courbot, linux-gpio@vger.kernel.org
On Tue, Nov 18, 2014 at 12:35 PM, Kamlakant Patel
<kamlakant.patel@linaro.org> wrote:
> On 17 November 2014 19:23, Jonas Jensen <jonas.jensen@gmail.com> wrote:
>> On 12 November 2014 13:00, Kamlakant Patel <kamlakant.patel@linaro.org>
>> Tested-by: Jonas Jensen <jonas.jensen@gmail.com>
>
> Thanks for testing, I will send v2 patch with above updates.
I can't find this v2 (or is it v3?) in my Inbox, have you sent it?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/5] gpio: moxart: convert to use basic mmio gpio library
2014-11-28 8:02 ` Linus Walleij
@ 2014-12-02 12:03 ` Kamlakant Patel
0 siblings, 0 replies; 12+ messages in thread
From: Kamlakant Patel @ 2014-12-02 12:03 UTC (permalink / raw)
To: Linus Walleij; +Cc: Jonas Jensen, Alexandre Courbot, linux-gpio@vger.kernel.org
Hi Linus,
On 28 November 2014 at 13:32, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Tue, Nov 18, 2014 at 12:35 PM, Kamlakant Patel
> <kamlakant.patel@linaro.org> wrote:
>> On 17 November 2014 19:23, Jonas Jensen <jonas.jensen@gmail.com> wrote:
>>> On 12 November 2014 13:00, Kamlakant Patel <kamlakant.patel@linaro.org>
>
>>> Tested-by: Jonas Jensen <jonas.jensen@gmail.com>
>>
>> Thanks for testing, I will send v2 patch with above updates.
>
> I can't find this v2 (or is it v3?) in my Inbox, have you sent it?
>
Sorry for the delay, I have sent updated patch set.
Thanks,
Kamlakant Patel
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-12-02 12:03 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-29 13:56 [PATCH 0/5] convert to use basic mmio gpio library kamlakant.patel
2014-10-29 13:56 ` [PATCH 1/5] gpio: moxart: " kamlakant.patel
2014-11-03 14:08 ` Jonas Jensen
2014-11-07 4:31 ` Kamlakant Patel
2014-11-12 12:00 ` Kamlakant Patel
[not found] ` <CACmBeS1Gf4U-A_-HHy-c+iDRqt81vTaMxjKsekcjnVMvTxTBuw@mail.gmail.com>
[not found] ` <CA+aN+yvwDtsm5g2o4mQPUBgzjtkJMUu-DXzXfZKzFyGg-C0PJw@mail.gmail.com>
2014-11-28 8:02 ` Linus Walleij
2014-12-02 12:03 ` Kamlakant Patel
2014-10-29 13:56 ` [PATCH 2/5] gpio: timberdale: " kamlakant.patel
2014-10-29 13:56 ` [PATCH 3/5] gpio: iop: " kamlakant.patel
2014-10-29 13:56 ` [PATCH 4/5] gpio: ge: " kamlakant.patel
2014-11-07 9:10 ` [PATCH 0/5] " Alexandre Courbot
2014-11-13 9:48 ` Linus Walleij
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).