MIPS: ath79: Move the GPIO driver to drivers/gpio
authorAlban Bedel <albeu@free.fr>
Fri, 3 Jul 2015 09:11:49 +0000 (11:11 +0200)
committerRalf Baechle <ralf@linux-mips.org>
Thu, 3 Sep 2015 10:08:02 +0000 (12:08 +0200)
GPIO drivers should be in drivers/gpio

Signed-off-by: Alban Bedel <albeu@free.fr>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: Gabor Juhos <juhosg@openwrt.org>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/10597/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/ath79/Makefile
arch/mips/ath79/gpio.c [deleted file]
drivers/gpio/Makefile
drivers/gpio/gpio-ath79.c [new file with mode: 0644]

index 5c9ff692ff3ca93ec1946f98095890983357b55d..fcc382cfc77091594093d8e01e814dc9bcd4060f 100644 (file)
@@ -8,7 +8,7 @@
 # under the terms of the GNU General Public License version 2 as published
 # by the Free Software Foundation.
 
-obj-y  := prom.o setup.o irq.o common.o clock.o gpio.o
+obj-y  := prom.o setup.o irq.o common.o clock.o
 
 obj-$(CONFIG_EARLY_PRINTK)             += early_printk.o
 obj-$(CONFIG_PCI)                      += pci.o
