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
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.
10 tj: Minor comment formatting updates.
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>
17 drivers/ata/ahci.h | 2 ++
18 drivers/ata/ahci_platform.c | 47 +++++++++++++++++++++++++++++++++++++++++--
19 2 files changed, 47 insertions(+), 2 deletions(-)
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
27 #include <linux/clk.h>
28 #include <linux/libata.h>
29 +#include <linux/phy/phy.h>
30 #include <linux/regulator/consumer.h>
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 */
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
46 #include <linux/platform_device.h>
47 #include <linux/libata.h>
48 #include <linux/ahci_platform.h>
49 +#include <linux/phy/phy.h>
52 static void ahci_host_stop(struct ata_host *host);
53 @@ -140,6 +141,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
56 * 2) Clocks (through ahci_platform_enable_clks)
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)
63 goto disable_regulator;
66 + rc = phy_init(hpriv->phy);
70 + rc = phy_power_on(hpriv->phy);
72 + phy_exit(hpriv->phy);
80 + ahci_platform_disable_clks(hpriv);
83 if (hpriv->target_pwr)
84 regulator_disable(hpriv->target_pwr);
85 @@ -176,11 +193,17 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
87 * This function disables all ahci_platform managed resources in the
89 - * 1) Clocks (through ahci_platform_disable_clks)
92 + * 2) Clocks (through ahci_platform_disable_clks)
95 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
98 + phy_power_off(hpriv->phy);
99 + phy_exit(hpriv->phy);
102 ahci_platform_disable_clks(hpriv);
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)
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;
117 + hpriv->phy = devm_phy_get(dev, "sata-phy");
118 + if (IS_ERR(hpriv->phy)) {
119 + rc = PTR_ERR(hpriv->phy);
123 + /* continue normally */
127 + case -EPROBE_DEFER:
131 + dev_err(dev, "couldn't get sata-phy\n");
136 devres_remove_group(dev, NULL);