ahci_tegra.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * drivers/ata/ahci_tegra.c
  3. *
  4. * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * Author:
  7. * Mikko Perttunen <mperttunen@nvidia.com>
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/ahci_platform.h>
  20. #include <linux/errno.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/of_device.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/regulator/consumer.h>
  26. #include <linux/reset.h>
  27. #include <soc/tegra/fuse.h>
  28. #include <soc/tegra/pmc.h>
  29. #include "ahci.h"
  30. #define DRV_NAME "tegra-ahci"
  31. #define SATA_CONFIGURATION_0 0x180
  32. #define SATA_CONFIGURATION_0_EN_FPCI BIT(0)
  33. #define SATA_CONFIGURATION_0_CLK_OVERRIDE BIT(31)
  34. #define SCFG_OFFSET 0x1000
  35. #define T_SATA0_CFG_1 0x04
  36. #define T_SATA0_CFG_1_IO_SPACE BIT(0)
  37. #define T_SATA0_CFG_1_MEMORY_SPACE BIT(1)
  38. #define T_SATA0_CFG_1_BUS_MASTER BIT(2)
  39. #define T_SATA0_CFG_1_SERR BIT(8)
  40. #define T_SATA0_CFG_9 0x24
  41. #define T_SATA0_CFG_9_BASE_ADDRESS 0x40020000
  42. #define SATA_FPCI_BAR5 0x94
  43. #define SATA_FPCI_BAR5_START_MASK (0xfffffff << 4)
  44. #define SATA_FPCI_BAR5_START (0x0040020 << 4)
  45. #define SATA_FPCI_BAR5_ACCESS_TYPE (0x1)
  46. #define SATA_INTR_MASK 0x188
  47. #define SATA_INTR_MASK_IP_INT_MASK BIT(16)
  48. #define T_SATA0_CFG_35 0x94
  49. #define T_SATA0_CFG_35_IDP_INDEX_MASK (0x7ff << 2)
  50. #define T_SATA0_CFG_35_IDP_INDEX (0x2a << 2)
  51. #define T_SATA0_AHCI_IDP1 0x98
  52. #define T_SATA0_AHCI_IDP1_DATA (0x400040)
  53. #define T_SATA0_CFG_PHY_1 0x12c
  54. #define T_SATA0_CFG_PHY_1_PADS_IDDQ_EN BIT(23)
  55. #define T_SATA0_CFG_PHY_1_PAD_PLL_IDDQ_EN BIT(22)
  56. #define T_SATA0_NVOOB 0x114
  57. #define T_SATA0_NVOOB_COMMA_CNT_MASK (0xff << 16)
  58. #define T_SATA0_NVOOB_COMMA_CNT (0x07 << 16)
  59. #define T_SATA0_NVOOB_SQUELCH_FILTER_MODE_MASK (0x3 << 24)
  60. #define T_SATA0_NVOOB_SQUELCH_FILTER_MODE (0x1 << 24)
  61. #define T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH_MASK (0x3 << 26)
  62. #define T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH (0x3 << 26)
  63. #define T_SATA_CFG_PHY_0 0x120
  64. #define T_SATA_CFG_PHY_0_USE_7BIT_ALIGN_DET_FOR_SPD BIT(11)
  65. #define T_SATA_CFG_PHY_0_MASK_SQUELCH BIT(24)
  66. #define T_SATA0_CFG2NVOOB_2 0x134
  67. #define T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW_MASK (0x1ff << 18)
  68. #define T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW (0xc << 18)
  69. #define T_SATA0_AHCI_HBA_CAP_BKDR 0x300
  70. #define T_SATA0_AHCI_HBA_CAP_BKDR_PARTIAL_ST_CAP BIT(13)
  71. #define T_SATA0_AHCI_HBA_CAP_BKDR_SLUMBER_ST_CAP BIT(14)
  72. #define T_SATA0_AHCI_HBA_CAP_BKDR_SALP BIT(26)
  73. #define T_SATA0_AHCI_HBA_CAP_BKDR_SUPP_PM BIT(17)
  74. #define T_SATA0_AHCI_HBA_CAP_BKDR_SNCQ BIT(30)
  75. #define T_SATA0_BKDOOR_CC 0x4a4
  76. #define T_SATA0_BKDOOR_CC_CLASS_CODE_MASK (0xffff << 16)
  77. #define T_SATA0_BKDOOR_CC_CLASS_CODE (0x0106 << 16)
  78. #define T_SATA0_BKDOOR_CC_PROG_IF_MASK (0xff << 8)
  79. #define T_SATA0_BKDOOR_CC_PROG_IF (0x01 << 8)
  80. #define T_SATA0_CFG_SATA 0x54c
  81. #define T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN BIT(12)
  82. #define T_SATA0_CFG_MISC 0x550
  83. #define T_SATA0_INDEX 0x680
  84. #define T_SATA0_CHX_PHY_CTRL1_GEN1 0x690
  85. #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_MASK 0xff
  86. #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT 0
  87. #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_MASK (0xff << 8)
  88. #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT 8
  89. #define T_SATA0_CHX_PHY_CTRL1_GEN2 0x694
  90. #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_MASK 0xff
  91. #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_SHIFT 0
  92. #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_MASK (0xff << 12)
  93. #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_SHIFT 12
  94. #define T_SATA0_CHX_PHY_CTRL2 0x69c
  95. #define T_SATA0_CHX_PHY_CTRL2_CDR_CNTL_GEN1 0x23
  96. #define T_SATA0_CHX_PHY_CTRL11 0x6d0
  97. #define T_SATA0_CHX_PHY_CTRL11_GEN2_RX_EQ (0x2800 << 16)
  98. #define T_SATA0_CHX_PHY_CTRL17_0 0x6e8
  99. #define T_SATA0_CHX_PHY_CTRL17_0_RX_EQ_CTRL_L_GEN1 0x55010000
  100. #define T_SATA0_CHX_PHY_CTRL18_0 0x6ec
  101. #define T_SATA0_CHX_PHY_CTRL18_0_RX_EQ_CTRL_L_GEN2 0x55010000
  102. #define T_SATA0_CHX_PHY_CTRL20_0 0x6f4
  103. #define T_SATA0_CHX_PHY_CTRL20_0_RX_EQ_CTRL_H_GEN1 0x1
  104. #define T_SATA0_CHX_PHY_CTRL21_0 0x6f8
  105. #define T_SATA0_CHX_PHY_CTRL21_0_RX_EQ_CTRL_H_GEN2 0x1
  106. /* AUX Registers */
  107. #define SATA_AUX_MISC_CNTL_1_0 0x8
  108. #define SATA_AUX_MISC_CNTL_1_0_DEVSLP_OVERRIDE BIT(17)
  109. #define SATA_AUX_MISC_CNTL_1_0_SDS_SUPPORT BIT(13)
  110. #define SATA_AUX_MISC_CNTL_1_0_DESO_SUPPORT BIT(15)
  111. #define SATA_AUX_RX_STAT_INT_0 0xc
  112. #define SATA_AUX_RX_STAT_INT_0_SATA_DEVSLP BIT(7)
  113. #define SATA_AUX_SPARE_CFG0_0 0x18
  114. #define SATA_AUX_SPARE_CFG0_0_MDAT_TIMER_AFTER_PG_VALID BIT(14)
  115. #define FUSE_SATA_CALIB 0x124
  116. #define FUSE_SATA_CALIB_MASK 0x3
  117. struct sata_pad_calibration {
  118. u8 gen1_tx_amp;
  119. u8 gen1_tx_peak;
  120. u8 gen2_tx_amp;
  121. u8 gen2_tx_peak;
  122. };
  123. static const struct sata_pad_calibration tegra124_pad_calibration[] = {
  124. {0x18, 0x04, 0x18, 0x0a},
  125. {0x0e, 0x04, 0x14, 0x0a},
  126. {0x0e, 0x07, 0x1a, 0x0e},
  127. {0x14, 0x0e, 0x1a, 0x0e},
  128. };
  129. struct tegra_ahci_ops {
  130. int (*init)(struct ahci_host_priv *hpriv);
  131. };
  132. struct tegra_ahci_soc {
  133. const char *const *supply_names;
  134. u32 num_supplies;
  135. bool supports_devslp;
  136. const struct tegra_ahci_ops *ops;
  137. };
  138. struct tegra_ahci_priv {
  139. struct platform_device *pdev;
  140. void __iomem *sata_regs;
  141. void __iomem *sata_aux_regs;
  142. struct reset_control *sata_rst;
  143. struct reset_control *sata_oob_rst;
  144. struct reset_control *sata_cold_rst;
  145. /* Needs special handling, cannot use ahci_platform */
  146. struct clk *sata_clk;
  147. struct regulator_bulk_data *supplies;
  148. const struct tegra_ahci_soc *soc;
  149. };
  150. static void tegra_ahci_handle_quirks(struct ahci_host_priv *hpriv)
  151. {
  152. struct tegra_ahci_priv *tegra = hpriv->plat_data;
  153. u32 val;
  154. if (tegra->sata_aux_regs && !tegra->soc->supports_devslp) {
  155. val = readl(tegra->sata_aux_regs + SATA_AUX_MISC_CNTL_1_0);
  156. val &= ~SATA_AUX_MISC_CNTL_1_0_SDS_SUPPORT;
  157. writel(val, tegra->sata_aux_regs + SATA_AUX_MISC_CNTL_1_0);
  158. }
  159. }
  160. static int tegra124_ahci_init(struct ahci_host_priv *hpriv)
  161. {
  162. struct tegra_ahci_priv *tegra = hpriv->plat_data;
  163. struct sata_pad_calibration calib;
  164. int ret;
  165. u32 val;
  166. /* Pad calibration */
  167. ret = tegra_fuse_readl(FUSE_SATA_CALIB, &val);
  168. if (ret)
  169. return ret;
  170. calib = tegra124_pad_calibration[val & FUSE_SATA_CALIB_MASK];
  171. writel(BIT(0), tegra->sata_regs + SCFG_OFFSET + T_SATA0_INDEX);
  172. val = readl(tegra->sata_regs +
  173. SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL1_GEN1);
  174. val &= ~T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_MASK;
  175. val &= ~T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_MASK;
  176. val |= calib.gen1_tx_amp << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT;
  177. val |= calib.gen1_tx_peak << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT;
  178. writel(val, tegra->sata_regs + SCFG_OFFSET +
  179. T_SATA0_CHX_PHY_CTRL1_GEN1);
  180. val = readl(tegra->sata_regs +
  181. SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL1_GEN2);
  182. val &= ~T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_MASK;
  183. val &= ~T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_MASK;
  184. val |= calib.gen2_tx_amp << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT;
  185. val |= calib.gen2_tx_peak << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT;
  186. writel(val, tegra->sata_regs + SCFG_OFFSET +
  187. T_SATA0_CHX_PHY_CTRL1_GEN2);
  188. writel(T_SATA0_CHX_PHY_CTRL11_GEN2_RX_EQ,
  189. tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL11);
  190. writel(T_SATA0_CHX_PHY_CTRL2_CDR_CNTL_GEN1,
  191. tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL2);
  192. writel(0, tegra->sata_regs + SCFG_OFFSET + T_SATA0_INDEX);
  193. return 0;
  194. }
  195. static int tegra_ahci_power_on(struct ahci_host_priv *hpriv)
  196. {
  197. struct tegra_ahci_priv *tegra = hpriv->plat_data;
  198. int ret;
  199. ret = regulator_bulk_enable(tegra->soc->num_supplies,
  200. tegra->supplies);
  201. if (ret)
  202. return ret;
  203. ret = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_SATA,
  204. tegra->sata_clk,
  205. tegra->sata_rst);
  206. if (ret)
  207. goto disable_regulators;
  208. reset_control_assert(tegra->sata_oob_rst);
  209. reset_control_assert(tegra->sata_cold_rst);
  210. ret = ahci_platform_enable_resources(hpriv);
  211. if (ret)
  212. goto disable_power;
  213. reset_control_deassert(tegra->sata_cold_rst);
  214. reset_control_deassert(tegra->sata_oob_rst);
  215. return 0;
  216. disable_power:
  217. clk_disable_unprepare(tegra->sata_clk);
  218. tegra_powergate_power_off(TEGRA_POWERGATE_SATA);
  219. disable_regulators:
  220. regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
  221. return ret;
  222. }
  223. static void tegra_ahci_power_off(struct ahci_host_priv *hpriv)
  224. {
  225. struct tegra_ahci_priv *tegra = hpriv->plat_data;
  226. ahci_platform_disable_resources(hpriv);
  227. reset_control_assert(tegra->sata_rst);
  228. reset_control_assert(tegra->sata_oob_rst);
  229. reset_control_assert(tegra->sata_cold_rst);
  230. clk_disable_unprepare(tegra->sata_clk);
  231. tegra_powergate_power_off(TEGRA_POWERGATE_SATA);
  232. regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
  233. }
  234. static int tegra_ahci_controller_init(struct ahci_host_priv *hpriv)
  235. {
  236. struct tegra_ahci_priv *tegra = hpriv->plat_data;
  237. int ret;
  238. u32 val;
  239. ret = tegra_ahci_power_on(hpriv);
  240. if (ret) {
  241. dev_err(&tegra->pdev->dev,
  242. "failed to power on AHCI controller: %d\n", ret);
  243. return ret;
  244. }
  245. /*
  246. * Program the following SATA IPFS registers to allow SW accesses to
  247. * SATA's MMIO register range.
  248. */
  249. val = readl(tegra->sata_regs + SATA_FPCI_BAR5);
  250. val &= ~(SATA_FPCI_BAR5_START_MASK | SATA_FPCI_BAR5_ACCESS_TYPE);
  251. val |= SATA_FPCI_BAR5_START | SATA_FPCI_BAR5_ACCESS_TYPE;
  252. writel(val, tegra->sata_regs + SATA_FPCI_BAR5);
  253. /* Program the following SATA IPFS register to enable the SATA */
  254. val = readl(tegra->sata_regs + SATA_CONFIGURATION_0);
  255. val |= SATA_CONFIGURATION_0_EN_FPCI;
  256. writel(val, tegra->sata_regs + SATA_CONFIGURATION_0);
  257. /* Electrical settings for better link stability */
  258. val = T_SATA0_CHX_PHY_CTRL17_0_RX_EQ_CTRL_L_GEN1;
  259. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL17_0);
  260. val = T_SATA0_CHX_PHY_CTRL18_0_RX_EQ_CTRL_L_GEN2;
  261. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL18_0);
  262. val = T_SATA0_CHX_PHY_CTRL20_0_RX_EQ_CTRL_H_GEN1;
  263. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL20_0);
  264. val = T_SATA0_CHX_PHY_CTRL21_0_RX_EQ_CTRL_H_GEN2;
  265. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL21_0);
  266. /* For SQUELCH Filter & Gen3 drive getting detected as Gen1 drive */
  267. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA_CFG_PHY_0);
  268. val |= T_SATA_CFG_PHY_0_MASK_SQUELCH;
  269. val &= ~T_SATA_CFG_PHY_0_USE_7BIT_ALIGN_DET_FOR_SPD;
  270. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA_CFG_PHY_0);
  271. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_NVOOB);
  272. val &= ~(T_SATA0_NVOOB_COMMA_CNT_MASK |
  273. T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH_MASK |
  274. T_SATA0_NVOOB_SQUELCH_FILTER_MODE_MASK);
  275. val |= (T_SATA0_NVOOB_COMMA_CNT |
  276. T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH |
  277. T_SATA0_NVOOB_SQUELCH_FILTER_MODE);
  278. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_NVOOB);
  279. /*
  280. * Change CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW from 83.3 ns to 58.8ns
  281. */
  282. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG2NVOOB_2);
  283. val &= ~T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW_MASK;
  284. val |= T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW;
  285. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG2NVOOB_2);
  286. if (tegra->soc->ops && tegra->soc->ops->init)
  287. tegra->soc->ops->init(hpriv);
  288. /*
  289. * Program the following SATA configuration registers to
  290. * initialize SATA
  291. */
  292. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_1);
  293. val |= (T_SATA0_CFG_1_IO_SPACE | T_SATA0_CFG_1_MEMORY_SPACE |
  294. T_SATA0_CFG_1_BUS_MASTER | T_SATA0_CFG_1_SERR);
  295. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_1);
  296. val = T_SATA0_CFG_9_BASE_ADDRESS;
  297. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_9);
  298. /* Program Class Code and Programming interface for SATA */
  299. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
  300. val |= T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN;
  301. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
  302. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_BKDOOR_CC);
  303. val &=
  304. ~(T_SATA0_BKDOOR_CC_CLASS_CODE_MASK |
  305. T_SATA0_BKDOOR_CC_PROG_IF_MASK);
  306. val |= T_SATA0_BKDOOR_CC_CLASS_CODE | T_SATA0_BKDOOR_CC_PROG_IF;
  307. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_BKDOOR_CC);
  308. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
  309. val &= ~T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN;
  310. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
  311. /* Enabling LPM capabilities through Backdoor Programming */
  312. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_AHCI_HBA_CAP_BKDR);
  313. val |= (T_SATA0_AHCI_HBA_CAP_BKDR_PARTIAL_ST_CAP |
  314. T_SATA0_AHCI_HBA_CAP_BKDR_SLUMBER_ST_CAP |
  315. T_SATA0_AHCI_HBA_CAP_BKDR_SALP |
  316. T_SATA0_AHCI_HBA_CAP_BKDR_SUPP_PM);
  317. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_AHCI_HBA_CAP_BKDR);
  318. /* SATA Second Level Clock Gating configuration
  319. * Enabling Gating of Tx/Rx clocks and driving Pad IDDQ and Lane
  320. * IDDQ Signals
  321. */
  322. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_35);
  323. val &= ~T_SATA0_CFG_35_IDP_INDEX_MASK;
  324. val |= T_SATA0_CFG_35_IDP_INDEX;
  325. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_35);
  326. val = T_SATA0_AHCI_IDP1_DATA;
  327. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_AHCI_IDP1);
  328. val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_PHY_1);
  329. val |= (T_SATA0_CFG_PHY_1_PADS_IDDQ_EN |
  330. T_SATA0_CFG_PHY_1_PAD_PLL_IDDQ_EN);
  331. writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_PHY_1);
  332. /* Enabling IPFS Clock Gating */
  333. val = readl(tegra->sata_regs + SATA_CONFIGURATION_0);
  334. val &= ~SATA_CONFIGURATION_0_CLK_OVERRIDE;
  335. writel(val, tegra->sata_regs + SATA_CONFIGURATION_0);
  336. tegra_ahci_handle_quirks(hpriv);
  337. /* Unmask SATA interrupts */
  338. val = readl(tegra->sata_regs + SATA_INTR_MASK);
  339. val |= SATA_INTR_MASK_IP_INT_MASK;
  340. writel(val, tegra->sata_regs + SATA_INTR_MASK);
  341. return 0;
  342. }
  343. static void tegra_ahci_controller_deinit(struct ahci_host_priv *hpriv)
  344. {
  345. tegra_ahci_power_off(hpriv);
  346. }
  347. static void tegra_ahci_host_stop(struct ata_host *host)
  348. {
  349. struct ahci_host_priv *hpriv = host->private_data;
  350. tegra_ahci_controller_deinit(hpriv);
  351. }
  352. static struct ata_port_operations ahci_tegra_port_ops = {
  353. .inherits = &ahci_ops,
  354. .host_stop = tegra_ahci_host_stop,
  355. };
  356. static const struct ata_port_info ahci_tegra_port_info = {
  357. .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_DIPM,
  358. .pio_mask = ATA_PIO4,
  359. .udma_mask = ATA_UDMA6,
  360. .port_ops = &ahci_tegra_port_ops,
  361. };
  362. static const char *const tegra124_supply_names[] = {
  363. "avdd", "hvdd", "vddio", "target-5v", "target-12v"
  364. };
  365. static const struct tegra_ahci_ops tegra124_ahci_ops = {
  366. .init = tegra124_ahci_init,
  367. };
  368. static const struct tegra_ahci_soc tegra124_ahci_soc = {
  369. .supply_names = tegra124_supply_names,
  370. .num_supplies = ARRAY_SIZE(tegra124_supply_names),
  371. .supports_devslp = false,
  372. .ops = &tegra124_ahci_ops,
  373. };
  374. static const struct tegra_ahci_soc tegra210_ahci_soc = {
  375. .supports_devslp = false,
  376. };
  377. static const struct of_device_id tegra_ahci_of_match[] = {
  378. {
  379. .compatible = "nvidia,tegra124-ahci",
  380. .data = &tegra124_ahci_soc
  381. },
  382. {
  383. .compatible = "nvidia,tegra210-ahci",
  384. .data = &tegra210_ahci_soc
  385. },
  386. {}
  387. };
  388. MODULE_DEVICE_TABLE(of, tegra_ahci_of_match);
  389. static struct scsi_host_template ahci_platform_sht = {
  390. AHCI_SHT(DRV_NAME),
  391. };
  392. static int tegra_ahci_probe(struct platform_device *pdev)
  393. {
  394. struct ahci_host_priv *hpriv;
  395. struct tegra_ahci_priv *tegra;
  396. struct resource *res;
  397. int ret;
  398. unsigned int i;
  399. hpriv = ahci_platform_get_resources(pdev, 0);
  400. if (IS_ERR(hpriv))
  401. return PTR_ERR(hpriv);
  402. tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
  403. if (!tegra)
  404. return -ENOMEM;
  405. hpriv->plat_data = tegra;
  406. tegra->pdev = pdev;
  407. tegra->soc = of_device_get_match_data(&pdev->dev);
  408. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  409. tegra->sata_regs = devm_ioremap_resource(&pdev->dev, res);
  410. if (IS_ERR(tegra->sata_regs))
  411. return PTR_ERR(tegra->sata_regs);
  412. /*
  413. * AUX registers is optional.
  414. */
  415. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  416. if (res) {
  417. tegra->sata_aux_regs = devm_ioremap_resource(&pdev->dev, res);
  418. if (IS_ERR(tegra->sata_aux_regs))
  419. return PTR_ERR(tegra->sata_aux_regs);
  420. }
  421. tegra->sata_rst = devm_reset_control_get(&pdev->dev, "sata");
  422. if (IS_ERR(tegra->sata_rst)) {
  423. dev_err(&pdev->dev, "Failed to get sata reset\n");
  424. return PTR_ERR(tegra->sata_rst);
  425. }
  426. tegra->sata_oob_rst = devm_reset_control_get(&pdev->dev, "sata-oob");
  427. if (IS_ERR(tegra->sata_oob_rst)) {
  428. dev_err(&pdev->dev, "Failed to get sata-oob reset\n");
  429. return PTR_ERR(tegra->sata_oob_rst);
  430. }
  431. tegra->sata_cold_rst = devm_reset_control_get(&pdev->dev, "sata-cold");
  432. if (IS_ERR(tegra->sata_cold_rst)) {
  433. dev_err(&pdev->dev, "Failed to get sata-cold reset\n");
  434. return PTR_ERR(tegra->sata_cold_rst);
  435. }
  436. tegra->sata_clk = devm_clk_get(&pdev->dev, "sata");
  437. if (IS_ERR(tegra->sata_clk)) {
  438. dev_err(&pdev->dev, "Failed to get sata clock\n");
  439. return PTR_ERR(tegra->sata_clk);
  440. }
  441. tegra->supplies = devm_kcalloc(&pdev->dev,
  442. tegra->soc->num_supplies,
  443. sizeof(*tegra->supplies), GFP_KERNEL);
  444. if (!tegra->supplies)
  445. return -ENOMEM;
  446. for (i = 0; i < tegra->soc->num_supplies; i++)
  447. tegra->supplies[i].supply = tegra->soc->supply_names[i];
  448. ret = devm_regulator_bulk_get(&pdev->dev,
  449. tegra->soc->num_supplies,
  450. tegra->supplies);
  451. if (ret) {
  452. dev_err(&pdev->dev, "Failed to get regulators\n");
  453. return ret;
  454. }
  455. ret = tegra_ahci_controller_init(hpriv);
  456. if (ret)
  457. return ret;
  458. ret = ahci_platform_init_host(pdev, hpriv, &ahci_tegra_port_info,
  459. &ahci_platform_sht);
  460. if (ret)
  461. goto deinit_controller;
  462. return 0;
  463. deinit_controller:
  464. tegra_ahci_controller_deinit(hpriv);
  465. return ret;
  466. };
  467. static struct platform_driver tegra_ahci_driver = {
  468. .probe = tegra_ahci_probe,
  469. .remove = ata_platform_remove_one,
  470. .driver = {
  471. .name = DRV_NAME,
  472. .of_match_table = tegra_ahci_of_match,
  473. },
  474. /* LP0 suspend support not implemented */
  475. };
  476. module_platform_driver(tegra_ahci_driver);
  477. MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
  478. MODULE_DESCRIPTION("Tegra AHCI SATA driver");
  479. MODULE_LICENSE("GPL v2");