common.c 15 KB

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