ata: ahci_platform: Manage SATA PHY

Some platforms have a PHY hooked up to the SATA controller. The PHY
needs to be initialized and powered up for SATA to work. We do that
using the PHY framework.

tj: Minor comment formatting updates.

CC: Balaji T K <balajitk@ti.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Tejun Heo<tj@kernel.org>
This commit is contained in:
Roger Quadros 2014-02-22 16:53:40 +01:00 committed by Tejun Heo
parent 42a7f53ba0
commit 21b5faeec2
2 changed files with 47 additions and 2 deletions

View File

@ -37,6 +37,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/libata.h> #include <linux/libata.h>
#include <linux/phy/phy.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
/* Enclosure Management Control */ /* Enclosure Management Control */
@ -325,6 +326,7 @@ struct ahci_host_priv {
u32 em_msg_type; /* EM message type */ u32 em_msg_type; /* EM message type */
struct clk *clks[AHCI_MAX_CLKS]; /* Optional */ struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
struct regulator *target_pwr; /* Optional */ struct regulator *target_pwr; /* Optional */
struct phy *phy; /* If platform uses phy */
void *plat_data; /* Other platform data */ void *plat_data; /* Other platform data */
/* /*
* Optional ahci_start_engine override, if not set this gets set to the * Optional ahci_start_engine override, if not set this gets set to the

View File

@ -22,6 +22,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/libata.h> #include <linux/libata.h>
#include <linux/ahci_platform.h> #include <linux/ahci_platform.h>
#include <linux/phy/phy.h>
#include "ahci.h" #include "ahci.h"
static void ahci_host_stop(struct ata_host *host); static void ahci_host_stop(struct ata_host *host);
@ -140,6 +141,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
* following order: * following order:
* 1) Regulator * 1) Regulator
* 2) Clocks (through ahci_platform_enable_clks) * 2) Clocks (through ahci_platform_enable_clks)
* 3) Phy
* *
* If resource enabling fails at any point the previous enabled resources * If resource enabling fails at any point the previous enabled resources
* are disabled in reverse order. * are disabled in reverse order.
@ -161,8 +163,23 @@ int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
if (rc) if (rc)
goto disable_regulator; goto disable_regulator;
if (hpriv->phy) {
rc = phy_init(hpriv->phy);
if (rc)
goto disable_clks;
rc = phy_power_on(hpriv->phy);
if (rc) {
phy_exit(hpriv->phy);
goto disable_clks;
}
}
return 0; return 0;
disable_clks:
ahci_platform_disable_clks(hpriv);
disable_regulator: disable_regulator:
if (hpriv->target_pwr) if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr); regulator_disable(hpriv->target_pwr);
@ -176,11 +193,17 @@ EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
* *
* This function disables all ahci_platform managed resources in the * This function disables all ahci_platform managed resources in the
* following order: * following order:
* 1) Clocks (through ahci_platform_disable_clks) * 1) Phy
* 2) Regulator * 2) Clocks (through ahci_platform_disable_clks)
* 3) Regulator
*/ */
void ahci_platform_disable_resources(struct ahci_host_priv *hpriv) void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
{ {
if (hpriv->phy) {
phy_power_off(hpriv->phy);
phy_exit(hpriv->phy);
}
ahci_platform_disable_clks(hpriv); ahci_platform_disable_clks(hpriv);
if (hpriv->target_pwr) if (hpriv->target_pwr)
@ -208,6 +231,7 @@ static void ahci_platform_put_resources(struct device *dev, void *res)
* 2) regulator for controlling the targets power (optional) * 2) regulator for controlling the targets power (optional)
* 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node, * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
* or for non devicetree enabled platforms a single clock * or for non devicetree enabled platforms a single clock
* 4) phy (optional)
* *
* RETURNS: * RETURNS:
* The allocated ahci_host_priv on success, otherwise an ERR_PTR value * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
@ -266,6 +290,25 @@ struct ahci_host_priv *ahci_platform_get_resources(
hpriv->clks[i] = clk; hpriv->clks[i] = clk;
} }
hpriv->phy = devm_phy_get(dev, "sata-phy");
if (IS_ERR(hpriv->phy)) {
rc = PTR_ERR(hpriv->phy);
switch (rc) {
case -ENODEV:
case -ENOSYS:
/* continue normally */
hpriv->phy = NULL;
break;
case -EPROBE_DEFER:
goto err_out;
default:
dev_err(dev, "couldn't get sata-phy\n");
goto err_out;
}
}
devres_remove_group(dev, NULL); devres_remove_group(dev, NULL);
return hpriv; return hpriv;