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 --- a/drivers/ata/ahci.h
22 +++ b/drivers/ata/ahci.h
25 #include <linux/clk.h>
26 #include <linux/libata.h>
27 +#include <linux/phy/phy.h>
28 #include <linux/regulator/consumer.h>
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 */
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
42 #include <linux/platform_device.h>
43 #include <linux/libata.h>
44 #include <linux/ahci_platform.h>
45 +#include <linux/phy/phy.h>
48 static void ahci_host_stop(struct ata_host *host);
49 @@ -140,6 +141,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_
52 * 2) Clocks (through ahci_platform_enable_clks)
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
59 goto disable_regulator;
62 + rc = phy_init(hpriv->phy);
66 + rc = phy_power_on(hpriv->phy);
68 + phy_exit(hpriv->phy);
76 + ahci_platform_disable_clks(hpriv);
79 if (hpriv->target_pwr)
80 regulator_disable(hpriv->target_pwr);
81 @@ -176,11 +193,17 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_r
83 * This function disables all ahci_platform managed resources in the
85 - * 1) Clocks (through ahci_platform_disable_clks)
88 + * 2) Clocks (through ahci_platform_disable_clks)
91 void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
94 + phy_power_off(hpriv->phy);
95 + phy_exit(hpriv->phy);
98 ahci_platform_disable_clks(hpriv);
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)
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;
113 + hpriv->phy = devm_phy_get(dev, "sata-phy");
114 + if (IS_ERR(hpriv->phy)) {
115 + rc = PTR_ERR(hpriv->phy);
119 + /* continue normally */
123 + case -EPROBE_DEFER:
127 + dev_err(dev, "couldn't get sata-phy\n");
132 devres_remove_group(dev, NULL);