driver_mips.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. return flag & 0x1F;
  66. }
  67. /* Get the MIPS IRQ assignment for a specified device.
  68. * If unassigned, 0 is returned.
  69. */
  70. unsigned int bcma_core_mips_irq(struct bcma_device *dev)
  71. {
  72. struct bcma_device *mdev = dev->bus->drv_mips.core;
  73. u32 irqflag;
  74. unsigned int irq;
  75. irqflag = bcma_core_mips_irqflag(dev);
  76. for (irq = 1; irq <= 4; irq++)
  77. if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
  78. (1 << irqflag))
  79. return irq;
  80. return 0;
  81. }
  82. EXPORT_SYMBOL(bcma_core_mips_irq);
  83. static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
  84. {
  85. unsigned int oldirq = bcma_core_mips_irq(dev);
  86. struct bcma_bus *bus = dev->bus;
  87. struct bcma_device *mdev = bus->drv_mips.core;
  88. u32 irqflag;
  89. irqflag = bcma_core_mips_irqflag(dev);
  90. BUG_ON(oldirq == 6);
  91. dev->irq = irq + 2;
  92. /* clear the old irq */
  93. if (oldirq == 0)
  94. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  95. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
  96. ~(1 << irqflag));
  97. else
  98. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(oldirq), 0);
  99. /* assign the new one */
  100. if (irq == 0) {
  101. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  102. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
  103. (1 << irqflag));
  104. } else {
  105. u32 oldirqflag = bcma_read32(mdev,
  106. BCMA_MIPS_MIPS74K_INTMASK(irq));
  107. if (oldirqflag) {
  108. struct bcma_device *core;
  109. /* backplane irq line is in use, find out who uses
  110. * it and set user to irq 0
  111. */
  112. list_for_each_entry(core, &bus->cores, list) {
  113. if ((1 << bcma_core_mips_irqflag(core)) ==
  114. oldirqflag) {
  115. bcma_core_mips_set_irq(core, 0);
  116. break;
  117. }
  118. }
  119. }
  120. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
  121. 1 << irqflag);
  122. }
  123. bcma_debug(bus, "set_irq: core 0x%04x, irq %d => %d\n",
  124. dev->id.id, oldirq + 2, irq + 2);
  125. }
  126. static void bcma_core_mips_set_irq_name(struct bcma_bus *bus, unsigned int irq,
  127. u16 coreid, u8 unit)
  128. {
  129. struct bcma_device *core;
  130. core = bcma_find_core_unit(bus, coreid, unit);
  131. if (!core) {
  132. bcma_warn(bus,
  133. "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
  134. coreid, unit);
  135. return;
  136. }
  137. bcma_core_mips_set_irq(core, irq);
  138. }
  139. static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
  140. {
  141. int i;
  142. static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
  143. printk(KERN_DEBUG KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
  144. for (i = 0; i <= 6; i++)
  145. printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
  146. printk("\n");
  147. }
  148. static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
  149. {
  150. struct bcma_device *core;
  151. list_for_each_entry(core, &bus->cores, list) {
  152. bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
  153. }
  154. }
  155. u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
  156. {
  157. struct bcma_bus *bus = mcore->core->bus;
  158. if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
  159. return bcma_pmu_get_cpu_clock(&bus->drv_cc);
  160. bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
  161. return 0;
  162. }
  163. EXPORT_SYMBOL(bcma_cpu_clock);
  164. static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
  165. {
  166. struct bcma_bus *bus = mcore->core->bus;
  167. struct bcma_drv_cc *cc = &bus->drv_cc;
  168. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  169. case BCMA_CC_FLASHT_STSER:
  170. case BCMA_CC_FLASHT_ATSER:
  171. bcma_debug(bus, "Found serial flash\n");
  172. bcma_sflash_init(cc);
  173. break;
  174. case BCMA_CC_FLASHT_PARA:
  175. bcma_debug(bus, "Found parallel flash\n");
  176. cc->pflash.present = true;
  177. cc->pflash.window = BCMA_SOC_FLASH2;
  178. cc->pflash.window_size = BCMA_SOC_FLASH2_SZ;
  179. if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
  180. BCMA_CC_FLASH_CFG_DS) == 0)
  181. cc->pflash.buswidth = 1;
  182. else
  183. cc->pflash.buswidth = 2;
  184. break;
  185. default:
  186. bcma_err(bus, "Flash type not supported\n");
  187. }
  188. if (cc->core->id.rev == 38 ||
  189. bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  190. if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
  191. bcma_debug(bus, "Found NAND flash\n");
  192. bcma_nflash_init(cc);
  193. }
  194. }
  195. }
  196. void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
  197. {
  198. struct bcma_bus *bus = mcore->core->bus;
  199. if (mcore->early_setup_done)
  200. return;
  201. bcma_chipco_serial_init(&bus->drv_cc);
  202. bcma_core_mips_flash_detect(mcore);
  203. mcore->early_setup_done = true;
  204. }
  205. void bcma_core_mips_init(struct bcma_drv_mips *mcore)
  206. {
  207. struct bcma_bus *bus;
  208. struct bcma_device *core;
  209. bus = mcore->core->bus;
  210. if (mcore->setup_done)
  211. return;
  212. bcma_debug(bus, "Initializing MIPS core...\n");
  213. bcma_core_mips_early_init(mcore);
  214. mcore->assigned_irqs = 1;
  215. switch (bus->chipinfo.id) {
  216. case BCMA_CHIP_ID_BCM4716:
  217. case BCMA_CHIP_ID_BCM4748:
  218. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  219. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  220. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  221. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_PCIE, 0);
  222. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  223. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  224. break;
  225. case BCMA_CHIP_ID_BCM5356:
  226. case BCMA_CHIP_ID_BCM47162:
  227. case BCMA_CHIP_ID_BCM53572:
  228. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  229. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  230. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  231. break;
  232. case BCMA_CHIP_ID_BCM5357:
  233. case BCMA_CHIP_ID_BCM4749:
  234. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  235. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  236. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  237. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  238. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  239. break;
  240. case BCMA_CHIP_ID_BCM4706:
  241. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_PCIE, 0);
  242. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_4706_MAC_GBIT,
  243. 0);
  244. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_PCIE, 1);
  245. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_USB20_HOST, 0);
  246. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_4706_CHIPCOMMON,
  247. 0);
  248. break;
  249. default:
  250. list_for_each_entry(core, &bus->cores, list) {
  251. core->irq = bcma_core_irq(core);
  252. }
  253. bcma_err(bus,
  254. "Unknown device (0x%x) found, can not configure IRQs\n",
  255. bus->chipinfo.id);
  256. }
  257. bcma_debug(bus, "IRQ reconfiguration done\n");
  258. bcma_core_mips_dump_irq(bus);
  259. mcore->setup_done = true;
  260. }