driver_mips.c 9.3 KB

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