2014-11-28 21:38:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Linaro Ltd
|
|
|
|
*
|
|
|
|
* Author: Ulf Hansson <ulf.hansson@linaro.org>
|
|
|
|
*
|
|
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
|
|
*
|
|
|
|
* MMC power sequence management
|
|
|
|
*/
|
2014-12-05 21:36:58 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
|
2014-11-28 21:38:36 +08:00
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
|
|
|
|
#include "pwrseq.h"
|
|
|
|
|
2014-12-05 21:36:58 +08:00
|
|
|
struct mmc_pwrseq_match {
|
|
|
|
const char *compatible;
|
2015-02-12 12:36:11 +08:00
|
|
|
struct mmc_pwrseq *(*alloc)(struct mmc_host *host, struct device *dev);
|
2014-12-05 21:36:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct mmc_pwrseq_match pwrseq_match[] = {
|
|
|
|
{
|
|
|
|
.compatible = "mmc-pwrseq-simple",
|
|
|
|
.alloc = mmc_pwrseq_simple_alloc,
|
2015-02-03 21:07:53 +08:00
|
|
|
}, {
|
|
|
|
.compatible = "mmc-pwrseq-emmc",
|
|
|
|
.alloc = mmc_pwrseq_emmc_alloc,
|
2014-12-05 21:36:58 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct mmc_pwrseq_match *mmc_pwrseq_find(struct device_node *np)
|
|
|
|
{
|
|
|
|
struct mmc_pwrseq_match *match = ERR_PTR(-ENODEV);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pwrseq_match); i++) {
|
|
|
|
if (of_device_is_compatible(np, pwrseq_match[i].compatible)) {
|
|
|
|
match = &pwrseq_match[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
2014-11-28 21:38:36 +08:00
|
|
|
|
|
|
|
int mmc_pwrseq_alloc(struct mmc_host *host)
|
|
|
|
{
|
2014-12-05 21:36:58 +08:00
|
|
|
struct platform_device *pdev;
|
|
|
|
struct device_node *np;
|
|
|
|
struct mmc_pwrseq_match *match;
|
2015-02-12 12:36:11 +08:00
|
|
|
struct mmc_pwrseq *pwrseq;
|
2014-12-05 21:36:58 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0);
|
|
|
|
if (!np)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pdev = of_find_device_by_node(np);
|
|
|
|
if (!pdev) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
match = mmc_pwrseq_find(np);
|
|
|
|
if (IS_ERR(match)) {
|
|
|
|
ret = PTR_ERR(match);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2015-02-12 12:36:11 +08:00
|
|
|
pwrseq = match->alloc(host, &pdev->dev);
|
|
|
|
if (IS_ERR(pwrseq)) {
|
2015-04-13 22:07:41 +08:00
|
|
|
ret = PTR_ERR(pwrseq);
|
2015-02-12 12:36:11 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->pwrseq = pwrseq;
|
|
|
|
dev_info(host->parent, "allocated mmc-pwrseq\n");
|
2014-12-05 21:36:58 +08:00
|
|
|
|
|
|
|
err:
|
|
|
|
of_node_put(np);
|
|
|
|
return ret;
|
2014-11-28 21:38:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void mmc_pwrseq_pre_power_on(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_pwrseq *pwrseq = host->pwrseq;
|
|
|
|
|
|
|
|
if (pwrseq && pwrseq->ops && pwrseq->ops->pre_power_on)
|
|
|
|
pwrseq->ops->pre_power_on(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmc_pwrseq_post_power_on(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_pwrseq *pwrseq = host->pwrseq;
|
|
|
|
|
|
|
|
if (pwrseq && pwrseq->ops && pwrseq->ops->post_power_on)
|
|
|
|
pwrseq->ops->post_power_on(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmc_pwrseq_power_off(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_pwrseq *pwrseq = host->pwrseq;
|
|
|
|
|
|
|
|
if (pwrseq && pwrseq->ops && pwrseq->ops->power_off)
|
|
|
|
pwrseq->ops->power_off(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmc_pwrseq_free(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_pwrseq *pwrseq = host->pwrseq;
|
|
|
|
|
|
|
|
if (pwrseq && pwrseq->ops && pwrseq->ops->free)
|
|
|
|
pwrseq->ops->free(host);
|
2015-02-12 12:36:11 +08:00
|
|
|
|
|
|
|
host->pwrseq = NULL;
|
2014-11-28 21:38:36 +08:00
|
|
|
}
|