2012-02-17 04:51:31 +04:00
|
|
|
/*
|
2014-11-07 03:26:40 +03:00
|
|
|
* Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
|
2011-07-18 14:21:23 +04:00
|
|
|
* http://www.samsung.com/
|
|
|
|
*
|
2012-02-17 04:51:31 +04:00
|
|
|
* EXYNOS - CPU PMU(Power Management Unit) support
|
2011-07-18 14:21:23 +04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
#include <linux/of.h>
|
2014-11-22 17:10:23 +03:00
|
|
|
#include <linux/of_address.h>
|
2017-01-19 16:48:41 +03:00
|
|
|
#include <linux/mfd/syscon.h>
|
2014-11-07 03:26:40 +03:00
|
|
|
#include <linux/platform_device.h>
|
2014-11-07 03:27:33 +03:00
|
|
|
#include <linux/delay.h>
|
|
|
|
|
2015-12-18 06:32:11 +03:00
|
|
|
#include <linux/soc/samsung/exynos-regs-pmu.h>
|
|
|
|
#include <linux/soc/samsung/exynos-pmu.h>
|
2011-07-18 14:21:23 +04:00
|
|
|
|
2015-12-18 06:32:12 +03:00
|
|
|
#include "exynos-pmu.h"
|
2014-11-07 03:26:40 +03:00
|
|
|
|
|
|
|
struct exynos_pmu_context {
|
|
|
|
struct device *dev;
|
|
|
|
const struct exynos_pmu_data *pmu_data;
|
|
|
|
};
|
|
|
|
|
2015-12-18 06:32:12 +03:00
|
|
|
void __iomem *pmu_base_addr;
|
2014-11-07 03:26:40 +03:00
|
|
|
static struct exynos_pmu_context *pmu_context;
|
2011-07-18 14:21:23 +04:00
|
|
|
|
2015-12-18 06:32:12 +03:00
|
|
|
void pmu_raw_writel(u32 val, u32 offset)
|
2014-11-07 03:26:47 +03:00
|
|
|
{
|
|
|
|
writel_relaxed(val, pmu_base_addr + offset);
|
|
|
|
}
|
|
|
|
|
2015-12-18 06:32:12 +03:00
|
|
|
u32 pmu_raw_readl(u32 offset)
|
2014-11-07 03:26:47 +03:00
|
|
|
{
|
|
|
|
return readl_relaxed(pmu_base_addr + offset);
|
|
|
|
}
|
|
|
|
|
2012-02-17 04:51:31 +04:00
|
|
|
void exynos_sys_powerdown_conf(enum sys_powerdown mode)
|
2011-07-18 14:21:23 +04:00
|
|
|
{
|
2011-09-27 02:22:11 +04:00
|
|
|
unsigned int i;
|
2015-11-13 12:29:36 +03:00
|
|
|
const struct exynos_pmu_data *pmu_data;
|
|
|
|
|
|
|
|
if (!pmu_context)
|
|
|
|
return;
|
2011-09-27 02:22:11 +04:00
|
|
|
|
2015-11-13 12:29:36 +03:00
|
|
|
pmu_data = pmu_context->pmu_data;
|
2012-02-17 07:23:51 +04:00
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
if (pmu_data->powerdown_conf)
|
|
|
|
pmu_data->powerdown_conf(mode);
|
2012-05-14 19:20:09 +04:00
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
if (pmu_data->pmu_config) {
|
|
|
|
for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
|
|
|
|
pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
|
|
|
|
pmu_data->pmu_config[i].offset);
|
|
|
|
}
|
|
|
|
|
2014-11-22 17:03:40 +03:00
|
|
|
if (pmu_data->powerdown_conf_extra)
|
|
|
|
pmu_data->powerdown_conf_extra(mode);
|
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
if (pmu_data->pmu_config_extra) {
|
|
|
|
for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++)
|
|
|
|
pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode],
|
|
|
|
pmu_data->pmu_config_extra[i].offset);
|
2012-05-14 19:20:09 +04:00
|
|
|
}
|
2011-09-27 02:22:11 +04:00
|
|
|
}
|
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
/*
|
|
|
|
* PMU platform driver and devicetree bindings.
|
|
|
|
*/
|
|
|
|
static const struct of_device_id exynos_pmu_of_device_ids[] = {
|
|
|
|
{
|
2014-11-22 17:03:40 +03:00
|
|
|
.compatible = "samsung,exynos3250-pmu",
|
|
|
|
.data = &exynos3250_pmu_data,
|
|
|
|
}, {
|
2014-11-07 03:26:40 +03:00
|
|
|
.compatible = "samsung,exynos4210-pmu",
|
|
|
|
.data = &exynos4210_pmu_data,
|
|
|
|
}, {
|
|
|
|
.compatible = "samsung,exynos4212-pmu",
|
|
|
|
.data = &exynos4212_pmu_data,
|
|
|
|
}, {
|
|
|
|
.compatible = "samsung,exynos4412-pmu",
|
|
|
|
.data = &exynos4412_pmu_data,
|
|
|
|
}, {
|
|
|
|
.compatible = "samsung,exynos5250-pmu",
|
|
|
|
.data = &exynos5250_pmu_data,
|
2014-11-07 03:27:33 +03:00
|
|
|
}, {
|
|
|
|
.compatible = "samsung,exynos5420-pmu",
|
|
|
|
.data = &exynos5420_pmu_data,
|
2014-11-07 03:26:40 +03:00
|
|
|
},
|
|
|
|
{ /*sentinel*/ },
|
|
|
|
};
|
2012-06-27 04:47:35 +04:00
|
|
|
|
2017-01-19 16:48:41 +03:00
|
|
|
struct regmap *exynos_get_pmu_regmap(void)
|
|
|
|
{
|
|
|
|
struct device_node *np = of_find_matching_node(NULL,
|
|
|
|
exynos_pmu_of_device_ids);
|
|
|
|
if (np)
|
|
|
|
return syscon_node_to_regmap(np);
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap);
|
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
static int exynos_pmu_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
const struct of_device_id *match;
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
pmu_base_addr = devm_ioremap_resource(dev, res);
|
|
|
|
if (IS_ERR(pmu_base_addr))
|
|
|
|
return PTR_ERR(pmu_base_addr);
|
|
|
|
|
|
|
|
pmu_context = devm_kzalloc(&pdev->dev,
|
|
|
|
sizeof(struct exynos_pmu_context),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!pmu_context) {
|
|
|
|
dev_err(dev, "Cannot allocate memory.\n");
|
|
|
|
return -ENOMEM;
|
2011-09-27 02:26:04 +04:00
|
|
|
}
|
2014-11-07 03:26:40 +03:00
|
|
|
pmu_context->dev = dev;
|
|
|
|
|
|
|
|
match = of_match_node(exynos_pmu_of_device_ids, dev->of_node);
|
|
|
|
|
|
|
|
pmu_context->pmu_data = match->data;
|
2011-07-18 14:21:23 +04:00
|
|
|
|
2014-11-07 03:26:40 +03:00
|
|
|
if (pmu_context->pmu_data->pmu_init)
|
|
|
|
pmu_context->pmu_data->pmu_init();
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, pmu_context);
|
|
|
|
|
|
|
|
dev_dbg(dev, "Exynos PMU Driver probe done\n");
|
2011-09-27 02:22:11 +04:00
|
|
|
return 0;
|
2011-07-18 14:21:23 +04:00
|
|
|
}
|
2014-11-07 03:26:40 +03:00
|
|
|
|
|
|
|
static struct platform_driver exynos_pmu_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "exynos-pmu",
|
|
|
|
.of_match_table = exynos_pmu_of_device_ids,
|
|
|
|
},
|
|
|
|
.probe = exynos_pmu_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init exynos_pmu_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&exynos_pmu_driver);
|
|
|
|
|
|
|
|
}
|
|
|
|
postcore_initcall(exynos_pmu_init);
|