powerpc/mpc512x: Add gpio driver
Subsystems (2)
Anatolij Gustschin
maintainerPATCH v3 1/1 powerpc/mpc512x: Add gpio driver
From: Matthias Fuchs <[email protected]>
This patch adds a gpio driver for MPC512X PowerPCs.
It has been tested on our CAN-CBX-CPU5201 module that uses a MPC5121 CPU. This platform comes with a couple of LEDs and configuration switches that have been used for testing.
---
Please consider this patch for inclusion in 2.6.36. Thanks!
v3: - rebase to apply on current mainline tree
- v2 switched to shadow registers but these are not pre-initialized (zero). As a result, setting pin direction or ODR register will clear other bits in direction and ODR registers. Fix this bug by adding shadow registers initialization code.
v2: - move driver to arch/powerpc/platforms/512x directory
- Kconfig changes are now in arch/powerpc/platform/512x/Kconfig
- put struct mpc512x_gpio_regs in driver's .c file
- rename GPIO_MASK into MPC512x_GPIO_MASK
- use shadow registers instead of r/m/w-operations
- don't use arch_initcall but call mpc512x_add_gpiochips() from mpc512x platform setup code.
arch/powerpc/platforms/512x/Kconfig | 9 ++ arch/powerpc/platforms/512x/Makefile | 1 + arch/powerpc/platforms/512x/mpc512x.h | 3 + arch/powerpc/platforms/512x/mpc512x_gpio.c | 198 ++++++++++++++++++++++++++ arch/powerpc/platforms/512x/mpc512x_shared.c | 3 + 5 files changed, 214 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/platforms/512x/mpc512x_gpio.c
arch/powerpc/platforms/512x/Kconfig +9 -0
@@ -30,3 +30,12 @@ config MPC5121_GENERIC Compatible boards include: Protonic LVT base boards (ZANMCU and VICVT2). + +config MPC512x_GPIO + bool "MPC512x GPIO support" + depends on PPC_MPC512x + select GENERIC_GPIO + select ARCH_REQUIRE_GPIOLIB + help + Say Y here if you're going to use hardware that connects to the + MPC512x GPIOs.
arch/powerpc/platforms/512x/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-y += clock.o mpc512x_shared.o obj-$(CONFIG_MPC5121_ADS) += mpc5121_ads.o mpc5121_ads_cpld.o obj-$(CONFIG_MPC5121_GENERIC) += mpc5121_generic.o +obj-$(CONFIG_MPC512x_GPIO) += mpc512x_gpio.o
arch/powerpc/platforms/512x/mpc512x.h +3 -0
@@ -16,4 +16,7 @@ extern void __init mpc512x_init(void);extern int __init mpc5121_clk_init (void );void __init mpc512x_declare_of_platform_devices (void );extern void mpc512x_restart (char *cmd); +#ifdef CONFIG_MPC512x_GPIO +extern int mpc512x_add_gpiochips (void ); +#endif #endif /* __MPC512X_H__ */
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +198 -0
198 lines not on this page · raw message
arch/powerpc/platforms/512x/mpc512x_shared.c +3 -0
@@ -178,4 +178,7 @@ void __init mpc512x_init(void)mpc5121_clk_init ();mpc512x_restart_init ();mpc512x_psc_fifo_init (); +#ifdef CONFIG_MPC512x_GPIO +mpc512x_add_gpiochips (); +#endif }
Signature · 1 line
1.7.0.4
Anatolij Gustschin
maintainerPATCH v4 1/1 powerpc/mpc512x: Add gpio driver
From: Matthias Fuchs <[email protected]>
This patch adds a gpio driver for MPC512X PowerPCs.
It has been tested on our CAN-CBX-CPU5201 module that uses a MPC5121 CPU. This platform comes with a couple of LEDs and configuration switches that have been used for testing.
---
Please consider this patch for inclusion in 2.6.36. Thanks!
v4: - actually v3 was rebased but without shadow
registers init code as stated in the v3 changelog. Correct it now.
v3: - rebase to apply on current mainline tree
- v2 switched to shadow registers but these are not pre-initialized (zero). As a result, setting pin direction or ODR register will clear other bits in direction and ODR registers. Fix this bug by adding shadow registers initialization code.
v2: - move driver to arch/powerpc/platforms/512x directory
- Kconfig changes are now in arch/powerpc/platform/512x/Kconfig
- put struct mpc512x_gpio_regs in driver's .c file
- rename GPIO_MASK into MPC512x_GPIO_MASK
- use shadow registers instead of r/m/w-operations
- don't use arch_initcall but call mpc512x_add_gpiochips() from mpc512x platform setup code.
arch/powerpc/platforms/512x/Kconfig | 9 + arch/powerpc/platforms/512x/Makefile | 1 + arch/powerpc/platforms/512x/mpc512x.h | 3 + arch/powerpc/platforms/512x/mpc512x_gpio.c | 204 ++++++++++++++++++++++++++ arch/powerpc/platforms/512x/mpc512x_shared.c | 3 + 5 files changed, 220 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/platforms/512x/mpc512x_gpio.c
arch/powerpc/platforms/512x/Kconfig +9 -0
@@ -30,3 +30,12 @@ config MPC5121_GENERIC Compatible boards include: Protonic LVT base boards (ZANMCU and VICVT2). + +config MPC512x_GPIO + bool "MPC512x GPIO support" + depends on PPC_MPC512x + select GENERIC_GPIO + select ARCH_REQUIRE_GPIOLIB + help + Say Y here if you're going to use hardware that connects to the + MPC512x GPIOs.
arch/powerpc/platforms/512x/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-y += clock.o mpc512x_shared.o obj-$(CONFIG_MPC5121_ADS) += mpc5121_ads.o mpc5121_ads_cpld.o obj-$(CONFIG_MPC5121_GENERIC) += mpc5121_generic.o +obj-$(CONFIG_MPC512x_GPIO) += mpc512x_gpio.o
arch/powerpc/platforms/512x/mpc512x.h +3 -0
@@ -16,4 +16,7 @@ extern void __init mpc512x_init(void);extern int __init mpc5121_clk_init (void );void __init mpc512x_declare_of_platform_devices (void );extern void mpc512x_restart (char *cmd); +#ifdef CONFIG_MPC512x_GPIO +extern int mpc512x_add_gpiochips (void ); +#endif #endif /* __MPC512X_H__ */
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +204 -0
204 lines not on this page · raw message
arch/powerpc/platforms/512x/mpc512x_shared.c +3 -0
@@ -178,4 +178,7 @@ void __init mpc512x_init(void)mpc5121_clk_init ();mpc512x_restart_init ();mpc512x_psc_fifo_init (); +#ifdef CONFIG_MPC512x_GPIO +mpc512x_add_gpiochips (); +#endif }
Signature · 1 line
1.7.0.4
Quoted 10 lines · Anatolij Gustschin
From: Matthias Fuchs <[email protected]>
This patch adds a gpio driver for MPC512X PowerPCs.
It has been tested on our CAN-CBX-CPU5201 module that uses a MPC5121 CPU. This platform comes with a couple of LEDs and configuration switches that have been used for testing.
Signed-off-by Matthias Fuchs <[email protected]>Signed-off-by Anatolij Gustschin <[email protected]>
Hi Anatolij,
Can you please rework this one on top of my next-devicetree branch. Change have been made to the of-gpio apis.
g.
Quoted 22 lines
---
Please consider this patch for inclusion in 2.6.36. Thanks!v4: - actually v3 was rebased but without shadow =A0 =A0 =A0registers init code as stated in the v3 changelog. =A0 =A0 =A0Correct it now.
v3: - rebase to apply on current mainline tree
=A0 =A0- v2 switched to shadow registers but these are =A0 =A0 =A0not pre-initialized (zero). As a result, setting =A0 =A0 =A0pin direction or ODR register will clear other bits =A0 =A0 =A0in direction and ODR registers. Fix this bug by adding =A0 =A0 =A0shadow registers initialization code.v2: - move driver to
arch/powerpc/platforms/512xdirectory =A0 =A0-Kconfigchanges are now inarch/powerpc/platform/512x/Kconfig=A0 =A0- put structmpc512x_gpio_regsin driver's .c file =A0 =A0- renameGPIO_MASKintoMPC512x_GPIO_MASK
=A0 =A0- use shadow registers instead of r/m/w-operations =A0 =A0- don't usearch_initcallbut callmpc512x_add_gpiochips()=A0 =A0 =A0from mpc512x platform setup code.
Quoted 4 lines
=A0arch/powerpc/platforms/512x/Kconfig =A0 =A0 =A0 =A0 =A0| =A0 =A09 + =A0arch/powerpc/platforms/512x/Makefile =A0 =A0 =A0 =A0 | =A0 =A01 + =A0arch/powerpc/platforms/512x/mpc512x.h =A0 =A0 =A0 =A0| =A0 =A03 + =A0arch/powerpc/platforms/512x/mpc512x_gpio.c =A0 | =A0204 ++++++++++++++=
++++++++++++
arch/powerpc/platforms=
Quoted 5 lines
=A0arch/powerpc/platforms/512x/mpc512x_shared.c | =A0 =A03 + =A05 files changed, 220 insertions(+), 0 deletions(-) =A0create mode 100644
arch/powerpc/platforms/512x/mpc512x_gpio.carch/powerpc/platforms= renamed from arch/powerpc/platforms/512x/Kconfig +0
-0
/512x/Kconfig
Quoted 6 lines
index 4dac9b0..bd763ee 100644
arch/powerpc/platforms/512x/Kconfig +0
-0@@ -30,3 +30,12 @@ config MPC5121_GENERIC=A0 =A0 =A0 =A0 =A0Compatible boards include: =A0Protonic LVT base boards=
(ZANMCU
arch/powerpc/platforms/512x/Kconfig
Quoted 9 lines
=A0 =A0 =A0 =A0 =A0and VICVT2).
arch/powerpc/platforms/512x/Kconfig +8
-0+ +config MPC512x_GPIO + =A0 =A0 =A0 bool "MPC512x GPIO support" + =A0 =A0 =A0 depends on PPC_MPC512x + =A0 =A0 =A0 select GENERIC_GPIO + =A0 =A0 =A0 select ARCH_REQUIRE_GPIOLIB + =A0 =A0 =A0 help + =A0 =A0 =A0 =A0 Say Y here if you're going to use hardware that connect=
s to the
arch/powerpc/platform=
Quoted 2 lines
+ =A0 =A0 =A0 =A0 MPC512x GPIOs.
arch/powerpc/platform= renamed from arch/powerpc/platforms/512x/Makefile +0
-0
s/512x/Makefile
Quoted 5 lines
index 90be2f5..12518e3 100644
arch/powerpc/platforms/512x/Makefile +0
-0@@ -4,3 +4,4 @@=A0obj-y =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0+=3D clock.o =
mpc512x_shared.o
Quoted 1 line
=A0obj-$(CONFIG_MPC5121_ADS) =A0 =A0 =A0+=3D mpc5121_ads.o mpc5121_ads_cp=
ld.o
arch/powerpc/platfor=
Quoted 3 lines
=A0obj-$(CONFIG_MPC5121_GENERIC) =A0+=3D mpc5121_generic.o
arch/powerpc/platforms/512x/Makefile +1
-0+obj-$(CONFIG_MPC512x_GPIO) =A0 =A0 +=3D mpc512x_gpio.oarch/powerpc/platfor= renamed from arch/powerpc/platforms/512x/mpc512x.h +0
-0
ms/512x/mpc512x.h
Quoted 11 lines
index b2daca0..4a1b094 100644
arch/powerpc/platforms/512x/mpc512x.h +3
-0@@ -16,4 +16,7 @@ extern void __init mpc512x_init(void); =A0extern int __init mpc5121_clk_init(void); =A0void __init mpc512x_declare_of_platform_devices(void); =A0extern void mpc512x_restart(char *cmd); +#ifdef CONFIG_MPC512x_GPIO +extern int mpc512x_add_gpiochips (void ); +#endif =A0#endif =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* __MPC512X_H_=
_ */
arch/powerpc/pl=
Quoted 1 line
arch/powerpc/pl= renamed from arch/powerpc/platforms/512x/mpc512x_gpio.c +0
-0
atforms/512x/mpc512x_gpio.c
Quoted 20 lines
new file mode 100644
index 0000000..13b2478arch/powerpc/platforms/512x/mpc512x_gpio.c new file +15
-0@@ -0,0 +1,204 @@ +/* +* MPC512x gpio driver +* +* Copyright (c) 2010 Matthias Fuchs <[email protected]>, esd gmbh +* +* derived from ppc4xx gpio driver +* +* Copyright (c) 2008 Harris Corporation +* Copyright (c) 2008 Sascha Hauer <[email protected]>, Pengutronix +* Copyright (c) MontaVista Software, Inc. 2008. +* +* Author: Steve Falco <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2
arch/powerpc/platforms/512x/mpc512x_gpio.c line 25
Quoted 10 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +10
-0+* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =A0See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA =A002111-130=
7 =A0USA
Quoted 44 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +44
-0+*/ + +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/spinlock.h> +#include <linux/io.h> +#include <linux/of.h> +#include <linux/of_gpio.h> +#include <linux/gpio.h> +#include <linux/types.h> + +#define MPC512x_GPIO_MASK (gpio) (0x80000000 >> (gpio)) + +struct mpc512x_gpio_regs { + =A0 =A0 =A0 u32 gpdir; + =A0 =A0 =A0 u32 gpodr; + =A0 =A0 =A0 u32 gpdat; + =A0 =A0 =A0 u32 gpier; + =A0 =A0 =A0 u32 gpimr; + =A0 =A0 =A0 u32 gpicr1; + =A0 =A0 =A0 u32 gpicr2; +}; + +struct mpc512x_chip { + =A0 =A0 =A0 struct of_mm_gpio_chip mm_gc; + =A0 =A0 =A0 spinlock_t lock; + + =A0 =A0 =A0 /* shadow registers */ + =A0 =A0 =A0 u32 dat; + =A0 =A0 =A0 u32 odr; + =A0 =A0 =A0 u32 dir; +}; + +/* +* GPIO LIB API implementation for GPIOs +* +* There are a maximum of 32 gpios in each gpio controller. +*/ +static inline struct mpc512x_chip * +to_mpc512x_gpiochip (struct of_mm_gpio_chip *mm_gc) +{ + =A0 =A0 =A0 return container_of(mm_gc, struct mpc512x_chip, mm_gc); +} +
arch/powerpc/platforms/512x/mpc512x_gpio.c
Quoted 10 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +10
-0+static int mpc512x_gpio_get (struct gpio_chip *gc,unsigned int gpio) +{ + =A0 =A0 =A0 struct of_mm_gpio_chip *mm_gc =3D to_of_mm_gpio_chip(gc); + =A0 =A0 =A0 struct mpc512x_gpio_regs __iomem *regs =3D mm_gc->regs; + + =A0 =A0 =A0 return in_be32(®s->gpdat) & MPC512x_GPIO_MASK(gpio); +} + +static inline void +__mpc512x_gpio_set(struct of_mm_gpio_chip *mm_gc, unsigned int gpio, int=
val)
Quoted 82 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +82
-0+{ + =A0 =A0 =A0 struct mpc512x_chip *chip =3D to_mpc512x_gpiochip(mm_gc); + =A0 =A0 =A0 struct mpc512x_gpio_regs __iomem *regs =3D mm_gc->regs; + + + =A0 =A0 =A0 if (val) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 chip->dat |=3D MPC512x_GPIO_MASK(gpio); + =A0 =A0 =A0 else + =A0 =A0 =A0 =A0 =A0 =A0 =A0 chip->dat &=3D ~MPC512x_GPIO_MASK(gpio); + + =A0 =A0 =A0 out_be32(®s->gpdat, chip->dat); +} + +static void +mpc512x_gpio_set (struct gpio_chip *gc,unsigned int gpio,int val) +{ + =A0 =A0 =A0 struct of_mm_gpio_chip *mm_gc =3D to_of_mm_gpio_chip(gc); + =A0 =A0 =A0 struct mpc512x_chip *chip =3D to_mpc512x_gpiochip(mm_gc); + =A0 =A0 =A0 unsigned long flags; + + =A0 =A0 =A0 spin_lock_irqsave(&chip->lock, flags); + + =A0 =A0 =A0 __mpc512x_gpio_set(mm_gc, gpio, val); + + =A0 =A0 =A0 spin_unlock_irqrestore(&chip->lock, flags); + + =A0 =A0 =A0 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val); +} + +static int mpc512x_gpio_dir_in (struct gpio_chip *gc,unsigned int gpio) +{ + =A0 =A0 =A0 struct of_mm_gpio_chip *mm_gc =3D to_of_mm_gpio_chip(gc); + =A0 =A0 =A0 struct mpc512x_chip *chip =3D to_mpc512x_gpiochip(mm_gc); + =A0 =A0 =A0 struct mpc512x_gpio_regs __iomem *regs =3D mm_gc->regs; + =A0 =A0 =A0 unsigned long flags; + + =A0 =A0 =A0 spin_lock_irqsave(&chip->lock, flags); + + =A0 =A0 =A0 /* Disable open-drain function */ + =A0 =A0 =A0 chip->odr &=3D ~MPC512x_GPIO_MASK(gpio); + =A0 =A0 =A0 out_be32(®s->gpodr, chip->odr); + + =A0 =A0 =A0 /* Float the pin */ + =A0 =A0 =A0 chip->dir &=3D ~MPC512x_GPIO_MASK(gpio); + =A0 =A0 =A0 out_be32(®s->gpdir, chip->dir); + + =A0 =A0 =A0 spin_unlock_irqrestore(&chip->lock, flags); + + =A0 =A0 =A0 return 0; +} + +static int +mpc512x_gpio_dir_out (struct gpio_chip *gc,unsigned int gpio,int val) +{ + =A0 =A0 =A0 struct of_mm_gpio_chip *mm_gc =3D to_of_mm_gpio_chip(gc); + =A0 =A0 =A0 struct mpc512x_chip *chip =3D to_mpc512x_gpiochip(mm_gc); + =A0 =A0 =A0 struct mpc512x_gpio_regs __iomem *regs =3D mm_gc->regs; + =A0 =A0 =A0 unsigned long flags; + + =A0 =A0 =A0 spin_lock_irqsave(&chip->lock, flags); + + =A0 =A0 =A0 /* First set initial value */ + =A0 =A0 =A0 __mpc512x_gpio_set(mm_gc, gpio, val); + + =A0 =A0 =A0 /* Disable open-drain function */ + =A0 =A0 =A0 chip->odr &=3D ~MPC512x_GPIO_MASK(gpio); + =A0 =A0 =A0 out_be32(®s->gpodr, chip->odr); + + =A0 =A0 =A0 /* Drive the pin */ + =A0 =A0 =A0 chip->dir |=3D MPC512x_GPIO_MASK(gpio); + =A0 =A0 =A0 out_be32(®s->gpdir, chip->dir); + + =A0 =A0 =A0 spin_unlock_irqrestore(&chip->lock, flags); + + =A0 =A0 =A0 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val); + + =A0 =A0 =A0 return 0; +} + +void __init mpc512x_add_gpiochips (void ) +{ + =A0 =A0 =A0 struct device_node *np;
arch/powerpc/platforms/512x/mpc512x_gpio.c line 171
Quoted 10 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +10
-0+ + =A0 =A0 =A0 for_each_compatible_node(np, NULL, "fsl,mpc5121-gpio") { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 int ret; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct mpc512x_chip *chip; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct of_mm_gpio_chip *mm_gc; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct of_gpio_chip *of_gc; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct gpio_chip *gc; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct mpc512x_gpio_regs __iomem *regs; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 chip =3D kzalloc(sizeof(*chip), GFP_KERNEL)=
;
arch/powerpc/platforms/512x/mpc512x_gpio.c line 184
Quoted 13 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +13
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (!chip) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -ENOMEM; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_init(&chip->lock); + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mm_gc =3D &chip->mm_gc; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 of_gc =3D &mm_gc->of_gc; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 gc =3D &of_gc->gc; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 gc->ngpio =3D 32; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 gc->direction_input =3D mpc512x_gpio_dir_in=
;
arch/powerpc/platforms/512x/mpc512x_gpio.c line 185
Quoted 1 line
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gc->direction_output =3D mpc512x_gpio_dir_o=
ut;
Quoted 4 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +4
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 gc->get =3D mpc512x_gpio_get; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 gc->set =3D mpc512x_gpio_set; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_mm_gpiochip_add(np, mm_gc);
arch/powerpc/platforms/512x/mpc512x_gpio.c line 199
Quoted 10 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +10
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ret) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto err; + + =A0 =A0 =A0 =A0 =A0 =A0 =A0 regs =3D mm_gc->regs; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 chip->dat =3D in_be32(®s->gpdat); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 chip->dir =3D in_be32(®s->gpdir); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 chip->odr =3D in_be32(®s->gpodr); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 continue; +err: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pr_err("%s: registration failed with status=
%d\n",
arch/powerpc/=
Quoted 6 lines
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0np->full_name, ret); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 kfree(chip); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* try others anyway */ + =A0 =A0 =A0 } +}arch/powerpc/= renamed from arch/powerpc/platforms/512x/mpc512x_shared.c +0
-0
platforms/512x/mpc512x_shared.c
Quoted 12 lines
index 707e572..15da1bc 100644
arch/powerpc/platforms/512x/mpc512x_shared.c +3
-1@@ -178,4 +178,7 @@ void __init mpc512x_init(void) =A0 =A0 =A0 =A0mpc5121_clk_init (); =A0 =A0 =A0 =A0mpc512x_restart_init(); =A0 =A0 =A0 =A0mpc512x_psc_fifo_init(); +#ifdef CONFIG_MPC512x_GPIO + =A0 =A0 =A0 mpc512x_add_gpiochips(); +#endif =A0} --
Quoted 3 lines
1.7.0.4
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Anatolij Gustschin
maintainerHi Grant,
Quoted 9 lines · On Thu, 10 Jun 2010 15:48:42 -0600 Grant Likely <[email protected]>…
Quoted 8 lines · Anatolij Gustschin
From: Matthias Fuchs <[email protected]>
This patch adds a gpio driver for MPC512X PowerPCs.
It has been tested on our CAN-CBX-CPU5201 module that uses a MPC5121 CPU. This platform comes with a couple of LEDs and configuration switches that have been used for testing.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Matthias Fuchs <[email protected]>Signed-off-by Anatolij Gustschin <[email protected]>Hi Anatolij,
Can you please rework this one on top of my next-devicetree branch. Change have been made to the of-gpio apis.
Ok, I'll look at it.
Anatolij
Anatolij Gustschin
maintainerPATCH v5 1/1 powerpc/mpc512x: Add gpio driver
In reply to Grant LikelyFrom: Matthias Fuchs <[email protected]>
This patch adds a gpio driver for MPC512X PowerPCs.
It has been tested on our CAN-CBX-CPU5201 module that uses a MPC5121 CPU. This platform comes with a couple of LEDs and configuration switches that have been used for testing.
After change to the of-gpio api the reworked driver has been tested on pdm360ng board with some configuration switches.
---
Please consider this patch for inclusion in 2.6.36. Thanks!
v4 -> v5:
- reworked after change to the of-gpio api,
tested on top of the next-devicetree branch.
arch/powerpc/platforms/512x/Kconfig | 9 + arch/powerpc/platforms/512x/Makefile | 1 + arch/powerpc/platforms/512x/mpc512x.h | 3 + arch/powerpc/platforms/512x/mpc512x_gpio.c | 202 ++++++++++++++++++++++++++ arch/powerpc/platforms/512x/mpc512x_shared.c | 3 + 5 files changed, 218 insertions(+), 0 deletions(-) create mode 100644 arch/powerpc/platforms/512x/mpc512x_gpio.c
arch/powerpc/platforms/512x/Kconfig +9 -0
@@ -30,3 +30,12 @@ config MPC5121_GENERIC Compatible boards include: Protonic LVT base boards (ZANMCU and VICVT2). + +config MPC512x_GPIO + bool "MPC512x GPIO support" + depends on PPC_MPC512x + select GENERIC_GPIO + select ARCH_REQUIRE_GPIOLIB + help + Say Y here if you're going to use hardware that connects to the + MPC512x GPIOs.
arch/powerpc/platforms/512x/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-y += clock.o mpc512x_shared.o obj-$(CONFIG_MPC5121_ADS) += mpc5121_ads.o mpc5121_ads_cpld.o obj-$(CONFIG_MPC5121_GENERIC) += mpc5121_generic.o +obj-$(CONFIG_MPC512x_GPIO) += mpc512x_gpio.o
arch/powerpc/platforms/512x/mpc512x.h +3 -0
@@ -16,4 +16,7 @@ extern void __init mpc512x_init(void);extern int __init mpc5121_clk_init (void );void __init mpc512x_declare_of_platform_devices (void );extern void mpc512x_restart (char *cmd); +#ifdef CONFIG_MPC512x_GPIO +extern int mpc512x_add_gpiochips (void ); +#endif #endif /* __MPC512X_H__ */
arch/powerpc/platforms/512x/mpc512x_gpio.c new file +202 -0
202 lines not on this page · raw message
arch/powerpc/platforms/512x/mpc512x_shared.c +3 -0
@@ -178,4 +178,7 @@ void __init mpc512x_init(void)mpc5121_clk_init ();mpc512x_restart_init ();mpc512x_psc_fifo_init (); +#ifdef CONFIG_MPC512x_GPIO +mpc512x_add_gpiochips (); +#endif }
Signature · 1 line
1.7.0.4
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Anatolij" == Anatolij Gustschin <[email protected]> writes:
Hi,
Old mail, I know ..
Anatolij> From: Matthias Fuchs <[email protected]> Anatolij> This patch adds a gpio driver for MPC512X PowerPCs.
Anatolij> It has been tested on our CAN-CBX-CPU5201 module that Anatolij> uses a MPC5121 CPU. This platform comes with a couple of Anatolij> LEDs and configuration switches that have been used for testing.
Anatolij> After change to the of-gpio api the reworked driver has been Anatolij> tested on pdm360ng board with some configuration switches.
This looks very similar to the existing arch/powerpc/sysdev/mpc8xxx_gpio.c - Couldn't we just add 5121 support there instead?
Anatolij> +struct mpc512x_gpio_regs {
Anatolij> + u32 gpdir;
Anatolij> + u32 gpodr;
Anatolij> + u32 gpdat;
Anatolij> + u32 gpier;
Anatolij> + u32 gpimr;
Anatolij> + u32 gpicr1;
Anatolij> + u32 gpicr2;
Anatolij> +};
Signature · 1 line
Bye, Peter Korsgaard
Quoted 4 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Anatolij" =3D=3D Anatolij Gustschin <[email protected]> writes:
Hi,
Quoted 8 lines
Old mail, I know ..
=A0Anatolij> From: Matthias Fuchs <[email protected]> =A0Anatolij> This patch adds a gpio driver for MPC512X PowerPCs.
=A0Anatolij> It has been tested on our CAN-CBX-CPU5201 module that =A0Anatolij> uses a MPC5121 CPU. This platform comes with a couple of =A0Anatolij> LEDs and configuration switches that have been used for test=
ing.
Quoted 8 lines
=A0Anatolij> After change to the of-gpio api the reworked driver has been =A0Anatolij> tested on pdm360ng board with some configuration switches.
This looks very similar to the existing
arch/powerpc/sysdev/mpc8xxx_gpio.c- Couldn't we just add 5121 support there instead?
Quoted 9 lines
=A0Anatolij> +struct
mpc512x_gpio_regs{
=A0Anatolij> + =A0 =A0u32 gpdir;
=A0Anatolij> + =A0 =A0u32 gpodr;
=A0Anatolij> + =A0 =A0u32 gpdat;
=A0Anatolij> + =A0 =A0u32 gpier;
=A0Anatolij> + =A0 =A0u32 gpimr;
=A0Anatolij> + =A0 =A0u32 gpicr1;
=A0Anatolij> + =A0 =A0u32 gpicr2;
=A0Anatolij> +};
Hi Anatolij,
Peter's right, the register map looks the same, except for the additional gpicr1 & 2 registers in the 512x version. Can the 512x gpios be supported by the 8xxx gpio driver?
g.
Anatolij Gustschin
maintainerQuoted 5 lines · On Thu, 29 Jul 2010 01:19:23 -0600 Grant Likely <[email protected]>…
Quoted 4 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Anatolij" =3D=3D Anatolij Gustschin <[email protected]> writes:
Hi,
Quoted 8 lines
Quoted 8 lines
Old mail, I know ..
=A0Anatolij> From: Matthias Fuchs <[email protected]> =A0Anatolij> This patch adds a gpio driver for MPC512X PowerPCs.
=A0Anatolij> It has been tested on our CAN-CBX-CPU5201 module that =A0Anatolij> uses a MPC5121 CPU. This platform comes with a couple of =A0Anatolij> LEDs and configuration switches that have been used for te=
sting.
Quoted 2 lines
Quoted 2 lines
=A0Anatolij> After change to the of-gpio api the reworked driver has be=
en
Quoted 15 lines
Quoted 6 lines
=A0Anatolij> tested on pdm360ng board with some configuration switches.
This looks very similar to the existing
arch/powerpc/sysdev/mpc8xxx_gpio.c- Couldn't we just add 5121 support there instead?Quoted 9 lines
=A0Anatolij> +struct
mpc512x_gpio_regs{
=A0Anatolij> + =A0 =A0u32 gpdir;
=A0Anatolij> + =A0 =A0u32 gpodr;
=A0Anatolij> + =A0 =A0u32 gpdat;
=A0Anatolij> + =A0 =A0u32 gpier;
=A0Anatolij> + =A0 =A0u32 gpimr;
=A0Anatolij> + =A0 =A0u32 gpicr1;
=A0Anatolij> + =A0 =A0u32 gpicr2;
=A0Anatolij> +};
Quoted 6 lines
=20
Hi Anatolij,
=20
Peter's right, the register map looks the same, except for the additional gpicr1 & 2 registers in the 512x version. Can the 512x gpios be supported by the 8xxx gpio driver?
Hi Grant,
I wanted to extend/test this driver but didn't have time so far. I'll look at 8xxx gpio driver this weekend to see if it can be used for 512x gpios.
Anatolij
Anatolij Gustschin
maintainerPATCH 1/1 powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Peter Korsgaard--- arch/powerpc/platforms/Kconfig | 7 ++-- arch/powerpc/sysdev/mpc8xxx_gpio.c | 54 +++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-)
arch/powerpc/platforms/Kconfig +4 -3
@@ -304,13 +304,14 @@ config OF_RTC source "arch/powerpc/sysdev/bestcomm/Kconfig" config MPC8xxx_GPIO - bool "MPC8xxx GPIO support" - depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || FSL_SOC_BOOKE || PPC_86xx + bool "MPC512x/MPC8xxx GPIO support" + depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ + FSL_SOC_BOOKE || PPC_86xx select GENERIC_GPIO select ARCH_REQUIRE_GPIOLIB help Say Y here if you're going to use hardware that connects to the - MPC831x/834x/837x/8572/8610 GPIOs. + MPC512x/831x/834x/837x/8572/8610 GPIOs. config SIMPLE_GPIO bool "Support for simple, memory-mapped GPIO controllers"
arch/powerpc/sysdev/mpc8xxx_gpio.c +53 -1
82 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
Hi Anatolij,
Looks pretty good, but some comments below...
Quoted 1 line · Anatolij Gustschin
Signed-off-by Anatolij Gustschin <[email protected]>
You haven't written a patch description. Give some details about how the 512x gpio controller is different from the 8xxx one.
Quoted 3 lines
---
=A0arch/powerpc/platforms/Kconfig =A0 =A0 | =A0 =A07 ++-- =A0arch/powerpc/sysdev/mpc8xxx_gpio.c | =A0 54 ++++++++++++++++++++++++++=
+++++++++-
arch/powerpc/platforms/Kcon=
Quoted 3 lines
=A02 files changed, 57 insertions(+), 4 deletions(-)
arch/powerpc/platforms/Kcon= renamed from arch/powerpc/platforms/Kconfig +0
-0
fig
Quoted 9 lines
index d1663db..471115a 100644
arch/powerpc/platforms/Kconfig +0
-0@@ -304,13 +304,14 @@ config OF_RTC=A0source "
arch/powerpc/sysdev/bestcomm/Kconfig"=A0config
MPC8xxx_GPIO
- =A0 =A0 =A0 bool "MPC8xxx GPIO support"
- =A0 =A0 =A0 depends onPPC_MPC831x||PPC_MPC834x||PPC_MPC837x|| FSL=
_SOC_BOOKE || PPC_86xx
Quoted 2 lines
+ =A0 =A0 =A0 bool "MPC512x/MPC8xxx GPIO support"
+ =A0 =A0 =A0 depends onPPC_MPC512x||PPC_MPC831x||PPC_MPC834x|| PPC=
_MPC837x || \
Quoted 5 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FSL_SOC_BOOKE ||
PPC_86xx=A0 =A0 =A0 =A0selectGENERIC_GPIO
=A0 =A0 =A0 =A0selectARCH_REQUIRE_GPIOLIB
=A0 =A0 =A0 =A0help
=A0 =A0 =A0 =A0 =A0Say Y here if you're going to use hardware that connec=
ts to the
arch/powerpc/sysdev/mpc=
Quoted 6 lines
- =A0 =A0 =A0 =A0 MPC831x/834x/837x/8572/8610 GPIOs.
+ =A0 =A0 =A0 =A0 MPC512x/831x/834x/837x/8572/8610 GPIOs.=A0config
SIMPLE_GPIO
=A0 =A0 =A0 =A0bool "Support for simple, memory-mapped GPIO controllers"arch/powerpc/sysdev/mpc= renamed from arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0
8xxx_gpio.c
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u=
Quoted 19 lines
index 2b69084..f5b4959 100644
arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -1,5 +1,5 @@=A0/*
- * GPIOs on MPC8349/8572/8610 and compatible
+ * GPIOs on MPC512x/8349/8572/8610 and compatible =A0*
=A0* Copyright (C) 2008 Peter Korsgaard <[email protected]> =A0*arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -26,6 +26,7 @@=A0#define
GPIO_IER=A0 =A0 =A0 =A0 =A0 =A0 =A00x0c=A0#defineGPIO_IMR=A0 =A0 =A0 =A0 =A0 =A0 =A00x10=A0#defineGPIO_ICR=A0 =A0 =A0 =A0 =A0 =A0 =A00x14+#defineGPIO_ICR2=A0 =A0 =A0 =A0 =A0 =A0 =A00x18=A0struct
mpc8xxx_gpio_chip{
=A0 =A0 =A0 =A0structof_mm_gpio_chipmm_gc;arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -215,6 +216,51 @@ static int mpc8xxx_irq_set_type(unsigned int virq, u=
nsigned int flow_type)
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 219
Quoted 4 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0=A0 =A0 =A0 =A0return 0; =A0} +static int mpc512x_irq_set_type(unsigned int virq, unsigned int flow_typ=
e)
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 221
Quoted 2 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +2
-0+{ + =A0 =A0 =A0 struct mpc8xxx_gpio_chip *mpc8xxx_gc =3D get_irq_chip_data(=
virq);
Quoted 8 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +8
-0+ =A0 =A0 =A0 struct of_mm_gpio_chip *mm =3D &mpc8xxx_gc->mm_gc; + =A0 =A0 =A0 unsigned long gpio =3D virq_to_hw(virq); + =A0 =A0 =A0 void __iomem *reg; + =A0 =A0 =A0 unsigned int shift; + =A0 =A0 =A0 unsigned long flags; + + =A0 =A0 =A0 if (gpio < 16) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 reg =3D mm->regs + GPIO_ICR;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 239
Quoted 10 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +10
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 shift =3D (15 - gpio) * 2; + =A0 =A0 =A0 } else { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 reg =3D mm->regs + GPIO_ICR2; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 shift =3D (15 - (gpio % 16)) * 2; + =A0 =A0 =A0 } + + =A0 =A0 =A0 switch (flow_type) { + =A0 =A0 =A0 case IRQ_TYPE_EDGE_FALLING: + =A0 =A0 =A0 case IRQ_TYPE_LEVEL_LOW: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_irqsave(&mpc8xxx_gc->lock, flags)=
;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 240
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 clrsetbits_be32(reg, 3 << shift, 2 << shift=
);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 241
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock_irqrestore(&mpc8xxx_gc->lock, f=
lags);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 246
Quoted 5 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 case IRQ_TYPE_EDGE_RISING: + =A0 =A0 =A0 case IRQ_TYPE_LEVEL_HIGH: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_irqsave(&mpc8xxx_gc->lock, flags)=
;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 247
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 clrsetbits_be32(reg, 3 << shift, 1 << shift=
);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 248
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock_irqrestore(&mpc8xxx_gc->lock, f=
lags);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 252
Quoted 4 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +4
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 case IRQ_TYPE_EDGE_BOTH: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_irqsave(&mpc8xxx_gc->lock, flags)=
;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 254
Quoted 2 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +2
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 clrbits32(reg, 3 << shift); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock_irqrestore(&mpc8xxx_gc->lock, f=
lags);
Quoted 14 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +9
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 default: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL; + =A0 =A0 =A0 } + + =A0 =A0 =A0 return 0; +} + =A0static struct irq_chip mpc8xxx_irq_chip =3D { =A0 =A0 =A0 =A0.name =A0 =A0 =A0 =A0 =A0 =3D "mpc8xxx-gpio", =A0 =A0 =A0 =A0.unmask =A0 =A0 =A0 =A0 =3D mpc8xxx_irq_unmask,@@ -226,6 +272,9 @@ static struct irq_chip mpc8xxx_irq_chip =3D { =A0static int mpc8xxx_gpio_irq_map(struct irq_host *h, unsigned int virq,
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0irq_hw_num=
ber_t hw)
Quoted 2 lines
=A0{
+ =A0 =A0 =A0 if (of_device_is_compatible(h->of_node, "fsl,mpc5121-gpio")=
)
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_irq_chip.set_type =3D mpc512x_irq_s=
et_type;
Quoted 1 line
+
You can put the set type hook into the of_match_table data which you will need for of_find_matching_node() (see below).
Quoted 2 lines
=A0 =A0 =A0 =A0set_irq_chip_data(virq,
h->host_data);
=A0 =A0 =A0 =A0set_irq_chip_and_handler(virq,&mpc8xxx_irq_chip, handle_l=
evel_irq);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int __init mpc8xxx_add_gpiochips(void) · line 384
Quoted 8 lines
=A0 =A0 =A0 =A0set_irq_type(virq,
IRQ_TYPE_NONE);arch/powerpc/sysdev/mpc8xxx_gpio.c +3
-0@@ -330,6 +379,9 @@ static int __init mpc8xxx_add_gpiochips(void) =A0 =A0 =A0 =A0for_each_compatible_node (np,NULL ,"fsl,mpc8610-gpio" ) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mpc8xxx_add_controller (np); + =A0 =A0 =A0 for_each_compatible_node(np, NULL, "fsl,mpc5121-gpio") + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_add_controller(np); +
This list is getting too long. Refactor this function to use for_each_matching_node(). Also doing it this way is dangerous because if say a 5121 gpio node claims compatibility with a 8610 gpio node, then the gpio controller will get registered twice.
Quoted 7 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-1=A0 =A0 =A0 =A0return 0; =A0} =A0arch_initcall (mpc8xxx_add_gpiochips); --1.7.0.4
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Anatolij Gustschin
maintainerRe: [PATCH] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
Hi Grant,
Quoted 9 lines · On Sat, 7 Aug 2010 09:12:50 -0600 Grant Likely <[email protected]>…
Hi Anatolij,
=20
Looks pretty good, but some comments below...
=20Quoted 1 line · Anatolij Gustschin
Signed-off-by Anatolij Gustschin <[email protected]>=20
You haven't written a patch description. Give some details about how the 512x gpio controller is different from the 8xxx one.
Ok, will fix.
...
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0
-0@@ -226,6 +272,9 @@ static struct irq_chip mpc8xxx_irq_chip =3D {=A0static int mpc8xxx_gpio_irq_map(struct
irq_host*h, unsigned int vir=
q,
Quoted 1 line
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0irq_hw_n=
umber_t hw)
Quoted 2 lines
Quoted 2 lines
=A0{
+ =A0 =A0 =A0 if (of_device_is_compatible(h->of_node, "fsl,mpc5121-gpio=
"))
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_irq_chip.set_type =3D mpc512x_irq=
_set_type;
Quoted 4 lines
Quoted 1 line
+
=20
You can put the set type hook into theof_match_tabledata which you will need forof_find_matching_node()(see below).
How can I get this match table data reference in mpc8xxx_gpio_irq_map() ? Is it okay to set data field of struct device_node to the set type hook? I could do it in mpc8xxx_add_gpiochips() but I'm not sure whether the data field will be used for other purposes somewhere else.
...
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -330,6 +379,9 @@ static int __init mpc8xxx_add_gpiochips(void) =A0 =A0 =A0 =A0for_each_compatible_node(np, NULL, "fsl,mpc8610-gpio") =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mpc8xxx_add_controller(np);
Quoted 8 lines
Review static int __init mpc8xxx_add_gpiochips(void) · line 384
Quoted 3 lines
(quoted diff) +3
-0+ =A0 =A0 =A0 for_each_compatible_node(np, NULL, "fsl,mpc5121-gpio") + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_add_controller(np); +=20
This list is getting too long. Refactor this function to usefor_each_matching_node(). Also doing it this way is dangerous because if say a 5121 gpio node claims compatibility with a 8610 gpio node, then the gpio controller will get registered twice.
Fixed.
Thanks,
Anatolij
Re: [PATCH] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
Quoted 3 lines · Anatolij Gustschin
Quoted 2 lines · Grant Likely
Quoted 2 lines
(quoted diff) +0
-0@@ -226,6 +272,9 @@ static struct irq_chip mpc8xxx_irq_chip =3D {=A0static int mpc8xxx_gpio_irq_map(struct
irq_host*h, unsigned int vi=
rq,
Quoted 1 line
Quoted 1 line
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0irq_hw_=
number_t hw)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
=A0{
+ =A0 =A0 =A0 if (of_device_is_compatible(h->of_node, "fsl,mpc5121-gpi=
o"))
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_irq_chip.set_type =3D mpc512x_ir=
q_set_type;
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+
You can put the set type hook into the
of_match_tabledata which you will need forof_find_matching_node()(see below).How can I get this match table data reference in
mpc8xxx_gpio_irq_map()?
of_match_node() will return the matching entry in the table.
Quoted 3 lines
Is it okay to set data field of struct
device_nodeto the set type hook? I could do it inmpc8xxx_add_gpiochips()but I'm not sure whether the data field will be used for other purposes somewhere else.
You are safe to use the .data field.
g.
Anatolij Gustschin
maintainerPATCH v2 1/1 powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Anatolij GustschinThe GPIO controller of MPC512x is slightly different from 8xxx GPIO controllers. The register interface is the same except the external interrupt control register. The MPC512x GPIO controller differentiates between four interrupt event types and therefore provides two interrupt control registers, GPICR1 and GPICR2. GPIO[0:15] interrupt event types are configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
This patch adds MPC512x speciffic set_type() callback and updates config file and comments. Additionally the gpio chip registration function is changed to use for_each_matching_node() preventing multiple registration if a node claimes compatibility with another gpio controller type.
---
v2:
- add patch description
- use match table data to set irq set_type hook as recommended
- refactor to use for_each_matching_node() in mpc8xxx_add_gpiochips() as suggested by Grant
arch/powerpc/platforms/Kconfig | 7 ++- arch/powerpc/sysdev/mpc8xxx_gpio.c | 72 ++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 11 deletions(-)
arch/powerpc/platforms/Kconfig +4 -3
@@ -304,13 +304,14 @@ config OF_RTC source "arch/powerpc/sysdev/bestcomm/Kconfig" config MPC8xxx_GPIO - bool "MPC8xxx GPIO support" - depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || FSL_SOC_BOOKE || PPC_86xx + bool "MPC512x/MPC8xxx GPIO support" + depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ + FSL_SOC_BOOKE || PPC_86xx select GENERIC_GPIO select ARCH_REQUIRE_GPIOLIB help Say Y here if you're going to use hardware that connects to the - MPC831x/834x/837x/8572/8610 GPIOs. + MPC512x/831x/834x/837x/8572/8610 GPIOs. config SIMPLE_GPIO bool "Support for simple, memory-mapped GPIO controllers"
arch/powerpc/sysdev/mpc8xxx_gpio.c +64 -8
105 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH v2] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
Quoted 150 lines · Anatolij Gustschin
The GPIO controller of MPC512x is slightly different from 8xxx GPIO controllers. The register interface is the same except the external interrupt control register. The MPC512x GPIO controller differentiates between four interrupt event types and therefore provides two interrupt control registers, GPICR1 and GPICR2. GPIO[0:15] interrupt event types are configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
This patch adds MPC512x speciffic
set_type()callback and updates config file and comments. Additionally the gpio chip registration function is changed to usefor_each_matching_node()preventing multiple registration if a node claimes compatibility with another gpio controller type.Signed-off-by Anatolij Gustschin <[email protected]>---
v2:
- add patch description
- use match table data to set irqset_typehook as recommended
- refactor to usefor_each_matching_node()inmpc8xxx_add_gpiochips()as suggested by Grant
arch/powerpc/platforms/Kconfig| 7 ++-arch/powerpc/sysdev/mpc8xxx_gpio.c| 72 ++++++++++++++++++++++++++++++++----2 files changed, 68 insertions(+), 11 deletions(-)arch/powerpc/platforms/Kconfig +0
-0@@ -304,13 +304,14 @@ config OF_RTCsource "
arch/powerpc/sysdev/bestcomm/Kconfig"config
MPC8xxx_GPIOarch/powerpc/platforms/Kconfig +3
-2- bool "MPC8xxx GPIO support" - depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || FSL_SOC_BOOKE || PPC_86xx + bool "MPC512x/MPC8xxx GPIO support" + depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ + FSL_SOC_BOOKE || PPC_86xxselect
GENERIC_GPIO
selectARCH_REQUIRE_GPIOLIB
help
Say Y here if you're going to use hardware that connects to thearch/powerpc/platforms/Kconfig +1
-1- MPC831x/834x/837x/8572/8610 GPIOs. + MPC512x/831x/834x/837x/8572/8610 GPIOs.config
SIMPLE_GPIO
bool "Support for simple, memory-mapped GPIO controllers"arch/powerpc/sysdev/mpc8xxx_gpio.c +59
-4@@ -1,5 +1,5 @@/* -* GPIOs on MPC8349/8572/8610 and compatible +* GPIOs on MPC512x/8349/8572/8610 and compatible * * Copyright (C) 2008 Peter Korsgaard <[email protected]> * @@ -26,6 +26,7 @@#define GPIO_IER 0x0c#define GPIO_IMR 0x10#define GPIO_ICR 0x14 +#define GPIO_ICR2 0x18struct mpc8xxx_gpio_chip {struct of_mm_gpio_chip mm_gc;@@ -215,6 +216,51 @@ static int mpc8xxx_irq_set_type(unsigned int virq, unsigned int flow_type)return 0 ; } +static int mpc512x_irq_set_type (unsigned int virq,unsigned int flow_type) +{ +struct mpc8xxx_gpio_chip *mpc8xxx_gc =get_irq_chip_data (virq); +struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; +unsigned long gpio =virq_to_hw (virq); +void __iomem *reg; +unsigned int shift; +unsigned long flags; + +if (gpio <16 ) { + reg = mm->regs +GPIO_ICR ; + shift = (15 - gpio) *2 ; + }else { + reg = mm->regs +GPIO_ICR2 ; + shift = (15 - (gpio %16 )) *2 ; + } + +switch (flow_type) { +case IRQ_TYPE_EDGE_FALLING : +case IRQ_TYPE_LEVEL_LOW : +spin_lock_irqsave (&mpc8xxx_gc->lock, flags); +clrsetbits_be32 (reg,3 << shift,2 << shift); +spin_unlock_irqrestore (&mpc8xxx_gc->lock, flags); +break ; + +case IRQ_TYPE_EDGE_RISING : +case IRQ_TYPE_LEVEL_HIGH : +spin_lock_irqsave (&mpc8xxx_gc->lock, flags); +clrsetbits_be32 (reg,3 << shift,1 << shift); +spin_unlock_irqrestore (&mpc8xxx_gc->lock, flags); +break ; + +case IRQ_TYPE_EDGE_BOTH : +spin_lock_irqsave (&mpc8xxx_gc->lock, flags); +clrbits32 (reg,3 << shift); +spin_unlock_irqrestore (&mpc8xxx_gc->lock, flags); +break ; + +default : +return -EINVAL ; + } + +return 0 ; +} +static struct irq_chip mpc8xxx_irq_chip = { .name ="mpc8xxx-gpio" , .unmask = mpc8xxx_irq_unmask,@@ -226,6 +272,9 @@ static struct irq_chip mpc8xxx_irq_chip = {static int mpc8xxx_gpio_irq_map (struct irq_host *h,unsigned int virq,irq_hw_number_t hw) { +if (h->of_node && h->of_node->data) + mpc8xxx_irq_chip.set_type = h->of_node->data; +set_irq_chip_data (virq, h->host_data);set_irq_chip_and_handler (virq, &mpc8xxx_irq_chip, handle_level_irq);set_irq_type (virq,IRQ_TYPE_NONE );@@ -317,18 +366,25 @@ err:return ; } +static struct of_device_id mpc8xxx_gpio_ids[]__initdata = { + { .compatible ="fsl,mpc8349-gpio" , }, + { .compatible ="fsl,mpc8572-gpio" , }, + { .compatible ="fsl,mpc8610-gpio" , }, + { .compatible ="fsl,mpc5121-gpio" , .data = mpc512x_irq_set_type, }, + {} +}; +static int __init mpc8xxx_add_gpiochips (void ) { +const struct of_device_id *id;struct device_node *np; -for_each_compatible_node (np,NULL ,"fsl,mpc8349-gpio" ) -mpc8xxx_add_controller (np); -
arch/powerpc/sysdev/mpc8xxx_gpio.c err: · line 387
Quoted 10 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +5
-4-for_each_compatible_node (np,NULL ,"fsl,mpc8572-gpio" ) -mpc8xxx_add_controller (np); - -for_each_compatible_node (np,NULL ,"fsl,mpc8610-gpio" ) +for_each_matching_node (np, mpc8xxx_gpio_ids) { + id =of_match_node (mpc8xxx_gpio_ids, np); +if (id) + np->data = id->data;mpc8xxx_add_controller (np); + }
Sorry, I miss led you. id->data is fine, but don't use np->data. Call of_match_node() inside mpc8xxx_add_controller() instead, or change the function signature to pass it in explicitly...
Actually, there is absolutely no reason to keep mpc8xxx_add_gpiochip() as a separate function with the simplification of mpc8xxx_add_gpiochips(). I'd simplify the whole thing by merging the two functions together.
g.
Re: [PATCH v2] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
On Sat, Aug 07, 2010 at 06:40:22PM -0600, Grant Likely wrote:
[...]
Quoted 18 lines
Quoted 18 lines
static int
__initmpc8xxx_add_gpiochips(void)
{arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+const struct of_device_id *id;struct device_node *np;arch/powerpc/sysdev/mpc8xxx_gpio.c +4
-7-for_each_compatible_node (np,NULL ,"fsl,mpc8349-gpio" ) -mpc8xxx_add_controller (np); - -for_each_compatible_node (np,NULL ,"fsl,mpc8572-gpio" ) -mpc8xxx_add_controller (np); - -for_each_compatible_node (np,NULL ,"fsl,mpc8610-gpio" ) +for_each_matching_node (np, mpc8xxx_gpio_ids) { + id =of_match_node (mpc8xxx_gpio_ids, np); +if (id) + np->data = id->data;mpc8xxx_add_controller(np);(quoted diff) +1
-0+ }
[...]
Quoted 4 lines
Actually, there is absolutely no reason to keep
mpc8xxx_add_gpiochip()as a separate function with the simplification ofmpc8xxx_add_gpiochips(). I'd simplify the whole thing by merging the two functions together.
You mean mpc8xxx_add_controller()? Putting 65-line function on a second indentation level, inside the for loop... sounds like a bad idea.
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Anatolij Gustschin
maintainerPATCH v3 1/1 powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Anatolij GustschinThe GPIO controller of MPC512x is slightly different from 8xxx GPIO controllers. The register interface is the same except the external interrupt control register. The MPC512x GPIO controller differentiates between four interrupt event types and therefore provides two interrupt control registers, GPICR1 and GPICR2. GPIO[0:15] interrupt event types are configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
This patch adds MPC512x speciffic set_type() callback and updates config file and comments. Additionally the gpio chip registration function is changed to use for_each_matching_node() preventing multiple registration if a node claimes compatibility with another gpio controller type. Also merge two chip registration functions into one.
---
v3:
- merge mpc8xxx_add_controller() into mpc8xxx_add_gpiochips()
- do not use of_node's data field for set type hook, use added void data pointer in the gpio chip struct instead.
v2:
- add patch description
- use match table data to set irq set_type hook as recommended
- refactor to use for_each_matching_node() in mpc8xxx_add_gpiochips() as suggested by Grant
arch/powerpc/platforms/Kconfig | 7 +- arch/powerpc/sysdev/mpc8xxx_gpio.c | 196 +++++++++++++++++++++++------------- 2 files changed, 129 insertions(+), 74 deletions(-)
arch/powerpc/platforms/Kconfig +4 -3
@@ -304,13 +304,14 @@ config OF_RTC source "arch/powerpc/sysdev/bestcomm/Kconfig" config MPC8xxx_GPIO - bool "MPC8xxx GPIO support" - depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || FSL_SOC_BOOKE || PPC_86xx + bool "MPC512x/MPC8xxx GPIO support" + depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ + FSL_SOC_BOOKE || PPC_86xx select GENERIC_GPIO select ARCH_REQUIRE_GPIOLIB help Say Y here if you're going to use hardware that connects to the - MPC831x/834x/837x/8572/8610 GPIOs. + MPC512x/831x/834x/837x/8572/8610 GPIOs. config SIMPLE_GPIO bool "Support for simple, memory-mapped GPIO controllers"
arch/powerpc/sysdev/mpc8xxx_gpio.c +125 -71
237 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH v2] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Anton VorontsovOn Sun, Aug 8, 2010 at 1:40 AM, Anton Vorontsov <[email protected]> wr= ote:
Quoted 21 lines · Grant Likely
[...]
Quoted 18 lines
Quoted 18 lines
static int
__initmpc8xxx_add_gpiochips(void)
{
+ =A0 =A0const structof_device_id*id;
=A0 =A0 structdevice_node*np;- =A0 =A0for_each_compatible_node(np, NULL, "fsl,mpc8349-gpio")
- =A0 =A0 =A0 =A0 =A0 =A0mpc8xxx_add_controller(np);(quoted diff) +4
-5- - =A0 =A0for_each_compatible_node(np, NULL, "fsl,mpc8572-gpio") - =A0 =A0 =A0 =A0 =A0 =A0mpc8xxx_add_controller(np); - - =A0 =A0for_each_compatible_node(np, NULL, "fsl,mpc8610-gpio") + =A0 =A0for_each_matching_node(np, mpc8xxx_gpio_ids) { + =A0 =A0 =A0 =A0 =A0 =A0id =3D of_match_node(mpc8xxx_gpio_ids, np); + =A0 =A0 =A0 =A0 =A0 =A0if (id) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0np->data =3D id->data;=A0 =A0 =A0 =A0 =A0 =A0
mpc8xxx_add_controller(np);
+ =A0 =A0}[...]
Quoted 8 lines
Quoted 4 lines
Actually, there is absolutely no reason to keep
mpc8xxx_add_gpiochip()as a separate function with the simplification ofmpc8xxx_add_gpiochips(). =A0I'd simplify the whole thing by merging the two functions together.You mean
mpc8xxx_add_controller()? Putting 65-line function on a second indentation level, inside the for loop... sounds like a bad idea.
That's a good point. I was thinking about it from the wrong way around (that the function could bail at the top on a non-match; which obviously isn't the case). Anatolij, I was wrong on this point. Sorry I didn't reply sooner before you respun the patch. :-(
g.
Anatolij Gustschin
maintainerPATCH v4 1/1 powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Anatolij GustschinThe GPIO controller of MPC512x is slightly different from 8xxx GPIO controllers. The register interface is the same except the external interrupt control register. The MPC512x GPIO controller differentiates between four interrupt event types and therefore provides two interrupt control registers, GPICR1 and GPICR2. GPIO[0:15] interrupt event types are configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
This patch adds MPC512x speciffic set_type() callback and updates config file and comments. Additionally the gpio chip registration function is changed to use for_each_matching_node() preventing multiple registration if a node claimes compatibility with another gpio controller type.
---
v4:
- undo function merging as it was wrong
- fix commit message
v3:
- merge mpc8xxx_add_controller() into mpc8xxx_add_gpiochips()
- do not use of_node's data field for set type hook, use added void data pointer in the gpio chip struct instead.
v2:
- add patch description
- use match table data to set irq set_type hook as recommended
- refactor to use for_each_matching_node() in mpc8xxx_add_gpiochips() as suggested by Grant
arch/powerpc/platforms/Kconfig | 7 ++- arch/powerpc/sysdev/mpc8xxx_gpio.c | 75 ++++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 11 deletions(-)
arch/powerpc/platforms/Kconfig +4 -3
@@ -304,13 +304,14 @@ config OF_RTC source "arch/powerpc/sysdev/bestcomm/Kconfig" config MPC8xxx_GPIO - bool "MPC8xxx GPIO support" - depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || FSL_SOC_BOOKE || PPC_86xx + bool "MPC512x/MPC8xxx GPIO support" + depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ + FSL_SOC_BOOKE || PPC_86xx select GENERIC_GPIO select ARCH_REQUIRE_GPIOLIB help Say Y here if you're going to use hardware that connects to the - MPC831x/834x/837x/8572/8610 GPIOs. + MPC512x/831x/834x/837x/8572/8610 GPIOs. config SIMPLE_GPIO bool "Support for simple, memory-mapped GPIO controllers"
arch/powerpc/sysdev/mpc8xxx_gpio.c +67 -8
126 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH v4] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
Quoted 14 lines · Anatolij Gustschin
The GPIO controller of MPC512x is slightly different from 8xxx GPIO controllers. The register interface is the same except the external interrupt control register. The MPC512x GPIO controller differentiates between four interrupt event types and therefore provides two interrupt control registers, GPICR1 and GPICR2. GPIO[0:15] interrupt event types are configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
This patch adds MPC512x speciffic
set_type()callback and updates config file and comments. Additionally the gpio chip registration function is changed to usefor_each_matching_node()preventing multiple registration if a node claimes compatibility with another gpio controller type.
Quoted 5 lines
Signed-off-by Anatolij Gustschin <[email protected]>---
v4:
=A0- undo function merging as it was wrong
=A0- fix commit message
Looks good, thanks. I'll pick it up after the merge window closes in prep for 2.6.27
g.
Quoted 14 lines
v3:
=A0- mergempc8xxx_add_controller()intompc8xxx_add_gpiochips()=A0- do not use of_node's data field for set type hook, =A0 =A0use added void data pointer in the gpio chip struct =A0 =A0instead.v2:
=A0- add patch description
=A0- use match table data to set irqset_typehook as =A0 recommended
=A0- refactor to usefor_each_matching_node()in =A0mpc8xxx_add_gpiochips()as suggested by Grant
Quoted 2 lines
=A0arch/powerpc/platforms/Kconfig =A0 =A0 | =A0 =A07 ++- =A0arch/powerpc/sysdev/mpc8xxx_gpio.c | =A0 75 ++++++++++++++++++++++++++=
++++++----
arch/powerpc/platforms/Kcon=
Quoted 3 lines
=A02 files changed, 71 insertions(+), 11 deletions(-)
arch/powerpc/platforms/Kcon= renamed from arch/powerpc/platforms/Kconfig +0
-0
fig
Quoted 9 lines
index d1663db..471115a 100644
arch/powerpc/platforms/Kconfig +0
-0@@ -304,13 +304,14 @@ config OF_RTC=A0source "
arch/powerpc/sysdev/bestcomm/Kconfig"=A0config
MPC8xxx_GPIO
- =A0 =A0 =A0 bool "MPC8xxx GPIO support"
- =A0 =A0 =A0 depends onPPC_MPC831x||PPC_MPC834x||PPC_MPC837x|| FSL=
_SOC_BOOKE || PPC_86xx
Quoted 2 lines
+ =A0 =A0 =A0 bool "MPC512x/MPC8xxx GPIO support"
+ =A0 =A0 =A0 depends onPPC_MPC512x||PPC_MPC831x||PPC_MPC834x|| PPC=
_MPC837x || \
Quoted 5 lines
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0FSL_SOC_BOOKE ||
PPC_86xx=A0 =A0 =A0 =A0selectGENERIC_GPIO
=A0 =A0 =A0 =A0selectARCH_REQUIRE_GPIOLIB
=A0 =A0 =A0 =A0help
=A0 =A0 =A0 =A0 =A0Say Y here if you're going to use hardware that connec=
ts to the
arch/powerpc/sysdev/mpc=
Quoted 6 lines
- =A0 =A0 =A0 =A0 MPC831x/834x/837x/8572/8610 GPIOs.
+ =A0 =A0 =A0 =A0 MPC512x/831x/834x/837x/8572/8610 GPIOs.=A0config
SIMPLE_GPIO
=A0 =A0 =A0 =A0bool "Support for simple, memory-mapped GPIO controllers"arch/powerpc/sysdev/mpc= renamed from arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0
8xxx_gpio.c
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u=
Quoted 27 lines
index 2b69084..3649939 100644
arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -1,5 +1,5 @@=A0/*
- * GPIOs on MPC8349/8572/8610 and compatible
+ * GPIOs on MPC512x/8349/8572/8610 and compatible =A0*
=A0* Copyright (C) 2008 Peter Korsgaard <[email protected]> =A0*arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -26,6 +26,7 @@=A0#define
GPIO_IER=A0 =A0 =A0 =A0 =A0 =A0 =A00x0c=A0#defineGPIO_IMR=A0 =A0 =A0 =A0 =A0 =A0 =A00x10=A0#defineGPIO_ICR=A0 =A0 =A0 =A0 =A0 =A0 =A00x14+#defineGPIO_ICR2=A0 =A0 =A0 =A0 =A0 =A0 =A00x18=A0struct
mpc8xxx_gpio_chip{
=A0 =A0 =A0 =A0structof_mm_gpio_chipmm_gc;arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -37,6 +38,7 @@ struct mpc8xxx_gpio_chip {=A0 =A0 =A0 =A0 */
=A0 =A0 =A0 =A0u32 data;
=A0 =A0 =A0 =A0structirq_host*irq;
+ =A0 =A0 =A0 void*of_dev_id_data;
=A0};=A0static inline u32
mpc8xxx_gpio2mask(unsigned int gpio)arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -215,6 +217,51 @@ static int mpc8xxx_irq_set_type(unsigned int virq, u=
nsigned int flow_type)
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 220
Quoted 4 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0=A0 =A0 =A0 =A0return 0; =A0} +static int mpc512x_irq_set_type(unsigned int virq, unsigned int flow_typ=
e)
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 222
Quoted 2 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +2
-0+{ + =A0 =A0 =A0 struct mpc8xxx_gpio_chip *mpc8xxx_gc =3D get_irq_chip_data(=
virq);
Quoted 8 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +8
-0+ =A0 =A0 =A0 struct of_mm_gpio_chip *mm =3D &mpc8xxx_gc->mm_gc; + =A0 =A0 =A0 unsigned long gpio =3D virq_to_hw(virq); + =A0 =A0 =A0 void __iomem *reg; + =A0 =A0 =A0 unsigned int shift; + =A0 =A0 =A0 unsigned long flags; + + =A0 =A0 =A0 if (gpio < 16) { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 reg =3D mm->regs + GPIO_ICR;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 240
Quoted 10 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +10
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 shift =3D (15 - gpio) * 2; + =A0 =A0 =A0 } else { + =A0 =A0 =A0 =A0 =A0 =A0 =A0 reg =3D mm->regs + GPIO_ICR2; + =A0 =A0 =A0 =A0 =A0 =A0 =A0 shift =3D (15 - (gpio % 16)) * 2; + =A0 =A0 =A0 } + + =A0 =A0 =A0 switch (flow_type) { + =A0 =A0 =A0 case IRQ_TYPE_EDGE_FALLING: + =A0 =A0 =A0 case IRQ_TYPE_LEVEL_LOW: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_irqsave(&mpc8xxx_gc->lock, flags)=
;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 241
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 clrsetbits_be32(reg, 3 << shift, 2 << shift=
);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 242
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock_irqrestore(&mpc8xxx_gc->lock, f=
lags);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 247
Quoted 5 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +5
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 case IRQ_TYPE_EDGE_RISING: + =A0 =A0 =A0 case IRQ_TYPE_LEVEL_HIGH: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_irqsave(&mpc8xxx_gc->lock, flags)=
;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 248
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 clrsetbits_be32(reg, 3 << shift, 1 << shift=
);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 249
Quoted 1 line
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock_irqrestore(&mpc8xxx_gc->lock, f=
lags);
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 253
Quoted 4 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +4
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 case IRQ_TYPE_EDGE_BOTH: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_lock_irqsave(&mpc8xxx_gc->lock, flags)=
;
arch/powerpc/sysdev/mpc8xxx_gpio.c static int mpc8xxx_irq_set_type(unsigned int virq, u= · line 255
Quoted 2 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +2
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 clrbits32(reg, 3 << shift); + =A0 =A0 =A0 =A0 =A0 =A0 =A0 spin_unlock_irqrestore(&mpc8xxx_gc->lock, f=
lags);
Quoted 14 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +9
-0+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; + + =A0 =A0 =A0 default: + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -EINVAL; + =A0 =A0 =A0 } + + =A0 =A0 =A0 return 0; +} + =A0static struct irq_chip mpc8xxx_irq_chip =3D { =A0 =A0 =A0 =A0.name =A0 =A0 =A0 =A0 =A0 =3D "mpc8xxx-gpio", =A0 =A0 =A0 =A0.unmask =A0 =A0 =A0 =A0 =3D mpc8xxx_irq_unmask,@@ -226,6 +273,11 @@ static struct irq_chip mpc8xxx_irq_chip =3D { =A0static int mpc8xxx_gpio_irq_map(struct irq_host *h, unsigned int virq,
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0irq_hw_num=
ber_t hw)
Quoted 5 lines
=A0{
+ =A0 =A0 =A0 structmpc8xxx_gpio_chip*mpc8xxx_gc=3Dh->host_data; +
+ =A0 =A0 =A0 if (mpc8xxx_gc->of_dev_id_data)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_irq_chip.set_type =3D mpc8xxx_gc->o=
f_dev_id_data;
Quoted 3 lines
+
=A0 =A0 =A0 =A0set_irq_chip_data(virq,h->host_data);
=A0 =A0 =A0 =A0set_irq_chip_and_handler(virq,&mpc8xxx_irq_chip, handle_l=
evel_irq);
arch/powerpc/sysdev/mpc8xxx_gpio.c static struct irq_host_ops mpc8xxx_gpio_irq_ops =3D=
Quoted 2 lines
=A0 =A0 =A0 =A0set_irq_type(virq,
IRQ_TYPE_NONE);arch/powerpc/sysdev/mpc8xxx_gpio.c +0
-0@@ -253,11 +305,20 @@ static struct irq_host_ops mpc8xxx_gpio_irq_ops =3D=
{
arch/powerpc/sysdev/mpc8xxx_gpio.c static struct irq_host_ops mpc8xxx_gpio_irq_ops =3D= · line 312
Quoted 8 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +5
-0=A0 =A0 =A0 =A0.xlate =A0=3D mpc8xxx_gpio_irq_xlate, =A0}; +static struct of_device_id mpc8xxx_gpio_ids[] __initdata =3D { + =A0 =A0 =A0 { .compatible =3D "fsl,mpc8349-gpio", }, + =A0 =A0 =A0 { .compatible =3D "fsl,mpc8572-gpio", }, + =A0 =A0 =A0 { .compatible =3D "fsl,mpc8610-gpio", }, + =A0 =A0 =A0 { .compatible =3D "fsl,mpc5121-gpio", .data =3D mpc512x_irq=
_set_type, },
arch/powerpc/sysdev/mpc8xxx_gpio.c static void __init mpc8xxx_add_controller(struct dev=
Quoted 13 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +4
-0+ =A0 =A0 =A0 {} +}; + =A0static void __init mpc8xxx_add_controller(struct device_node *np) =A0{ =A0 =A0 =A0 =A0struct mpc8xxx_gpio_chip *mpc8xxx_gc; =A0 =A0 =A0 =A0struct of_mm_gpio_chip *mm_gc; =A0 =A0 =A0 =A0struct gpio_chip *gc; + =A0 =A0 =A0 const struct of_device_id *id; =A0 =A0 =A0 =A0unsigned hwirq; =A0 =A0 =A0 =A0int ret;@@ -297,6 +358,10 @@ static void __init mpc8xxx_add_controller(struct dev=
ice_node *np)
Quoted 26 lines
arch/powerpc/sysdev/mpc8xxx_gpio.c +4
-0=A0 =A0 =A0 =A0if (!mpc8xxx_gc->irq) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto skip_irq; + =A0 =A0 =A0 id =3D of_match_node(mpc8xxx_gpio_ids, np); + =A0 =A0 =A0 if (id) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_gc->of_dev_id_data =3D id->data; + =A0 =A0 =A0 =A0mpc8xxx_gc->irq->host_data =3D mpc8xxx_gc;=A0 =A0 =A0 =A0/* ack and mask all irqs */
arch/powerpc/sysdev/mpc8xxx_gpio.c +1
-8@@ -321,13 +386,7 @@ static int __init mpc8xxx_add_gpiochips(void) =A0{ =A0 =A0 =A0 =A0struct device_node *np; - =A0 =A0 =A0 for_each_compatible_node(np, NULL, "fsl,mpc8349-gpio") - =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_add_controller(np); - - =A0 =A0 =A0 for_each_compatible_node(np, NULL, "fsl,mpc8572-gpio") - =A0 =A0 =A0 =A0 =A0 =A0 =A0 mpc8xxx_add_controller(np); - - =A0 =A0 =A0 for_each_compatible_node(np, NULL, "fsl,mpc8610-gpio") + =A0 =A0 =A0 for_each_matching_node(np, mpc8xxx_gpio_ids) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0mpc8xxx_add_controller (np); =A0 =A0 =A0 =A0return 0; --
Quoted 3 lines
1.7.0.4
--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
Re: [PATCH v4] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Anatolij GustschinQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Anatolij" == Anatolij Gustschin <[email protected]> writes:
Anatolij> The GPIO controller of MPC512x is slightly different from Anatolij> 8xxx GPIO controllers. The register interface is the same Anatolij> except the external interrupt control register. The MPC512x Anatolij> GPIO controller differentiates between four interrupt event Anatolij> types and therefore provides two interrupt control registers, Anatolij> GPICR1 and GPICR2. GPIO[0:15] interrupt event types are Anatolij> configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
Anatolij> This patch adds MPC512x speciffic set_type() callback and Anatolij> updates config file and comments. Additionally the gpio chip Anatolij> registration function is changed to use for_each_matching_node() Anatolij> preventing multiple registration if a node claimes compatibility Anatolij> with another gpio controller type.
Anatolij> Signed-off-by: Anatolij Gustschin <[email protected]>
Sorry, was away on holiday.
Signature · 1 line
Bye, Peter Korsgaard
Grant Likely
AppliedRe: [PATCH v4] powerpc/mpc8xxx_gpio.c: extend the driver to support mpc512x gpios
In reply to Anatolij GustschinQuoted 33 lines · Anatolij Gustschin
The GPIO controller of MPC512x is slightly different from 8xxx GPIO controllers. The register interface is the same except the external interrupt control register. The MPC512x GPIO controller differentiates between four interrupt event types and therefore provides two interrupt control registers, GPICR1 and GPICR2. GPIO[0:15] interrupt event types are configured in GPICR1 register, GPIO[16:31] - in GPICR2 register.
This patch adds MPC512x speciffic
set_type()callback and updates config file and comments. Additionally the gpio chip registration function is changed to usefor_each_matching_node()preventing multiple registration if a node claimes compatibility with another gpio controller type.Signed-off-by Anatolij Gustschin <[email protected]>---
v4:
- undo function merging as it was wrong
- fix commit messagev3:
- mergempc8xxx_add_controller()intompc8xxx_add_gpiochips()
- do not use of_node's data field for set type hook, use added void data pointer in the gpio chip struct instead.v2:
- add patch description
- use match table data to set irqset_typehook as recommended
- refactor to usefor_each_matching_node()inmpc8xxx_add_gpiochips()as suggested by Grant
Quoted 3 lines
arch/powerpc/platforms/Kconfig | 7 ++- arch/powerpc/sysdev/mpc8xxx_gpio.c | 75 ++++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 11 deletions(-)
Applied to -next, thanks.
g.
Quoted 164 lines
arch/powerpc/platforms/Kconfig +4
-3@@ -304,13 +304,14 @@ config OF_RTC source "arch/powerpc/sysdev/bestcomm/Kconfig" config MPC8xxx_GPIO - bool "MPC8xxx GPIO support" - depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || FSL_SOC_BOOKE || PPC_86xx + bool "MPC512x/MPC8xxx GPIO support" + depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \ + FSL_SOC_BOOKE || PPC_86xx select GENERIC_GPIO select ARCH_REQUIRE_GPIOLIB help Say Y here if you're going to use hardware that connects to the - MPC831x/834x/837x/8572/8610 GPIOs. + MPC512x/831x/834x/837x/8572/8610 GPIOs. config SIMPLE_GPIO bool "Support for simple, memory-mapped GPIO controllers"arch/powerpc/sysdev/mpc8xxx_gpio.c +67
-8@@ -1,5 +1,5 @@/* -* GPIOs on MPC8349/8572/8610 and compatible +* GPIOs on MPC512x/8349/8572/8610 and compatible * * Copyright (C) 2008 Peter Korsgaard <[email protected]> * @@ -26,6 +26,7 @@#define GPIO_IER 0x0c#define GPIO_IMR 0x10#define GPIO_ICR 0x14 +#define GPIO_ICR2 0x18struct mpc8xxx_gpio_chip {struct of_mm_gpio_chip mm_gc;@@ -37,6 +38,7 @@ struct mpc8xxx_gpio_chip {*/ u32 data;struct irq_host *irq; +void *of_dev_id_data; };static inline u32 mpc8xxx_gpio2mask (unsigned int gpio)@@ -215,6 +217,51 @@ static int mpc8xxx_irq_set_type(unsigned int virq, unsigned int flow_type)return 0 ; } +static int mpc512x_irq_set_type (unsigned int virq,unsigned int flow_type) +{ +struct mpc8xxx_gpio_chip *mpc8xxx_gc =get_irq_chip_data (virq); +struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc; +unsigned long gpio =virq_to_hw (virq); +void __iomem *reg; +unsigned int shift; +unsigned long flags; + +if (gpio <16 ) { + reg = mm->regs +GPIO_ICR ; + shift = (15 - gpio) *2 ; + }else { + reg = mm->regs +GPIO_ICR2 ; + shift = (15 - (gpio %16 )) *2 ; + } + +switch (flow_type) { +case IRQ_TYPE_EDGE_FALLING : +case IRQ_TYPE_LEVEL_LOW : +spin_lock_irqsave (&mpc8xxx_gc->lock, flags); +clrsetbits_be32 (reg,3 << shift,2 << shift); +spin_unlock_irqrestore (&mpc8xxx_gc->lock, flags); +break ; + +case IRQ_TYPE_EDGE_RISING : +case IRQ_TYPE_LEVEL_HIGH : +spin_lock_irqsave (&mpc8xxx_gc->lock, flags); +clrsetbits_be32 (reg,3 << shift,1 << shift); +spin_unlock_irqrestore (&mpc8xxx_gc->lock, flags); +break ; + +case IRQ_TYPE_EDGE_BOTH : +spin_lock_irqsave (&mpc8xxx_gc->lock, flags); +clrbits32 (reg,3 << shift); +spin_unlock_irqrestore (&mpc8xxx_gc->lock, flags); +break ; + +default : +return -EINVAL ; + } + +return 0 ; +} +static struct irq_chip mpc8xxx_irq_chip = { .name ="mpc8xxx-gpio" , .unmask = mpc8xxx_irq_unmask,@@ -226,6 +273,11 @@ static struct irq_chip mpc8xxx_irq_chip = {static int mpc8xxx_gpio_irq_map (struct irq_host *h,unsigned int virq,irq_hw_number_t hw) { +struct mpc8xxx_gpio_chip *mpc8xxx_gc = h->host_data; + +if (mpc8xxx_gc->of_dev_id_data) + mpc8xxx_irq_chip.set_type = mpc8xxx_gc->of_dev_id_data; +set_irq_chip_data (virq, h->host_data);set_irq_chip_and_handler (virq, &mpc8xxx_irq_chip, handle_level_irq);set_irq_type (virq,IRQ_TYPE_NONE );@@ -253,11 +305,20 @@ static struct irq_host_ops mpc8xxx_gpio_irq_ops = { .xlate = mpc8xxx_gpio_irq_xlate, }; +static struct of_device_id mpc8xxx_gpio_ids[]__initdata = { + { .compatible ="fsl,mpc8349-gpio" , }, + { .compatible ="fsl,mpc8572-gpio" , }, + { .compatible ="fsl,mpc8610-gpio" , }, + { .compatible ="fsl,mpc5121-gpio" , .data = mpc512x_irq_set_type, }, + {} +}; +static void __init mpc8xxx_add_controller (struct device_node *np) {struct mpc8xxx_gpio_chip *mpc8xxx_gc;struct of_mm_gpio_chip *mm_gc;struct gpio_chip *gc; +const struct of_device_id *id;unsigned hwirq;int ret;@@ -297,6 +358,10 @@ static void __init mpc8xxx_add_controller(struct device_node *np)if (!mpc8xxx_gc->irq) goto skip_irq; + id =of_match_node (mpc8xxx_gpio_ids, np); +if (id) + mpc8xxx_gc->of_dev_id_data = id->data; + mpc8xxx_gc->irq->host_data = mpc8xxx_gc;/* ack and mask all irqs */ @@ -321,13 +386,7 @@ static int __init mpc8xxx_add_gpiochips(void) {struct device_node *np; -for_each_compatible_node (np,NULL ,"fsl,mpc8349-gpio" ) -mpc8xxx_add_controller (np); - -for_each_compatible_node (np,NULL ,"fsl,mpc8572-gpio" ) -mpc8xxx_add_controller (np); - -for_each_compatible_node (np,NULL ,"fsl,mpc8610-gpio" ) +for_each_matching_node (np, mpc8xxx_gpio_ids)mpc8xxx_add_controller (np);return 0 ;Signature · 1 line
1.7.0.4