main.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. /*
  2. * Sonics Silicon Backplane
  3. * Subsystem core
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include "ssb_private.h"
  11. #include <linux/delay.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ssb/ssb.h>
  16. #include <linux/ssb/ssb_regs.h>
  17. #include <linux/ssb/ssb_driver_gige.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/pci.h>
  20. #include <linux/mmc/sdio_func.h>
  21. #include <linux/slab.h>
  22. #include <pcmcia/cistpl.h>
  23. #include <pcmcia/ds.h>
  24. MODULE_DESCRIPTION("Sonics Silicon Backplane driver");
  25. MODULE_LICENSE("GPL");
  26. /* Temporary list of yet-to-be-attached buses */
  27. static LIST_HEAD(attach_queue);
  28. /* List if running buses */
  29. static LIST_HEAD(buses);
  30. /* Software ID counter */
  31. static unsigned int next_busnumber;
  32. /* buses_mutes locks the two buslists and the next_busnumber.
  33. * Don't lock this directly, but use ssb_buses_[un]lock() below. */
  34. static DEFINE_MUTEX(buses_mutex);
  35. /* There are differences in the codeflow, if the bus is
  36. * initialized from early boot, as various needed services
  37. * are not available early. This is a mechanism to delay
  38. * these initializations to after early boot has finished.
  39. * It's also used to avoid mutex locking, as that's not
  40. * available and needed early. */
  41. static bool ssb_is_early_boot = 1;
  42. static void ssb_buses_lock(void);
  43. static void ssb_buses_unlock(void);
  44. #ifdef CONFIG_SSB_PCIHOST
  45. struct ssb_bus *ssb_pci_dev_to_bus(struct pci_dev *pdev)
  46. {
  47. struct ssb_bus *bus;
  48. ssb_buses_lock();
  49. list_for_each_entry(bus, &buses, list) {
  50. if (bus->bustype == SSB_BUSTYPE_PCI &&
  51. bus->host_pci == pdev)
  52. goto found;
  53. }
  54. bus = NULL;
  55. found:
  56. ssb_buses_unlock();
  57. return bus;
  58. }
  59. #endif /* CONFIG_SSB_PCIHOST */
  60. #ifdef CONFIG_SSB_PCMCIAHOST
  61. struct ssb_bus *ssb_pcmcia_dev_to_bus(struct pcmcia_device *pdev)
  62. {
  63. struct ssb_bus *bus;
  64. ssb_buses_lock();
  65. list_for_each_entry(bus, &buses, list) {
  66. if (bus->bustype == SSB_BUSTYPE_PCMCIA &&
  67. bus->host_pcmcia == pdev)
  68. goto found;
  69. }
  70. bus = NULL;
  71. found:
  72. ssb_buses_unlock();
  73. return bus;
  74. }
  75. #endif /* CONFIG_SSB_PCMCIAHOST */
  76. int ssb_for_each_bus_call(unsigned long data,
  77. int (*func)(struct ssb_bus *bus, unsigned long data))
  78. {
  79. struct ssb_bus *bus;
  80. int res;
  81. ssb_buses_lock();
  82. list_for_each_entry(bus, &buses, list) {
  83. res = func(bus, data);
  84. if (res >= 0) {
  85. ssb_buses_unlock();
  86. return res;
  87. }
  88. }
  89. ssb_buses_unlock();
  90. return -ENODEV;
  91. }
  92. static struct ssb_device *ssb_device_get(struct ssb_device *dev)
  93. {
  94. if (dev)
  95. get_device(dev->dev);
  96. return dev;
  97. }
  98. static void ssb_device_put(struct ssb_device *dev)
  99. {
  100. if (dev)
  101. put_device(dev->dev);
  102. }
  103. static int ssb_device_resume(struct device *dev)
  104. {
  105. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  106. struct ssb_driver *ssb_drv;
  107. int err = 0;
  108. if (dev->driver) {
  109. ssb_drv = drv_to_ssb_drv(dev->driver);
  110. if (ssb_drv && ssb_drv->resume)
  111. err = ssb_drv->resume(ssb_dev);
  112. if (err)
  113. goto out;
  114. }
  115. out:
  116. return err;
  117. }
  118. static int ssb_device_suspend(struct device *dev, pm_message_t state)
  119. {
  120. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  121. struct ssb_driver *ssb_drv;
  122. int err = 0;
  123. if (dev->driver) {
  124. ssb_drv = drv_to_ssb_drv(dev->driver);
  125. if (ssb_drv && ssb_drv->suspend)
  126. err = ssb_drv->suspend(ssb_dev, state);
  127. if (err)
  128. goto out;
  129. }
  130. out:
  131. return err;
  132. }
  133. int ssb_bus_resume(struct ssb_bus *bus)
  134. {
  135. int err;
  136. /* Reset HW state information in memory, so that HW is
  137. * completely reinitialized. */
  138. bus->mapped_device = NULL;
  139. #ifdef CONFIG_SSB_DRIVER_PCICORE
  140. bus->pcicore.setup_done = 0;
  141. #endif
  142. err = ssb_bus_powerup(bus, 0);
  143. if (err)
  144. return err;
  145. err = ssb_pcmcia_hardware_setup(bus);
  146. if (err) {
  147. ssb_bus_may_powerdown(bus);
  148. return err;
  149. }
  150. ssb_chipco_resume(&bus->chipco);
  151. ssb_bus_may_powerdown(bus);
  152. return 0;
  153. }
  154. EXPORT_SYMBOL(ssb_bus_resume);
  155. int ssb_bus_suspend(struct ssb_bus *bus)
  156. {
  157. ssb_chipco_suspend(&bus->chipco);
  158. ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
  159. return 0;
  160. }
  161. EXPORT_SYMBOL(ssb_bus_suspend);
  162. #ifdef CONFIG_SSB_SPROM
  163. /** ssb_devices_freeze - Freeze all devices on the bus.
  164. *
  165. * After freezing no device driver will be handling a device
  166. * on this bus anymore. ssb_devices_thaw() must be called after
  167. * a successful freeze to reactivate the devices.
  168. *
  169. * @bus: The bus.
  170. * @ctx: Context structure. Pass this to ssb_devices_thaw().
  171. */
  172. int ssb_devices_freeze(struct ssb_bus *bus, struct ssb_freeze_context *ctx)
  173. {
  174. struct ssb_device *sdev;
  175. struct ssb_driver *sdrv;
  176. unsigned int i;
  177. memset(ctx, 0, sizeof(*ctx));
  178. ctx->bus = bus;
  179. SSB_WARN_ON(bus->nr_devices > ARRAY_SIZE(ctx->device_frozen));
  180. for (i = 0; i < bus->nr_devices; i++) {
  181. sdev = ssb_device_get(&bus->devices[i]);
  182. if (!sdev->dev || !sdev->dev->driver ||
  183. !device_is_registered(sdev->dev)) {
  184. ssb_device_put(sdev);
  185. continue;
  186. }
  187. sdrv = drv_to_ssb_drv(sdev->dev->driver);
  188. if (SSB_WARN_ON(!sdrv->remove))
  189. continue;
  190. sdrv->remove(sdev);
  191. ctx->device_frozen[i] = 1;
  192. }
  193. return 0;
  194. }
  195. /** ssb_devices_thaw - Unfreeze all devices on the bus.
  196. *
  197. * This will re-attach the device drivers and re-init the devices.
  198. *
  199. * @ctx: The context structure from ssb_devices_freeze()
  200. */
  201. int ssb_devices_thaw(struct ssb_freeze_context *ctx)
  202. {
  203. struct ssb_bus *bus = ctx->bus;
  204. struct ssb_device *sdev;
  205. struct ssb_driver *sdrv;
  206. unsigned int i;
  207. int err, result = 0;
  208. for (i = 0; i < bus->nr_devices; i++) {
  209. if (!ctx->device_frozen[i])
  210. continue;
  211. sdev = &bus->devices[i];
  212. if (SSB_WARN_ON(!sdev->dev || !sdev->dev->driver))
  213. continue;
  214. sdrv = drv_to_ssb_drv(sdev->dev->driver);
  215. if (SSB_WARN_ON(!sdrv || !sdrv->probe))
  216. continue;
  217. err = sdrv->probe(sdev, &sdev->id);
  218. if (err) {
  219. ssb_err("Failed to thaw device %s\n",
  220. dev_name(sdev->dev));
  221. result = err;
  222. }
  223. ssb_device_put(sdev);
  224. }
  225. return result;
  226. }
  227. #endif /* CONFIG_SSB_SPROM */
  228. static void ssb_device_shutdown(struct device *dev)
  229. {
  230. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  231. struct ssb_driver *ssb_drv;
  232. if (!dev->driver)
  233. return;
  234. ssb_drv = drv_to_ssb_drv(dev->driver);
  235. if (ssb_drv && ssb_drv->shutdown)
  236. ssb_drv->shutdown(ssb_dev);
  237. }
  238. static int ssb_device_remove(struct device *dev)
  239. {
  240. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  241. struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver);
  242. if (ssb_drv && ssb_drv->remove)
  243. ssb_drv->remove(ssb_dev);
  244. ssb_device_put(ssb_dev);
  245. return 0;
  246. }
  247. static int ssb_device_probe(struct device *dev)
  248. {
  249. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  250. struct ssb_driver *ssb_drv = drv_to_ssb_drv(dev->driver);
  251. int err = 0;
  252. ssb_device_get(ssb_dev);
  253. if (ssb_drv && ssb_drv->probe)
  254. err = ssb_drv->probe(ssb_dev, &ssb_dev->id);
  255. if (err)
  256. ssb_device_put(ssb_dev);
  257. return err;
  258. }
  259. static int ssb_match_devid(const struct ssb_device_id *tabid,
  260. const struct ssb_device_id *devid)
  261. {
  262. if ((tabid->vendor != devid->vendor) &&
  263. tabid->vendor != SSB_ANY_VENDOR)
  264. return 0;
  265. if ((tabid->coreid != devid->coreid) &&
  266. tabid->coreid != SSB_ANY_ID)
  267. return 0;
  268. if ((tabid->revision != devid->revision) &&
  269. tabid->revision != SSB_ANY_REV)
  270. return 0;
  271. return 1;
  272. }
  273. static int ssb_bus_match(struct device *dev, struct device_driver *drv)
  274. {
  275. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  276. struct ssb_driver *ssb_drv = drv_to_ssb_drv(drv);
  277. const struct ssb_device_id *id;
  278. for (id = ssb_drv->id_table;
  279. id->vendor || id->coreid || id->revision;
  280. id++) {
  281. if (ssb_match_devid(id, &ssb_dev->id))
  282. return 1; /* found */
  283. }
  284. return 0;
  285. }
  286. static int ssb_device_uevent(struct device *dev, struct kobj_uevent_env *env)
  287. {
  288. struct ssb_device *ssb_dev = dev_to_ssb_dev(dev);
  289. if (!dev)
  290. return -ENODEV;
  291. return add_uevent_var(env,
  292. "MODALIAS=ssb:v%04Xid%04Xrev%02X",
  293. ssb_dev->id.vendor, ssb_dev->id.coreid,
  294. ssb_dev->id.revision);
  295. }
  296. #define ssb_config_attr(attrib, field, format_string) \
  297. static ssize_t \
  298. attrib##_show(struct device *dev, struct device_attribute *attr, char *buf) \
  299. { \
  300. return sprintf(buf, format_string, dev_to_ssb_dev(dev)->field); \
  301. } \
  302. static DEVICE_ATTR_RO(attrib);
  303. ssb_config_attr(core_num, core_index, "%u\n")
  304. ssb_config_attr(coreid, id.coreid, "0x%04x\n")
  305. ssb_config_attr(vendor, id.vendor, "0x%04x\n")
  306. ssb_config_attr(revision, id.revision, "%u\n")
  307. ssb_config_attr(irq, irq, "%u\n")
  308. static ssize_t
  309. name_show(struct device *dev, struct device_attribute *attr, char *buf)
  310. {
  311. return sprintf(buf, "%s\n",
  312. ssb_core_name(dev_to_ssb_dev(dev)->id.coreid));
  313. }
  314. static DEVICE_ATTR_RO(name);
  315. static struct attribute *ssb_device_attrs[] = {
  316. &dev_attr_name.attr,
  317. &dev_attr_core_num.attr,
  318. &dev_attr_coreid.attr,
  319. &dev_attr_vendor.attr,
  320. &dev_attr_revision.attr,
  321. &dev_attr_irq.attr,
  322. NULL,
  323. };
  324. ATTRIBUTE_GROUPS(ssb_device);
  325. static struct bus_type ssb_bustype = {
  326. .name = "ssb",
  327. .match = ssb_bus_match,
  328. .probe = ssb_device_probe,
  329. .remove = ssb_device_remove,
  330. .shutdown = ssb_device_shutdown,
  331. .suspend = ssb_device_suspend,
  332. .resume = ssb_device_resume,
  333. .uevent = ssb_device_uevent,
  334. .dev_groups = ssb_device_groups,
  335. };
  336. static void ssb_buses_lock(void)
  337. {
  338. /* See the comment at the ssb_is_early_boot definition */
  339. if (!ssb_is_early_boot)
  340. mutex_lock(&buses_mutex);
  341. }
  342. static void ssb_buses_unlock(void)
  343. {
  344. /* See the comment at the ssb_is_early_boot definition */
  345. if (!ssb_is_early_boot)
  346. mutex_unlock(&buses_mutex);
  347. }
  348. static void ssb_devices_unregister(struct ssb_bus *bus)
  349. {
  350. struct ssb_device *sdev;
  351. int i;
  352. for (i = bus->nr_devices - 1; i >= 0; i--) {
  353. sdev = &(bus->devices[i]);
  354. if (sdev->dev)
  355. device_unregister(sdev->dev);
  356. }
  357. #ifdef CONFIG_SSB_EMBEDDED
  358. if (bus->bustype == SSB_BUSTYPE_SSB)
  359. platform_device_unregister(bus->watchdog);
  360. #endif
  361. }
  362. void ssb_bus_unregister(struct ssb_bus *bus)
  363. {
  364. int err;
  365. err = ssb_gpio_unregister(bus);
  366. if (err == -EBUSY)
  367. ssb_dbg("Some GPIOs are still in use\n");
  368. else if (err)
  369. ssb_dbg("Can not unregister GPIO driver: %i\n", err);
  370. ssb_buses_lock();
  371. ssb_devices_unregister(bus);
  372. list_del(&bus->list);
  373. ssb_buses_unlock();
  374. ssb_pcmcia_exit(bus);
  375. ssb_pci_exit(bus);
  376. ssb_iounmap(bus);
  377. }
  378. EXPORT_SYMBOL(ssb_bus_unregister);
  379. static void ssb_release_dev(struct device *dev)
  380. {
  381. struct __ssb_dev_wrapper *devwrap;
  382. devwrap = container_of(dev, struct __ssb_dev_wrapper, dev);
  383. kfree(devwrap);
  384. }
  385. static int ssb_devices_register(struct ssb_bus *bus)
  386. {
  387. struct ssb_device *sdev;
  388. struct device *dev;
  389. struct __ssb_dev_wrapper *devwrap;
  390. int i, err = 0;
  391. int dev_idx = 0;
  392. for (i = 0; i < bus->nr_devices; i++) {
  393. sdev = &(bus->devices[i]);
  394. /* We don't register SSB-system devices to the kernel,
  395. * as the drivers for them are built into SSB. */
  396. switch (sdev->id.coreid) {
  397. case SSB_DEV_CHIPCOMMON:
  398. case SSB_DEV_PCI:
  399. case SSB_DEV_PCIE:
  400. case SSB_DEV_PCMCIA:
  401. case SSB_DEV_MIPS:
  402. case SSB_DEV_MIPS_3302:
  403. case SSB_DEV_EXTIF:
  404. continue;
  405. }
  406. devwrap = kzalloc(sizeof(*devwrap), GFP_KERNEL);
  407. if (!devwrap) {
  408. ssb_err("Could not allocate device\n");
  409. err = -ENOMEM;
  410. goto error;
  411. }
  412. dev = &devwrap->dev;
  413. devwrap->sdev = sdev;
  414. dev->release = ssb_release_dev;
  415. dev->bus = &ssb_bustype;
  416. dev_set_name(dev, "ssb%u:%d", bus->busnumber, dev_idx);
  417. switch (bus->bustype) {
  418. case SSB_BUSTYPE_PCI:
  419. #ifdef CONFIG_SSB_PCIHOST
  420. sdev->irq = bus->host_pci->irq;
  421. dev->parent = &bus->host_pci->dev;
  422. sdev->dma_dev = dev->parent;
  423. #endif
  424. break;
  425. case SSB_BUSTYPE_PCMCIA:
  426. #ifdef CONFIG_SSB_PCMCIAHOST
  427. sdev->irq = bus->host_pcmcia->irq;
  428. dev->parent = &bus->host_pcmcia->dev;
  429. #endif
  430. break;
  431. case SSB_BUSTYPE_SDIO:
  432. #ifdef CONFIG_SSB_SDIOHOST
  433. dev->parent = &bus->host_sdio->dev;
  434. #endif
  435. break;
  436. case SSB_BUSTYPE_SSB:
  437. dev->dma_mask = &dev->coherent_dma_mask;
  438. sdev->dma_dev = dev;
  439. break;
  440. }
  441. sdev->dev = dev;
  442. err = device_register(dev);
  443. if (err) {
  444. ssb_err("Could not register %s\n", dev_name(dev));
  445. /* Set dev to NULL to not unregister
  446. * dev on error unwinding. */
  447. sdev->dev = NULL;
  448. kfree(devwrap);
  449. goto error;
  450. }
  451. dev_idx++;
  452. }
  453. #ifdef CONFIG_SSB_DRIVER_MIPS
  454. if (bus->mipscore.pflash.present) {
  455. err = platform_device_register(&ssb_pflash_dev);
  456. if (err)
  457. pr_err("Error registering parallel flash\n");
  458. }
  459. #endif
  460. #ifdef CONFIG_SSB_SFLASH
  461. if (bus->mipscore.sflash.present) {
  462. err = platform_device_register(&ssb_sflash_dev);
  463. if (err)
  464. pr_err("Error registering serial flash\n");
  465. }
  466. #endif
  467. return 0;
  468. error:
  469. /* Unwind the already registered devices. */
  470. ssb_devices_unregister(bus);
  471. return err;
  472. }
  473. /* Needs ssb_buses_lock() */
  474. static int ssb_attach_queued_buses(void)
  475. {
  476. struct ssb_bus *bus, *n;
  477. int err = 0;
  478. int drop_them_all = 0;
  479. list_for_each_entry_safe(bus, n, &attach_queue, list) {
  480. if (drop_them_all) {
  481. list_del(&bus->list);
  482. continue;
  483. }
  484. /* Can't init the PCIcore in ssb_bus_register(), as that
  485. * is too early in boot for embedded systems
  486. * (no udelay() available). So do it here in attach stage.
  487. */
  488. err = ssb_bus_powerup(bus, 0);
  489. if (err)
  490. goto error;
  491. ssb_pcicore_init(&bus->pcicore);
  492. if (bus->bustype == SSB_BUSTYPE_SSB)
  493. ssb_watchdog_register(bus);
  494. err = ssb_gpio_init(bus);
  495. if (err == -ENOTSUPP)
  496. ssb_dbg("GPIO driver not activated\n");
  497. else if (err)
  498. ssb_dbg("Error registering GPIO driver: %i\n", err);
  499. ssb_bus_may_powerdown(bus);
  500. err = ssb_devices_register(bus);
  501. error:
  502. if (err) {
  503. drop_them_all = 1;
  504. list_del(&bus->list);
  505. continue;
  506. }
  507. list_move_tail(&bus->list, &buses);
  508. }
  509. return err;
  510. }
  511. static int ssb_fetch_invariants(struct ssb_bus *bus,
  512. ssb_invariants_func_t get_invariants)
  513. {
  514. struct ssb_init_invariants iv;
  515. int err;
  516. memset(&iv, 0, sizeof(iv));
  517. err = get_invariants(bus, &iv);
  518. if (err)
  519. goto out;
  520. memcpy(&bus->boardinfo, &iv.boardinfo, sizeof(iv.boardinfo));
  521. memcpy(&bus->sprom, &iv.sprom, sizeof(iv.sprom));
  522. bus->has_cardbus_slot = iv.has_cardbus_slot;
  523. out:
  524. return err;
  525. }
  526. static int __maybe_unused
  527. ssb_bus_register(struct ssb_bus *bus,
  528. ssb_invariants_func_t get_invariants,
  529. unsigned long baseaddr)
  530. {
  531. int err;
  532. spin_lock_init(&bus->bar_lock);
  533. INIT_LIST_HEAD(&bus->list);
  534. #ifdef CONFIG_SSB_EMBEDDED
  535. spin_lock_init(&bus->gpio_lock);
  536. #endif
  537. /* Powerup the bus */
  538. err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
  539. if (err)
  540. goto out;
  541. /* Init SDIO-host device (if any), before the scan */
  542. err = ssb_sdio_init(bus);
  543. if (err)
  544. goto err_disable_xtal;
  545. ssb_buses_lock();
  546. bus->busnumber = next_busnumber;
  547. /* Scan for devices (cores) */
  548. err = ssb_bus_scan(bus, baseaddr);
  549. if (err)
  550. goto err_sdio_exit;
  551. /* Init PCI-host device (if any) */
  552. err = ssb_pci_init(bus);
  553. if (err)
  554. goto err_unmap;
  555. /* Init PCMCIA-host device (if any) */
  556. err = ssb_pcmcia_init(bus);
  557. if (err)
  558. goto err_pci_exit;
  559. /* Initialize basic system devices (if available) */
  560. err = ssb_bus_powerup(bus, 0);
  561. if (err)
  562. goto err_pcmcia_exit;
  563. ssb_chipcommon_init(&bus->chipco);
  564. ssb_extif_init(&bus->extif);
  565. ssb_mipscore_init(&bus->mipscore);
  566. err = ssb_fetch_invariants(bus, get_invariants);
  567. if (err) {
  568. ssb_bus_may_powerdown(bus);
  569. goto err_pcmcia_exit;
  570. }
  571. ssb_bus_may_powerdown(bus);
  572. /* Queue it for attach.
  573. * See the comment at the ssb_is_early_boot definition. */
  574. list_add_tail(&bus->list, &attach_queue);
  575. if (!ssb_is_early_boot) {
  576. /* This is not early boot, so we must attach the bus now */
  577. err = ssb_attach_queued_buses();
  578. if (err)
  579. goto err_dequeue;
  580. }
  581. next_busnumber++;
  582. ssb_buses_unlock();
  583. out:
  584. return err;
  585. err_dequeue:
  586. list_del(&bus->list);
  587. err_pcmcia_exit:
  588. ssb_pcmcia_exit(bus);
  589. err_pci_exit:
  590. ssb_pci_exit(bus);
  591. err_unmap:
  592. ssb_iounmap(bus);
  593. err_sdio_exit:
  594. ssb_sdio_exit(bus);
  595. err_disable_xtal:
  596. ssb_buses_unlock();
  597. ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
  598. return err;
  599. }
  600. #ifdef CONFIG_SSB_PCIHOST
  601. int ssb_bus_pcibus_register(struct ssb_bus *bus, struct pci_dev *host_pci)
  602. {
  603. int err;
  604. bus->bustype = SSB_BUSTYPE_PCI;
  605. bus->host_pci = host_pci;
  606. bus->ops = &ssb_pci_ops;
  607. err = ssb_bus_register(bus, ssb_pci_get_invariants, 0);
  608. if (!err) {
  609. ssb_info("Sonics Silicon Backplane found on PCI device %s\n",
  610. dev_name(&host_pci->dev));
  611. } else {
  612. ssb_err("Failed to register PCI version of SSB with error %d\n",
  613. err);
  614. }
  615. return err;
  616. }
  617. #endif /* CONFIG_SSB_PCIHOST */
  618. #ifdef CONFIG_SSB_PCMCIAHOST
  619. int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
  620. struct pcmcia_device *pcmcia_dev,
  621. unsigned long baseaddr)
  622. {
  623. int err;
  624. bus->bustype = SSB_BUSTYPE_PCMCIA;
  625. bus->host_pcmcia = pcmcia_dev;
  626. bus->ops = &ssb_pcmcia_ops;
  627. err = ssb_bus_register(bus, ssb_pcmcia_get_invariants, baseaddr);
  628. if (!err) {
  629. ssb_info("Sonics Silicon Backplane found on PCMCIA device %s\n",
  630. pcmcia_dev->devname);
  631. }
  632. return err;
  633. }
  634. #endif /* CONFIG_SSB_PCMCIAHOST */
  635. #ifdef CONFIG_SSB_SDIOHOST
  636. int ssb_bus_sdiobus_register(struct ssb_bus *bus, struct sdio_func *func,
  637. unsigned int quirks)
  638. {
  639. int err;
  640. bus->bustype = SSB_BUSTYPE_SDIO;
  641. bus->host_sdio = func;
  642. bus->ops = &ssb_sdio_ops;
  643. bus->quirks = quirks;
  644. err = ssb_bus_register(bus, ssb_sdio_get_invariants, ~0);
  645. if (!err) {
  646. ssb_info("Sonics Silicon Backplane found on SDIO device %s\n",
  647. sdio_func_id(func));
  648. }
  649. return err;
  650. }
  651. EXPORT_SYMBOL(ssb_bus_sdiobus_register);
  652. #endif /* CONFIG_SSB_PCMCIAHOST */
  653. #ifdef CONFIG_SSB_HOST_SOC
  654. int ssb_bus_host_soc_register(struct ssb_bus *bus, unsigned long baseaddr)
  655. {
  656. int err;
  657. bus->bustype = SSB_BUSTYPE_SSB;
  658. bus->ops = &ssb_host_soc_ops;
  659. err = ssb_bus_register(bus, ssb_host_soc_get_invariants, baseaddr);
  660. if (!err) {
  661. ssb_info("Sonics Silicon Backplane found at address 0x%08lX\n",
  662. baseaddr);
  663. }
  664. return err;
  665. }
  666. #endif
  667. int __ssb_driver_register(struct ssb_driver *drv, struct module *owner)
  668. {
  669. drv->drv.name = drv->name;
  670. drv->drv.bus = &ssb_bustype;
  671. drv->drv.owner = owner;
  672. return driver_register(&drv->drv);
  673. }
  674. EXPORT_SYMBOL(__ssb_driver_register);
  675. void ssb_driver_unregister(struct ssb_driver *drv)
  676. {
  677. driver_unregister(&drv->drv);
  678. }
  679. EXPORT_SYMBOL(ssb_driver_unregister);
  680. void ssb_set_devtypedata(struct ssb_device *dev, void *data)
  681. {
  682. struct ssb_bus *bus = dev->bus;
  683. struct ssb_device *ent;
  684. int i;
  685. for (i = 0; i < bus->nr_devices; i++) {
  686. ent = &(bus->devices[i]);
  687. if (ent->id.vendor != dev->id.vendor)
  688. continue;
  689. if (ent->id.coreid != dev->id.coreid)
  690. continue;
  691. ent->devtypedata = data;
  692. }
  693. }
  694. EXPORT_SYMBOL(ssb_set_devtypedata);
  695. static u32 clkfactor_f6_resolve(u32 v)
  696. {
  697. /* map the magic values */
  698. switch (v) {
  699. case SSB_CHIPCO_CLK_F6_2:
  700. return 2;
  701. case SSB_CHIPCO_CLK_F6_3:
  702. return 3;
  703. case SSB_CHIPCO_CLK_F6_4:
  704. return 4;
  705. case SSB_CHIPCO_CLK_F6_5:
  706. return 5;
  707. case SSB_CHIPCO_CLK_F6_6:
  708. return 6;
  709. case SSB_CHIPCO_CLK_F6_7:
  710. return 7;
  711. }
  712. return 0;
  713. }
  714. /* Calculate the speed the backplane would run at a given set of clockcontrol values */
  715. u32 ssb_calc_clock_rate(u32 plltype, u32 n, u32 m)
  716. {
  717. u32 n1, n2, clock, m1, m2, m3, mc;
  718. n1 = (n & SSB_CHIPCO_CLK_N1);
  719. n2 = ((n & SSB_CHIPCO_CLK_N2) >> SSB_CHIPCO_CLK_N2_SHIFT);
  720. switch (plltype) {
  721. case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */
  722. if (m & SSB_CHIPCO_CLK_T6_MMASK)
  723. return SSB_CHIPCO_CLK_T6_M1;
  724. return SSB_CHIPCO_CLK_T6_M0;
  725. case SSB_PLLTYPE_1: /* 48Mhz base, 3 dividers */
  726. case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
  727. case SSB_PLLTYPE_4: /* 48Mhz, 4 dividers */
  728. case SSB_PLLTYPE_7: /* 25Mhz, 4 dividers */
  729. n1 = clkfactor_f6_resolve(n1);
  730. n2 += SSB_CHIPCO_CLK_F5_BIAS;
  731. break;
  732. case SSB_PLLTYPE_2: /* 48Mhz, 4 dividers */
  733. n1 += SSB_CHIPCO_CLK_T2_BIAS;
  734. n2 += SSB_CHIPCO_CLK_T2_BIAS;
  735. SSB_WARN_ON(!((n1 >= 2) && (n1 <= 7)));
  736. SSB_WARN_ON(!((n2 >= 5) && (n2 <= 23)));
  737. break;
  738. case SSB_PLLTYPE_5: /* 25Mhz, 4 dividers */
  739. return 100000000;
  740. default:
  741. SSB_WARN_ON(1);
  742. }
  743. switch (plltype) {
  744. case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
  745. case SSB_PLLTYPE_7: /* 25Mhz, 4 dividers */
  746. clock = SSB_CHIPCO_CLK_BASE2 * n1 * n2;
  747. break;
  748. default:
  749. clock = SSB_CHIPCO_CLK_BASE1 * n1 * n2;
  750. }
  751. if (!clock)
  752. return 0;
  753. m1 = (m & SSB_CHIPCO_CLK_M1);
  754. m2 = ((m & SSB_CHIPCO_CLK_M2) >> SSB_CHIPCO_CLK_M2_SHIFT);
  755. m3 = ((m & SSB_CHIPCO_CLK_M3) >> SSB_CHIPCO_CLK_M3_SHIFT);
  756. mc = ((m & SSB_CHIPCO_CLK_MC) >> SSB_CHIPCO_CLK_MC_SHIFT);
  757. switch (plltype) {
  758. case SSB_PLLTYPE_1: /* 48Mhz base, 3 dividers */
  759. case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
  760. case SSB_PLLTYPE_4: /* 48Mhz, 4 dividers */
  761. case SSB_PLLTYPE_7: /* 25Mhz, 4 dividers */
  762. m1 = clkfactor_f6_resolve(m1);
  763. if ((plltype == SSB_PLLTYPE_1) ||
  764. (plltype == SSB_PLLTYPE_3))
  765. m2 += SSB_CHIPCO_CLK_F5_BIAS;
  766. else
  767. m2 = clkfactor_f6_resolve(m2);
  768. m3 = clkfactor_f6_resolve(m3);
  769. switch (mc) {
  770. case SSB_CHIPCO_CLK_MC_BYPASS:
  771. return clock;
  772. case SSB_CHIPCO_CLK_MC_M1:
  773. return (clock / m1);
  774. case SSB_CHIPCO_CLK_MC_M1M2:
  775. return (clock / (m1 * m2));
  776. case SSB_CHIPCO_CLK_MC_M1M2M3:
  777. return (clock / (m1 * m2 * m3));
  778. case SSB_CHIPCO_CLK_MC_M1M3:
  779. return (clock / (m1 * m3));
  780. }
  781. return 0;
  782. case SSB_PLLTYPE_2:
  783. m1 += SSB_CHIPCO_CLK_T2_BIAS;
  784. m2 += SSB_CHIPCO_CLK_T2M2_BIAS;
  785. m3 += SSB_CHIPCO_CLK_T2_BIAS;
  786. SSB_WARN_ON(!((m1 >= 2) && (m1 <= 7)));
  787. SSB_WARN_ON(!((m2 >= 3) && (m2 <= 10)));
  788. SSB_WARN_ON(!((m3 >= 2) && (m3 <= 7)));
  789. if (!(mc & SSB_CHIPCO_CLK_T2MC_M1BYP))
  790. clock /= m1;
  791. if (!(mc & SSB_CHIPCO_CLK_T2MC_M2BYP))
  792. clock /= m2;
  793. if (!(mc & SSB_CHIPCO_CLK_T2MC_M3BYP))
  794. clock /= m3;
  795. return clock;
  796. default:
  797. SSB_WARN_ON(1);
  798. }
  799. return 0;
  800. }
  801. /* Get the current speed the backplane is running at */
  802. u32 ssb_clockspeed(struct ssb_bus *bus)
  803. {
  804. u32 rate;
  805. u32 plltype;
  806. u32 clkctl_n, clkctl_m;
  807. if (bus->chipco.capabilities & SSB_CHIPCO_CAP_PMU)
  808. return ssb_pmu_get_controlclock(&bus->chipco);
  809. if (ssb_extif_available(&bus->extif))
  810. ssb_extif_get_clockcontrol(&bus->extif, &plltype,
  811. &clkctl_n, &clkctl_m);
  812. else if (bus->chipco.dev)
  813. ssb_chipco_get_clockcontrol(&bus->chipco, &plltype,
  814. &clkctl_n, &clkctl_m);
  815. else
  816. return 0;
  817. if (bus->chip_id == 0x5365) {
  818. rate = 100000000;
  819. } else {
  820. rate = ssb_calc_clock_rate(plltype, clkctl_n, clkctl_m);
  821. if (plltype == SSB_PLLTYPE_3) /* 25Mhz, 2 dividers */
  822. rate /= 2;
  823. }
  824. return rate;
  825. }
  826. EXPORT_SYMBOL(ssb_clockspeed);
  827. static u32 ssb_tmslow_reject_bitmask(struct ssb_device *dev)
  828. {
  829. u32 rev = ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_SSBREV;
  830. /* The REJECT bit seems to be different for Backplane rev 2.3 */
  831. switch (rev) {
  832. case SSB_IDLOW_SSBREV_22:
  833. case SSB_IDLOW_SSBREV_24:
  834. case SSB_IDLOW_SSBREV_26:
  835. return SSB_TMSLOW_REJECT;
  836. case SSB_IDLOW_SSBREV_23:
  837. return SSB_TMSLOW_REJECT_23;
  838. case SSB_IDLOW_SSBREV_25: /* TODO - find the proper REJECT bit */
  839. case SSB_IDLOW_SSBREV_27: /* same here */
  840. return SSB_TMSLOW_REJECT; /* this is a guess */
  841. case SSB_IDLOW_SSBREV:
  842. break;
  843. default:
  844. WARN(1, KERN_INFO "ssb: Backplane Revision 0x%.8X\n", rev);
  845. }
  846. return (SSB_TMSLOW_REJECT | SSB_TMSLOW_REJECT_23);
  847. }
  848. int ssb_device_is_enabled(struct ssb_device *dev)
  849. {
  850. u32 val;
  851. u32 reject;
  852. reject = ssb_tmslow_reject_bitmask(dev);
  853. val = ssb_read32(dev, SSB_TMSLOW);
  854. val &= SSB_TMSLOW_CLOCK | SSB_TMSLOW_RESET | reject;
  855. return (val == SSB_TMSLOW_CLOCK);
  856. }
  857. EXPORT_SYMBOL(ssb_device_is_enabled);
  858. static void ssb_flush_tmslow(struct ssb_device *dev)
  859. {
  860. /* Make _really_ sure the device has finished the TMSLOW
  861. * register write transaction, as we risk running into
  862. * a machine check exception otherwise.
  863. * Do this by reading the register back to commit the
  864. * PCI write and delay an additional usec for the device
  865. * to react to the change. */
  866. ssb_read32(dev, SSB_TMSLOW);
  867. udelay(1);
  868. }
  869. void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags)
  870. {
  871. u32 val;
  872. ssb_device_disable(dev, core_specific_flags);
  873. ssb_write32(dev, SSB_TMSLOW,
  874. SSB_TMSLOW_RESET | SSB_TMSLOW_CLOCK |
  875. SSB_TMSLOW_FGC | core_specific_flags);
  876. ssb_flush_tmslow(dev);
  877. /* Clear SERR if set. This is a hw bug workaround. */
  878. if (ssb_read32(dev, SSB_TMSHIGH) & SSB_TMSHIGH_SERR)
  879. ssb_write32(dev, SSB_TMSHIGH, 0);
  880. val = ssb_read32(dev, SSB_IMSTATE);
  881. if (val & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO)) {
  882. val &= ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO);
  883. ssb_write32(dev, SSB_IMSTATE, val);
  884. }
  885. ssb_write32(dev, SSB_TMSLOW,
  886. SSB_TMSLOW_CLOCK | SSB_TMSLOW_FGC |
  887. core_specific_flags);
  888. ssb_flush_tmslow(dev);
  889. ssb_write32(dev, SSB_TMSLOW, SSB_TMSLOW_CLOCK |
  890. core_specific_flags);
  891. ssb_flush_tmslow(dev);
  892. }
  893. EXPORT_SYMBOL(ssb_device_enable);
  894. /* Wait for bitmask in a register to get set or cleared.
  895. * timeout is in units of ten-microseconds */
  896. static int ssb_wait_bits(struct ssb_device *dev, u16 reg, u32 bitmask,
  897. int timeout, int set)
  898. {
  899. int i;
  900. u32 val;
  901. for (i = 0; i < timeout; i++) {
  902. val = ssb_read32(dev, reg);
  903. if (set) {
  904. if ((val & bitmask) == bitmask)
  905. return 0;
  906. } else {
  907. if (!(val & bitmask))
  908. return 0;
  909. }
  910. udelay(10);
  911. }
  912. printk(KERN_ERR PFX "Timeout waiting for bitmask %08X on "
  913. "register %04X to %s.\n",
  914. bitmask, reg, (set ? "set" : "clear"));
  915. return -ETIMEDOUT;
  916. }
  917. void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags)
  918. {
  919. u32 reject, val;
  920. if (ssb_read32(dev, SSB_TMSLOW) & SSB_TMSLOW_RESET)
  921. return;
  922. reject = ssb_tmslow_reject_bitmask(dev);
  923. if (ssb_read32(dev, SSB_TMSLOW) & SSB_TMSLOW_CLOCK) {
  924. ssb_write32(dev, SSB_TMSLOW, reject | SSB_TMSLOW_CLOCK);
  925. ssb_wait_bits(dev, SSB_TMSLOW, reject, 1000, 1);
  926. ssb_wait_bits(dev, SSB_TMSHIGH, SSB_TMSHIGH_BUSY, 1000, 0);
  927. if (ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_INITIATOR) {
  928. val = ssb_read32(dev, SSB_IMSTATE);
  929. val |= SSB_IMSTATE_REJECT;
  930. ssb_write32(dev, SSB_IMSTATE, val);
  931. ssb_wait_bits(dev, SSB_IMSTATE, SSB_IMSTATE_BUSY, 1000,
  932. 0);
  933. }
  934. ssb_write32(dev, SSB_TMSLOW,
  935. SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
  936. reject | SSB_TMSLOW_RESET |
  937. core_specific_flags);
  938. ssb_flush_tmslow(dev);
  939. if (ssb_read32(dev, SSB_IDLOW) & SSB_IDLOW_INITIATOR) {
  940. val = ssb_read32(dev, SSB_IMSTATE);
  941. val &= ~SSB_IMSTATE_REJECT;
  942. ssb_write32(dev, SSB_IMSTATE, val);
  943. }
  944. }
  945. ssb_write32(dev, SSB_TMSLOW,
  946. reject | SSB_TMSLOW_RESET |
  947. core_specific_flags);
  948. ssb_flush_tmslow(dev);
  949. }
  950. EXPORT_SYMBOL(ssb_device_disable);
  951. /* Some chipsets need routing known for PCIe and 64-bit DMA */
  952. static bool ssb_dma_translation_special_bit(struct ssb_device *dev)
  953. {
  954. u16 chip_id = dev->bus->chip_id;
  955. if (dev->id.coreid == SSB_DEV_80211) {
  956. return (chip_id == 0x4322 || chip_id == 43221 ||
  957. chip_id == 43231 || chip_id == 43222);
  958. }
  959. return 0;
  960. }
  961. u32 ssb_dma_translation(struct ssb_device *dev)
  962. {
  963. switch (dev->bus->bustype) {
  964. case SSB_BUSTYPE_SSB:
  965. return 0;
  966. case SSB_BUSTYPE_PCI:
  967. if (pci_is_pcie(dev->bus->host_pci) &&
  968. ssb_read32(dev, SSB_TMSHIGH) & SSB_TMSHIGH_DMA64) {
  969. return SSB_PCIE_DMA_H32;
  970. } else {
  971. if (ssb_dma_translation_special_bit(dev))
  972. return SSB_PCIE_DMA_H32;
  973. else
  974. return SSB_PCI_DMA;
  975. }
  976. default:
  977. __ssb_dma_not_implemented(dev);
  978. }
  979. return 0;
  980. }
  981. EXPORT_SYMBOL(ssb_dma_translation);
  982. int ssb_bus_may_powerdown(struct ssb_bus *bus)
  983. {
  984. struct ssb_chipcommon *cc;
  985. int err = 0;
  986. /* On buses where more than one core may be working
  987. * at a time, we must not powerdown stuff if there are
  988. * still cores that may want to run. */
  989. if (bus->bustype == SSB_BUSTYPE_SSB)
  990. goto out;
  991. cc = &bus->chipco;
  992. if (!cc->dev)
  993. goto out;
  994. if (cc->dev->id.revision < 5)
  995. goto out;
  996. ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW);
  997. err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 0);
  998. if (err)
  999. goto error;
  1000. out:
  1001. #ifdef CONFIG_SSB_DEBUG
  1002. bus->powered_up = 0;
  1003. #endif
  1004. return err;
  1005. error:
  1006. ssb_err("Bus powerdown failed\n");
  1007. goto out;
  1008. }
  1009. EXPORT_SYMBOL(ssb_bus_may_powerdown);
  1010. int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl)
  1011. {
  1012. int err;
  1013. enum ssb_clkmode mode;
  1014. err = ssb_pci_xtal(bus, SSB_GPIO_XTAL | SSB_GPIO_PLL, 1);
  1015. if (err)
  1016. goto error;
  1017. #ifdef CONFIG_SSB_DEBUG
  1018. bus->powered_up = 1;
  1019. #endif
  1020. mode = dynamic_pctl ? SSB_CLKMODE_DYNAMIC : SSB_CLKMODE_FAST;
  1021. ssb_chipco_set_clockmode(&bus->chipco, mode);
  1022. return 0;
  1023. error:
  1024. ssb_err("Bus powerup failed\n");
  1025. return err;
  1026. }
  1027. EXPORT_SYMBOL(ssb_bus_powerup);
  1028. static void ssb_broadcast_value(struct ssb_device *dev,
  1029. u32 address, u32 data)
  1030. {
  1031. #ifdef CONFIG_SSB_DRIVER_PCICORE
  1032. /* This is used for both, PCI and ChipCommon core, so be careful. */
  1033. BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR);
  1034. BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA);
  1035. #endif
  1036. ssb_write32(dev, SSB_CHIPCO_BCAST_ADDR, address);
  1037. ssb_read32(dev, SSB_CHIPCO_BCAST_ADDR); /* flush */
  1038. ssb_write32(dev, SSB_CHIPCO_BCAST_DATA, data);
  1039. ssb_read32(dev, SSB_CHIPCO_BCAST_DATA); /* flush */
  1040. }
  1041. void ssb_commit_settings(struct ssb_bus *bus)
  1042. {
  1043. struct ssb_device *dev;
  1044. #ifdef CONFIG_SSB_DRIVER_PCICORE
  1045. dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
  1046. #else
  1047. dev = bus->chipco.dev;
  1048. #endif
  1049. if (WARN_ON(!dev))
  1050. return;
  1051. /* This forces an update of the cached registers. */
  1052. ssb_broadcast_value(dev, 0xFD8, 0);
  1053. }
  1054. EXPORT_SYMBOL(ssb_commit_settings);
  1055. u32 ssb_admatch_base(u32 adm)
  1056. {
  1057. u32 base = 0;
  1058. switch (adm & SSB_ADM_TYPE) {
  1059. case SSB_ADM_TYPE0:
  1060. base = (adm & SSB_ADM_BASE0);
  1061. break;
  1062. case SSB_ADM_TYPE1:
  1063. SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
  1064. base = (adm & SSB_ADM_BASE1);
  1065. break;
  1066. case SSB_ADM_TYPE2:
  1067. SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
  1068. base = (adm & SSB_ADM_BASE2);
  1069. break;
  1070. default:
  1071. SSB_WARN_ON(1);
  1072. }
  1073. return base;
  1074. }
  1075. EXPORT_SYMBOL(ssb_admatch_base);
  1076. u32 ssb_admatch_size(u32 adm)
  1077. {
  1078. u32 size = 0;
  1079. switch (adm & SSB_ADM_TYPE) {
  1080. case SSB_ADM_TYPE0:
  1081. size = ((adm & SSB_ADM_SZ0) >> SSB_ADM_SZ0_SHIFT);
  1082. break;
  1083. case SSB_ADM_TYPE1:
  1084. SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
  1085. size = ((adm & SSB_ADM_SZ1) >> SSB_ADM_SZ1_SHIFT);
  1086. break;
  1087. case SSB_ADM_TYPE2:
  1088. SSB_WARN_ON(adm & SSB_ADM_NEG); /* unsupported */
  1089. size = ((adm & SSB_ADM_SZ2) >> SSB_ADM_SZ2_SHIFT);
  1090. break;
  1091. default:
  1092. SSB_WARN_ON(1);
  1093. }
  1094. size = (1 << (size + 1));
  1095. return size;
  1096. }
  1097. EXPORT_SYMBOL(ssb_admatch_size);
  1098. static int __init ssb_modinit(void)
  1099. {
  1100. int err;
  1101. /* See the comment at the ssb_is_early_boot definition */
  1102. ssb_is_early_boot = 0;
  1103. err = bus_register(&ssb_bustype);
  1104. if (err)
  1105. return err;
  1106. /* Maybe we already registered some buses at early boot.
  1107. * Check for this and attach them
  1108. */
  1109. ssb_buses_lock();
  1110. err = ssb_attach_queued_buses();
  1111. ssb_buses_unlock();
  1112. if (err) {
  1113. bus_unregister(&ssb_bustype);
  1114. goto out;
  1115. }
  1116. err = b43_pci_ssb_bridge_init();
  1117. if (err) {
  1118. ssb_err("Broadcom 43xx PCI-SSB-bridge initialization failed\n");
  1119. /* don't fail SSB init because of this */
  1120. err = 0;
  1121. }
  1122. err = ssb_host_pcmcia_init();
  1123. if (err) {
  1124. ssb_err("PCMCIA host initialization failed\n");
  1125. /* don't fail SSB init because of this */
  1126. err = 0;
  1127. }
  1128. err = ssb_gige_init();
  1129. if (err) {
  1130. ssb_err("SSB Broadcom Gigabit Ethernet driver initialization failed\n");
  1131. /* don't fail SSB init because of this */
  1132. err = 0;
  1133. }
  1134. out:
  1135. return err;
  1136. }
  1137. /* ssb must be initialized after PCI but before the ssb drivers.
  1138. * That means we must use some initcall between subsys_initcall
  1139. * and device_initcall. */
  1140. fs_initcall(ssb_modinit);
  1141. static void __exit ssb_modexit(void)
  1142. {
  1143. ssb_gige_exit();
  1144. ssb_host_pcmcia_exit();
  1145. b43_pci_ssb_bridge_exit();
  1146. bus_unregister(&ssb_bustype);
  1147. }
  1148. module_exit(ssb_modexit)