driver_mips.c 8.2 KB

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