2 * Copyright (C) 2014 Linaro Ltd
4 * Author: Ulf Hansson <ulf.hansson@linaro.org>
6 * License terms: GNU General Public License (GPL) version 2
8 * MMC power sequence management
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/err.h>
14 #include <linux/of_platform.h>
16 #include <linux/mmc/host.h>
20 struct mmc_pwrseq_match {
21 const char *compatible;
22 int (*alloc)(struct mmc_host *host, struct device *dev);
25 static struct mmc_pwrseq_match pwrseq_match[] = {
27 .compatible = "mmc-pwrseq-simple",
28 .alloc = mmc_pwrseq_simple_alloc,
30 .compatible = "mmc-pwrseq-emmc",
31 .alloc = mmc_pwrseq_emmc_alloc,
35 static struct mmc_pwrseq_match *mmc_pwrseq_find(struct device_node *np)
37 struct mmc_pwrseq_match *match = ERR_PTR(-ENODEV);
40 for (i = 0; i < ARRAY_SIZE(pwrseq_match); i++) {
41 if (of_device_is_compatible(np, pwrseq_match[i].compatible)) {
42 match = &pwrseq_match[i];
50 int mmc_pwrseq_alloc(struct mmc_host *host)
52 struct platform_device *pdev;
53 struct device_node *np;
54 struct mmc_pwrseq_match *match;
57 np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0);
61 pdev = of_find_device_by_node(np);
67 match = mmc_pwrseq_find(np);
73 ret = match->alloc(host, &pdev->dev);
75 dev_info(host->parent, "allocated mmc-pwrseq\n");
82 void mmc_pwrseq_pre_power_on(struct mmc_host *host)
84 struct mmc_pwrseq *pwrseq = host->pwrseq;
86 if (pwrseq && pwrseq->ops && pwrseq->ops->pre_power_on)
87 pwrseq->ops->pre_power_on(host);
90 void mmc_pwrseq_post_power_on(struct mmc_host *host)
92 struct mmc_pwrseq *pwrseq = host->pwrseq;
94 if (pwrseq && pwrseq->ops && pwrseq->ops->post_power_on)
95 pwrseq->ops->post_power_on(host);
98 void mmc_pwrseq_power_off(struct mmc_host *host)
100 struct mmc_pwrseq *pwrseq = host->pwrseq;
102 if (pwrseq && pwrseq->ops && pwrseq->ops->power_off)
103 pwrseq->ops->power_off(host);
106 void mmc_pwrseq_free(struct mmc_host *host)
108 struct mmc_pwrseq *pwrseq = host->pwrseq;
110 if (pwrseq && pwrseq->ops && pwrseq->ops->free)
111 pwrseq->ops->free(host);