Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Broadcom specific AMBA |
| 3 | * Bus subsystem |
| 4 | * |
| 5 | * Licensed under the GNU/GPL. See COPYING for details. |
| 6 | */ |
| 7 | |
| 8 | #include "bcma_private.h" |
Paul Gortmaker | 200351c | 2011-07-01 16:06:37 -0400 | [diff] [blame] | 9 | #include <linux/module.h> |
Rafał Miłecki | d57ef3a | 2012-08-10 21:23:53 +0200 | [diff] [blame] | 10 | #include <linux/platform_device.h> |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 11 | #include <linux/bcma/bcma.h> |
Geert Uytterhoeven | eef7269 | 2011-06-26 10:19:44 +0200 | [diff] [blame] | 12 | #include <linux/slab.h> |
Hauke Mehrtens | 2101e53 | 2014-09-26 00:09:19 +0200 | [diff] [blame] | 13 | #include <linux/of_address.h> |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 14 | |
| 15 | MODULE_DESCRIPTION("Broadcom's specific AMBA driver"); |
| 16 | MODULE_LICENSE("GPL"); |
| 17 | |
Hauke Mehrtens | 8f9ada4 | 2012-01-31 00:03:36 +0100 | [diff] [blame] | 18 | /* contains the number the next bus should get. */ |
| 19 | static unsigned int bcma_bus_next_num = 0; |
| 20 | |
| 21 | /* bcma_buses_mutex locks the bcma_bus_next_num */ |
| 22 | static DEFINE_MUTEX(bcma_buses_mutex); |
| 23 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 24 | static int bcma_bus_match(struct device *dev, struct device_driver *drv); |
| 25 | static int bcma_device_probe(struct device *dev); |
| 26 | static int bcma_device_remove(struct device *dev); |
David Woodhouse | 886b66e | 2011-08-19 22:14:47 +0200 | [diff] [blame] | 27 | static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 28 | |
| 29 | static ssize_t manuf_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 30 | { |
| 31 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 32 | return sprintf(buf, "0x%03X\n", core->id.manuf); |
| 33 | } |
Greg Kroah-Hartman | fdcf4f8 | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 34 | static DEVICE_ATTR_RO(manuf); |
| 35 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 36 | static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 37 | { |
| 38 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 39 | return sprintf(buf, "0x%03X\n", core->id.id); |
| 40 | } |
Greg Kroah-Hartman | fdcf4f8 | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 41 | static DEVICE_ATTR_RO(id); |
| 42 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 43 | static ssize_t rev_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 44 | { |
| 45 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 46 | return sprintf(buf, "0x%02X\n", core->id.rev); |
| 47 | } |
Greg Kroah-Hartman | fdcf4f8 | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 48 | static DEVICE_ATTR_RO(rev); |
| 49 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 50 | static ssize_t class_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 51 | { |
| 52 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 53 | return sprintf(buf, "0x%X\n", core->id.class); |
| 54 | } |
Greg Kroah-Hartman | fdcf4f8 | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 55 | static DEVICE_ATTR_RO(class); |
| 56 | |
| 57 | static struct attribute *bcma_device_attrs[] = { |
| 58 | &dev_attr_manuf.attr, |
| 59 | &dev_attr_id.attr, |
| 60 | &dev_attr_rev.attr, |
| 61 | &dev_attr_class.attr, |
| 62 | NULL, |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 63 | }; |
Greg Kroah-Hartman | fdcf4f8 | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 64 | ATTRIBUTE_GROUPS(bcma_device); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 65 | |
| 66 | static struct bus_type bcma_bus_type = { |
| 67 | .name = "bcma", |
| 68 | .match = bcma_bus_match, |
| 69 | .probe = bcma_device_probe, |
| 70 | .remove = bcma_device_remove, |
David Woodhouse | 886b66e | 2011-08-19 22:14:47 +0200 | [diff] [blame] | 71 | .uevent = bcma_device_uevent, |
Greg Kroah-Hartman | fdcf4f8 | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 72 | .dev_groups = bcma_device_groups, |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Rafał Miłecki | 6d5cfc9 | 2012-07-10 23:45:49 +0200 | [diff] [blame] | 75 | static u16 bcma_cc_core_id(struct bcma_bus *bus) |
| 76 | { |
| 77 | if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) |
| 78 | return BCMA_CORE_4706_CHIPCOMMON; |
| 79 | return BCMA_CORE_CHIPCOMMON; |
| 80 | } |
| 81 | |
Hauke Mehrtens | 929a03a | 2013-01-04 00:51:20 +0100 | [diff] [blame] | 82 | struct bcma_device *bcma_find_core_unit(struct bcma_bus *bus, u16 coreid, |
| 83 | u8 unit) |
Hauke Mehrtens | dfae714 | 2012-09-29 20:40:18 +0200 | [diff] [blame] | 84 | { |
| 85 | struct bcma_device *core; |
| 86 | |
| 87 | list_for_each_entry(core, &bus->cores, list) { |
| 88 | if (core->id.id == coreid && core->core_unit == unit) |
| 89 | return core; |
| 90 | } |
| 91 | return NULL; |
| 92 | } |
Hauke Mehrtens | b2395b8 | 2014-01-05 01:10:43 +0100 | [diff] [blame] | 93 | EXPORT_SYMBOL_GPL(bcma_find_core_unit); |
Hauke Mehrtens | dfae714 | 2012-09-29 20:40:18 +0200 | [diff] [blame] | 94 | |
Rafał Miłecki | 88f9b65 | 2013-06-26 10:02:11 +0200 | [diff] [blame] | 95 | bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value, |
| 96 | int timeout) |
| 97 | { |
| 98 | unsigned long deadline = jiffies + timeout; |
| 99 | u32 val; |
| 100 | |
| 101 | do { |
| 102 | val = bcma_read32(core, reg); |
| 103 | if ((val & mask) == value) |
| 104 | return true; |
| 105 | cpu_relax(); |
| 106 | udelay(10); |
| 107 | } while (!time_after_eq(jiffies, deadline)); |
| 108 | |
| 109 | bcma_warn(core->bus, "Timeout waiting for register 0x%04X!\n", reg); |
| 110 | |
| 111 | return false; |
| 112 | } |
| 113 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 114 | static void bcma_release_core_dev(struct device *dev) |
| 115 | { |
| 116 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
Hauke Mehrtens | ecd177c | 2011-07-23 01:20:08 +0200 | [diff] [blame] | 117 | if (core->io_addr) |
| 118 | iounmap(core->io_addr); |
| 119 | if (core->io_wrap) |
| 120 | iounmap(core->io_wrap); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 121 | kfree(core); |
| 122 | } |
| 123 | |
Rafał Miłecki | 37a7f87 | 2014-09-05 00:18:49 +0200 | [diff] [blame] | 124 | static bool bcma_is_core_needed_early(u16 core_id) |
| 125 | { |
| 126 | switch (core_id) { |
| 127 | case BCMA_CORE_NS_NAND: |
| 128 | case BCMA_CORE_NS_QSPI: |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | return false; |
| 133 | } |
| 134 | |
Hauke Mehrtens | 2101e53 | 2014-09-26 00:09:19 +0200 | [diff] [blame] | 135 | #ifdef CONFIG_OF |
| 136 | static struct device_node *bcma_of_find_child_device(struct platform_device *parent, |
| 137 | struct bcma_device *core) |
| 138 | { |
| 139 | struct device_node *node; |
| 140 | u64 size; |
| 141 | const __be32 *reg; |
| 142 | |
| 143 | if (!parent || !parent->dev.of_node) |
| 144 | return NULL; |
| 145 | |
| 146 | for_each_child_of_node(parent->dev.of_node, node) { |
| 147 | reg = of_get_address(node, 0, &size, NULL); |
| 148 | if (!reg) |
| 149 | continue; |
| 150 | if (of_translate_address(node, reg) == core->addr) |
| 151 | return node; |
| 152 | } |
| 153 | return NULL; |
| 154 | } |
| 155 | |
| 156 | static void bcma_of_fill_device(struct platform_device *parent, |
| 157 | struct bcma_device *core) |
| 158 | { |
| 159 | struct device_node *node; |
| 160 | |
| 161 | node = bcma_of_find_child_device(parent, core); |
| 162 | if (node) |
| 163 | core->dev.of_node = node; |
| 164 | } |
| 165 | #else |
| 166 | static void bcma_of_fill_device(struct platform_device *parent, |
| 167 | struct bcma_device *core) |
| 168 | { |
| 169 | } |
| 170 | #endif /* CONFIG_OF */ |
| 171 | |
Hauke Mehrtens | 85eb92e | 2014-11-01 16:54:55 +0100 | [diff] [blame^] | 172 | unsigned int bcma_core_irq(struct bcma_device *core, int num) |
| 173 | { |
| 174 | struct bcma_bus *bus = core->bus; |
| 175 | unsigned int mips_irq; |
| 176 | |
| 177 | switch (bus->hosttype) { |
| 178 | case BCMA_HOSTTYPE_PCI: |
| 179 | return bus->host_pci->irq; |
| 180 | case BCMA_HOSTTYPE_SOC: |
| 181 | if (bus->drv_mips.core && num == 0) { |
| 182 | mips_irq = bcma_core_mips_irq(core); |
| 183 | return mips_irq <= 4 ? mips_irq + 2 : 0; |
| 184 | } |
| 185 | break; |
| 186 | case BCMA_HOSTTYPE_SDIO: |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | EXPORT_SYMBOL(bcma_core_irq); |
| 193 | |
Rafał Miłecki | ab54bc8 | 2014-10-03 17:00:24 +0200 | [diff] [blame] | 194 | void bcma_prepare_core(struct bcma_bus *bus, struct bcma_device *core) |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 195 | { |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 196 | core->dev.release = bcma_release_core_dev; |
| 197 | core->dev.bus = &bcma_bus_type; |
| 198 | dev_set_name(&core->dev, "bcma%d:%d", bus->num, core->core_index); |
| 199 | |
| 200 | switch (bus->hosttype) { |
| 201 | case BCMA_HOSTTYPE_PCI: |
| 202 | core->dev.parent = &bus->host_pci->dev; |
| 203 | core->dma_dev = &bus->host_pci->dev; |
| 204 | core->irq = bus->host_pci->irq; |
| 205 | break; |
| 206 | case BCMA_HOSTTYPE_SOC: |
| 207 | core->dev.dma_mask = &core->dev.coherent_dma_mask; |
Hauke Mehrtens | 2101e53 | 2014-09-26 00:09:19 +0200 | [diff] [blame] | 208 | if (bus->host_pdev) { |
| 209 | core->dma_dev = &bus->host_pdev->dev; |
| 210 | core->dev.parent = &bus->host_pdev->dev; |
| 211 | bcma_of_fill_device(bus->host_pdev, core); |
| 212 | } else { |
| 213 | core->dma_dev = &core->dev; |
| 214 | } |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 215 | break; |
| 216 | case BCMA_HOSTTYPE_SDIO: |
| 217 | break; |
| 218 | } |
Rafał Miłecki | ab54bc8 | 2014-10-03 17:00:24 +0200 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core) |
| 222 | { |
| 223 | int err; |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 224 | |
| 225 | err = device_register(&core->dev); |
| 226 | if (err) { |
| 227 | bcma_err(bus, "Could not register dev for core 0x%03X\n", |
| 228 | core->id.id); |
| 229 | put_device(&core->dev); |
| 230 | return; |
| 231 | } |
| 232 | core->dev_registered = true; |
| 233 | } |
| 234 | |
| 235 | static int bcma_register_devices(struct bcma_bus *bus) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 236 | { |
| 237 | struct bcma_device *core; |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 238 | int err; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 239 | |
| 240 | list_for_each_entry(core, &bus->cores, list) { |
| 241 | /* We support that cores ourself */ |
| 242 | switch (core->id.id) { |
Rafał Miłecki | 6d5cfc9 | 2012-07-10 23:45:49 +0200 | [diff] [blame] | 243 | case BCMA_CORE_4706_CHIPCOMMON: |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 244 | case BCMA_CORE_CHIPCOMMON: |
Hauke Mehrtens | 1716bcf | 2014-09-08 22:53:36 +0200 | [diff] [blame] | 245 | case BCMA_CORE_NS_CHIPCOMMON_B: |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 246 | case BCMA_CORE_PCI: |
| 247 | case BCMA_CORE_PCIE: |
Rafał Miłecki | f473832 | 2014-07-05 01:10:41 +0200 | [diff] [blame] | 248 | case BCMA_CORE_PCIE2: |
Hauke Mehrtens | 21e0534 | 2011-07-23 01:20:09 +0200 | [diff] [blame] | 249 | case BCMA_CORE_MIPS_74K: |
Rafał Miłecki | e1ac4b4 | 2012-07-11 09:23:43 +0200 | [diff] [blame] | 250 | case BCMA_CORE_4706_MAC_GBIT_COMMON: |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 251 | continue; |
| 252 | } |
| 253 | |
Rafał Miłecki | 37a7f87 | 2014-09-05 00:18:49 +0200 | [diff] [blame] | 254 | /* Early cores were already registered */ |
| 255 | if (bcma_is_core_needed_early(core->id.id)) |
| 256 | continue; |
| 257 | |
Rafał Miłecki | 10419d0 | 2013-02-19 19:41:42 +0100 | [diff] [blame] | 258 | /* Only first GMAC core on BCM4706 is connected and working */ |
| 259 | if (core->id.id == BCMA_CORE_4706_MAC_GBIT && |
| 260 | core->core_unit > 0) |
| 261 | continue; |
| 262 | |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 263 | bcma_register_core(bus, core); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Rafał Miłecki | 73e4dbe4 | 2013-01-25 11:37:26 +0100 | [diff] [blame] | 266 | #ifdef CONFIG_BCMA_DRIVER_MIPS |
| 267 | if (bus->drv_cc.pflash.present) { |
| 268 | err = platform_device_register(&bcma_pflash_dev); |
| 269 | if (err) |
| 270 | bcma_err(bus, "Error registering parallel flash\n"); |
| 271 | } |
| 272 | #endif |
| 273 | |
Rafał Miłecki | d57ef3a | 2012-08-10 21:23:53 +0200 | [diff] [blame] | 274 | #ifdef CONFIG_BCMA_SFLASH |
| 275 | if (bus->drv_cc.sflash.present) { |
| 276 | err = platform_device_register(&bcma_sflash_dev); |
| 277 | if (err) |
| 278 | bcma_err(bus, "Error registering serial flash\n"); |
| 279 | } |
| 280 | #endif |
| 281 | |
Rafał Miłecki | 371a004 | 2012-08-12 13:08:05 +0200 | [diff] [blame] | 282 | #ifdef CONFIG_BCMA_NFLASH |
| 283 | if (bus->drv_cc.nflash.present) { |
| 284 | err = platform_device_register(&bcma_nflash_dev); |
| 285 | if (err) |
| 286 | bcma_err(bus, "Error registering NAND flash\n"); |
| 287 | } |
| 288 | #endif |
Hauke Mehrtens | cf0936b | 2012-11-20 22:24:30 +0000 | [diff] [blame] | 289 | err = bcma_gpio_init(&bus->drv_cc); |
| 290 | if (err == -ENOTSUPP) |
| 291 | bcma_debug(bus, "GPIO driver not activated\n"); |
| 292 | else if (err) |
| 293 | bcma_err(bus, "Error registering GPIO driver: %i\n", err); |
Rafał Miłecki | 371a004 | 2012-08-12 13:08:05 +0200 | [diff] [blame] | 294 | |
Hauke Mehrtens | a4855f39 | 2012-12-05 18:46:02 +0100 | [diff] [blame] | 295 | if (bus->hosttype == BCMA_HOSTTYPE_SOC) { |
| 296 | err = bcma_chipco_watchdog_register(&bus->drv_cc); |
| 297 | if (err) |
| 298 | bcma_err(bus, "Error registering watchdog driver\n"); |
| 299 | } |
| 300 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static void bcma_unregister_cores(struct bcma_bus *bus) |
| 305 | { |
Piotr Haber | 1fffa90 | 2012-10-11 14:05:15 +0200 | [diff] [blame] | 306 | struct bcma_device *core, *tmp; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 307 | |
Piotr Haber | 1fffa90 | 2012-10-11 14:05:15 +0200 | [diff] [blame] | 308 | list_for_each_entry_safe(core, tmp, &bus->cores, list) { |
| 309 | list_del(&core->list); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 310 | if (core->dev_registered) |
| 311 | device_unregister(&core->dev); |
| 312 | } |
Hauke Mehrtens | a4855f39 | 2012-12-05 18:46:02 +0100 | [diff] [blame] | 313 | if (bus->hosttype == BCMA_HOSTTYPE_SOC) |
| 314 | platform_device_unregister(bus->drv_cc.watchdog); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Greg Kroah-Hartman | 0f58a01 | 2012-12-21 15:12:59 -0800 | [diff] [blame] | 317 | int bcma_bus_register(struct bcma_bus *bus) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 318 | { |
| 319 | int err; |
| 320 | struct bcma_device *core; |
| 321 | |
Hauke Mehrtens | 8f9ada4 | 2012-01-31 00:03:36 +0100 | [diff] [blame] | 322 | mutex_lock(&bcma_buses_mutex); |
| 323 | bus->num = bcma_bus_next_num++; |
| 324 | mutex_unlock(&bcma_buses_mutex); |
| 325 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 326 | /* Scan for devices (cores) */ |
| 327 | err = bcma_bus_scan(bus); |
| 328 | if (err) { |
Rafał Miłecki | 3d9d8af | 2012-07-05 22:07:32 +0200 | [diff] [blame] | 329 | bcma_err(bus, "Failed to scan: %d\n", err); |
Hauke Mehrtens | 1cabf7d | 2013-07-15 13:15:07 +0200 | [diff] [blame] | 330 | return err; |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 331 | } |
| 332 | |
Hauke Mehrtens | 30cfb02 | 2012-09-29 20:29:50 +0200 | [diff] [blame] | 333 | /* Early init CC core */ |
| 334 | core = bcma_find_core(bus, bcma_cc_core_id(bus)); |
| 335 | if (core) { |
| 336 | bus->drv_cc.core = core; |
| 337 | bcma_core_chipcommon_early_init(&bus->drv_cc); |
| 338 | } |
| 339 | |
Rafał Miłecki | 37a7f87 | 2014-09-05 00:18:49 +0200 | [diff] [blame] | 340 | /* Cores providing flash access go before SPROM init */ |
| 341 | list_for_each_entry(core, &bus->cores, list) { |
| 342 | if (bcma_is_core_needed_early(core->id.id)) |
| 343 | bcma_register_core(bus, core); |
| 344 | } |
| 345 | |
Hauke Mehrtens | 30cfb02 | 2012-09-29 20:29:50 +0200 | [diff] [blame] | 346 | /* Try to get SPROM */ |
| 347 | err = bcma_sprom_get(bus); |
| 348 | if (err == -ENOENT) { |
| 349 | bcma_err(bus, "No SPROM available\n"); |
| 350 | } else if (err) |
| 351 | bcma_err(bus, "Failed to get SPROM: %d\n", err); |
| 352 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 353 | /* Init CC core */ |
Rafał Miłecki | 6d5cfc9 | 2012-07-10 23:45:49 +0200 | [diff] [blame] | 354 | core = bcma_find_core(bus, bcma_cc_core_id(bus)); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 355 | if (core) { |
| 356 | bus->drv_cc.core = core; |
| 357 | bcma_core_chipcommon_init(&bus->drv_cc); |
| 358 | } |
| 359 | |
Hauke Mehrtens | 1716bcf | 2014-09-08 22:53:36 +0200 | [diff] [blame] | 360 | /* Init CC core */ |
| 361 | core = bcma_find_core(bus, BCMA_CORE_NS_CHIPCOMMON_B); |
| 362 | if (core) { |
| 363 | bus->drv_cc_b.core = core; |
| 364 | bcma_core_chipcommon_b_init(&bus->drv_cc_b); |
| 365 | } |
| 366 | |
Hauke Mehrtens | 21e0534 | 2011-07-23 01:20:09 +0200 | [diff] [blame] | 367 | /* Init MIPS core */ |
| 368 | core = bcma_find_core(bus, BCMA_CORE_MIPS_74K); |
| 369 | if (core) { |
| 370 | bus->drv_mips.core = core; |
| 371 | bcma_core_mips_init(&bus->drv_mips); |
| 372 | } |
| 373 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 374 | /* Init PCIE core */ |
Hauke Mehrtens | dfae714 | 2012-09-29 20:40:18 +0200 | [diff] [blame] | 375 | core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 0); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 376 | if (core) { |
Hauke Mehrtens | dfae714 | 2012-09-29 20:40:18 +0200 | [diff] [blame] | 377 | bus->drv_pci[0].core = core; |
| 378 | bcma_core_pci_init(&bus->drv_pci[0]); |
| 379 | } |
| 380 | |
| 381 | /* Init PCIE core */ |
| 382 | core = bcma_find_core_unit(bus, BCMA_CORE_PCIE, 1); |
| 383 | if (core) { |
| 384 | bus->drv_pci[1].core = core; |
| 385 | bcma_core_pci_init(&bus->drv_pci[1]); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Rafał Miłecki | f473832 | 2014-07-05 01:10:41 +0200 | [diff] [blame] | 388 | /* Init PCIe Gen 2 core */ |
| 389 | core = bcma_find_core_unit(bus, BCMA_CORE_PCIE2, 0); |
| 390 | if (core) { |
| 391 | bus->drv_pcie2.core = core; |
| 392 | bcma_core_pcie2_init(&bus->drv_pcie2); |
| 393 | } |
| 394 | |
Rafał Miłecki | e1ac4b4 | 2012-07-11 09:23:43 +0200 | [diff] [blame] | 395 | /* Init GBIT MAC COMMON core */ |
| 396 | core = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON); |
| 397 | if (core) { |
| 398 | bus->drv_gmac_cmn.core = core; |
| 399 | bcma_core_gmac_cmn_init(&bus->drv_gmac_cmn); |
| 400 | } |
| 401 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 402 | /* Register found cores */ |
Rafał Miłecki | 6e094bd | 2014-09-05 00:18:48 +0200 | [diff] [blame] | 403 | bcma_register_devices(bus); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 404 | |
Rafał Miłecki | 3d9d8af | 2012-07-05 22:07:32 +0200 | [diff] [blame] | 405 | bcma_info(bus, "Bus registered\n"); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 406 | |
| 407 | return 0; |
| 408 | } |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 409 | |
| 410 | void bcma_bus_unregister(struct bcma_bus *bus) |
| 411 | { |
Saul St. John | ee91592 | 2012-08-16 15:42:30 -0500 | [diff] [blame] | 412 | struct bcma_device *cores[3]; |
Hauke Mehrtens | c50ae94 | 2013-02-03 23:25:33 +0100 | [diff] [blame] | 413 | int err; |
| 414 | |
| 415 | err = bcma_gpio_unregister(&bus->drv_cc); |
| 416 | if (err == -EBUSY) |
| 417 | bcma_err(bus, "Some GPIOs are still in use.\n"); |
| 418 | else if (err) |
| 419 | bcma_err(bus, "Can not unregister GPIO driver: %i\n", err); |
Saul St. John | ee91592 | 2012-08-16 15:42:30 -0500 | [diff] [blame] | 420 | |
Hauke Mehrtens | 1716bcf | 2014-09-08 22:53:36 +0200 | [diff] [blame] | 421 | bcma_core_chipcommon_b_free(&bus->drv_cc_b); |
| 422 | |
Saul St. John | ee91592 | 2012-08-16 15:42:30 -0500 | [diff] [blame] | 423 | cores[0] = bcma_find_core(bus, BCMA_CORE_MIPS_74K); |
| 424 | cores[1] = bcma_find_core(bus, BCMA_CORE_PCIE); |
| 425 | cores[2] = bcma_find_core(bus, BCMA_CORE_4706_MAC_GBIT_COMMON); |
| 426 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 427 | bcma_unregister_cores(bus); |
Saul St. John | ee91592 | 2012-08-16 15:42:30 -0500 | [diff] [blame] | 428 | |
| 429 | kfree(cores[2]); |
| 430 | kfree(cores[1]); |
| 431 | kfree(cores[0]); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 432 | } |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 433 | |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 434 | int __init bcma_bus_early_register(struct bcma_bus *bus, |
| 435 | struct bcma_device *core_cc, |
| 436 | struct bcma_device *core_mips) |
| 437 | { |
| 438 | int err; |
| 439 | struct bcma_device *core; |
| 440 | struct bcma_device_id match; |
| 441 | |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 442 | match.manuf = BCMA_MANUF_BCM; |
Rafał Miłecki | 6d5cfc9 | 2012-07-10 23:45:49 +0200 | [diff] [blame] | 443 | match.id = bcma_cc_core_id(bus); |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 444 | match.class = BCMA_CL_SIM; |
| 445 | match.rev = BCMA_ANY_REV; |
| 446 | |
| 447 | /* Scan for chip common core */ |
| 448 | err = bcma_bus_scan_early(bus, &match, core_cc); |
| 449 | if (err) { |
Rafał Miłecki | 3d9d8af | 2012-07-05 22:07:32 +0200 | [diff] [blame] | 450 | bcma_err(bus, "Failed to scan for common core: %d\n", err); |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 451 | return -1; |
| 452 | } |
| 453 | |
| 454 | match.manuf = BCMA_MANUF_MIPS; |
| 455 | match.id = BCMA_CORE_MIPS_74K; |
| 456 | match.class = BCMA_CL_SIM; |
| 457 | match.rev = BCMA_ANY_REV; |
| 458 | |
| 459 | /* Scan for mips core */ |
| 460 | err = bcma_bus_scan_early(bus, &match, core_mips); |
| 461 | if (err) { |
Rafał Miłecki | 3d9d8af | 2012-07-05 22:07:32 +0200 | [diff] [blame] | 462 | bcma_err(bus, "Failed to scan for mips core: %d\n", err); |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 463 | return -1; |
| 464 | } |
| 465 | |
Hauke Mehrtens | 49655bb | 2012-09-29 20:29:49 +0200 | [diff] [blame] | 466 | /* Early init CC core */ |
Rafał Miłecki | 6d5cfc9 | 2012-07-10 23:45:49 +0200 | [diff] [blame] | 467 | core = bcma_find_core(bus, bcma_cc_core_id(bus)); |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 468 | if (core) { |
| 469 | bus->drv_cc.core = core; |
Hauke Mehrtens | 49655bb | 2012-09-29 20:29:49 +0200 | [diff] [blame] | 470 | bcma_core_chipcommon_early_init(&bus->drv_cc); |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 471 | } |
| 472 | |
Hauke Mehrtens | 49655bb | 2012-09-29 20:29:49 +0200 | [diff] [blame] | 473 | /* Early init MIPS core */ |
Hauke Mehrtens | 21e0534 | 2011-07-23 01:20:09 +0200 | [diff] [blame] | 474 | core = bcma_find_core(bus, BCMA_CORE_MIPS_74K); |
| 475 | if (core) { |
| 476 | bus->drv_mips.core = core; |
Hauke Mehrtens | 49655bb | 2012-09-29 20:29:49 +0200 | [diff] [blame] | 477 | bcma_core_mips_early_init(&bus->drv_mips); |
Hauke Mehrtens | 21e0534 | 2011-07-23 01:20:09 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Rafał Miłecki | 3d9d8af | 2012-07-05 22:07:32 +0200 | [diff] [blame] | 480 | bcma_info(bus, "Early bus registered\n"); |
Hauke Mehrtens | 517f43e | 2011-07-23 01:20:07 +0200 | [diff] [blame] | 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
Rafał Miłecki | 775ab52 | 2011-12-09 22:16:07 +0100 | [diff] [blame] | 485 | #ifdef CONFIG_PM |
Linus Torvalds | 685a4ef | 2012-01-13 23:58:40 +0100 | [diff] [blame] | 486 | int bcma_bus_suspend(struct bcma_bus *bus) |
| 487 | { |
Linus Torvalds | 7d5869e | 2012-01-13 23:58:41 +0100 | [diff] [blame] | 488 | struct bcma_device *core; |
| 489 | |
| 490 | list_for_each_entry(core, &bus->cores, list) { |
| 491 | struct device_driver *drv = core->dev.driver; |
| 492 | if (drv) { |
| 493 | struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv); |
| 494 | if (adrv->suspend) |
| 495 | adrv->suspend(core); |
| 496 | } |
| 497 | } |
Linus Torvalds | 685a4ef | 2012-01-13 23:58:40 +0100 | [diff] [blame] | 498 | return 0; |
| 499 | } |
| 500 | |
Rafał Miłecki | 775ab52 | 2011-12-09 22:16:07 +0100 | [diff] [blame] | 501 | int bcma_bus_resume(struct bcma_bus *bus) |
| 502 | { |
| 503 | struct bcma_device *core; |
| 504 | |
| 505 | /* Init CC core */ |
Rafał Miłecki | 6d5cfc9 | 2012-07-10 23:45:49 +0200 | [diff] [blame] | 506 | if (bus->drv_cc.core) { |
Rafał Miłecki | 775ab52 | 2011-12-09 22:16:07 +0100 | [diff] [blame] | 507 | bus->drv_cc.setup_done = false; |
| 508 | bcma_core_chipcommon_init(&bus->drv_cc); |
| 509 | } |
| 510 | |
Linus Torvalds | 7d5869e | 2012-01-13 23:58:41 +0100 | [diff] [blame] | 511 | list_for_each_entry(core, &bus->cores, list) { |
| 512 | struct device_driver *drv = core->dev.driver; |
| 513 | if (drv) { |
| 514 | struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv); |
| 515 | if (adrv->resume) |
| 516 | adrv->resume(core); |
| 517 | } |
| 518 | } |
| 519 | |
Rafał Miłecki | 775ab52 | 2011-12-09 22:16:07 +0100 | [diff] [blame] | 520 | return 0; |
| 521 | } |
| 522 | #endif |
| 523 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 524 | int __bcma_driver_register(struct bcma_driver *drv, struct module *owner) |
| 525 | { |
| 526 | drv->drv.name = drv->name; |
| 527 | drv->drv.bus = &bcma_bus_type; |
| 528 | drv->drv.owner = owner; |
| 529 | |
| 530 | return driver_register(&drv->drv); |
| 531 | } |
| 532 | EXPORT_SYMBOL_GPL(__bcma_driver_register); |
| 533 | |
| 534 | void bcma_driver_unregister(struct bcma_driver *drv) |
| 535 | { |
| 536 | driver_unregister(&drv->drv); |
| 537 | } |
| 538 | EXPORT_SYMBOL_GPL(bcma_driver_unregister); |
| 539 | |
| 540 | static int bcma_bus_match(struct device *dev, struct device_driver *drv) |
| 541 | { |
| 542 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 543 | struct bcma_driver *adrv = container_of(drv, struct bcma_driver, drv); |
| 544 | const struct bcma_device_id *cid = &core->id; |
| 545 | const struct bcma_device_id *did; |
| 546 | |
| 547 | for (did = adrv->id_table; did->manuf || did->id || did->rev; did++) { |
| 548 | if ((did->manuf == cid->manuf || did->manuf == BCMA_ANY_MANUF) && |
| 549 | (did->id == cid->id || did->id == BCMA_ANY_ID) && |
| 550 | (did->rev == cid->rev || did->rev == BCMA_ANY_REV) && |
| 551 | (did->class == cid->class || did->class == BCMA_ANY_CLASS)) |
| 552 | return 1; |
| 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int bcma_device_probe(struct device *dev) |
| 558 | { |
| 559 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 560 | struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver, |
| 561 | drv); |
| 562 | int err = 0; |
| 563 | |
| 564 | if (adrv->probe) |
| 565 | err = adrv->probe(core); |
| 566 | |
| 567 | return err; |
| 568 | } |
| 569 | |
| 570 | static int bcma_device_remove(struct device *dev) |
| 571 | { |
| 572 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 573 | struct bcma_driver *adrv = container_of(dev->driver, struct bcma_driver, |
| 574 | drv); |
| 575 | |
| 576 | if (adrv->remove) |
| 577 | adrv->remove(core); |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
David Woodhouse | 886b66e | 2011-08-19 22:14:47 +0200 | [diff] [blame] | 582 | static int bcma_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 583 | { |
| 584 | struct bcma_device *core = container_of(dev, struct bcma_device, dev); |
| 585 | |
| 586 | return add_uevent_var(env, |
| 587 | "MODALIAS=bcma:m%04Xid%04Xrev%02Xcl%02X", |
| 588 | core->id.manuf, core->id.id, |
| 589 | core->id.rev, core->id.class); |
| 590 | } |
| 591 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 592 | static int __init bcma_modinit(void) |
| 593 | { |
| 594 | int err; |
| 595 | |
| 596 | err = bus_register(&bcma_bus_type); |
| 597 | if (err) |
| 598 | return err; |
| 599 | |
Hauke Mehrtens | 2101e53 | 2014-09-26 00:09:19 +0200 | [diff] [blame] | 600 | err = bcma_host_soc_register_driver(); |
| 601 | if (err) { |
| 602 | pr_err("SoC host initialization failed\n"); |
| 603 | err = 0; |
| 604 | } |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 605 | #ifdef CONFIG_BCMA_HOST_PCI |
| 606 | err = bcma_host_pci_init(); |
| 607 | if (err) { |
| 608 | pr_err("PCI host initialization failed\n"); |
| 609 | err = 0; |
| 610 | } |
| 611 | #endif |
| 612 | |
| 613 | return err; |
| 614 | } |
| 615 | fs_initcall(bcma_modinit); |
| 616 | |
| 617 | static void __exit bcma_modexit(void) |
| 618 | { |
| 619 | #ifdef CONFIG_BCMA_HOST_PCI |
| 620 | bcma_host_pci_exit(); |
| 621 | #endif |
Hauke Mehrtens | 2101e53 | 2014-09-26 00:09:19 +0200 | [diff] [blame] | 622 | bcma_host_soc_unregister_driver(); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 623 | bus_unregister(&bcma_bus_type); |
| 624 | } |
| 625 | module_exit(bcma_modexit) |