diff --git a/arch/mips/ath79/gpio.c b/arch/mips/ath79/gpio.c
deleted file mode 100644 (file)
index c3c92eb..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- *  Atheros AR71XX/AR724X/AR913X GPIO API support
- *
- *  Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
- *  Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
- *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
- *
- *  Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
- *
- *  This program is free software; you can redistribute it and/or modify it
- *  under the terms of the GNU General Public License version 2 as published
- *  by the Free Software Foundation.
- */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/spinlock.h>
-#include <linux/io.h>
-#include <linux/ioport.h>
-#include <linux/gpio.h>
-#include <linux/platform_data/gpio-ath79.h>
-#include <linux/of_device.h>
-
-#include <asm/mach-ath79/ar71xx_regs.h>
-
-static void __iomem *ath79_gpio_base;
-static u32 ath79_gpio_count;
-static DEFINE_SPINLOCK(ath79_gpio_lock);
-
-static void __ath79_gpio_set_value(unsigned gpio, int value)
-{
-       void __iomem *base = ath79_gpio_base;
-
-       if (value)
-               __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_SET);
-       else
-               __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_CLEAR);
-}
-
-static int __ath79_gpio_get_value(unsigned gpio)
-{
-       return (__raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_IN) >> gpio) & 1;
-}
-
-static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned offset)
-{
-       return __ath79_gpio_get_value(offset);
-}
-
-static void ath79_gpio_set_value(struct gpio_chip *chip,
-                                 unsigned offset, int value)
-{
-       __ath79_gpio_set_value(offset, value);
-}
-
-static int ath79_gpio_direction_input(struct gpio_chip *chip,
-                                      unsigned offset)
-{
-       void __iomem *base = ath79_gpio_base;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ath79_gpio_lock, flags);
-
-       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset),
-                    base + AR71XX_GPIO_REG_OE);
-
-       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
-
-       return 0;
-}
-
-static int ath79_gpio_direction_output(struct gpio_chip *chip,
-                                       unsigned offset, int value)
-{
-       void __iomem *base = ath79_gpio_base;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ath79_gpio_lock, flags);
-
-       if (value)
-               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET);
-       else
-               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR);
-
-       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset),
-                    base + AR71XX_GPIO_REG_OE);
-
-       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
-
-       return 0;
-}
-
-static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
-       void __iomem *base = ath79_gpio_base;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ath79_gpio_lock, flags);
-
-       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset),
-                    base + AR71XX_GPIO_REG_OE);
-
-       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
-
-       return 0;
-}
-
-static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
-                                       int value)
-{
-       void __iomem *base = ath79_gpio_base;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ath79_gpio_lock, flags);
-
-       if (value)
-               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET);
-       else
-               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR);
-
-       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset),
-                    base + AR71XX_GPIO_REG_OE);
-
-       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
-
-       return 0;
-}
-
-static struct gpio_chip ath79_gpio_chip = {
-       .label                  = "ath79",
-       .get                    = ath79_gpio_get_value,
-       .set                    = ath79_gpio_set_value,
-       .direction_input        = ath79_gpio_direction_input,
-       .direction_output       = ath79_gpio_direction_output,
-       .base                   = 0,
-};
-
-static const struct of_device_id ath79_gpio_of_match[] = {
-       { .compatible = "qca,ar7100-gpio" },
-       { .compatible = "qca,ar9340-gpio" },
-       {},
-};
-
-static int ath79_gpio_probe(struct platform_device *pdev)
-{
-       struct ath79_gpio_platform_data *pdata = pdev->dev.platform_data;
-       struct device_node *np = pdev->dev.of_node;
-       struct resource *res;
-       bool oe_inverted;
-       int err;
-
-       if (np) {
-               err = of_property_read_u32(np, "ngpios", &ath79_gpio_count);
-               if (err) {
-                       dev_err(&pdev->dev, "ngpios property is not valid\n");
-                       return err;
-               }
-               if (ath79_gpio_count >= 32) {
-                       dev_err(&pdev->dev, "ngpios must be less than 32\n");
-                       return -EINVAL;
-               }
-               oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio");
-       } else if (pdata) {
-               ath79_gpio_count = pdata->ngpios;
-               oe_inverted = pdata->oe_inverted;
-       } else {
-               dev_err(&pdev->dev, "No DT node or platform data found\n");
-               return -EINVAL;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       ath79_gpio_base = devm_ioremap_nocache(
-               &pdev->dev, res->start, resource_size(res));
-       if (!ath79_gpio_base)
-               return -ENOMEM;
-
-       ath79_gpio_chip.dev = &pdev->dev;
-       ath79_gpio_chip.ngpio = ath79_gpio_count;
-       if (oe_inverted) {
-               ath79_gpio_chip.direction_input = ar934x_gpio_direction_input;
-               ath79_gpio_chip.direction_output = ar934x_gpio_direction_output;
-       }
-
-       err = gpiochip_add(&ath79_gpio_chip);
-       if (err) {
-               dev_err(&pdev->dev,
-                       "cannot add AR71xx GPIO chip, error=%d", err);
-               return err;
-       }
-
-       return 0;
-}
-
-static struct platform_driver ath79_gpio_driver = {
-       .driver = {
-               .name = "ath79-gpio",
-               .of_match_table = ath79_gpio_of_match,
-       },
-       .probe = ath79_gpio_probe,
-};
-
-module_platform_driver(ath79_gpio_driver);
-
-int gpio_get_value(unsigned gpio)
-{
-       if (gpio < ath79_gpio_count)
-               return __ath79_gpio_get_value(gpio);
-
-       return __gpio_get_value(gpio);
-}
-EXPORT_SYMBOL(gpio_get_value);
-
-void gpio_set_value(unsigned gpio, int value)
-{
-       if (gpio < ath79_gpio_count)
-               __ath79_gpio_set_value(gpio, value);
-       else
-               __gpio_set_value(gpio, value);
-}
-EXPORT_SYMBOL(gpio_set_value);
-
-int gpio_to_irq(unsigned gpio)
-{
-       /* FIXME */
-       return -EINVAL;
-}
-EXPORT_SYMBOL(gpio_to_irq);
-
-int irq_to_gpio(unsigned irq)
-{
-       /* FIXME */
-       return -EINVAL;
-}
-EXPORT_SYMBOL(irq_to_gpio);
index f82cd678ce086e68da421506aceaed8d7b4f458b..2b64f6177e33cb36d9f0b965f4524f1461101576 100644 (file)
@@ -20,6 +20,7 @@ obj-$(CONFIG_GPIO_ADP5588)    += gpio-adp5588.o
 obj-$(CONFIG_GPIO_ALTERA)      += gpio-altera.o
 obj-$(CONFIG_GPIO_AMD8111)     += gpio-amd8111.o
 obj-$(CONFIG_GPIO_ARIZONA)     += gpio-arizona.o
+obj-$(CONFIG_ATH79)            += gpio-ath79.o
 obj-$(CONFIG_GPIO_BCM_KONA)    += gpio-bcm-kona.o
 obj-$(CONFIG_GPIO_BRCMSTB)     += gpio-brcmstb.o
 obj-$(CONFIG_GPIO_BT8XX)       += gpio-bt8xx.o
diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
new file mode 100644 (file)
index 0000000..c3c92eb
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ *  Atheros AR71XX/AR724X/AR913X GPIO API support
+ *
+ *  Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
+ *  Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
+ *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
+ *
+ *  Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms of the GNU General Public License version 2 as published
+ *  by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/gpio.h>
+#include <linux/platform_data/gpio-ath79.h>
+#include <linux/of_device.h>
+
+#include <asm/mach-ath79/ar71xx_regs.h>
+
+static void __iomem *ath79_gpio_base;
+static u32 ath79_gpio_count;
+static DEFINE_SPINLOCK(ath79_gpio_lock);
+
+static void __ath79_gpio_set_value(unsigned gpio, int value)
+{
+       void __iomem *base = ath79_gpio_base;
+
+       if (value)
+               __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_SET);
+       else
+               __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_CLEAR);
+}
+
+static int __ath79_gpio_get_value(unsigned gpio)
+{
+       return (__raw_readl(ath79_gpio_base + AR71XX_GPIO_REG_IN) >> gpio) & 1;
+}
+
+static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned offset)
+{
+       return __ath79_gpio_get_value(offset);
+}
+
+static void ath79_gpio_set_value(struct gpio_chip *chip,
+                                 unsigned offset, int value)
+{
+       __ath79_gpio_set_value(offset, value);
+}
+
+static int ath79_gpio_direction_input(struct gpio_chip *chip,
+                                      unsigned offset)
+{
+       void __iomem *base = ath79_gpio_base;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ath79_gpio_lock, flags);
+
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
+
+       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
+
+       return 0;
+}
+
+static int ath79_gpio_direction_output(struct gpio_chip *chip,
+                                       unsigned offset, int value)
+{
+       void __iomem *base = ath79_gpio_base;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ath79_gpio_lock, flags);
+
+       if (value)
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET);
+       else
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR);
+
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
+
+       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
+
+       return 0;
+}
+
+static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+       void __iomem *base = ath79_gpio_base;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ath79_gpio_lock, flags);
+
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
+
+       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
+
+       return 0;
+}
+
+static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
+                                       int value)
+{
+       void __iomem *base = ath79_gpio_base;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ath79_gpio_lock, flags);
+
+       if (value)
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET);
+       else
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR);
+
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
+
+       spin_unlock_irqrestore(&ath79_gpio_lock, flags);
+
+       return 0;
+}
+
+static struct gpio_chip ath79_gpio_chip = {
+       .label                  = "ath79",
+       .get                    = ath79_gpio_get_value,
+       .set                    = ath79_gpio_set_value,
+       .direction_input        = ath79_gpio_direction_input,
+       .direction_output       = ath79_gpio_direction_output,
+       .base                   = 0,
+};
+
+static const struct of_device_id ath79_gpio_of_match[] = {
+       { .compatible = "qca,ar7100-gpio" },
+       { .compatible = "qca,ar9340-gpio" },
+       {},
+};
+
+static int ath79_gpio_probe(struct platform_device *pdev)
+{
+       struct ath79_gpio_platform_data *pdata = pdev->dev.platform_data;
+       struct device_node *np = pdev->dev.of_node;
+       struct resource *res;
+       bool oe_inverted;
+       int err;
+
+       if (np) {
+               err = of_property_read_u32(np, "ngpios", &ath79_gpio_count);
+               if (err) {
+                       dev_err(&pdev->dev, "ngpios property is not valid\n");
+                       return err;
+               }
+               if (ath79_gpio_count >= 32) {
+                       dev_err(&pdev->dev, "ngpios must be less than 32\n");
+                       return -EINVAL;
+               }
+               oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio");
+       } else if (pdata) {
+               ath79_gpio_count = pdata->ngpios;
+               oe_inverted = pdata->oe_inverted;
+       } else {
+               dev_err(&pdev->dev, "No DT node or platform data found\n");
+               return -EINVAL;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       ath79_gpio_base = devm_ioremap_nocache(
+               &pdev->dev, res->start, resource_size(res));
+       if (!ath79_gpio_base)
+               return -ENOMEM;
+
+       ath79_gpio_chip.dev = &pdev->dev;
+       ath79_gpio_chip.ngpio = ath79_gpio_count;
+       if (oe_inverted) {
+               ath79_gpio_chip.direction_input = ar934x_gpio_direction_input;
+               ath79_gpio_chip.direction_output = ar934x_gpio_direction_output;
+       }
+
+       err = gpiochip_add(&ath79_gpio_chip);
+       if (err) {
+               dev_err(&pdev->dev,
+                       "cannot add AR71xx GPIO chip, error=%d", err);
+               return err;
+       }
+
+       return 0;
+}
+
+static struct platform_driver ath79_gpio_driver = {
+       .driver = {
+               .name = "ath79-gpio",
+               .of_match_table = ath79_gpio_of_match,
+       },
+       .probe = ath79_gpio_probe,
+};
+
+module_platform_driver(ath79_gpio_driver);
+
+int gpio_get_value(unsigned gpio)
+{
+       if (gpio < ath79_gpio_count)
+               return __ath79_gpio_get_value(gpio);
+
+       return __gpio_get_value(gpio);
+}
+EXPORT_SYMBOL(gpio_get_value);
+
+void gpio_set_value(unsigned gpio, int value)
+{
+       if (gpio < ath79_gpio_count)
+               __ath79_gpio_set_value(gpio, value);
+       else
+               __gpio_set_value(gpio, value);
+}
+EXPORT_SYMBOL(gpio_set_value);
+
+int gpio_to_irq(unsigned gpio)
+{
+       /* FIXME */
+       return -EINVAL;
+}
+EXPORT_SYMBOL(gpio_to_irq);
+
+int irq_to_gpio(unsigned irq)
+{
+       /* FIXME */
+       return -EINVAL;
+}
+EXPORT_SYMBOL(irq_to_gpio);