driver_mips.c 9.5 KB

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