1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/ata/ahci_tegra.c
5 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
8 * Mikko Perttunen <mperttunen@nvidia.com>
11 #include <linux/ahci_platform.h>
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/consumer.h>
18 #include <linux/reset.h>
20 #include <soc/tegra/fuse.h>
21 #include <soc/tegra/pmc.h>
25 #define DRV_NAME "tegra-ahci"
27 #define SATA_CONFIGURATION_0 0x180
28 #define SATA_CONFIGURATION_0_EN_FPCI BIT(0)
29 #define SATA_CONFIGURATION_0_CLK_OVERRIDE BIT(31)
31 #define SCFG_OFFSET 0x1000
33 #define T_SATA0_CFG_1 0x04
34 #define T_SATA0_CFG_1_IO_SPACE BIT(0)
35 #define T_SATA0_CFG_1_MEMORY_SPACE BIT(1)
36 #define T_SATA0_CFG_1_BUS_MASTER BIT(2)
37 #define T_SATA0_CFG_1_SERR BIT(8)
39 #define T_SATA0_CFG_9 0x24
40 #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)
47 #define SATA_INTR_MASK 0x188
48 #define SATA_INTR_MASK_IP_INT_MASK BIT(16)
50 #define T_SATA0_CFG_35 0x94
51 #define T_SATA0_CFG_35_IDP_INDEX_MASK (0x7ff << 2)
52 #define T_SATA0_CFG_35_IDP_INDEX (0x2a << 2)
54 #define T_SATA0_AHCI_IDP1 0x98
55 #define T_SATA0_AHCI_IDP1_DATA (0x400040)
57 #define T_SATA0_CFG_PHY_1 0x12c
58 #define T_SATA0_CFG_PHY_1_PADS_IDDQ_EN BIT(23)
59 #define T_SATA0_CFG_PHY_1_PAD_PLL_IDDQ_EN BIT(22)
61 #define T_SATA0_NVOOB 0x114
62 #define T_SATA0_NVOOB_SQUELCH_FILTER_MODE_MASK (0x3 << 24)
63 #define T_SATA0_NVOOB_SQUELCH_FILTER_MODE (0x1 << 24)
64 #define T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH_MASK (0x3 << 26)
65 #define T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH (0x3 << 26)
67 #define T_SATA_CFG_PHY_0 0x120
68 #define T_SATA_CFG_PHY_0_USE_7BIT_ALIGN_DET_FOR_SPD BIT(11)
69 #define T_SATA_CFG_PHY_0_MASK_SQUELCH BIT(24)
71 #define T_SATA0_CFG2NVOOB_2 0x134
72 #define T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW_MASK (0x1ff << 18)
73 #define T_SATA0_CFG2NVOOB_2_COMWAKE_IDLE_CNT_LOW (0xc << 18)
75 #define T_SATA0_AHCI_HBA_CAP_BKDR 0x300
76 #define T_SATA0_AHCI_HBA_CAP_BKDR_PARTIAL_ST_CAP BIT(13)
77 #define T_SATA0_AHCI_HBA_CAP_BKDR_SLUMBER_ST_CAP BIT(14)
78 #define T_SATA0_AHCI_HBA_CAP_BKDR_SALP BIT(26)
79 #define T_SATA0_AHCI_HBA_CAP_BKDR_SUPP_PM BIT(17)
80 #define T_SATA0_AHCI_HBA_CAP_BKDR_SNCQ BIT(30)
82 #define T_SATA0_BKDOOR_CC 0x4a4
83 #define T_SATA0_BKDOOR_CC_CLASS_CODE_MASK (0xffff << 16)
84 #define T_SATA0_BKDOOR_CC_CLASS_CODE (0x0106 << 16)
85 #define T_SATA0_BKDOOR_CC_PROG_IF_MASK (0xff << 8)
86 #define T_SATA0_BKDOOR_CC_PROG_IF (0x01 << 8)
88 #define T_SATA0_CFG_SATA 0x54c
89 #define T_SATA0_CFG_SATA_BACKDOOR_PROG_IF_EN BIT(12)
91 #define T_SATA0_CFG_MISC 0x550
93 #define T_SATA0_INDEX 0x680
95 #define T_SATA0_CHX_PHY_CTRL1_GEN1 0x690
96 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_MASK 0xff
97 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT 0
98 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_MASK (0xff << 8)
99 #define T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT 8
101 #define T_SATA0_CHX_PHY_CTRL1_GEN2 0x694
102 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_MASK 0xff
103 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_SHIFT 0
104 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_MASK (0xff << 12)
105 #define T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_SHIFT 12
107 #define T_SATA0_CHX_PHY_CTRL2 0x69c
108 #define T_SATA0_CHX_PHY_CTRL2_CDR_CNTL_GEN1 0x23
110 #define T_SATA0_CHX_PHY_CTRL11 0x6d0
111 #define T_SATA0_CHX_PHY_CTRL11_GEN2_RX_EQ (0x2800 << 16)
113 #define T_SATA0_CHX_PHY_CTRL17_0 0x6e8
114 #define T_SATA0_CHX_PHY_CTRL17_0_RX_EQ_CTRL_L_GEN1 0x55010000
115 #define T_SATA0_CHX_PHY_CTRL18_0 0x6ec
116 #define T_SATA0_CHX_PHY_CTRL18_0_RX_EQ_CTRL_L_GEN2 0x55010000
117 #define T_SATA0_CHX_PHY_CTRL20_0 0x6f4
118 #define T_SATA0_CHX_PHY_CTRL20_0_RX_EQ_CTRL_H_GEN1 0x1
119 #define T_SATA0_CHX_PHY_CTRL21_0 0x6f8
120 #define T_SATA0_CHX_PHY_CTRL21_0_RX_EQ_CTRL_H_GEN2 0x1
123 #define SATA_AUX_MISC_CNTL_1_0 0x8
124 #define SATA_AUX_MISC_CNTL_1_0_DEVSLP_OVERRIDE BIT(17)
125 #define SATA_AUX_MISC_CNTL_1_0_SDS_SUPPORT BIT(13)
126 #define SATA_AUX_MISC_CNTL_1_0_DESO_SUPPORT BIT(15)
128 #define SATA_AUX_RX_STAT_INT_0 0xc
129 #define SATA_AUX_RX_STAT_INT_0_SATA_DEVSLP BIT(7)
131 #define SATA_AUX_SPARE_CFG0_0 0x18
132 #define SATA_AUX_SPARE_CFG0_0_MDAT_TIMER_AFTER_PG_VALID BIT(14)
134 #define FUSE_SATA_CALIB 0x124
135 #define FUSE_SATA_CALIB_MASK 0x3
137 struct sata_pad_calibration {
144 static const struct sata_pad_calibration tegra124_pad_calibration[] = {
145 {0x18, 0x04, 0x18, 0x0a},
146 {0x0e, 0x04, 0x14, 0x0a},
147 {0x0e, 0x07, 0x1a, 0x0e},
148 {0x14, 0x0e, 0x1a, 0x0e},
151 struct tegra_ahci_ops {
152 int (*init)(struct ahci_host_priv *hpriv);
155 struct tegra_ahci_regs {
156 unsigned int nvoob_comma_cnt_mask;
157 unsigned int nvoob_comma_cnt_val;
160 struct tegra_ahci_soc {
161 const char *const *supply_names;
163 bool supports_devslp;
164 bool has_sata_oob_rst;
165 const struct tegra_ahci_ops *ops;
166 const struct tegra_ahci_regs *regs;
169 struct tegra_ahci_priv {
170 struct platform_device *pdev;
171 void __iomem *sata_regs;
172 void __iomem *sata_aux_regs;
173 struct reset_control *sata_rst;
174 struct reset_control *sata_oob_rst;
175 struct reset_control *sata_cold_rst;
176 /* Needs special handling, cannot use ahci_platform */
177 struct clk *sata_clk;
178 struct regulator_bulk_data *supplies;
179 const struct tegra_ahci_soc *soc;
182 static void tegra_ahci_handle_quirks(struct ahci_host_priv *hpriv)
184 struct tegra_ahci_priv *tegra = hpriv->plat_data;
187 if (tegra->sata_aux_regs && !tegra->soc->supports_devslp) {
188 val = readl(tegra->sata_aux_regs + SATA_AUX_MISC_CNTL_1_0);
189 val &= ~SATA_AUX_MISC_CNTL_1_0_SDS_SUPPORT;
190 writel(val, tegra->sata_aux_regs + SATA_AUX_MISC_CNTL_1_0);
194 static int tegra124_ahci_init(struct ahci_host_priv *hpriv)
196 struct tegra_ahci_priv *tegra = hpriv->plat_data;
197 struct sata_pad_calibration calib;
201 /* Pad calibration */
202 ret = tegra_fuse_readl(FUSE_SATA_CALIB, &val);
206 calib = tegra124_pad_calibration[val & FUSE_SATA_CALIB_MASK];
208 writel(BIT(0), tegra->sata_regs + SCFG_OFFSET + T_SATA0_INDEX);
210 val = readl(tegra->sata_regs +
211 SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL1_GEN1);
212 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_MASK;
213 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_MASK;
214 val |= calib.gen1_tx_amp << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT;
215 val |= calib.gen1_tx_peak << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT;
216 writel(val, tegra->sata_regs + SCFG_OFFSET +
217 T_SATA0_CHX_PHY_CTRL1_GEN1);
219 val = readl(tegra->sata_regs +
220 SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL1_GEN2);
221 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN2_TX_AMP_MASK;
222 val &= ~T_SATA0_CHX_PHY_CTRL1_GEN2_TX_PEAK_MASK;
223 val |= calib.gen2_tx_amp << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_AMP_SHIFT;
224 val |= calib.gen2_tx_peak << T_SATA0_CHX_PHY_CTRL1_GEN1_TX_PEAK_SHIFT;
225 writel(val, tegra->sata_regs + SCFG_OFFSET +
226 T_SATA0_CHX_PHY_CTRL1_GEN2);
228 writel(T_SATA0_CHX_PHY_CTRL11_GEN2_RX_EQ,
229 tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL11);
230 writel(T_SATA0_CHX_PHY_CTRL2_CDR_CNTL_GEN1,
231 tegra->sata_regs + SCFG_OFFSET + T_SATA0_CHX_PHY_CTRL2);
233 writel(0, tegra->sata_regs + SCFG_OFFSET + T_SATA0_INDEX);
238 static int tegra_ahci_power_on(struct ahci_host_priv *hpriv)
240 struct tegra_ahci_priv *tegra = hpriv->plat_data;
243 ret = regulator_bulk_enable(tegra->soc->num_supplies,
248 if (!tegra->pdev->dev.pm_domain) {
249 ret = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_SATA,
253 goto disable_regulators;
256 reset_control_assert(tegra->sata_oob_rst);
257 reset_control_assert(tegra->sata_cold_rst);
259 ret = ahci_platform_enable_resources(hpriv);
263 reset_control_deassert(tegra->sata_cold_rst);
264 reset_control_deassert(tegra->sata_oob_rst);
269 clk_disable_unprepare(tegra->sata_clk);
271 if (!tegra->pdev->dev.pm_domain)
272 tegra_powergate_power_off(TEGRA_POWERGATE_SATA);
275 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies);
280 static void tegra_ahci_power_off(struct ahci_host_priv *hpriv)
282 struct tegra_ahci_priv *tegra = hpriv->plat_data;
284 ahci_platform_disable_resources(hpriv);
286 reset_control_assert(tegra->sata_rst);
287 reset_control_assert(tegra->sata_oob_rst);
288 reset_control_assert(tegra->sata_cold_rst);
290 clk_disable_unprepare(tegra->sata_clk);
291 if (!tegra->pdev->dev.pm_domain)
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;
303 ret = tegra_ahci_power_on(hpriv);
305 dev_err(&tegra->pdev->dev,
306 "failed to power on AHCI controller: %d\n", 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 &= ~(tegra->soc->regs->nvoob_comma_cnt_mask |
343 T_SATA0_NVOOB_SQUELCH_FILTER_LENGTH_MASK |
344 T_SATA0_NVOOB_SQUELCH_FILTER_MODE_MASK);
345 val |= (tegra->soc->regs->nvoob_comma_cnt_val |
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
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);
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
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);
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_regs tegra124_ahci_regs = {
462 .nvoob_comma_cnt_mask = GENMASK(30, 28),
463 .nvoob_comma_cnt_val = (7 << 28),
466 static const struct tegra_ahci_soc tegra124_ahci_soc = {
467 .supply_names = tegra124_supply_names,
468 .num_supplies = ARRAY_SIZE(tegra124_supply_names),
469 .supports_devslp = false,
470 .has_sata_oob_rst = true,
471 .ops = &tegra124_ahci_ops,
472 .regs = &tegra124_ahci_regs,
475 static const struct tegra_ahci_soc tegra210_ahci_soc = {
476 .supports_devslp = false,
477 .has_sata_oob_rst = true,
478 .regs = &tegra124_ahci_regs,
481 static const struct tegra_ahci_regs tegra186_ahci_regs = {
482 .nvoob_comma_cnt_mask = GENMASK(23, 16),
483 .nvoob_comma_cnt_val = (7 << 16),
486 static const struct tegra_ahci_soc tegra186_ahci_soc = {
487 .supports_devslp = false,
488 .has_sata_oob_rst = false,
489 .regs = &tegra186_ahci_regs,
492 static const struct of_device_id tegra_ahci_of_match[] = {
494 .compatible = "nvidia,tegra124-ahci",
495 .data = &tegra124_ahci_soc
498 .compatible = "nvidia,tegra210-ahci",
499 .data = &tegra210_ahci_soc
502 .compatible = "nvidia,tegra186-ahci",
503 .data = &tegra186_ahci_soc
507 MODULE_DEVICE_TABLE(of, tegra_ahci_of_match);
509 static struct scsi_host_template ahci_platform_sht = {
513 static int tegra_ahci_probe(struct platform_device *pdev)
515 struct ahci_host_priv *hpriv;
516 struct tegra_ahci_priv *tegra;
517 struct resource *res;
520 hpriv = ahci_platform_get_resources(pdev, 0);
522 return PTR_ERR(hpriv);
524 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
528 hpriv->plat_data = tegra;
531 tegra->soc = of_device_get_match_data(&pdev->dev);
533 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
534 tegra->sata_regs = devm_ioremap_resource(&pdev->dev, res);
535 if (IS_ERR(tegra->sata_regs))
536 return PTR_ERR(tegra->sata_regs);
539 * AUX registers is optional.
541 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
543 tegra->sata_aux_regs = devm_ioremap_resource(&pdev->dev, res);
544 if (IS_ERR(tegra->sata_aux_regs))
545 return PTR_ERR(tegra->sata_aux_regs);
548 tegra->sata_rst = devm_reset_control_get(&pdev->dev, "sata");
549 if (IS_ERR(tegra->sata_rst)) {
550 dev_err(&pdev->dev, "Failed to get sata reset\n");
551 return PTR_ERR(tegra->sata_rst);
554 if (tegra->soc->has_sata_oob_rst) {
555 tegra->sata_oob_rst = devm_reset_control_get(&pdev->dev,
557 if (IS_ERR(tegra->sata_oob_rst)) {
558 dev_err(&pdev->dev, "Failed to get sata-oob reset\n");
559 return PTR_ERR(tegra->sata_oob_rst);
563 tegra->sata_cold_rst = devm_reset_control_get(&pdev->dev, "sata-cold");
564 if (IS_ERR(tegra->sata_cold_rst)) {
565 dev_err(&pdev->dev, "Failed to get sata-cold reset\n");
566 return PTR_ERR(tegra->sata_cold_rst);
569 tegra->sata_clk = devm_clk_get(&pdev->dev, "sata");
570 if (IS_ERR(tegra->sata_clk)) {
571 dev_err(&pdev->dev, "Failed to get sata clock\n");
572 return PTR_ERR(tegra->sata_clk);
575 tegra->supplies = devm_kcalloc(&pdev->dev,
576 tegra->soc->num_supplies,
577 sizeof(*tegra->supplies), GFP_KERNEL);
578 if (!tegra->supplies)
581 regulator_bulk_set_supply_names(tegra->supplies,
582 tegra->soc->supply_names,
583 tegra->soc->num_supplies);
585 ret = devm_regulator_bulk_get(&pdev->dev,
586 tegra->soc->num_supplies,
589 dev_err(&pdev->dev, "Failed to get regulators\n");
593 ret = tegra_ahci_controller_init(hpriv);
597 ret = ahci_platform_init_host(pdev, hpriv, &ahci_tegra_port_info,
600 goto deinit_controller;
605 tegra_ahci_controller_deinit(hpriv);
610 static struct platform_driver tegra_ahci_driver = {
611 .probe = tegra_ahci_probe,
612 .remove = ata_platform_remove_one,
615 .of_match_table = tegra_ahci_of_match,
617 /* LP0 suspend support not implemented */
619 module_platform_driver(tegra_ahci_driver);
621 MODULE_AUTHOR("Mikko Perttunen <mperttunen@nvidia.com>");
622 MODULE_DESCRIPTION("Tegra AHCI SATA driver");
623 MODULE_LICENSE("GPL v2");