ovl: add reflink/copyfile/dedup support
[linux/fpc-iii.git] / drivers / ata / ahci_tegra.c
blob64d848409fe23d4c457f57f8b26d39769199caed
1 /*
2 * drivers/ata/ahci_tegra.c
4 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
6 * Author:
7 * Mikko Perttunen <mperttunen@nvidia.com>
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.
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.
20 #include <linux/ahci_platform.h>
21 #include <linux/errno.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/of_device.h>
25 #include <linux/platform_device.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/reset.h>
29 #include <soc/tegra/fuse.h>
30 #include <soc/tegra/pmc.h>
32 #include "ahci.h"
34 #define DRV_NAME "tegra-ahci"
36 #define SATA_CONFIGURATION_0 0x180
37 #define SATA_CONFIGURATION_0_EN_FPCI BIT(0)
38 #define SATA_CONFIGURATION_0_CLK_OVERRIDE BIT(31)
40 #define SCFG_OFFSET 0x1000
42 #define T_SATA0_CFG_1 0x04
43 #define T_SATA0_CFG_1_IO_SPACE BIT(0)
44 #define T_SATA0_CFG_1_MEMORY_SPACE BIT(1)
45 #define T_SATA0_CFG_1_BUS_MASTER BIT(2)
46 #define T_SATA0_CFG_1_SERR BIT(8)
48 #define T_SATA0_CFG_9 0x24
49 #define T_SATA0_CFG_9_BASE_ADDRESS 0x40020000
51 #define SATA_FPCI_BAR5 0x94
52 #define SATA_FPCI_BAR5_START_MASK (0xfffffff << 4)
53 #define SATA_FPCI_BAR5_START (0x0040020 << 4)
54 #define SATA_FPCI_BAR5_ACCESS_TYPE (0x1)
56 #define SATA_INTR_MASK 0x188
57 #define SATA_INTR_MASK_IP_INT_MASK BIT(16)
59 #define T_SATA0_CFG_35 0x94
60 #define T_SATA0_CFG_35_IDP_INDEX_MASK (0x7ff << 2)
61 #define T_SATA0_CFG_35_IDP_INDEX (0x2a << 2)
63 #define T_SATA0_AHCI_IDP1 0x98
64 #define T_SATA0_AHCI_IDP1_DATA (0x400040)
66 #define T_SATA0_CFG_PHY_1 0x12c
67 #define T_SATA0_CFG_PHY_1_PADS_IDDQ_EN BIT(23)
68 #define T_SATA0_CFG_PHY_1_PAD_PLL_IDDQ_EN BIT(22)
70 #define T_SATA0_NVOOB 0x114
71 #define T_SATA0_NVOOB_COMMA_CNT_MASK (0xff << 16)
72 #define T_SATA0_NVOOB_COMMA_CNT (0x07 << 16)
73 #define T_SATA0_NVOOB_SQUELCH_FILTER_MODE_MASK (0x3 << 24)
74 #define T_SATA0_NVOOB_SQUELCH_FILTER_MODE (0x1 << 24)
75 #define T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH_MASK (0x3 << 26)
76 #define T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH (0x3 << 26)
78 #define T_SATA_CFG_PHY_0 0x120
79 #define T_SATA_CFG_PHY_0_USE_7BIT_ALIGN_DET_FOR_SPD BIT(11)
80 #define T_SATA_CFG_PHY_0_MASK_SQUELCH BIT(24)
82 #define T_SATA0_CFG2NVOOB_2 0x134
83 #define T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW_MASK (0x1ff << 18)
84 #define T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW (0xc << 18)
86 #define T_SATA0_AHCI_HBA_CAP_BKDR 0x300
87 #define T_SATA0_AHCI_HBA_CAP_BKDR_PARTIAL_ST_CAP BIT(13)
88 #define T_SATA0_AHCI_HBA_CAP_BKDR_SLUMBER_ST_CAP BIT(14)
89 #define T_SATA0_AHCI_HBA_CAP_BKDR_SALP BIT(26)
90 #define T_SATA0_AHCI_HBA_CAP_BKDR_SUPP_PM BIT(17)
91 #define T_SATA0_AHCI_HBA_CAP_BKDR_SNCQ BIT(30)
93 #define T_SATA0_BKDOOR_CC 0x4a4
94 #define T_SATA0_BKDOOR_CC_CLASS_CODE_MASK (0xffff << 16)
95 #define T_SATA0_BKDOOR_CC_CLASS_CODE (0x0106 << 16)
96 #define T_SATA0_BKDOOR_CC_PROG_IF_MASK (0xff << 8)
97 #define T_SATA0_BKDOOR_CC_PROG_IF (0x01 << 8)
99 #define T_SATA0_CFG_SATA 0x54c
100 #define T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN BIT(12)
102 #define T_SATA0_CFG_MISC 0x550
104 #define T_SATA0_INDEX 0x680
106 #define T_SATA0_CHX_PHY_CTRL1_GEN1 0x690
107 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_MASK 0xff
108 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT 0
109 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_MASK (0xff << 8)
110 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT 8
112 #define T_SATA0_CHX_PHY_CTRL1_GEN2 0x694
113 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_MASK 0xff
114 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_SHIFT 0
115 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_MASK (0xff << 12)
116 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_SHIFT 12
118 #define T_SATA0_CHX_PHY_CTRL2 0x69c
119 #define T_SATA0_CHX_PHY_CTRL2_CDR_CNTL_GEN1 0x23
121 #define T_SATA0_CHX_PHY_CTRL11 0x6d0
122 #define T_SATA0_CHX_PHY_CTRL11_GEN2_RX_EQ (0x2800 << 16)
124 #define T_SATA0_CHX_PHY_CTRL17_0 0x6e8
125 #define T_SATA0_CHX_PHY_CTRL17_0_RX_EQ_CTRL_L_GEN1 0x55010000
126 #define T_SATA0_CHX_PHY_CTRL18_0 0x6ec
127 #define T_SATA0_CHX_PHY_CTRL18_0_RX_EQ_CTRL_L_GEN2 0x55010000
128 #define T_SATA0_CHX_PHY_CTRL20_0 0x6f4
129 #define T_SATA0_CHX_PHY_CTRL20_0_RX_EQ_CTRL_H_GEN1 0x1
130 #define T_SATA0_CHX_PHY_CTRL21_0 0x6f8
131 #define T_SATA0_CHX_PHY_CTRL21_0_RX_EQ_CTRL_H_GEN2 0x1
133 /* AUX Registers */
134 #define SATA_AUX_MISC_CNTL_1_0 0x8
135 #define SATA_AUX_MISC_CNTL_1_0_DEVSLP_OVERRIDE BIT(17)
136 #define SATA_AUX_MISC_CNTL_1_0_SDS_SUPPORT BIT(13)
137 #define SATA_AUX_MISC_CNTL_1_0_DESO_SUPPORT BIT(15)
139 #define SATA_AUX_RX_STAT_INT_0 0xc
140 #define SATA_AUX_RX_STAT_INT_0_SATA_DEVSLP BIT(7)
142 #define SATA_AUX_SPARE_CFG0_0 0x18
143 #define SATA_AUX_SPARE_CFG0_0_MDAT_TIMER_AFTER_PG_VALID BIT(14)
145 #define FUSE_SATA_CALIB 0x124
146 #define FUSE_SATA_CALIB_MASK 0x3
148 struct sata_pad_calibration {
149 u8 gen1_tx_amp;
150 u8 gen1_tx_peak;
151 u8 gen2_tx_amp;
152 u8 gen2_tx_peak;
155 static const struct sata_pad_calibration tegra124_pad_calibration[] = {
156 {0x18, 0x04, 0x18, 0x0a},
157 {0x0e, 0x04, 0x14, 0x0a},
158 {0x0e, 0x07, 0x1a, 0x0e},
159 {0x14, 0x0e, 0x1a, 0x0e},
162 struct tegra_ahci_ops {
163 int (*init)(struct ahci_host_priv *hpriv);
166 struct tegra_ahci_soc {
167 const char *const *supply_names;
168 u32 num_supplies;
169 bool supports_devslp;
170 const struct tegra_ahci_ops *ops;
173 struct tegra_ahci_priv {
174 struct platform_device *pdev;
175 void __iomem *sata_regs;
176 void __iomem *sata_aux_regs;
177 struct reset_control *sata_rst;
178 struct reset_control *sata_oob_rst;
179 struct reset_control *sata_cold_rst;
180 /* Needs special handling, cannot use ahci_platform */
181 struct clk *sata_clk;
182 struct regulator_bulk_data *supplies;
183 const struct tegra_ahci_soc *soc;
186 static void tegra_ahci_handle_quirks(struct ahci_host_priv *hpriv)
188 struct tegra_ahci_priv *tegra = hpriv->plat_data;
189 u32 val;
191 if (tegra->sata_aux_regs && !tegra->soc->supports_devslp) {
192 val = readl(tegra->sata_aux_regs + SATA_AUX_MISC_CNTL_1_0);
193 val &= ~SATA_AUX_MISC_CNTL_1_0_SDS_SUPPORT;
194 writel(val, tegra->sata_aux_regs + SATA_AUX_MISC_CNTL_1_0);
198 static int tegra124_ahci_init(struct ahci_host_priv *hpriv)
200 struct tegra_ahci_priv *tegra = hpriv->plat_data;
201 struct sata_pad_calibration calib;
202 int ret;
203 u32 val;
205 /* Pad calibration */
206 ret = tegra_fuse_readl(FUSE_SATA_CALIB, &val);
207 if (ret)
208 return ret;
210 calib = tegra124_pad_calibration[val & FUSE_SATA_CALIB_MASK];
212 writel(BIT(0), tegra->sata_regs + SCFG_OFFSET + T_SATA0_INDEX);
214 val = readl(tegra->sata_regs +
215 SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL1_GEN1);
216 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_MASK;
217 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_MASK;
218 val |= calib.gen1_tx_amp << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT;
219 val |= calib.gen1_tx_peak << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT;
220 writel(val, tegra->sata_regs + SCFG_OFFSET +
221 T_SATA0_CHX_PHY_CTRL1_GEN1);
223 val = readl(tegra->sata_regs +
224 SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL1_GEN2);
225 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_MASK;
226 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_MASK;
227 val |= calib.gen2_tx_amp << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT;
228 val |= calib.gen2_tx_peak << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT;
229 writel(val, tegra->sata_regs + SCFG_OFFSET +
230 T_SATA0_CHX_PHY_CTRL1_GEN2);
232 writel(T_SATA0_CHX_PHY_CTRL11_GEN2_RX_EQ,
233 tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL11);
234 writel(T_SATA0_CHX_PHY_CTRL2_CDR_CNTL_GEN1,
235 tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL2);
237 writel(0, tegra->sata_regs + SCFG_OFFSET + T_SATA0_INDEX);
239 return 0;
242 static int tegra_ahci_power_on(struct ahci_host_priv *hpriv)
244 struct tegra_ahci_priv *tegra = hpriv->plat_data;
245 int ret;
247 ret = regulator_bulk_enable(tegra->soc->num_supplies,
248 tegra->supplies);
249 if (ret)
250 return ret;
252 ret = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_SATA,
253 tegra->sata_clk,
254 tegra->sata_rst);
255 if (ret)
256 goto disable_regulators;
258 reset_control_assert(tegra->sata_oob_rst);
259 reset_control_assert(tegra->sata_cold_rst);
261 ret = ahci_platform_enable_resources(hpriv);
262 if (ret)
263 goto disable_power;
265 reset_control_deassert(tegra->sata_cold_rst);
266 reset_control_deassert(tegra->sata_oob_rst);
268 return 0;
270 disable_power:
271 clk_disable_unprepare(tegra->sata_clk);
273 tegra_powergate_power_off(TEGRA_POWERGATE_SATA);
275 disable_regulators:
276 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
278 return ret;
281 static void tegra_ahci_power_off(struct ahci_host_priv *hpriv)
283 struct tegra_ahci_priv *tegra = hpriv->plat_data;
285 ahci_platform_disable_resources(hpriv);
287 reset_control_assert(tegra->sata_rst);
288 reset_control_assert(tegra->sata_oob_rst);
289 reset_control_assert(tegra->sata_cold_rst);
291 clk_disable_unprepare(tegra->sata_clk);
292 tegra_powergate_power_off(TEGRA_POWERGATE_SATA);
294 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
297 static int tegra_ahci_controller_init(struct ahci_host_priv *hpriv)
299 struct tegra_ahci_priv *tegra = hpriv->plat_data;
300 int ret;
301 u32 val;
303 ret = tegra_ahci_power_on(hpriv);
304 if (ret) {
305 dev_err(&tegra->pdev->dev,
306 "failed to power on AHCI controller: %d\n", ret);
307 return ret;
311 * Program the following SATA IPFS registers to allow SW accesses to
312 * SATA's MMIO register range.
314 val = readl(tegra->sata_regs + SATA_FPCI_BAR5);
315 val &= ~(SATA_FPCI_BAR5_START_MASK | SATA_FPCI_BAR5_ACCESS_TYPE);
316 val |= SATA_FPCI_BAR5_START | SATA_FPCI_BAR5_ACCESS_TYPE;
317 writel(val, tegra->sata_regs + SATA_FPCI_BAR5);
319 /* Program the following SATA IPFS register to enable the SATA */
320 val = readl(tegra->sata_regs + SATA_CONFIGURATION_0);
321 val |= SATA_CONFIGURATION_0_EN_FPCI;
322 writel(val, tegra->sata_regs + SATA_CONFIGURATION_0);
324 /* Electrical settings for better link stability */
325 val = T_SATA0_CHX_PHY_CTRL17_0_RX_EQ_CTRL_L_GEN1;
326 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL17_0);
327 val = T_SATA0_CHX_PHY_CTRL18_0_RX_EQ_CTRL_L_GEN2;
328 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL18_0);
329 val = T_SATA0_CHX_PHY_CTRL20_0_RX_EQ_CTRL_H_GEN1;
330 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL20_0);
331 val = T_SATA0_CHX_PHY_CTRL21_0_RX_EQ_CTRL_H_GEN2;
332 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL21_0);
334 /* For SQUELCH Filter & Gen3 drive getting detected as Gen1 drive */
336 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA_CFG_PHY_0);
337 val |= T_SATA_CFG_PHY_0_MASK_SQUELCH;
338 val &= ~T_SATA_CFG_PHY_0_USE_7BIT_ALIGN_DET_FOR_SPD;
339 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA_CFG_PHY_0);
341 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_NVOOB);
342 val &= ~(T_SATA0_NVOOB_COMMA_CNT_MASK |
343 T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH_MASK |
344 T_SATA0_NVOOB_SQUELCH_FILTER_MODE_MASK);
345 val |= (T_SATA0_NVOOB_COMMA_CNT |
346 T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH |
347 T_SATA0_NVOOB_SQUELCH_FILTER_MODE);
348 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_NVOOB);
351 * Change CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW from 83.3 ns to 58.8ns
353 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG2NVOOB_2);
354 val &= ~T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW_MASK;
355 val |= T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW;
356 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG2NVOOB_2);
358 if (tegra->soc->ops && tegra->soc->ops->init)
359 tegra->soc->ops->init(hpriv);
362 * Program the following SATA configuration registers to
363 * initialize SATA
365 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_1);
366 val |= (T_SATA0_CFG_1_IO_SPACE | T_SATA0_CFG_1_MEMORY_SPACE |
367 T_SATA0_CFG_1_BUS_MASTER | T_SATA0_CFG_1_SERR);
368 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_1);
369 val = T_SATA0_CFG_9_BASE_ADDRESS;
370 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_9);
372 /* Program Class Code and Programming interface for SATA */
373 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
374 val |= T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN;
375 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
377 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_BKDOOR_CC);
378 val &=
379 ~(T_SATA0_BKDOOR_CC_CLASS_CODE_MASK |
380 T_SATA0_BKDOOR_CC_PROG_IF_MASK);
381 val |= T_SATA0_BKDOOR_CC_CLASS_CODE | T_SATA0_BKDOOR_CC_PROG_IF;
382 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_BKDOOR_CC);
384 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
385 val &= ~T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN;
386 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_SATA);
388 /* Enabling LPM capabilities through Backdoor Programming */
389 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_AHCI_HBA_CAP_BKDR);
390 val |= (T_SATA0_AHCI_HBA_CAP_BKDR_PARTIAL_ST_CAP |
391 T_SATA0_AHCI_HBA_CAP_BKDR_SLUMBER_ST_CAP |
392 T_SATA0_AHCI_HBA_CAP_BKDR_SALP |
393 T_SATA0_AHCI_HBA_CAP_BKDR_SUPP_PM);
394 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_AHCI_HBA_CAP_BKDR);
396 /* SATA Second Level Clock Gating configuration
397 * Enabling Gating of Tx/Rx clocks and driving Pad IDDQ and Lane
398 * IDDQ Signals
400 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_35);
401 val &= ~T_SATA0_CFG_35_IDP_INDEX_MASK;
402 val |= T_SATA0_CFG_35_IDP_INDEX;
403 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_35);
405 val = T_SATA0_AHCI_IDP1_DATA;
406 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_AHCI_IDP1);
408 val = readl(tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_PHY_1);
409 val |= (T_SATA0_CFG_PHY_1_PADS_IDDQ_EN |
410 T_SATA0_CFG_PHY_1_PAD_PLL_IDDQ_EN);
411 writel(val, tegra->sata_regs + SCFG_OFFSET + T_SATA0_CFG_PHY_1);
413 /* Enabling IPFS Clock Gating */
414 val = readl(tegra->sata_regs + SATA_CONFIGURATION_0);
415 val &= ~SATA_CONFIGURATION_0_CLK_OVERRIDE;
416 writel(val, tegra->sata_regs + SATA_CONFIGURATION_0);
418 tegra_ahci_handle_quirks(hpriv);
420 /* Unmask SATA interrupts */
422 val = readl(tegra->sata_regs + SATA_INTR_MASK);
423 val |= SATA_INTR_MASK_IP_INT_MASK;
424 writel(val, tegra->sata_regs + SATA_INTR_MASK);
426 return 0;
429 static void tegra_ahci_controller_deinit(struct ahci_host_priv *hpriv)
431 tegra_ahci_power_off(hpriv);
434 static void tegra_ahci_host_stop(struct ata_host *host)
436 struct ahci_host_priv *hpriv = host->private_data;
438 tegra_ahci_controller_deinit(hpriv);
441 static struct ata_port_operations ahci_tegra_port_ops = {
442 .inherits = &ahci_ops,
443 .host_stop = tegra_ahci_host_stop,
446 static const struct ata_port_info ahci_tegra_port_info = {
447 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NO_DIPM,
448 .pio_mask = ATA_PIO4,
449 .udma_mask = ATA_UDMA6,
450 .port_ops = &ahci_tegra_port_ops,
453 static const char *const tegra124_supply_names[] = {
454 "avdd", "hvdd", "vddio", "target-5v", "target-12v"
457 static const struct tegra_ahci_ops tegra124_ahci_ops = {
458 .init = tegra124_ahci_init,
461 static const struct tegra_ahci_soc tegra124_ahci_soc = {
462 .supply_names = tegra124_supply_names,
463 .num_supplies = ARRAY_SIZE(tegra124_supply_names),
464 .supports_devslp = false,
465 .ops = &tegra124_ahci_ops,
468 static const struct tegra_ahci_soc tegra210_ahci_soc = {
469 .supports_devslp = false,
472 static const struct of_device_id tegra_ahci_of_match[] = {
474 .compatible = "nvidia,tegra124-ahci",
475 .data = &tegra124_ahci_soc
478 .compatible = "nvidia,tegra210-ahci",
479 .data = &tegra210_ahci_soc
483 MODULE_DEVICE_TABLE(of, tegra_ahci_of_match);
485 static struct scsi_host_template ahci_platform_sht = {
486 AHCI_SHT(DRV_NAME),
489 static int tegra_ahci_probe(struct platform_device *pdev)
491 struct ahci_host_priv *hpriv;
492 struct tegra_ahci_priv *tegra;
493 struct resource *res;
494 int ret;
495 unsigned int i;
497 hpriv = ahci_platform_get_resources(pdev);
498 if (IS_ERR(hpriv))
499 return PTR_ERR(hpriv);
501 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
502 if (!tegra)
503 return -ENOMEM;
505 hpriv->plat_data = tegra;
507 tegra->pdev = pdev;
508 tegra->soc = of_device_get_match_data(&pdev->dev);
510 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
511 tegra->sata_regs = devm_ioremap_resource(&pdev->dev, res);
512 if (IS_ERR(tegra->sata_regs))
513 return PTR_ERR(tegra->sata_regs);
516 * AUX registers is optional.
518 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
519 if (res) {
520 tegra->sata_aux_regs = devm_ioremap_resource(&pdev->dev, res);
521 if (IS_ERR(tegra->sata_aux_regs))
522 return PTR_ERR(tegra->sata_aux_regs);
525 tegra->sata_rst = devm_reset_control_get(&pdev->dev, "sata");
526 if (IS_ERR(tegra->sata_rst)) {
527 dev_err(&pdev->dev, "Failed to get sata reset\n");
528 return PTR_ERR(tegra->sata_rst);
531 tegra->sata_oob_rst = devm_reset_control_get(&pdev->dev, "sata-oob");
532 if (IS_ERR(tegra->sata_oob_rst)) {
533 dev_err(&pdev->dev, "Failed to get sata-oob reset\n");
534 return PTR_ERR(tegra->sata_oob_rst);
537 tegra->sata_cold_rst = devm_reset_control_get(&pdev->dev, "sata-cold");
538 if (IS_ERR(tegra->sata_cold_rst)) {
539 dev_err(&pdev->dev, "Failed to get sata-cold reset\n");
540 return PTR_ERR(tegra->sata_cold_rst);
543 tegra->sata_clk = devm_clk_get(&pdev->dev, "sata");
544 if (IS_ERR(tegra->sata_clk)) {
545 dev_err(&pdev->dev, "Failed to get sata clock\n");
546 return PTR_ERR(tegra->sata_clk);
549 tegra->supplies = devm_kcalloc(&pdev->dev,
550 tegra->soc->num_supplies,
551 sizeof(*tegra->supplies), GFP_KERNEL);
552 if (!tegra->supplies)
553 return -ENOMEM;
555 for (i = 0; i < tegra->soc->num_supplies; i++)
556 tegra->supplies[i].supply = tegra->soc->supply_names[i];
558 ret = devm_regulator_bulk_get(&pdev->dev,
559 tegra->soc->num_supplies,
560 tegra->supplies);
561 if (ret) {
562 dev_err(&pdev->dev, "Failed to get regulators\n");
563 return ret;
566 ret = tegra_ahci_controller_init(hpriv);
567 if (ret)
568 return ret;
570 ret = ahci_platform_init_host(pdev, hpriv, &ahci_tegra_port_info,
571 &ahci_platform_sht);
572 if (ret)
573 goto deinit_controller;
575 return 0;
577 deinit_controller:
578 tegra_ahci_controller_deinit(hpriv);
580 return ret;
583 static struct platform_driver tegra_ahci_driver = {
584 .probe = tegra_ahci_probe,
585 .remove = ata_platform_remove_one,
586 .driver = {
587 .name = DRV_NAME,
588 .of_match_table = tegra_ahci_of_match,
590 /* LP0 suspend support not implemented */
592 module_platform_driver(tegra_ahci_driver);
594 MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
595 MODULE_DESCRIPTION("Tegra AHCI SATA driver");
596 MODULE_LICENSE("GPL v2");