1 --- a/drivers/ssb/Kconfig
2 +++ b/drivers/ssb/Kconfig
3 @@ -168,6 +168,7 @@ config SSB_DRIVER_GIGE
6 depends on SSB && GPIOLIB
7 + select IRQ_DOMAIN if SSB_EMBEDDED
9 Driver to provide access to the GPIO pins on the bus.
11 --- a/drivers/ssb/driver_chipcommon_sflash.c
12 +++ b/drivers/ssb/driver_chipcommon_sflash.c
13 @@ -37,7 +37,7 @@ static const struct ssb_sflash_tbl_e ssb
14 { "M25P32", 0x15, 0x10000, 64, },
15 { "M25P64", 0x16, 0x10000, 128, },
16 { "M25FL128", 0x17, 0x10000, 256, },
21 static const struct ssb_sflash_tbl_e ssb_sflash_sst_tbl[] = {
22 @@ -55,7 +55,7 @@ static const struct ssb_sflash_tbl_e ssb
23 { "SST25VF016", 0x41, 0x1000, 512, },
24 { "SST25VF032", 0x4a, 0x1000, 1024, },
25 { "SST25VF064", 0x4b, 0x1000, 2048, },
30 static const struct ssb_sflash_tbl_e ssb_sflash_at_tbl[] = {
31 @@ -66,7 +66,7 @@ static const struct ssb_sflash_tbl_e ssb
32 { "AT45DB161", 0x2c, 512, 4096, },
33 { "AT45DB321", 0x34, 512, 8192, },
34 { "AT45DB642", 0x3c, 1024, 8192, },
39 static void ssb_sflash_cmd(struct ssb_chipcommon *cc, u32 opcode)
40 --- a/drivers/ssb/driver_gpio.c
41 +++ b/drivers/ssb/driver_gpio.c
45 #include <linux/gpio.h>
46 +#include <linux/irq.h>
47 +#include <linux/interrupt.h>
48 +#include <linux/irqdomain.h>
49 #include <linux/export.h>
50 #include <linux/ssb/ssb.h>
52 #include "ssb_private.h"
55 +/**************************************************
57 + **************************************************/
59 static struct ssb_bus *ssb_gpio_get_bus(struct gpio_chip *chip)
61 return container_of(chip, struct ssb_bus, gpio);
64 +#if IS_ENABLED(CONFIG_SSB_EMBEDDED)
65 +static int ssb_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
67 + struct ssb_bus *bus = ssb_gpio_get_bus(chip);
69 + if (bus->bustype == SSB_BUSTYPE_SSB)
70 + return irq_find_mapping(bus->irq_domain, gpio);
76 +/**************************************************
78 + **************************************************/
80 static int ssb_gpio_chipco_get_value(struct gpio_chip *chip, unsigned gpio)
82 struct ssb_bus *bus = ssb_gpio_get_bus(chip);
83 @@ -74,19 +98,129 @@ static void ssb_gpio_chipco_free(struct
84 ssb_chipco_gpio_pullup(&bus->chipco, 1 << gpio, 0);
87 -static int ssb_gpio_chipco_to_irq(struct gpio_chip *chip, unsigned gpio)
88 +#if IS_ENABLED(CONFIG_SSB_EMBEDDED)
89 +static void ssb_gpio_irq_chipco_mask(struct irq_data *d)
91 - struct ssb_bus *bus = ssb_gpio_get_bus(chip);
92 + struct ssb_bus *bus = irq_data_get_irq_chip_data(d);
93 + int gpio = irqd_to_hwirq(d);
95 - if (bus->bustype == SSB_BUSTYPE_SSB)
96 - return ssb_mips_irq(bus->chipco.dev) + 2;
99 + ssb_chipco_gpio_intmask(&bus->chipco, BIT(gpio), 0);
102 +static void ssb_gpio_irq_chipco_unmask(struct irq_data *d)
104 + struct ssb_bus *bus = irq_data_get_irq_chip_data(d);
105 + int gpio = irqd_to_hwirq(d);
106 + u32 val = ssb_chipco_gpio_in(&bus->chipco, BIT(gpio));
108 + ssb_chipco_gpio_polarity(&bus->chipco, BIT(gpio), val);
109 + ssb_chipco_gpio_intmask(&bus->chipco, BIT(gpio), BIT(gpio));
112 +static struct irq_chip ssb_gpio_irq_chipco_chip = {
113 + .name = "SSB-GPIO-CC",
114 + .irq_mask = ssb_gpio_irq_chipco_mask,
115 + .irq_unmask = ssb_gpio_irq_chipco_unmask,
118 +static irqreturn_t ssb_gpio_irq_chipco_handler(int irq, void *dev_id)
120 + struct ssb_bus *bus = dev_id;
121 + struct ssb_chipcommon *chipco = &bus->chipco;
122 + u32 val = chipco_read32(chipco, SSB_CHIPCO_GPIOIN);
123 + u32 mask = chipco_read32(chipco, SSB_CHIPCO_GPIOIRQ);
124 + u32 pol = chipco_read32(chipco, SSB_CHIPCO_GPIOPOL);
125 + unsigned long irqs = (val ^ pol) & mask;
131 + for_each_set_bit(gpio, &irqs, bus->gpio.ngpio)
132 + generic_handle_irq(ssb_gpio_to_irq(&bus->gpio, gpio));
133 + ssb_chipco_gpio_polarity(chipco, irqs, val & irqs);
135 + return IRQ_HANDLED;
138 +static int ssb_gpio_irq_chipco_domain_init(struct ssb_bus *bus)
140 + struct ssb_chipcommon *chipco = &bus->chipco;
141 + struct gpio_chip *chip = &bus->gpio;
142 + int gpio, hwirq, err;
144 + if (bus->bustype != SSB_BUSTYPE_SSB)
147 + bus->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
148 + &irq_domain_simple_ops, chipco);
149 + if (!bus->irq_domain) {
151 + goto err_irq_domain;
153 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
154 + int irq = irq_create_mapping(bus->irq_domain, gpio);
156 + irq_set_chip_data(irq, bus);
157 + irq_set_chip_and_handler(irq, &ssb_gpio_irq_chipco_chip,
158 + handle_simple_irq);
161 + hwirq = ssb_mips_irq(bus->chipco.dev) + 2;
162 + err = request_irq(hwirq, ssb_gpio_irq_chipco_handler, IRQF_SHARED,
167 + ssb_chipco_gpio_intmask(&bus->chipco, ~0, 0);
168 + chipco_set32(chipco, SSB_CHIPCO_IRQMASK, SSB_CHIPCO_IRQ_GPIO);
173 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
174 + int irq = irq_find_mapping(bus->irq_domain, gpio);
176 + irq_dispose_mapping(irq);
178 + irq_domain_remove(bus->irq_domain);
183 +static void ssb_gpio_irq_chipco_domain_exit(struct ssb_bus *bus)
185 + struct ssb_chipcommon *chipco = &bus->chipco;
186 + struct gpio_chip *chip = &bus->gpio;
189 + if (bus->bustype != SSB_BUSTYPE_SSB)
192 + chipco_mask32(chipco, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO);
193 + free_irq(ssb_mips_irq(bus->chipco.dev) + 2, chipco);
194 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
195 + int irq = irq_find_mapping(bus->irq_domain, gpio);
197 + irq_dispose_mapping(irq);
199 + irq_domain_remove(bus->irq_domain);
202 +static int ssb_gpio_irq_chipco_domain_init(struct ssb_bus *bus)
207 +static void ssb_gpio_irq_chipco_domain_exit(struct ssb_bus *bus)
212 static int ssb_gpio_chipco_init(struct ssb_bus *bus)
214 struct gpio_chip *chip = &bus->gpio;
217 chip->label = "ssb_chipco_gpio";
218 chip->owner = THIS_MODULE;
219 @@ -96,7 +230,9 @@ static int ssb_gpio_chipco_init(struct s
220 chip->set = ssb_gpio_chipco_set_value;
221 chip->direction_input = ssb_gpio_chipco_direction_input;
222 chip->direction_output = ssb_gpio_chipco_direction_output;
223 - chip->to_irq = ssb_gpio_chipco_to_irq;
224 +#if IS_ENABLED(CONFIG_SSB_EMBEDDED)
225 + chip->to_irq = ssb_gpio_to_irq;
228 /* There is just one SoC in one device and its GPIO addresses should be
229 * deterministic to address them more easily. The other buses could get
230 @@ -106,9 +242,23 @@ static int ssb_gpio_chipco_init(struct s
234 - return gpiochip_add(chip);
235 + err = ssb_gpio_irq_chipco_domain_init(bus);
239 + err = gpiochip_add(chip);
241 + ssb_gpio_irq_chipco_domain_exit(bus);
248 +/**************************************************
250 + **************************************************/
252 #ifdef CONFIG_SSB_DRIVER_EXTIF
254 static int ssb_gpio_extif_get_value(struct gpio_chip *chip, unsigned gpio)
255 @@ -145,19 +295,127 @@ static int ssb_gpio_extif_direction_outp
259 -static int ssb_gpio_extif_to_irq(struct gpio_chip *chip, unsigned gpio)
260 +#if IS_ENABLED(CONFIG_SSB_EMBEDDED)
261 +static void ssb_gpio_irq_extif_mask(struct irq_data *d)
263 - struct ssb_bus *bus = ssb_gpio_get_bus(chip);
264 + struct ssb_bus *bus = irq_data_get_irq_chip_data(d);
265 + int gpio = irqd_to_hwirq(d);
267 - if (bus->bustype == SSB_BUSTYPE_SSB)
268 - return ssb_mips_irq(bus->extif.dev) + 2;
271 + ssb_extif_gpio_intmask(&bus->extif, BIT(gpio), 0);
274 +static void ssb_gpio_irq_extif_unmask(struct irq_data *d)
276 + struct ssb_bus *bus = irq_data_get_irq_chip_data(d);
277 + int gpio = irqd_to_hwirq(d);
278 + u32 val = ssb_extif_gpio_in(&bus->extif, BIT(gpio));
280 + ssb_extif_gpio_polarity(&bus->extif, BIT(gpio), val);
281 + ssb_extif_gpio_intmask(&bus->extif, BIT(gpio), BIT(gpio));
284 +static struct irq_chip ssb_gpio_irq_extif_chip = {
285 + .name = "SSB-GPIO-EXTIF",
286 + .irq_mask = ssb_gpio_irq_extif_mask,
287 + .irq_unmask = ssb_gpio_irq_extif_unmask,
290 +static irqreturn_t ssb_gpio_irq_extif_handler(int irq, void *dev_id)
292 + struct ssb_bus *bus = dev_id;
293 + struct ssb_extif *extif = &bus->extif;
294 + u32 val = ssb_read32(extif->dev, SSB_EXTIF_GPIO_IN);
295 + u32 mask = ssb_read32(extif->dev, SSB_EXTIF_GPIO_INTMASK);
296 + u32 pol = ssb_read32(extif->dev, SSB_EXTIF_GPIO_INTPOL);
297 + unsigned long irqs = (val ^ pol) & mask;
303 + for_each_set_bit(gpio, &irqs, bus->gpio.ngpio)
304 + generic_handle_irq(ssb_gpio_to_irq(&bus->gpio, gpio));
305 + ssb_extif_gpio_polarity(extif, irqs, val & irqs);
307 + return IRQ_HANDLED;
310 +static int ssb_gpio_irq_extif_domain_init(struct ssb_bus *bus)
312 + struct ssb_extif *extif = &bus->extif;
313 + struct gpio_chip *chip = &bus->gpio;
314 + int gpio, hwirq, err;
316 + if (bus->bustype != SSB_BUSTYPE_SSB)
319 + bus->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
320 + &irq_domain_simple_ops, extif);
321 + if (!bus->irq_domain) {
323 + goto err_irq_domain;
325 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
326 + int irq = irq_create_mapping(bus->irq_domain, gpio);
328 + irq_set_chip_data(irq, bus);
329 + irq_set_chip_and_handler(irq, &ssb_gpio_irq_extif_chip,
330 + handle_simple_irq);
333 + hwirq = ssb_mips_irq(bus->extif.dev) + 2;
334 + err = request_irq(hwirq, ssb_gpio_irq_extif_handler, IRQF_SHARED,
339 + ssb_extif_gpio_intmask(&bus->extif, ~0, 0);
344 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
345 + int irq = irq_find_mapping(bus->irq_domain, gpio);
347 + irq_dispose_mapping(irq);
349 + irq_domain_remove(bus->irq_domain);
354 +static void ssb_gpio_irq_extif_domain_exit(struct ssb_bus *bus)
356 + struct ssb_extif *extif = &bus->extif;
357 + struct gpio_chip *chip = &bus->gpio;
360 + if (bus->bustype != SSB_BUSTYPE_SSB)
363 + free_irq(ssb_mips_irq(bus->extif.dev) + 2, extif);
364 + for (gpio = 0; gpio < chip->ngpio; gpio++) {
365 + int irq = irq_find_mapping(bus->irq_domain, gpio);
367 + irq_dispose_mapping(irq);
369 + irq_domain_remove(bus->irq_domain);
372 +static int ssb_gpio_irq_extif_domain_init(struct ssb_bus *bus)
377 +static void ssb_gpio_irq_extif_domain_exit(struct ssb_bus *bus)
382 static int ssb_gpio_extif_init(struct ssb_bus *bus)
384 struct gpio_chip *chip = &bus->gpio;
387 chip->label = "ssb_extif_gpio";
388 chip->owner = THIS_MODULE;
389 @@ -165,7 +423,9 @@ static int ssb_gpio_extif_init(struct ss
390 chip->set = ssb_gpio_extif_set_value;
391 chip->direction_input = ssb_gpio_extif_direction_input;
392 chip->direction_output = ssb_gpio_extif_direction_output;
393 - chip->to_irq = ssb_gpio_extif_to_irq;
394 +#if IS_ENABLED(CONFIG_SSB_EMBEDDED)
395 + chip->to_irq = ssb_gpio_to_irq;
398 /* There is just one SoC in one device and its GPIO addresses should be
399 * deterministic to address them more easily. The other buses could get
400 @@ -175,7 +435,17 @@ static int ssb_gpio_extif_init(struct ss
404 - return gpiochip_add(chip);
405 + err = ssb_gpio_irq_extif_domain_init(bus);
409 + err = gpiochip_add(chip);
411 + ssb_gpio_irq_extif_domain_exit(bus);
419 @@ -185,6 +455,10 @@ static int ssb_gpio_extif_init(struct ss
423 +/**************************************************
425 + **************************************************/
427 int ssb_gpio_init(struct ssb_bus *bus)
429 if (ssb_chipco_available(&bus->chipco))
430 --- a/drivers/ssb/main.c
431 +++ b/drivers/ssb/main.c
432 @@ -374,7 +374,8 @@ static ssize_t \
433 attrib##_show(struct device *dev, struct device_attribute *attr, char *buf) \
435 return sprintf(buf, format_string, dev_to_ssb_dev(dev)->field); \
438 +static DEVICE_ATTR_RO(attrib);
440 ssb_config_attr(core_num, core_index, "%u\n")
441 ssb_config_attr(coreid, id.coreid, "0x%04x\n")
442 @@ -387,16 +388,18 @@ name_show(struct device *dev, struct dev
443 return sprintf(buf, "%s\n",
444 ssb_core_name(dev_to_ssb_dev(dev)->id.coreid));
446 +static DEVICE_ATTR_RO(name);
448 -static struct device_attribute ssb_device_attrs[] = {
450 - __ATTR_RO(core_num),
453 - __ATTR_RO(revision),
456 +static struct attribute *ssb_device_attrs[] = {
457 + &dev_attr_name.attr,
458 + &dev_attr_core_num.attr,
459 + &dev_attr_coreid.attr,
460 + &dev_attr_vendor.attr,
461 + &dev_attr_revision.attr,
462 + &dev_attr_irq.attr,
465 +ATTRIBUTE_GROUPS(ssb_device);
467 static struct bus_type ssb_bustype = {
469 @@ -407,7 +410,7 @@ static struct bus_type ssb_bustype = {
470 .suspend = ssb_device_suspend,
471 .resume = ssb_device_resume,
472 .uevent = ssb_device_uevent,
473 - .dev_attrs = ssb_device_attrs,
474 + .dev_groups = ssb_device_groups,
477 static void ssb_buses_lock(void)
478 @@ -590,6 +593,13 @@ static int ssb_attach_queued_buses(void)
479 ssb_pcicore_init(&bus->pcicore);
480 if (bus->bustype == SSB_BUSTYPE_SSB)
481 ssb_watchdog_register(bus);
483 + err = ssb_gpio_init(bus);
484 + if (err == -ENOTSUPP)
485 + ssb_dbg("GPIO driver not activated\n");
487 + ssb_dbg("Error registering GPIO driver: %i\n", err);
489 ssb_bus_may_powerdown(bus);
491 err = ssb_devices_register(bus);
492 @@ -827,11 +837,6 @@ static int ssb_bus_register(struct ssb_b
493 ssb_chipcommon_init(&bus->chipco);
494 ssb_extif_init(&bus->extif);
495 ssb_mipscore_init(&bus->mipscore);
496 - err = ssb_gpio_init(bus);
497 - if (err == -ENOTSUPP)
498 - ssb_dbg("GPIO driver not activated\n");
500 - ssb_dbg("Error registering GPIO driver: %i\n", err);
501 err = ssb_fetch_invariants(bus, get_invariants);
503 ssb_bus_may_powerdown(bus);
504 --- a/include/linux/ssb/ssb.h
505 +++ b/include/linux/ssb/ssb.h
506 @@ -33,6 +33,7 @@ struct ssb_sprom {
507 u8 et1phyaddr; /* MII address for enet1 */
508 u8 et0mdcport; /* MDIO for enet0 */
509 u8 et1mdcport; /* MDIO for enet1 */
510 + u16 dev_id; /* Device ID overriding e.g. PCI ID */
511 u16 board_rev; /* Board revision number from SPROM. */
512 u16 board_num; /* Board number from SPROM. */
513 u16 board_type; /* Board type from SPROM. */
514 @@ -486,6 +487,7 @@ struct ssb_bus {
515 #endif /* EMBEDDED */
516 #ifdef CONFIG_SSB_DRIVER_GPIO
517 struct gpio_chip gpio;
518 + struct irq_domain *irq_domain;
519 #endif /* DRIVER_GPIO */
521 /* Internal-only stuff follows. Do not touch. */
522 --- a/include/linux/ssb/ssb_driver_gige.h
523 +++ b/include/linux/ssb/ssb_driver_gige.h
524 @@ -108,6 +108,16 @@ static inline int ssb_gige_get_macaddr(s
528 +/* Get the device phy address */
529 +static inline int ssb_gige_get_phyaddr(struct pci_dev *pdev)
531 + struct ssb_gige *dev = pdev_to_ssb_gige(pdev);
535 + return dev->dev->bus->sprom.et0phyaddr;
538 extern int ssb_gige_pcibios_plat_dev_init(struct ssb_device *sdev,
539 struct pci_dev *pdev);
540 extern int ssb_gige_map_irq(struct ssb_device *sdev,
541 @@ -174,6 +184,10 @@ static inline int ssb_gige_get_macaddr(s
545 +static inline int ssb_gige_get_phyaddr(struct pci_dev *pdev)
550 #endif /* CONFIG_SSB_DRIVER_GIGE */
551 #endif /* LINUX_SSB_DRIVER_GIGE_H_ */
552 --- a/arch/mips/bcm47xx/sprom.c
553 +++ b/arch/mips/bcm47xx/sprom.c
554 @@ -168,6 +168,7 @@ static void nvram_read_alpha2(const char
555 static void bcm47xx_fill_sprom_r1234589(struct ssb_sprom *sprom,
556 const char *prefix, bool fallback)
558 + nvram_read_u16(prefix, NULL, "devid", &sprom->dev_id, 0, fallback);
559 nvram_read_u8(prefix, NULL, "ledbh0", &sprom->gpio0, 0xff, fallback);
560 nvram_read_u8(prefix, NULL, "ledbh1", &sprom->gpio1, 0xff, fallback);
561 nvram_read_u8(prefix, NULL, "ledbh2", &sprom->gpio2, 0xff, fallback);