ahci-platform: Add enable_ / disable_resources helper functions

tj: Minor comment formatting updates.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Hans de Goede 2014-02-22 16:53:33 +01:00 коммит произвёл Tejun Heo
Родитель 4b3e603a29
Коммит 96a01ba52c
2 изменённых файлов: 71 добавлений и 37 удалений

Просмотреть файл

@ -132,6 +132,62 @@ void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)
} }
EXPORT_SYMBOL_GPL(ahci_platform_disable_clks); EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
/**
* ahci_platform_enable_resources - Enable platform resources
* @hpriv: host private area to store config values
*
* This function enables all ahci_platform managed resources in the
* following order:
* 1) Regulator
* 2) Clocks (through ahci_platform_enable_clks)
*
* If resource enabling fails at any point the previous enabled resources
* are disabled in reverse order.
*
* RETURNS:
* 0 on success otherwise a negative error code
*/
int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
{
int rc;
if (hpriv->target_pwr) {
rc = regulator_enable(hpriv->target_pwr);
if (rc)
return rc;
}
rc = ahci_platform_enable_clks(hpriv);
if (rc)
goto disable_regulator;
return 0;
disable_regulator:
if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr);
return rc;
}
EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
/**
* ahci_platform_disable_resources - Disable platform resources
* @hpriv: host private area to store config values
*
* This function disables all ahci_platform managed resources in the
* following order:
* 1) Clocks (through ahci_platform_disable_clks)
* 2) Regulator
*/
void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
{
ahci_platform_disable_clks(hpriv);
if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr);
}
EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
static void ahci_put_clks(struct ahci_host_priv *hpriv) static void ahci_put_clks(struct ahci_host_priv *hpriv)
{ {
int c; int c;
@ -214,15 +270,9 @@ static int ahci_probe(struct platform_device *pdev)
hpriv->clks[i] = clk; hpriv->clks[i] = clk;
} }
if (hpriv->target_pwr) { rc = ahci_platform_enable_resources(hpriv);
rc = regulator_enable(hpriv->target_pwr);
if (rc)
goto free_clk;
}
rc = ahci_enable_clks(dev, hpriv);
if (rc) if (rc)
goto disable_regulator; goto free_clk;
/* /*
* Some platforms might need to prepare for mmio region access, * Some platforms might need to prepare for mmio region access,
@ -233,7 +283,7 @@ static int ahci_probe(struct platform_device *pdev)
if (pdata && pdata->init) { if (pdata && pdata->init) {
rc = pdata->init(dev, hpriv->mmio); rc = pdata->init(dev, hpriv->mmio);
if (rc) if (rc)
goto disable_unprepare_clk; goto disable_resources;
} }
ahci_save_initial_config(dev, hpriv, ahci_save_initial_config(dev, hpriv,
@ -303,11 +353,8 @@ static int ahci_probe(struct platform_device *pdev)
pdata_exit: pdata_exit:
if (pdata && pdata->exit) if (pdata && pdata->exit)
pdata->exit(dev); pdata->exit(dev);
disable_unprepare_clk: disable_resources:
ahci_disable_clks(hpriv); ahci_platform_disable_resources(hpriv);
disable_regulator:
if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr);
free_clk: free_clk:
ahci_put_clks(hpriv); ahci_put_clks(hpriv);
return rc; return rc;
@ -322,11 +369,8 @@ static void ahci_host_stop(struct ata_host *host)
if (pdata && pdata->exit) if (pdata && pdata->exit)
pdata->exit(dev); pdata->exit(dev);
ahci_disable_clks(hpriv); ahci_platform_disable_resources(hpriv);
ahci_put_clks(hpriv); ahci_put_clks(hpriv);
if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr);
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
@ -361,10 +405,7 @@ static int ahci_suspend(struct device *dev)
if (pdata && pdata->suspend) if (pdata && pdata->suspend)
return pdata->suspend(dev); return pdata->suspend(dev);
ahci_disable_clks(hpriv); ahci_platform_disable_resources(hpriv);
if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr);
return 0; return 0;
} }
@ -376,26 +417,20 @@ static int ahci_resume(struct device *dev)
struct ahci_host_priv *hpriv = host->private_data; struct ahci_host_priv *hpriv = host->private_data;
int rc; int rc;
if (hpriv->target_pwr) { rc = ahci_platform_enable_resources(hpriv);
rc = regulator_enable(hpriv->target_pwr);
if (rc)
return rc;
}
rc = ahci_enable_clks(dev, hpriv);
if (rc) if (rc)
goto disable_regulator; return rc;
if (pdata && pdata->resume) { if (pdata && pdata->resume) {
rc = pdata->resume(dev); rc = pdata->resume(dev);
if (rc) if (rc)
goto disable_unprepare_clk; goto disable_resources;
} }
if (dev->power.power_state.event == PM_EVENT_SUSPEND) { if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
rc = ahci_reset_controller(host); rc = ahci_reset_controller(host);
if (rc) if (rc)
goto disable_unprepare_clk; goto disable_resources;
ahci_init_controller(host); ahci_init_controller(host);
} }
@ -404,11 +439,8 @@ static int ahci_resume(struct device *dev)
return 0; return 0;
disable_unprepare_clk: disable_resources:
ahci_disable_clks(hpriv); ahci_platform_disable_resources(hpriv);
disable_regulator:
if (hpriv->target_pwr)
regulator_disable(hpriv->target_pwr);
return rc; return rc;
} }

Просмотреть файл

@ -33,5 +33,7 @@ struct ahci_platform_data {
int ahci_platform_enable_clks(struct ahci_host_priv *hpriv); int ahci_platform_enable_clks(struct ahci_host_priv *hpriv);
void ahci_platform_disable_clks(struct ahci_host_priv *hpriv); void ahci_platform_disable_clks(struct ahci_host_priv *hpriv);
int ahci_platform_enable_resources(struct ahci_host_priv *hpriv);
void ahci_platform_disable_resources(struct ahci_host_priv *hpriv);
#endif /* _AHCI_PLATFORM_H */ #endif /* _AHCI_PLATFORM_H */