common.c 14 KB

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