driver_mipscore.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom MIPS core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include <linux/ssb/ssb.h>
  11. #include <linux/serial.h>
  12. #include <linux/serial_core.h>
  13. #include <linux/serial_reg.h>
  14. #include <linux/time.h>
  15. #include "ssb_private.h"
  16. static inline u32 mips_read32(struct ssb_mipscore *mcore,
  17. u16 offset)
  18. {
  19. return ssb_read32(mcore->dev, offset);
  20. }
  21. static inline void mips_write32(struct ssb_mipscore *mcore,
  22. u16 offset,
  23. u32 value)
  24. {
  25. ssb_write32(mcore->dev, offset, value);
  26. }
  27. static const u32 ipsflag_irq_mask[] = {
  28. 0,
  29. SSB_IPSFLAG_IRQ1,
  30. SSB_IPSFLAG_IRQ2,
  31. SSB_IPSFLAG_IRQ3,
  32. SSB_IPSFLAG_IRQ4,
  33. };
  34. static const u32 ipsflag_irq_shift[] = {
  35. 0,
  36. SSB_IPSFLAG_IRQ1_SHIFT,
  37. SSB_IPSFLAG_IRQ2_SHIFT,
  38. SSB_IPSFLAG_IRQ3_SHIFT,
  39. SSB_IPSFLAG_IRQ4_SHIFT,
  40. };
  41. static inline u32 ssb_irqflag(struct ssb_device *dev)
  42. {
  43. return ssb_read32(dev, SSB_TPSFLAG) & SSB_TPSFLAG_BPFLAG;
  44. }
  45. /* Get the MIPS IRQ assignment for a specified device.
  46. * If unassigned, 0 is returned.
  47. */
  48. unsigned int ssb_mips_irq(struct ssb_device *dev)
  49. {
  50. struct ssb_bus *bus = dev->bus;
  51. u32 irqflag;
  52. u32 ipsflag;
  53. u32 tmp;
  54. unsigned int irq;
  55. irqflag = ssb_irqflag(dev);
  56. ipsflag = ssb_read32(bus->mipscore.dev, SSB_IPSFLAG);
  57. for (irq = 1; irq <= 4; irq++) {
  58. tmp = ((ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq]);
  59. if (tmp == irqflag)
  60. break;
  61. }
  62. if (irq == 5)
  63. irq = 0;
  64. return irq;
  65. }
  66. static void clear_irq(struct ssb_bus *bus, unsigned int irq)
  67. {
  68. struct ssb_device *dev = bus->mipscore.dev;
  69. /* Clear the IRQ in the MIPScore backplane registers */
  70. if (irq == 0) {
  71. ssb_write32(dev, SSB_INTVEC, 0);
  72. } else {
  73. ssb_write32(dev, SSB_IPSFLAG,
  74. ssb_read32(dev, SSB_IPSFLAG) |
  75. ipsflag_irq_mask[irq]);
  76. }
  77. }
  78. static void set_irq(struct ssb_device *dev, unsigned int irq)
  79. {
  80. unsigned int oldirq = ssb_mips_irq(dev);
  81. struct ssb_bus *bus = dev->bus;
  82. struct ssb_device *mdev = bus->mipscore.dev;
  83. u32 irqflag = ssb_irqflag(dev);
  84. dev->irq = irq + 2;
  85. ssb_dprintk(KERN_INFO PFX
  86. "set_irq: core 0x%04x, irq %d => %d\n",
  87. dev->id.coreid, oldirq, irq);
  88. /* clear the old irq */
  89. if (oldirq == 0)
  90. ssb_write32(mdev, SSB_INTVEC, (~(1 << irqflag) & ssb_read32(mdev, SSB_INTVEC)));
  91. else
  92. clear_irq(bus, oldirq);
  93. /* assign the new one */
  94. if (irq == 0) {
  95. ssb_write32(mdev, SSB_INTVEC, ((1 << irqflag) | ssb_read32(mdev, SSB_INTVEC)));
  96. } else {
  97. irqflag <<= ipsflag_irq_shift[irq];
  98. irqflag |= (ssb_read32(mdev, SSB_IPSFLAG) & ~ipsflag_irq_mask[irq]);
  99. ssb_write32(mdev, SSB_IPSFLAG, irqflag);
  100. }
  101. }
  102. static void ssb_mips_serial_init(struct ssb_mipscore *mcore)
  103. {
  104. struct ssb_bus *bus = mcore->dev->bus;
  105. if (bus->extif.dev)
  106. mcore->nr_serial_ports = ssb_extif_serial_init(&bus->extif, mcore->serial_ports);
  107. else if (bus->chipco.dev)
  108. mcore->nr_serial_ports = ssb_chipco_serial_init(&bus->chipco, mcore->serial_ports);
  109. else
  110. mcore->nr_serial_ports = 0;
  111. }
  112. static void ssb_mips_flash_detect(struct ssb_mipscore *mcore)
  113. {
  114. struct ssb_bus *bus = mcore->dev->bus;
  115. mcore->flash_buswidth = 2;
  116. if (bus->chipco.dev) {
  117. mcore->flash_window = 0x1c000000;
  118. mcore->flash_window_size = 0x02000000;
  119. if ((ssb_read32(bus->chipco.dev, SSB_CHIPCO_FLASH_CFG)
  120. & SSB_CHIPCO_CFG_DS16) == 0)
  121. mcore->flash_buswidth = 1;
  122. } else {
  123. mcore->flash_window = 0x1fc00000;
  124. mcore->flash_window_size = 0x00400000;
  125. }
  126. }
  127. u32 ssb_cpu_clock(struct ssb_mipscore *mcore)
  128. {
  129. struct ssb_bus *bus = mcore->dev->bus;
  130. u32 pll_type, n, m, rate = 0;
  131. if (bus->extif.dev) {
  132. ssb_extif_get_clockcontrol(&bus->extif, &pll_type, &n, &m);
  133. } else if (bus->chipco.dev) {
  134. ssb_chipco_get_clockcpu(&bus->chipco, &pll_type, &n, &m);
  135. } else
  136. return 0;
  137. if ((pll_type == SSB_PLLTYPE_5) || (bus->chip_id == 0x5365)) {
  138. rate = 200000000;
  139. } else {
  140. rate = ssb_calc_clock_rate(pll_type, n, m);
  141. }
  142. if (pll_type == SSB_PLLTYPE_6) {
  143. rate *= 2;
  144. }
  145. return rate;
  146. }
  147. void ssb_mipscore_init(struct ssb_mipscore *mcore)
  148. {
  149. struct ssb_bus *bus;
  150. struct ssb_device *dev;
  151. unsigned long hz, ns;
  152. unsigned int irq, i;
  153. if (!mcore->dev)
  154. return; /* We don't have a MIPS core */
  155. ssb_dprintk(KERN_INFO PFX "Initializing MIPS core...\n");
  156. bus = mcore->dev->bus;
  157. hz = ssb_clockspeed(bus);
  158. if (!hz)
  159. hz = 100000000;
  160. ns = 1000000000 / hz;
  161. if (bus->extif.dev)
  162. ssb_extif_timing_init(&bus->extif, ns);
  163. else if (bus->chipco.dev)
  164. ssb_chipco_timing_init(&bus->chipco, ns);
  165. /* Assign IRQs to all cores on the bus, start with irq line 2, because serial usually takes 1 */
  166. for (irq = 2, i = 0; i < bus->nr_devices; i++) {
  167. dev = &(bus->devices[i]);
  168. dev->irq = ssb_mips_irq(dev) + 2;
  169. switch (dev->id.coreid) {
  170. case SSB_DEV_USB11_HOST:
  171. /* shouldn't need a separate irq line for non-4710, most of them have a proper
  172. * external usb controller on the pci */
  173. if ((bus->chip_id == 0x4710) && (irq <= 4)) {
  174. set_irq(dev, irq++);
  175. break;
  176. }
  177. /* fallthrough */
  178. case SSB_DEV_PCI:
  179. case SSB_DEV_ETHERNET:
  180. case SSB_DEV_ETHERNET_GBIT:
  181. case SSB_DEV_80211:
  182. case SSB_DEV_USB20_HOST:
  183. /* These devices get their own IRQ line if available, the rest goes on IRQ0 */
  184. if (irq <= 4) {
  185. set_irq(dev, irq++);
  186. break;
  187. }
  188. }
  189. }
  190. ssb_mips_serial_init(mcore);
  191. ssb_mips_flash_detect(mcore);
  192. }