1 From 9b10bc9f84fc221fcef9ddca92972af9b442f49d Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Mon, 2 Dec 2013 16:13:32 +0100
4 Subject: [PATCH] libahci: Allow drivers to override start_engine
6 Allwinner A10 and A20 ARM SoCs have an AHCI sata controller which needs a
7 special register to be poked before starting the DMA engine.
9 This register gets reset on an ahci_stop_engine call, so there is no other
10 place then ahci_start_engine where this poking can be done.
12 This commit allows drivers to override ahci_start_engine behavior for use by
13 the Allwinner AHCI driver (and potentially other drivers in the future).
15 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
17 drivers/ata/ahci.c | 6 ++++--
18 drivers/ata/ahci.h | 6 ++++++
19 drivers/ata/libahci.c | 26 +++++++++++++++++++-------
20 drivers/ata/sata_highbank.c | 3 ++-
21 4 files changed, 31 insertions(+), 10 deletions(-)
23 diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
24 index dc2756f..eda68b4 100644
25 --- a/drivers/ata/ahci.c
26 +++ b/drivers/ata/ahci.c
27 @@ -564,6 +564,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
28 unsigned long deadline)
30 struct ata_port *ap = link->ap;
31 + struct ahci_host_priv *hpriv = ap->host->private_data;
35 @@ -574,7 +575,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
36 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
37 deadline, &online, NULL);
39 - ahci_start_engine(ap);
40 + hpriv->start_engine(ap);
42 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
44 @@ -589,6 +590,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
46 struct ata_port *ap = link->ap;
47 struct ahci_port_priv *pp = ap->private_data;
48 + struct ahci_host_priv *hpriv = ap->host->private_data;
49 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
50 struct ata_taskfile tf;
52 @@ -604,7 +606,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
53 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
54 deadline, &online, NULL);
56 - ahci_start_engine(ap);
57 + hpriv->start_engine(ap);
59 /* The pseudo configuration device on SIMG4726 attached to
60 * ASUS P5W-DH Deluxe doesn't send signature FIS after
61 diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
62 index 2289efd..64d1a99d 100644
63 --- a/drivers/ata/ahci.h
64 +++ b/drivers/ata/ahci.h
65 @@ -323,6 +323,12 @@ struct ahci_host_priv {
66 u32 em_msg_type; /* EM message type */
67 struct clk *clk; /* Only for platforms supporting clk */
68 void *plat_data; /* Other platform data */
70 + * Optional ahci_start_engine override, if not set this gets set to the
71 + * default ahci_start_engine during ahci_save_initial_config, this can
72 + * be overridden anytime before the host is activated.
74 + void (*start_engine)(struct ata_port *ap);
77 extern int ahci_ignore_sss;
78 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
79 index 36605ab..f839bb3 100644
80 --- a/drivers/ata/libahci.c
81 +++ b/drivers/ata/libahci.c
82 @@ -394,6 +394,9 @@ static ssize_t ahci_show_em_supported(struct device *dev,
84 * If inconsistent, config values are fixed up by this function.
86 + * If it is not set already this function sets hpriv->start_engine to
87 + * ahci_start_engine.
92 @@ -500,6 +503,9 @@ void ahci_save_initial_config(struct device *dev,
95 hpriv->port_map = port_map;
97 + if (!hpriv->start_engine)
98 + hpriv->start_engine = ahci_start_engine;
100 EXPORT_SYMBOL_GPL(ahci_save_initial_config);
102 @@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_port *ap)
105 if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
106 - ahci_start_engine(ap);
107 + hpriv->start_engine(ap);
110 if (ap->flags & ATA_FLAG_EM) {
111 @@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
115 - ahci_start_engine(ap);
116 + hpriv->start_engine(ap);
119 EXPORT_SYMBOL_GPL(ahci_kick_engine);
120 @@ -1426,6 +1432,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
121 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
122 struct ata_port *ap = link->ap;
123 struct ahci_port_priv *pp = ap->private_data;
124 + struct ahci_host_priv *hpriv = ap->host->private_data;
125 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
126 struct ata_taskfile tf;
128 @@ -1443,7 +1450,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
129 rc = sata_link_hardreset(link, timing, deadline, &online,
132 - ahci_start_engine(ap);
133 + hpriv->start_engine(ap);
136 *class = ahci_dev_classify(ap);
137 @@ -2007,10 +2014,12 @@ static void ahci_thaw(struct ata_port *ap)
139 void ahci_error_handler(struct ata_port *ap)
141 + struct ahci_host_priv *hpriv = ap->host->private_data;
143 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
145 ahci_stop_engine(ap);
146 - ahci_start_engine(ap);
147 + hpriv->start_engine(ap);
150 sata_pmp_error_handler(ap);
151 @@ -2031,6 +2040,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
153 static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
155 + struct ahci_host_priv *hpriv = ap->host->private_data;
156 void __iomem *port_mmio = ahci_port_base(ap);
157 struct ata_device *dev = ap->link.device;
158 u32 devslp, dm, dito, mdat, deto;
159 @@ -2094,7 +2104,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
161 writel(devslp, port_mmio + PORT_DEVSLP);
163 - ahci_start_engine(ap);
164 + hpriv->start_engine(ap);
166 /* enable device sleep feature for the drive */
167 err_mask = ata_dev_set_feature(dev,
168 @@ -2106,6 +2116,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
170 static void ahci_enable_fbs(struct ata_port *ap)
172 + struct ahci_host_priv *hpriv = ap->host->private_data;
173 struct ahci_port_priv *pp = ap->private_data;
174 void __iomem *port_mmio = ahci_port_base(ap);
176 @@ -2134,11 +2145,12 @@ static void ahci_enable_fbs(struct ata_port *ap)
178 dev_err(ap->host->dev, "Failed to enable FBS\n");
180 - ahci_start_engine(ap);
181 + hpriv->start_engine(ap);
184 static void ahci_disable_fbs(struct ata_port *ap)
186 + struct ahci_host_priv *hpriv = ap->host->private_data;
187 struct ahci_port_priv *pp = ap->private_data;
188 void __iomem *port_mmio = ahci_port_base(ap);
190 @@ -2166,7 +2178,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
191 pp->fbs_enabled = false;
194 - ahci_start_engine(ap);
195 + hpriv->start_engine(ap);
198 static void ahci_pmp_attach(struct ata_port *ap)
199 diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c
200 index 870b11e..b3b18d1 100644
201 --- a/drivers/ata/sata_highbank.c
202 +++ b/drivers/ata/sata_highbank.c
203 @@ -403,6 +403,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
204 static const unsigned long timing[] = { 5, 100, 500};
205 struct ata_port *ap = link->ap;
206 struct ahci_port_priv *pp = ap->private_data;
207 + struct ahci_host_priv *hpriv = ap->host->private_data;
208 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
209 struct ata_taskfile tf;
211 @@ -431,7 +432,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
213 } while (!online && retry--);
215 - ahci_start_engine(ap);
216 + hpriv->start_engine(ap);
219 *class = ahci_dev_classify(ap);