common.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. * arch/arm/mach-orion5x/common.c
  3. *
  4. * Core functions for Marvell Orion 5x SoCs
  5. *
  6. * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/serial_8250.h>
  16. #include <linux/mbus.h>
  17. #include <linux/mv643xx_i2c.h>
  18. #include <linux/ata_platform.h>
  19. #include <net/dsa.h>
  20. #include <asm/page.h>
  21. #include <asm/setup.h>
  22. #include <asm/timex.h>
  23. #include <asm/mach/arch.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/mach/time.h>
  26. #include <mach/bridge-regs.h>
  27. #include <mach/hardware.h>
  28. #include <mach/orion5x.h>
  29. #include <plat/ehci-orion.h>
  30. #include <plat/mv_xor.h>
  31. #include <plat/orion_nand.h>
  32. #include <plat/orion_wdt.h>
  33. #include <plat/time.h>
  34. #include <plat/common.h>
  35. #include "common.h"
  36. /*****************************************************************************
  37. * I/O Address Mapping
  38. ****************************************************************************/
  39. static struct map_desc orion5x_io_desc[] __initdata = {
  40. {
  41. .virtual = ORION5X_REGS_VIRT_BASE,
  42. .pfn = __phys_to_pfn(ORION5X_REGS_PHYS_BASE),
  43. .length = ORION5X_REGS_SIZE,
  44. .type = MT_DEVICE,
  45. }, {
  46. .virtual = ORION5X_PCIE_IO_VIRT_BASE,
  47. .pfn = __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE),
  48. .length = ORION5X_PCIE_IO_SIZE,
  49. .type = MT_DEVICE,
  50. }, {
  51. .virtual = ORION5X_PCI_IO_VIRT_BASE,
  52. .pfn = __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE),
  53. .length = ORION5X_PCI_IO_SIZE,
  54. .type = MT_DEVICE,
  55. }, {
  56. .virtual = ORION5X_PCIE_WA_VIRT_BASE,
  57. .pfn = __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE),
  58. .length = ORION5X_PCIE_WA_SIZE,
  59. .type = MT_DEVICE,
  60. },
  61. };
  62. void __init orion5x_map_io(void)
  63. {
  64. iotable_init(orion5x_io_desc, ARRAY_SIZE(orion5x_io_desc));
  65. }
  66. /*****************************************************************************
  67. * EHCI
  68. ****************************************************************************/
  69. static struct orion_ehci_data orion5x_ehci_data = {
  70. .dram = &orion5x_mbus_dram_info,
  71. .phy_version = EHCI_PHY_ORION,
  72. };
  73. static u64 ehci_dmamask = DMA_BIT_MASK(32);
  74. /*****************************************************************************
  75. * EHCI0
  76. ****************************************************************************/
  77. static struct resource orion5x_ehci0_resources[] = {
  78. {
  79. .start = ORION5X_USB0_PHYS_BASE,
  80. .end = ORION5X_USB0_PHYS_BASE + SZ_4K - 1,
  81. .flags = IORESOURCE_MEM,
  82. }, {
  83. .start = IRQ_ORION5X_USB0_CTRL,
  84. .end = IRQ_ORION5X_USB0_CTRL,
  85. .flags = IORESOURCE_IRQ,
  86. },
  87. };
  88. static struct platform_device orion5x_ehci0 = {
  89. .name = "orion-ehci",
  90. .id = 0,
  91. .dev = {
  92. .dma_mask = &ehci_dmamask,
  93. .coherent_dma_mask = DMA_BIT_MASK(32),
  94. .platform_data = &orion5x_ehci_data,
  95. },
  96. .resource = orion5x_ehci0_resources,
  97. .num_resources = ARRAY_SIZE(orion5x_ehci0_resources),
  98. };
  99. void __init orion5x_ehci0_init(void)
  100. {
  101. platform_device_register(&orion5x_ehci0);
  102. }
  103. /*****************************************************************************
  104. * EHCI1
  105. ****************************************************************************/
  106. static struct resource orion5x_ehci1_resources[] = {
  107. {
  108. .start = ORION5X_USB1_PHYS_BASE,
  109. .end = ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
  110. .flags = IORESOURCE_MEM,
  111. }, {
  112. .start = IRQ_ORION5X_USB1_CTRL,
  113. .end = IRQ_ORION5X_USB1_CTRL,
  114. .flags = IORESOURCE_IRQ,
  115. },
  116. };
  117. static struct platform_device orion5x_ehci1 = {
  118. .name = "orion-ehci",
  119. .id = 1,
  120. .dev = {
  121. .dma_mask = &ehci_dmamask,
  122. .coherent_dma_mask = DMA_BIT_MASK(32),
  123. .platform_data = &orion5x_ehci_data,
  124. },
  125. .resource = orion5x_ehci1_resources,
  126. .num_resources = ARRAY_SIZE(orion5x_ehci1_resources),
  127. };
  128. void __init orion5x_ehci1_init(void)
  129. {
  130. platform_device_register(&orion5x_ehci1);
  131. }
  132. /*****************************************************************************
  133. * GE00
  134. ****************************************************************************/
  135. void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
  136. {
  137. orion_ge00_init(eth_data, &orion5x_mbus_dram_info,
  138. ORION5X_ETH_PHYS_BASE, IRQ_ORION5X_ETH_SUM,
  139. IRQ_ORION5X_ETH_ERR, orion5x_tclk);
  140. }
  141. /*****************************************************************************
  142. * Ethernet switch
  143. ****************************************************************************/
  144. void __init orion5x_eth_switch_init(struct dsa_platform_data *d, int irq)
  145. {
  146. orion_ge00_switch_init(d, irq);
  147. }
  148. /*****************************************************************************
  149. * I2C
  150. ****************************************************************************/
  151. void __init orion5x_i2c_init(void)
  152. {
  153. orion_i2c_init(I2C_PHYS_BASE, IRQ_ORION5X_I2C, 8);
  154. }
  155. /*****************************************************************************
  156. * SATA
  157. ****************************************************************************/
  158. static struct resource orion5x_sata_resources[] = {
  159. {
  160. .name = "sata base",
  161. .start = ORION5X_SATA_PHYS_BASE,
  162. .end = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
  163. .flags = IORESOURCE_MEM,
  164. }, {
  165. .name = "sata irq",
  166. .start = IRQ_ORION5X_SATA,
  167. .end = IRQ_ORION5X_SATA,
  168. .flags = IORESOURCE_IRQ,
  169. },
  170. };
  171. static struct platform_device orion5x_sata = {
  172. .name = "sata_mv",
  173. .id = 0,
  174. .dev = {
  175. .coherent_dma_mask = DMA_BIT_MASK(32),
  176. },
  177. .num_resources = ARRAY_SIZE(orion5x_sata_resources),
  178. .resource = orion5x_sata_resources,
  179. };
  180. void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
  181. {
  182. sata_data->dram = &orion5x_mbus_dram_info;
  183. orion5x_sata.dev.platform_data = sata_data;
  184. platform_device_register(&orion5x_sata);
  185. }
  186. /*****************************************************************************
  187. * SPI
  188. ****************************************************************************/
  189. void __init orion5x_spi_init()
  190. {
  191. orion_spi_init(SPI_PHYS_BASE, orion5x_tclk);
  192. }
  193. /*****************************************************************************
  194. * UART0
  195. ****************************************************************************/
  196. void __init orion5x_uart0_init(void)
  197. {
  198. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  199. IRQ_ORION5X_UART0, orion5x_tclk);
  200. }
  201. /*****************************************************************************
  202. * UART1
  203. ****************************************************************************/
  204. void __init orion5x_uart1_init(void)
  205. {
  206. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  207. IRQ_ORION5X_UART1, orion5x_tclk);
  208. }
  209. /*****************************************************************************
  210. * XOR engine
  211. ****************************************************************************/
  212. struct mv_xor_platform_shared_data orion5x_xor_shared_data = {
  213. .dram = &orion5x_mbus_dram_info,
  214. };
  215. static struct resource orion5x_xor_shared_resources[] = {
  216. {
  217. .name = "xor low",
  218. .start = ORION5X_XOR_PHYS_BASE,
  219. .end = ORION5X_XOR_PHYS_BASE + 0xff,
  220. .flags = IORESOURCE_MEM,
  221. }, {
  222. .name = "xor high",
  223. .start = ORION5X_XOR_PHYS_BASE + 0x200,
  224. .end = ORION5X_XOR_PHYS_BASE + 0x2ff,
  225. .flags = IORESOURCE_MEM,
  226. },
  227. };
  228. static struct platform_device orion5x_xor_shared = {
  229. .name = MV_XOR_SHARED_NAME,
  230. .id = 0,
  231. .dev = {
  232. .platform_data = &orion5x_xor_shared_data,
  233. },
  234. .num_resources = ARRAY_SIZE(orion5x_xor_shared_resources),
  235. .resource = orion5x_xor_shared_resources,
  236. };
  237. static u64 orion5x_xor_dmamask = DMA_BIT_MASK(32);
  238. static struct resource orion5x_xor0_resources[] = {
  239. [0] = {
  240. .start = IRQ_ORION5X_XOR0,
  241. .end = IRQ_ORION5X_XOR0,
  242. .flags = IORESOURCE_IRQ,
  243. },
  244. };
  245. static struct mv_xor_platform_data orion5x_xor0_data = {
  246. .shared = &orion5x_xor_shared,
  247. .hw_id = 0,
  248. .pool_size = PAGE_SIZE,
  249. };
  250. static struct platform_device orion5x_xor0_channel = {
  251. .name = MV_XOR_NAME,
  252. .id = 0,
  253. .num_resources = ARRAY_SIZE(orion5x_xor0_resources),
  254. .resource = orion5x_xor0_resources,
  255. .dev = {
  256. .dma_mask = &orion5x_xor_dmamask,
  257. .coherent_dma_mask = DMA_BIT_MASK(64),
  258. .platform_data = &orion5x_xor0_data,
  259. },
  260. };
  261. static struct resource orion5x_xor1_resources[] = {
  262. [0] = {
  263. .start = IRQ_ORION5X_XOR1,
  264. .end = IRQ_ORION5X_XOR1,
  265. .flags = IORESOURCE_IRQ,
  266. },
  267. };
  268. static struct mv_xor_platform_data orion5x_xor1_data = {
  269. .shared = &orion5x_xor_shared,
  270. .hw_id = 1,
  271. .pool_size = PAGE_SIZE,
  272. };
  273. static struct platform_device orion5x_xor1_channel = {
  274. .name = MV_XOR_NAME,
  275. .id = 1,
  276. .num_resources = ARRAY_SIZE(orion5x_xor1_resources),
  277. .resource = orion5x_xor1_resources,
  278. .dev = {
  279. .dma_mask = &orion5x_xor_dmamask,
  280. .coherent_dma_mask = DMA_BIT_MASK(64),
  281. .platform_data = &orion5x_xor1_data,
  282. },
  283. };
  284. void __init orion5x_xor_init(void)
  285. {
  286. platform_device_register(&orion5x_xor_shared);
  287. /*
  288. * two engines can't do memset simultaneously, this limitation
  289. * satisfied by removing memset support from one of the engines.
  290. */
  291. dma_cap_set(DMA_MEMCPY, orion5x_xor0_data.cap_mask);
  292. dma_cap_set(DMA_XOR, orion5x_xor0_data.cap_mask);
  293. platform_device_register(&orion5x_xor0_channel);
  294. dma_cap_set(DMA_MEMCPY, orion5x_xor1_data.cap_mask);
  295. dma_cap_set(DMA_MEMSET, orion5x_xor1_data.cap_mask);
  296. dma_cap_set(DMA_XOR, orion5x_xor1_data.cap_mask);
  297. platform_device_register(&orion5x_xor1_channel);
  298. }
  299. static struct resource orion5x_crypto_res[] = {
  300. {
  301. .name = "regs",
  302. .start = ORION5X_CRYPTO_PHYS_BASE,
  303. .end = ORION5X_CRYPTO_PHYS_BASE + 0xffff,
  304. .flags = IORESOURCE_MEM,
  305. }, {
  306. .name = "sram",
  307. .start = ORION5X_SRAM_PHYS_BASE,
  308. .end = ORION5X_SRAM_PHYS_BASE + SZ_8K - 1,
  309. .flags = IORESOURCE_MEM,
  310. }, {
  311. .name = "crypto interrupt",
  312. .start = IRQ_ORION5X_CESA,
  313. .end = IRQ_ORION5X_CESA,
  314. .flags = IORESOURCE_IRQ,
  315. },
  316. };
  317. static struct platform_device orion5x_crypto_device = {
  318. .name = "mv_crypto",
  319. .id = -1,
  320. .num_resources = ARRAY_SIZE(orion5x_crypto_res),
  321. .resource = orion5x_crypto_res,
  322. };
  323. static int __init orion5x_crypto_init(void)
  324. {
  325. int ret;
  326. ret = orion5x_setup_sram_win();
  327. if (ret)
  328. return ret;
  329. return platform_device_register(&orion5x_crypto_device);
  330. }
  331. /*****************************************************************************
  332. * Watchdog
  333. ****************************************************************************/
  334. static struct orion_wdt_platform_data orion5x_wdt_data = {
  335. .tclk = 0,
  336. };
  337. static struct platform_device orion5x_wdt_device = {
  338. .name = "orion_wdt",
  339. .id = -1,
  340. .dev = {
  341. .platform_data = &orion5x_wdt_data,
  342. },
  343. .num_resources = 0,
  344. };
  345. void __init orion5x_wdt_init(void)
  346. {
  347. orion5x_wdt_data.tclk = orion5x_tclk;
  348. platform_device_register(&orion5x_wdt_device);
  349. }
  350. /*****************************************************************************
  351. * Time handling
  352. ****************************************************************************/
  353. void __init orion5x_init_early(void)
  354. {
  355. orion_time_set_base(TIMER_VIRT_BASE);
  356. }
  357. int orion5x_tclk;
  358. int __init orion5x_find_tclk(void)
  359. {
  360. u32 dev, rev;
  361. orion5x_pcie_id(&dev, &rev);
  362. if (dev == MV88F6183_DEV_ID &&
  363. (readl(MPP_RESET_SAMPLE) & 0x00000200) == 0)
  364. return 133333333;
  365. return 166666667;
  366. }
  367. static void orion5x_timer_init(void)
  368. {
  369. orion5x_tclk = orion5x_find_tclk();
  370. orion_time_init(ORION5X_BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  371. IRQ_ORION5X_BRIDGE, orion5x_tclk);
  372. }
  373. struct sys_timer orion5x_timer = {
  374. .init = orion5x_timer_init,
  375. };
  376. /*****************************************************************************
  377. * General
  378. ****************************************************************************/
  379. /*
  380. * Identify device ID and rev from PCIe configuration header space '0'.
  381. */
  382. static void __init orion5x_id(u32 *dev, u32 *rev, char **dev_name)
  383. {
  384. orion5x_pcie_id(dev, rev);
  385. if (*dev == MV88F5281_DEV_ID) {
  386. if (*rev == MV88F5281_REV_D2) {
  387. *dev_name = "MV88F5281-D2";
  388. } else if (*rev == MV88F5281_REV_D1) {
  389. *dev_name = "MV88F5281-D1";
  390. } else if (*rev == MV88F5281_REV_D0) {
  391. *dev_name = "MV88F5281-D0";
  392. } else {
  393. *dev_name = "MV88F5281-Rev-Unsupported";
  394. }
  395. } else if (*dev == MV88F5182_DEV_ID) {
  396. if (*rev == MV88F5182_REV_A2) {
  397. *dev_name = "MV88F5182-A2";
  398. } else {
  399. *dev_name = "MV88F5182-Rev-Unsupported";
  400. }
  401. } else if (*dev == MV88F5181_DEV_ID) {
  402. if (*rev == MV88F5181_REV_B1) {
  403. *dev_name = "MV88F5181-Rev-B1";
  404. } else if (*rev == MV88F5181L_REV_A1) {
  405. *dev_name = "MV88F5181L-Rev-A1";
  406. } else {
  407. *dev_name = "MV88F5181(L)-Rev-Unsupported";
  408. }
  409. } else if (*dev == MV88F6183_DEV_ID) {
  410. if (*rev == MV88F6183_REV_B0) {
  411. *dev_name = "MV88F6183-Rev-B0";
  412. } else {
  413. *dev_name = "MV88F6183-Rev-Unsupported";
  414. }
  415. } else {
  416. *dev_name = "Device-Unknown";
  417. }
  418. }
  419. void __init orion5x_init(void)
  420. {
  421. char *dev_name;
  422. u32 dev, rev;
  423. orion5x_id(&dev, &rev, &dev_name);
  424. printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, orion5x_tclk);
  425. /*
  426. * Setup Orion address map
  427. */
  428. orion5x_setup_cpu_mbus_bridge();
  429. /*
  430. * Don't issue "Wait for Interrupt" instruction if we are
  431. * running on D0 5281 silicon.
  432. */
  433. if (dev == MV88F5281_DEV_ID && rev == MV88F5281_REV_D0) {
  434. printk(KERN_INFO "Orion: Applying 5281 D0 WFI workaround.\n");
  435. disable_hlt();
  436. }
  437. /*
  438. * The 5082/5181l/5182/6082/6082l/6183 have crypto
  439. * while 5180n/5181/5281 don't have crypto.
  440. */
  441. if ((dev == MV88F5181_DEV_ID && rev >= MV88F5181L_REV_A0) ||
  442. dev == MV88F5182_DEV_ID || dev == MV88F6183_DEV_ID)
  443. orion5x_crypto_init();
  444. /*
  445. * Register watchdog driver
  446. */
  447. orion5x_wdt_init();
  448. }
  449. /*
  450. * Many orion-based systems have buggy bootloader implementations.
  451. * This is a common fixup for bogus memory tags.
  452. */
  453. void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t,
  454. char **from, struct meminfo *meminfo)
  455. {
  456. for (; t->hdr.size; t = tag_next(t))
  457. if (t->hdr.tag == ATAG_MEM &&
  458. (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
  459. t->u.mem.start & ~PAGE_MASK)) {
  460. printk(KERN_WARNING
  461. "Clearing invalid memory bank %dKB@0x%08x\n",
  462. t->u.mem.size / 1024, t->u.mem.start);
  463. t->hdr.tag = 0;
  464. }
  465. }