mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-09 06:36:40 +07:00
d97a1e5d7c
simple-pwrseq and emmc-pwrseq drivers rely on platform_device structure from of_find_device_by_node(), this works mostly. But, as there is no driver associated with this devices, cases like default/init pinctrl setup would never be performed by pwrseq. This becomes problem when the gpios used in pwrseq require pinctrl setup. Currently most of the common pinctrl setup is done in drivers/base/pinctrl.c by pinctrl_bind_pins(). There are two ways to solve this issue on either convert pwrseq drivers to a proper platform drivers or copy the exact code from pcintrl_bind_pins(). I prefer converting pwrseq to proper drivers so that other cases like setting up clks/parents from dt would also be possible. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
111 lines
2.2 KiB
C
111 lines
2.2 KiB
C
/*
|
|
* 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
|
|
*/
|
|
#include <linux/kernel.h>
|
|
#include <linux/err.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
#include "pwrseq.h"
|
|
|
|
static DEFINE_MUTEX(pwrseq_list_mutex);
|
|
static LIST_HEAD(pwrseq_list);
|
|
|
|
int mmc_pwrseq_alloc(struct mmc_host *host)
|
|
{
|
|
struct device_node *np;
|
|
struct mmc_pwrseq *p;
|
|
|
|
np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0);
|
|
if (!np)
|
|
return 0;
|
|
|
|
mutex_lock(&pwrseq_list_mutex);
|
|
list_for_each_entry(p, &pwrseq_list, pwrseq_node) {
|
|
if (p->dev->of_node == np) {
|
|
if (!try_module_get(p->owner))
|
|
dev_err(host->parent,
|
|
"increasing module refcount failed\n");
|
|
else
|
|
host->pwrseq = p;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
of_node_put(np);
|
|
mutex_unlock(&pwrseq_list_mutex);
|
|
|
|
if (!host->pwrseq)
|
|
return -EPROBE_DEFER;
|
|
|
|
dev_info(host->parent, "allocated mmc-pwrseq\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
void mmc_pwrseq_pre_power_on(struct mmc_host *host)
|
|
{
|
|
struct mmc_pwrseq *pwrseq = host->pwrseq;
|
|
|
|
if (pwrseq && 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->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->power_off)
|
|
pwrseq->ops->power_off(host);
|
|
}
|
|
|
|
void mmc_pwrseq_free(struct mmc_host *host)
|
|
{
|
|
struct mmc_pwrseq *pwrseq = host->pwrseq;
|
|
|
|
if (pwrseq) {
|
|
module_put(pwrseq->owner);
|
|
host->pwrseq = NULL;
|
|
}
|
|
}
|
|
|
|
int mmc_pwrseq_register(struct mmc_pwrseq *pwrseq)
|
|
{
|
|
if (!pwrseq || !pwrseq->ops || !pwrseq->dev)
|
|
return -EINVAL;
|
|
|
|
mutex_lock(&pwrseq_list_mutex);
|
|
list_add(&pwrseq->pwrseq_node, &pwrseq_list);
|
|
mutex_unlock(&pwrseq_list_mutex);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(mmc_pwrseq_register);
|
|
|
|
void mmc_pwrseq_unregister(struct mmc_pwrseq *pwrseq)
|
|
{
|
|
if (pwrseq) {
|
|
mutex_lock(&pwrseq_list_mutex);
|
|
list_del(&pwrseq->pwrseq_node);
|
|
mutex_unlock(&pwrseq_list_mutex);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(mmc_pwrseq_unregister);
|