aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKamlakant Patel <kamlakant.patel@linaro.org>2014-12-01 07:09:34 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-01-09 04:24:29 -0500
commit3c01b9a896c9c592d9edc7439d5e5cf6c411d014 (patch)
tree55604a42e9d5c0fc608d1371a8a08e933615cd7b
parentb7392d2247cfe6771f95d256374f1a8e6a6f48d6 (diff)
gpio: moxart: convert to use basic mmio gpio library
This patch converts MOXART GPIO driver to use basic_mmio_gpio generic library. Signed-off-by: Kamlakant Patel <kamlakant.patel@linaro.org> Acked-by: Alexandre Courbot <acourbot@nvidia.com> Tested-by: Jonas Jensen <jonas.jensen@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/Kconfig1
-rw-r--r--drivers/gpio/gpio-moxart.c101
2 files changed, 32 insertions, 70 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 633ec216e185..e367296208a7 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -200,6 +200,7 @@ config GPIO_F7188X
200config GPIO_MOXART 200config GPIO_MOXART
201 bool "MOXART GPIO support" 201 bool "MOXART GPIO support"
202 depends on ARCH_MOXART 202 depends on ARCH_MOXART
203 select GPIO_GENERIC
203 help 204 help
204 Select this option to enable GPIO driver for 205 Select this option to enable GPIO driver for
205 MOXA ART SoC devices. 206 MOXA ART SoC devices.
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index 31e2551ed903..c3ab46e595da 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -23,21 +23,12 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/timer.h> 24#include <linux/timer.h>
25#include <linux/bitops.h> 25#include <linux/bitops.h>
26#include <linux/basic_mmio_gpio.h>
26 27
27#define GPIO_DATA_OUT 0x00 28#define GPIO_DATA_OUT 0x00
28#define GPIO_DATA_IN 0x04 29#define GPIO_DATA_IN 0x04
29#define GPIO_PIN_DIRECTION 0x08 30#define GPIO_PIN_DIRECTION 0x08
30 31
31struct moxart_gpio_chip {
32 struct gpio_chip gpio;
33 void __iomem *base;
34};
35
36static inline struct moxart_gpio_chip *to_moxart_gpio(struct gpio_chip *chip)
37{
38 return container_of(chip, struct moxart_gpio_chip, gpio);
39}
40
41static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset) 32static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
42{ 33{
43 return pinctrl_request_gpio(offset); 34 return pinctrl_request_gpio(offset);
@@ -48,90 +39,60 @@ static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
48 pinctrl_free_gpio(offset); 39 pinctrl_free_gpio(offset);
49} 40}
50 41
51static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
52{
53 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
54 void __iomem *ioaddr = gc->base + GPIO_DATA_OUT;
55 u32 reg = readl(ioaddr);
56
57 if (value)
58 reg = reg | BIT(offset);
59 else
60 reg = reg & ~BIT(offset);
61
62 writel(reg, ioaddr);
63}
64
65static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset) 42static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
66{ 43{
67 struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 44 struct bgpio_chip *bgc = to_bgpio_chip(chip);
68 u32 ret = readl(gc->base + GPIO_PIN_DIRECTION); 45 u32 ret = bgc->read_reg(bgc->reg_dir);
69 46
70 if (ret & BIT(offset)) 47 if (ret & BIT(offset))
71 return !!(readl(gc->base + GPIO_DATA_OUT) & BIT(offset)); 48 return !!(bgc->read_reg(bgc->reg_set) & BIT(offset));
72 else 49 else
73 return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset)); 50 return !!(bgc->read_reg(bgc->reg_dat) & BIT(offset));
74}
75
76static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
77{
78 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
79 void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
80
81 writel(readl(ioaddr) & ~BIT(offset), ioaddr);
82 return 0;
83}
84
85static int moxart_gpio_direction_output(struct gpio_chip *chip,
86 unsigned offset, int value)
87{
88 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
89 void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
90
91 moxart_gpio_set(chip, offset, value);
92 writel(readl(ioaddr) | BIT(offset), ioaddr);
93 return 0;
94} 51}
95 52
96static struct gpio_chip moxart_template_chip = {
97 .label = "moxart-gpio",
98 .request = moxart_gpio_request,
99 .free = moxart_gpio_free,
100 .direction_input = moxart_gpio_direction_input,
101 .direction_output = moxart_gpio_direction_output,
102 .set = moxart_gpio_set,
103 .get = moxart_gpio_get,
104 .ngpio = 32,
105 .owner = THIS_MODULE,
106};
107
108static int moxart_gpio_probe(struct platform_device *pdev) 53static int moxart_gpio_probe(struct platform_device *pdev)
109{ 54{
110 struct device *dev = &pdev->dev; 55 struct device *dev = &pdev->dev;
111 struct resource *res; 56 struct resource *res;
112 struct moxart_gpio_chip *mgc; 57 struct bgpio_chip *bgc;
58 void __iomem *base;
113 int ret; 59 int ret;
114 60
115 mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL); 61 bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
116 if (!mgc) 62 if (!bgc)
117 return -ENOMEM; 63 return -ENOMEM;
118 mgc->gpio = moxart_template_chip;
119 64
120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 65 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
121 mgc->base = devm_ioremap_resource(dev, res); 66 base = devm_ioremap_resource(dev, res);
122 if (IS_ERR(mgc->base)) 67 if (IS_ERR(base))
123 return PTR_ERR(mgc->base); 68 return PTR_ERR(base);
124 69
125 mgc->gpio.dev = dev; 70 ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN,
71 base + GPIO_DATA_OUT, NULL,
72 base + GPIO_PIN_DIRECTION, NULL, 0);
73 if (ret) {
74 dev_err(&pdev->dev, "bgpio_init failed\n");
75 return ret;
76 }
126 77
127 ret = gpiochip_add(&mgc->gpio); 78 bgc->gc.label = "moxart-gpio";
79 bgc->gc.request = moxart_gpio_request;
80 bgc->gc.free = moxart_gpio_free;
81 bgc->gc.get = moxart_gpio_get;
82 bgc->data = bgc->read_reg(bgc->reg_set);
83 bgc->gc.base = 0;
84 bgc->gc.ngpio = 32;
85 bgc->gc.dev = dev;
86 bgc->gc.owner = THIS_MODULE;
87
88 ret = gpiochip_add(&bgc->gc);
128 if (ret) { 89 if (ret) {
129 dev_err(dev, "%s: gpiochip_add failed\n", 90 dev_err(dev, "%s: gpiochip_add failed\n",
130 dev->of_node->full_name); 91 dev->of_node->full_name);
131 return ret; 92 return ret;
132 } 93 }
133 94
134 return 0; 95 return ret;
135} 96}
136 97
137static const struct of_device_id moxart_gpio_match[] = { 98static const struct of_device_id moxart_gpio_match[] = {