spear1340.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/of_platform.h>
  18. #include <asm/mach/arch.h>
  19. #include "generic.h"
  20. #include <mach/spear.h>
  21. /* FIXME: Move SATA PHY code into a standalone driver */
  22. /* Base addresses */
  23. #define SPEAR1340_SATA_BASE UL(0xB1000000)
  24. /* Power Management Registers */
  25. #define SPEAR1340_PCM_CFG (VA_MISC_BASE + 0x100)
  26. #define SPEAR1340_PCM_WKUP_CFG (VA_MISC_BASE + 0x104)
  27. #define SPEAR1340_SWITCH_CTR (VA_MISC_BASE + 0x108)
  28. #define SPEAR1340_PERIP1_SW_RST (VA_MISC_BASE + 0x318)
  29. #define SPEAR1340_PERIP2_SW_RST (VA_MISC_BASE + 0x31C)
  30. #define SPEAR1340_PERIP3_SW_RST (VA_MISC_BASE + 0x320)
  31. /* PCIE - SATA configuration registers */
  32. #define SPEAR1340_PCIE_SATA_CFG (VA_MISC_BASE + 0x424)
  33. /* PCIE CFG MASks */
  34. #define SPEAR1340_PCIE_CFG_DEVICE_PRESENT (1 << 11)
  35. #define SPEAR1340_PCIE_CFG_POWERUP_RESET (1 << 10)
  36. #define SPEAR1340_PCIE_CFG_CORE_CLK_EN (1 << 9)
  37. #define SPEAR1340_PCIE_CFG_AUX_CLK_EN (1 << 8)
  38. #define SPEAR1340_SATA_CFG_TX_CLK_EN (1 << 4)
  39. #define SPEAR1340_SATA_CFG_RX_CLK_EN (1 << 3)
  40. #define SPEAR1340_SATA_CFG_POWERUP_RESET (1 << 2)
  41. #define SPEAR1340_SATA_CFG_PM_CLK_EN (1 << 1)
  42. #define SPEAR1340_PCIE_SATA_SEL_PCIE (0)
  43. #define SPEAR1340_PCIE_SATA_SEL_SATA (1)
  44. #define SPEAR1340_SATA_PCIE_CFG_MASK 0xF1F
  45. #define SPEAR1340_PCIE_CFG_VAL (SPEAR1340_PCIE_SATA_SEL_PCIE | \
  46. SPEAR1340_PCIE_CFG_AUX_CLK_EN | \
  47. SPEAR1340_PCIE_CFG_CORE_CLK_EN | \
  48. SPEAR1340_PCIE_CFG_POWERUP_RESET | \
  49. SPEAR1340_PCIE_CFG_DEVICE_PRESENT)
  50. #define SPEAR1340_SATA_CFG_VAL (SPEAR1340_PCIE_SATA_SEL_SATA | \
  51. SPEAR1340_SATA_CFG_PM_CLK_EN | \
  52. SPEAR1340_SATA_CFG_POWERUP_RESET | \
  53. SPEAR1340_SATA_CFG_RX_CLK_EN | \
  54. SPEAR1340_SATA_CFG_TX_CLK_EN)
  55. #define SPEAR1340_PCIE_MIPHY_CFG (VA_MISC_BASE + 0x428)
  56. #define SPEAR1340_MIPHY_OSC_BYPASS_EXT (1 << 31)
  57. #define SPEAR1340_MIPHY_CLK_REF_DIV2 (1 << 27)
  58. #define SPEAR1340_MIPHY_CLK_REF_DIV4 (2 << 27)
  59. #define SPEAR1340_MIPHY_CLK_REF_DIV8 (3 << 27)
  60. #define SPEAR1340_MIPHY_PLL_RATIO_TOP(x) (x << 0)
  61. #define SPEAR1340_PCIE_SATA_MIPHY_CFG_SATA \
  62. (SPEAR1340_MIPHY_OSC_BYPASS_EXT | \
  63. SPEAR1340_MIPHY_CLK_REF_DIV2 | \
  64. SPEAR1340_MIPHY_PLL_RATIO_TOP(60))
  65. #define SPEAR1340_PCIE_SATA_MIPHY_CFG_SATA_25M_CRYSTAL_CLK \
  66. (SPEAR1340_MIPHY_PLL_RATIO_TOP(120))
  67. #define SPEAR1340_PCIE_SATA_MIPHY_CFG_PCIE \
  68. (SPEAR1340_MIPHY_OSC_BYPASS_EXT | \
  69. SPEAR1340_MIPHY_PLL_RATIO_TOP(25))
  70. /* SATA device registration */
  71. static int sata_miphy_init(struct device *dev, void __iomem *addr)
  72. {
  73. writel(SPEAR1340_SATA_CFG_VAL, SPEAR1340_PCIE_SATA_CFG);
  74. writel(SPEAR1340_PCIE_SATA_MIPHY_CFG_SATA_25M_CRYSTAL_CLK,
  75. SPEAR1340_PCIE_MIPHY_CFG);
  76. /* Switch on sata power domain */
  77. writel((readl(SPEAR1340_PCM_CFG) | (0x800)), SPEAR1340_PCM_CFG);
  78. msleep(20);
  79. /* Disable PCIE SATA Controller reset */
  80. writel((readl(SPEAR1340_PERIP1_SW_RST) & (~0x1000)),
  81. SPEAR1340_PERIP1_SW_RST);
  82. msleep(20);
  83. return 0;
  84. }
  85. void sata_miphy_exit(struct device *dev)
  86. {
  87. writel(0, SPEAR1340_PCIE_SATA_CFG);
  88. writel(0, SPEAR1340_PCIE_MIPHY_CFG);
  89. /* Enable PCIE SATA Controller reset */
  90. writel((readl(SPEAR1340_PERIP1_SW_RST) | (0x1000)),
  91. SPEAR1340_PERIP1_SW_RST);
  92. msleep(20);
  93. /* Switch off sata power domain */
  94. writel((readl(SPEAR1340_PCM_CFG) & (~0x800)), SPEAR1340_PCM_CFG);
  95. msleep(20);
  96. }
  97. int sata_suspend(struct device *dev)
  98. {
  99. if (dev->power.power_state.event == PM_EVENT_FREEZE)
  100. return 0;
  101. sata_miphy_exit(dev);
  102. return 0;
  103. }
  104. int sata_resume(struct device *dev)
  105. {
  106. if (dev->power.power_state.event == PM_EVENT_THAW)
  107. return 0;
  108. return sata_miphy_init(dev, NULL);
  109. }
  110. static struct ahci_platform_data sata_pdata = {
  111. .init = sata_miphy_init,
  112. .exit = sata_miphy_exit,
  113. .suspend = sata_suspend,
  114. .resume = sata_resume,
  115. };
  116. /* Add SPEAr1340 auxdata to pass platform data */
  117. static struct of_dev_auxdata spear1340_auxdata_lookup[] __initdata = {
  118. OF_DEV_AUXDATA("snps,spear-ahci", SPEAR1340_SATA_BASE, NULL,
  119. &sata_pdata),
  120. {}
  121. };
  122. static void __init spear1340_dt_init(void)
  123. {
  124. of_platform_populate(NULL, of_default_bus_match_table,
  125. spear1340_auxdata_lookup, NULL);
  126. }
  127. static const char * const spear1340_dt_board_compat[] = {
  128. "st,spear1340",
  129. "st,spear1340-evb",
  130. NULL,
  131. };
  132. DT_MACHINE_START(SPEAR1340_DT, "ST SPEAr1340 SoC with Flattened Device Tree")
  133. .smp = smp_ops(spear13xx_smp_ops),
  134. .map_io = spear13xx_map_io,
  135. .init_time = spear13xx_timer_init,
  136. .init_machine = spear1340_dt_init,
  137. .restart = spear_restart,
  138. .dt_compat = spear1340_dt_board_compat,
  139. MACHINE_END