spear1340.c 4.9 KB

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