driver_mips.c 11 KB

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