2 * Freescale QorIQ AHCI SATA platform driver
4 * Copyright 2015 Freescale, Inc.
5 * Tang Yuantian <Yuantian.Tang@freescale.com>
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)
13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <linux/ahci_platform.h>
17 #include <linux/device.h>
18 #include <linux/of_address.h>
20 #include <linux/of_device.h>
21 #include <linux/platform_device.h>
22 #include <linux/libata.h>
25 #define DRV_NAME "ahci-qoriq"
27 /* port register definition */
28 #define PORT_PHY1 0xA8
29 #define PORT_PHY2 0xAC
30 #define PORT_PHY3 0xB0
31 #define PORT_PHY4 0xB4
32 #define PORT_PHY5 0xB8
33 #define PORT_TRANS 0xC8
35 /* port register default value */
36 #define AHCI_PORT_PHY_1_CFG 0xa003fffe
37 #define AHCI_PORT_PHY_2_CFG 0x28183411
38 #define AHCI_PORT_PHY_3_CFG 0x0e081004
39 #define AHCI_PORT_PHY_4_CFG 0x00480811
40 #define AHCI_PORT_PHY_5_CFG 0x192c96a4
41 #define AHCI_PORT_TRANS_CFG 0x08000025
43 #define SATA_ECC_DISABLE 0x00020000
45 enum ahci_qoriq_type
{
51 struct ahci_qoriq_priv
{
52 struct ccsr_ahci
*reg_base
;
53 enum ahci_qoriq_type type
;
54 void __iomem
*ecc_addr
;
57 static const struct of_device_id ahci_qoriq_of_match
[] = {
58 { .compatible
= "fsl,ls1021a-ahci", .data
= (void *)AHCI_LS1021A
},
59 { .compatible
= "fsl,ls1043a-ahci", .data
= (void *)AHCI_LS1043A
},
60 { .compatible
= "fsl,ls2085a-ahci", .data
= (void *)AHCI_LS2085A
},
63 MODULE_DEVICE_TABLE(of
, ahci_qoriq_of_match
);
65 static int ahci_qoriq_hardreset(struct ata_link
*link
, unsigned int *class,
66 unsigned long deadline
)
68 const unsigned long *timing
= sata_ehc_deb_timing(&link
->eh_context
);
69 void __iomem
*port_mmio
= ahci_port_base(link
->ap
);
70 u32 px_cmd
, px_is
, px_val
;
71 struct ata_port
*ap
= link
->ap
;
72 struct ahci_port_priv
*pp
= ap
->private_data
;
73 struct ahci_host_priv
*hpriv
= ap
->host
->private_data
;
74 struct ahci_qoriq_priv
*qoriq_priv
= hpriv
->plat_data
;
75 u8
*d2h_fis
= pp
->rx_fis
+ RX_FIS_D2H_REG
;
76 struct ata_taskfile tf
;
85 * There is a errata on ls1021a Rev1.0 and Rev2.0 which is:
86 * A-009042: The device detection initialization sequence
87 * mistakenly resets some registers.
89 * Workaround for this is:
90 * The software should read and store PxCMD and PxIS values
91 * before issuing the device detection initialization sequence.
92 * After the sequence is complete, software should restore the
93 * PxCMD and PxIS with the stored values.
95 if (qoriq_priv
->type
== AHCI_LS1021A
) {
96 px_cmd
= readl(port_mmio
+ PORT_CMD
);
97 px_is
= readl(port_mmio
+ PORT_IRQ_STAT
);
100 /* clear D2H reception area to properly wait for D2H FIS */
101 ata_tf_init(link
->device
, &tf
);
102 tf
.command
= ATA_BUSY
;
103 ata_tf_to_fis(&tf
, 0, 0, d2h_fis
);
105 rc
= sata_link_hardreset(link
, timing
, deadline
, &online
,
108 /* restore the PxCMD and PxIS on ls1021 */
109 if (qoriq_priv
->type
== AHCI_LS1021A
) {
110 px_val
= readl(port_mmio
+ PORT_CMD
);
111 if (px_val
!= px_cmd
)
112 writel(px_cmd
, port_mmio
+ PORT_CMD
);
114 px_val
= readl(port_mmio
+ PORT_IRQ_STAT
);
116 writel(px_is
, port_mmio
+ PORT_IRQ_STAT
);
119 hpriv
->start_engine(ap
);
122 *class = ahci_dev_classify(ap
);
124 DPRINTK("EXIT, rc=%d, class=%u\n", rc
, *class);
128 static struct ata_port_operations ahci_qoriq_ops
= {
129 .inherits
= &ahci_ops
,
130 .hardreset
= ahci_qoriq_hardreset
,
133 static const struct ata_port_info ahci_qoriq_port_info
= {
134 .flags
= AHCI_FLAG_COMMON
| ATA_FLAG_NCQ
,
135 .pio_mask
= ATA_PIO4
,
136 .udma_mask
= ATA_UDMA6
,
137 .port_ops
= &ahci_qoriq_ops
,
140 static struct scsi_host_template ahci_qoriq_sht
= {
144 static int ahci_qoriq_phy_init(struct ahci_host_priv
*hpriv
)
146 struct ahci_qoriq_priv
*qpriv
= hpriv
->plat_data
;
147 void __iomem
*reg_base
= hpriv
->mmio
;
149 switch (qpriv
->type
) {
151 writel(SATA_ECC_DISABLE
, qpriv
->ecc_addr
);
152 writel(AHCI_PORT_PHY_1_CFG
, reg_base
+ PORT_PHY1
);
153 writel(AHCI_PORT_PHY_2_CFG
, reg_base
+ PORT_PHY2
);
154 writel(AHCI_PORT_PHY_3_CFG
, reg_base
+ PORT_PHY3
);
155 writel(AHCI_PORT_PHY_4_CFG
, reg_base
+ PORT_PHY4
);
156 writel(AHCI_PORT_PHY_5_CFG
, reg_base
+ PORT_PHY5
);
157 writel(AHCI_PORT_TRANS_CFG
, reg_base
+ PORT_TRANS
);
162 writel(AHCI_PORT_PHY_1_CFG
, reg_base
+ PORT_PHY1
);
169 static int ahci_qoriq_probe(struct platform_device
*pdev
)
171 struct device_node
*np
= pdev
->dev
.of_node
;
172 struct device
*dev
= &pdev
->dev
;
173 struct ahci_host_priv
*hpriv
;
174 struct ahci_qoriq_priv
*qoriq_priv
;
175 const struct of_device_id
*of_id
;
176 struct resource
*res
;
179 hpriv
= ahci_platform_get_resources(pdev
);
181 return PTR_ERR(hpriv
);
183 of_id
= of_match_node(ahci_qoriq_of_match
, np
);
187 qoriq_priv
= devm_kzalloc(dev
, sizeof(*qoriq_priv
), GFP_KERNEL
);
191 qoriq_priv
->type
= (enum ahci_qoriq_type
)of_id
->data
;
193 if (qoriq_priv
->type
== AHCI_LS1021A
) {
194 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
196 qoriq_priv
->ecc_addr
= devm_ioremap_resource(dev
, res
);
197 if (IS_ERR(qoriq_priv
->ecc_addr
))
198 return PTR_ERR(qoriq_priv
->ecc_addr
);
201 rc
= ahci_platform_enable_resources(hpriv
);
205 hpriv
->plat_data
= qoriq_priv
;
206 rc
= ahci_qoriq_phy_init(hpriv
);
208 goto disable_resources
;
210 rc
= ahci_platform_init_host(pdev
, hpriv
, &ahci_qoriq_port_info
,
213 goto disable_resources
;
218 ahci_platform_disable_resources(hpriv
);
223 #ifdef CONFIG_PM_SLEEP
224 static int ahci_qoriq_resume(struct device
*dev
)
226 struct ata_host
*host
= dev_get_drvdata(dev
);
227 struct ahci_host_priv
*hpriv
= host
->private_data
;
230 rc
= ahci_platform_enable_resources(hpriv
);
234 rc
= ahci_qoriq_phy_init(hpriv
);
236 goto disable_resources
;
238 rc
= ahci_platform_resume_host(dev
);
240 goto disable_resources
;
242 /* We resumed so update PM runtime state */
243 pm_runtime_disable(dev
);
244 pm_runtime_set_active(dev
);
245 pm_runtime_enable(dev
);
250 ahci_platform_disable_resources(hpriv
);
256 static SIMPLE_DEV_PM_OPS(ahci_qoriq_pm_ops
, ahci_platform_suspend
,
259 static struct platform_driver ahci_qoriq_driver
= {
260 .probe
= ahci_qoriq_probe
,
261 .remove
= ata_platform_remove_one
,
264 .of_match_table
= ahci_qoriq_of_match
,
265 .pm
= &ahci_qoriq_pm_ops
,
268 module_platform_driver(ahci_qoriq_driver
);
270 MODULE_DESCRIPTION("Freescale QorIQ AHCI SATA platform driver");
271 MODULE_AUTHOR("Tang Yuantian <Yuantian.Tang@freescale.com>");
272 MODULE_LICENSE("GPL");