ipq806x: Add support for IPQ806x chip family
[openwrt/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 diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
22 index bf8100c..3ab7ac9 100644
23 --- a/drivers/ata/ahci.h
24 +++ b/drivers/ata/ahci.h
25 @@ -37,6 +37,7 @@
26
27 #include <linux/clk.h>
28 #include <linux/libata.h>
29 +#include <linux/phy/phy.h>
30 #include <linux/regulator/consumer.h>
31
32 /* Enclosure Management Control */
33 @@ -325,6 +326,7 @@ struct ahci_host_priv {
34 u32 em_msg_type; /* EM message type */
35 struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
36 struct regulator *target_pwr; /* Optional */
37 + struct phy *phy; /* If platform uses phy */
38 void *plat_data; /* Other platform data */
39 /*
40 * Optional ahci_start_engine override, if not set this gets set to the
41 diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
42 index 968e7d9..243dde3 100644
43 --- a/drivers/ata/ahci_platform.c
44 +++ b/drivers/ata/ahci_platform.c
45 @@ -22,6 +22,7 @@
46 #include <linux/platform_device.h>
47 #include <linux/libata.h>
48 #include <linux/ahci_platform.h>
49 +#include <linux/phy/phy.h>
50 #include "ahci.h"
51
52 static void ahci_host_stop(struct ata_host *host);
53 @@ -140,6 +141,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
54 * following order:
55 * 1) Regulator
56 * 2) Clocks (through ahci_platform_enable_clks)
57 + * 3) Phy
58 *
59 * If resource enabling fails at any point the previous enabled resources
60 * are disabled in reverse order.
61 @@ -161,8 +163,23 @@ int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
62 if (rc)
63 goto disable_regulator;
64
65 + if (hpriv->phy) {
66 + rc = phy_init(hpriv->phy);
67 + if (rc)
68 + goto disable_clks;
69 +
70 + rc = phy_power_on(hpriv->phy);
71 + if (rc) {
72 + phy_exit(hpriv->phy);
73 + goto disable_clks;
74 + }
75 + }
76 +
77 return 0;
78
79 +disable_clks:
80 + ahci_platform_disable_clks(hpriv);
81 +
82 disable_regulator:
83 if (hpriv->target_pwr)
84 regulator_disable(hpriv->target_pwr);
85 @@ -176,11 +193,17 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
86 *
87 * This function disables all ahci_platform managed resources in the
88 * following order:
89 - * 1) Clocks (through ahci_platform_disable_clks)
90 - * 2) Regulator
91 + * 1) Phy
92 + * 2) Clocks (through ahci_platform_disable_clks)
93 + * 3) Regulator
94 */
95 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
96 {
97 + if (hpriv->phy) {
98 + phy_power_off(hpriv->phy);
99 + phy_exit(hpriv->phy);
100 + }
101 +
102 ahci_platform_disable_clks(hpriv);
103
104 if (hpriv->target_pwr)
105 @@ -208,6 +231,7 @@ static void ahci_platform_put_resources(struct device *dev, void *res)
106 * 2) regulator for controlling the targets power (optional)
107 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
108 * or for non devicetree enabled platforms a single clock
109 + * 4) phy (optional)
110 *
111 * RETURNS:
112 * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
113 @@ -266,6 +290,25 @@ struct ahci_host_priv *ahci_platform_get_resources(
114 hpriv->clks[i] = clk;
115 }
116
117 + hpriv->phy = devm_phy_get(dev, "sata-phy");
118 + if (IS_ERR(hpriv->phy)) {
119 + rc = PTR_ERR(hpriv->phy);
120 + switch (rc) {
121 + case -ENODEV:
122 + case -ENOSYS:
123 + /* continue normally */
124 + hpriv->phy = NULL;
125 + break;
126 +
127 + case -EPROBE_DEFER:
128 + goto err_out;
129 +
130 + default:
131 + dev_err(dev, "couldn't get sata-phy\n");
132 + goto err_out;
133 + }
134 + }
135 +
136 devres_remove_group(dev, NULL);
137 return hpriv;
138
139 --
140 1.7.10.4
141