common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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/mbus.h>
  15. #include <linux/ata_platform.h>
  16. #include <linux/mtd/nand.h>
  17. #include <linux/dma-mapping.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/common.h>
  31. #include <plat/time.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(&kirkwood_mbus_dram_info,
  71. USB_PHYS_BASE, IRQ_KIRKWOOD_USB);
  72. }
  73. /*****************************************************************************
  74. * GE00
  75. ****************************************************************************/
  76. void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
  77. {
  78. kirkwood_clk_ctrl |= CGC_GE0;
  79. orion_ge00_init(eth_data, &kirkwood_mbus_dram_info,
  80. GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM,
  81. IRQ_KIRKWOOD_GE00_ERR, kirkwood_tclk);
  82. }
  83. /*****************************************************************************
  84. * GE01
  85. ****************************************************************************/
  86. void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data)
  87. {
  88. kirkwood_clk_ctrl |= CGC_GE1;
  89. orion_ge01_init(eth_data, &kirkwood_mbus_dram_info,
  90. GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM,
  91. IRQ_KIRKWOOD_GE01_ERR, kirkwood_tclk);
  92. }
  93. /*****************************************************************************
  94. * Ethernet switch
  95. ****************************************************************************/
  96. void __init kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq)
  97. {
  98. orion_ge00_switch_init(d, irq);
  99. }
  100. /*****************************************************************************
  101. * NAND flash
  102. ****************************************************************************/
  103. static struct resource kirkwood_nand_resource = {
  104. .flags = IORESOURCE_MEM,
  105. .start = KIRKWOOD_NAND_MEM_PHYS_BASE,
  106. .end = KIRKWOOD_NAND_MEM_PHYS_BASE +
  107. KIRKWOOD_NAND_MEM_SIZE - 1,
  108. };
  109. static struct orion_nand_data kirkwood_nand_data = {
  110. .cle = 0,
  111. .ale = 1,
  112. .width = 8,
  113. };
  114. static struct platform_device kirkwood_nand_flash = {
  115. .name = "orion_nand",
  116. .id = -1,
  117. .dev = {
  118. .platform_data = &kirkwood_nand_data,
  119. },
  120. .resource = &kirkwood_nand_resource,
  121. .num_resources = 1,
  122. };
  123. void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
  124. int chip_delay)
  125. {
  126. kirkwood_clk_ctrl |= CGC_RUNIT;
  127. kirkwood_nand_data.parts = parts;
  128. kirkwood_nand_data.nr_parts = nr_parts;
  129. kirkwood_nand_data.chip_delay = chip_delay;
  130. platform_device_register(&kirkwood_nand_flash);
  131. }
  132. void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
  133. int (*dev_ready)(struct mtd_info *))
  134. {
  135. kirkwood_clk_ctrl |= CGC_RUNIT;
  136. kirkwood_nand_data.parts = parts;
  137. kirkwood_nand_data.nr_parts = nr_parts;
  138. kirkwood_nand_data.dev_ready = dev_ready;
  139. platform_device_register(&kirkwood_nand_flash);
  140. }
  141. /*****************************************************************************
  142. * SoC RTC
  143. ****************************************************************************/
  144. static void __init kirkwood_rtc_init(void)
  145. {
  146. orion_rtc_init(RTC_PHYS_BASE, IRQ_KIRKWOOD_RTC);
  147. }
  148. /*****************************************************************************
  149. * SATA
  150. ****************************************************************************/
  151. void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
  152. {
  153. kirkwood_clk_ctrl |= CGC_SATA0;
  154. if (sata_data->n_ports > 1)
  155. kirkwood_clk_ctrl |= CGC_SATA1;
  156. orion_sata_init(sata_data, &kirkwood_mbus_dram_info,
  157. 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. mvsdio_data->dram = &kirkwood_mbus_dram_info;
  194. kirkwood_clk_ctrl |= CGC_SDIO;
  195. kirkwood_sdio.dev.platform_data = mvsdio_data;
  196. platform_device_register(&kirkwood_sdio);
  197. }
  198. /*****************************************************************************
  199. * SPI
  200. ****************************************************************************/
  201. void __init kirkwood_spi_init()
  202. {
  203. kirkwood_clk_ctrl |= CGC_RUNIT;
  204. orion_spi_init(SPI_PHYS_BASE, kirkwood_tclk);
  205. }
  206. /*****************************************************************************
  207. * I2C
  208. ****************************************************************************/
  209. void __init kirkwood_i2c_init(void)
  210. {
  211. orion_i2c_init(I2C_PHYS_BASE, IRQ_KIRKWOOD_TWSI, 8);
  212. }
  213. /*****************************************************************************
  214. * UART0
  215. ****************************************************************************/
  216. void __init kirkwood_uart0_init(void)
  217. {
  218. orion_uart0_init(UART0_VIRT_BASE, UART0_PHYS_BASE,
  219. IRQ_KIRKWOOD_UART_0, kirkwood_tclk);
  220. }
  221. /*****************************************************************************
  222. * UART1
  223. ****************************************************************************/
  224. void __init kirkwood_uart1_init(void)
  225. {
  226. orion_uart1_init(UART1_VIRT_BASE, UART1_PHYS_BASE,
  227. IRQ_KIRKWOOD_UART_1, kirkwood_tclk);
  228. }
  229. /*****************************************************************************
  230. * Cryptographic Engines and Security Accelerator (CESA)
  231. ****************************************************************************/
  232. void __init kirkwood_crypto_init(void)
  233. {
  234. kirkwood_clk_ctrl |= CGC_CRYPTO;
  235. orion_crypto_init(CRYPTO_PHYS_BASE, KIRKWOOD_SRAM_PHYS_BASE,
  236. KIRKWOOD_SRAM_SIZE, IRQ_KIRKWOOD_CRYPTO);
  237. }
  238. /*****************************************************************************
  239. * XOR0
  240. ****************************************************************************/
  241. static void __init kirkwood_xor0_init(void)
  242. {
  243. kirkwood_clk_ctrl |= CGC_XOR0;
  244. orion_xor0_init(&kirkwood_mbus_dram_info,
  245. XOR0_PHYS_BASE, XOR0_HIGH_PHYS_BASE,
  246. IRQ_KIRKWOOD_XOR_00, IRQ_KIRKWOOD_XOR_01);
  247. }
  248. /*****************************************************************************
  249. * XOR1
  250. ****************************************************************************/
  251. static void __init kirkwood_xor1_init(void)
  252. {
  253. kirkwood_clk_ctrl |= CGC_XOR1;
  254. orion_xor1_init(XOR1_PHYS_BASE, XOR1_HIGH_PHYS_BASE,
  255. IRQ_KIRKWOOD_XOR_10, IRQ_KIRKWOOD_XOR_11);
  256. }
  257. /*****************************************************************************
  258. * Watchdog
  259. ****************************************************************************/
  260. static void __init kirkwood_wdt_init(void)
  261. {
  262. orion_wdt_init(kirkwood_tclk);
  263. }
  264. /*****************************************************************************
  265. * Time handling
  266. ****************************************************************************/
  267. void __init kirkwood_init_early(void)
  268. {
  269. orion_time_set_base(TIMER_VIRT_BASE);
  270. }
  271. int kirkwood_tclk;
  272. static int __init kirkwood_find_tclk(void)
  273. {
  274. u32 dev, rev;
  275. kirkwood_pcie_id(&dev, &rev);
  276. if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
  277. if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
  278. return 200000000;
  279. return 166666667;
  280. }
  281. static void __init kirkwood_timer_init(void)
  282. {
  283. kirkwood_tclk = kirkwood_find_tclk();
  284. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  285. IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  286. }
  287. struct sys_timer kirkwood_timer = {
  288. .init = kirkwood_timer_init,
  289. };
  290. /*****************************************************************************
  291. * Audio
  292. ****************************************************************************/
  293. static struct resource kirkwood_i2s_resources[] = {
  294. [0] = {
  295. .start = AUDIO_PHYS_BASE,
  296. .end = AUDIO_PHYS_BASE + SZ_16K - 1,
  297. .flags = IORESOURCE_MEM,
  298. },
  299. [1] = {
  300. .start = IRQ_KIRKWOOD_I2S,
  301. .end = IRQ_KIRKWOOD_I2S,
  302. .flags = IORESOURCE_IRQ,
  303. },
  304. };
  305. static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
  306. .dram = &kirkwood_mbus_dram_info,
  307. .burst = 128,
  308. };
  309. static struct platform_device kirkwood_i2s_device = {
  310. .name = "kirkwood-i2s",
  311. .id = -1,
  312. .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
  313. .resource = kirkwood_i2s_resources,
  314. .dev = {
  315. .platform_data = &kirkwood_i2s_data,
  316. },
  317. };
  318. static struct platform_device kirkwood_pcm_device = {
  319. .name = "kirkwood-pcm-audio",
  320. .id = -1,
  321. };
  322. void __init kirkwood_audio_init(void)
  323. {
  324. kirkwood_clk_ctrl |= CGC_AUDIO;
  325. platform_device_register(&kirkwood_i2s_device);
  326. platform_device_register(&kirkwood_pcm_device);
  327. }
  328. /*****************************************************************************
  329. * General
  330. ****************************************************************************/
  331. /*
  332. * Identify device ID and revision.
  333. */
  334. static char * __init kirkwood_id(void)
  335. {
  336. u32 dev, rev;
  337. kirkwood_pcie_id(&dev, &rev);
  338. if (dev == MV88F6281_DEV_ID) {
  339. if (rev == MV88F6281_REV_Z0)
  340. return "MV88F6281-Z0";
  341. else if (rev == MV88F6281_REV_A0)
  342. return "MV88F6281-A0";
  343. else if (rev == MV88F6281_REV_A1)
  344. return "MV88F6281-A1";
  345. else
  346. return "MV88F6281-Rev-Unsupported";
  347. } else if (dev == MV88F6192_DEV_ID) {
  348. if (rev == MV88F6192_REV_Z0)
  349. return "MV88F6192-Z0";
  350. else if (rev == MV88F6192_REV_A0)
  351. return "MV88F6192-A0";
  352. else if (rev == MV88F6192_REV_A1)
  353. return "MV88F6192-A1";
  354. else
  355. return "MV88F6192-Rev-Unsupported";
  356. } else if (dev == MV88F6180_DEV_ID) {
  357. if (rev == MV88F6180_REV_A0)
  358. return "MV88F6180-Rev-A0";
  359. else if (rev == MV88F6180_REV_A1)
  360. return "MV88F6180-Rev-A1";
  361. else
  362. return "MV88F6180-Rev-Unsupported";
  363. } else if (dev == MV88F6282_DEV_ID) {
  364. if (rev == MV88F6282_REV_A0)
  365. return "MV88F6282-Rev-A0";
  366. else
  367. return "MV88F6282-Rev-Unsupported";
  368. } else {
  369. return "Device-Unknown";
  370. }
  371. }
  372. static void __init kirkwood_l2_init(void)
  373. {
  374. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  375. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  376. feroceon_l2_init(1);
  377. #else
  378. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  379. feroceon_l2_init(0);
  380. #endif
  381. }
  382. void __init kirkwood_init(void)
  383. {
  384. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  385. kirkwood_id(), kirkwood_tclk);
  386. kirkwood_i2s_data.tclk = kirkwood_tclk;
  387. /*
  388. * Disable propagation of mbus errors to the CPU local bus,
  389. * as this causes mbus errors (which can occur for example
  390. * for PCI aborts) to throw CPU aborts, which we're not set
  391. * up to deal with.
  392. */
  393. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  394. kirkwood_setup_cpu_mbus();
  395. #ifdef CONFIG_CACHE_FEROCEON_L2
  396. kirkwood_l2_init();
  397. #endif
  398. /* internal devices that every board has */
  399. kirkwood_rtc_init();
  400. kirkwood_wdt_init();
  401. kirkwood_xor0_init();
  402. kirkwood_xor1_init();
  403. kirkwood_crypto_init();
  404. #ifdef CONFIG_KEXEC
  405. kexec_reinit = kirkwood_enable_pcie;
  406. #endif
  407. }
  408. static int __init kirkwood_clock_gate(void)
  409. {
  410. unsigned int curr = readl(CLOCK_GATING_CTRL);
  411. u32 dev, rev;
  412. kirkwood_pcie_id(&dev, &rev);
  413. printk(KERN_DEBUG "Gating clock of unused units\n");
  414. printk(KERN_DEBUG "before: 0x%08x\n", curr);
  415. /* Make sure those units are accessible */
  416. writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
  417. /* For SATA: first shutdown the phy */
  418. if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
  419. /* Disable PLL and IVREF */
  420. writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
  421. /* Disable PHY */
  422. writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
  423. }
  424. if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
  425. /* Disable PLL and IVREF */
  426. writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
  427. /* Disable PHY */
  428. writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
  429. }
  430. /* For PCIe: first shutdown the phy */
  431. if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
  432. writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
  433. while (1)
  434. if (readl(PCIE_STATUS) & 0x1)
  435. break;
  436. writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
  437. }
  438. /* For PCIe 1: first shutdown the phy */
  439. if (dev == MV88F6282_DEV_ID) {
  440. if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
  441. writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
  442. while (1)
  443. if (readl(PCIE1_STATUS) & 0x1)
  444. break;
  445. writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
  446. }
  447. } else /* keep this bit set for devices that don't have PCIe1 */
  448. kirkwood_clk_ctrl |= CGC_PEX1;
  449. /* Now gate clock the required units */
  450. writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
  451. printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
  452. return 0;
  453. }
  454. late_initcall(kirkwood_clock_gate);
  455. void kirkwood_restart(char mode, const char *cmd)
  456. {
  457. /*
  458. * Enable soft reset to assert RSTOUTn.
  459. */
  460. writel(SOFT_RESET_OUT_EN, RSTOUTn_MASK);
  461. /*
  462. * Assert soft reset.
  463. */
  464. writel(SOFT_RESET, SYSTEM_SOFT_RESET);
  465. while (1)
  466. ;
  467. }