ipq806x: Add support for IPQ806x chip family
[openwrt/openwrt.git] / target / linux / ipq806x / patches / 0109-libahci-Allow-drivers-to-override-start_engine.patch
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
5
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.
8
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.
11
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).
14
15 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
16 Signed-off-by: Tejun Heo <tj@kernel.org>
17 ---
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(-)
23
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)
30 {
31 struct ata_port *ap = link->ap;
32 + struct ahci_host_priv *hpriv = ap->host->private_data;
33 bool online;
34 int rc;
35
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);
39
40 - ahci_start_engine(ap);
41 + hpriv->start_engine(ap);
42
43 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
44
45 @@ -603,6 +604,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
46 {
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;
52 bool online;
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);
56
57 - ahci_start_engine(ap);
58 + hpriv->start_engine(ap);
59
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 */
70 + /*
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.
74 + */
75 + void (*start_engine)(struct ata_port *ap);
76 };
77
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,
84 *
85 * If inconsistent, config values are fixed up by this function.
86 *
87 + * If it is not set already this function sets hpriv->start_engine to
88 + * ahci_start_engine.
89 + *
90 * LOCKING:
91 * None.
92 */
93 @@ -500,6 +503,9 @@ void ahci_save_initial_config(struct device *dev,
94 hpriv->cap = cap;
95 hpriv->cap2 = cap2;
96 hpriv->port_map = port_map;
97 +
98 + if (!hpriv->start_engine)
99 + hpriv->start_engine = ahci_start_engine;
100 }
101 EXPORT_SYMBOL_GPL(ahci_save_initial_config);
102
103 @@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_port *ap)
104
105 /* enable DMA */
106 if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
107 - ahci_start_engine(ap);
108 + hpriv->start_engine(ap);
109
110 /* turn on LEDs */
111 if (ap->flags & ATA_FLAG_EM) {
112 @@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
113
114 /* restart engine */
115 out_restart:
116 - ahci_start_engine(ap);
117 + hpriv->start_engine(ap);
118 return rc;
119 }
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;
128 bool online;
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,
131 ahci_check_ready);
132
133 - ahci_start_engine(ap);
134 + hpriv->start_engine(ap);
135
136 if (online)
137 *class = ahci_dev_classify(ap);
138 @@ -2007,10 +2014,12 @@ static void ahci_thaw(struct ata_port *ap)
139
140 void ahci_error_handler(struct ata_port *ap)
141 {
142 + struct ahci_host_priv *hpriv = ap->host->private_data;
143 +
144 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
145 /* restart engine */
146 ahci_stop_engine(ap);
147 - ahci_start_engine(ap);
148 + hpriv->start_engine(ap);
149 }
150
151 sata_pmp_error_handler(ap);
152 @@ -2031,6 +2040,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
153
154 static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
155 {
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)
161 PORT_DEVSLP_ADSE);
162 writel(devslp, port_mmio + PORT_DEVSLP);
163
164 - ahci_start_engine(ap);
165 + hpriv->start_engine(ap);
166
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)
170
171 static void ahci_enable_fbs(struct ata_port *ap)
172 {
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);
176 u32 fbs;
177 @@ -2134,11 +2145,12 @@ static void ahci_enable_fbs(struct ata_port *ap)
178 } else
179 dev_err(ap->host->dev, "Failed to enable FBS\n");
180
181 - ahci_start_engine(ap);
182 + hpriv->start_engine(ap);
183 }
184
185 static void ahci_disable_fbs(struct ata_port *ap)
186 {
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);
190 u32 fbs;
191 @@ -2166,7 +2178,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
192 pp->fbs_enabled = false;
193 }
194
195 - ahci_start_engine(ap);
196 + hpriv->start_engine(ap);
197 }
198
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;
211 bool online;
212 @@ -431,7 +432,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
213 break;
214 } while (!online && retry--);
215
216 - ahci_start_engine(ap);
217 + hpriv->start_engine(ap);
218
219 if (online)
220 *class = ahci_dev_classify(ap);
221 --
222 1.7.10.4
223