common.c 16 KB

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