gpio: Add device driver for GRGPIO cores
PATCH 1/1 gpio: Add device driver for GRGPIO cores
This driver supports GRGPIO gpio cores available in the GRLIB VHDL IP core library.
--- drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-grgpio.c | 313 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 321 insertions(+), 0 deletions(-) create mode 100644 drivers/gpio/gpio-grgpio.c
drivers/gpio/Kconfig +7 -0
@@ -298,6 +298,13 @@ config GPIO_GE_FPGA and write pin state) for GPIO implemented in a number of GE single board computers. +config GPIO_GRGPIO + tristate "Aeroflex Gaisler GRGPIO support" + depends on OF + help + Select this to support Aeroflex Gaisler GRGPIO cores from the GRLIB + VHDL IP core library. + comment "I2C GPIO expanders:" config GPIO_ARIZONA
drivers/gpio/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o obj-$(CONFIG_GPIO_EM) += gpio-em.o obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o +obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o obj-$(CONFIG_GPIO_ICH) += gpio-ich.o obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o
drivers/gpio/gpio-grgpio.c new file +313 -0
313 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Quoted 4 lines · Andreas Larsson
This driver supports GRGPIO gpio cores available in the GRLIB VHDL IP core library.
Signed-off-by Andreas Larsson <andreas-FkzTOoA/[email protected]>
OK...
Quoted 11 lines
drivers/gpio/gpio-grgpio.c new file +11
-0+#if defined(__BIG_ENDIAN) +static inline u32 grgpio_read_reg (u32 __iomem *reg) +{ +return ioread32be (reg); +} + +static inline void grgpio_write_reg (u32 __iomem *reg,u32 val) +{ +iowrite32be (val, reg); +} +#else
drivers/gpio/gpio-grgpio.c line 91
Quoted 10 lines
drivers/gpio/gpio-grgpio.c new file +10
-0+static inline u32 grgpio_read_reg (u32 __iomem *reg) +{ +return ioread32 (reg); +} + +static inline void grgpio_write_reg (u32 __iomem *reg,u32 val) +{ +iowrite32 (val, reg); +} +#endif
Where is this __BIG_ENDIAN flag coming from?
And do you really have and test this regularly on both LE and BE hardware? I am worrying a bit about maintenance...
Quoted 5 lines
drivers/gpio/gpio-grgpio.c new file +5
-0+static void grgpio_set_sbit (struct grgpio_priv *priv,u32 __iomem *reg, +unsigned offset,int val,u32 *shadow) +{ +unsigned long flags; +
drivers/gpio/gpio-grgpio.c line 107
Quoted 10 lines
drivers/gpio/gpio-grgpio.c new file +10
-0+spin_lock_irqsave (&priv->lock, flags); + +if (val) + *shadow |= (1 << offset); +else + *shadow &= ~(1 << offset); +grgpio_write_reg (reg, *shadow); + +spin_unlock_irqrestore (&priv->lock, flags); +}
This is all very basic stuff. Please make a best effort to reuse or augment and reuse this:drivers/gpio/gpio-generic.c
IIRC this one also handles endianness issues, but I could be wrong.
Yours,
Linus Walleij
Quoted 15 lines · Linus Walleij
drivers/gpio/gpio-grgpio.c line 81
Quoted 12 lines
drivers/gpio/gpio-grgpio.c new file +11
-0+#if defined(__BIG_ENDIAN) +static inline u32 grgpio_read_reg (u32 __iomem *reg) +{ +return ioread32be (reg); +} + +static inline void grgpio_write_reg (u32 __iomem *reg,u32 val) +{ +iowrite32be (val, reg); +} +#else Where is this
__BIG_ENDIANflag coming from?
Quoted 2 lines
And do you really have and test this regularly on both LE and BE hardware? I am worrying a bit about maintenance...
I am more than happy to drop that. I will most probably never test this on LE hardware.
Quoted 20 lines
Quoted 5 lines
drivers/gpio/gpio-grgpio.c new file +5
-0+static void grgpio_set_sbit (struct grgpio_priv *priv,u32 __iomem *reg, +unsigned offset,int val,u32 *shadow) +{ +unsigned long flags; +drivers/gpio/gpio-grgpio.c line 107
Quoted 10 lines
drivers/gpio/gpio-grgpio.c new file +10
-0+spin_lock_irqsave (&priv->lock, flags); + +if (val) + *shadow |= (1 << offset); +else + *shadow &= ~(1 << offset); +grgpio_write_reg (reg, *shadow); + +spin_unlock_irqrestore (&priv->lock, flags); +}This is all very basic stuff. Please make a best effort to reuse or augment and reuse this:
drivers/gpio/gpio-generic.c
Quoted 1 line
IIRC this one also handles endianness issues, but I could be wrong.
Sure, many of the initial functions do small basic tasks and resembles functions in gpio-generic. But that does not make the hardware itself a good candidate to use gpio-generic IMHO:
1) This core is generally running on SPARC, that is BE, but even on SPARC, readl and writel (that would be used in gprio-generic) deals with LE accesses and my registers are BE.
2) The grgpio_to_irq function is very hardware specific, and there is of course no gpio_to_irq support in gpio-generic.
3) Running on SPARC, I get Open Firmware information from prom, so there is no platform data to access in the probe function. Of course general Open Firmware support could be added to gpio-generic, but in addition my probe needs to set up very hardware specific things for gpio_to_irq.
Thank you for the feedback!
Cheers,
Andreas Larsson
(CC:ing Anton who wrote the generic GPIO. I might be wrong.)
Quoted 18 lines · Andreas Larsson
Quoted 17 lines · Linus Walleij
drivers/gpio/gpio-grgpio.c line 81
Quoted 13 lines
drivers/gpio/gpio-grgpio.c new file +11
-0+#if defined(__BIG_ENDIAN) +static inline u32 grgpio_read_reg (u32 __iomem *reg) +{ +return ioread32be (reg); +} + +static inline void grgpio_write_reg (u32 __iomem *reg,u32 val) +{ +iowrite32be (val, reg); +} +#else Where is this
__BIG_ENDIANflag coming from?
Quoted 5 lines
Quoted 2 lines
And do you really have and test this regularly on both LE and BE hardware? I am worrying a bit about maintenance...
I am more than happy to drop that. I will most probably never test this on LE hardware.
Will someone else? I'm more thinking whether it is customary in the SPARC drivers to do things like this, then we should follow that pattern of course.
Quoted 23 lines
Quoted 21 lines
Quoted 5 lines
drivers/gpio/gpio-grgpio.c new file +5
-0+static void grgpio_set_sbit (struct grgpio_priv *priv,u32 __iomem *reg, +unsigned offset,int val,u32 *shadow) +{ +unsigned long flags; +drivers/gpio/gpio-grgpio.c line 107
Quoted 10 lines
drivers/gpio/gpio-grgpio.c new file +10
-0+spin_lock_irqsave (&priv->lock, flags); + +if (val) + *shadow |= (1 << offset); +else + *shadow &= ~(1 << offset); +grgpio_write_reg (reg, *shadow); + +spin_unlock_irqrestore (&priv->lock, flags); +}This is all very basic stuff. Please make a best effort to reuse or augment and reuse this:
drivers/gpio/gpio-generic.cQuoted 1 line
IIRC this one also handles endianness issues, but I could be wrong.
Quoted 7 lines
Sure, many of the initial functions do small basic tasks and resembles functions in gpio-generic. But that does not make the hardware itself a good candidate to use gpio-generic IMHO:
1) This core is generally running on SPARC, that is BE, but even on SPARC, readl and writel (that would be used in gprio-generic) deals with LE accesses and my registers are BE.
Yeah that's true. :-(
I think it's because read[lwb]/write[lwb] comes out of PCI and PCI is LE.
Didn't think of this...
Quoted 2 lines
2) The
grgpio_to_irqfunction is very hardware specific, and there is of course nogpio_to_irqsupport in gpio-generic.
Well, the idea about gpio-generic is to use the pieces you need IIRC. You may override.
Quoted 4 lines
3) Running on SPARC, I get Open Firmware information from prom, so there is no platform data to access in the probe function. Of course general Open Firmware support could be added to gpio-generic, but in addition my probe needs to set up very hardware specific things for
gpio_to_irq.
We should probably add some way to handle generic GPIO with compatible strings etc, but that's way outside my competence so OK. Maybe Rob or Grant can say something.
Yours,
Linus Walleij
Quoted 9 lines · Linus Walleij
Quoted 5 lines
Quoted 2 lines
And do you really have and test this regularly on both LE and BE hardware? I am worrying a bit about maintenance...
I am more than happy to drop that. I will most probably never test this on LE hardware.
Will someone else? I'm more thinking whether it is customary in the SPARC drivers to do things like this, then we should follow that pattern of course.
It is definitely not customary in SPARC drivers. The module is marked "depends on OF" in Kconfig though and there seems to be no way to depend on an endianness. Unless someone instantiates the core in a LE system there is no reason for it.
Quoted 5 lines
Quoted 2 lines
2) The
grgpio_to_irqfunction is very hardware specific, and there is of course nogpio_to_irqsupport in gpio-generic.Well, the idea about gpio-generic is to use the pieces you need IIRC. You may override.
Ah, I see, bgpio_init is exported, so I might be able use that from my driver to get rid of some functions. There is support for BE I saw now. It seems broken to me (flips bits, not bytes), but that can be fixed.
Quoted 8 lines
Quoted 4 lines
3) Running on SPARC, I get Open Firmware information from prom, so there is no platform data to access in the probe function. Of course general Open Firmware support could be added to gpio-generic, but in addition my probe needs to set up very hardware specific things for
gpio_to_irq.We should probably add some way to handle generic GPIO with compatible strings etc, but that's way outside my competence so OK. Maybe Rob or Grant can say something.
Might be a good idea. However, by just using bgpio_init in a separate driver (like most other users of bgpio_init), that would not be required or used by me anyhow.
I'll look into using bgpio_init from my driver.
Cheers,
Andreas Larsson
Quoted 4 lines · Andreas Larsson
This driver supports GRGPIO gpio cores available in the GRLIB VHDL IP core library.
Signed-off-by Andreas Larsson <andreas-FkzTOoA/[email protected]>
Have you looked at drivers/gpio/gpio-generic.c? This looks to me like yet another memory mapped gpio controller than could be handled with the generic driver.
g.
On Mon, Feb 04, 2013 at 11:27:33AM +0100, Andreas Larsson wrote:
[...]
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
2) The
grgpio_to_irqfunction is very hardware specific, and there is of course nogpio_to_irqsupport in gpio-generic.Well, the idea about gpio-generic is to use the pieces you need IIRC. You may override.
Ah, I see,
bgpio_initis exported, so I might be able use that from my driver to get rid of some functions. There is support for BE I saw now. It seems broken to me (flips bits, not bytes), but that can be fixed.
No, it is not broken. :-) There is a BE-notation of GPIO numbering. BE/LE issue is also valid for bits. Please don't "fix" this. :)
If you need to introduce byte endianness support in addition, that's fine.
Thanks,
Anton