.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Freescale QorIQ AHCI SATA platform driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2015 Freescale, Inc. |
---|
5 | 6 | * Tang Yuantian <Yuantian.Tang@freescale.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License as published by |
---|
9 | | - * the Free Software Foundation; either version 2, or (at your option) |
---|
10 | | - * any later version. |
---|
11 | 7 | */ |
---|
12 | 8 | |
---|
| 9 | +#include <linux/acpi.h> |
---|
13 | 10 | #include <linux/kernel.h> |
---|
14 | 11 | #include <linux/module.h> |
---|
15 | 12 | #include <linux/pm.h> |
---|
.. | .. |
---|
53 | 50 | |
---|
54 | 51 | enum ahci_qoriq_type { |
---|
55 | 52 | AHCI_LS1021A, |
---|
| 53 | + AHCI_LS1028A, |
---|
56 | 54 | AHCI_LS1043A, |
---|
57 | 55 | AHCI_LS2080A, |
---|
58 | 56 | AHCI_LS1046A, |
---|
59 | 57 | AHCI_LS1088A, |
---|
60 | 58 | AHCI_LS2088A, |
---|
| 59 | + AHCI_LX2160A, |
---|
61 | 60 | }; |
---|
62 | 61 | |
---|
63 | 62 | struct ahci_qoriq_priv { |
---|
.. | .. |
---|
67 | 66 | bool is_dmacoherent; |
---|
68 | 67 | }; |
---|
69 | 68 | |
---|
| 69 | +static bool ecc_initialized; |
---|
| 70 | + |
---|
70 | 71 | static const struct of_device_id ahci_qoriq_of_match[] = { |
---|
71 | 72 | { .compatible = "fsl,ls1021a-ahci", .data = (void *)AHCI_LS1021A}, |
---|
| 73 | + { .compatible = "fsl,ls1028a-ahci", .data = (void *)AHCI_LS1028A}, |
---|
72 | 74 | { .compatible = "fsl,ls1043a-ahci", .data = (void *)AHCI_LS1043A}, |
---|
73 | 75 | { .compatible = "fsl,ls2080a-ahci", .data = (void *)AHCI_LS2080A}, |
---|
74 | 76 | { .compatible = "fsl,ls1046a-ahci", .data = (void *)AHCI_LS1046A}, |
---|
75 | 77 | { .compatible = "fsl,ls1088a-ahci", .data = (void *)AHCI_LS1088A}, |
---|
76 | 78 | { .compatible = "fsl,ls2088a-ahci", .data = (void *)AHCI_LS2088A}, |
---|
| 79 | + { .compatible = "fsl,lx2160a-ahci", .data = (void *)AHCI_LX2160A}, |
---|
77 | 80 | {}, |
---|
78 | 81 | }; |
---|
79 | 82 | MODULE_DEVICE_TABLE(of, ahci_qoriq_of_match); |
---|
| 83 | + |
---|
| 84 | +static const struct acpi_device_id ahci_qoriq_acpi_match[] = { |
---|
| 85 | + {"NXP0004", .driver_data = (kernel_ulong_t)AHCI_LX2160A}, |
---|
| 86 | + { } |
---|
| 87 | +}; |
---|
| 88 | +MODULE_DEVICE_TABLE(acpi, ahci_qoriq_acpi_match); |
---|
80 | 89 | |
---|
81 | 90 | static int ahci_qoriq_hardreset(struct ata_link *link, unsigned int *class, |
---|
82 | 91 | unsigned long deadline) |
---|
.. | .. |
---|
165 | 174 | |
---|
166 | 175 | switch (qpriv->type) { |
---|
167 | 176 | case AHCI_LS1021A: |
---|
168 | | - if (!qpriv->ecc_addr) |
---|
| 177 | + if (!(qpriv->ecc_addr || ecc_initialized)) |
---|
169 | 178 | return -EINVAL; |
---|
170 | | - writel(SATA_ECC_DISABLE, qpriv->ecc_addr); |
---|
| 179 | + else if (qpriv->ecc_addr && !ecc_initialized) |
---|
| 180 | + writel(SATA_ECC_DISABLE, qpriv->ecc_addr); |
---|
171 | 181 | writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1); |
---|
172 | 182 | writel(LS1021A_PORT_PHY2, reg_base + PORT_PHY2); |
---|
173 | 183 | writel(LS1021A_PORT_PHY3, reg_base + PORT_PHY3); |
---|
.. | .. |
---|
180 | 190 | break; |
---|
181 | 191 | |
---|
182 | 192 | case AHCI_LS1043A: |
---|
183 | | - if (!qpriv->ecc_addr) |
---|
| 193 | + if (!(qpriv->ecc_addr || ecc_initialized)) |
---|
184 | 194 | return -EINVAL; |
---|
185 | | - writel(readl(qpriv->ecc_addr) | ECC_DIS_ARMV8_CH2, |
---|
186 | | - qpriv->ecc_addr); |
---|
| 195 | + else if (qpriv->ecc_addr && !ecc_initialized) |
---|
| 196 | + writel(readl(qpriv->ecc_addr) | |
---|
| 197 | + ECC_DIS_ARMV8_CH2, |
---|
| 198 | + qpriv->ecc_addr); |
---|
187 | 199 | writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1); |
---|
188 | 200 | writel(AHCI_PORT_PHY2_CFG, reg_base + PORT_PHY2); |
---|
189 | 201 | writel(AHCI_PORT_PHY3_CFG, reg_base + PORT_PHY3); |
---|
.. | .. |
---|
202 | 214 | break; |
---|
203 | 215 | |
---|
204 | 216 | case AHCI_LS1046A: |
---|
205 | | - if (!qpriv->ecc_addr) |
---|
| 217 | + if (!(qpriv->ecc_addr || ecc_initialized)) |
---|
206 | 218 | return -EINVAL; |
---|
207 | | - writel(readl(qpriv->ecc_addr) | ECC_DIS_ARMV8_CH2, |
---|
208 | | - qpriv->ecc_addr); |
---|
| 219 | + else if (qpriv->ecc_addr && !ecc_initialized) |
---|
| 220 | + writel(readl(qpriv->ecc_addr) | |
---|
| 221 | + ECC_DIS_ARMV8_CH2, |
---|
| 222 | + qpriv->ecc_addr); |
---|
209 | 223 | writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1); |
---|
210 | 224 | writel(AHCI_PORT_PHY2_CFG, reg_base + PORT_PHY2); |
---|
211 | 225 | writel(AHCI_PORT_PHY3_CFG, reg_base + PORT_PHY3); |
---|
.. | .. |
---|
214 | 228 | writel(AHCI_PORT_AXICC_CFG, reg_base + PORT_AXICC); |
---|
215 | 229 | break; |
---|
216 | 230 | |
---|
| 231 | + case AHCI_LS1028A: |
---|
217 | 232 | case AHCI_LS1088A: |
---|
218 | | - if (!qpriv->ecc_addr) |
---|
| 233 | + case AHCI_LX2160A: |
---|
| 234 | + if (!(qpriv->ecc_addr || ecc_initialized)) |
---|
219 | 235 | return -EINVAL; |
---|
220 | | - writel(readl(qpriv->ecc_addr) | ECC_DIS_LS1088A, |
---|
221 | | - qpriv->ecc_addr); |
---|
| 236 | + else if (qpriv->ecc_addr && !ecc_initialized) |
---|
| 237 | + writel(readl(qpriv->ecc_addr) | |
---|
| 238 | + ECC_DIS_LS1088A, |
---|
| 239 | + qpriv->ecc_addr); |
---|
222 | 240 | writel(AHCI_PORT_PHY_1_CFG, reg_base + PORT_PHY1); |
---|
223 | 241 | writel(AHCI_PORT_PHY2_CFG, reg_base + PORT_PHY2); |
---|
224 | 242 | writel(AHCI_PORT_PHY3_CFG, reg_base + PORT_PHY3); |
---|
.. | .. |
---|
237 | 255 | break; |
---|
238 | 256 | } |
---|
239 | 257 | |
---|
| 258 | + ecc_initialized = true; |
---|
240 | 259 | return 0; |
---|
241 | 260 | } |
---|
242 | 261 | |
---|
243 | 262 | static int ahci_qoriq_probe(struct platform_device *pdev) |
---|
244 | 263 | { |
---|
245 | 264 | struct device_node *np = pdev->dev.of_node; |
---|
| 265 | + const struct acpi_device_id *acpi_id; |
---|
246 | 266 | struct device *dev = &pdev->dev; |
---|
247 | 267 | struct ahci_host_priv *hpriv; |
---|
248 | 268 | struct ahci_qoriq_priv *qoriq_priv; |
---|
.. | .. |
---|
255 | 275 | return PTR_ERR(hpriv); |
---|
256 | 276 | |
---|
257 | 277 | of_id = of_match_node(ahci_qoriq_of_match, np); |
---|
258 | | - if (!of_id) |
---|
| 278 | + acpi_id = acpi_match_device(ahci_qoriq_acpi_match, &pdev->dev); |
---|
| 279 | + if (!(of_id || acpi_id)) |
---|
259 | 280 | return -ENODEV; |
---|
260 | 281 | |
---|
261 | 282 | qoriq_priv = devm_kzalloc(dev, sizeof(*qoriq_priv), GFP_KERNEL); |
---|
262 | 283 | if (!qoriq_priv) |
---|
263 | 284 | return -ENOMEM; |
---|
264 | 285 | |
---|
265 | | - qoriq_priv->type = (enum ahci_qoriq_type)of_id->data; |
---|
| 286 | + if (of_id) |
---|
| 287 | + qoriq_priv->type = (enum ahci_qoriq_type)of_id->data; |
---|
| 288 | + else |
---|
| 289 | + qoriq_priv->type = (enum ahci_qoriq_type)acpi_id->driver_data; |
---|
266 | 290 | |
---|
267 | | - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
---|
268 | | - "sata-ecc"); |
---|
269 | | - if (res) { |
---|
270 | | - qoriq_priv->ecc_addr = devm_ioremap_resource(dev, res); |
---|
271 | | - if (IS_ERR(qoriq_priv->ecc_addr)) |
---|
272 | | - return PTR_ERR(qoriq_priv->ecc_addr); |
---|
| 291 | + if (unlikely(!ecc_initialized)) { |
---|
| 292 | + res = platform_get_resource_byname(pdev, |
---|
| 293 | + IORESOURCE_MEM, |
---|
| 294 | + "sata-ecc"); |
---|
| 295 | + if (res) { |
---|
| 296 | + qoriq_priv->ecc_addr = |
---|
| 297 | + devm_ioremap_resource(dev, res); |
---|
| 298 | + if (IS_ERR(qoriq_priv->ecc_addr)) |
---|
| 299 | + return PTR_ERR(qoriq_priv->ecc_addr); |
---|
| 300 | + } |
---|
273 | 301 | } |
---|
274 | | - qoriq_priv->is_dmacoherent = of_dma_is_coherent(np); |
---|
| 302 | + |
---|
| 303 | + if (device_get_dma_attr(&pdev->dev) == DEV_DMA_COHERENT) |
---|
| 304 | + qoriq_priv->is_dmacoherent = true; |
---|
275 | 305 | |
---|
276 | 306 | rc = ahci_platform_enable_resources(hpriv); |
---|
277 | 307 | if (rc) |
---|
.. | .. |
---|
337 | 367 | .driver = { |
---|
338 | 368 | .name = DRV_NAME, |
---|
339 | 369 | .of_match_table = ahci_qoriq_of_match, |
---|
| 370 | + .acpi_match_table = ahci_qoriq_acpi_match, |
---|
340 | 371 | .pm = &ahci_qoriq_pm_ops, |
---|
341 | 372 | }, |
---|
342 | 373 | }; |
---|