common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * arch/arm/mach-kirkwood/common.c
  3. *
  4. * Core functions for Marvell Kirkwood SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/serial_8250.h>
  14. #include <linux/mbus.h>
  15. #include <linux/mv643xx_eth.h>
  16. #include <linux/ata_platform.h>
  17. #include <linux/spi/orion_spi.h>
  18. #include <asm/page.h>
  19. #include <asm/timex.h>
  20. #include <asm/mach/map.h>
  21. #include <asm/mach/time.h>
  22. #include <mach/kirkwood.h>
  23. #include <plat/cache-feroceon-l2.h>
  24. #include <plat/ehci-orion.h>
  25. #include <plat/mv_xor.h>
  26. #include <plat/orion_nand.h>
  27. #include <plat/time.h>
  28. #include "common.h"
  29. /*****************************************************************************
  30. * I/O Address Mapping
  31. ****************************************************************************/
  32. static struct map_desc kirkwood_io_desc[] __initdata = {
  33. {
  34. .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
  35. .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
  36. .length = KIRKWOOD_PCIE_IO_SIZE,
  37. .type = MT_DEVICE,
  38. }, {
  39. .virtual = KIRKWOOD_REGS_VIRT_BASE,
  40. .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
  41. .length = KIRKWOOD_REGS_SIZE,
  42. .type = MT_DEVICE,
  43. },
  44. };
  45. void __init kirkwood_map_io(void)
  46. {
  47. iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
  48. }
  49. /*****************************************************************************
  50. * EHCI
  51. ****************************************************************************/
  52. static struct orion_ehci_data kirkwood_ehci_data = {
  53. .dram = &kirkwood_mbus_dram_info,
  54. };
  55. static u64 ehci_dmamask = 0xffffffffUL;
  56. /*****************************************************************************
  57. * EHCI0
  58. ****************************************************************************/
  59. static struct resource kirkwood_ehci_resources[] = {
  60. {
  61. .start = USB_PHYS_BASE,
  62. .end = USB_PHYS_BASE + 0x0fff,
  63. .flags = IORESOURCE_MEM,
  64. }, {
  65. .start = IRQ_KIRKWOOD_USB,
  66. .end = IRQ_KIRKWOOD_USB,
  67. .flags = IORESOURCE_IRQ,
  68. },
  69. };
  70. static struct platform_device kirkwood_ehci = {
  71. .name = "orion-ehci",
  72. .id = 0,
  73. .dev = {
  74. .dma_mask = &ehci_dmamask,
  75. .coherent_dma_mask = 0xffffffff,
  76. .platform_data = &kirkwood_ehci_data,
  77. },
  78. .resource = kirkwood_ehci_resources,
  79. .num_resources = ARRAY_SIZE(kirkwood_ehci_resources),
  80. };
  81. void __init kirkwood_ehci_init(void)
  82. {
  83. platform_device_register(&kirkwood_ehci);
  84. }
  85. /*****************************************************************************
  86. * GE00
  87. ****************************************************************************/
  88. struct mv643xx_eth_shared_platform_data kirkwood_ge00_shared_data = {
  89. .dram = &kirkwood_mbus_dram_info,
  90. };
  91. static struct resource kirkwood_ge00_shared_resources[] = {
  92. {
  93. .name = "ge00 base",
  94. .start = GE00_PHYS_BASE + 0x2000,
  95. .end = GE00_PHYS_BASE + 0x3fff,
  96. .flags = IORESOURCE_MEM,
  97. }, {
  98. .name = "ge00 err irq",
  99. .start = IRQ_KIRKWOOD_GE00_ERR,
  100. .end = IRQ_KIRKWOOD_GE00_ERR,
  101. .flags = IORESOURCE_IRQ,
  102. },
  103. };
  104. static struct platform_device kirkwood_ge00_shared = {
  105. .name = MV643XX_ETH_SHARED_NAME,
  106. .id = 0,
  107. .dev = {
  108. .platform_data = &kirkwood_ge00_shared_data,
  109. },
  110. .num_resources = ARRAY_SIZE(kirkwood_ge00_shared_resources),
  111. .resource = kirkwood_ge00_shared_resources,
  112. };
  113. static struct resource kirkwood_ge00_resources[] = {
  114. {
  115. .name = "ge00 irq",
  116. .start = IRQ_KIRKWOOD_GE00_SUM,
  117. .end = IRQ_KIRKWOOD_GE00_SUM,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. };
  121. static struct platform_device kirkwood_ge00 = {
  122. .name = MV643XX_ETH_NAME,
  123. .id = 0,
  124. .num_resources = 1,
  125. .resource = kirkwood_ge00_resources,
  126. };
  127. void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  128. {
  129. eth_data->shared = &kirkwood_ge00_shared;
  130. kirkwood_ge00.dev.platform_data = eth_data;
  131. platform_device_register(&kirkwood_ge00_shared);
  132. platform_device_register(&kirkwood_ge00);
  133. }
  134. /*****************************************************************************
  135. * SoC RTC
  136. ****************************************************************************/
  137. static struct resource kirkwood_rtc_resource = {
  138. .start = RTC_PHYS_BASE,
  139. .end = RTC_PHYS_BASE + SZ_16 - 1,
  140. .flags = IORESOURCE_MEM,
  141. };
  142. void __init kirkwood_rtc_init(void)
  143. {
  144. platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
  145. }
  146. /*****************************************************************************
  147. * SATA
  148. ****************************************************************************/
  149. static struct resource kirkwood_sata_resources[] = {
  150. {
  151. .name = "sata base",
  152. .start = SATA_PHYS_BASE,
  153. .end = SATA_PHYS_BASE + 0x5000 - 1,
  154. .flags = IORESOURCE_MEM,
  155. }, {
  156. .name = "sata irq",
  157. .start = IRQ_KIRKWOOD_SATA,
  158. .end = IRQ_KIRKWOOD_SATA,
  159. .flags = IORESOURCE_IRQ,
  160. },
  161. };
  162. static struct platform_device kirkwood_sata = {
  163. .name = "sata_mv",
  164. .id = 0,
  165. .dev = {
  166. .coherent_dma_mask = 0xffffffff,
  167. },
  168. .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
  169. .resource = kirkwood_sata_resources,
  170. };
  171. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  172. {
  173. sata_data->dram = &kirkwood_mbus_dram_info;
  174. kirkwood_sata.dev.platform_data = sata_data;
  175. platform_device_register(&kirkwood_sata);
  176. }
  177. /*****************************************************************************
  178. * SPI
  179. ****************************************************************************/
  180. static struct orion_spi_info kirkwood_spi_plat_data = {
  181. };
  182. static struct resource kirkwood_spi_resources[] = {
  183. {
  184. .start = SPI_PHYS_BASE,
  185. .end = SPI_PHYS_BASE + SZ_512 - 1,
  186. .flags = IORESOURCE_MEM,
  187. },
  188. };
  189. static struct platform_device kirkwood_spi = {
  190. .name = "orion_spi",
  191. .id = 0,
  192. .resource = kirkwood_spi_resources,
  193. .dev = {
  194. .platform_data = &kirkwood_spi_plat_data,
  195. },
  196. .num_resources = ARRAY_SIZE(kirkwood_spi_resources),
  197. };
  198. void __init kirkwood_spi_init()
  199. {
  200. platform_device_register(&kirkwood_spi);
  201. }
  202. /*****************************************************************************
  203. * UART0
  204. ****************************************************************************/
  205. static struct plat_serial8250_port kirkwood_uart0_data[] = {
  206. {
  207. .mapbase = UART0_PHYS_BASE,
  208. .membase = (char *)UART0_VIRT_BASE,
  209. .irq = IRQ_KIRKWOOD_UART_0,
  210. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  211. .iotype = UPIO_MEM,
  212. .regshift = 2,
  213. .uartclk = 0,
  214. }, {
  215. },
  216. };
  217. static struct resource kirkwood_uart0_resources[] = {
  218. {
  219. .start = UART0_PHYS_BASE,
  220. .end = UART0_PHYS_BASE + 0xff,
  221. .flags = IORESOURCE_MEM,
  222. }, {
  223. .start = IRQ_KIRKWOOD_UART_0,
  224. .end = IRQ_KIRKWOOD_UART_0,
  225. .flags = IORESOURCE_IRQ,
  226. },
  227. };
  228. static struct platform_device kirkwood_uart0 = {
  229. .name = "serial8250",
  230. .id = 0,
  231. .dev = {
  232. .platform_data = kirkwood_uart0_data,
  233. },
  234. .resource = kirkwood_uart0_resources,
  235. .num_resources = ARRAY_SIZE(kirkwood_uart0_resources),
  236. };
  237. void __init kirkwood_uart0_init(void)
  238. {
  239. platform_device_register(&kirkwood_uart0);
  240. }
  241. /*****************************************************************************
  242. * UART1
  243. ****************************************************************************/
  244. static struct plat_serial8250_port kirkwood_uart1_data[] = {
  245. {
  246. .mapbase = UART1_PHYS_BASE,
  247. .membase = (char *)UART1_VIRT_BASE,
  248. .irq = IRQ_KIRKWOOD_UART_1,
  249. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  250. .iotype = UPIO_MEM,
  251. .regshift = 2,
  252. .uartclk = 0,
  253. }, {
  254. },
  255. };
  256. static struct resource kirkwood_uart1_resources[] = {
  257. {
  258. .start = UART1_PHYS_BASE,
  259. .end = UART1_PHYS_BASE + 0xff,
  260. .flags = IORESOURCE_MEM,
  261. }, {
  262. .start = IRQ_KIRKWOOD_UART_1,
  263. .end = IRQ_KIRKWOOD_UART_1,
  264. .flags = IORESOURCE_IRQ,
  265. },
  266. };
  267. static struct platform_device kirkwood_uart1 = {
  268. .name = "serial8250",
  269. .id = 1,
  270. .dev = {
  271. .platform_data = kirkwood_uart1_data,
  272. },
  273. .resource = kirkwood_uart1_resources,
  274. .num_resources = ARRAY_SIZE(kirkwood_uart1_resources),
  275. };
  276. void __init kirkwood_uart1_init(void)
  277. {
  278. platform_device_register(&kirkwood_uart1);
  279. }
  280. /*****************************************************************************
  281. * XOR
  282. ****************************************************************************/
  283. static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
  284. .dram = &kirkwood_mbus_dram_info,
  285. };
  286. static u64 kirkwood_xor_dmamask = DMA_32BIT_MASK;
  287. /*****************************************************************************
  288. * XOR0
  289. ****************************************************************************/
  290. static struct resource kirkwood_xor0_shared_resources[] = {
  291. {
  292. .name = "xor 0 low",
  293. .start = XOR0_PHYS_BASE,
  294. .end = XOR0_PHYS_BASE + 0xff,
  295. .flags = IORESOURCE_MEM,
  296. }, {
  297. .name = "xor 0 high",
  298. .start = XOR0_HIGH_PHYS_BASE,
  299. .end = XOR0_HIGH_PHYS_BASE + 0xff,
  300. .flags = IORESOURCE_MEM,
  301. },
  302. };
  303. static struct platform_device kirkwood_xor0_shared = {
  304. .name = MV_XOR_SHARED_NAME,
  305. .id = 0,
  306. .dev = {
  307. .platform_data = &kirkwood_xor_shared_data,
  308. },
  309. .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
  310. .resource = kirkwood_xor0_shared_resources,
  311. };
  312. static struct resource kirkwood_xor00_resources[] = {
  313. [0] = {
  314. .start = IRQ_KIRKWOOD_XOR_00,
  315. .end = IRQ_KIRKWOOD_XOR_00,
  316. .flags = IORESOURCE_IRQ,
  317. },
  318. };
  319. static struct mv_xor_platform_data kirkwood_xor00_data = {
  320. .shared = &kirkwood_xor0_shared,
  321. .hw_id = 0,
  322. .pool_size = PAGE_SIZE,
  323. };
  324. static struct platform_device kirkwood_xor00_channel = {
  325. .name = MV_XOR_NAME,
  326. .id = 0,
  327. .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
  328. .resource = kirkwood_xor00_resources,
  329. .dev = {
  330. .dma_mask = &kirkwood_xor_dmamask,
  331. .coherent_dma_mask = DMA_64BIT_MASK,
  332. .platform_data = (void *)&kirkwood_xor00_data,
  333. },
  334. };
  335. static struct resource kirkwood_xor01_resources[] = {
  336. [0] = {
  337. .start = IRQ_KIRKWOOD_XOR_01,
  338. .end = IRQ_KIRKWOOD_XOR_01,
  339. .flags = IORESOURCE_IRQ,
  340. },
  341. };
  342. static struct mv_xor_platform_data kirkwood_xor01_data = {
  343. .shared = &kirkwood_xor0_shared,
  344. .hw_id = 1,
  345. .pool_size = PAGE_SIZE,
  346. };
  347. static struct platform_device kirkwood_xor01_channel = {
  348. .name = MV_XOR_NAME,
  349. .id = 1,
  350. .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
  351. .resource = kirkwood_xor01_resources,
  352. .dev = {
  353. .dma_mask = &kirkwood_xor_dmamask,
  354. .coherent_dma_mask = DMA_64BIT_MASK,
  355. .platform_data = (void *)&kirkwood_xor01_data,
  356. },
  357. };
  358. void __init kirkwood_xor0_init(void)
  359. {
  360. platform_device_register(&kirkwood_xor0_shared);
  361. /*
  362. * two engines can't do memset simultaneously, this limitation
  363. * satisfied by removing memset support from one of the engines.
  364. */
  365. dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
  366. dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
  367. platform_device_register(&kirkwood_xor00_channel);
  368. dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
  369. dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
  370. dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
  371. platform_device_register(&kirkwood_xor01_channel);
  372. }
  373. /*****************************************************************************
  374. * XOR1
  375. ****************************************************************************/
  376. static struct resource kirkwood_xor1_shared_resources[] = {
  377. {
  378. .name = "xor 1 low",
  379. .start = XOR1_PHYS_BASE,
  380. .end = XOR1_PHYS_BASE + 0xff,
  381. .flags = IORESOURCE_MEM,
  382. }, {
  383. .name = "xor 1 high",
  384. .start = XOR1_HIGH_PHYS_BASE,
  385. .end = XOR1_HIGH_PHYS_BASE + 0xff,
  386. .flags = IORESOURCE_MEM,
  387. },
  388. };
  389. static struct platform_device kirkwood_xor1_shared = {
  390. .name = MV_XOR_SHARED_NAME,
  391. .id = 1,
  392. .dev = {
  393. .platform_data = &kirkwood_xor_shared_data,
  394. },
  395. .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
  396. .resource = kirkwood_xor1_shared_resources,
  397. };
  398. static struct resource kirkwood_xor10_resources[] = {
  399. [0] = {
  400. .start = IRQ_KIRKWOOD_XOR_10,
  401. .end = IRQ_KIRKWOOD_XOR_10,
  402. .flags = IORESOURCE_IRQ,
  403. },
  404. };
  405. static struct mv_xor_platform_data kirkwood_xor10_data = {
  406. .shared = &kirkwood_xor1_shared,
  407. .hw_id = 0,
  408. .pool_size = PAGE_SIZE,
  409. };
  410. static struct platform_device kirkwood_xor10_channel = {
  411. .name = MV_XOR_NAME,
  412. .id = 2,
  413. .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
  414. .resource = kirkwood_xor10_resources,
  415. .dev = {
  416. .dma_mask = &kirkwood_xor_dmamask,
  417. .coherent_dma_mask = DMA_64BIT_MASK,
  418. .platform_data = (void *)&kirkwood_xor10_data,
  419. },
  420. };
  421. static struct resource kirkwood_xor11_resources[] = {
  422. [0] = {
  423. .start = IRQ_KIRKWOOD_XOR_11,
  424. .end = IRQ_KIRKWOOD_XOR_11,
  425. .flags = IORESOURCE_IRQ,
  426. },
  427. };
  428. static struct mv_xor_platform_data kirkwood_xor11_data = {
  429. .shared = &kirkwood_xor1_shared,
  430. .hw_id = 1,
  431. .pool_size = PAGE_SIZE,
  432. };
  433. static struct platform_device kirkwood_xor11_channel = {
  434. .name = MV_XOR_NAME,
  435. .id = 3,
  436. .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
  437. .resource = kirkwood_xor11_resources,
  438. .dev = {
  439. .dma_mask = &kirkwood_xor_dmamask,
  440. .coherent_dma_mask = DMA_64BIT_MASK,
  441. .platform_data = (void *)&kirkwood_xor11_data,
  442. },
  443. };
  444. void __init kirkwood_xor1_init(void)
  445. {
  446. platform_device_register(&kirkwood_xor1_shared);
  447. /*
  448. * two engines can't do memset simultaneously, this limitation
  449. * satisfied by removing memset support from one of the engines.
  450. */
  451. dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
  452. dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
  453. platform_device_register(&kirkwood_xor10_channel);
  454. dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
  455. dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
  456. dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
  457. platform_device_register(&kirkwood_xor11_channel);
  458. }
  459. /*****************************************************************************
  460. * Time handling
  461. ****************************************************************************/
  462. int kirkwood_tclk;
  463. int __init kirkwood_find_tclk(void)
  464. {
  465. u32 dev, rev;
  466. kirkwood_pcie_id(&dev, &rev);
  467. if (dev == MV88F6281_DEV_ID && rev == MV88F6281_REV_A0)
  468. return 200000000;
  469. return 166666667;
  470. }
  471. static void kirkwood_timer_init(void)
  472. {
  473. kirkwood_tclk = kirkwood_find_tclk();
  474. orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  475. }
  476. struct sys_timer kirkwood_timer = {
  477. .init = kirkwood_timer_init,
  478. };
  479. /*****************************************************************************
  480. * General
  481. ****************************************************************************/
  482. /*
  483. * Identify device ID and revision.
  484. */
  485. static char * __init kirkwood_id(void)
  486. {
  487. u32 dev, rev;
  488. kirkwood_pcie_id(&dev, &rev);
  489. if (dev == MV88F6281_DEV_ID) {
  490. if (rev == MV88F6281_REV_Z0)
  491. return "MV88F6281-Z0";
  492. else if (rev == MV88F6281_REV_A0)
  493. return "MV88F6281-A0";
  494. else
  495. return "MV88F6281-Rev-Unsupported";
  496. } else if (dev == MV88F6192_DEV_ID) {
  497. if (rev == MV88F6192_REV_Z0)
  498. return "MV88F6192-Z0";
  499. else if (rev == MV88F6192_REV_A0)
  500. return "MV88F6192-A0";
  501. else
  502. return "MV88F6192-Rev-Unsupported";
  503. } else if (dev == MV88F6180_DEV_ID) {
  504. if (rev == MV88F6180_REV_A0)
  505. return "MV88F6180-Rev-A0";
  506. else
  507. return "MV88F6180-Rev-Unsupported";
  508. } else {
  509. return "Device-Unknown";
  510. }
  511. }
  512. static void __init kirkwood_l2_init(void)
  513. {
  514. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  515. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  516. feroceon_l2_init(1);
  517. #else
  518. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  519. feroceon_l2_init(0);
  520. #endif
  521. }
  522. void __init kirkwood_init(void)
  523. {
  524. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  525. kirkwood_id(), kirkwood_tclk);
  526. kirkwood_ge00_shared_data.t_clk = kirkwood_tclk;
  527. kirkwood_spi_plat_data.tclk = kirkwood_tclk;
  528. kirkwood_uart0_data[0].uartclk = kirkwood_tclk;
  529. kirkwood_uart1_data[0].uartclk = kirkwood_tclk;
  530. kirkwood_setup_cpu_mbus();
  531. #ifdef CONFIG_CACHE_FEROCEON_L2
  532. kirkwood_l2_init();
  533. #endif
  534. }