driver_mips.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /*
  2. * Broadcom specific AMBA
  3. * Broadcom MIPS32 74K core driver
  4. *
  5. * Copyright 2009, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
  7. * Copyright 2010, Bernhard Loos <bernhardloos@googlemail.com>
  8. * Copyright 2011, Hauke Mehrtens <hauke@hauke-m.de>
  9. *
  10. * Licensed under the GNU/GPL. See COPYING for details.
  11. */
  12. #include "bcma_private.h"
  13. #include <linux/bcma/bcma.h>
  14. #include <linux/mtd/physmap.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/serial.h>
  17. #include <linux/serial_core.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/time.h>
  20. enum bcma_boot_dev {
  21. BCMA_BOOT_DEV_UNK = 0,
  22. BCMA_BOOT_DEV_ROM,
  23. BCMA_BOOT_DEV_PARALLEL,
  24. BCMA_BOOT_DEV_SERIAL,
  25. BCMA_BOOT_DEV_NAND,
  26. };
  27. static const char * const part_probes[] = { "bcm47xxpart", NULL };
  28. static struct physmap_flash_data bcma_pflash_data = {
  29. .part_probe_types = part_probes,
  30. };
  31. static struct resource bcma_pflash_resource = {
  32. .name = "bcma_pflash",
  33. .flags = IORESOURCE_MEM,
  34. };
  35. struct platform_device bcma_pflash_dev = {
  36. .name = "physmap-flash",
  37. .dev = {
  38. .platform_data = &bcma_pflash_data,
  39. },
  40. .resource = &bcma_pflash_resource,
  41. .num_resources = 1,
  42. };
  43. /* The 47162a0 hangs when reading MIPS DMP registers registers */
  44. static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device *dev)
  45. {
  46. return dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM47162 &&
  47. dev->bus->chipinfo.rev == 0 && dev->id.id == BCMA_CORE_MIPS_74K;
  48. }
  49. /* The 5357b0 hangs when reading USB20H DMP registers */
  50. static inline bool bcma_core_mips_bcm5357b0_quirk(struct bcma_device *dev)
  51. {
  52. return (dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
  53. dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) &&
  54. dev->bus->chipinfo.pkg == 11 &&
  55. dev->id.id == BCMA_CORE_USB20_HOST;
  56. }
  57. static inline u32 mips_read32(struct bcma_drv_mips *mcore,
  58. u16 offset)
  59. {
  60. return bcma_read32(mcore->core, offset);
  61. }
  62. static inline void mips_write32(struct bcma_drv_mips *mcore,
  63. u16 offset,
  64. u32 value)
  65. {
  66. bcma_write32(mcore->core, offset, value);
  67. }
  68. static const u32 ipsflag_irq_mask[] = {
  69. 0,
  70. BCMA_MIPS_IPSFLAG_IRQ1,
  71. BCMA_MIPS_IPSFLAG_IRQ2,
  72. BCMA_MIPS_IPSFLAG_IRQ3,
  73. BCMA_MIPS_IPSFLAG_IRQ4,
  74. };
  75. static const u32 ipsflag_irq_shift[] = {
  76. 0,
  77. BCMA_MIPS_IPSFLAG_IRQ1_SHIFT,
  78. BCMA_MIPS_IPSFLAG_IRQ2_SHIFT,
  79. BCMA_MIPS_IPSFLAG_IRQ3_SHIFT,
  80. BCMA_MIPS_IPSFLAG_IRQ4_SHIFT,
  81. };
  82. static u32 bcma_core_mips_irqflag(struct bcma_device *dev)
  83. {
  84. u32 flag;
  85. if (bcma_core_mips_bcm47162a0_quirk(dev))
  86. return dev->core_index;
  87. if (bcma_core_mips_bcm5357b0_quirk(dev))
  88. return dev->core_index;
  89. flag = bcma_aread32(dev, BCMA_MIPS_OOBSELOUTA30);
  90. if (flag)
  91. return flag & 0x1F;
  92. else
  93. return 0x3f;
  94. }
  95. /* Get the MIPS IRQ assignment for a specified device.
  96. * If unassigned, 0 is returned.
  97. * If disabled, 5 is returned.
  98. * If not supported, 6 is returned.
  99. */
  100. static unsigned int bcma_core_mips_irq(struct bcma_device *dev)
  101. {
  102. struct bcma_device *mdev = dev->bus->drv_mips.core;
  103. u32 irqflag;
  104. unsigned int irq;
  105. irqflag = bcma_core_mips_irqflag(dev);
  106. if (irqflag == 0x3f)
  107. return 6;
  108. for (irq = 0; irq <= 4; irq++)
  109. if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
  110. (1 << irqflag))
  111. return irq;
  112. return 5;
  113. }
  114. unsigned int bcma_core_irq(struct bcma_device *dev)
  115. {
  116. unsigned int mips_irq = bcma_core_mips_irq(dev);
  117. return mips_irq <= 4 ? mips_irq + 2 : 0;
  118. }
  119. EXPORT_SYMBOL(bcma_core_irq);
  120. static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
  121. {
  122. unsigned int oldirq = bcma_core_mips_irq(dev);
  123. struct bcma_bus *bus = dev->bus;
  124. struct bcma_device *mdev = bus->drv_mips.core;
  125. u32 irqflag;
  126. irqflag = bcma_core_mips_irqflag(dev);
  127. BUG_ON(oldirq == 6);
  128. dev->irq = irq + 2;
  129. /* clear the old irq */
  130. if (oldirq == 0)
  131. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  132. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
  133. ~(1 << irqflag));
  134. else if (oldirq != 5)
  135. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(oldirq), 0);
  136. /* assign the new one */
  137. if (irq == 0) {
  138. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  139. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
  140. (1 << irqflag));
  141. } else {
  142. u32 irqinitmask = bcma_read32(mdev,
  143. BCMA_MIPS_MIPS74K_INTMASK(irq));
  144. if (irqinitmask) {
  145. struct bcma_device *core;
  146. /* backplane irq line is in use, find out who uses
  147. * it and set user to irq 0
  148. */
  149. list_for_each_entry(core, &bus->cores, list) {
  150. if ((1 << bcma_core_mips_irqflag(core)) ==
  151. irqinitmask) {
  152. bcma_core_mips_set_irq(core, 0);
  153. break;
  154. }
  155. }
  156. }
  157. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
  158. 1 << irqflag);
  159. }
  160. bcma_debug(bus, "set_irq: core 0x%04x, irq %d => %d\n",
  161. dev->id.id, oldirq <= 4 ? oldirq + 2 : 0, irq + 2);
  162. }
  163. static void bcma_core_mips_set_irq_name(struct bcma_bus *bus, unsigned int irq,
  164. u16 coreid, u8 unit)
  165. {
  166. struct bcma_device *core;
  167. core = bcma_find_core_unit(bus, coreid, unit);
  168. if (!core) {
  169. bcma_warn(bus,
  170. "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
  171. coreid, unit);
  172. return;
  173. }
  174. bcma_core_mips_set_irq(core, irq);
  175. }
  176. static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
  177. {
  178. int i;
  179. static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
  180. printk(KERN_DEBUG KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
  181. for (i = 0; i <= 6; i++)
  182. printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
  183. printk("\n");
  184. }
  185. static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
  186. {
  187. struct bcma_device *core;
  188. list_for_each_entry(core, &bus->cores, list) {
  189. bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
  190. }
  191. }
  192. u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
  193. {
  194. struct bcma_bus *bus = mcore->core->bus;
  195. if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
  196. return bcma_pmu_get_cpu_clock(&bus->drv_cc);
  197. bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
  198. return 0;
  199. }
  200. EXPORT_SYMBOL(bcma_cpu_clock);
  201. static enum bcma_boot_dev bcma_boot_dev(struct bcma_bus *bus)
  202. {
  203. struct bcma_drv_cc *cc = &bus->drv_cc;
  204. u8 cc_rev = cc->core->id.rev;
  205. if (cc_rev == 42) {
  206. struct bcma_device *core;
  207. core = bcma_find_core(bus, BCMA_CORE_NS_ROM);
  208. if (core) {
  209. switch (bcma_aread32(core, BCMA_IOST) &
  210. BCMA_NS_ROM_IOST_BOOT_DEV_MASK) {
  211. case BCMA_NS_ROM_IOST_BOOT_DEV_NOR:
  212. return BCMA_BOOT_DEV_SERIAL;
  213. case BCMA_NS_ROM_IOST_BOOT_DEV_NAND:
  214. return BCMA_BOOT_DEV_NAND;
  215. case BCMA_NS_ROM_IOST_BOOT_DEV_ROM:
  216. default:
  217. return BCMA_BOOT_DEV_ROM;
  218. }
  219. }
  220. } else {
  221. if (cc_rev == 38) {
  222. if (cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT)
  223. return BCMA_BOOT_DEV_NAND;
  224. else if (cc->status & BIT(5))
  225. return BCMA_BOOT_DEV_ROM;
  226. }
  227. if ((cc->capabilities & BCMA_CC_CAP_FLASHT) ==
  228. BCMA_CC_FLASHT_PARA)
  229. return BCMA_BOOT_DEV_PARALLEL;
  230. else
  231. return BCMA_BOOT_DEV_SERIAL;
  232. }
  233. return BCMA_BOOT_DEV_SERIAL;
  234. }
  235. static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
  236. {
  237. struct bcma_bus *bus = mcore->core->bus;
  238. struct bcma_drv_cc *cc = &bus->drv_cc;
  239. struct bcma_pflash *pflash = &cc->pflash;
  240. enum bcma_boot_dev boot_dev;
  241. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  242. case BCMA_CC_FLASHT_STSER:
  243. case BCMA_CC_FLASHT_ATSER:
  244. bcma_debug(bus, "Found serial flash\n");
  245. bcma_sflash_init(cc);
  246. break;
  247. case BCMA_CC_FLASHT_PARA:
  248. bcma_debug(bus, "Found parallel flash\n");
  249. pflash->present = true;
  250. pflash->window = BCMA_SOC_FLASH2;
  251. pflash->window_size = BCMA_SOC_FLASH2_SZ;
  252. if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
  253. BCMA_CC_FLASH_CFG_DS) == 0)
  254. pflash->buswidth = 1;
  255. else
  256. pflash->buswidth = 2;
  257. bcma_pflash_data.width = pflash->buswidth;
  258. bcma_pflash_resource.start = pflash->window;
  259. bcma_pflash_resource.end = pflash->window + pflash->window_size;
  260. break;
  261. default:
  262. bcma_err(bus, "Flash type not supported\n");
  263. }
  264. if (cc->core->id.rev == 38 ||
  265. bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  266. if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
  267. bcma_debug(bus, "Found NAND flash\n");
  268. bcma_nflash_init(cc);
  269. }
  270. }
  271. /* Determine flash type this SoC boots from */
  272. boot_dev = bcma_boot_dev(bus);
  273. switch (boot_dev) {
  274. case BCMA_BOOT_DEV_PARALLEL:
  275. case BCMA_BOOT_DEV_SERIAL:
  276. /* TODO: Init NVRAM using BCMA_SOC_FLASH2 window */
  277. break;
  278. case BCMA_BOOT_DEV_NAND:
  279. /* TODO: Init NVRAM using BCMA_SOC_FLASH1 window */
  280. break;
  281. default:
  282. break;
  283. }
  284. }
  285. void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
  286. {
  287. struct bcma_bus *bus = mcore->core->bus;
  288. if (mcore->early_setup_done)
  289. return;
  290. bcma_chipco_serial_init(&bus->drv_cc);
  291. bcma_core_mips_flash_detect(mcore);
  292. mcore->early_setup_done = true;
  293. }
  294. static void bcma_fix_i2s_irqflag(struct bcma_bus *bus)
  295. {
  296. struct bcma_device *cpu, *pcie, *i2s;
  297. /* Fixup the interrupts in 4716/4748 for i2s core (2010 Broadcom SDK)
  298. * (IRQ flags > 7 are ignored when setting the interrupt masks)
  299. */
  300. if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4716 &&
  301. bus->chipinfo.id != BCMA_CHIP_ID_BCM4748)
  302. return;
  303. cpu = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
  304. pcie = bcma_find_core(bus, BCMA_CORE_PCIE);
  305. i2s = bcma_find_core(bus, BCMA_CORE_I2S);
  306. if (cpu && pcie && i2s &&
  307. bcma_aread32(cpu, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
  308. bcma_aread32(pcie, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
  309. bcma_aread32(i2s, BCMA_MIPS_OOBSELOUTA30) == 0x88) {
  310. bcma_awrite32(cpu, BCMA_MIPS_OOBSELINA74, 0x07060504);
  311. bcma_awrite32(pcie, BCMA_MIPS_OOBSELINA74, 0x07060504);
  312. bcma_awrite32(i2s, BCMA_MIPS_OOBSELOUTA30, 0x87);
  313. bcma_debug(bus,
  314. "Moved i2s interrupt to oob line 7 instead of 8\n");
  315. }
  316. }
  317. void bcma_core_mips_init(struct bcma_drv_mips *mcore)
  318. {
  319. struct bcma_bus *bus;
  320. struct bcma_device *core;
  321. bus = mcore->core->bus;
  322. if (mcore->setup_done)
  323. return;
  324. bcma_debug(bus, "Initializing MIPS core...\n");
  325. bcma_core_mips_early_init(mcore);
  326. bcma_fix_i2s_irqflag(bus);
  327. switch (bus->chipinfo.id) {
  328. case BCMA_CHIP_ID_BCM4716:
  329. case BCMA_CHIP_ID_BCM4748:
  330. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  331. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  332. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  333. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_PCIE, 0);
  334. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  335. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  336. break;
  337. case BCMA_CHIP_ID_BCM5356:
  338. case BCMA_CHIP_ID_BCM47162:
  339. case BCMA_CHIP_ID_BCM53572:
  340. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  341. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  342. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  343. break;
  344. case BCMA_CHIP_ID_BCM5357:
  345. case BCMA_CHIP_ID_BCM4749:
  346. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  347. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  348. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  349. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  350. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  351. break;
  352. case BCMA_CHIP_ID_BCM4706:
  353. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_PCIE, 0);
  354. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_4706_MAC_GBIT,
  355. 0);
  356. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_PCIE, 1);
  357. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_USB20_HOST, 0);
  358. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_4706_CHIPCOMMON,
  359. 0);
  360. break;
  361. default:
  362. list_for_each_entry(core, &bus->cores, list) {
  363. core->irq = bcma_core_irq(core);
  364. }
  365. bcma_err(bus,
  366. "Unknown device (0x%x) found, can not configure IRQs\n",
  367. bus->chipinfo.id);
  368. }
  369. bcma_debug(bus, "IRQ reconfiguration done\n");
  370. bcma_core_mips_dump_irq(bus);
  371. mcore->setup_done = true;
  372. }