spear1340.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * arch/arm/mach-spear13xx/spear1340.c
  3. *
  4. * SPEAr1340 machine source file
  5. *
  6. * Copyright (C) 2012 ST Microelectronics
  7. * Viresh Kumar <viresh.linux@gmail.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public
  10. * License version 2. This program is licensed "as is" without any
  11. * warranty of any kind, whether express or implied.
  12. */
  13. #define pr_fmt(fmt) "SPEAr1340: " fmt
  14. #include <linux/ahci_platform.h>
  15. #include <linux/amba/serial.h>
  16. #include <linux/delay.h>
  17. #include <linux/dw_dmac.h>
  18. #include <linux/of_platform.h>
  19. #include <asm/hardware/gic.h>
  20. #include <asm/mach/arch.h>
  21. #include <mach/dma.h>
  22. #include <mach/generic.h>
  23. #include <mach/spear.h>
  24. /* Base addresses */
  25. #define SPEAR1340_SATA_BASE UL(0xB1000000)
  26. #define SPEAR1340_UART1_BASE UL(0xB4100000)
  27. /* Power Management Registers */
  28. #define SPEAR1340_PCM_CFG (VA_MISC_BASE + 0x100)
  29. #define SPEAR1340_PCM_WKUP_CFG (VA_MISC_BASE + 0x104)
  30. #define SPEAR1340_SWITCH_CTR (VA_MISC_BASE + 0x108)
  31. #define SPEAR1340_PERIP1_SW_RST (VA_MISC_BASE + 0x318)
  32. #define SPEAR1340_PERIP2_SW_RST (VA_MISC_BASE + 0x31C)
  33. #define SPEAR1340_PERIP3_SW_RST (VA_MISC_BASE + 0x320)
  34. /* PCIE - SATA configuration registers */
  35. #define SPEAR1340_PCIE_SATA_CFG (VA_MISC_BASE + 0x424)
  36. /* PCIE CFG MASks */
  37. #define SPEAR1340_PCIE_CFG_DEVICE_PRESENT (1 << 11)
  38. #define SPEAR1340_PCIE_CFG_POWERUP_RESET (1 << 10)
  39. #define SPEAR1340_PCIE_CFG_CORE_CLK_EN (1 << 9)
  40. #define SPEAR1340_PCIE_CFG_AUX_CLK_EN (1 << 8)
  41. #define SPEAR1340_SATA_CFG_TX_CLK_EN (1 << 4)
  42. #define SPEAR1340_SATA_CFG_RX_CLK_EN (1 << 3)
  43. #define SPEAR1340_SATA_CFG_POWERUP_RESET (1 << 2)
  44. #define SPEAR1340_SATA_CFG_PM_CLK_EN (1 << 1)
  45. #define SPEAR1340_PCIE_SATA_SEL_PCIE (0)
  46. #define SPEAR1340_PCIE_SATA_SEL_SATA (1)
  47. #define SPEAR1340_SATA_PCIE_CFG_MASK 0xF1F
  48. #define SPEAR1340_PCIE_CFG_VAL (SPEAR1340_PCIE_SATA_SEL_PCIE | \
  49. SPEAR1340_PCIE_CFG_AUX_CLK_EN | \
  50. SPEAR1340_PCIE_CFG_CORE_CLK_EN | \
  51. SPEAR1340_PCIE_CFG_POWERUP_RESET | \
  52. SPEAR1340_PCIE_CFG_DEVICE_PRESENT)
  53. #define SPEAR1340_SATA_CFG_VAL (SPEAR1340_PCIE_SATA_SEL_SATA | \
  54. SPEAR1340_SATA_CFG_PM_CLK_EN | \
  55. SPEAR1340_SATA_CFG_POWERUP_RESET | \
  56. SPEAR1340_SATA_CFG_RX_CLK_EN | \
  57. SPEAR1340_SATA_CFG_TX_CLK_EN)
  58. #define SPEAR1340_PCIE_MIPHY_CFG (VA_MISC_BASE + 0x428)
  59. #define SPEAR1340_MIPHY_OSC_BYPASS_EXT (1 << 31)
  60. #define SPEAR1340_MIPHY_CLK_REF_DIV2 (1 << 27)
  61. #define SPEAR1340_MIPHY_CLK_REF_DIV4 (2 << 27)
  62. #define SPEAR1340_MIPHY_CLK_REF_DIV8 (3 << 27)
  63. #define SPEAR1340_MIPHY_PLL_RATIO_TOP(x) (x << 0)
  64. #define SPEAR1340_PCIE_SATA_MIPHY_CFG_SATA \
  65. (SPEAR1340_MIPHY_OSC_BYPASS_EXT | \
  66. SPEAR1340_MIPHY_CLK_REF_DIV2 | \
  67. SPEAR1340_MIPHY_PLL_RATIO_TOP(60))
  68. #define SPEAR1340_PCIE_SATA_MIPHY_CFG_SATA_25M_CRYSTAL_CLK \
  69. (SPEAR1340_MIPHY_PLL_RATIO_TOP(120))
  70. #define SPEAR1340_PCIE_SATA_MIPHY_CFG_PCIE \
  71. (SPEAR1340_MIPHY_OSC_BYPASS_EXT | \
  72. SPEAR1340_MIPHY_PLL_RATIO_TOP(25))
  73. static struct dw_dma_slave uart1_dma_param[] = {
  74. {
  75. /* Tx */
  76. .cfg_hi = DWC_CFGH_DST_PER(SPEAR1340_DMA_REQ_UART1_TX),
  77. .cfg_lo = 0,
  78. .src_master = DMA_MASTER_MEMORY,
  79. .dst_master = SPEAR1340_DMA_MASTER_UART1,
  80. }, {
  81. /* Rx */
  82. .cfg_hi = DWC_CFGH_SRC_PER(SPEAR1340_DMA_REQ_UART1_RX),
  83. .cfg_lo = 0,
  84. .src_master = SPEAR1340_DMA_MASTER_UART1,
  85. .dst_master = DMA_MASTER_MEMORY,
  86. }
  87. };
  88. static struct amba_pl011_data uart1_data = {
  89. .dma_filter = dw_dma_filter,
  90. .dma_tx_param = &uart1_dma_param[0],
  91. .dma_rx_param = &uart1_dma_param[1],
  92. };
  93. /* SATA device registration */
  94. static int sata_miphy_init(struct device *dev, void __iomem *addr)
  95. {
  96. writel(SPEAR1340_SATA_CFG_VAL, SPEAR1340_PCIE_SATA_CFG);
  97. writel(SPEAR1340_PCIE_SATA_MIPHY_CFG_SATA_25M_CRYSTAL_CLK,
  98. SPEAR1340_PCIE_MIPHY_CFG);
  99. /* Switch on sata power domain */
  100. writel((readl(SPEAR1340_PCM_CFG) | (0x800)), SPEAR1340_PCM_CFG);
  101. msleep(20);
  102. /* Disable PCIE SATA Controller reset */
  103. writel((readl(SPEAR1340_PERIP1_SW_RST) & (~0x1000)),
  104. SPEAR1340_PERIP1_SW_RST);
  105. msleep(20);
  106. return 0;
  107. }
  108. void sata_miphy_exit(struct device *dev)
  109. {
  110. writel(0, SPEAR1340_PCIE_SATA_CFG);
  111. writel(0, SPEAR1340_PCIE_MIPHY_CFG);
  112. /* Enable PCIE SATA Controller reset */
  113. writel((readl(SPEAR1340_PERIP1_SW_RST) | (0x1000)),
  114. SPEAR1340_PERIP1_SW_RST);
  115. msleep(20);
  116. /* Switch off sata power domain */
  117. writel((readl(SPEAR1340_PCM_CFG) & (~0x800)), SPEAR1340_PCM_CFG);
  118. msleep(20);
  119. }
  120. int sata_suspend(struct device *dev)
  121. {
  122. if (dev->power.power_state.event == PM_EVENT_FREEZE)
  123. return 0;
  124. sata_miphy_exit(dev);
  125. return 0;
  126. }
  127. int sata_resume(struct device *dev)
  128. {
  129. if (dev->power.power_state.event == PM_EVENT_THAW)
  130. return 0;
  131. return sata_miphy_init(dev, NULL);
  132. }
  133. static struct ahci_platform_data sata_pdata = {
  134. .init = sata_miphy_init,
  135. .exit = sata_miphy_exit,
  136. .suspend = sata_suspend,
  137. .resume = sata_resume,
  138. };
  139. /* Add SPEAr1340 auxdata to pass platform data */
  140. static struct of_dev_auxdata spear1340_auxdata_lookup[] __initdata = {
  141. OF_DEV_AUXDATA("arasan,cf-spear1340", MCIF_CF_BASE, NULL, &cf_dma_priv),
  142. OF_DEV_AUXDATA("snps,dma-spear1340", DMAC0_BASE, NULL, &dmac_plat_data),
  143. OF_DEV_AUXDATA("snps,dma-spear1340", DMAC1_BASE, NULL, &dmac_plat_data),
  144. OF_DEV_AUXDATA("arm,pl022", SSP_BASE, NULL, &pl022_plat_data),
  145. OF_DEV_AUXDATA("snps,spear-ahci", SPEAR1340_SATA_BASE, NULL,
  146. &sata_pdata),
  147. OF_DEV_AUXDATA("arm,pl011", SPEAR1340_UART1_BASE, NULL, &uart1_data),
  148. {}
  149. };
  150. static void __init spear1340_dt_init(void)
  151. {
  152. of_platform_populate(NULL, of_default_bus_match_table,
  153. spear1340_auxdata_lookup, NULL);
  154. }
  155. static const char * const spear1340_dt_board_compat[] = {
  156. "st,spear1340",
  157. "st,spear1340-evb",
  158. NULL,
  159. };
  160. DT_MACHINE_START(SPEAR1340_DT, "ST SPEAr1340 SoC with Flattened Device Tree")
  161. .smp = smp_ops(spear13xx_smp_ops),
  162. .map_io = spear13xx_map_io,
  163. .init_irq = spear13xx_dt_init_irq,
  164. .handle_irq = gic_handle_irq,
  165. .timer = &spear13xx_timer,
  166. .init_machine = spear1340_dt_init,
  167. .restart = spear_restart,
  168. .dt_compat = spear1340_dt_board_compat,
  169. MACHINE_END