1 From 10f3c772363e549c3dbd3cc3755d270c5656d5b8 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sat, 22 Feb 2014 16:53:30 +0100
4 Subject: [PATCH 109/182] 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>
16 Signed-off-by: Tejun Heo <tj@kernel.org>
18 drivers/ata/ahci.c | 6 ++++--
19 drivers/ata/ahci.h | 6 ++++++
20 drivers/ata/libahci.c | 26 +++++++++++++++++++-------
21 drivers/ata/sata_highbank.c | 3 ++-
22 4 files changed, 31 insertions(+), 10 deletions(-)
24 diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
25 index c81d809..8bfc477 100644
26 --- a/drivers/ata/ahci.c
27 +++ b/drivers/ata/ahci.c
28 @@ -578,6 +578,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
29 unsigned long deadline)
31 struct ata_port *ap = link->ap;
32 + struct ahci_host_priv *hpriv = ap->host->private_data;
36 @@ -588,7 +589,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
37 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
38 deadline, &online, NULL);
40 - ahci_start_engine(ap);
41 + hpriv->start_engine(ap);
43 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
45 @@ -603,6 +604,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
47 struct ata_port *ap = link->ap;
48 struct ahci_port_priv *pp = ap->private_data;
49 + struct ahci_host_priv *hpriv = ap->host->private_data;
50 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
51 struct ata_taskfile tf;
53 @@ -618,7 +620,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
54 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
55 deadline, &online, NULL);
57 - ahci_start_engine(ap);
58 + hpriv->start_engine(ap);
60 /* The pseudo configuration device on SIMG4726 attached to
61 * ASUS P5W-DH Deluxe doesn't send signature FIS after
62 diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
63 index 2289efd..64d1a99 100644
64 --- a/drivers/ata/ahci.h
65 +++ b/drivers/ata/ahci.h
66 @@ -323,6 +323,12 @@ struct ahci_host_priv {
67 u32 em_msg_type; /* EM message type */
68 struct clk *clk; /* Only for platforms supporting clk */
69 void *plat_data; /* Other platform data */
71 + * Optional ahci_start_engine override, if not set this gets set to the
72 + * default ahci_start_engine during ahci_save_initial_config, this can
73 + * be overridden anytime before the host is activated.
75 + void (*start_engine)(struct ata_port *ap);
78 extern int ahci_ignore_sss;
79 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
80 index 36605ab..f839bb3 100644
81 --- a/drivers/ata/libahci.c
82 +++ b/drivers/ata/libahci.c
83 @@ -394,6 +394,9 @@ static ssize_t ahci_show_em_supported(struct device *dev,
85 * If inconsistent, config values are fixed up by this function.
87 + * If it is not set already this function sets hpriv->start_engine to
88 + * ahci_start_engine.
93 @@ -500,6 +503,9 @@ void ahci_save_initial_config(struct device *dev,
96 hpriv->port_map = port_map;
98 + if (!hpriv->start_engine)
99 + hpriv->start_engine = ahci_start_engine;
101 EXPORT_SYMBOL_GPL(ahci_save_initial_config);
103 @@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_port *ap)
106 if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
107 - ahci_start_engine(ap);
108 + hpriv->start_engine(ap);
111 if (ap->flags & ATA_FLAG_EM) {
112 @@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
116 - ahci_start_engine(ap);
117 + hpriv->start_engine(ap);
120 EXPORT_SYMBOL_GPL(ahci_kick_engine);
121 @@ -1426,6 +1432,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
122 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
123 struct ata_port *ap = link->ap;
124 struct ahci_port_priv *pp = ap->private_data;
125 + struct ahci_host_priv *hpriv = ap->host->private_data;
126 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
127 struct ata_taskfile tf;
129 @@ -1443,7 +1450,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
130 rc = sata_link_hardreset(link, timing, deadline, &online,
133 - ahci_start_engine(ap);
134 + hpriv->start_engine(ap);
137 *class = ahci_dev_classify(ap);
138 @@ -2007,10 +2014,12 @@ static void ahci_thaw(struct ata_port *ap)
140 void ahci_error_handler(struct ata_port *ap)
142 + struct ahci_host_priv *hpriv = ap->host->private_data;
144 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
146 ahci_stop_engine(ap);
147 - ahci_start_engine(ap);
148 + hpriv->start_engine(ap);
151 sata_pmp_error_handler(ap);
152 @@ -2031,6 +2040,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
154 static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
156 + struct ahci_host_priv *hpriv = ap->host->private_data;
157 void __iomem *port_mmio = ahci_port_base(ap);
158 struct ata_device *dev = ap->link.device;
159 u32 devslp, dm, dito, mdat, deto;
160 @@ -2094,7 +2104,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
162 writel(devslp, port_mmio + PORT_DEVSLP);
164 - ahci_start_engine(ap);
165 + hpriv->start_engine(ap);
167 /* enable device sleep feature for the drive */
168 err_mask = ata_dev_set_feature(dev,
169 @@ -2106,6 +2116,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
171 static void ahci_enable_fbs(struct ata_port *ap)
173 + struct ahci_host_priv *hpriv = ap->host->private_data;
174 struct ahci_port_priv *pp = ap->private_data;
175 void __iomem *port_mmio = ahci_port_base(ap);
177 @@ -2134,11 +2145,12 @@ static void ahci_enable_fbs(struct ata_port *ap)
179 dev_err(ap->host->dev, "Failed to enable FBS\n");
181 - ahci_start_engine(ap);
182 + hpriv->start_engine(ap);
185 static void ahci_disable_fbs(struct ata_port *ap)
187 + struct ahci_host_priv *hpriv = ap->host->private_data;
188 struct ahci_port_priv *pp = ap->private_data;
189 void __iomem *port_mmio = ahci_port_base(ap);
191 @@ -2166,7 +2178,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
192 pp->fbs_enabled = false;
195 - ahci_start_engine(ap);
196 + hpriv->start_engine(ap);
199 static void ahci_pmp_attach(struct ata_port *ap)
200 diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c
201 index 870b11e..b3b18d1 100644
202 --- a/drivers/ata/sata_highbank.c
203 +++ b/drivers/ata/sata_highbank.c
204 @@ -403,6 +403,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
205 static const unsigned long timing[] = { 5, 100, 500};
206 struct ata_port *ap = link->ap;
207 struct ahci_port_priv *pp = ap->private_data;
208 + struct ahci_host_priv *hpriv = ap->host->private_data;
209 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
210 struct ata_taskfile tf;
212 @@ -431,7 +432,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
214 } while (!online && retry--);
216 - ahci_start_engine(ap);
217 + hpriv->start_engine(ap);
220 *class = ahci_dev_classify(ap);