diff options
author | Michael Büsch <mb@bu3sch.de> | 2008-02-19 15:22:17 +0000 |
---|---|---|
committer | Michael Büsch <mb@bu3sch.de> | 2008-02-19 15:22:17 +0000 |
commit | 378e11cb84859d53366526e0d7bd940a35c1196a (patch) | |
tree | a292f0359e7d5042945a8b0ee5be65c67d48e64f | |
parent | e5a4fe334d805d6e1dfefaf65dddee624e8ebadc (diff) | |
download | upstream-378e11cb84859d53366526e0d7bd940a35c1196a.tar.gz upstream-378e11cb84859d53366526e0d7bd940a35c1196a.tar.bz2 upstream-378e11cb84859d53366526e0d7bd940a35c1196a.zip |
ssb: Make the GPIO API reentrancy safe.
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@10496 3c298f89-4303-0410-b956-a3cf2f4a3e73
-rw-r--r-- | package/broadcom-diag/src/gpio.h | 29 | ||||
-rw-r--r-- | package/switch/src/gpio-bcm947xx.h | 29 | ||||
-rw-r--r-- | target/linux/brcm47xx/files/include/asm-mips/mach-bcm947xx/gpio.h | 34 | ||||
-rw-r--r-- | target/linux/brcm47xx/patches-2.6.23/621-ssb-common-gpio-api.patch | 245 |
4 files changed, 265 insertions, 72 deletions
diff --git a/package/broadcom-diag/src/gpio.h b/package/broadcom-diag/src/gpio.h index 22f20c99b2..2284e9801e 100644 --- a/package/broadcom-diag/src/gpio.h +++ b/package/broadcom-diag/src/gpio.h @@ -3,54 +3,39 @@ #include <linux/interrupt.h> #ifndef BCMDRIVER -#include <linux/ssb/ssb.h> -#include <linux/ssb/ssb_driver_chipcommon.h> -#include <linux/ssb/ssb_driver_extif.h> +#include <linux/ssb/ssb_embedded.h> extern struct ssb_bus ssb; -#define gpio_op(op, param...) \ - do { \ - if (ssb.chipco.dev) \ - return ssb_chipco_gpio_##op(&ssb.chipco, param); \ - else if (ssb.extif.dev) \ - return ssb_extif_gpio_##op(&ssb.extif, param); \ - else \ - return 0; \ - } while (0); - static inline u32 gpio_in(void) { - gpio_op(in, ~0); + return ssb_gpio_in(&ssb, ~0); } static inline u32 gpio_out(u32 mask, u32 value) { - gpio_op(out, mask, value); + return ssb_gpio_out(&ssb, mask, value); } static inline u32 gpio_outen(u32 mask, u32 value) { - gpio_op(outen, mask, value); + return ssb_gpio_outen(&ssb, mask, value); } static inline u32 gpio_control(u32 mask, u32 value) { - if (ssb.chipco.dev) - return ssb_chipco_gpio_control(&ssb.chipco, mask, value); - else - return 0; + return ssb_gpio_control(&ssb, mask, value); } static inline u32 gpio_intmask(u32 mask, u32 value) { - gpio_op(intmask, mask, value); + return ssb_gpio_intmask(&ssb, mask, value); } static inline u32 gpio_intpolarity(u32 mask, u32 value) { - gpio_op(polarity, mask, value); + return ssb_gpio_polarity(&ssb, mask, value); } static inline u32 __ssb_write32_masked(struct ssb_device *dev, u16 offset, diff --git a/package/switch/src/gpio-bcm947xx.h b/package/switch/src/gpio-bcm947xx.h index 384ea3ea18..9417bce2a1 100644 --- a/package/switch/src/gpio-bcm947xx.h +++ b/package/switch/src/gpio-bcm947xx.h @@ -3,54 +3,39 @@ #include <linux/interrupt.h> #ifndef BCMDRIVER -#include <linux/ssb/ssb.h> -#include <linux/ssb/ssb_driver_chipcommon.h> -#include <linux/ssb/ssb_driver_extif.h> +#include <linux/ssb/ssb_embedded.h> extern struct ssb_bus ssb; -#define gpio_op(op, param...) \ - do { \ - if (ssb.chipco.dev) \ - return ssb_chipco_gpio_##op(&ssb.chipco, param); \ - else if (ssb.extif.dev) \ - return ssb_extif_gpio_##op(&ssb.extif, param); \ - else \ - return 0; \ - } while (0); - static inline u32 gpio_in(void) { - gpio_op(in, ~0); + return ssb_gpio_in(&ssb, ~0); } static inline u32 gpio_out(u32 mask, u32 value) { - gpio_op(out, mask, value); + return ssb_gpio_out(&ssb, mask, value); } static inline u32 gpio_outen(u32 mask, u32 value) { - gpio_op(outen, mask, value); + return ssb_gpio_outen(&ssb, mask, value); } static inline u32 gpio_control(u32 mask, u32 value) { - if (ssb.chipco.dev) - return ssb_chipco_gpio_control(&ssb.chipco, mask, value); - else - return 0; + return ssb_gpio_control(&ssb, mask, value); } static inline u32 gpio_intmask(u32 mask, u32 value) { - gpio_op(intmask, mask, value); + return ssb_gpio_intmask(&ssb, mask, value); } static inline u32 gpio_intpolarity(u32 mask, u32 value) { - gpio_op(polarity, mask, value); + return ssb_gpio_polarity(&ssb, mask, value); } #else diff --git a/target/linux/brcm47xx/files/include/asm-mips/mach-bcm947xx/gpio.h b/target/linux/brcm47xx/files/include/asm-mips/mach-bcm947xx/gpio.h index 499df4ef18..4a897d1ea4 100644 --- a/target/linux/brcm47xx/files/include/asm-mips/mach-bcm947xx/gpio.h +++ b/target/linux/brcm47xx/files/include/asm-mips/mach-bcm947xx/gpio.h @@ -1,9 +1,7 @@ #ifndef __BCM947XX_GPIO_H #define __BCM947XX_GPIO_H -#include <linux/ssb/ssb.h> -#include <linux/ssb/ssb_driver_chipcommon.h> -#include <linux/ssb/ssb_driver_extif.h> +#include <linux/ssb/ssb_embedded.h> extern struct ssb_bus ssb; @@ -18,24 +16,13 @@ static inline void gpio_free(unsigned gpio) static inline int gpio_direction_input(unsigned gpio) { - if (ssb.chipco.dev) - ssb_chipco_gpio_outen(&ssb.chipco, 1 << gpio, 0); - else if (ssb.extif.dev) - ssb_extif_gpio_outen(&ssb.extif, 1 << gpio, 0); - else - return -EINVAL; + ssb_gpio_outen(&ssb, 1 << gpio, 0); return 0; } static inline int gpio_direction_output(unsigned gpio, int value) { - if (ssb.chipco.dev) - ssb_chipco_gpio_outen(&ssb.chipco, 1 << gpio, value << gpio); - else if (ssb.extif.dev) - ssb_extif_gpio_outen(&ssb.extif, 1 << gpio, value << gpio); - else - return -EINVAL; - + ssb_gpio_outen(&ssb, 1 << gpio, value << gpio); return 0; } @@ -43,7 +30,7 @@ static inline int gpio_direction_output(unsigned gpio, int value) static inline int gpio_to_irq(unsigned gpio) { struct ssb_device *dev; - + dev = ssb.chipco.dev; if (!dev) dev = ssb.extif.dev; @@ -61,21 +48,12 @@ static inline int irq_to_gpio(unsigned gpio) static inline int gpio_get_value(unsigned gpio) { - if (ssb.chipco.dev) - return ssb_chipco_gpio_in(&ssb.chipco, 1 << gpio) ? 1 : 0; - else if (ssb.extif.dev) - return ssb_extif_gpio_in(&ssb.extif, 1 << gpio) ? 1 : 0; - else - return 0; + return !!ssb_gpio_in(&ssb, 1 << gpio); } static inline int gpio_set_value(unsigned gpio, int value) { - if (ssb.chipco.dev) - ssb_chipco_gpio_out(&ssb.chipco, 1 << gpio, (value ? 1 << gpio : 0)); - else if (ssb.extif.dev) - ssb_extif_gpio_out(&ssb.extif, 1 << gpio, (value ? 1 << gpio : 0)); - + ssb_gpio_out(&ssb, 1 << gpio, (value ? 1 << gpio : 0)); return 0; } diff --git a/target/linux/brcm47xx/patches-2.6.23/621-ssb-common-gpio-api.patch b/target/linux/brcm47xx/patches-2.6.23/621-ssb-common-gpio-api.patch new file mode 100644 index 0000000000..d1debcfe3a --- /dev/null +++ b/target/linux/brcm47xx/patches-2.6.23/621-ssb-common-gpio-api.patch @@ -0,0 +1,245 @@ +Index: linux-2.6.23.16/drivers/ssb/driver_chipcommon.c +=================================================================== +--- linux-2.6.23.16.orig/drivers/ssb/driver_chipcommon.c 2008-02-19 15:50:42.000000000 +0100 ++++ linux-2.6.23.16/drivers/ssb/driver_chipcommon.c 2008-02-19 15:50:44.000000000 +0100 +@@ -361,37 +361,31 @@ u32 ssb_chipco_gpio_in(struct ssb_chipco + { + return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask; + } +-EXPORT_SYMBOL(ssb_chipco_gpio_in); + + u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value) + { + return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value); + } +-EXPORT_SYMBOL(ssb_chipco_gpio_out); + + u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value) + { + return chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value); + } +-EXPORT_SYMBOL(ssb_chipco_gpio_outen); + + u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value) + { + return chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value); + } +-EXPORT_SYMBOL(ssb_chipco_gpio_control); + + u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value) + { + return chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value); + } +-EXPORT_SYMBOL(ssb_chipco_gpio_intmask); + + u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value) + { + return chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value); + } +-EXPORT_SYMBOL(ssb_chipco_gpio_polarity); + + #ifdef CONFIG_SSB_SERIAL + int ssb_chipco_serial_init(struct ssb_chipcommon *cc, +Index: linux-2.6.23.16/drivers/ssb/driver_extif.c +=================================================================== +--- linux-2.6.23.16.orig/drivers/ssb/driver_extif.c 2008-02-19 15:50:42.000000000 +0100 ++++ linux-2.6.23.16/drivers/ssb/driver_extif.c 2008-02-19 15:50:44.000000000 +0100 +@@ -122,30 +122,25 @@ u32 ssb_extif_gpio_in(struct ssb_extif * + { + return extif_read32(extif, SSB_EXTIF_GPIO_IN) & mask; + } +-EXPORT_SYMBOL(ssb_extif_gpio_in); + + u32 ssb_extif_gpio_out(struct ssb_extif *extif, u32 mask, u32 value) + { + return extif_write32_masked(extif, SSB_EXTIF_GPIO_OUT(0), + mask, value); + } +-EXPORT_SYMBOL(ssb_extif_gpio_out); + + u32 ssb_extif_gpio_outen(struct ssb_extif *extif, u32 mask, u32 value) + { + return extif_write32_masked(extif, SSB_EXTIF_GPIO_OUTEN(0), + mask, value); + } +-EXPORT_SYMBOL(ssb_extif_gpio_outen); + + u32 ssb_extif_gpio_polarity(struct ssb_extif *extif, u32 mask, u32 value) + { + return extif_write32_masked(extif, SSB_EXTIF_GPIO_INTPOL, mask, value); + } +-EXPORT_SYMBOL(ssb_extif_gpio_polarity); + + u32 ssb_extif_gpio_intmask(struct ssb_extif *extif, u32 mask, u32 value) + { + return extif_write32_masked(extif, SSB_EXTIF_GPIO_INTMASK, mask, value); + } +-EXPORT_SYMBOL(ssb_extif_gpio_intmask); +Index: linux-2.6.23.16/drivers/ssb/embedded.c +=================================================================== +--- linux-2.6.23.16.orig/drivers/ssb/embedded.c 2008-02-19 15:50:42.000000000 +0100 ++++ linux-2.6.23.16/drivers/ssb/embedded.c 2008-02-19 15:51:01.000000000 +0100 +@@ -11,6 +11,8 @@ + #include <linux/ssb/ssb.h> + #include <linux/ssb/ssb_embedded.h> + ++#include "ssb_private.h" ++ + + int ssb_watchdog_timer_set(struct ssb_bus *bus, u32 ticks) + { +@@ -24,3 +26,107 @@ int ssb_watchdog_timer_set(struct ssb_bu + } + return -ENODEV; + } ++ ++u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask) ++{ ++ unsigned long flags; ++ u32 res = 0; ++ ++ spin_lock_irqsave(&bus->gpio_lock, flags); ++ if (ssb_chipco_available(&bus->chipco)) ++ res = ssb_chipco_gpio_in(&bus->chipco, mask); ++ else if (ssb_extif_available(&bus->extif)) ++ res = ssb_extif_gpio_in(&bus->extif, mask); ++ else ++ SSB_WARN_ON(1); ++ spin_unlock_irqrestore(&bus->gpio_lock, flags); ++ ++ return res; ++} ++EXPORT_SYMBOL(ssb_gpio_in); ++ ++u32 ssb_gpio_out(struct ssb_bus *bus, u32 mask, u32 value) ++{ ++ unsigned long flags; ++ u32 res = 0; ++ ++ spin_lock_irqsave(&bus->gpio_lock, flags); ++ if (ssb_chipco_available(&bus->chipco)) ++ res = ssb_chipco_gpio_out(&bus->chipco, mask, value); ++ else if (ssb_extif_available(&bus->extif)) ++ res = ssb_extif_gpio_out(&bus->extif, mask, value); ++ else ++ SSB_WARN_ON(1); ++ spin_unlock_irqrestore(&bus->gpio_lock, flags); ++ ++ return res; ++} ++EXPORT_SYMBOL(ssb_gpio_out); ++ ++u32 ssb_gpio_outen(struct ssb_bus *bus, u32 mask, u32 value) ++{ ++ unsigned long flags; ++ u32 res = 0; ++ ++ spin_lock_irqsave(&bus->gpio_lock, flags); ++ if (ssb_chipco_available(&bus->chipco)) ++ res = ssb_chipco_gpio_outen(&bus->chipco, mask, value); ++ else if (ssb_extif_available(&bus->extif)) ++ res = ssb_extif_gpio_outen(&bus->extif, mask, value); ++ else ++ SSB_WARN_ON(1); ++ spin_unlock_irqrestore(&bus->gpio_lock, flags); ++ ++ return res; ++} ++EXPORT_SYMBOL(ssb_gpio_outen); ++ ++u32 ssb_gpio_control(struct ssb_bus *bus, u32 mask, u32 value) ++{ ++ unsigned long flags; ++ u32 res = 0; ++ ++ spin_lock_irqsave(&bus->gpio_lock, flags); ++ if (ssb_chipco_available(&bus->chipco)) ++ res = ssb_chipco_gpio_control(&bus->chipco, mask, value); ++ spin_unlock_irqrestore(&bus->gpio_lock, flags); ++ ++ return res; ++} ++EXPORT_SYMBOL(ssb_gpio_control); ++ ++u32 ssb_gpio_intmask(struct ssb_bus *bus, u32 mask, u32 value) ++{ ++ unsigned long flags; ++ u32 res = 0; ++ ++ spin_lock_irqsave(&bus->gpio_lock, flags); ++ if (ssb_chipco_available(&bus->chipco)) ++ res = ssb_chipco_gpio_intmask(&bus->chipco, mask, value); ++ else if (ssb_extif_available(&bus->extif)) ++ res = ssb_extif_gpio_intmask(&bus->extif, mask, value); ++ else ++ SSB_WARN_ON(1); ++ spin_unlock_irqrestore(&bus->gpio_lock, flags); ++ ++ return res; ++} ++EXPORT_SYMBOL(ssb_gpio_intmask); ++ ++u32 ssb_gpio_polarity(struct ssb_bus *bus, u32 mask, u32 value) ++{ ++ unsigned long flags; ++ u32 res = 0; ++ ++ spin_lock_irqsave(&bus->gpio_lock, flags); ++ if (ssb_chipco_available(&bus->chipco)) ++ res = ssb_chipco_gpio_polarity(&bus->chipco, mask, value); ++ else if (ssb_extif_available(&bus->extif)) ++ res = ssb_extif_gpio_polarity(&bus->extif, mask, value); ++ else ++ SSB_WARN_ON(1); ++ spin_unlock_irqrestore(&bus->gpio_lock, flags); ++ ++ return res; ++} ++EXPORT_SYMBOL(ssb_gpio_polarity); +Index: linux-2.6.23.16/include/linux/ssb/ssb.h +=================================================================== +--- linux-2.6.23.16.orig/include/linux/ssb/ssb.h 2008-02-19 15:50:42.000000000 +0100 ++++ linux-2.6.23.16/include/linux/ssb/ssb.h 2008-02-19 15:50:44.000000000 +0100 +@@ -283,6 +283,11 @@ struct ssb_bus { + /* Contents of the SPROM. */ + struct ssb_sprom sprom; + ++#ifdef CONFIG_SSB_EMBEDDED ++ /* Lock for GPIO register access. */ ++ spinlock_t gpio_lock; ++#endif /* EMBEDDED */ ++ + /* Internal-only stuff follows. Do not touch. */ + struct list_head list; + #ifdef CONFIG_SSB_DEBUG +Index: linux-2.6.23.16/include/linux/ssb/ssb_embedded.h +=================================================================== +--- linux-2.6.23.16.orig/include/linux/ssb/ssb_embedded.h 2008-02-19 15:50:42.000000000 +0100 ++++ linux-2.6.23.16/include/linux/ssb/ssb_embedded.h 2008-02-19 15:50:44.000000000 +0100 +@@ -7,4 +7,12 @@ + + extern int ssb_watchdog_timer_set(struct ssb_bus *bus, u32 ticks); + ++/* Generic GPIO API */ ++u32 ssb_gpio_in(struct ssb_bus *bus, u32 mask); ++u32 ssb_gpio_out(struct ssb_bus *bus, u32 mask, u32 value); ++u32 ssb_gpio_outen(struct ssb_bus *bus, u32 mask, u32 value); ++u32 ssb_gpio_control(struct ssb_bus *bus, u32 mask, u32 value); ++u32 ssb_gpio_intmask(struct ssb_bus *bus, u32 mask, u32 value); ++u32 ssb_gpio_polarity(struct ssb_bus *bus, u32 mask, u32 value); ++ + #endif /* LINUX_SSB_EMBEDDED_H_ */ +Index: linux-2.6.23.16/drivers/ssb/main.c +=================================================================== +--- linux-2.6.23.16.orig/drivers/ssb/main.c 2008-02-19 15:50:42.000000000 +0100 ++++ linux-2.6.23.16/drivers/ssb/main.c 2008-02-19 15:50:44.000000000 +0100 +@@ -571,6 +571,9 @@ static int ssb_bus_register(struct ssb_b + + spin_lock_init(&bus->bar_lock); + INIT_LIST_HEAD(&bus->list); ++#ifdef CONFIG_SSB_EMBEDDED ++ spin_lock_init(&bus->gpio_lock); ++#endif + + /* Powerup the bus */ + err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1); |