Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1320971 > unrolled thread
| Started by | Alban Bedel <albeu@free.fr> |
|---|---|
| First post | 2016-01-28 20:50 +0100 |
| Last post | 2016-02-08 04:00 +0100 |
| Articles | 5 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 1/5] gpio: ath79: Move to the generic GPIO driver Alban Bedel <albeu@free.fr> - 2016-01-28 20:50 +0100
[PATCH 5/5] gpio: ath79: Update the copyright notice Alban Bedel <albeu@free.fr> - 2016-01-28 20:50 +0100
[PATCH 3/5] gpio: ath79: Make the driver removable Alban Bedel <albeu@free.fr> - 2016-01-28 20:50 +0100
Re: [PATCH 3/5] gpio: ath79: Make the driver removable Alexandre Courbot <gnurou@gmail.com> - 2016-02-08 04:10 +0100
Re: [PATCH 1/5] gpio: ath79: Move to the generic GPIO driver Alexandre Courbot <gnurou@gmail.com> - 2016-02-08 04:00 +0100
| From | Alban Bedel <albeu@free.fr> |
|---|---|
| Date | 2016-01-28 20:50 +0100 |
| Subject | [PATCH 1/5] gpio: ath79: Move to the generic GPIO driver |
| Message-ID | <qW0JP-8ef-3@gated-at.bofh.it> |
Drop most of the code in favor of the generic MMIO GPIO driver.
As the driver now depend on CONFIG_GPIO_GENERIC also add a Kconfig
entry to make the driver optional.
We leave the base pointer and lock in the data struct because they are
needed for the IRQ support.
Signed-off-by: Alban Bedel <albeu@free.fr>
---
drivers/gpio/Kconfig | 9 ++++
drivers/gpio/Makefile | 2 +-
drivers/gpio/gpio-ath79.c | 126 ++++++----------------------------------------
3 files changed, 24 insertions(+), 113 deletions(-)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 00f1767..ee9909c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -126,6 +126,15 @@ config GPIO_AMDPT
driver for GPIO functionality on Promontory IOHub
Require ACPI ASL code to enumerate as a platform device.
+config GPIO_ATH79
+ tristate "Atheros AR71XX/AR724X/AR913X GPIO support"
+ default y if ATH79
+ depends on ATH79
+ select GPIO_GENERIC
+ help
+ Select this option to enable GPIO driver for
+ Atheros AR71XX/AR724X/AR913X SoC devices.
+
config GPIO_BCM_KONA
bool "Broadcom Kona GPIO"
depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST)
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index d4cc4f3..643b24e 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -24,7 +24,7 @@ obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o
obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o
obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
-obj-$(CONFIG_ATH79) += gpio-ath79.o
+obj-$(CONFIG_GPIO_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
index d13dd13..13d9648 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -19,115 +19,11 @@
#include <asm/mach-ath79/ar71xx_regs.h>
struct ath79_gpio_ctrl {
- struct gpio_chip chip;
+ struct gpio_chip gc;
void __iomem *base;
spinlock_t lock;
};
-static void ath79_gpio_set_value(struct gpio_chip *chip,
- unsigned gpio, int value)
-{
- struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
-
- if (value)
- __raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_SET);
- else
- __raw_writel(BIT(gpio), ctrl->base + AR71XX_GPIO_REG_CLEAR);
-}
-
-static int ath79_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
-{
- struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
-
- return (__raw_readl(ctrl->base + AR71XX_GPIO_REG_IN) >> gpio) & 1;
-}
-
-static int ath79_gpio_direction_input(struct gpio_chip *chip,
- unsigned offset)
-{
- struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
- unsigned long flags;
-
- spin_lock_irqsave(&ctrl->lock, flags);
-
- __raw_writel(
- __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) & ~BIT(offset),
- ctrl->base + AR71XX_GPIO_REG_OE);
-
- spin_unlock_irqrestore(&ctrl->lock, flags);
-
- return 0;
-}
-
-static int ath79_gpio_direction_output(struct gpio_chip *chip,
- unsigned offset, int value)
-{
- struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
- unsigned long flags;
-
- spin_lock_irqsave(&ctrl->lock, flags);
-
- if (value)
- __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_SET);
- else
- __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_CLEAR);
-
- __raw_writel(
- __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) | BIT(offset),
- ctrl->base + AR71XX_GPIO_REG_OE);
-
- spin_unlock_irqrestore(&ctrl->lock, flags);
-
- return 0;
-}
-
-static int ar934x_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
-{
- struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
- unsigned long flags;
-
- spin_lock_irqsave(&ctrl->lock, flags);
-
- __raw_writel(
- __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) | BIT(offset),
- ctrl->base + AR71XX_GPIO_REG_OE);
-
- spin_unlock_irqrestore(&ctrl->lock, flags);
-
- return 0;
-}
-
-static int ar934x_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
- int value)
-{
- struct ath79_gpio_ctrl *ctrl = gpiochip_get_data(chip);
- unsigned long flags;
-
- spin_lock_irqsave(&ctrl->lock, flags);
-
- if (value)
- __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_SET);
- else
- __raw_writel(BIT(offset), ctrl->base + AR71XX_GPIO_REG_CLEAR);
-
- __raw_writel(
- __raw_readl(ctrl->base + AR71XX_GPIO_REG_OE) & ~BIT(offset),
- ctrl->base + AR71XX_GPIO_REG_OE);
-
- spin_unlock_irqrestore(&ctrl->lock, flags);
-
- return 0;
-}
-
-static const 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" },
@@ -174,15 +70,21 @@ static int ath79_gpio_probe(struct platform_device *pdev)
return -ENOMEM;
spin_lock_init(&ctrl->lock);
- memcpy(&ctrl->chip, &ath79_gpio_chip, sizeof(ctrl->chip));
- ctrl->chip.parent = &pdev->dev;
- ctrl->chip.ngpio = ath79_gpio_count;
- if (oe_inverted) {
- ctrl->chip.direction_input = ar934x_gpio_direction_input;
- ctrl->chip.direction_output = ar934x_gpio_direction_output;
+ err = bgpio_init(&ctrl->gc, &pdev->dev, 4,
+ ctrl->base + AR71XX_GPIO_REG_IN,
+ ctrl->base + AR71XX_GPIO_REG_SET,
+ ctrl->base + AR71XX_GPIO_REG_CLEAR,
+ oe_inverted ? NULL : ctrl->base + AR71XX_GPIO_REG_OE,
+ oe_inverted ? ctrl->base + AR71XX_GPIO_REG_OE : NULL,
+ 0);
+ if (err) {
+ dev_err(&pdev->dev, "bgpio_init failed\n");
+ return err;
}
+ /* Use base 0 to stay compatible with legacy platforms */
+ ctrl->gc.base = 0;
- err = gpiochip_add_data(&ctrl->chip, ctrl);
+ err = gpiochip_add_data(&ctrl->gc, ctrl);
if (err) {
dev_err(&pdev->dev,
"cannot add AR71xx GPIO chip, error=%d", err);
--
2.0.0
[toc] | [next] | [standalone]
| From | Alban Bedel <albeu@free.fr> |
|---|---|
| Date | 2016-01-28 20:50 +0100 |
| Subject | [PATCH 5/5] gpio: ath79: Update the copyright notice |
| Message-ID | <qW0JQ-8ef-25@gated-at.bofh.it> |
| In reply to | #1320971 |
Add myself to the copyright list and remove the reference to Atheros' BSP as nothing is left of this code. Signed-off-by: Alban Bedel <albeu@free.fr> --- drivers/gpio/gpio-ath79.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c index 0d94c0b..018ea9d 100644 --- a/drivers/gpio/gpio-ath79.c +++ b/drivers/gpio/gpio-ath79.c @@ -1,12 +1,11 @@ /* * Atheros AR71XX/AR724X/AR913X GPIO API support * + * Copyright (C) 2015 Alban Bedel <albeu@free.fr> * 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. -- 2.0.0
[toc] | [prev] | [next] | [standalone]
| From | Alban Bedel <albeu@free.fr> |
|---|---|
| Date | 2016-01-28 20:50 +0100 |
| Subject | [PATCH 3/5] gpio: ath79: Make the driver removable |
| Message-ID | <qW0JS-8ef-57@gated-at.bofh.it> |
| In reply to | #1320971 |
As we now allow the driver to be built as a module it should be
removable.
Signed-off-by: Alban Bedel <albeu@free.fr>
---
drivers/gpio/gpio-ath79.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index afb535e..6b15792 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -46,6 +46,7 @@ static int ath79_gpio_probe(struct platform_device *pdev)
ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL);
if (!ctrl)
return -ENOMEM;
+ platform_set_drvdata(pdev, ctrl);
if (np) {
err = of_property_read_u32(np, "ngpios", &ath79_gpio_count);
@@ -97,12 +98,21 @@ static int ath79_gpio_probe(struct platform_device *pdev)
return 0;
}
+static int ath79_gpio_remove(struct platform_device *pdev)
+{
+ struct ath79_gpio_ctrl *ctrl = platform_get_drvdata(pdev);
+
+ gpiochip_remove(&ctrl->gc);
+ return 0;
+}
+
static struct platform_driver ath79_gpio_driver = {
.driver = {
.name = "ath79-gpio",
.of_match_table = ath79_gpio_of_match,
},
.probe = ath79_gpio_probe,
+ .remove = ath79_gpio_remove,
};
module_platform_driver(ath79_gpio_driver);
--
2.0.0
[toc] | [prev] | [next] | [standalone]
| From | Alexandre Courbot <gnurou@gmail.com> |
|---|---|
| Date | 2016-02-08 04:10 +0100 |
| Subject | Re: [PATCH 3/5] gpio: ath79: Make the driver removable |
| Message-ID | <qZKn8-7r7-3@gated-at.bofh.it> |
| In reply to | #1320992 |
On Fri, Jan 29, 2016 at 4:44 AM, Alban Bedel <albeu@free.fr> wrote:
> As we now allow the driver to be built as a module it should be
> removable.
>
> Signed-off-by: Alban Bedel <albeu@free.fr>
> ---
> drivers/gpio/gpio-ath79.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
> index afb535e..6b15792 100644
> --- a/drivers/gpio/gpio-ath79.c
> +++ b/drivers/gpio/gpio-ath79.c
> @@ -46,6 +46,7 @@ static int ath79_gpio_probe(struct platform_device *pdev)
> ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL);
> if (!ctrl)
> return -ENOMEM;
> + platform_set_drvdata(pdev, ctrl);
>
> if (np) {
> err = of_property_read_u32(np, "ngpios", &ath79_gpio_count);
> @@ -97,12 +98,21 @@ static int ath79_gpio_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static int ath79_gpio_remove(struct platform_device *pdev)
> +{
> + struct ath79_gpio_ctrl *ctrl = platform_get_drvdata(pdev);
platform_get_drvdata will return a gpio_chip *. I agree the address
will be the same, but for correctness you should use the expected
type. Especially since you will not use a member of ath79_gpio_ctrl in
this function anyway.
> +
> + gpiochip_remove(&ctrl->gc);
> + return 0;
> +}
I suspect this removal pattern to be quite common, maybe we should
just export bgpio_pdev_remove() to allow other drivers to use it
instead of rewriting their own version?
[toc] | [prev] | [next] | [standalone]
| From | Alexandre Courbot <gnurou@gmail.com> |
|---|---|
| Date | 2016-02-08 04:00 +0100 |
| Message-ID | <qZKds-77A-9@gated-at.bofh.it> |
| In reply to | #1320971 |
On Fri, Jan 29, 2016 at 4:44 AM, Alban Bedel <albeu@free.fr> wrote: > Drop most of the code in favor of the generic MMIO GPIO driver. > As the driver now depend on CONFIG_GPIO_GENERIC also add a Kconfig > entry to make the driver optional. > > We leave the base pointer and lock in the data struct because they are > needed for the IRQ support. > > Signed-off-by: Alban Bedel <albeu@free.fr> > --- > drivers/gpio/Kconfig | 9 ++++ > drivers/gpio/Makefile | 2 +- > drivers/gpio/gpio-ath79.c | 126 ++++++---------------------------------------- > 3 files changed, 24 insertions(+), 113 deletions(-) Nice, much less code! Acked-by: Alexandre Courbot <acourbot@nvidia.com>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web