scan.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * Sonics Silicon Backplane
  3. * Bus scanning
  4. *
  5. * Copyright (C) 2005-2007 Michael Buesch <mb@bu3sch.de>
  6. * Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
  7. * Copyright (C) 2005 Stefano Brivio <st3@riseup.net>
  8. * Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
  9. * Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  10. * Copyright (C) 2006 Broadcom Corporation.
  11. *
  12. * Licensed under the GNU/GPL. See COPYING for details.
  13. */
  14. #include <linux/ssb/ssb.h>
  15. #include <linux/ssb/ssb_regs.h>
  16. #include <linux/pci.h>
  17. #include <linux/io.h>
  18. #include <pcmcia/cistpl.h>
  19. #include <pcmcia/ds.h>
  20. #include "ssb_private.h"
  21. const char *ssb_core_name(u16 coreid)
  22. {
  23. switch (coreid) {
  24. case SSB_DEV_CHIPCOMMON:
  25. return "ChipCommon";
  26. case SSB_DEV_ILINE20:
  27. return "ILine 20";
  28. case SSB_DEV_SDRAM:
  29. return "SDRAM";
  30. case SSB_DEV_PCI:
  31. return "PCI";
  32. case SSB_DEV_MIPS:
  33. return "MIPS";
  34. case SSB_DEV_ETHERNET:
  35. return "Fast Ethernet";
  36. case SSB_DEV_V90:
  37. return "V90";
  38. case SSB_DEV_USB11_HOSTDEV:
  39. return "USB 1.1 Hostdev";
  40. case SSB_DEV_ADSL:
  41. return "ADSL";
  42. case SSB_DEV_ILINE100:
  43. return "ILine 100";
  44. case SSB_DEV_IPSEC:
  45. return "IPSEC";
  46. case SSB_DEV_PCMCIA:
  47. return "PCMCIA";
  48. case SSB_DEV_INTERNAL_MEM:
  49. return "Internal Memory";
  50. case SSB_DEV_MEMC_SDRAM:
  51. return "MEMC SDRAM";
  52. case SSB_DEV_EXTIF:
  53. return "EXTIF";
  54. case SSB_DEV_80211:
  55. return "IEEE 802.11";
  56. case SSB_DEV_MIPS_3302:
  57. return "MIPS 3302";
  58. case SSB_DEV_USB11_HOST:
  59. return "USB 1.1 Host";
  60. case SSB_DEV_USB11_DEV:
  61. return "USB 1.1 Device";
  62. case SSB_DEV_USB20_HOST:
  63. return "USB 2.0 Host";
  64. case SSB_DEV_USB20_DEV:
  65. return "USB 2.0 Device";
  66. case SSB_DEV_SDIO_HOST:
  67. return "SDIO Host";
  68. case SSB_DEV_ROBOSWITCH:
  69. return "Roboswitch";
  70. case SSB_DEV_PARA_ATA:
  71. return "PATA";
  72. case SSB_DEV_SATA_XORDMA:
  73. return "SATA XOR-DMA";
  74. case SSB_DEV_ETHERNET_GBIT:
  75. return "GBit Ethernet";
  76. case SSB_DEV_PCIE:
  77. return "PCI-E";
  78. case SSB_DEV_MIMO_PHY:
  79. return "MIMO PHY";
  80. case SSB_DEV_SRAM_CTRLR:
  81. return "SRAM Controller";
  82. case SSB_DEV_MINI_MACPHY:
  83. return "Mini MACPHY";
  84. case SSB_DEV_ARM_1176:
  85. return "ARM 1176";
  86. case SSB_DEV_ARM_7TDMI:
  87. return "ARM 7TDMI";
  88. }
  89. return "UNKNOWN";
  90. }
  91. static u16 pcidev_to_chipid(struct pci_dev *pci_dev)
  92. {
  93. u16 chipid_fallback = 0;
  94. switch (pci_dev->device) {
  95. case 0x4301:
  96. chipid_fallback = 0x4301;
  97. break;
  98. case 0x4305 ... 0x4307:
  99. chipid_fallback = 0x4307;
  100. break;
  101. case 0x4403:
  102. chipid_fallback = 0x4402;
  103. break;
  104. case 0x4610 ... 0x4615:
  105. chipid_fallback = 0x4610;
  106. break;
  107. case 0x4710 ... 0x4715:
  108. chipid_fallback = 0x4710;
  109. break;
  110. case 0x4320 ... 0x4325:
  111. chipid_fallback = 0x4309;
  112. break;
  113. case PCI_DEVICE_ID_BCM4401:
  114. case PCI_DEVICE_ID_BCM4401B0:
  115. case PCI_DEVICE_ID_BCM4401B1:
  116. chipid_fallback = 0x4401;
  117. break;
  118. default:
  119. ssb_printk(KERN_ERR PFX
  120. "PCI-ID not in fallback list\n");
  121. }
  122. return chipid_fallback;
  123. }
  124. static u8 chipid_to_nrcores(u16 chipid)
  125. {
  126. switch (chipid) {
  127. case 0x5365:
  128. return 7;
  129. case 0x4306:
  130. return 6;
  131. case 0x4310:
  132. return 8;
  133. case 0x4307:
  134. case 0x4301:
  135. return 5;
  136. case 0x4401:
  137. case 0x4402:
  138. return 3;
  139. case 0x4710:
  140. case 0x4610:
  141. case 0x4704:
  142. return 9;
  143. default:
  144. ssb_printk(KERN_ERR PFX
  145. "CHIPID not in nrcores fallback list\n");
  146. }
  147. return 1;
  148. }
  149. static u32 scan_read32(struct ssb_bus *bus, u8 current_coreidx,
  150. u16 offset)
  151. {
  152. u32 lo, hi;
  153. switch (bus->bustype) {
  154. case SSB_BUSTYPE_SSB:
  155. offset += current_coreidx * SSB_CORE_SIZE;
  156. break;
  157. case SSB_BUSTYPE_PCI:
  158. break;
  159. case SSB_BUSTYPE_PCMCIA:
  160. if (offset >= 0x800) {
  161. ssb_pcmcia_switch_segment(bus, 1);
  162. offset -= 0x800;
  163. } else
  164. ssb_pcmcia_switch_segment(bus, 0);
  165. lo = readw(bus->mmio + offset);
  166. hi = readw(bus->mmio + offset + 2);
  167. return lo | (hi << 16);
  168. case SSB_BUSTYPE_SDIO:
  169. offset += current_coreidx * SSB_CORE_SIZE;
  170. return ssb_sdio_scan_read32(bus, offset);
  171. }
  172. return readl(bus->mmio + offset);
  173. }
  174. static int scan_switchcore(struct ssb_bus *bus, u8 coreidx)
  175. {
  176. switch (bus->bustype) {
  177. case SSB_BUSTYPE_SSB:
  178. break;
  179. case SSB_BUSTYPE_PCI:
  180. return ssb_pci_switch_coreidx(bus, coreidx);
  181. case SSB_BUSTYPE_PCMCIA:
  182. return ssb_pcmcia_switch_coreidx(bus, coreidx);
  183. case SSB_BUSTYPE_SDIO:
  184. return ssb_sdio_scan_switch_coreidx(bus, coreidx);
  185. }
  186. return 0;
  187. }
  188. void ssb_iounmap(struct ssb_bus *bus)
  189. {
  190. switch (bus->bustype) {
  191. case SSB_BUSTYPE_SSB:
  192. case SSB_BUSTYPE_PCMCIA:
  193. iounmap(bus->mmio);
  194. break;
  195. case SSB_BUSTYPE_PCI:
  196. #ifdef CONFIG_SSB_PCIHOST
  197. pci_iounmap(bus->host_pci, bus->mmio);
  198. #else
  199. SSB_BUG_ON(1); /* Can't reach this code. */
  200. #endif
  201. break;
  202. case SSB_BUSTYPE_SDIO:
  203. break;
  204. }
  205. bus->mmio = NULL;
  206. bus->mapped_device = NULL;
  207. }
  208. static void __iomem *ssb_ioremap(struct ssb_bus *bus,
  209. unsigned long baseaddr)
  210. {
  211. void __iomem *mmio = NULL;
  212. switch (bus->bustype) {
  213. case SSB_BUSTYPE_SSB:
  214. /* Only map the first core for now. */
  215. /* fallthrough... */
  216. case SSB_BUSTYPE_PCMCIA:
  217. mmio = ioremap(baseaddr, SSB_CORE_SIZE);
  218. break;
  219. case SSB_BUSTYPE_PCI:
  220. #ifdef CONFIG_SSB_PCIHOST
  221. mmio = pci_iomap(bus->host_pci, 0, ~0UL);
  222. #else
  223. SSB_BUG_ON(1); /* Can't reach this code. */
  224. #endif
  225. break;
  226. case SSB_BUSTYPE_SDIO:
  227. /* Nothing to ioremap in the SDIO case, just fake it */
  228. mmio = (void __iomem *)baseaddr;
  229. break;
  230. }
  231. return mmio;
  232. }
  233. static int we_support_multiple_80211_cores(struct ssb_bus *bus)
  234. {
  235. /* More than one 802.11 core is only supported by special chips.
  236. * There are chips with two 802.11 cores, but with dangling
  237. * pins on the second core. Be careful and reject them here.
  238. */
  239. #ifdef CONFIG_SSB_PCIHOST
  240. if (bus->bustype == SSB_BUSTYPE_PCI) {
  241. if (bus->host_pci->vendor == PCI_VENDOR_ID_BROADCOM &&
  242. ((bus->host_pci->device == 0x4313) ||
  243. (bus->host_pci->device == 0x431A) ||
  244. (bus->host_pci->device == 0x4321) ||
  245. (bus->host_pci->device == 0x4324)))
  246. return 1;
  247. }
  248. #endif /* CONFIG_SSB_PCIHOST */
  249. return 0;
  250. }
  251. int ssb_bus_scan(struct ssb_bus *bus,
  252. unsigned long baseaddr)
  253. {
  254. int err = -ENOMEM;
  255. void __iomem *mmio;
  256. u32 idhi, cc, rev, tmp;
  257. int dev_i, i;
  258. struct ssb_device *dev;
  259. int nr_80211_cores = 0;
  260. mmio = ssb_ioremap(bus, baseaddr);
  261. if (!mmio)
  262. goto out;
  263. bus->mmio = mmio;
  264. err = scan_switchcore(bus, 0); /* Switch to first core */
  265. if (err)
  266. goto err_unmap;
  267. idhi = scan_read32(bus, 0, SSB_IDHIGH);
  268. cc = (idhi & SSB_IDHIGH_CC) >> SSB_IDHIGH_CC_SHIFT;
  269. rev = (idhi & SSB_IDHIGH_RCLO);
  270. rev |= (idhi & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT;
  271. bus->nr_devices = 0;
  272. if (cc == SSB_DEV_CHIPCOMMON) {
  273. tmp = scan_read32(bus, 0, SSB_CHIPCO_CHIPID);
  274. bus->chip_id = (tmp & SSB_CHIPCO_IDMASK);
  275. bus->chip_rev = (tmp & SSB_CHIPCO_REVMASK) >>
  276. SSB_CHIPCO_REVSHIFT;
  277. bus->chip_package = (tmp & SSB_CHIPCO_PACKMASK) >>
  278. SSB_CHIPCO_PACKSHIFT;
  279. if (rev >= 4) {
  280. bus->nr_devices = (tmp & SSB_CHIPCO_NRCORESMASK) >>
  281. SSB_CHIPCO_NRCORESSHIFT;
  282. }
  283. tmp = scan_read32(bus, 0, SSB_CHIPCO_CAP);
  284. bus->chipco.capabilities = tmp;
  285. } else {
  286. if (bus->bustype == SSB_BUSTYPE_PCI) {
  287. bus->chip_id = pcidev_to_chipid(bus->host_pci);
  288. pci_read_config_byte(bus->host_pci, PCI_REVISION_ID,
  289. &bus->chip_rev);
  290. bus->chip_package = 0;
  291. } else {
  292. bus->chip_id = 0x4710;
  293. bus->chip_rev = 0;
  294. bus->chip_package = 0;
  295. }
  296. }
  297. if (!bus->nr_devices)
  298. bus->nr_devices = chipid_to_nrcores(bus->chip_id);
  299. if (bus->nr_devices > ARRAY_SIZE(bus->devices)) {
  300. ssb_printk(KERN_ERR PFX
  301. "More than %d ssb cores found (%d)\n",
  302. SSB_MAX_NR_CORES, bus->nr_devices);
  303. goto err_unmap;
  304. }
  305. if (bus->bustype == SSB_BUSTYPE_SSB) {
  306. /* Now that we know the number of cores,
  307. * remap the whole IO space for all cores.
  308. */
  309. err = -ENOMEM;
  310. iounmap(mmio);
  311. mmio = ioremap(baseaddr, SSB_CORE_SIZE * bus->nr_devices);
  312. if (!mmio)
  313. goto out;
  314. bus->mmio = mmio;
  315. }
  316. /* Fetch basic information about each core/device */
  317. for (i = 0, dev_i = 0; i < bus->nr_devices; i++) {
  318. err = scan_switchcore(bus, i);
  319. if (err)
  320. goto err_unmap;
  321. dev = &(bus->devices[dev_i]);
  322. idhi = scan_read32(bus, i, SSB_IDHIGH);
  323. dev->id.coreid = (idhi & SSB_IDHIGH_CC) >> SSB_IDHIGH_CC_SHIFT;
  324. dev->id.revision = (idhi & SSB_IDHIGH_RCLO);
  325. dev->id.revision |= (idhi & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT;
  326. dev->id.vendor = (idhi & SSB_IDHIGH_VC) >> SSB_IDHIGH_VC_SHIFT;
  327. dev->core_index = i;
  328. dev->bus = bus;
  329. dev->ops = bus->ops;
  330. printk(KERN_DEBUG PFX
  331. "Core %d found: %s "
  332. "(cc 0x%03X, rev 0x%02X, vendor 0x%04X)\n",
  333. i, ssb_core_name(dev->id.coreid),
  334. dev->id.coreid, dev->id.revision, dev->id.vendor);
  335. switch (dev->id.coreid) {
  336. case SSB_DEV_80211:
  337. nr_80211_cores++;
  338. if (nr_80211_cores > 1) {
  339. if (!we_support_multiple_80211_cores(bus)) {
  340. ssb_dprintk(KERN_INFO PFX "Ignoring additional "
  341. "802.11 core\n");
  342. continue;
  343. }
  344. }
  345. break;
  346. case SSB_DEV_EXTIF:
  347. #ifdef CONFIG_SSB_DRIVER_EXTIF
  348. if (bus->extif.dev) {
  349. ssb_printk(KERN_WARNING PFX
  350. "WARNING: Multiple EXTIFs found\n");
  351. break;
  352. }
  353. bus->extif.dev = dev;
  354. #endif /* CONFIG_SSB_DRIVER_EXTIF */
  355. break;
  356. case SSB_DEV_CHIPCOMMON:
  357. if (bus->chipco.dev) {
  358. ssb_printk(KERN_WARNING PFX
  359. "WARNING: Multiple ChipCommon found\n");
  360. break;
  361. }
  362. bus->chipco.dev = dev;
  363. break;
  364. case SSB_DEV_MIPS:
  365. case SSB_DEV_MIPS_3302:
  366. #ifdef CONFIG_SSB_DRIVER_MIPS
  367. if (bus->mipscore.dev) {
  368. ssb_printk(KERN_WARNING PFX
  369. "WARNING: Multiple MIPS cores found\n");
  370. break;
  371. }
  372. bus->mipscore.dev = dev;
  373. #endif /* CONFIG_SSB_DRIVER_MIPS */
  374. break;
  375. case SSB_DEV_PCI:
  376. case SSB_DEV_PCIE:
  377. #ifdef CONFIG_SSB_DRIVER_PCICORE
  378. if (bus->bustype == SSB_BUSTYPE_PCI) {
  379. /* Ignore PCI cores on PCI-E cards.
  380. * Ignore PCI-E cores on PCI cards. */
  381. if (dev->id.coreid == SSB_DEV_PCI) {
  382. if (pci_is_pcie(bus->host_pci))
  383. continue;
  384. } else {
  385. if (!pci_is_pcie(bus->host_pci))
  386. continue;
  387. }
  388. }
  389. if (bus->pcicore.dev) {
  390. ssb_printk(KERN_WARNING PFX
  391. "WARNING: Multiple PCI(E) cores found\n");
  392. break;
  393. }
  394. bus->pcicore.dev = dev;
  395. #endif /* CONFIG_SSB_DRIVER_PCICORE */
  396. break;
  397. case SSB_DEV_ETHERNET:
  398. if (bus->bustype == SSB_BUSTYPE_PCI) {
  399. if (bus->host_pci->vendor == PCI_VENDOR_ID_BROADCOM &&
  400. (bus->host_pci->device & 0xFF00) == 0x4300) {
  401. /* This is a dangling ethernet core on a
  402. * wireless device. Ignore it. */
  403. continue;
  404. }
  405. }
  406. break;
  407. default:
  408. break;
  409. }
  410. dev_i++;
  411. }
  412. bus->nr_devices = dev_i;
  413. err = 0;
  414. out:
  415. return err;
  416. err_unmap:
  417. ssb_iounmap(bus);
  418. goto out;
  419. }