sunxi: driver refresh for 3.13
[openwrt.git] / target / linux / sunxi / patches-3.13 / 160-4-libahci-allow-override-start_engine.patch
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
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 ---
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(-)
22
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)
29  {
30         struct ata_port *ap = link->ap;
31 +       struct ahci_host_priv *hpriv = ap->host->private_data;
32         bool online;
33         int rc;
34  
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);
38  
39 -       ahci_start_engine(ap);
40 +       hpriv->start_engine(ap);
41  
42         DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
43  
44 @@ -589,6 +590,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
45  {
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;
51         bool online;
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);
55  
56 -       ahci_start_engine(ap);
57 +       hpriv->start_engine(ap);
58  
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 */
69 +       /*
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.
73 +        */
74 +       void                    (*start_engine)(struct ata_port *ap);
75  };
76  
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,
83   *
84   *     If inconsistent, config values are fixed up by this function.
85   *
86 + *     If it is not set already this function sets hpriv->start_engine to
87 + *     ahci_start_engine.
88 + *
89   *     LOCKING:
90   *     None.
91   */
92 @@ -500,6 +503,9 @@ void ahci_save_initial_config(struct device *dev,
93         hpriv->cap = cap;
94         hpriv->cap2 = cap2;
95         hpriv->port_map = port_map;
96 +
97 +       if (!hpriv->start_engine)
98 +               hpriv->start_engine = ahci_start_engine;
99  }
100  EXPORT_SYMBOL_GPL(ahci_save_initial_config);
101  
102 @@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_port *ap)
103  
104         /* enable DMA */
105         if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
106 -               ahci_start_engine(ap);
107 +               hpriv->start_engine(ap);
108  
109         /* turn on LEDs */
110         if (ap->flags & ATA_FLAG_EM) {
111 @@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
112  
113         /* restart engine */
114   out_restart:
115 -       ahci_start_engine(ap);
116 +       hpriv->start_engine(ap);
117         return rc;
118  }
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;
127         bool online;
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,
130                                  ahci_check_ready);
131  
132 -       ahci_start_engine(ap);
133 +       hpriv->start_engine(ap);
134  
135         if (online)
136                 *class = ahci_dev_classify(ap);
137 @@ -2007,10 +2014,12 @@ static void ahci_thaw(struct ata_port *ap)
138  
139  void ahci_error_handler(struct ata_port *ap)
140  {
141 +       struct ahci_host_priv *hpriv = ap->host->private_data;
142 +
143         if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
144                 /* restart engine */
145                 ahci_stop_engine(ap);
146 -               ahci_start_engine(ap);
147 +               hpriv->start_engine(ap);
148         }
149  
150         sata_pmp_error_handler(ap);
151 @@ -2031,6 +2040,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
152  
153  static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
154  {
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)
160                    PORT_DEVSLP_ADSE);
161         writel(devslp, port_mmio + PORT_DEVSLP);
162  
163 -       ahci_start_engine(ap);
164 +       hpriv->start_engine(ap);
165  
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)
169  
170  static void ahci_enable_fbs(struct ata_port *ap)
171  {
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);
175         u32 fbs;
176 @@ -2134,11 +2145,12 @@ static void ahci_enable_fbs(struct ata_port *ap)
177         } else
178                 dev_err(ap->host->dev, "Failed to enable FBS\n");
179  
180 -       ahci_start_engine(ap);
181 +       hpriv->start_engine(ap);
182  }
183  
184  static void ahci_disable_fbs(struct ata_port *ap)
185  {
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);
189         u32 fbs;
190 @@ -2166,7 +2178,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
191                 pp->fbs_enabled = false;
192         }
193  
194 -       ahci_start_engine(ap);
195 +       hpriv->start_engine(ap);
196  }
197  
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;
210         bool online;
211 @@ -431,7 +432,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
212                         break;
213         } while (!online && retry--);
214  
215 -       ahci_start_engine(ap);
216 +       hpriv->start_engine(ap);
217  
218         if (online)
219                 *class = ahci_dev_classify(ap);
220 -- 
221 1.8.5.5
222