xref: /openbmc/linux/drivers/soc/samsung/exynos-pmu.c (revision bfce552d)
1bfce552dSPankaj Dubey /*
2bfce552dSPankaj Dubey  * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
3bfce552dSPankaj Dubey  *		http://www.samsung.com/
4bfce552dSPankaj Dubey  *
5bfce552dSPankaj Dubey  * EXYNOS - CPU PMU(Power Management Unit) support
6bfce552dSPankaj Dubey  *
7bfce552dSPankaj Dubey  * This program is free software; you can redistribute it and/or modify
8bfce552dSPankaj Dubey  * it under the terms of the GNU General Public License version 2 as
9bfce552dSPankaj Dubey  * published by the Free Software Foundation.
10bfce552dSPankaj Dubey  */
11bfce552dSPankaj Dubey 
12bfce552dSPankaj Dubey #include <linux/of.h>
13bfce552dSPankaj Dubey #include <linux/of_address.h>
14bfce552dSPankaj Dubey #include <linux/platform_device.h>
15bfce552dSPankaj Dubey #include <linux/delay.h>
16bfce552dSPankaj Dubey 
17bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h>
18bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-pmu.h>
19bfce552dSPankaj Dubey 
20bfce552dSPankaj Dubey #include "exynos-pmu.h"
21bfce552dSPankaj Dubey 
22bfce552dSPankaj Dubey struct exynos_pmu_context {
23bfce552dSPankaj Dubey 	struct device *dev;
24bfce552dSPankaj Dubey 	const struct exynos_pmu_data *pmu_data;
25bfce552dSPankaj Dubey };
26bfce552dSPankaj Dubey 
27bfce552dSPankaj Dubey void __iomem *pmu_base_addr;
28bfce552dSPankaj Dubey static struct exynos_pmu_context *pmu_context;
29bfce552dSPankaj Dubey 
30bfce552dSPankaj Dubey void pmu_raw_writel(u32 val, u32 offset)
31bfce552dSPankaj Dubey {
32bfce552dSPankaj Dubey 	writel_relaxed(val, pmu_base_addr + offset);
33bfce552dSPankaj Dubey }
34bfce552dSPankaj Dubey 
35bfce552dSPankaj Dubey u32 pmu_raw_readl(u32 offset)
36bfce552dSPankaj Dubey {
37bfce552dSPankaj Dubey 	return readl_relaxed(pmu_base_addr + offset);
38bfce552dSPankaj Dubey }
39bfce552dSPankaj Dubey 
40bfce552dSPankaj Dubey void exynos_sys_powerdown_conf(enum sys_powerdown mode)
41bfce552dSPankaj Dubey {
42bfce552dSPankaj Dubey 	unsigned int i;
43bfce552dSPankaj Dubey 	const struct exynos_pmu_data *pmu_data;
44bfce552dSPankaj Dubey 
45bfce552dSPankaj Dubey 	if (!pmu_context)
46bfce552dSPankaj Dubey 		return;
47bfce552dSPankaj Dubey 
48bfce552dSPankaj Dubey 	pmu_data = pmu_context->pmu_data;
49bfce552dSPankaj Dubey 
50bfce552dSPankaj Dubey 	if (pmu_data->powerdown_conf)
51bfce552dSPankaj Dubey 		pmu_data->powerdown_conf(mode);
52bfce552dSPankaj Dubey 
53bfce552dSPankaj Dubey 	if (pmu_data->pmu_config) {
54bfce552dSPankaj Dubey 		for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
55bfce552dSPankaj Dubey 			pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
56bfce552dSPankaj Dubey 					pmu_data->pmu_config[i].offset);
57bfce552dSPankaj Dubey 	}
58bfce552dSPankaj Dubey 
59bfce552dSPankaj Dubey 	if (pmu_data->powerdown_conf_extra)
60bfce552dSPankaj Dubey 		pmu_data->powerdown_conf_extra(mode);
61bfce552dSPankaj Dubey 
62bfce552dSPankaj Dubey 	if (pmu_data->pmu_config_extra) {
63bfce552dSPankaj Dubey 		for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++)
64bfce552dSPankaj Dubey 			pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode],
65bfce552dSPankaj Dubey 					pmu_data->pmu_config_extra[i].offset);
66bfce552dSPankaj Dubey 	}
67bfce552dSPankaj Dubey }
68bfce552dSPankaj Dubey 
69bfce552dSPankaj Dubey /*
70bfce552dSPankaj Dubey  * PMU platform driver and devicetree bindings.
71bfce552dSPankaj Dubey  */
72bfce552dSPankaj Dubey static const struct of_device_id exynos_pmu_of_device_ids[] = {
73bfce552dSPankaj Dubey 	{
74bfce552dSPankaj Dubey 		.compatible = "samsung,exynos3250-pmu",
75bfce552dSPankaj Dubey 		.data = &exynos3250_pmu_data,
76bfce552dSPankaj Dubey 	}, {
77bfce552dSPankaj Dubey 		.compatible = "samsung,exynos4210-pmu",
78bfce552dSPankaj Dubey 		.data = &exynos4210_pmu_data,
79bfce552dSPankaj Dubey 	}, {
80bfce552dSPankaj Dubey 		.compatible = "samsung,exynos4212-pmu",
81bfce552dSPankaj Dubey 		.data = &exynos4212_pmu_data,
82bfce552dSPankaj Dubey 	}, {
83bfce552dSPankaj Dubey 		.compatible = "samsung,exynos4412-pmu",
84bfce552dSPankaj Dubey 		.data = &exynos4412_pmu_data,
85bfce552dSPankaj Dubey 	}, {
86bfce552dSPankaj Dubey 		.compatible = "samsung,exynos5250-pmu",
87bfce552dSPankaj Dubey 		.data = &exynos5250_pmu_data,
88bfce552dSPankaj Dubey 	}, {
89bfce552dSPankaj Dubey 		.compatible = "samsung,exynos5420-pmu",
90bfce552dSPankaj Dubey 		.data = &exynos5420_pmu_data,
91bfce552dSPankaj Dubey 	},
92bfce552dSPankaj Dubey 	{ /*sentinel*/ },
93bfce552dSPankaj Dubey };
94bfce552dSPankaj Dubey 
95bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev)
96bfce552dSPankaj Dubey {
97bfce552dSPankaj Dubey 	const struct of_device_id *match;
98bfce552dSPankaj Dubey 	struct device *dev = &pdev->dev;
99bfce552dSPankaj Dubey 	struct resource *res;
100bfce552dSPankaj Dubey 
101bfce552dSPankaj Dubey 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
102bfce552dSPankaj Dubey 	pmu_base_addr = devm_ioremap_resource(dev, res);
103bfce552dSPankaj Dubey 	if (IS_ERR(pmu_base_addr))
104bfce552dSPankaj Dubey 		return PTR_ERR(pmu_base_addr);
105bfce552dSPankaj Dubey 
106bfce552dSPankaj Dubey 	pmu_context = devm_kzalloc(&pdev->dev,
107bfce552dSPankaj Dubey 			sizeof(struct exynos_pmu_context),
108bfce552dSPankaj Dubey 			GFP_KERNEL);
109bfce552dSPankaj Dubey 	if (!pmu_context) {
110bfce552dSPankaj Dubey 		dev_err(dev, "Cannot allocate memory.\n");
111bfce552dSPankaj Dubey 		return -ENOMEM;
112bfce552dSPankaj Dubey 	}
113bfce552dSPankaj Dubey 	pmu_context->dev = dev;
114bfce552dSPankaj Dubey 
115bfce552dSPankaj Dubey 	match = of_match_node(exynos_pmu_of_device_ids, dev->of_node);
116bfce552dSPankaj Dubey 
117bfce552dSPankaj Dubey 	pmu_context->pmu_data = match->data;
118bfce552dSPankaj Dubey 
119bfce552dSPankaj Dubey 	if (pmu_context->pmu_data->pmu_init)
120bfce552dSPankaj Dubey 		pmu_context->pmu_data->pmu_init();
121bfce552dSPankaj Dubey 
122bfce552dSPankaj Dubey 	platform_set_drvdata(pdev, pmu_context);
123bfce552dSPankaj Dubey 
124bfce552dSPankaj Dubey 	dev_dbg(dev, "Exynos PMU Driver probe done\n");
125bfce552dSPankaj Dubey 	return 0;
126bfce552dSPankaj Dubey }
127bfce552dSPankaj Dubey 
128bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = {
129bfce552dSPankaj Dubey 	.driver  = {
130bfce552dSPankaj Dubey 		.name   = "exynos-pmu",
131bfce552dSPankaj Dubey 		.of_match_table = exynos_pmu_of_device_ids,
132bfce552dSPankaj Dubey 	},
133bfce552dSPankaj Dubey 	.probe = exynos_pmu_probe,
134bfce552dSPankaj Dubey };
135bfce552dSPankaj Dubey 
136bfce552dSPankaj Dubey static int __init exynos_pmu_init(void)
137bfce552dSPankaj Dubey {
138bfce552dSPankaj Dubey 	return platform_driver_register(&exynos_pmu_driver);
139bfce552dSPankaj Dubey 
140bfce552dSPankaj Dubey }
141bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init);
142