driver_mips.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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_info(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_print_irq(struct bcma_device *dev, unsigned int irq)
  127. {
  128. int i;
  129. static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
  130. printk(KERN_INFO KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
  131. for (i = 0; i <= 6; i++)
  132. printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
  133. printk("\n");
  134. }
  135. static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
  136. {
  137. struct bcma_device *core;
  138. list_for_each_entry(core, &bus->cores, list) {
  139. bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
  140. }
  141. }
  142. u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
  143. {
  144. struct bcma_bus *bus = mcore->core->bus;
  145. if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
  146. return bcma_pmu_get_cpu_clock(&bus->drv_cc);
  147. bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
  148. return 0;
  149. }
  150. EXPORT_SYMBOL(bcma_cpu_clock);
  151. static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
  152. {
  153. struct bcma_bus *bus = mcore->core->bus;
  154. struct bcma_drv_cc *cc = &bus->drv_cc;
  155. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  156. case BCMA_CC_FLASHT_STSER:
  157. case BCMA_CC_FLASHT_ATSER:
  158. bcma_debug(bus, "Found serial flash\n");
  159. bcma_sflash_init(cc);
  160. break;
  161. case BCMA_CC_FLASHT_PARA:
  162. bcma_debug(bus, "Found parallel flash\n");
  163. cc->pflash.present = true;
  164. cc->pflash.window = BCMA_SOC_FLASH2;
  165. cc->pflash.window_size = BCMA_SOC_FLASH2_SZ;
  166. if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
  167. BCMA_CC_FLASH_CFG_DS) == 0)
  168. cc->pflash.buswidth = 1;
  169. else
  170. cc->pflash.buswidth = 2;
  171. break;
  172. default:
  173. bcma_err(bus, "Flash type not supported\n");
  174. }
  175. if (cc->core->id.rev == 38 ||
  176. bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  177. if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
  178. bcma_debug(bus, "Found NAND flash\n");
  179. bcma_nflash_init(cc);
  180. }
  181. }
  182. }
  183. void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
  184. {
  185. struct bcma_bus *bus = mcore->core->bus;
  186. if (mcore->early_setup_done)
  187. return;
  188. bcma_chipco_serial_init(&bus->drv_cc);
  189. bcma_core_mips_flash_detect(mcore);
  190. mcore->early_setup_done = true;
  191. }
  192. void bcma_core_mips_init(struct bcma_drv_mips *mcore)
  193. {
  194. struct bcma_bus *bus;
  195. struct bcma_device *core;
  196. bus = mcore->core->bus;
  197. if (mcore->setup_done)
  198. return;
  199. bcma_info(bus, "Initializing MIPS core...\n");
  200. bcma_core_mips_early_init(mcore);
  201. mcore->assigned_irqs = 1;
  202. /* Assign IRQs to all cores on the bus */
  203. list_for_each_entry(core, &bus->cores, list) {
  204. int mips_irq;
  205. if (core->irq)
  206. continue;
  207. mips_irq = bcma_core_mips_irq(core);
  208. if (mips_irq > 4)
  209. core->irq = 0;
  210. else
  211. core->irq = mips_irq + 2;
  212. if (core->irq > 5)
  213. continue;
  214. switch (core->id.id) {
  215. case BCMA_CORE_PCI:
  216. case BCMA_CORE_PCIE:
  217. case BCMA_CORE_ETHERNET:
  218. case BCMA_CORE_ETHERNET_GBIT:
  219. case BCMA_CORE_MAC_GBIT:
  220. case BCMA_CORE_80211:
  221. case BCMA_CORE_USB20_HOST:
  222. /* These devices get their own IRQ line if available,
  223. * the rest goes on IRQ0
  224. */
  225. if (mcore->assigned_irqs <= 4)
  226. bcma_core_mips_set_irq(core,
  227. mcore->assigned_irqs++);
  228. break;
  229. }
  230. }
  231. bcma_info(bus, "IRQ reconfiguration done\n");
  232. bcma_core_mips_dump_irq(bus);
  233. mcore->setup_done = true;
  234. }