kernel: update 3.14 to 3.14.18
[openwrt.git] / target / linux / ipq806x / patches / 0117-ata-ahci_platform-Manage-SATA-PHY.patch
1 From 05b9b8d1035944af25694d2ebe53077cf1ccb067 Mon Sep 17 00:00:00 2001
2 From: Roger Quadros <rogerq@ti.com>
3 Date: Sat, 22 Feb 2014 16:53:40 +0100
4 Subject: [PATCH 117/182] ata: ahci_platform: Manage SATA PHY
5
6 Some platforms have a PHY hooked up to the SATA controller. The PHY
7 needs to be initialized and powered up for SATA to work. We do that
8 using the PHY framework.
9
10 tj: Minor comment formatting updates.
11
12 CC: Balaji T K <balajitk@ti.com>
13 Signed-off-by: Roger Quadros <rogerq@ti.com>
14 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
15 Signed-off-by: Tejun Heo<tj@kernel.org>
16 ---
17  drivers/ata/ahci.h          |    2 ++
18  drivers/ata/ahci_platform.c |   47 +++++++++++++++++++++++++++++++++++++++++--
19  2 files changed, 47 insertions(+), 2 deletions(-)
20
21 --- a/drivers/ata/ahci.h
22 +++ b/drivers/ata/ahci.h
23 @@ -37,6 +37,7 @@
24  
25  #include <linux/clk.h>
26  #include <linux/libata.h>
27 +#include <linux/phy/phy.h>
28  #include <linux/regulator/consumer.h>
29  
30  /* Enclosure Management Control */
31 @@ -326,6 +327,7 @@ struct ahci_host_priv {
32         u32                     em_msg_type;    /* EM message type */
33         struct clk              *clks[AHCI_MAX_CLKS]; /* Optional */
34         struct regulator        *target_pwr;    /* Optional */
35 +       struct phy              *phy;           /* If platform uses phy */
36         void                    *plat_data;     /* Other platform data */
37         /*
38          * Optional ahci_start_engine override, if not set this gets set to the
39 --- a/drivers/ata/ahci_platform.c
40 +++ b/drivers/ata/ahci_platform.c
41 @@ -22,6 +22,7 @@
42  #include <linux/platform_device.h>
43  #include <linux/libata.h>
44  #include <linux/ahci_platform.h>
45 +#include <linux/phy/phy.h>
46  #include "ahci.h"
47  
48  static void ahci_host_stop(struct ata_host *host);
49 @@ -140,6 +141,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_
50   * following order:
51   * 1) Regulator
52   * 2) Clocks (through ahci_platform_enable_clks)
53 + * 3) Phy
54   *
55   * If resource enabling fails at any point the previous enabled resources
56   * are disabled in reverse order.
57 @@ -161,8 +163,23 @@ int ahci_platform_enable_resources(struc
58         if (rc)
59                 goto disable_regulator;
60  
61 +       if (hpriv->phy) {
62 +               rc = phy_init(hpriv->phy);
63 +               if (rc)
64 +                       goto disable_clks;
65 +
66 +               rc = phy_power_on(hpriv->phy);
67 +               if (rc) {
68 +                       phy_exit(hpriv->phy);
69 +                       goto disable_clks;
70 +               }
71 +       }
72 +
73         return 0;
74  
75 +disable_clks:
76 +       ahci_platform_disable_clks(hpriv);
77 +
78  disable_regulator:
79         if (hpriv->target_pwr)
80                 regulator_disable(hpriv->target_pwr);
81 @@ -176,11 +193,17 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_r
82   *
83   * This function disables all ahci_platform managed resources in the
84   * following order:
85 - * 1) Clocks (through ahci_platform_disable_clks)
86 - * 2) Regulator
87 + * 1) Phy
88 + * 2) Clocks (through ahci_platform_disable_clks)
89 + * 3) Regulator
90   */
91  void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
92  {
93 +       if (hpriv->phy) {
94 +               phy_power_off(hpriv->phy);
95 +               phy_exit(hpriv->phy);
96 +       }
97 +
98         ahci_platform_disable_clks(hpriv);
99  
100         if (hpriv->target_pwr)
101 @@ -208,6 +231,7 @@ static void ahci_platform_put_resources(
102   * 2) regulator for controlling the targets power (optional)
103   * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
104   *    or for non devicetree enabled platforms a single clock
105 + *     4) phy (optional)
106   *
107   * RETURNS:
108   * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
109 @@ -266,6 +290,25 @@ struct ahci_host_priv *ahci_platform_get
110                 hpriv->clks[i] = clk;
111         }
112  
113 +       hpriv->phy = devm_phy_get(dev, "sata-phy");
114 +       if (IS_ERR(hpriv->phy)) {
115 +               rc = PTR_ERR(hpriv->phy);
116 +               switch (rc) {
117 +               case -ENODEV:
118 +               case -ENOSYS:
119 +                       /* continue normally */
120 +                       hpriv->phy = NULL;
121 +                       break;
122 +
123 +               case -EPROBE_DEFER:
124 +                       goto err_out;
125 +
126 +               default:
127 +                       dev_err(dev, "couldn't get sata-phy\n");
128 +                       goto err_out;
129 +               }
130 +       }
131 +
132         devres_remove_group(dev, NULL);
133         return hpriv;
134