common.c 14 KB

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