driver_mipscore.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom MIPS core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include <linux/ssb/ssb.h>
  11. #include <linux/mtd/physmap.h>
  12. #include <linux/serial.h>
  13. #include <linux/serial_core.h>
  14. #include <linux/serial_reg.h>
  15. #include <linux/time.h>
  16. #include "ssb_private.h"
  17. static const char *part_probes[] = { "bcm47xxpart", NULL };
  18. static struct physmap_flash_data ssb_pflash_data = {
  19. .part_probe_types = part_probes,
  20. };
  21. static struct resource ssb_pflash_resource = {
  22. .name = "ssb_pflash",
  23. .flags = IORESOURCE_MEM,
  24. };
  25. struct platform_device ssb_pflash_dev = {
  26. .name = "physmap-flash",
  27. .dev = {
  28. .platform_data = &ssb_pflash_data,
  29. },
  30. .resource = &ssb_pflash_resource,
  31. .num_resources = 1,
  32. };
  33. static inline u32 mips_read32(struct ssb_mipscore *mcore,
  34. u16 offset)
  35. {
  36. return ssb_read32(mcore->dev, offset);
  37. }
  38. static inline void mips_write32(struct ssb_mipscore *mcore,
  39. u16 offset,
  40. u32 value)
  41. {
  42. ssb_write32(mcore->dev, offset, value);
  43. }
  44. static const u32 ipsflag_irq_mask[] = {
  45. 0,
  46. SSB_IPSFLAG_IRQ1,
  47. SSB_IPSFLAG_IRQ2,
  48. SSB_IPSFLAG_IRQ3,
  49. SSB_IPSFLAG_IRQ4,
  50. };
  51. static const u32 ipsflag_irq_shift[] = {
  52. 0,
  53. SSB_IPSFLAG_IRQ1_SHIFT,
  54. SSB_IPSFLAG_IRQ2_SHIFT,
  55. SSB_IPSFLAG_IRQ3_SHIFT,
  56. SSB_IPSFLAG_IRQ4_SHIFT,
  57. };
  58. static inline u32 ssb_irqflag(struct ssb_device *dev)
  59. {
  60. u32 tpsflag = ssb_read32(dev, SSB_TPSFLAG);
  61. if (tpsflag)
  62. return ssb_read32(dev, SSB_TPSFLAG) & SSB_TPSFLAG_BPFLAG;
  63. else
  64. /* not irq supported */
  65. return 0x3f;
  66. }
  67. static struct ssb_device *find_device(struct ssb_device *rdev, int irqflag)
  68. {
  69. struct ssb_bus *bus = rdev->bus;
  70. int i;
  71. for (i = 0; i < bus->nr_devices; i++) {
  72. struct ssb_device *dev;
  73. dev = &(bus->devices[i]);
  74. if (ssb_irqflag(dev) == irqflag)
  75. return dev;
  76. }
  77. return NULL;
  78. }
  79. /* Get the MIPS IRQ assignment for a specified device.
  80. * If unassigned, 0 is returned.
  81. * If disabled, 5 is returned.
  82. * If not supported, 6 is returned.
  83. */
  84. unsigned int ssb_mips_irq(struct ssb_device *dev)
  85. {
  86. struct ssb_bus *bus = dev->bus;
  87. struct ssb_device *mdev = bus->mipscore.dev;
  88. u32 irqflag;
  89. u32 ipsflag;
  90. u32 tmp;
  91. unsigned int irq;
  92. irqflag = ssb_irqflag(dev);
  93. if (irqflag == 0x3f)
  94. return 6;
  95. ipsflag = ssb_read32(bus->mipscore.dev, SSB_IPSFLAG);
  96. for (irq = 1; irq <= 4; irq++) {
  97. tmp = ((ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq]);
  98. if (tmp == irqflag)
  99. break;
  100. }
  101. if (irq == 5) {
  102. if ((1 << irqflag) & ssb_read32(mdev, SSB_INTVEC))
  103. irq = 0;
  104. }
  105. return irq;
  106. }
  107. static void clear_irq(struct ssb_bus *bus, unsigned int irq)
  108. {
  109. struct ssb_device *dev = bus->mipscore.dev;
  110. /* Clear the IRQ in the MIPScore backplane registers */
  111. if (irq == 0) {
  112. ssb_write32(dev, SSB_INTVEC, 0);
  113. } else {
  114. ssb_write32(dev, SSB_IPSFLAG,
  115. ssb_read32(dev, SSB_IPSFLAG) |
  116. ipsflag_irq_mask[irq]);
  117. }
  118. }
  119. static void set_irq(struct ssb_device *dev, unsigned int irq)
  120. {
  121. unsigned int oldirq = ssb_mips_irq(dev);
  122. struct ssb_bus *bus = dev->bus;
  123. struct ssb_device *mdev = bus->mipscore.dev;
  124. u32 irqflag = ssb_irqflag(dev);
  125. BUG_ON(oldirq == 6);
  126. dev->irq = irq + 2;
  127. /* clear the old irq */
  128. if (oldirq == 0)
  129. ssb_write32(mdev, SSB_INTVEC, (~(1 << irqflag) & ssb_read32(mdev, SSB_INTVEC)));
  130. else if (oldirq != 5)
  131. clear_irq(bus, oldirq);
  132. /* assign the new one */
  133. if (irq == 0) {
  134. ssb_write32(mdev, SSB_INTVEC, ((1 << irqflag) | ssb_read32(mdev, SSB_INTVEC)));
  135. } else {
  136. u32 ipsflag = ssb_read32(mdev, SSB_IPSFLAG);
  137. if ((ipsflag & ipsflag_irq_mask[irq]) != ipsflag_irq_mask[irq]) {
  138. u32 oldipsflag = (ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq];
  139. struct ssb_device *olddev = find_device(dev, oldipsflag);
  140. if (olddev)
  141. set_irq(olddev, 0);
  142. }
  143. irqflag <<= ipsflag_irq_shift[irq];
  144. irqflag |= (ipsflag & ~ipsflag_irq_mask[irq]);
  145. ssb_write32(mdev, SSB_IPSFLAG, irqflag);
  146. }
  147. ssb_dprintk(KERN_INFO PFX
  148. "set_irq: core 0x%04x, irq %d => %d\n",
  149. dev->id.coreid, oldirq+2, irq+2);
  150. }
  151. static void print_irq(struct ssb_device *dev, unsigned int irq)
  152. {
  153. int i;
  154. static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
  155. ssb_dprintk(KERN_INFO PFX
  156. "core 0x%04x, irq :", dev->id.coreid);
  157. for (i = 0; i <= 6; i++) {
  158. ssb_dprintk(" %s%s", irq_name[i], i==irq?"*":" ");
  159. }
  160. ssb_dprintk("\n");
  161. }
  162. static void dump_irq(struct ssb_bus *bus)
  163. {
  164. int i;
  165. for (i = 0; i < bus->nr_devices; i++) {
  166. struct ssb_device *dev;
  167. dev = &(bus->devices[i]);
  168. print_irq(dev, ssb_mips_irq(dev));
  169. }
  170. }
  171. static void ssb_mips_serial_init(struct ssb_mipscore *mcore)
  172. {
  173. struct ssb_bus *bus = mcore->dev->bus;
  174. if (ssb_extif_available(&bus->extif))
  175. mcore->nr_serial_ports = ssb_extif_serial_init(&bus->extif, mcore->serial_ports);
  176. else if (ssb_chipco_available(&bus->chipco))
  177. mcore->nr_serial_ports = ssb_chipco_serial_init(&bus->chipco, mcore->serial_ports);
  178. else
  179. mcore->nr_serial_ports = 0;
  180. }
  181. static void ssb_mips_flash_detect(struct ssb_mipscore *mcore)
  182. {
  183. struct ssb_bus *bus = mcore->dev->bus;
  184. struct ssb_pflash *pflash = &mcore->pflash;
  185. /* When there is no chipcommon on the bus there is 4MB flash */
  186. if (!ssb_chipco_available(&bus->chipco)) {
  187. pflash->present = true;
  188. pflash->buswidth = 2;
  189. pflash->window = SSB_FLASH1;
  190. pflash->window_size = SSB_FLASH1_SZ;
  191. goto ssb_pflash;
  192. }
  193. /* There is ChipCommon, so use it to read info about flash */
  194. switch (bus->chipco.capabilities & SSB_CHIPCO_CAP_FLASHT) {
  195. case SSB_CHIPCO_FLASHT_STSER:
  196. case SSB_CHIPCO_FLASHT_ATSER:
  197. pr_debug("Found serial flash\n");
  198. ssb_sflash_init(&bus->chipco);
  199. break;
  200. case SSB_CHIPCO_FLASHT_PARA:
  201. pr_debug("Found parallel flash\n");
  202. pflash->present = true;
  203. pflash->window = SSB_FLASH2;
  204. pflash->window_size = SSB_FLASH2_SZ;
  205. if ((ssb_read32(bus->chipco.dev, SSB_CHIPCO_FLASH_CFG)
  206. & SSB_CHIPCO_CFG_DS16) == 0)
  207. pflash->buswidth = 1;
  208. else
  209. pflash->buswidth = 2;
  210. break;
  211. }
  212. ssb_pflash:
  213. if (pflash->present) {
  214. ssb_pflash_data.width = pflash->buswidth;
  215. ssb_pflash_resource.start = pflash->window;
  216. ssb_pflash_resource.end = pflash->window + pflash->window_size;
  217. }
  218. }
  219. u32 ssb_cpu_clock(struct ssb_mipscore *mcore)
  220. {
  221. struct ssb_bus *bus = mcore->dev->bus;
  222. u32 pll_type, n, m, rate = 0;
  223. if (bus->chipco.capabilities & SSB_CHIPCO_CAP_PMU)
  224. return ssb_pmu_get_cpu_clock(&bus->chipco);
  225. if (ssb_extif_available(&bus->extif)) {
  226. ssb_extif_get_clockcontrol(&bus->extif, &pll_type, &n, &m);
  227. } else if (ssb_chipco_available(&bus->chipco)) {
  228. ssb_chipco_get_clockcpu(&bus->chipco, &pll_type, &n, &m);
  229. } else
  230. return 0;
  231. if ((pll_type == SSB_PLLTYPE_5) || (bus->chip_id == 0x5365)) {
  232. rate = 200000000;
  233. } else {
  234. rate = ssb_calc_clock_rate(pll_type, n, m);
  235. }
  236. if (pll_type == SSB_PLLTYPE_6) {
  237. rate *= 2;
  238. }
  239. return rate;
  240. }
  241. void ssb_mipscore_init(struct ssb_mipscore *mcore)
  242. {
  243. struct ssb_bus *bus;
  244. struct ssb_device *dev;
  245. unsigned long hz, ns;
  246. unsigned int irq, i;
  247. if (!mcore->dev)
  248. return; /* We don't have a MIPS core */
  249. ssb_dprintk(KERN_INFO PFX "Initializing MIPS core...\n");
  250. bus = mcore->dev->bus;
  251. hz = ssb_clockspeed(bus);
  252. if (!hz)
  253. hz = 100000000;
  254. ns = 1000000000 / hz;
  255. if (ssb_extif_available(&bus->extif))
  256. ssb_extif_timing_init(&bus->extif, ns);
  257. else if (ssb_chipco_available(&bus->chipco))
  258. ssb_chipco_timing_init(&bus->chipco, ns);
  259. /* Assign IRQs to all cores on the bus, start with irq line 2, because serial usually takes 1 */
  260. for (irq = 2, i = 0; i < bus->nr_devices; i++) {
  261. int mips_irq;
  262. dev = &(bus->devices[i]);
  263. mips_irq = ssb_mips_irq(dev);
  264. if (mips_irq > 4)
  265. dev->irq = 0;
  266. else
  267. dev->irq = mips_irq + 2;
  268. if (dev->irq > 5)
  269. continue;
  270. switch (dev->id.coreid) {
  271. case SSB_DEV_USB11_HOST:
  272. /* shouldn't need a separate irq line for non-4710, most of them have a proper
  273. * external usb controller on the pci */
  274. if ((bus->chip_id == 0x4710) && (irq <= 4)) {
  275. set_irq(dev, irq++);
  276. }
  277. break;
  278. case SSB_DEV_PCI:
  279. case SSB_DEV_ETHERNET:
  280. case SSB_DEV_ETHERNET_GBIT:
  281. case SSB_DEV_80211:
  282. case SSB_DEV_USB20_HOST:
  283. /* These devices get their own IRQ line if available, the rest goes on IRQ0 */
  284. if (irq <= 4) {
  285. set_irq(dev, irq++);
  286. break;
  287. }
  288. /* fallthrough */
  289. case SSB_DEV_EXTIF:
  290. set_irq(dev, 0);
  291. break;
  292. }
  293. }
  294. ssb_dprintk(KERN_INFO PFX "after irq reconfiguration\n");
  295. dump_irq(bus);
  296. ssb_mips_serial_init(mcore);
  297. ssb_mips_flash_detect(mcore);
  298. }