aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/ahci_imx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/ahci_imx.c')
-rw-r--r--drivers/ata/ahci_imx.c242
1 files changed, 157 insertions, 85 deletions
diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c
index 3e23e9941dad..dd4d6f74d7bd 100644
--- a/drivers/ata/ahci_imx.c
+++ b/drivers/ata/ahci_imx.c
@@ -34,10 +34,21 @@ enum {
34 HOST_TIMER1MS = 0xe0, /* Timer 1-ms */ 34 HOST_TIMER1MS = 0xe0, /* Timer 1-ms */
35}; 35};
36 36
37enum ahci_imx_type {
38 AHCI_IMX53,
39 AHCI_IMX6Q,
40};
41
37struct imx_ahci_priv { 42struct imx_ahci_priv {
38 struct platform_device *ahci_pdev; 43 struct platform_device *ahci_pdev;
44 enum ahci_imx_type type;
45
46 /* i.MX53 clock */
47 struct clk *sata_gate_clk;
48 /* Common clock */
39 struct clk *sata_ref_clk; 49 struct clk *sata_ref_clk;
40 struct clk *ahb_clk; 50 struct clk *ahb_clk;
51
41 struct regmap *gpr; 52 struct regmap *gpr;
42 bool no_device; 53 bool no_device;
43 bool first_time; 54 bool first_time;
@@ -47,6 +58,59 @@ static int ahci_imx_hotplug;
47module_param_named(hotplug, ahci_imx_hotplug, int, 0644); 58module_param_named(hotplug, ahci_imx_hotplug, int, 0644);
48MODULE_PARM_DESC(hotplug, "AHCI IMX hot-plug support (0=Don't support, 1=support)"); 59MODULE_PARM_DESC(hotplug, "AHCI IMX hot-plug support (0=Don't support, 1=support)");
49 60
61static int imx_sata_clock_enable(struct device *dev)
62{
63 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
64 int ret;
65
66 if (imxpriv->type == AHCI_IMX53) {
67 ret = clk_prepare_enable(imxpriv->sata_gate_clk);
68 if (ret < 0) {
69 dev_err(dev, "prepare-enable sata_gate clock err:%d\n",
70 ret);
71 return ret;
72 }
73 }
74
75 ret = clk_prepare_enable(imxpriv->sata_ref_clk);
76 if (ret < 0) {
77 dev_err(dev, "prepare-enable sata_ref clock err:%d\n",
78 ret);
79 goto clk_err;
80 }
81
82 if (imxpriv->type == AHCI_IMX6Q) {
83 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
84 IMX6Q_GPR13_SATA_MPLL_CLK_EN,
85 IMX6Q_GPR13_SATA_MPLL_CLK_EN);
86 }
87
88 usleep_range(1000, 2000);
89
90 return 0;
91
92clk_err:
93 if (imxpriv->type == AHCI_IMX53)
94 clk_disable_unprepare(imxpriv->sata_gate_clk);
95 return ret;
96}
97
98static void imx_sata_clock_disable(struct device *dev)
99{
100 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
101
102 if (imxpriv->type == AHCI_IMX6Q) {
103 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
104 IMX6Q_GPR13_SATA_MPLL_CLK_EN,
105 !IMX6Q_GPR13_SATA_MPLL_CLK_EN);
106 }
107
108 clk_disable_unprepare(imxpriv->sata_ref_clk);
109
110 if (imxpriv->type == AHCI_IMX53)
111 clk_disable_unprepare(imxpriv->sata_gate_clk);
112}
113
50static void ahci_imx_error_handler(struct ata_port *ap) 114static void ahci_imx_error_handler(struct ata_port *ap)
51{ 115{
52 u32 reg_val; 116 u32 reg_val;
@@ -72,16 +136,29 @@ static void ahci_imx_error_handler(struct ata_port *ap)
72 */ 136 */
73 reg_val = readl(mmio + PORT_PHY_CTL); 137 reg_val = readl(mmio + PORT_PHY_CTL);
74 writel(reg_val | PORT_PHY_CTL_PDDQ_LOC, mmio + PORT_PHY_CTL); 138 writel(reg_val | PORT_PHY_CTL_PDDQ_LOC, mmio + PORT_PHY_CTL);
75 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, 139 imx_sata_clock_disable(ap->dev);
76 IMX6Q_GPR13_SATA_MPLL_CLK_EN,
77 !IMX6Q_GPR13_SATA_MPLL_CLK_EN);
78 clk_disable_unprepare(imxpriv->sata_ref_clk);
79 imxpriv->no_device = true; 140 imxpriv->no_device = true;
80} 141}
81 142
143static int ahci_imx_softreset(struct ata_link *link, unsigned int *class,
144 unsigned long deadline)
145{
146 struct ata_port *ap = link->ap;
147 struct imx_ahci_priv *imxpriv = dev_get_drvdata(ap->dev->parent);
148 int ret = -EIO;
149
150 if (imxpriv->type == AHCI_IMX53)
151 ret = ahci_pmp_retry_srst_ops.softreset(link, class, deadline);
152 else if (imxpriv->type == AHCI_IMX6Q)
153 ret = ahci_ops.softreset(link, class, deadline);
154
155 return ret;
156}
157
82static struct ata_port_operations ahci_imx_ops = { 158static struct ata_port_operations ahci_imx_ops = {
83 .inherits = &ahci_platform_ops, 159 .inherits = &ahci_platform_ops,
84 .error_handler = ahci_imx_error_handler, 160 .error_handler = ahci_imx_error_handler,
161 .softreset = ahci_imx_softreset,
85}; 162};
86 163
87static const struct ata_port_info ahci_imx_port_info = { 164static const struct ata_port_info ahci_imx_port_info = {
@@ -91,52 +168,15 @@ static const struct ata_port_info ahci_imx_port_info = {
91 .port_ops = &ahci_imx_ops, 168 .port_ops = &ahci_imx_ops,
92}; 169};
93 170
94static int imx6q_sata_init(struct device *dev, void __iomem *mmio) 171static int imx_sata_init(struct device *dev, void __iomem *mmio)
95{ 172{
96 int ret = 0; 173 int ret = 0;
97 unsigned int reg_val; 174 unsigned int reg_val;
98 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent); 175 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
99 176
100 imxpriv->gpr = 177 ret = imx_sata_clock_enable(dev);
101 syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr"); 178 if (ret < 0)
102 if (IS_ERR(imxpriv->gpr)) {
103 dev_err(dev, "failed to find fsl,imx6q-iomux-gpr regmap\n");
104 return PTR_ERR(imxpriv->gpr);
105 }
106
107 ret = clk_prepare_enable(imxpriv->sata_ref_clk);
108 if (ret < 0) {
109 dev_err(dev, "prepare-enable sata_ref clock err:%d\n", ret);
110 return ret; 179 return ret;
111 }
112
113 /*
114 * set PHY Paremeters, two steps to configure the GPR13,
115 * one write for rest of parameters, mask of first write
116 * is 0x07ffffff, and the other one write for setting
117 * the mpll_clk_en.
118 */
119 regmap_update_bits(imxpriv->gpr, 0x34, IMX6Q_GPR13_SATA_RX_EQ_VAL_MASK
120 | IMX6Q_GPR13_SATA_RX_LOS_LVL_MASK
121 | IMX6Q_GPR13_SATA_RX_DPLL_MODE_MASK
122 | IMX6Q_GPR13_SATA_SPD_MODE_MASK
123 | IMX6Q_GPR13_SATA_MPLL_SS_EN
124 | IMX6Q_GPR13_SATA_TX_ATTEN_MASK
125 | IMX6Q_GPR13_SATA_TX_BOOST_MASK
126 | IMX6Q_GPR13_SATA_TX_LVL_MASK
127 | IMX6Q_GPR13_SATA_MPLL_CLK_EN
128 | IMX6Q_GPR13_SATA_TX_EDGE_RATE
129 , IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB
130 | IMX6Q_GPR13_SATA_RX_LOS_LVL_SATA2M
131 | IMX6Q_GPR13_SATA_RX_DPLL_MODE_2P_4F
132 | IMX6Q_GPR13_SATA_SPD_MODE_3P0G
133 | IMX6Q_GPR13_SATA_MPLL_SS_EN
134 | IMX6Q_GPR13_SATA_TX_ATTEN_9_16
135 | IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB
136 | IMX6Q_GPR13_SATA_TX_LVL_1_025_V);
137 regmap_update_bits(imxpriv->gpr, 0x34, IMX6Q_GPR13_SATA_MPLL_CLK_EN,
138 IMX6Q_GPR13_SATA_MPLL_CLK_EN);
139 usleep_range(100, 200);
140 180
141 /* 181 /*
142 * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL, 182 * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL,
@@ -162,13 +202,9 @@ static int imx6q_sata_init(struct device *dev, void __iomem *mmio)
162 return 0; 202 return 0;
163} 203}
164 204
165static void imx6q_sata_exit(struct device *dev) 205static void imx_sata_exit(struct device *dev)
166{ 206{
167 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent); 207 imx_sata_clock_disable(dev);
168
169 regmap_update_bits(imxpriv->gpr, 0x34, IMX6Q_GPR13_SATA_MPLL_CLK_EN,
170 !IMX6Q_GPR13_SATA_MPLL_CLK_EN);
171 clk_disable_unprepare(imxpriv->sata_ref_clk);
172} 208}
173 209
174static int imx_ahci_suspend(struct device *dev) 210static int imx_ahci_suspend(struct device *dev)
@@ -179,12 +215,8 @@ static int imx_ahci_suspend(struct device *dev)
179 * If no_device is set, The CLKs had been gated off in the 215 * If no_device is set, The CLKs had been gated off in the
180 * initialization so don't do it again here. 216 * initialization so don't do it again here.
181 */ 217 */
182 if (!imxpriv->no_device) { 218 if (!imxpriv->no_device)
183 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, 219 imx_sata_clock_disable(dev);
184 IMX6Q_GPR13_SATA_MPLL_CLK_EN,
185 !IMX6Q_GPR13_SATA_MPLL_CLK_EN);
186 clk_disable_unprepare(imxpriv->sata_ref_clk);
187 }
188 220
189 return 0; 221 return 0;
190} 222}
@@ -192,34 +224,26 @@ static int imx_ahci_suspend(struct device *dev)
192static int imx_ahci_resume(struct device *dev) 224static int imx_ahci_resume(struct device *dev)
193{ 225{
194 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent); 226 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
195 int ret; 227 int ret = 0;
196
197 if (!imxpriv->no_device) {
198 ret = clk_prepare_enable(imxpriv->sata_ref_clk);
199 if (ret < 0) {
200 dev_err(dev, "pre-enable sata_ref clock err:%d\n", ret);
201 return ret;
202 }
203 228
204 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, 229 if (!imxpriv->no_device)
205 IMX6Q_GPR13_SATA_MPLL_CLK_EN, 230 ret = imx_sata_clock_enable(dev);
206 IMX6Q_GPR13_SATA_MPLL_CLK_EN);
207 usleep_range(1000, 2000);
208 }
209 231
210 return 0; 232 return ret;
211} 233}
212 234
213static struct ahci_platform_data imx6q_sata_pdata = { 235static struct ahci_platform_data imx_sata_pdata = {
214 .init = imx6q_sata_init, 236 .init = imx_sata_init,
215 .exit = imx6q_sata_exit, 237 .exit = imx_sata_exit,
216 .ata_port_info = &ahci_imx_port_info, 238 .ata_port_info = &ahci_imx_port_info,
217 .suspend = imx_ahci_suspend, 239 .suspend = imx_ahci_suspend,
218 .resume = imx_ahci_resume, 240 .resume = imx_ahci_resume,
241
219}; 242};
220 243
221static const struct of_device_id imx_ahci_of_match[] = { 244static const struct of_device_id imx_ahci_of_match[] = {
222 { .compatible = "fsl,imx6q-ahci", .data = &imx6q_sata_pdata}, 245 { .compatible = "fsl,imx53-ahci", .data = (void *)AHCI_IMX53 },
246 { .compatible = "fsl,imx6q-ahci", .data = (void *)AHCI_IMX6Q },
223 {}, 247 {},
224}; 248};
225MODULE_DEVICE_TABLE(of, imx_ahci_of_match); 249MODULE_DEVICE_TABLE(of, imx_ahci_of_match);
@@ -229,12 +253,20 @@ static int imx_ahci_probe(struct platform_device *pdev)
229 struct device *dev = &pdev->dev; 253 struct device *dev = &pdev->dev;
230 struct resource *mem, *irq, res[2]; 254 struct resource *mem, *irq, res[2];
231 const struct of_device_id *of_id; 255 const struct of_device_id *of_id;
256 enum ahci_imx_type type;
232 const struct ahci_platform_data *pdata = NULL; 257 const struct ahci_platform_data *pdata = NULL;
233 struct imx_ahci_priv *imxpriv; 258 struct imx_ahci_priv *imxpriv;
234 struct device *ahci_dev; 259 struct device *ahci_dev;
235 struct platform_device *ahci_pdev; 260 struct platform_device *ahci_pdev;
236 int ret; 261 int ret;
237 262
263 of_id = of_match_device(imx_ahci_of_match, dev);
264 if (!of_id)
265 return -EINVAL;
266
267 type = (enum ahci_imx_type)of_id->data;
268 pdata = &imx_sata_pdata;
269
238 imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL); 270 imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL);
239 if (!imxpriv) { 271 if (!imxpriv) {
240 dev_err(dev, "can't alloc ahci_host_priv\n"); 272 dev_err(dev, "can't alloc ahci_host_priv\n");
@@ -250,6 +282,8 @@ static int imx_ahci_probe(struct platform_device *pdev)
250 282
251 imxpriv->no_device = false; 283 imxpriv->no_device = false;
252 imxpriv->first_time = true; 284 imxpriv->first_time = true;
285 imxpriv->type = type;
286
253 imxpriv->ahb_clk = devm_clk_get(dev, "ahb"); 287 imxpriv->ahb_clk = devm_clk_get(dev, "ahb");
254 if (IS_ERR(imxpriv->ahb_clk)) { 288 if (IS_ERR(imxpriv->ahb_clk)) {
255 dev_err(dev, "can't get ahb clock.\n"); 289 dev_err(dev, "can't get ahb clock.\n");
@@ -257,6 +291,15 @@ static int imx_ahci_probe(struct platform_device *pdev)
257 goto err_out; 291 goto err_out;
258 } 292 }
259 293
294 if (type == AHCI_IMX53) {
295 imxpriv->sata_gate_clk = devm_clk_get(dev, "sata_gate");
296 if (IS_ERR(imxpriv->sata_gate_clk)) {
297 dev_err(dev, "can't get sata_gate clock.\n");
298 ret = PTR_ERR(imxpriv->sata_gate_clk);
299 goto err_out;
300 }
301 }
302
260 imxpriv->sata_ref_clk = devm_clk_get(dev, "sata_ref"); 303 imxpriv->sata_ref_clk = devm_clk_get(dev, "sata_ref");
261 if (IS_ERR(imxpriv->sata_ref_clk)) { 304 if (IS_ERR(imxpriv->sata_ref_clk)) {
262 dev_err(dev, "can't get sata_ref clock.\n"); 305 dev_err(dev, "can't get sata_ref clock.\n");
@@ -267,14 +310,6 @@ static int imx_ahci_probe(struct platform_device *pdev)
267 imxpriv->ahci_pdev = ahci_pdev; 310 imxpriv->ahci_pdev = ahci_pdev;
268 platform_set_drvdata(pdev, imxpriv); 311 platform_set_drvdata(pdev, imxpriv);
269 312
270 of_id = of_match_device(imx_ahci_of_match, dev);
271 if (of_id) {
272 pdata = of_id->data;
273 } else {
274 ret = -EINVAL;
275 goto err_out;
276 }
277
278 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 313 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
279 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 314 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
280 if (!mem || !irq) { 315 if (!mem || !irq) {
@@ -290,6 +325,43 @@ static int imx_ahci_probe(struct platform_device *pdev)
290 ahci_dev->dma_mask = &ahci_dev->coherent_dma_mask; 325 ahci_dev->dma_mask = &ahci_dev->coherent_dma_mask;
291 ahci_dev->of_node = dev->of_node; 326 ahci_dev->of_node = dev->of_node;
292 327
328 if (type == AHCI_IMX6Q) {
329 imxpriv->gpr = syscon_regmap_lookup_by_compatible(
330 "fsl,imx6q-iomuxc-gpr");
331 if (IS_ERR(imxpriv->gpr)) {
332 dev_err(dev,
333 "failed to find fsl,imx6q-iomux-gpr regmap\n");
334 ret = PTR_ERR(imxpriv->gpr);
335 goto err_out;
336 }
337
338 /*
339 * Set PHY Paremeters, two steps to configure the GPR13,
340 * one write for rest of parameters, mask of first write
341 * is 0x07fffffe, and the other one write for setting
342 * the mpll_clk_en happens in imx_sata_clock_enable().
343 */
344 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
345 IMX6Q_GPR13_SATA_RX_EQ_VAL_MASK |
346 IMX6Q_GPR13_SATA_RX_LOS_LVL_MASK |
347 IMX6Q_GPR13_SATA_RX_DPLL_MODE_MASK |
348 IMX6Q_GPR13_SATA_SPD_MODE_MASK |
349 IMX6Q_GPR13_SATA_MPLL_SS_EN |
350 IMX6Q_GPR13_SATA_TX_ATTEN_MASK |
351 IMX6Q_GPR13_SATA_TX_BOOST_MASK |
352 IMX6Q_GPR13_SATA_TX_LVL_MASK |
353 IMX6Q_GPR13_SATA_MPLL_CLK_EN |
354 IMX6Q_GPR13_SATA_TX_EDGE_RATE,
355 IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB |
356 IMX6Q_GPR13_SATA_RX_LOS_LVL_SATA2M |
357 IMX6Q_GPR13_SATA_RX_DPLL_MODE_2P_4F |
358 IMX6Q_GPR13_SATA_SPD_MODE_3P0G |
359 IMX6Q_GPR13_SATA_MPLL_SS_EN |
360 IMX6Q_GPR13_SATA_TX_ATTEN_9_16 |
361 IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB |
362 IMX6Q_GPR13_SATA_TX_LVL_1_025_V);
363 }
364
293 ret = platform_device_add_resources(ahci_pdev, res, 2); 365 ret = platform_device_add_resources(ahci_pdev, res, 2);
294 if (ret) 366 if (ret)
295 goto err_out; 367 goto err_out;