common.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. static struct resource kirkwood_crypto_res[] = {
  233. {
  234. .name = "regs",
  235. .start = CRYPTO_PHYS_BASE,
  236. .end = CRYPTO_PHYS_BASE + 0xffff,
  237. .flags = IORESOURCE_MEM,
  238. }, {
  239. .name = "sram",
  240. .start = KIRKWOOD_SRAM_PHYS_BASE,
  241. .end = KIRKWOOD_SRAM_PHYS_BASE + KIRKWOOD_SRAM_SIZE - 1,
  242. .flags = IORESOURCE_MEM,
  243. }, {
  244. .name = "crypto interrupt",
  245. .start = IRQ_KIRKWOOD_CRYPTO,
  246. .end = IRQ_KIRKWOOD_CRYPTO,
  247. .flags = IORESOURCE_IRQ,
  248. },
  249. };
  250. static struct platform_device kirkwood_crypto_device = {
  251. .name = "mv_crypto",
  252. .id = -1,
  253. .num_resources = ARRAY_SIZE(kirkwood_crypto_res),
  254. .resource = kirkwood_crypto_res,
  255. };
  256. void __init kirkwood_crypto_init(void)
  257. {
  258. kirkwood_clk_ctrl |= CGC_CRYPTO;
  259. platform_device_register(&kirkwood_crypto_device);
  260. }
  261. /*****************************************************************************
  262. * XOR0
  263. ****************************************************************************/
  264. static void __init kirkwood_xor0_init(void)
  265. {
  266. kirkwood_clk_ctrl |= CGC_XOR0;
  267. orion_xor0_init(&kirkwood_mbus_dram_info,
  268. XOR0_PHYS_BASE, XOR0_HIGH_PHYS_BASE,
  269. IRQ_KIRKWOOD_XOR_00, IRQ_KIRKWOOD_XOR_01);
  270. }
  271. /*****************************************************************************
  272. * XOR1
  273. ****************************************************************************/
  274. static void __init kirkwood_xor1_init(void)
  275. {
  276. kirkwood_clk_ctrl |= CGC_XOR1;
  277. orion_xor1_init(XOR1_PHYS_BASE, XOR1_HIGH_PHYS_BASE,
  278. IRQ_KIRKWOOD_XOR_10, IRQ_KIRKWOOD_XOR_11);
  279. }
  280. /*****************************************************************************
  281. * Watchdog
  282. ****************************************************************************/
  283. static void __init kirkwood_wdt_init(void)
  284. {
  285. orion_wdt_init(kirkwood_tclk);
  286. }
  287. /*****************************************************************************
  288. * Time handling
  289. ****************************************************************************/
  290. void __init kirkwood_init_early(void)
  291. {
  292. orion_time_set_base(TIMER_VIRT_BASE);
  293. }
  294. int kirkwood_tclk;
  295. static int __init kirkwood_find_tclk(void)
  296. {
  297. u32 dev, rev;
  298. kirkwood_pcie_id(&dev, &rev);
  299. if (dev == MV88F6281_DEV_ID || dev == MV88F6282_DEV_ID)
  300. if (((readl(SAMPLE_AT_RESET) >> 21) & 1) == 0)
  301. return 200000000;
  302. return 166666667;
  303. }
  304. static void __init kirkwood_timer_init(void)
  305. {
  306. kirkwood_tclk = kirkwood_find_tclk();
  307. orion_time_init(BRIDGE_VIRT_BASE, BRIDGE_INT_TIMER1_CLR,
  308. IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
  309. }
  310. struct sys_timer kirkwood_timer = {
  311. .init = kirkwood_timer_init,
  312. };
  313. /*****************************************************************************
  314. * Audio
  315. ****************************************************************************/
  316. static struct resource kirkwood_i2s_resources[] = {
  317. [0] = {
  318. .start = AUDIO_PHYS_BASE,
  319. .end = AUDIO_PHYS_BASE + SZ_16K - 1,
  320. .flags = IORESOURCE_MEM,
  321. },
  322. [1] = {
  323. .start = IRQ_KIRKWOOD_I2S,
  324. .end = IRQ_KIRKWOOD_I2S,
  325. .flags = IORESOURCE_IRQ,
  326. },
  327. };
  328. static struct kirkwood_asoc_platform_data kirkwood_i2s_data = {
  329. .dram = &kirkwood_mbus_dram_info,
  330. .burst = 128,
  331. };
  332. static struct platform_device kirkwood_i2s_device = {
  333. .name = "kirkwood-i2s",
  334. .id = -1,
  335. .num_resources = ARRAY_SIZE(kirkwood_i2s_resources),
  336. .resource = kirkwood_i2s_resources,
  337. .dev = {
  338. .platform_data = &kirkwood_i2s_data,
  339. },
  340. };
  341. static struct platform_device kirkwood_pcm_device = {
  342. .name = "kirkwood-pcm-audio",
  343. .id = -1,
  344. };
  345. void __init kirkwood_audio_init(void)
  346. {
  347. kirkwood_clk_ctrl |= CGC_AUDIO;
  348. platform_device_register(&kirkwood_i2s_device);
  349. platform_device_register(&kirkwood_pcm_device);
  350. }
  351. /*****************************************************************************
  352. * General
  353. ****************************************************************************/
  354. /*
  355. * Identify device ID and revision.
  356. */
  357. static char * __init kirkwood_id(void)
  358. {
  359. u32 dev, rev;
  360. kirkwood_pcie_id(&dev, &rev);
  361. if (dev == MV88F6281_DEV_ID) {
  362. if (rev == MV88F6281_REV_Z0)
  363. return "MV88F6281-Z0";
  364. else if (rev == MV88F6281_REV_A0)
  365. return "MV88F6281-A0";
  366. else if (rev == MV88F6281_REV_A1)
  367. return "MV88F6281-A1";
  368. else
  369. return "MV88F6281-Rev-Unsupported";
  370. } else if (dev == MV88F6192_DEV_ID) {
  371. if (rev == MV88F6192_REV_Z0)
  372. return "MV88F6192-Z0";
  373. else if (rev == MV88F6192_REV_A0)
  374. return "MV88F6192-A0";
  375. else if (rev == MV88F6192_REV_A1)
  376. return "MV88F6192-A1";
  377. else
  378. return "MV88F6192-Rev-Unsupported";
  379. } else if (dev == MV88F6180_DEV_ID) {
  380. if (rev == MV88F6180_REV_A0)
  381. return "MV88F6180-Rev-A0";
  382. else if (rev == MV88F6180_REV_A1)
  383. return "MV88F6180-Rev-A1";
  384. else
  385. return "MV88F6180-Rev-Unsupported";
  386. } else if (dev == MV88F6282_DEV_ID) {
  387. if (rev == MV88F6282_REV_A0)
  388. return "MV88F6282-Rev-A0";
  389. else
  390. return "MV88F6282-Rev-Unsupported";
  391. } else {
  392. return "Device-Unknown";
  393. }
  394. }
  395. static void __init kirkwood_l2_init(void)
  396. {
  397. #ifdef CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH
  398. writel(readl(L2_CONFIG_REG) | L2_WRITETHROUGH, L2_CONFIG_REG);
  399. feroceon_l2_init(1);
  400. #else
  401. writel(readl(L2_CONFIG_REG) & ~L2_WRITETHROUGH, L2_CONFIG_REG);
  402. feroceon_l2_init(0);
  403. #endif
  404. }
  405. void __init kirkwood_init(void)
  406. {
  407. printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
  408. kirkwood_id(), kirkwood_tclk);
  409. kirkwood_i2s_data.tclk = kirkwood_tclk;
  410. /*
  411. * Disable propagation of mbus errors to the CPU local bus,
  412. * as this causes mbus errors (which can occur for example
  413. * for PCI aborts) to throw CPU aborts, which we're not set
  414. * up to deal with.
  415. */
  416. writel(readl(CPU_CONFIG) & ~CPU_CONFIG_ERROR_PROP, CPU_CONFIG);
  417. kirkwood_setup_cpu_mbus();
  418. #ifdef CONFIG_CACHE_FEROCEON_L2
  419. kirkwood_l2_init();
  420. #endif
  421. /* internal devices that every board has */
  422. kirkwood_rtc_init();
  423. kirkwood_wdt_init();
  424. kirkwood_xor0_init();
  425. kirkwood_xor1_init();
  426. kirkwood_crypto_init();
  427. #ifdef CONFIG_KEXEC
  428. kexec_reinit = kirkwood_enable_pcie;
  429. #endif
  430. }
  431. static int __init kirkwood_clock_gate(void)
  432. {
  433. unsigned int curr = readl(CLOCK_GATING_CTRL);
  434. u32 dev, rev;
  435. kirkwood_pcie_id(&dev, &rev);
  436. printk(KERN_DEBUG "Gating clock of unused units\n");
  437. printk(KERN_DEBUG "before: 0x%08x\n", curr);
  438. /* Make sure those units are accessible */
  439. writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
  440. /* For SATA: first shutdown the phy */
  441. if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
  442. /* Disable PLL and IVREF */
  443. writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2);
  444. /* Disable PHY */
  445. writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL);
  446. }
  447. if (!(kirkwood_clk_ctrl & CGC_SATA1)) {
  448. /* Disable PLL and IVREF */
  449. writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2);
  450. /* Disable PHY */
  451. writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL);
  452. }
  453. /* For PCIe: first shutdown the phy */
  454. if (!(kirkwood_clk_ctrl & CGC_PEX0)) {
  455. writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL);
  456. while (1)
  457. if (readl(PCIE_STATUS) & 0x1)
  458. break;
  459. writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
  460. }
  461. /* For PCIe 1: first shutdown the phy */
  462. if (dev == MV88F6282_DEV_ID) {
  463. if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
  464. writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
  465. while (1)
  466. if (readl(PCIE1_STATUS) & 0x1)
  467. break;
  468. writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
  469. }
  470. } else /* keep this bit set for devices that don't have PCIe1 */
  471. kirkwood_clk_ctrl |= CGC_PEX1;
  472. /* Now gate clock the required units */
  473. writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
  474. printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
  475. return 0;
  476. }
  477. late_initcall(kirkwood_clock_gate);