driver_mips.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 == 47162 && dev->bus->chipinfo.rev == 0 &&
  22. 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 == 0x5357 ||
  28. dev->bus->chipinfo.id == 0x4749) &&
  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_reverse(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. pr_info("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_reverse(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_clockcpu(&bus->drv_cc);
  147. pr_err("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. switch (bus->drv_cc.capabilities & BCMA_CC_CAP_FLASHT) {
  155. case BCMA_CC_FLASHT_STSER:
  156. case BCMA_CC_FLASHT_ATSER:
  157. pr_err("Serial flash not supported.\n");
  158. break;
  159. case BCMA_CC_FLASHT_PARA:
  160. pr_info("found parallel flash.\n");
  161. bus->drv_cc.pflash.window = 0x1c000000;
  162. bus->drv_cc.pflash.window_size = 0x02000000;
  163. if ((bcma_read32(bus->drv_cc.core, BCMA_CC_FLASH_CFG) &
  164. BCMA_CC_FLASH_CFG_DS) == 0)
  165. bus->drv_cc.pflash.buswidth = 1;
  166. else
  167. bus->drv_cc.pflash.buswidth = 2;
  168. break;
  169. default:
  170. pr_err("flash not supported.\n");
  171. }
  172. }
  173. void bcma_core_mips_init(struct bcma_drv_mips *mcore)
  174. {
  175. struct bcma_bus *bus;
  176. struct bcma_device *core;
  177. bus = mcore->core->bus;
  178. pr_info("Initializing MIPS core...\n");
  179. if (!mcore->setup_done)
  180. mcore->assigned_irqs = 1;
  181. /* Assign IRQs to all cores on the bus */
  182. list_for_each_entry_reverse(core, &bus->cores, list) {
  183. int mips_irq;
  184. if (core->irq)
  185. continue;
  186. mips_irq = bcma_core_mips_irq(core);
  187. if (mips_irq > 4)
  188. core->irq = 0;
  189. else
  190. core->irq = mips_irq + 2;
  191. if (core->irq > 5)
  192. continue;
  193. switch (core->id.id) {
  194. case BCMA_CORE_PCI:
  195. case BCMA_CORE_PCIE:
  196. case BCMA_CORE_ETHERNET:
  197. case BCMA_CORE_ETHERNET_GBIT:
  198. case BCMA_CORE_MAC_GBIT:
  199. case BCMA_CORE_80211:
  200. case BCMA_CORE_USB20_HOST:
  201. /* These devices get their own IRQ line if available,
  202. * the rest goes on IRQ0
  203. */
  204. if (mcore->assigned_irqs <= 4)
  205. bcma_core_mips_set_irq(core,
  206. mcore->assigned_irqs++);
  207. break;
  208. }
  209. }
  210. pr_info("IRQ reconfiguration done\n");
  211. bcma_core_mips_dump_irq(bus);
  212. if (mcore->setup_done)
  213. return;
  214. bcma_chipco_serial_init(&bus->drv_cc);
  215. bcma_core_mips_flash_detect(mcore);
  216. mcore->setup_done = true;
  217. }