3aad2a16db0a5358d2cc18b6918ac02b525773b9
[openwrt.git] / target / linux / generic / patches-3.13 / 025-bcma_backport.patch
1 --- a/drivers/bcma/Kconfig
2 +++ b/drivers/bcma/Kconfig
3 @@ -75,6 +75,7 @@ config BCMA_DRIVER_GMAC_CMN
4  config BCMA_DRIVER_GPIO
5         bool "BCMA GPIO driver"
6         depends on BCMA && GPIOLIB
7 +       select IRQ_DOMAIN if BCMA_HOST_SOC
8         help
9           Driver to provide access to the GPIO pins of the bcma bus.
10  
11 --- a/drivers/bcma/bcma_private.h
12 +++ b/drivers/bcma/bcma_private.h
13 @@ -33,8 +33,6 @@ int __init bcma_bus_early_register(struc
14  int bcma_bus_suspend(struct bcma_bus *bus);
15  int bcma_bus_resume(struct bcma_bus *bus);
16  #endif
17 -struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
18 -                                       u8 unit);
19  
20  /* scan.c */
21  int bcma_bus_scan(struct bcma_bus *bus);
22 --- a/drivers/bcma/driver_chipcommon_sflash.c
23 +++ b/drivers/bcma/driver_chipcommon_sflash.c
24 @@ -38,7 +38,7 @@ static const struct bcma_sflash_tbl_e bc
25         { "M25P32", 0x15, 0x10000, 64, },
26         { "M25P64", 0x16, 0x10000, 128, },
27         { "M25FL128", 0x17, 0x10000, 256, },
28 -       { 0 },
29 +       { NULL },
30  };
31  
32  static const struct bcma_sflash_tbl_e bcma_sflash_sst_tbl[] = {
33 @@ -56,7 +56,7 @@ static const struct bcma_sflash_tbl_e bc
34         { "SST25VF016", 0x41, 0x1000, 512, },
35         { "SST25VF032", 0x4a, 0x1000, 1024, },
36         { "SST25VF064", 0x4b, 0x1000, 2048, },
37 -       { 0 },
38 +       { NULL },
39  };
40  
41  static const struct bcma_sflash_tbl_e bcma_sflash_at_tbl[] = {
42 @@ -67,7 +67,7 @@ static const struct bcma_sflash_tbl_e bc
43         { "AT45DB161", 0x2c, 512, 4096, },
44         { "AT45DB321", 0x34, 512, 8192, },
45         { "AT45DB642", 0x3c, 1024, 8192, },
46 -       { 0 },
47 +       { NULL },
48  };
49  
50  static void bcma_sflash_cmd(struct bcma_drv_cc *cc, u32 opcode)
51 --- a/drivers/bcma/driver_gpio.c
52 +++ b/drivers/bcma/driver_gpio.c
53 @@ -9,6 +9,9 @@
54   */
55  
56  #include <linux/gpio.h>
57 +#include <linux/irq.h>
58 +#include <linux/interrupt.h>
59 +#include <linux/irqdomain.h>
60  #include <linux/export.h>
61  #include <linux/bcma/bcma.h>
62  
63 @@ -73,19 +76,136 @@ static void bcma_gpio_free(struct gpio_c
64         bcma_chipco_gpio_pullup(cc, 1 << gpio, 0);
65  }
66  
67 +#if IS_BUILTIN(CONFIG_BCMA_HOST_SOC)
68  static int bcma_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
69  {
70         struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
71  
72         if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
73 -               return bcma_core_irq(cc->core);
74 +               return irq_find_mapping(cc->irq_domain, gpio);
75         else
76                 return -EINVAL;
77  }
78  
79 +static void bcma_gpio_irq_unmask(struct irq_data *d)
80 +{
81 +       struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
82 +       int gpio = irqd_to_hwirq(d);
83 +       u32 val = bcma_chipco_gpio_in(cc, BIT(gpio));
84 +
85 +       bcma_chipco_gpio_polarity(cc, BIT(gpio), val);
86 +       bcma_chipco_gpio_intmask(cc, BIT(gpio), BIT(gpio));
87 +}
88 +
89 +static void bcma_gpio_irq_mask(struct irq_data *d)
90 +{
91 +       struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
92 +       int gpio = irqd_to_hwirq(d);
93 +
94 +       bcma_chipco_gpio_intmask(cc, BIT(gpio), 0);
95 +}
96 +
97 +static struct irq_chip bcma_gpio_irq_chip = {
98 +       .name           = "BCMA-GPIO",
99 +       .irq_mask       = bcma_gpio_irq_mask,
100 +       .irq_unmask     = bcma_gpio_irq_unmask,
101 +};
102 +
103 +static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
104 +{
105 +       struct bcma_drv_cc *cc = dev_id;
106 +       u32 val = bcma_cc_read32(cc, BCMA_CC_GPIOIN);
107 +       u32 mask = bcma_cc_read32(cc, BCMA_CC_GPIOIRQ);
108 +       u32 pol = bcma_cc_read32(cc, BCMA_CC_GPIOPOL);
109 +       unsigned long irqs = (val ^ pol) & mask;
110 +       int gpio;
111 +
112 +       if (!irqs)
113 +               return IRQ_NONE;
114 +
115 +       for_each_set_bit(gpio, &irqs, cc->gpio.ngpio)
116 +               generic_handle_irq(bcma_gpio_to_irq(&cc->gpio, gpio));
117 +       bcma_chipco_gpio_polarity(cc, irqs, val & irqs);
118 +
119 +       return IRQ_HANDLED;
120 +}
121 +
122 +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
123 +{
124 +       struct gpio_chip *chip = &cc->gpio;
125 +       int gpio, hwirq, err;
126 +
127 +       if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
128 +               return 0;
129 +
130 +       cc->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
131 +                                              &irq_domain_simple_ops, cc);
132 +       if (!cc->irq_domain) {
133 +               err = -ENODEV;
134 +               goto err_irq_domain;
135 +       }
136 +       for (gpio = 0; gpio < chip->ngpio; gpio++) {
137 +               int irq = irq_create_mapping(cc->irq_domain, gpio);
138 +
139 +               irq_set_chip_data(irq, cc);
140 +               irq_set_chip_and_handler(irq, &bcma_gpio_irq_chip,
141 +                                        handle_simple_irq);
142 +       }
143 +
144 +       hwirq = bcma_core_irq(cc->core);
145 +       err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
146 +                         cc);
147 +       if (err)
148 +               goto err_req_irq;
149 +
150 +       bcma_chipco_gpio_intmask(cc, ~0, 0);
151 +       bcma_cc_set32(cc, BCMA_CC_IRQMASK, BCMA_CC_IRQ_GPIO);
152 +
153 +       return 0;
154 +
155 +err_req_irq:
156 +       for (gpio = 0; gpio < chip->ngpio; gpio++) {
157 +               int irq = irq_find_mapping(cc->irq_domain, gpio);
158 +
159 +               irq_dispose_mapping(irq);
160 +       }
161 +       irq_domain_remove(cc->irq_domain);
162 +err_irq_domain:
163 +       return err;
164 +}
165 +
166 +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
167 +{
168 +       struct gpio_chip *chip = &cc->gpio;
169 +       int gpio;
170 +
171 +       if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
172 +               return;
173 +
174 +       bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO);
175 +       free_irq(bcma_core_irq(cc->core), cc);
176 +       for (gpio = 0; gpio < chip->ngpio; gpio++) {
177 +               int irq = irq_find_mapping(cc->irq_domain, gpio);
178 +
179 +               irq_dispose_mapping(irq);
180 +       }
181 +       irq_domain_remove(cc->irq_domain);
182 +}
183 +#else
184 +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
185 +{
186 +       return 0;
187 +}
188 +
189 +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
190 +{
191 +}
192 +#endif
193 +
194  int bcma_gpio_init(struct bcma_drv_cc *cc)
195  {
196         struct gpio_chip *chip = &cc->gpio;
197 +       int err;
198  
199         chip->label             = "bcma_gpio";
200         chip->owner             = THIS_MODULE;
201 @@ -95,7 +215,9 @@ int bcma_gpio_init(struct bcma_drv_cc *c
202         chip->set               = bcma_gpio_set_value;
203         chip->direction_input   = bcma_gpio_direction_input;
204         chip->direction_output  = bcma_gpio_direction_output;
205 +#if IS_BUILTIN(CONFIG_BCMA_HOST_SOC)
206         chip->to_irq            = bcma_gpio_to_irq;
207 +#endif
208         chip->ngpio             = 16;
209         /* There is just one SoC in one device and its GPIO addresses should be
210          * deterministic to address them more easily. The other buses could get
211 @@ -105,10 +227,21 @@ int bcma_gpio_init(struct bcma_drv_cc *c
212         else
213                 chip->base              = -1;
214  
215 -       return gpiochip_add(chip);
216 +       err = bcma_gpio_irq_domain_init(cc);
217 +       if (err)
218 +               return err;
219 +
220 +       err = gpiochip_add(chip);
221 +       if (err) {
222 +               bcma_gpio_irq_domain_exit(cc);
223 +               return err;
224 +       }
225 +
226 +       return 0;
227  }
228  
229  int bcma_gpio_unregister(struct bcma_drv_cc *cc)
230  {
231 +       bcma_gpio_irq_domain_exit(cc);
232         return gpiochip_remove(&cc->gpio);
233  }
234 --- a/drivers/bcma/host_pci.c
235 +++ b/drivers/bcma/host_pci.c
236 @@ -238,7 +238,6 @@ static void bcma_host_pci_remove(struct
237         pci_release_regions(dev);
238         pci_disable_device(dev);
239         kfree(bus);
240 -       pci_set_drvdata(dev, NULL);
241  }
242  
243  #ifdef CONFIG_PM_SLEEP
244 @@ -270,7 +269,7 @@ static SIMPLE_DEV_PM_OPS(bcma_pm_ops, bc
245  
246  #endif /* CONFIG_PM_SLEEP */
247  
248 -static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
249 +static const struct pci_device_id bcma_pci_bridge_tbl[] = {
250         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
251         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4313) },
252         { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 43224) },
253 --- a/drivers/bcma/main.c
254 +++ b/drivers/bcma/main.c
255 @@ -78,18 +78,6 @@ static u16 bcma_cc_core_id(struct bcma_b
256         return BCMA_CORE_CHIPCOMMON;
257  }
258  
259 -struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
260 -{
261 -       struct bcma_device *core;
262 -
263 -       list_for_each_entry(core, &bus->cores, list) {
264 -               if (core->id.id == coreid)
265 -                       return core;
266 -       }
267 -       return NULL;
268 -}
269 -EXPORT_SYMBOL_GPL(bcma_find_core);
270 -
271  struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
272                                         u8 unit)
273  {
274 @@ -101,6 +89,7 @@ struct bcma_device *bcma_find_core_unit(
275         }
276         return NULL;
277  }
278 +EXPORT_SYMBOL_GPL(bcma_find_core_unit);
279  
280  bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
281                      int timeout)
282 @@ -176,6 +165,7 @@ static int bcma_register_cores(struct bc
283                         bcma_err(bus,
284                                  "Could not register dev for core 0x%03X\n",
285                                  core->id.id);
286 +                       put_device(&core->dev);
287                         continue;
288                 }
289                 core->dev_registered = true;
290 --- a/include/linux/bcma/bcma.h
291 +++ b/include/linux/bcma/bcma.h
292 @@ -418,7 +418,14 @@ static inline void bcma_maskset16(struct
293         bcma_write16(cc, offset, (bcma_read16(cc, offset) & mask) | set);
294  }
295  
296 -extern struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid);
297 +extern struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
298 +                                              u8 unit);
299 +static inline struct bcma_device *bcma_find_core(struct bcma_bus *bus,
300 +                                                u16 coreid)
301 +{
302 +       return bcma_find_core_unit(bus, coreid, 0);
303 +}
304 +
305  extern bool bcma_core_is_enabled(struct bcma_device *core);
306  extern void bcma_core_disable(struct bcma_device *core, u32 flags);
307  extern int bcma_core_enable(struct bcma_device *core, u32 flags);
308 --- a/include/linux/bcma/bcma_driver_chipcommon.h
309 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
310 @@ -640,6 +640,7 @@ struct bcma_drv_cc {
311         spinlock_t gpio_lock;
312  #ifdef CONFIG_BCMA_DRIVER_GPIO
313         struct gpio_chip gpio;
314 +       struct irq_domain *irq_domain;
315  #endif
316  };
317