common.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. .t_clk = KIRKWOOD_TCLK,
  90. .dram = &kirkwood_mbus_dram_info,
  91. };
  92. static struct resource kirkwood_ge00_shared_resources[] = {
  93. {
  94. .name = "ge00 base",
  95. .start = GE00_PHYS_BASE + 0x2000,
  96. .end = GE00_PHYS_BASE + 0x3fff,
  97. .flags = IORESOURCE_MEM,
  98. }, {
  99. .name = "ge00 err irq",
  100. .start = IRQ_KIRKWOOD_GE00_ERR,
  101. .end = IRQ_KIRKWOOD_GE00_ERR,
  102. .flags = IORESOURCE_IRQ,
  103. },
  104. };
  105. static struct platform_device kirkwood_ge00_shared = {
  106. .name = MV643XX_ETH_SHARED_NAME,
  107. .id = 0,
  108. .dev = {
  109. .platform_data = &kirkwood_ge00_shared_data,
  110. },
  111. .num_resources = ARRAY_SIZE(kirkwood_ge00_shared_resources),
  112. .resource = kirkwood_ge00_shared_resources,
  113. };
  114. static struct resource kirkwood_ge00_resources[] = {
  115. {
  116. .name = "ge00 irq",
  117. .start = IRQ_KIRKWOOD_GE00_SUM,
  118. .end = IRQ_KIRKWOOD_GE00_SUM,
  119. .flags = IORESOURCE_IRQ,
  120. },
  121. };
  122. static struct platform_device kirkwood_ge00 = {
  123. .name = MV643XX_ETH_NAME,
  124. .id = 0,
  125. .num_resources = 1,
  126. .resource = kirkwood_ge00_resources,
  127. };
  128. void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  129. {
  130. eth_data->shared = &kirkwood_ge00_shared;
  131. kirkwood_ge00.dev.platform_data = eth_data;
  132. platform_device_register(&kirkwood_ge00_shared);
  133. platform_device_register(&kirkwood_ge00);
  134. }
  135. /*****************************************************************************
  136. * SoC RTC
  137. ****************************************************************************/
  138. static struct resource kirkwood_rtc_resource = {
  139. .start = RTC_PHYS_BASE,
  140. .end = RTC_PHYS_BASE + SZ_16 - 1,
  141. .flags = IORESOURCE_MEM,
  142. };
  143. void __init kirkwood_rtc_init(void)
  144. {
  145. platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
  146. }
  147. /*****************************************************************************
  148. * SATA
  149. ****************************************************************************/
  150. static struct resource kirkwood_sata_resources[] = {
  151. {
  152. .name = "sata base",
  153. .start = SATA_PHYS_BASE,
  154. .end = SATA_PHYS_BASE + 0x5000 - 1,
  155. .flags = IORESOURCE_MEM,
  156. }, {
  157. .name = "sata irq",
  158. .start = IRQ_KIRKWOOD_SATA,
  159. .end = IRQ_KIRKWOOD_SATA,
  160. .flags = IORESOURCE_IRQ,
  161. },
  162. };
  163. static struct platform_device kirkwood_sata = {
  164. .name = "sata_mv",
  165. .id = 0,
  166. .dev = {
  167. .coherent_dma_mask = 0xffffffff,
  168. },
  169. .num_resources = ARRAY_SIZE(kirkwood_sata_resources),
  170. .resource = kirkwood_sata_resources,
  171. };
  172. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  173. {
  174. sata_data->dram = &kirkwood_mbus_dram_info;
  175. kirkwood_sata.dev.platform_data = sata_data;
  176. platform_device_register(&kirkwood_sata);
  177. }
  178. /*****************************************************************************
  179. * SPI
  180. ****************************************************************************/
  181. static struct orion_spi_info kirkwood_spi_plat_data = {
  182. .tclk = KIRKWOOD_TCLK,
  183. };
  184. static struct resource kirkwood_spi_resources[] = {
  185. {
  186. .start = SPI_PHYS_BASE,
  187. .end = SPI_PHYS_BASE + SZ_512 - 1,
  188. .flags = IORESOURCE_MEM,
  189. },
  190. };
  191. static struct platform_device kirkwood_spi = {
  192. .name = "orion_spi",
  193. .id = 0,
  194. .resource = kirkwood_spi_resources,
  195. .dev = {
  196. .platform_data = &kirkwood_spi_plat_data,
  197. },
  198. .num_resources = ARRAY_SIZE(kirkwood_spi_resources),
  199. };
  200. void __init kirkwood_spi_init()
  201. {
  202. platform_device_register(&kirkwood_spi);
  203. }
  204. /*****************************************************************************
  205. * UART0
  206. ****************************************************************************/
  207. static struct plat_serial8250_port kirkwood_uart0_data[] = {
  208. {
  209. .mapbase = UART0_PHYS_BASE,
  210. .membase = (char *)UART0_VIRT_BASE,
  211. .irq = IRQ_KIRKWOOD_UART_0,
  212. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  213. .iotype = UPIO_MEM,
  214. .regshift = 2,
  215. .uartclk = KIRKWOOD_TCLK,
  216. }, {
  217. },
  218. };
  219. static struct resource kirkwood_uart0_resources[] = {
  220. {
  221. .start = UART0_PHYS_BASE,
  222. .end = UART0_PHYS_BASE + 0xff,
  223. .flags = IORESOURCE_MEM,
  224. }, {
  225. .start = IRQ_KIRKWOOD_UART_0,
  226. .end = IRQ_KIRKWOOD_UART_0,
  227. .flags = IORESOURCE_IRQ,
  228. },
  229. };
  230. static struct platform_device kirkwood_uart0 = {
  231. .name = "serial8250",
  232. .id = 0,
  233. .dev = {
  234. .platform_data = kirkwood_uart0_data,
  235. },
  236. .resource = kirkwood_uart0_resources,
  237. .num_resources = ARRAY_SIZE(kirkwood_uart0_resources),
  238. };
  239. void __init kirkwood_uart0_init(void)
  240. {
  241. platform_device_register(&kirkwood_uart0);
  242. }
  243. /*****************************************************************************
  244. * UART1
  245. ****************************************************************************/
  246. static struct plat_serial8250_port kirkwood_uart1_data[] = {
  247. {
  248. .mapbase = UART1_PHYS_BASE,
  249. .membase = (char *)UART1_VIRT_BASE,
  250. .irq = IRQ_KIRKWOOD_UART_1,
  251. .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
  252. .iotype = UPIO_MEM,
  253. .regshift = 2,
  254. .uartclk = KIRKWOOD_TCLK,
  255. }, {
  256. },
  257. };
  258. static struct resource kirkwood_uart1_resources[] = {
  259. {
  260. .start = UART1_PHYS_BASE,
  261. .end = UART1_PHYS_BASE + 0xff,
  262. .flags = IORESOURCE_MEM,
  263. }, {
  264. .start = IRQ_KIRKWOOD_UART_1,
  265. .end = IRQ_KIRKWOOD_UART_1,
  266. .flags = IORESOURCE_IRQ,
  267. },
  268. };
  269. static struct platform_device kirkwood_uart1 = {
  270. .name = "serial8250",
  271. .id = 1,
  272. .dev = {
  273. .platform_data = kirkwood_uart1_data,
  274. },
  275. .resource = kirkwood_uart1_resources,
  276. .num_resources = ARRAY_SIZE(kirkwood_uart1_resources),
  277. };
  278. void __init kirkwood_uart1_init(void)
  279. {
  280. platform_device_register(&kirkwood_uart1);
  281. }
  282. /*****************************************************************************
  283. * XOR
  284. ****************************************************************************/
  285. static struct mv_xor_platform_shared_data kirkwood_xor_shared_data = {
  286. .dram = &kirkwood_mbus_dram_info,
  287. };
  288. static u64 kirkwood_xor_dmamask = DMA_32BIT_MASK;
  289. /*****************************************************************************
  290. * XOR0
  291. ****************************************************************************/
  292. static struct resource kirkwood_xor0_shared_resources[] = {
  293. {
  294. .name = "xor 0 low",
  295. .start = XOR0_PHYS_BASE,
  296. .end = XOR0_PHYS_BASE + 0xff,
  297. .flags = IORESOURCE_MEM,
  298. }, {
  299. .name = "xor 0 high",
  300. .start = XOR0_HIGH_PHYS_BASE,
  301. .end = XOR0_HIGH_PHYS_BASE + 0xff,
  302. .flags = IORESOURCE_MEM,
  303. },
  304. };
  305. static struct platform_device kirkwood_xor0_shared = {
  306. .name = MV_XOR_SHARED_NAME,
  307. .id = 0,
  308. .dev = {
  309. .platform_data = &kirkwood_xor_shared_data,
  310. },
  311. .num_resources = ARRAY_SIZE(kirkwood_xor0_shared_resources),
  312. .resource = kirkwood_xor0_shared_resources,
  313. };
  314. static struct resource kirkwood_xor00_resources[] = {
  315. [0] = {
  316. .start = IRQ_KIRKWOOD_XOR_00,
  317. .end = IRQ_KIRKWOOD_XOR_00,
  318. .flags = IORESOURCE_IRQ,
  319. },
  320. };
  321. static struct mv_xor_platform_data kirkwood_xor00_data = {
  322. .shared = &kirkwood_xor0_shared,
  323. .hw_id = 0,
  324. .pool_size = PAGE_SIZE,
  325. };
  326. static struct platform_device kirkwood_xor00_channel = {
  327. .name = MV_XOR_NAME,
  328. .id = 0,
  329. .num_resources = ARRAY_SIZE(kirkwood_xor00_resources),
  330. .resource = kirkwood_xor00_resources,
  331. .dev = {
  332. .dma_mask = &kirkwood_xor_dmamask,
  333. .coherent_dma_mask = DMA_64BIT_MASK,
  334. .platform_data = (void *)&kirkwood_xor00_data,
  335. },
  336. };
  337. static struct resource kirkwood_xor01_resources[] = {
  338. [0] = {
  339. .start = IRQ_KIRKWOOD_XOR_01,
  340. .end = IRQ_KIRKWOOD_XOR_01,
  341. .flags = IORESOURCE_IRQ,
  342. },
  343. };
  344. static struct mv_xor_platform_data kirkwood_xor01_data = {
  345. .shared = &kirkwood_xor0_shared,
  346. .hw_id = 1,
  347. .pool_size = PAGE_SIZE,
  348. };
  349. static struct platform_device kirkwood_xor01_channel = {
  350. .name = MV_XOR_NAME,
  351. .id = 1,
  352. .num_resources = ARRAY_SIZE(kirkwood_xor01_resources),
  353. .resource = kirkwood_xor01_resources,
  354. .dev = {
  355. .dma_mask = &kirkwood_xor_dmamask,
  356. .coherent_dma_mask = DMA_64BIT_MASK,
  357. .platform_data = (void *)&kirkwood_xor01_data,
  358. },
  359. };
  360. void __init kirkwood_xor0_init(void)
  361. {
  362. platform_device_register(&kirkwood_xor0_shared);
  363. /*
  364. * two engines can't do memset simultaneously, this limitation
  365. * satisfied by removing memset support from one of the engines.
  366. */
  367. dma_cap_set(DMA_MEMCPY, kirkwood_xor00_data.cap_mask);
  368. dma_cap_set(DMA_XOR, kirkwood_xor00_data.cap_mask);
  369. platform_device_register(&kirkwood_xor00_channel);
  370. dma_cap_set(DMA_MEMCPY, kirkwood_xor01_data.cap_mask);
  371. dma_cap_set(DMA_MEMSET, kirkwood_xor01_data.cap_mask);
  372. dma_cap_set(DMA_XOR, kirkwood_xor01_data.cap_mask);
  373. platform_device_register(&kirkwood_xor01_channel);
  374. }
  375. /*****************************************************************************
  376. * XOR1
  377. ****************************************************************************/
  378. static struct resource kirkwood_xor1_shared_resources[] = {
  379. {
  380. .name = "xor 1 low",
  381. .start = XOR1_PHYS_BASE,
  382. .end = XOR1_PHYS_BASE + 0xff,
  383. .flags = IORESOURCE_MEM,
  384. }, {
  385. .name = "xor 1 high",
  386. .start = XOR1_HIGH_PHYS_BASE,
  387. .end = XOR1_HIGH_PHYS_BASE + 0xff,
  388. .flags = IORESOURCE_MEM,
  389. },
  390. };
  391. static struct platform_device kirkwood_xor1_shared = {
  392. .name = MV_XOR_SHARED_NAME,
  393. .id = 1,
  394. .dev = {
  395. .platform_data = &kirkwood_xor_shared_data,
  396. },
  397. .num_resources = ARRAY_SIZE(kirkwood_xor1_shared_resources),
  398. .resource = kirkwood_xor1_shared_resources,
  399. };
  400. static struct resource kirkwood_xor10_resources[] = {
  401. [0] = {
  402. .start = IRQ_KIRKWOOD_XOR_10,
  403. .end = IRQ_KIRKWOOD_XOR_10,
  404. .flags = IORESOURCE_IRQ,
  405. },
  406. };
  407. static struct mv_xor_platform_data kirkwood_xor10_data = {
  408. .shared = &kirkwood_xor1_shared,
  409. .hw_id = 0,
  410. .pool_size = PAGE_SIZE,
  411. };
  412. static struct platform_device kirkwood_xor10_channel = {
  413. .name = MV_XOR_NAME,
  414. .id = 2,
  415. .num_resources = ARRAY_SIZE(kirkwood_xor10_resources),
  416. .resource = kirkwood_xor10_resources,
  417. .dev = {
  418. .dma_mask = &kirkwood_xor_dmamask,
  419. .coherent_dma_mask = DMA_64BIT_MASK,
  420. .platform_data = (void *)&kirkwood_xor10_data,
  421. },
  422. };
  423. static struct resource kirkwood_xor11_resources[] = {
  424. [0] = {
  425. .start = IRQ_KIRKWOOD_XOR_11,
  426. .end = IRQ_KIRKWOOD_XOR_11,
  427. .flags = IORESOURCE_IRQ,
  428. },
  429. };
  430. static struct mv_xor_platform_data kirkwood_xor11_data = {
  431. .shared = &kirkwood_xor1_shared,
  432. .hw_id = 1,
  433. .pool_size = PAGE_SIZE,
  434. };
  435. static struct platform_device kirkwood_xor11_channel = {
  436. .name = MV_XOR_NAME,
  437. .id = 3,
  438. .num_resources = ARRAY_SIZE(kirkwood_xor11_resources),
  439. .resource = kirkwood_xor11_resources,
  440. .dev = {
  441. .dma_mask = &kirkwood_xor_dmamask,
  442. .coherent_dma_mask = DMA_64BIT_MASK,
  443. .platform_data = (void *)&kirkwood_xor11_data,
  444. },
  445. };
  446. void __init kirkwood_xor1_init(void)
  447. {
  448. platform_device_register(&kirkwood_xor1_shared);
  449. /*
  450. * two engines can't do memset simultaneously, this limitation
  451. * satisfied by removing memset support from one of the engines.
  452. */
  453. dma_cap_set(DMA_MEMCPY, kirkwood_xor10_data.cap_mask);
  454. dma_cap_set(DMA_XOR, kirkwood_xor10_data.cap_mask);
  455. platform_device_register(&kirkwood_xor10_channel);
  456. dma_cap_set(DMA_MEMCPY, kirkwood_xor11_data.cap_mask);
  457. dma_cap_set(DMA_MEMSET, kirkwood_xor11_data.cap_mask);
  458. dma_cap_set(DMA_XOR, kirkwood_xor11_data.cap_mask);
  459. platform_device_register(&kirkwood_xor11_channel);
  460. }
  461. /*****************************************************************************
  462. * Time handling
  463. ****************************************************************************/
  464. static void kirkwood_timer_init(void)
  465. {
  466. orion_time_init(IRQ_KIRKWOOD_BRIDGE, KIRKWOOD_TCLK);
  467. }
  468. struct sys_timer kirkwood_timer = {
  469. .init = kirkwood_timer_init,
  470. };
  471. /*****************************************************************************
  472. * General
  473. ****************************************************************************/
  474. static char * __init kirkwood_id(void)
  475. {
  476. switch (readl(DEVICE_ID) & 0x3) {
  477. case 0:
  478. return "88F6180";
  479. case 1:
  480. return "88F6192";
  481. case 2:
  482. return "88F6281";
  483. }
  484. return "unknown 88F6000 variant";
  485. }
  486. static int __init is_l2_writethrough(void)
  487. {
  488. return !!(readl(L2_CONFIG_REG) & L2_WRITETHROUGH);
  489. }
  490. void __init kirkwood_init(void)
  491. {
  492. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  493. kirkwood_id(), KIRKWOOD_TCLK);
  494. kirkwood_setup_cpu_mbus();
  495. #ifdef CONFIG_CACHE_FEROCEON_L2
  496. feroceon_l2_init(is_l2_writethrough());
  497. #endif
  498. }