common.c 15 KB

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