common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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/ata_platform.h>
  15. #include <linux/mtd/nand.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/of.h>
  18. #include <net/dsa.h>
  19. #include <asm/page.h>
  20. #include <asm/timex.h>
  21. #include <asm/kexec.h>
  22. #include <asm/mach/map.h>
  23. #include <asm/mach/time.h>
  24. #include <mach/kirkwood.h>
  25. #include <mach/bridge-regs.h>
  26. #include <plat/audio.h>
  27. #include <plat/cache-feroceon-l2.h>
  28. #include <plat/mvsdio.h>
  29. #include <plat/orion_nand.h>
  30. #include <plat/ehci-orion.h>
  31. #include <plat/common.h>
  32. #include <plat/time.h>
  33. #include <plat/addr-map.h>
  34. #include "common.h"
  35. /*****************************************************************************
  36. * I/O Address Mapping
  37. ****************************************************************************/
  38. static struct map_desc kirkwood_io_desc[] __initdata = {
  39. {
  40. .virtual = KIRKWOOD_PCIE_IO_VIRT_BASE,
  41. .pfn = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
  42. .length = KIRKWOOD_PCIE_IO_SIZE,
  43. .type = MT_DEVICE,
  44. }, {
  45. .virtual = KIRKWOOD_PCIE1_IO_VIRT_BASE,
  46. .pfn = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
  47. .length = KIRKWOOD_PCIE1_IO_SIZE,
  48. .type = MT_DEVICE,
  49. }, {
  50. .virtual = KIRKWOOD_REGS_VIRT_BASE,
  51. .pfn = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
  52. .length = KIRKWOOD_REGS_SIZE,
  53. .type = MT_DEVICE,
  54. },
  55. };
  56. void __init kirkwood_map_io(void)
  57. {
  58. iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
  59. }
  60. /*
  61. * Default clock control bits. Any bit _not_ set in this variable
  62. * will be cleared from the hardware after platform devices have been
  63. * registered. Some reserved bits must be set to 1.
  64. */
  65. unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED;
  66. /*****************************************************************************
  67. * EHCI0
  68. ****************************************************************************/
  69. void __init kirkwood_ehci_init(void)
  70. {
  71. kirkwood_clk_ctrl |= CGC_USB0;
  72. orion_ehci_init(USB_PHYS_BASE, IRQ_KIRKWOOD_USB, EHCI_PHY_NA);
  73. }
  74. /*****************************************************************************
  75. * GE00
  76. ****************************************************************************/
  77. void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  78. {
  79. kirkwood_clk_ctrl |= CGC_GE0;
  80. orion_ge00_init(eth_data,
  81. GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
  82. IRQ_KIRKWOOD_GE00_ERR, kirkwood_tclk);
  83. }
  84. /*****************************************************************************
  85. * GE01
  86. ****************************************************************************/
  87. void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  88. {
  89. kirkwood_clk_ctrl |= CGC_GE1;
  90. orion_ge01_init(eth_data,
  91. GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
  92. IRQ_KIRKWOOD_GE01_ERR, kirkwood_tclk);
  93. }
  94. /*****************************************************************************
  95. * Ethernet switch
  96. ****************************************************************************/
  97. void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
  98. {
  99. orion_ge00_switch_init(d, irq);
  100. }
  101. /*****************************************************************************
  102. * NAND flash
  103. ****************************************************************************/
  104. static struct resource kirkwood_nand_resource = {
  105. .flags = IORESOURCE_MEM,
  106. .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
  107. .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
  108. KIRKWOOD_NAND_MEM_SIZE - 1,
  109. };
  110. static struct orion_nand_data kirkwood_nand_data = {
  111. .cle = 0,
  112. .ale = 1,
  113. .width = 8,
  114. };
  115. static struct platform_device kirkwood_nand_flash = {
  116. .name = "orion_nand",
  117. .id = -1,
  118. .dev = {
  119. .platform_data = &kirkwood_nand_data,
  120. },
  121. .resource = &kirkwood_nand_resource,
  122. .num_resources = 1,
  123. };
  124. void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
  125. int chip_delay)
  126. {
  127. kirkwood_clk_ctrl |= CGC_RUNIT;
  128. kirkwood_nand_data.parts = parts;
  129. kirkwood_nand_data.nr_parts = nr_parts;
  130. kirkwood_nand_data.chip_delay = chip_delay;
  131. platform_device_register(&kirkwood_nand_flash);
  132. }
  133. void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
  134. int (*dev_ready)(struct mtd_info *))
  135. {
  136. kirkwood_clk_ctrl |= CGC_RUNIT;
  137. kirkwood_nand_data.parts = parts;
  138. kirkwood_nand_data.nr_parts = nr_parts;
  139. kirkwood_nand_data.dev_ready = dev_ready;
  140. platform_device_register(&kirkwood_nand_flash);
  141. }
  142. /*****************************************************************************
  143. * SoC RTC
  144. ****************************************************************************/
  145. static void __init kirkwood_rtc_init(void)
  146. {
  147. orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
  148. }
  149. /*****************************************************************************
  150. * SATA
  151. ****************************************************************************/
  152. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  153. {
  154. kirkwood_clk_ctrl |= CGC_SATA0;
  155. if (sata_data->n_ports > 1)
  156. kirkwood_clk_ctrl |= CGC_SATA1;
  157. orion_sata_init(sata_data, SATA_PHYS_BASE, IRQ_KIRKWOOD_SATA);
  158. }
  159. /*****************************************************************************
  160. * SD/SDIO/MMC
  161. ****************************************************************************/
  162. static struct resource mvsdio_resources[] = {
  163. [0] = {
  164. .start = SDIO_PHYS_BASE,
  165. .end = SDIO_PHYS_BASE + SZ_1K - 1,
  166. .flags = IORESOURCE_MEM,
  167. },
  168. [1] = {
  169. .start = IRQ_KIRKWOOD_SDIO,
  170. .end = IRQ_KIRKWOOD_SDIO,
  171. .flags = IORESOURCE_IRQ,
  172. },
  173. };
  174. static u64 mvsdio_dmamask = DMA_BIT_MASK(32);
  175. static struct platform_device kirkwood_sdio = {
  176. .name = "mvsdio",
  177. .id = -1,
  178. .dev = {
  179. .dma_mask = &mvsdio_dmamask,
  180. .coherent_dma_mask = DMA_BIT_MASK(32),
  181. },
  182. .num_resources = ARRAY_SIZE(mvsdio_resources),
  183. .resource = mvsdio_resources,
  184. };
  185. void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
  186. {
  187. u32 dev, rev;
  188. kirkwood_pcie_id(&dev, &rev);
  189. if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
  190. mvsdio_data->clock = 100000000;
  191. else
  192. mvsdio_data->clock = 200000000;
  193. kirkwood_clk_ctrl |= CGC_SDIO;
  194. kirkwood_sdio.dev.platform_data = mvsdio_data;
  195. platform_device_register(&kirkwood_sdio);
  196. }
  197. /*****************************************************************************
  198. * SPI
  199. ****************************************************************************/
  200. void __init kirkwood_spi_init()
  201. {
  202. kirkwood_clk_ctrl |= CGC_RUNIT;
  203. orion_spi_init(SPI_PHYS_BASE, kirkwood_tclk);
  204. }
  205. /*****************************************************************************
  206. * I2C
  207. ****************************************************************************/
  208. void __init kirkwood_i2c_init(void)
  209. {
  210. orion_i2c_init(I2C_PHYS_BASE, IRQ_KIRKWOOD_TWSI, 8);
  211. }
  212. /*****************************************************************************
  213. * UART0
  214. ****************************************************************************/
  215. void __init kirkwood_uart0_init(void)
  216. {
  217. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  218. IRQ_KIRKWOOD_UART_0, kirkwood_tclk);
  219. }
  220. /*****************************************************************************
  221. * UART1
  222. ****************************************************************************/
  223. void __init kirkwood_uart1_init(void)
  224. {
  225. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  226. IRQ_KIRKWOOD_UART_1, kirkwood_tclk);
  227. }
  228. /*****************************************************************************
  229. * Cryptographic Engines and Security Accelerator (CESA)
  230. ****************************************************************************/
  231. void __init kirkwood_crypto_init(void)
  232. {
  233. kirkwood_clk_ctrl |= CGC_CRYPTO;
  234. orion_crypto_init(CRYPTO_PHYS_BASE, KIRKWOOD_SRAM_PHYS_BASE,
  235. KIRKWOOD_SRAM_SIZE, IRQ_KIRKWOOD_CRYPTO);
  236. }
  237. /*****************************************************************************
  238. * XOR0
  239. ****************************************************************************/
  240. void __init kirkwood_xor0_init(void)
  241. {
  242. kirkwood_clk_ctrl |= CGC_XOR0;
  243. orion_xor0_init(XOR0_PHYS_BASE, XOR0_HIGH_PHYS_BASE,
  244. IRQ_KIRKWOOD_XOR_00, IRQ_KIRKWOOD_XOR_01);
  245. }
  246. /*****************************************************************************
  247. * XOR1
  248. ****************************************************************************/
  249. void __init kirkwood_xor1_init(void)
  250. {
  251. kirkwood_clk_ctrl |= CGC_XOR1;
  252. orion_xor1_init(XOR1_PHYS_BASE, XOR1_HIGH_PHYS_BASE,
  253. IRQ_KIRKWOOD_XOR_10, IRQ_KIRKWOOD_XOR_11);
  254. }
  255. /*****************************************************************************
  256. * Watchdog
  257. ****************************************************************************/
  258. void __init kirkwood_wdt_init(void)
  259. {
  260. orion_wdt_init(kirkwood_tclk);
  261. }
  262. /*****************************************************************************
  263. * Time handling
  264. ****************************************************************************/
  265. void __init kirkwood_init_early(void)
  266. {
  267. orion_time_set_base(TIMER_VIRT_BASE);
  268. }
  269. int kirkwood_tclk;
  270. static int __init kirkwood_find_tclk(void)
  271. {
  272. u32 dev, rev;
  273. kirkwood_pcie_id(&dev, &rev);
  274. if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
  275. if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
  276. return 200000000;
  277. return 166666667;
  278. }
  279. static void __init kirkwood_timer_init(void)
  280. {
  281. kirkwood_tclk = kirkwood_find_tclk();
  282. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  283. IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  284. }
  285. struct sys_timer kirkwood_timer = {
  286. .init = kirkwood_timer_init,
  287. };
  288. /*****************************************************************************
  289. * Audio
  290. ****************************************************************************/
  291. static struct resource kirkwood_i2s_resources[] = {
  292. [0] = {
  293. .start = AUDIO_PHYS_BASE,
  294. .end = AUDIO_PHYS_BASE + SZ_16K - 1,
  295. .flags = IORESOURCE_MEM,
  296. },
  297. [1] = {
  298. .start = IRQ_KIRKWOOD_I2S,
  299. .end = IRQ_KIRKWOOD_I2S,
  300. .flags = IORESOURCE_IRQ,
  301. },
  302. };
  303. static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
  304. .burst = 128,
  305. };
  306. static struct platform_device kirkwood_i2s_device = {
  307. .name = "kirkwood-i2s",
  308. .id = -1,
  309. .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
  310. .resource = kirkwood_i2s_resources,
  311. .dev = {
  312. .platform_data = &kirkwood_i2s_data,
  313. },
  314. };
  315. static struct platform_device kirkwood_pcm_device = {
  316. .name = "kirkwood-pcm-audio",
  317. .id = -1,
  318. };
  319. void __init kirkwood_audio_init(void)
  320. {
  321. kirkwood_clk_ctrl |= CGC_AUDIO;
  322. platform_device_register(&kirkwood_i2s_device);
  323. platform_device_register(&kirkwood_pcm_device);
  324. }
  325. /*****************************************************************************
  326. * General
  327. ****************************************************************************/
  328. /*
  329. * Identify device ID and revision.
  330. */
  331. char * __init kirkwood_id(void)
  332. {
  333. u32 dev, rev;
  334. kirkwood_pcie_id(&dev, &rev);
  335. if (dev == MV88F6281_DEV_ID) {
  336. if (rev == MV88F6281_REV_Z0)
  337. return "MV88F6281-Z0";
  338. else if (rev == MV88F6281_REV_A0)
  339. return "MV88F6281-A0";
  340. else if (rev == MV88F6281_REV_A1)
  341. return "MV88F6281-A1";
  342. else
  343. return "MV88F6281-Rev-Unsupported";
  344. } else if (dev == MV88F6192_DEV_ID) {
  345. if (rev == MV88F6192_REV_Z0)
  346. return "MV88F6192-Z0";
  347. else if (rev == MV88F6192_REV_A0)
  348. return "MV88F6192-A0";
  349. else if (rev == MV88F6192_REV_A1)
  350. return "MV88F6192-A1";
  351. else
  352. return "MV88F6192-Rev-Unsupported";
  353. } else if (dev == MV88F6180_DEV_ID) {
  354. if (rev == MV88F6180_REV_A0)
  355. return "MV88F6180-Rev-A0";
  356. else if (rev == MV88F6180_REV_A1)
  357. return "MV88F6180-Rev-A1";
  358. else
  359. return "MV88F6180-Rev-Unsupported";
  360. } else if (dev == MV88F6282_DEV_ID) {
  361. if (rev == MV88F6282_REV_A0)
  362. return "MV88F6282-Rev-A0";
  363. else if (rev == MV88F6282_REV_A1)
  364. return "MV88F6282-Rev-A1";
  365. else
  366. return "MV88F6282-Rev-Unsupported";
  367. } else {
  368. return "Device-Unknown";
  369. }
  370. }
  371. void __init kirkwood_l2_init(void)
  372. {
  373. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  374. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  375. feroceon_l2_init(1);
  376. #else
  377. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  378. feroceon_l2_init(0);
  379. #endif
  380. }
  381. void __init kirkwood_init(void)
  382. {
  383. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  384. kirkwood_id(), kirkwood_tclk);
  385. /*
  386. * Disable propagation of mbus errors to the CPU local bus,
  387. * as this causes mbus errors (which can occur for example
  388. * for PCI aborts) to throw CPU aborts, which we're not set
  389. * up to deal with.
  390. */
  391. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  392. kirkwood_setup_cpu_mbus();
  393. #ifdef CONFIG_CACHE_FEROCEON_L2
  394. kirkwood_l2_init();
  395. #endif
  396. /* internal devices that every board has */
  397. kirkwood_rtc_init();
  398. kirkwood_wdt_init();
  399. kirkwood_xor0_init();
  400. kirkwood_xor1_init();
  401. kirkwood_crypto_init();
  402. #ifdef CONFIG_KEXEC
  403. kexec_reinit = kirkwood_enable_pcie;
  404. #endif
  405. }
  406. static int __init kirkwood_clock_gate(void)
  407. {
  408. unsigned int curr = readl(CLOCK_GATING_CTRL);
  409. u32 dev, rev;
  410. #ifdef CONFIG_OF
  411. struct device_node *np;
  412. #endif
  413. kirkwood_pcie_id(&dev, &rev);
  414. printk(KERN_DEBUG "Gating clock of unused units\n");
  415. printk(KERN_DEBUG "before: 0x%08x\n", curr);
  416. /* Make sure those units are accessible */
  417. writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
  418. #ifdef CONFIG_OF
  419. np = of_find_compatible_node(NULL, NULL, "mrvl,orion-nand");
  420. if (np && of_device_is_available(np)) {
  421. kirkwood_clk_ctrl |= CGC_RUNIT;
  422. of_node_put(np);
  423. }
  424. #endif
  425. /* For SATA: first shutdown the phy */
  426. if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
  427. /* Disable PLL and IVREF */
  428. writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
  429. /* Disable PHY */
  430. writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
  431. }
  432. if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
  433. /* Disable PLL and IVREF */
  434. writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
  435. /* Disable PHY */
  436. writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
  437. }
  438. /* For PCIe: first shutdown the phy */
  439. if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
  440. writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
  441. while (1)
  442. if (readl(PCIE_STATUS) & 0x1)
  443. break;
  444. writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
  445. }
  446. /* For PCIe 1: first shutdown the phy */
  447. if (dev == MV88F6282_DEV_ID) {
  448. if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
  449. writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
  450. while (1)
  451. if (readl(PCIE1_STATUS) & 0x1)
  452. break;
  453. writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
  454. }
  455. } else /* keep this bit set for devices that don't have PCIe1 */
  456. kirkwood_clk_ctrl |= CGC_PEX1;
  457. /* Now gate clock the required units */
  458. writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
  459. printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
  460. return 0;
  461. }
  462. late_initcall(kirkwood_clock_gate);
  463. void kirkwood_restart(char mode, const char *cmd)
  464. {
  465. /*
  466. * Enable soft reset to assert RSTOUTn.
  467. */
  468. writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
  469. /*
  470. * Assert soft reset.
  471. */
  472. writel(SOFT_RESET, SYSTEM_SOFT_RESET);
  473. while (1)
  474. ;
  475. }