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
9 Driver to provide access to the GPIO pins of the bcma bus.
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);
17 -struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
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, },
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, },
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, },
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
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>
63 @@ -73,19 +76,136 @@ static void bcma_gpio_free(struct gpio_c
64 bcma_chipco_gpio_pullup(cc, 1 << gpio, 0);
67 +#if IS_BUILTIN(CONFIG_BCMA_HOST_SOC)
68 static int bcma_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
70 struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
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);
79 +static void bcma_gpio_irq_unmask(struct irq_data *d)
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));
85 + bcma_chipco_gpio_polarity(cc, BIT(gpio), val);
86 + bcma_chipco_gpio_intmask(cc, BIT(gpio), BIT(gpio));
89 +static void bcma_gpio_irq_mask(struct irq_data *d)
91 + struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
92 + int gpio = irqd_to_hwirq(d);
94 + bcma_chipco_gpio_intmask(cc, BIT(gpio), 0);
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,
103 +static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
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;
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);
119 + return IRQ_HANDLED;
122 +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
124 + struct gpio_chip *chip = &cc->gpio;
125 + int gpio, hwirq, err;
127 + if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
130 + cc->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
131 + &irq_domain_simple_ops, cc);
132 + if (!cc->irq_domain) {
134 + goto err_irq_domain;
136 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
137 + int irq = irq_create_mapping(cc->irq_domain, gpio);
139 + irq_set_chip_data(irq, cc);
140 + irq_set_chip_and_handler(irq, &bcma_gpio_irq_chip,
141 + handle_simple_irq);
144 + hwirq = bcma_core_irq(cc->core);
145 + err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
150 + bcma_chipco_gpio_intmask(cc, ~0, 0);
151 + bcma_cc_set32(cc, BCMA_CC_IRQMASK, BCMA_CC_IRQ_GPIO);
156 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
157 + int irq = irq_find_mapping(cc->irq_domain, gpio);
159 + irq_dispose_mapping(irq);
161 + irq_domain_remove(cc->irq_domain);
166 +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
168 + struct gpio_chip *chip = &cc->gpio;
171 + if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
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);
179 + irq_dispose_mapping(irq);
181 + irq_domain_remove(cc->irq_domain);
184 +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
189 +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
194 int bcma_gpio_init(struct bcma_drv_cc *cc)
196 struct gpio_chip *chip = &cc->gpio;
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;
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
215 - return gpiochip_add(chip);
216 + err = bcma_gpio_irq_domain_init(cc);
220 + err = gpiochip_add(chip);
222 + bcma_gpio_irq_domain_exit(cc);
229 int bcma_gpio_unregister(struct bcma_drv_cc *cc)
231 + bcma_gpio_irq_domain_exit(cc);
232 return gpiochip_remove(&cc->gpio);
234 --- a/drivers/bcma/host_pci.c
235 +++ b/drivers/bcma/host_pci.c
236 @@ -188,8 +188,11 @@ static int bcma_host_pci_probe(struct pc
237 pci_write_config_dword(dev, 0x40, val & 0xffff00ff);
239 /* SSB needed additional powering up, do we have any AMBA PCI cards? */
240 - if (!pci_is_pcie(dev))
241 - bcma_err(bus, "PCI card detected, report problems.\n");
242 + if (!pci_is_pcie(dev)) {
243 + bcma_err(bus, "PCI card detected, they are not supported.\n");
245 + goto err_pci_release_regions;
250 @@ -235,7 +238,6 @@ static void bcma_host_pci_remove(struct
251 pci_release_regions(dev);
252 pci_disable_device(dev);
254 - pci_set_drvdata(dev, NULL);
257 #ifdef CONFIG_PM_SLEEP
258 @@ -267,8 +269,9 @@ static SIMPLE_DEV_PM_OPS(bcma_pm_ops, bc
260 #endif /* CONFIG_PM_SLEEP */
262 -static DEFINE_PCI_DEVICE_TABLE(bcma_pci_bridge_tbl) = {
263 +static const struct pci_device_id bcma_pci_bridge_tbl[] = {
264 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) },
265 + { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4313) },
266 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 43224) },
267 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4331) },
268 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) },
269 --- a/drivers/bcma/main.c
270 +++ b/drivers/bcma/main.c
271 @@ -30,28 +30,37 @@ static ssize_t manuf_show(struct device
272 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
273 return sprintf(buf, "0x%03X\n", core->id.manuf);
275 +static DEVICE_ATTR_RO(manuf);
277 static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf)
279 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
280 return sprintf(buf, "0x%03X\n", core->id.id);
282 +static DEVICE_ATTR_RO(id);
284 static ssize_t rev_show(struct device *dev, struct device_attribute *attr, char *buf)
286 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
287 return sprintf(buf, "0x%02X\n", core->id.rev);
289 +static DEVICE_ATTR_RO(rev);
291 static ssize_t class_show(struct device *dev, struct device_attribute *attr, char *buf)
293 struct bcma_device *core = container_of(dev, struct bcma_device, dev);
294 return sprintf(buf, "0x%X\n", core->id.class);
296 -static struct device_attribute bcma_device_attrs[] = {
302 +static DEVICE_ATTR_RO(class);
304 +static struct attribute *bcma_device_attrs[] = {
305 + &dev_attr_manuf.attr,
307 + &dev_attr_rev.attr,
308 + &dev_attr_class.attr,
311 +ATTRIBUTE_GROUPS(bcma_device);
313 static struct bus_type bcma_bus_type = {
315 @@ -59,7 +68,7 @@ static struct bus_type bcma_bus_type = {
316 .probe = bcma_device_probe,
317 .remove = bcma_device_remove,
318 .uevent = bcma_device_uevent,
319 - .dev_attrs = bcma_device_attrs,
320 + .dev_groups = bcma_device_groups,
323 static u16 bcma_cc_core_id(struct bcma_bus *bus)
324 @@ -69,18 +78,6 @@ static u16 bcma_cc_core_id(struct bcma_b
325 return BCMA_CORE_CHIPCOMMON;
328 -struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid)
330 - struct bcma_device *core;
332 - list_for_each_entry(core, &bus->cores, list) {
333 - if (core->id.id == coreid)
338 -EXPORT_SYMBOL_GPL(bcma_find_core);
340 struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
343 @@ -92,6 +89,7 @@ struct bcma_device *bcma_find_core_unit(
347 +EXPORT_SYMBOL_GPL(bcma_find_core_unit);
349 bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
351 @@ -167,6 +165,7 @@ static int bcma_register_cores(struct bc
353 "Could not register dev for core 0x%03X\n",
355 + put_device(&core->dev);
358 core->dev_registered = true;
359 --- a/include/linux/bcma/bcma.h
360 +++ b/include/linux/bcma/bcma.h
361 @@ -418,7 +418,14 @@ static inline void bcma_maskset16(struct
362 bcma_write16(cc, offset, (bcma_read16(cc, offset) & mask) | set);
365 -extern struct bcma_device *bcma_find_core(struct bcma_bus *bus, u16 coreid);
366 +extern struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid,
368 +static inline struct bcma_device *bcma_find_core(struct bcma_bus *bus,
371 + return bcma_find_core_unit(bus, coreid, 0);
374 extern bool bcma_core_is_enabled(struct bcma_device *core);
375 extern void bcma_core_disable(struct bcma_device *core, u32 flags);
376 extern int bcma_core_enable(struct bcma_device *core, u32 flags);
377 --- a/include/linux/bcma/bcma_driver_chipcommon.h
378 +++ b/include/linux/bcma/bcma_driver_chipcommon.h
379 @@ -640,6 +640,7 @@ struct bcma_drv_cc {
380 spinlock_t gpio_lock;
381 #ifdef CONFIG_BCMA_DRIVER_GPIO
382 struct gpio_chip gpio;
383 + struct irq_domain *irq_domain;