driver_mips.c 9.3 KB

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