main.c 17 KB

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