brcm47xx: use libgpio instaed of implementing the gpio interface ourself.
[openwrt.git] / target / linux / brcm47xx / patches-3.3 / 501-bcma-add-gpio-driver.patch
1 --- a/drivers/bcma/Kconfig
2 +++ b/drivers/bcma/Kconfig
3 @@ -39,6 +39,11 @@ config BCMA_HOST_SOC
4         depends on BCMA_DRIVER_MIPS
5         select USB_HCD_BCMA if USB_EHCI_HCD || USB_OHCI_HCD
6  
7 +config BCMA_DRIVER_GPIO
8 +       bool
9 +       depends on BCMA_DRIVER_MIPS
10 +       default y
11 +
12  config BCMA_SFLASH
13         bool
14         depends on BCMA_DRIVER_MIPS
15 --- a/drivers/bcma/Makefile
16 +++ b/drivers/bcma/Makefile
17 @@ -6,6 +6,7 @@ bcma-y                                  += driver_pci.o
18  bcma-$(CONFIG_BCMA_DRIVER_PCI_HOSTMODE)        += driver_pci_host.o
19  bcma-$(CONFIG_BCMA_DRIVER_MIPS)                += driver_mips.o
20  bcma-$(CONFIG_BCMA_DRIVER_GMAC_CMN)    += driver_gmac_cmn.o
21 +bcma-$(CONFIG_BCMA_DRIVER_GPIO)                += driver_gpio.o
22  bcma-$(CONFIG_BCMA_HOST_PCI)           += host_pci.o
23  bcma-$(CONFIG_BCMA_HOST_SOC)           += host_soc.o
24  obj-$(CONFIG_BCMA)                     += bcma.o
25 --- /dev/null
26 +++ b/drivers/bcma/driver_gpio.c
27 @@ -0,0 +1,96 @@
28 +/*
29 + * Broadcom specific AMBA
30 + * GPIO driver for SoCs
31 + *
32 + * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
33 + *
34 + * Licensed under the GNU/GPL. See COPYING for details.
35 + */
36 +
37 +#include <linux/export.h>
38 +#include <linux/bcma/bcma.h>
39 +#include <linux/bcma/bcma_driver_gpio.h>
40 +
41 +u32 bcma_gpio_in(struct bcma_bus *bus, u32 mask)
42 +{
43 +       unsigned long flags;
44 +       u32 res = 0;
45 +
46 +       spin_lock_irqsave(&bus->gpio_lock, flags);
47 +       res = bcma_chipco_gpio_in(&bus->drv_cc, mask);
48 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
49 +
50 +       return res;
51 +}
52 +EXPORT_SYMBOL(bcma_gpio_in);
53 +
54 +u32 bcma_gpio_out(struct bcma_bus *bus, u32 mask, u32 value)
55 +{
56 +       unsigned long flags;
57 +       u32 res = 0;
58 +
59 +       spin_lock_irqsave(&bus->gpio_lock, flags);
60 +       res = bcma_chipco_gpio_out(&bus->drv_cc, mask, value);
61 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
62 +
63 +       return res;
64 +}
65 +EXPORT_SYMBOL(bcma_gpio_out);
66 +
67 +u32 bcma_gpio_outen(struct bcma_bus *bus, u32 mask, u32 value)
68 +{
69 +       unsigned long flags;
70 +       u32 res = 0;
71 +
72 +       spin_lock_irqsave(&bus->gpio_lock, flags);
73 +       res = bcma_chipco_gpio_outen(&bus->drv_cc, mask, value);
74 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
75 +
76 +       return res;
77 +}
78 +EXPORT_SYMBOL(bcma_gpio_outen);
79 +
80 +u32 bcma_gpio_control(struct bcma_bus *bus, u32 mask, u32 value)
81 +{
82 +       unsigned long flags;
83 +       u32 res = 0;
84 +
85 +       spin_lock_irqsave(&bus->gpio_lock, flags);
86 +       res = bcma_chipco_gpio_control(&bus->drv_cc, mask, value);
87 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
88 +
89 +       return res;
90 +}
91 +EXPORT_SYMBOL(bcma_gpio_control);
92 +
93 +u32 bcma_gpio_intmask(struct bcma_bus *bus, u32 mask, u32 value)
94 +{
95 +       unsigned long flags;
96 +       u32 res = 0;
97 +
98 +       spin_lock_irqsave(&bus->gpio_lock, flags);
99 +       res = bcma_chipco_gpio_intmask(&bus->drv_cc, mask, value);
100 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
101 +
102 +       return res;
103 +}
104 +EXPORT_SYMBOL(bcma_gpio_intmask);
105 +
106 +u32 bcma_gpio_polarity(struct bcma_bus *bus, u32 mask, u32 value)
107 +{
108 +       unsigned long flags;
109 +       u32 res = 0;
110 +
111 +       spin_lock_irqsave(&bus->gpio_lock, flags);
112 +       res = bcma_chipco_gpio_polarity(&bus->drv_cc, mask, value);
113 +       spin_unlock_irqrestore(&bus->gpio_lock, flags);
114 +
115 +       return res;
116 +}
117 +EXPORT_SYMBOL(bcma_gpio_polarity);
118 +
119 +int bcma_gpio_count(struct bcma_bus *bus)
120 +{
121 +       return BCMA_GPIO_CC_LINES;
122 +}
123 +EXPORT_SYMBOL(bcma_gpio_count);
124 --- a/drivers/bcma/scan.c
125 +++ b/drivers/bcma/scan.c
126 @@ -422,6 +422,10 @@ void bcma_init_bus(struct bcma_bus *bus)
127         if (bus->init_done)
128                 return;
129  
130 +#ifdef CONFIG_BCMA_DRIVER_GPIO
131 +       spin_lock_init(&bus->gpio_lock);
132 +#endif
133 +
134         INIT_LIST_HEAD(&bus->cores);
135         bus->nr_cores = 0;
136  
137 --- a/include/linux/bcma/bcma.h
138 +++ b/include/linux/bcma/bcma.h
139 @@ -255,6 +255,11 @@ struct bcma_bus {
140         struct bcma_drv_mips drv_mips;
141         struct bcma_drv_gmac_cmn drv_gmac_cmn;
142  
143 +#ifdef CONFIG_BCMA_DRIVER_GPIO
144 +       /* Lock for GPIO register access. */
145 +       spinlock_t gpio_lock;
146 +#endif /* CONFIG_BCMA_DRIVER_GPIO */
147 +
148         /* We decided to share SPROM struct with SSB as long as we do not need
149          * any hacks for BCMA. This simplifies drivers code. */
150         struct ssb_sprom sprom;
151 --- /dev/null
152 +++ b/include/linux/bcma/bcma_driver_gpio.h
153 @@ -0,0 +1,17 @@
154 +#ifndef LINUX_BCMA_DRIVER_GPIO_H_
155 +#define LINUX_BCMA_DRIVER_GPIO_H_
156 +
157 +#include <linux/types.h>
158 +#include <linux/bcma/bcma.h>
159 +
160 +#define BCMA_GPIO_CC_LINES     16
161 +
162 +u32 bcma_gpio_in(struct bcma_bus *bus, u32 mask);
163 +u32 bcma_gpio_out(struct bcma_bus *bus, u32 mask, u32 value);
164 +u32 bcma_gpio_outen(struct bcma_bus *bus, u32 mask, u32 value);
165 +u32 bcma_gpio_control(struct bcma_bus *bus, u32 mask, u32 value);
166 +u32 bcma_gpio_intmask(struct bcma_bus *bus, u32 mask, u32 value);
167 +u32 bcma_gpio_polarity(struct bcma_bus *bus, u32 mask, u32 value);
168 +int bcma_gpio_count(struct bcma_bus *bus);
169 +
170 +#endif /* LINUX_BCMA_DRIVER_GPIO_H_ */