driver_mips.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. 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. static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
  115. {
  116. unsigned int oldirq = bcma_core_mips_irq(dev);
  117. struct bcma_bus *bus = dev->bus;
  118. struct bcma_device *mdev = bus->drv_mips.core;
  119. u32 irqflag;
  120. irqflag = bcma_core_mips_irqflag(dev);
  121. BUG_ON(oldirq == 6);
  122. dev->irq = irq + 2;
  123. /* clear the old irq */
  124. if (oldirq == 0)
  125. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  126. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
  127. ~(1 << irqflag));
  128. else if (oldirq != 5)
  129. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(oldirq), 0);
  130. /* assign the new one */
  131. if (irq == 0) {
  132. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  133. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
  134. (1 << irqflag));
  135. } else {
  136. u32 irqinitmask = bcma_read32(mdev,
  137. BCMA_MIPS_MIPS74K_INTMASK(irq));
  138. if (irqinitmask) {
  139. struct bcma_device *core;
  140. /* backplane irq line is in use, find out who uses
  141. * it and set user to irq 0
  142. */
  143. list_for_each_entry(core, &bus->cores, list) {
  144. if ((1 << bcma_core_mips_irqflag(core)) ==
  145. irqinitmask) {
  146. bcma_core_mips_set_irq(core, 0);
  147. break;
  148. }
  149. }
  150. }
  151. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
  152. 1 << irqflag);
  153. }
  154. bcma_debug(bus, "set_irq: core 0x%04x, irq %d => %d\n",
  155. dev->id.id, oldirq <= 4 ? oldirq + 2 : 0, irq + 2);
  156. }
  157. static void bcma_core_mips_set_irq_name(struct bcma_bus *bus, unsigned int irq,
  158. u16 coreid, u8 unit)
  159. {
  160. struct bcma_device *core;
  161. core = bcma_find_core_unit(bus, coreid, unit);
  162. if (!core) {
  163. bcma_warn(bus,
  164. "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
  165. coreid, unit);
  166. return;
  167. }
  168. bcma_core_mips_set_irq(core, irq);
  169. }
  170. static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
  171. {
  172. int i;
  173. static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
  174. printk(KERN_DEBUG KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
  175. for (i = 0; i <= 6; i++)
  176. printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
  177. printk("\n");
  178. }
  179. static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
  180. {
  181. struct bcma_device *core;
  182. list_for_each_entry(core, &bus->cores, list) {
  183. bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
  184. }
  185. }
  186. u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
  187. {
  188. struct bcma_bus *bus = mcore->core->bus;
  189. if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
  190. return bcma_pmu_get_cpu_clock(&bus->drv_cc);
  191. bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
  192. return 0;
  193. }
  194. EXPORT_SYMBOL(bcma_cpu_clock);
  195. static enum bcma_boot_dev bcma_boot_dev(struct bcma_bus *bus)
  196. {
  197. struct bcma_drv_cc *cc = &bus->drv_cc;
  198. u8 cc_rev = cc->core->id.rev;
  199. if (cc_rev == 42) {
  200. struct bcma_device *core;
  201. core = bcma_find_core(bus, BCMA_CORE_NS_ROM);
  202. if (core) {
  203. switch (bcma_aread32(core, BCMA_IOST) &
  204. BCMA_NS_ROM_IOST_BOOT_DEV_MASK) {
  205. case BCMA_NS_ROM_IOST_BOOT_DEV_NOR:
  206. return BCMA_BOOT_DEV_SERIAL;
  207. case BCMA_NS_ROM_IOST_BOOT_DEV_NAND:
  208. return BCMA_BOOT_DEV_NAND;
  209. case BCMA_NS_ROM_IOST_BOOT_DEV_ROM:
  210. default:
  211. return BCMA_BOOT_DEV_ROM;
  212. }
  213. }
  214. } else {
  215. if (cc_rev == 38) {
  216. if (cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT)
  217. return BCMA_BOOT_DEV_NAND;
  218. else if (cc->status & BIT(5))
  219. return BCMA_BOOT_DEV_ROM;
  220. }
  221. if ((cc->capabilities & BCMA_CC_CAP_FLASHT) ==
  222. BCMA_CC_FLASHT_PARA)
  223. return BCMA_BOOT_DEV_PARALLEL;
  224. else
  225. return BCMA_BOOT_DEV_SERIAL;
  226. }
  227. return BCMA_BOOT_DEV_SERIAL;
  228. }
  229. static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
  230. {
  231. struct bcma_bus *bus = mcore->core->bus;
  232. struct bcma_drv_cc *cc = &bus->drv_cc;
  233. struct bcma_pflash *pflash = &cc->pflash;
  234. enum bcma_boot_dev boot_dev;
  235. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  236. case BCMA_CC_FLASHT_STSER:
  237. case BCMA_CC_FLASHT_ATSER:
  238. bcma_debug(bus, "Found serial flash\n");
  239. bcma_sflash_init(cc);
  240. break;
  241. case BCMA_CC_FLASHT_PARA:
  242. bcma_debug(bus, "Found parallel flash\n");
  243. pflash->present = true;
  244. pflash->window = BCMA_SOC_FLASH2;
  245. pflash->window_size = BCMA_SOC_FLASH2_SZ;
  246. if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
  247. BCMA_CC_FLASH_CFG_DS) == 0)
  248. pflash->buswidth = 1;
  249. else
  250. pflash->buswidth = 2;
  251. bcma_pflash_data.width = pflash->buswidth;
  252. bcma_pflash_resource.start = pflash->window;
  253. bcma_pflash_resource.end = pflash->window + pflash->window_size;
  254. break;
  255. default:
  256. bcma_err(bus, "Flash type not supported\n");
  257. }
  258. if (cc->core->id.rev == 38 ||
  259. bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  260. if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
  261. bcma_debug(bus, "Found NAND flash\n");
  262. bcma_nflash_init(cc);
  263. }
  264. }
  265. /* Determine flash type this SoC boots from */
  266. boot_dev = bcma_boot_dev(bus);
  267. switch (boot_dev) {
  268. case BCMA_BOOT_DEV_PARALLEL:
  269. case BCMA_BOOT_DEV_SERIAL:
  270. /* TODO: Init NVRAM using BCMA_SOC_FLASH2 window */
  271. break;
  272. case BCMA_BOOT_DEV_NAND:
  273. /* TODO: Init NVRAM using BCMA_SOC_FLASH1 window */
  274. break;
  275. default:
  276. break;
  277. }
  278. }
  279. void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
  280. {
  281. struct bcma_bus *bus = mcore->core->bus;
  282. if (mcore->early_setup_done)
  283. return;
  284. bcma_chipco_serial_init(&bus->drv_cc);
  285. bcma_core_mips_flash_detect(mcore);
  286. mcore->early_setup_done = true;
  287. }
  288. static void bcma_fix_i2s_irqflag(struct bcma_bus *bus)
  289. {
  290. struct bcma_device *cpu, *pcie, *i2s;
  291. /* Fixup the interrupts in 4716/4748 for i2s core (2010 Broadcom SDK)
  292. * (IRQ flags > 7 are ignored when setting the interrupt masks)
  293. */
  294. if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4716 &&
  295. bus->chipinfo.id != BCMA_CHIP_ID_BCM4748)
  296. return;
  297. cpu = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
  298. pcie = bcma_find_core(bus, BCMA_CORE_PCIE);
  299. i2s = bcma_find_core(bus, BCMA_CORE_I2S);
  300. if (cpu && pcie && i2s &&
  301. bcma_aread32(cpu, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
  302. bcma_aread32(pcie, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
  303. bcma_aread32(i2s, BCMA_MIPS_OOBSELOUTA30) == 0x88) {
  304. bcma_awrite32(cpu, BCMA_MIPS_OOBSELINA74, 0x07060504);
  305. bcma_awrite32(pcie, BCMA_MIPS_OOBSELINA74, 0x07060504);
  306. bcma_awrite32(i2s, BCMA_MIPS_OOBSELOUTA30, 0x87);
  307. bcma_debug(bus,
  308. "Moved i2s interrupt to oob line 7 instead of 8\n");
  309. }
  310. }
  311. void bcma_core_mips_init(struct bcma_drv_mips *mcore)
  312. {
  313. struct bcma_bus *bus;
  314. struct bcma_device *core;
  315. bus = mcore->core->bus;
  316. if (mcore->setup_done)
  317. return;
  318. bcma_debug(bus, "Initializing MIPS core...\n");
  319. bcma_core_mips_early_init(mcore);
  320. bcma_fix_i2s_irqflag(bus);
  321. switch (bus->chipinfo.id) {
  322. case BCMA_CHIP_ID_BCM4716:
  323. case BCMA_CHIP_ID_BCM4748:
  324. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  325. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  326. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  327. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_PCIE, 0);
  328. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  329. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  330. break;
  331. case BCMA_CHIP_ID_BCM5356:
  332. case BCMA_CHIP_ID_BCM47162:
  333. case BCMA_CHIP_ID_BCM53572:
  334. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  335. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  336. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  337. break;
  338. case BCMA_CHIP_ID_BCM5357:
  339. case BCMA_CHIP_ID_BCM4749:
  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, 3, BCMA_CORE_USB20_HOST, 0);
  343. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  344. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  345. break;
  346. case BCMA_CHIP_ID_BCM4706:
  347. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_PCIE, 0);
  348. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_4706_MAC_GBIT,
  349. 0);
  350. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_PCIE, 1);
  351. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_USB20_HOST, 0);
  352. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_4706_CHIPCOMMON,
  353. 0);
  354. break;
  355. default:
  356. list_for_each_entry(core, &bus->cores, list) {
  357. core->irq = bcma_core_irq(core, 0);
  358. }
  359. bcma_err(bus,
  360. "Unknown device (0x%x) found, can not configure IRQs\n",
  361. bus->chipinfo.id);
  362. }
  363. bcma_debug(bus, "IRQ reconfiguration done\n");
  364. bcma_core_mips_dump_irq(bus);
  365. mcore->setup_done = true;
  366. }