update gpio patches

SVN-Revision: 33208
This commit is contained in:
Hauke Mehrtens 2012-08-18 11:51:35 +00:00
parent 67e6461ad7
commit f4d6baf498
2 changed files with 105 additions and 106 deletions

View file

@ -18,7 +18,7 @@
Support for BCM47XX based boards Support for BCM47XX based boards
--- a/arch/mips/bcm47xx/gpio.c --- a/arch/mips/bcm47xx/gpio.c
+++ b/arch/mips/bcm47xx/gpio.c +++ b/arch/mips/bcm47xx/gpio.c
@@ -4,81 +4,198 @@ @@ -4,83 +4,150 @@
* for more details. * for more details.
* *
* Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net> * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
@ -62,10 +62,20 @@
- if (ssb_extif_available(&bcm47xx_bus.ssb.extif) && - if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
- ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES)) - ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
- return -EINVAL; - return -EINVAL;
-
- if (test_and_set_bit(gpio, gpio_in_use))
- return -EBUSY;
-
- return 0;
+ return ssb_gpio_in(&bcm47xx_bus.ssb, mask); + return ssb_gpio_in(&bcm47xx_bus.ssb, mask);
+#endif #endif
+#ifdef CONFIG_BCM47XX_BCMA #ifdef CONFIG_BCM47XX_BCMA
+ case BCM47XX_BUS_TYPE_BCMA: case BCM47XX_BUS_TYPE_BCMA:
- if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
- return -EINVAL;
-
- if (test_and_set_bit(gpio, gpio_in_use))
- return -EBUSY;
+ return bcma_gpio_in(&bcm47xx_bus.bcma.bus, mask); + return bcma_gpio_in(&bcm47xx_bus.bcma.bus, mask);
+#endif +#endif
+ } + }
@ -73,8 +83,7 @@
+} +}
+EXPORT_SYMBOL(bcm47xx_gpio_in); +EXPORT_SYMBOL(bcm47xx_gpio_in);
- if (test_and_set_bit(gpio, gpio_in_use)) - return 0;
- return -EBUSY;
+u32 bcm47xx_gpio_out(u32 mask, u32 value) +u32 bcm47xx_gpio_out(u32 mask, u32 value)
+{ +{
+ switch (bcm47xx_bus_type) { + switch (bcm47xx_bus_type) {
@ -85,24 +94,26 @@
+#ifdef CONFIG_BCM47XX_BCMA +#ifdef CONFIG_BCM47XX_BCMA
+ case BCM47XX_BUS_TYPE_BCMA: + case BCM47XX_BUS_TYPE_BCMA:
+ return bcma_gpio_out(&bcm47xx_bus.bcma.bus, mask, value); + return bcma_gpio_out(&bcm47xx_bus.bcma.bus, mask, value);
+#endif #endif
+ } }
+ return -EINVAL; return -EINVAL;
+} }
-EXPORT_SYMBOL(gpio_request);
+EXPORT_SYMBOL(bcm47xx_gpio_out); +EXPORT_SYMBOL(bcm47xx_gpio_out);
- return 0; -void gpio_free(unsigned gpio)
+u32 bcm47xx_gpio_outen(u32 mask, u32 value) +u32 bcm47xx_gpio_outen(u32 mask, u32 value)
+{ {
+ switch (bcm47xx_bus_type) { switch (bcm47xx_bus_type) {
+#ifdef CONFIG_BCM47XX_SSB #ifdef CONFIG_BCM47XX_SSB
+ case BCM47XX_BUS_TYPE_SSB: case BCM47XX_BUS_TYPE_SSB:
- if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
- ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
- return;
+ return ssb_gpio_outen(&bcm47xx_bus.ssb, mask, value); + return ssb_gpio_outen(&bcm47xx_bus.ssb, mask, value);
#endif +#endif
#ifdef CONFIG_BCM47XX_BCMA +#ifdef CONFIG_BCM47XX_BCMA
case BCM47XX_BUS_TYPE_BCMA: + case BCM47XX_BUS_TYPE_BCMA:
- if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
- return -EINVAL;
+ return bcma_gpio_outen(&bcm47xx_bus.bcma.bus, mask, value); + return bcma_gpio_outen(&bcm47xx_bus.bcma.bus, mask, value);
+#endif +#endif
+ } + }
@ -110,8 +121,9 @@
+} +}
+EXPORT_SYMBOL(bcm47xx_gpio_outen); +EXPORT_SYMBOL(bcm47xx_gpio_outen);
- if (test_and_set_bit(gpio, gpio_in_use)) - if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
- return -EBUSY; - ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
- return;
+u32 bcm47xx_gpio_control(u32 mask, u32 value) +u32 bcm47xx_gpio_control(u32 mask, u32 value)
+{ +{
+ switch (bcm47xx_bus_type) { + switch (bcm47xx_bus_type) {
@ -128,46 +140,45 @@
+} +}
+EXPORT_SYMBOL(bcm47xx_gpio_control); +EXPORT_SYMBOL(bcm47xx_gpio_control);
- return 0; - clear_bit(gpio, gpio_in_use);
- return;
+u32 bcm47xx_gpio_intmask(u32 mask, u32 value) +u32 bcm47xx_gpio_intmask(u32 mask, u32 value)
+{ +{
+ switch (bcm47xx_bus_type) { + switch (bcm47xx_bus_type) {
+#ifdef CONFIG_BCM47XX_SSB +#ifdef CONFIG_BCM47XX_SSB
+ case BCM47XX_BUS_TYPE_SSB: + case BCM47XX_BUS_TYPE_SSB:
+ return ssb_gpio_intmask(&bcm47xx_bus.ssb, mask, value); + return ssb_gpio_intmask(&bcm47xx_bus.ssb, mask, value);
+#endif
+#ifdef CONFIG_BCM47XX_BCMA
+ case BCM47XX_BUS_TYPE_BCMA:
+ return bcma_gpio_intmask(&bcm47xx_bus.bcma.bus, mask, value);
#endif #endif
} #ifdef CONFIG_BCM47XX_BCMA
return -EINVAL; case BCM47XX_BUS_TYPE_BCMA:
} - if (gpio >= BCM47XX_CHIPCO_GPIO_LINES)
-EXPORT_SYMBOL(gpio_request); - return;
+ return bcma_gpio_intmask(&bcm47xx_bus.bcma.bus, mask, value);
+#endif
+ }
+ return -EINVAL;
+}
+EXPORT_SYMBOL(bcm47xx_gpio_intmask); +EXPORT_SYMBOL(bcm47xx_gpio_intmask);
-void gpio_free(unsigned gpio) - clear_bit(gpio, gpio_in_use);
- return;
+u32 bcm47xx_gpio_polarity(u32 mask, u32 value) +u32 bcm47xx_gpio_polarity(u32 mask, u32 value)
{ +{
switch (bcm47xx_bus_type) { + switch (bcm47xx_bus_type) {
#ifdef CONFIG_BCM47XX_SSB +#ifdef CONFIG_BCM47XX_SSB
case BCM47XX_BUS_TYPE_SSB: + case BCM47XX_BUS_TYPE_SSB:
- if (ssb_chipco_available(&bcm47xx_bus.ssb.chipco) &&
- ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
- return;
+ return ssb_gpio_polarity(&bcm47xx_bus.ssb, mask, value); + return ssb_gpio_polarity(&bcm47xx_bus.ssb, mask, value);
+#endif +#endif
+#ifdef CONFIG_BCM47XX_BCMA +#ifdef CONFIG_BCM47XX_BCMA
+ case BCM47XX_BUS_TYPE_BCMA: + case BCM47XX_BUS_TYPE_BCMA:
+ return bcma_gpio_polarity(&bcm47xx_bus.bcma.bus, mask, value); + return bcma_gpio_polarity(&bcm47xx_bus.bcma.bus, mask, value);
+#endif #endif
+ } }
+ return -EINVAL; + return -EINVAL;
+} +}
+EXPORT_SYMBOL(bcm47xx_gpio_polarity); +EXPORT_SYMBOL(bcm47xx_gpio_polarity);
+ +
+ +
+
+static int bcm47xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio) +static int bcm47xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
+{ +{
+ return bcm47xx_gpio_in(1 << gpio); + return bcm47xx_gpio_in(1 << gpio);
@ -194,7 +205,19 @@
+ /* then set the gpio mode */ + /* then set the gpio mode */
+ bcm47xx_gpio_outen(1 << gpio, 1 << gpio); + bcm47xx_gpio_outen(1 << gpio, 1 << gpio);
+ return 0; + return 0;
+} }
-EXPORT_SYMBOL(gpio_free);
-int gpio_to_irq(unsigned gpio)
+static int bcm47xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
{
switch (bcm47xx_bus_type) {
#ifdef CONFIG_BCM47XX_SSB
@@ -99,4 +166,55 @@ int gpio_to_irq(unsigned gpio)
}
return -EINVAL;
}
-EXPORT_SYMBOL_GPL(gpio_to_irq);
+ +
+static struct gpio_chip bcm47xx_gpio_chip = { +static struct gpio_chip bcm47xx_gpio_chip = {
+ .label = "bcm47xx", + .label = "bcm47xx",
@ -202,41 +225,33 @@
+ .set = bcm47xx_gpio_set_value, + .set = bcm47xx_gpio_set_value,
+ .direction_input = bcm47xx_gpio_direction_input, + .direction_input = bcm47xx_gpio_direction_input,
+ .direction_output = bcm47xx_gpio_direction_output, + .direction_output = bcm47xx_gpio_direction_output,
+ .to_irq = bcm47xx_gpio_to_irq,
+ .base = 0, + .base = 0,
+}; +};
+
- if (ssb_extif_available(&bcm47xx_bus.ssb.extif) &&
- ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
- return;
+void __init bcm47xx_gpio_init(void) +void __init bcm47xx_gpio_init(void)
+{ +{
+ int err; + int err;
+
- clear_bit(gpio, gpio_in_use);
- return;
+ switch (bcm47xx_bus_type) { + switch (bcm47xx_bus_type) {
+#ifdef CONFIG_BCM47XX_SSB +#ifdef CONFIG_BCM47XX_SSB
+ case BCM47XX_BUS_TYPE_SSB: + case BCM47XX_BUS_TYPE_SSB:
+ bcm47xx_gpio_count = ssb_gpio_count(&bcm47xx_bus.ssb); + bcm47xx_gpio_count = ssb_gpio_count(&bcm47xx_bus.ssb);
#endif + break;
#ifdef CONFIG_BCM47XX_BCMA +#endif
case BCM47XX_BUS_TYPE_BCMA: +#ifdef CONFIG_BCM47XX_BCMA
- if (gpio >= BCM47XX_CHIPCO_GPIO_LINES) + case BCM47XX_BUS_TYPE_BCMA:
- return;
-
- clear_bit(gpio, gpio_in_use);
- return;
+ bcm47xx_gpio_count = bcma_gpio_count(&bcm47xx_bus.bcma.bus); + bcm47xx_gpio_count = bcma_gpio_count(&bcm47xx_bus.bcma.bus);
#endif + break;
} +#endif
+ }
+ +
+ bcm47xx_gpio_chip.ngpio = bcm47xx_gpio_count; + bcm47xx_gpio_chip.ngpio = bcm47xx_gpio_count;
+ +
+ err = gpiochip_add(&bcm47xx_gpio_chip); + err = gpiochip_add(&bcm47xx_gpio_chip);
+ if (err) + if (err)
+ panic("cannot add BCM47xx GPIO chip, error=%d", err); + panic("cannot add BCM47xx GPIO chip, error=%d", err);
} +}
-EXPORT_SYMBOL(gpio_free);
+ +
+int gpio_get_value(unsigned gpio) +int gpio_get_value(unsigned gpio)
+{ +{
@ -255,22 +270,6 @@
+ __gpio_set_value(gpio, value); + __gpio_set_value(gpio, value);
+} +}
+EXPORT_SYMBOL(gpio_set_value); +EXPORT_SYMBOL(gpio_set_value);
int gpio_to_irq(unsigned gpio)
{
@@ -99,4 +216,11 @@ int gpio_to_irq(unsigned gpio)
}
return -EINVAL;
}
-EXPORT_SYMBOL_GPL(gpio_to_irq);
+EXPORT_SYMBOL(gpio_to_irq);
+
+int irq_to_gpio(unsigned irq)
+{
+ /* FIXME */
+ return -EINVAL;
+}
+EXPORT_SYMBOL(irq_to_gpio);
--- a/arch/mips/bcm47xx/setup.c --- a/arch/mips/bcm47xx/setup.c
+++ b/arch/mips/bcm47xx/setup.c +++ b/arch/mips/bcm47xx/setup.c
@@ -344,6 +344,8 @@ void __init plat_mem_setup(void) @@ -344,6 +344,8 @@ void __init plat_mem_setup(void)
@ -298,7 +297,7 @@
+ err = gpio_request(WGT634U_GPIO_RESET, "reset-buton"); + err = gpio_request(WGT634U_GPIO_RESET, "reset-buton");
+ if (err) { + if (err) {
+ printk(KERN_INFO "Can not register gpio fir reset button\n"); + printk(KERN_INFO "Can not register gpio for reset button\n");
+ return 0; + return 0;
+ } + }
+ +
@ -316,7 +315,7 @@
#endif /* __ASM_BCM47XX_H */ #endif /* __ASM_BCM47XX_H */
--- a/arch/mips/include/asm/mach-bcm47xx/gpio.h --- a/arch/mips/include/asm/mach-bcm47xx/gpio.h
+++ b/arch/mips/include/asm/mach-bcm47xx/gpio.h +++ b/arch/mips/include/asm/mach-bcm47xx/gpio.h
@@ -4,152 +4,39 @@ @@ -4,152 +4,42 @@
* for more details. * for more details.
* *
* Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net> * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
@ -336,9 +335,7 @@
-extern int gpio_request(unsigned gpio, const char *label); -extern int gpio_request(unsigned gpio, const char *label);
-extern void gpio_free(unsigned gpio); -extern void gpio_free(unsigned gpio);
-extern int gpio_to_irq(unsigned gpio); -extern int gpio_to_irq(unsigned gpio);
+#define ARCH_NR_GPIOS 64 -
+#include <asm-generic/gpio.h>
-static inline int gpio_get_value(unsigned gpio) -static inline int gpio_get_value(unsigned gpio)
-{ -{
- switch (bcm47xx_bus_type) { - switch (bcm47xx_bus_type) {
@ -381,6 +378,14 @@
-{ -{
- return 0; - return 0;
-} -}
-
-static inline int gpio_is_valid(unsigned gpio)
-{
- return gpio < (BCM47XX_EXTIF_GPIO_LINES + BCM47XX_CHIPCO_GPIO_LINES);
-}
+#define ARCH_NR_GPIOS 64
+#include <asm-generic/gpio.h>
+/* low level BCM47xx gpio api */ +/* low level BCM47xx gpio api */
+u32 bcm47xx_gpio_in(u32 mask); +u32 bcm47xx_gpio_in(u32 mask);
+u32 bcm47xx_gpio_out(u32 mask, u32 value); +u32 bcm47xx_gpio_out(u32 mask, u32 value);
@ -389,19 +394,8 @@
+u32 bcm47xx_gpio_intmask(u32 mask, u32 value); +u32 bcm47xx_gpio_intmask(u32 mask, u32 value);
+u32 bcm47xx_gpio_polarity(u32 mask, u32 value); +u32 bcm47xx_gpio_polarity(u32 mask, u32 value);
-static inline int gpio_is_valid(unsigned gpio)
-{
- return gpio < (BCM47XX_EXTIF_GPIO_LINES + BCM47XX_CHIPCO_GPIO_LINES);
-}
+int gpio_to_irq(unsigned gpio);
+int irq_to_gpio(unsigned irq);
+int gpio_get_value(unsigned gpio);
+void gpio_set_value(unsigned gpio, int value);
-
-static inline int gpio_direction_input(unsigned gpio) -static inline int gpio_direction_input(unsigned gpio)
+static inline void gpio_intmask(unsigned gpio, int value) -{
{
- switch (bcm47xx_bus_type) { - switch (bcm47xx_bus_type) {
-#ifdef CONFIG_BCM47XX_SSB -#ifdef CONFIG_BCM47XX_SSB
- case BCM47XX_BUS_TYPE_SSB: - case BCM47XX_BUS_TYPE_SSB:
@ -416,11 +410,12 @@
-#endif -#endif
- } - }
- return -EINVAL; - return -EINVAL;
+ bcm47xx_gpio_intmask(1 << gpio, value ? 1 << gpio : 0); -}
} +int gpio_get_value(unsigned gpio);
+void gpio_set_value(unsigned gpio, int value);
-static inline int gpio_direction_output(unsigned gpio, int value) -static inline int gpio_direction_output(unsigned gpio, int value)
+static inline void gpio_polarity(unsigned gpio, int value) +static inline void gpio_intmask(unsigned gpio, int value)
{ {
- switch (bcm47xx_bus_type) { - switch (bcm47xx_bus_type) {
-#ifdef CONFIG_BCM47XX_SSB -#ifdef CONFIG_BCM47XX_SSB
@ -444,11 +439,12 @@
-#endif -#endif
- } - }
- return -EINVAL; - return -EINVAL;
+ bcm47xx_gpio_polarity(1 << gpio, value ? 1 << gpio : 0); + bcm47xx_gpio_intmask(1 << gpio, value ? 1 << gpio : 0);
} }
-static inline int gpio_intmask(unsigned gpio, int value) -static inline int gpio_intmask(unsigned gpio, int value)
-{ +static inline void gpio_polarity(unsigned gpio, int value)
{
- switch (bcm47xx_bus_type) { - switch (bcm47xx_bus_type) {
-#ifdef CONFIG_BCM47XX_SSB -#ifdef CONFIG_BCM47XX_SSB
- case BCM47XX_BUS_TYPE_SSB: - case BCM47XX_BUS_TYPE_SSB:
@ -464,10 +460,12 @@
-#endif -#endif
- } - }
- return -EINVAL; - return -EINVAL;
-} + bcm47xx_gpio_polarity(1 << gpio, value ? 1 << gpio : 0);
- }
-static inline int gpio_polarity(unsigned gpio, int value) -static inline int gpio_polarity(unsigned gpio, int value)
-{ +static inline int irq_to_gpio(int gpio)
{
- switch (bcm47xx_bus_type) { - switch (bcm47xx_bus_type) {
-#ifdef CONFIG_BCM47XX_SSB -#ifdef CONFIG_BCM47XX_SSB
- case BCM47XX_BUS_TYPE_SSB: - case BCM47XX_BUS_TYPE_SSB:
@ -482,9 +480,10 @@
- return 0; - return 0;
-#endif -#endif
- } - }
- return -EINVAL; return -EINVAL;
-} }
+#define gpio_cansleep __gpio_cansleep +#define gpio_cansleep __gpio_cansleep
+#define gpio_to_irq __gpio_to_irq
#endif /* __BCM47XX_GPIO_H */ #endif /* __BCM47XX_GPIO_H */

View file

@ -159,7 +159,7 @@
- -
- err = gpio_request(WGT634U_GPIO_RESET, "reset-buton"); - err = gpio_request(WGT634U_GPIO_RESET, "reset-buton");
- if (err) { - if (err) {
- printk(KERN_INFO "Can not register gpio fir reset button\n"); - printk(KERN_INFO "Can not register gpio for reset button\n");
- return 0; - return 0;
- } - }
- -