common.c 16 KB

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