driver_mips.c 9.9 KB

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