driver_mips.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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/mtd/physmap.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/serial.h>
  17. #include <linux/serial_core.h>
  18. #include <linux/serial_reg.h>
  19. #include <linux/time.h>
  20. static const char *part_probes[] = { "bcm47xxpart", NULL };
  21. static struct physmap_flash_data bcma_pflash_data = {
  22. .part_probe_types = part_probes,
  23. };
  24. static struct resource bcma_pflash_resource = {
  25. .name = "bcma_pflash",
  26. .flags = IORESOURCE_MEM,
  27. };
  28. struct platform_device bcma_pflash_dev = {
  29. .name = "physmap-flash",
  30. .dev = {
  31. .platform_data = &bcma_pflash_data,
  32. },
  33. .resource = &bcma_pflash_resource,
  34. .num_resources = 1,
  35. };
  36. /* The 47162a0 hangs when reading MIPS DMP registers registers */
  37. static inline bool bcma_core_mips_bcm47162a0_quirk(struct bcma_device *dev)
  38. {
  39. return dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM47162 &&
  40. dev->bus->chipinfo.rev == 0 && dev->id.id == BCMA_CORE_MIPS_74K;
  41. }
  42. /* The 5357b0 hangs when reading USB20H DMP registers */
  43. static inline bool bcma_core_mips_bcm5357b0_quirk(struct bcma_device *dev)
  44. {
  45. return (dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
  46. dev->bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) &&
  47. dev->bus->chipinfo.pkg == 11 &&
  48. dev->id.id == BCMA_CORE_USB20_HOST;
  49. }
  50. static inline u32 mips_read32(struct bcma_drv_mips *mcore,
  51. u16 offset)
  52. {
  53. return bcma_read32(mcore->core, offset);
  54. }
  55. static inline void mips_write32(struct bcma_drv_mips *mcore,
  56. u16 offset,
  57. u32 value)
  58. {
  59. bcma_write32(mcore->core, offset, value);
  60. }
  61. static const u32 ipsflag_irq_mask[] = {
  62. 0,
  63. BCMA_MIPS_IPSFLAG_IRQ1,
  64. BCMA_MIPS_IPSFLAG_IRQ2,
  65. BCMA_MIPS_IPSFLAG_IRQ3,
  66. BCMA_MIPS_IPSFLAG_IRQ4,
  67. };
  68. static const u32 ipsflag_irq_shift[] = {
  69. 0,
  70. BCMA_MIPS_IPSFLAG_IRQ1_SHIFT,
  71. BCMA_MIPS_IPSFLAG_IRQ2_SHIFT,
  72. BCMA_MIPS_IPSFLAG_IRQ3_SHIFT,
  73. BCMA_MIPS_IPSFLAG_IRQ4_SHIFT,
  74. };
  75. static u32 bcma_core_mips_irqflag(struct bcma_device *dev)
  76. {
  77. u32 flag;
  78. if (bcma_core_mips_bcm47162a0_quirk(dev))
  79. return dev->core_index;
  80. if (bcma_core_mips_bcm5357b0_quirk(dev))
  81. return dev->core_index;
  82. flag = bcma_aread32(dev, BCMA_MIPS_OOBSELOUTA30);
  83. if (flag)
  84. return flag & 0x1F;
  85. else
  86. return 0x3f;
  87. }
  88. /* Get the MIPS IRQ assignment for a specified device.
  89. * If unassigned, 0 is returned.
  90. * If disabled, 5 is returned.
  91. * If not supported, 6 is returned.
  92. */
  93. static unsigned int bcma_core_mips_irq(struct bcma_device *dev)
  94. {
  95. struct bcma_device *mdev = dev->bus->drv_mips.core;
  96. u32 irqflag;
  97. unsigned int irq;
  98. irqflag = bcma_core_mips_irqflag(dev);
  99. if (irqflag == 0x3f)
  100. return 6;
  101. for (irq = 0; irq <= 4; irq++)
  102. if (bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq)) &
  103. (1 << irqflag))
  104. return irq;
  105. return 5;
  106. }
  107. unsigned int bcma_core_irq(struct bcma_device *dev)
  108. {
  109. unsigned int mips_irq = bcma_core_mips_irq(dev);
  110. return mips_irq <= 4 ? mips_irq + 2 : 0;
  111. }
  112. EXPORT_SYMBOL(bcma_core_irq);
  113. static void bcma_core_mips_set_irq(struct bcma_device *dev, unsigned int irq)
  114. {
  115. unsigned int oldirq = bcma_core_mips_irq(dev);
  116. struct bcma_bus *bus = dev->bus;
  117. struct bcma_device *mdev = bus->drv_mips.core;
  118. u32 irqflag;
  119. irqflag = bcma_core_mips_irqflag(dev);
  120. BUG_ON(oldirq == 6);
  121. dev->irq = irq + 2;
  122. /* clear the old irq */
  123. if (oldirq == 0)
  124. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  125. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) &
  126. ~(1 << irqflag));
  127. else if (oldirq != 5)
  128. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(oldirq), 0);
  129. /* assign the new one */
  130. if (irq == 0) {
  131. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0),
  132. bcma_read32(mdev, BCMA_MIPS_MIPS74K_INTMASK(0)) |
  133. (1 << irqflag));
  134. } else {
  135. u32 irqinitmask = bcma_read32(mdev,
  136. BCMA_MIPS_MIPS74K_INTMASK(irq));
  137. if (irqinitmask) {
  138. struct bcma_device *core;
  139. /* backplane irq line is in use, find out who uses
  140. * it and set user to irq 0
  141. */
  142. list_for_each_entry(core, &bus->cores, list) {
  143. if ((1 << bcma_core_mips_irqflag(core)) ==
  144. irqinitmask) {
  145. bcma_core_mips_set_irq(core, 0);
  146. break;
  147. }
  148. }
  149. }
  150. bcma_write32(mdev, BCMA_MIPS_MIPS74K_INTMASK(irq),
  151. 1 << irqflag);
  152. }
  153. bcma_debug(bus, "set_irq: core 0x%04x, irq %d => %d\n",
  154. dev->id.id, oldirq <= 4 ? oldirq + 2 : 0, irq + 2);
  155. }
  156. static void bcma_core_mips_set_irq_name(struct bcma_bus *bus, unsigned int irq,
  157. u16 coreid, u8 unit)
  158. {
  159. struct bcma_device *core;
  160. core = bcma_find_core_unit(bus, coreid, unit);
  161. if (!core) {
  162. bcma_warn(bus,
  163. "Can not find core (id: 0x%x, unit %i) for IRQ configuration.\n",
  164. coreid, unit);
  165. return;
  166. }
  167. bcma_core_mips_set_irq(core, irq);
  168. }
  169. static void bcma_core_mips_print_irq(struct bcma_device *dev, unsigned int irq)
  170. {
  171. int i;
  172. static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
  173. printk(KERN_DEBUG KBUILD_MODNAME ": core 0x%04x, irq :", dev->id.id);
  174. for (i = 0; i <= 6; i++)
  175. printk(" %s%s", irq_name[i], i == irq ? "*" : " ");
  176. printk("\n");
  177. }
  178. static void bcma_core_mips_dump_irq(struct bcma_bus *bus)
  179. {
  180. struct bcma_device *core;
  181. list_for_each_entry(core, &bus->cores, list) {
  182. bcma_core_mips_print_irq(core, bcma_core_mips_irq(core));
  183. }
  184. }
  185. u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
  186. {
  187. struct bcma_bus *bus = mcore->core->bus;
  188. if (bus->drv_cc.capabilities & BCMA_CC_CAP_PMU)
  189. return bcma_pmu_get_cpu_clock(&bus->drv_cc);
  190. bcma_err(bus, "No PMU available, need this to get the cpu clock\n");
  191. return 0;
  192. }
  193. EXPORT_SYMBOL(bcma_cpu_clock);
  194. static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
  195. {
  196. struct bcma_bus *bus = mcore->core->bus;
  197. struct bcma_drv_cc *cc = &bus->drv_cc;
  198. struct bcma_pflash *pflash = &cc->pflash;
  199. switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
  200. case BCMA_CC_FLASHT_STSER:
  201. case BCMA_CC_FLASHT_ATSER:
  202. bcma_debug(bus, "Found serial flash\n");
  203. bcma_sflash_init(cc);
  204. break;
  205. case BCMA_CC_FLASHT_PARA:
  206. bcma_debug(bus, "Found parallel flash\n");
  207. pflash->present = true;
  208. pflash->window = BCMA_SOC_FLASH2;
  209. pflash->window_size = BCMA_SOC_FLASH2_SZ;
  210. if ((bcma_read32(cc->core, BCMA_CC_FLASH_CFG) &
  211. BCMA_CC_FLASH_CFG_DS) == 0)
  212. pflash->buswidth = 1;
  213. else
  214. pflash->buswidth = 2;
  215. bcma_pflash_data.width = pflash->buswidth;
  216. bcma_pflash_resource.start = pflash->window;
  217. bcma_pflash_resource.end = pflash->window + pflash->window_size;
  218. break;
  219. default:
  220. bcma_err(bus, "Flash type not supported\n");
  221. }
  222. if (cc->core->id.rev == 38 ||
  223. bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
  224. if (cc->capabilities & BCMA_CC_CAP_NFLASH) {
  225. bcma_debug(bus, "Found NAND flash\n");
  226. bcma_nflash_init(cc);
  227. }
  228. }
  229. }
  230. void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
  231. {
  232. struct bcma_bus *bus = mcore->core->bus;
  233. if (mcore->early_setup_done)
  234. return;
  235. bcma_chipco_serial_init(&bus->drv_cc);
  236. bcma_core_mips_flash_detect(mcore);
  237. mcore->early_setup_done = true;
  238. }
  239. static void bcma_fix_i2s_irqflag(struct bcma_bus *bus)
  240. {
  241. struct bcma_device *cpu, *pcie, *i2s;
  242. /* Fixup the interrupts in 4716/4748 for i2s core (2010 Broadcom SDK)
  243. * (IRQ flags > 7 are ignored when setting the interrupt masks)
  244. */
  245. if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4716 &&
  246. bus->chipinfo.id != BCMA_CHIP_ID_BCM4748)
  247. return;
  248. cpu = bcma_find_core(bus, BCMA_CORE_MIPS_74K);
  249. pcie = bcma_find_core(bus, BCMA_CORE_PCIE);
  250. i2s = bcma_find_core(bus, BCMA_CORE_I2S);
  251. if (cpu && pcie && i2s &&
  252. bcma_aread32(cpu, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
  253. bcma_aread32(pcie, BCMA_MIPS_OOBSELINA74) == 0x08060504 &&
  254. bcma_aread32(i2s, BCMA_MIPS_OOBSELOUTA30) == 0x88) {
  255. bcma_awrite32(cpu, BCMA_MIPS_OOBSELINA74, 0x07060504);
  256. bcma_awrite32(pcie, BCMA_MIPS_OOBSELINA74, 0x07060504);
  257. bcma_awrite32(i2s, BCMA_MIPS_OOBSELOUTA30, 0x87);
  258. bcma_debug(bus,
  259. "Moved i2s interrupt to oob line 7 instead of 8\n");
  260. }
  261. }
  262. void bcma_core_mips_init(struct bcma_drv_mips *mcore)
  263. {
  264. struct bcma_bus *bus;
  265. struct bcma_device *core;
  266. bus = mcore->core->bus;
  267. if (mcore->setup_done)
  268. return;
  269. bcma_debug(bus, "Initializing MIPS core...\n");
  270. bcma_core_mips_early_init(mcore);
  271. bcma_fix_i2s_irqflag(bus);
  272. switch (bus->chipinfo.id) {
  273. case BCMA_CHIP_ID_BCM4716:
  274. case BCMA_CHIP_ID_BCM4748:
  275. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  276. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  277. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  278. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_PCIE, 0);
  279. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  280. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  281. break;
  282. case BCMA_CHIP_ID_BCM5356:
  283. case BCMA_CHIP_ID_BCM47162:
  284. case BCMA_CHIP_ID_BCM53572:
  285. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  286. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  287. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  288. break;
  289. case BCMA_CHIP_ID_BCM5357:
  290. case BCMA_CHIP_ID_BCM4749:
  291. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_80211, 0);
  292. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_MAC_GBIT, 0);
  293. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_USB20_HOST, 0);
  294. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_CHIPCOMMON, 0);
  295. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_I2S, 0);
  296. break;
  297. case BCMA_CHIP_ID_BCM4706:
  298. bcma_core_mips_set_irq_name(bus, 1, BCMA_CORE_PCIE, 0);
  299. bcma_core_mips_set_irq_name(bus, 2, BCMA_CORE_4706_MAC_GBIT,
  300. 0);
  301. bcma_core_mips_set_irq_name(bus, 3, BCMA_CORE_PCIE, 1);
  302. bcma_core_mips_set_irq_name(bus, 4, BCMA_CORE_USB20_HOST, 0);
  303. bcma_core_mips_set_irq_name(bus, 0, BCMA_CORE_4706_CHIPCOMMON,
  304. 0);
  305. break;
  306. default:
  307. list_for_each_entry(core, &bus->cores, list) {
  308. core->irq = bcma_core_irq(core);
  309. }
  310. bcma_err(bus,
  311. "Unknown device (0x%x) found, can not configure IRQs\n",
  312. bus->chipinfo.id);
  313. }
  314. bcma_debug(bus, "IRQ reconfiguration done\n");
  315. bcma_core_mips_dump_irq(bus);
  316. mcore->setup_done = true;
  317. }