ramips: fix cd-poll sd card remove randomly
[openwrt/staging/chunkeey.git] / target / linux / generic / patches-3.18 / 025-bcma_backport.patch
1 --- a/drivers/bcma/bcma_private.h
2 +++ b/drivers/bcma/bcma_private.h
3 @@ -22,6 +22,7 @@ struct bcma_bus;
4 /* main.c */
5 bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
6 int timeout);
7 +void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core);
8 int bcma_bus_register(struct bcma_bus *bus);
9 void bcma_bus_unregister(struct bcma_bus *bus);
10 int __init bcma_bus_early_register(struct bcma_bus *bus,
11 --- a/drivers/bcma/driver_chipcommon.c
12 +++ b/drivers/bcma/driver_chipcommon.c
13 @@ -339,7 +339,7 @@ void bcma_chipco_serial_init(struct bcma
14 return;
15 }
16
17 - irq = bcma_core_irq(cc->core);
18 + irq = bcma_core_irq(cc->core, 0);
19
20 /* Determine the registers of the UARTs */
21 cc->nr_serial_ports = (cc->capabilities & BCMA_CC_CAP_NRUART);
22 --- a/drivers/bcma/driver_gpio.c
23 +++ b/drivers/bcma/driver_gpio.c
24 @@ -152,7 +152,7 @@ static int bcma_gpio_irq_domain_init(str
25 handle_simple_irq);
26 }
27
28 - hwirq = bcma_core_irq(cc->core);
29 + hwirq = bcma_core_irq(cc->core, 0);
30 err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
31 cc);
32 if (err)
33 @@ -183,7 +183,7 @@ static void bcma_gpio_irq_domain_exit(st
34 return;
35
36 bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO);
37 - free_irq(bcma_core_irq(cc->core), cc);
38 + free_irq(bcma_core_irq(cc->core, 0), cc);
39 for (gpio = 0; gpio < chip->ngpio; gpio++) {
40 int irq = irq_find_mapping(cc->irq_domain, gpio);
41
42 --- a/drivers/bcma/driver_mips.c
43 +++ b/drivers/bcma/driver_mips.c
44 @@ -115,7 +115,7 @@ static u32 bcma_core_mips_irqflag(struct
45 * If disabled, 5 is returned.
46 * If not supported, 6 is returned.
47 */
48 -static unsigned int bcma_core_mips_irq(struct bcma_device *dev)
49 +unsigned int bcma_core_mips_irq(struct bcma_device *dev)
50 {
51 struct bcma_device *mdev = dev->bus->drv_mips.core;
52 u32 irqflag;
53 @@ -133,13 +133,6 @@ static unsigned int bcma_core_mips_irq(s
54 return 5;
55 }
56
57 -unsigned int bcma_core_irq(struct bcma_device *dev)
58 -{
59 - unsigned int mips_irq = bcma_core_mips_irq(dev);
60 - return mips_irq <= 4 ? mips_irq + 2 : 0;
61 -}
62 -EXPORT_SYMBOL(bcma_core_irq);
63 -
64 static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
65 {
66 unsigned int oldirq = bcma_core_mips_irq(dev);
67 @@ -423,7 +416,7 @@ void bcma_core_mips_init(struct bcma_drv
68 break;
69 default:
70 list_for_each_entry(core, &bus->cores, list) {
71 - core->irq = bcma_core_irq(core);
72 + core->irq = bcma_core_irq(core, 0);
73 }
74 bcma_err(bus,
75 "Unknown device (0x%x) found, can not configure IRQs\n",
76 --- a/drivers/bcma/driver_pci_host.c
77 +++ b/drivers/bcma/driver_pci_host.c
78 @@ -593,7 +593,7 @@ int bcma_core_pci_plat_dev_init(struct p
79 pr_info("PCI: Fixing up device %s\n", pci_name(dev));
80
81 /* Fix up interrupt lines */
82 - dev->irq = bcma_core_irq(pc_host->pdev->core);
83 + dev->irq = bcma_core_irq(pc_host->pdev->core, 0);
84 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
85
86 readrq = pcie_get_readrq(dev);
87 @@ -617,6 +617,6 @@ int bcma_core_pci_pcibios_map_irq(const
88
89 pc_host = container_of(dev->bus->ops, struct bcma_drv_pci_host,
90 pci_ops);
91 - return bcma_core_irq(pc_host->pdev->core);
92 + return bcma_core_irq(pc_host->pdev->core, 0);
93 }
94 EXPORT_SYMBOL(bcma_core_pci_pcibios_map_irq);
95 --- a/drivers/bcma/main.c
96 +++ b/drivers/bcma/main.c
97 @@ -11,6 +11,7 @@
98 #include <linux/bcma/bcma.h>
99 #include <linux/slab.h>
100 #include <linux/of_address.h>
101 +#include <linux/of_irq.h>
102
103 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
104 MODULE_LICENSE("GPL");
105 @@ -153,6 +154,46 @@ static struct device_node *bcma_of_find_
106 return NULL;
107 }
108
109 +static int bcma_of_irq_parse(struct platform_device *parent,
110 + struct bcma_device *core,
111 + struct of_phandle_args *out_irq, int num)
112 +{
113 + __be32 laddr[1];
114 + int rc;
115 +
116 + if (core->dev.of_node) {
117 + rc = of_irq_parse_one(core->dev.of_node, num, out_irq);
118 + if (!rc)
119 + return rc;
120 + }
121 +
122 + out_irq->np = parent->dev.of_node;
123 + out_irq->args_count = 1;
124 + out_irq->args[0] = num;
125 +
126 + laddr[0] = cpu_to_be32(core->addr);
127 + return of_irq_parse_raw(laddr, out_irq);
128 +}
129 +
130 +static unsigned int bcma_of_get_irq(struct platform_device *parent,
131 + struct bcma_device *core, int num)
132 +{
133 + struct of_phandle_args out_irq;
134 + int ret;
135 +
136 + if (!parent || !parent->dev.of_node)
137 + return 0;
138 +
139 + ret = bcma_of_irq_parse(parent, core, &out_irq, num);
140 + if (ret) {
141 + bcma_debug(core->bus, "bcma_of_get_irq() failed with rc=%d\n",
142 + ret);
143 + return 0;
144 + }
145 +
146 + return irq_create_of_mapping(&out_irq);
147 +}
148 +
149 static void bcma_of_fill_device(struct platform_device *parent,
150 struct bcma_device *core)
151 {
152 @@ -161,18 +202,47 @@ static void bcma_of_fill_device(struct p
153 node = bcma_of_find_child_device(parent, core);
154 if (node)
155 core->dev.of_node = node;
156 +
157 + core->irq = bcma_of_get_irq(parent, core, 0);
158 }
159 #else
160 static void bcma_of_fill_device(struct platform_device *parent,
161 struct bcma_device *core)
162 {
163 }
164 +static inline unsigned int bcma_of_get_irq(struct platform_device *parent,
165 + struct bcma_device *core, int num)
166 +{
167 + return 0;
168 +}
169 #endif /* CONFIG_OF */
170
171 -static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
172 +unsigned int bcma_core_irq(struct bcma_device *core, int num)
173 {
174 - int err;
175 + struct bcma_bus *bus = core->bus;
176 + unsigned int mips_irq;
177 +
178 + switch (bus->hosttype) {
179 + case BCMA_HOSTTYPE_PCI:
180 + return bus->host_pci->irq;
181 + case BCMA_HOSTTYPE_SOC:
182 + if (bus->drv_mips.core && num == 0) {
183 + mips_irq = bcma_core_mips_irq(core);
184 + return mips_irq <= 4 ? mips_irq + 2 : 0;
185 + }
186 + if (bus->host_pdev)
187 + return bcma_of_get_irq(bus->host_pdev, core, num);
188 + return 0;
189 + case BCMA_HOSTTYPE_SDIO:
190 + return 0;
191 + }
192
193 + return 0;
194 +}
195 +EXPORT_SYMBOL(bcma_core_irq);
196 +
197 +void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core)
198 +{
199 core->dev.release = bcma_release_core_dev;
200 core->dev.bus = &bcma_bus_type;
201 dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index);
202 @@ -196,6 +266,11 @@ static void bcma_register_core(struct bc
203 case BCMA_HOSTTYPE_SDIO:
204 break;
205 }
206 +}
207 +
208 +static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
209 +{
210 + int err;
211
212 err = device_register(&core->dev);
213 if (err) {
214 --- a/drivers/bcma/scan.c
215 +++ b/drivers/bcma/scan.c
216 @@ -505,6 +505,7 @@ int bcma_bus_scan(struct bcma_bus *bus)
217 bus->nr_cores++;
218 other_core = bcma_find_core_reverse(bus, core->id.id);
219 core->core_unit = (other_core == NULL) ? 0 : other_core->core_unit + 1;
220 + bcma_prepare_core(bus, core);
221
222 bcma_info(bus, "Core %d found: %s (manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
223 core->core_index, bcma_device_name(&core->id),
224 --- a/include/linux/bcma/bcma.h
225 +++ b/include/linux/bcma/bcma.h
226 @@ -448,4 +448,6 @@ extern u32 bcma_chipco_pll_read(struct b
227 #define BCMA_DMA_TRANSLATION_DMA64_CMT 0x80000000 /* Client Mode Translation for 64-bit DMA */
228 extern u32 bcma_core_dma_translation(struct bcma_device *core);
229
230 +extern unsigned int bcma_core_irq(struct bcma_device *core, int num);
231 +
232 #endif /* LINUX_BCMA_H_ */
233 --- a/include/linux/bcma/bcma_driver_mips.h
234 +++ b/include/linux/bcma/bcma_driver_mips.h
235 @@ -43,12 +43,12 @@ struct bcma_drv_mips {
236 extern void bcma_core_mips_init(struct bcma_drv_mips *mcore);
237 extern void bcma_core_mips_early_init(struct bcma_drv_mips *mcore);
238
239 -extern unsigned int bcma_core_irq(struct bcma_device *core);
240 +extern unsigned int bcma_core_mips_irq(struct bcma_device *dev);
241 #else
242 static inline void bcma_core_mips_init(struct bcma_drv_mips *mcore) { }
243 static inline void bcma_core_mips_early_init(struct bcma_drv_mips *mcore) { }
244
245 -static inline unsigned int bcma_core_irq(struct bcma_device *core)
246 +static inline unsigned int bcma_core_mips_irq(struct bcma_device *dev)
247 {
248 return 0;
249 }
250 --- a/Documentation/devicetree/bindings/bus/bcma.txt
251 +++ b/Documentation/devicetree/bindings/bus/bcma.txt
252 @@ -8,6 +8,11 @@ Required properties:
253
254 The cores on the AXI bus are automatically detected by bcma with the
255 memory ranges they are using and they get registered afterwards.
256 +Automatic detection of the IRQ number is not working on
257 +BCM47xx/BCM53xx ARM SoCs. To assign IRQ numbers to the cores, provide
258 +them manually through device tree. Use an interrupt-map to specify the
259 +IRQ used by the devices on the bus. The first address is just an index,
260 +because we do not have any special register.
261
262 The top-level axi bus may contain children representing attached cores
263 (devices). This is needed since some hardware details can't be auto
264 @@ -22,6 +27,22 @@ Example:
265 ranges = <0x00000000 0x18000000 0x00100000>;
266 #address-cells = <1>;
267 #size-cells = <1>;
268 + #interrupt-cells = <1>;
269 + interrupt-map-mask = <0x000fffff 0xffff>;
270 + interrupt-map =
271 + /* Ethernet Controller 0 */
272 + <0x00024000 0 &gic GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
273 +
274 + /* Ethernet Controller 1 */
275 + <0x00025000 0 &gic GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
276 +
277 + /* PCIe Controller 0 */
278 + <0x00012000 0 &gic GIC_SPI 126 IRQ_TYPE_LEVEL_HIGH>,
279 + <0x00012000 1 &gic GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>,
280 + <0x00012000 2 &gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH>,
281 + <0x00012000 3 &gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH>,
282 + <0x00012000 4 &gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>,
283 + <0x00012000 5 &gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
284
285 chipcommon {
286 reg = <0x00000000 0x1000>;