All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] provide functions for gpio configuration
@ 2008-10-29 20:00 Phil Sutter
  2008-10-29 20:07 ` Florian Fainelli
  0 siblings, 1 reply; 19+ messages in thread
From: Phil Sutter @ 2008-10-29 20:00 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Florian Fainelli, Linux-Mips List

As gpiolib doesn't support pin multiplexing, it provides no way to
access the GPIOFUNC register. Also there is no support for setting
interrupt status and level. These functions provide access to them and
are needed by the CompactFlash driver.

The function rb532_gpio_set_cfg is redundant with
rb532_gpio_direction_{input,output} but was added for simplicity's sake.
Maybe gpiolib support could be dropped completely as there are not many
users of it.

Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
 arch/mips/include/asm/mach-rc32434/rb.h |    1 +
 arch/mips/rb532/gpio.c                  |   39 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/arch/mips/include/asm/mach-rc32434/rb.h b/arch/mips/include/asm/mach-rc32434/rb.h
index 0cb9466..f25a849 100644
--- a/arch/mips/include/asm/mach-rc32434/rb.h
+++ b/arch/mips/include/asm/mach-rc32434/rb.h
@@ -41,6 +41,7 @@
 #define BTCOMPARE	0x010044
 #define GPIOBASE	0x050000
 /* Offsets relative to GPIOBASE */
+#define GPIOFUNC	0x00
 #define GPIOCFG		0x04
 #define GPIOD		0x08
 #define GPIOILEVEL	0x0C
diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 70c4a67..f56f73b 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -287,6 +287,45 @@ static struct rb532_gpio_chip rb532_gpio_chip[] = {
 	},
 };
 
+static void rb532_do_gpio_set(int bit, unsigned gpio, void __iomem *addr)
+{
+	unsigned long flags;
+	u32 val;
+
+	local_irq_save(flags);
+	val = readl(addr);
+	if (bit)
+		val |= (1 << gpio);
+	else
+		val &= ~(1 << gpio);
+	writel(val, addr);
+	local_irq_restore(flags);
+}
+
+void  rb532_gpio_set_func(int bit, unsigned gpio)
+{
+	rb532_do_gpio_set(bit, gpio, rb532_gpio_chip->regbase + GPIOFUNC);
+}
+EXPORT_SYMBOL(rb532_gpio_set_func);
+
+void  rb532_gpio_set_cfg(int bit, unsigned gpio)
+{
+	rb532_do_gpio_set(bit, gpio, rb532_gpio_chip->regbase + GPIOCFG);
+}
+EXPORT_SYMBOL(rb532_gpio_set_cfg);
+
+void  rb532_gpio_set_ilevel(int bit, unsigned gpio)
+{
+	rb532_do_gpio_set(bit, gpio, rb532_gpio_chip->regbase + GPIOILEVEL);
+}
+EXPORT_SYMBOL(rb532_gpio_set_ilevel);
+
+void  rb532_gpio_set_istat(int bit, unsigned gpio)
+{
+	rb532_do_gpio_set(bit, gpio, rb532_gpio_chip->regbase + GPIOISTAT);
+}
+EXPORT_SYMBOL(rb532_gpio_set_istat);
+
 int __init rb532_gpio_init(void)
 {
 	struct resource *r;
-- 
1.5.6.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread
* [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit()
@ 2008-11-11 23:14 Phil Sutter
  2008-11-11 23:26 ` Phil Sutter
  0 siblings, 1 reply; 19+ messages in thread
From: Phil Sutter @ 2008-11-11 23:14 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips, florian

This is a simplified version of the original fix, thanks to Atsushi Nemoto for
the hint.

Greetings, Phil

---

The algorithm works unconditionally. If bitval is one, the first line is
a no op and the second line sets the bit at offset position. Vice versa,
if bitval is zero, the first line clears the bit at offset position and
the second line is a no op.

Signed-off-by: Phil Sutter <n0-1@freewrt.org>
---
 arch/mips/rb532/gpio.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/mips/rb532/gpio.c b/arch/mips/rb532/gpio.c
index 0e84c8a..e35cb75 100644
--- a/arch/mips/rb532/gpio.c
+++ b/arch/mips/rb532/gpio.c
@@ -119,13 +119,11 @@ static inline void rb532_set_bit(unsigned bitval,
 	unsigned long flags;
 	u32 val;
 
-	bitval = !!bitval;              /* map parameter to {0,1} */
-
 	local_irq_save(flags);
 
 	val = readl(ioaddr);
-	val &= ~( ~bitval << offset );   /* unset bit if bitval == 0 */
-	val |=  (  bitval << offset );   /* set bit if bitval == 1 */
+	val &= ~(!bitval << offset);   /* unset bit if bitval == 0 */
+	val |= (!!bitval << offset);   /* set bit if bitval == 1 */
 	writel(val, ioaddr);
 
 	local_irq_restore(flags);
-- 
1.5.6.4

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2009-01-29 16:27 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-29 20:00 [PATCH] provide functions for gpio configuration Phil Sutter
2008-10-29 20:07 ` Florian Fainelli
2008-10-29 21:10   ` Phil Sutter
2008-10-30 17:13     ` Florian Fainelli
2008-10-30 17:47       ` Phil Sutter
2008-10-30 18:16         ` Florian Fainelli
2008-10-30 20:20           ` Phil Sutter
2008-10-30 20:26             ` Florian Fainelli
2008-10-31  0:25             ` [PATCH] add prototypes for the exported symbols Phil Sutter
2008-10-31 14:58               ` [PATCH] provide functions for gpio configuration Phil Sutter
2008-11-02 21:56                 ` Sergei Shtylyov
2008-11-03 14:29                   ` Phil Sutter
2008-11-03 14:30                     ` [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit() Phil Sutter
2008-11-03 14:48                       ` Atsushi Nemoto
2008-11-03 15:05                         ` Phil Sutter
2008-11-11 23:09                           ` Phil Sutter
2009-01-29 16:27                             ` Ralf Baechle
  -- strict thread matches above, loose matches on Subject: below --
2008-11-11 23:14 Phil Sutter
2008-11-11 23:26 ` Phil Sutter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.