xref: /linux/drivers/soc/samsung/exynos-pmu.c (revision f5dc0140d483fcc6417d1d655481f0ff1de390b0)
106512c53SKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0
206512c53SKrzysztof Kozlowski //
306512c53SKrzysztof Kozlowski // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
406512c53SKrzysztof Kozlowski //		http://www.samsung.com/
506512c53SKrzysztof Kozlowski //
694500540SKrzysztof Kozlowski // Exynos - CPU PMU(Power Management Unit) support
7bfce552dSPankaj Dubey 
8bfce552dSPankaj Dubey #include <linux/of.h>
9bfce552dSPankaj Dubey #include <linux/of_address.h>
10ec7cc5b1SMarek Szyprowski #include <linux/of_device.h>
1193618e34SKrzysztof Kozlowski #include <linux/mfd/core.h>
1276640b84SMarek Szyprowski #include <linux/mfd/syscon.h>
13bfce552dSPankaj Dubey #include <linux/platform_device.h>
14bfce552dSPankaj Dubey #include <linux/delay.h>
15bfce552dSPankaj Dubey 
16bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h>
17bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-pmu.h>
18bfce552dSPankaj Dubey 
19bfce552dSPankaj Dubey #include "exynos-pmu.h"
20bfce552dSPankaj Dubey 
21bfce552dSPankaj Dubey struct exynos_pmu_context {
22bfce552dSPankaj Dubey 	struct device *dev;
23bfce552dSPankaj Dubey 	const struct exynos_pmu_data *pmu_data;
24bfce552dSPankaj Dubey };
25bfce552dSPankaj Dubey 
26bfce552dSPankaj Dubey void __iomem *pmu_base_addr;
27bfce552dSPankaj Dubey static struct exynos_pmu_context *pmu_context;
28bfce552dSPankaj Dubey 
29bfce552dSPankaj Dubey void pmu_raw_writel(u32 val, u32 offset)
30bfce552dSPankaj Dubey {
31bfce552dSPankaj Dubey 	writel_relaxed(val, pmu_base_addr + offset);
32bfce552dSPankaj Dubey }
33bfce552dSPankaj Dubey 
34bfce552dSPankaj Dubey u32 pmu_raw_readl(u32 offset)
35bfce552dSPankaj Dubey {
36bfce552dSPankaj Dubey 	return readl_relaxed(pmu_base_addr + offset);
37bfce552dSPankaj Dubey }
38bfce552dSPankaj Dubey 
39bfce552dSPankaj Dubey void exynos_sys_powerdown_conf(enum sys_powerdown mode)
40bfce552dSPankaj Dubey {
41bfce552dSPankaj Dubey 	unsigned int i;
42bfce552dSPankaj Dubey 	const struct exynos_pmu_data *pmu_data;
43bfce552dSPankaj Dubey 
44fa59aa70SMarek Szyprowski 	if (!pmu_context || !pmu_context->pmu_data)
45bfce552dSPankaj Dubey 		return;
46bfce552dSPankaj Dubey 
47bfce552dSPankaj Dubey 	pmu_data = pmu_context->pmu_data;
48bfce552dSPankaj Dubey 
49bfce552dSPankaj Dubey 	if (pmu_data->powerdown_conf)
50bfce552dSPankaj Dubey 		pmu_data->powerdown_conf(mode);
51bfce552dSPankaj Dubey 
52bfce552dSPankaj Dubey 	if (pmu_data->pmu_config) {
53bfce552dSPankaj Dubey 		for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
54bfce552dSPankaj Dubey 			pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
55bfce552dSPankaj Dubey 					pmu_data->pmu_config[i].offset);
56bfce552dSPankaj Dubey 	}
57bfce552dSPankaj Dubey 
58bfce552dSPankaj Dubey 	if (pmu_data->powerdown_conf_extra)
59bfce552dSPankaj Dubey 		pmu_data->powerdown_conf_extra(mode);
60bfce552dSPankaj Dubey }
61bfce552dSPankaj Dubey 
62bfce552dSPankaj Dubey /*
63a0ebf662SKrzysztof Kozlowski  * Split the data between ARM architectures because it is relatively big
64a0ebf662SKrzysztof Kozlowski  * and useless on other arch.
65a0ebf662SKrzysztof Kozlowski  */
66a0ebf662SKrzysztof Kozlowski #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS
67a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data)	(&data)
68a0ebf662SKrzysztof Kozlowski #else
69a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data)	NULL
70a0ebf662SKrzysztof Kozlowski #endif
71a0ebf662SKrzysztof Kozlowski 
72a0ebf662SKrzysztof Kozlowski /*
73bfce552dSPankaj Dubey  * PMU platform driver and devicetree bindings.
74bfce552dSPankaj Dubey  */
75bfce552dSPankaj Dubey static const struct of_device_id exynos_pmu_of_device_ids[] = {
76bfce552dSPankaj Dubey 	{
77bfce552dSPankaj Dubey 		.compatible = "samsung,exynos3250-pmu",
78a0ebf662SKrzysztof Kozlowski 		.data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data),
79bfce552dSPankaj Dubey 	}, {
80bfce552dSPankaj Dubey 		.compatible = "samsung,exynos4210-pmu",
81a0ebf662SKrzysztof Kozlowski 		.data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data),
82bfce552dSPankaj Dubey 	}, {
83bfce552dSPankaj Dubey 		.compatible = "samsung,exynos4412-pmu",
84a0ebf662SKrzysztof Kozlowski 		.data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data),
85bfce552dSPankaj Dubey 	}, {
86bfce552dSPankaj Dubey 		.compatible = "samsung,exynos5250-pmu",
87a0ebf662SKrzysztof Kozlowski 		.data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data),
88bfce552dSPankaj Dubey 	}, {
897353c546SKrzysztof Kozlowski 		.compatible = "samsung,exynos5410-pmu",
907353c546SKrzysztof Kozlowski 	}, {
91bfce552dSPankaj Dubey 		.compatible = "samsung,exynos5420-pmu",
92a0ebf662SKrzysztof Kozlowski 		.data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data),
93fa59aa70SMarek Szyprowski 	}, {
94fa59aa70SMarek Szyprowski 		.compatible = "samsung,exynos5433-pmu",
957353c546SKrzysztof Kozlowski 	}, {
967353c546SKrzysztof Kozlowski 		.compatible = "samsung,exynos7-pmu",
97*f5dc0140SSam Protsenko 	}, {
98*f5dc0140SSam Protsenko 		.compatible = "samsung,exynos850-pmu",
99bfce552dSPankaj Dubey 	},
100bfce552dSPankaj Dubey 	{ /*sentinel*/ },
101bfce552dSPankaj Dubey };
102bfce552dSPankaj Dubey 
10393618e34SKrzysztof Kozlowski static const struct mfd_cell exynos_pmu_devs[] = {
10493618e34SKrzysztof Kozlowski 	{ .name = "exynos-clkout", },
10593618e34SKrzysztof Kozlowski };
10693618e34SKrzysztof Kozlowski 
10776640b84SMarek Szyprowski struct regmap *exynos_get_pmu_regmap(void)
10876640b84SMarek Szyprowski {
10976640b84SMarek Szyprowski 	struct device_node *np = of_find_matching_node(NULL,
11076640b84SMarek Szyprowski 						      exynos_pmu_of_device_ids);
11176640b84SMarek Szyprowski 	if (np)
11276640b84SMarek Szyprowski 		return syscon_node_to_regmap(np);
11376640b84SMarek Szyprowski 	return ERR_PTR(-ENODEV);
11476640b84SMarek Szyprowski }
11576640b84SMarek Szyprowski EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap);
11676640b84SMarek Szyprowski 
117bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev)
118bfce552dSPankaj Dubey {
119bfce552dSPankaj Dubey 	struct device *dev = &pdev->dev;
12093618e34SKrzysztof Kozlowski 	int ret;
121bfce552dSPankaj Dubey 
12281a0efb7SYangtao Li 	pmu_base_addr = devm_platform_ioremap_resource(pdev, 0);
123bfce552dSPankaj Dubey 	if (IS_ERR(pmu_base_addr))
124bfce552dSPankaj Dubey 		return PTR_ERR(pmu_base_addr);
125bfce552dSPankaj Dubey 
126bfce552dSPankaj Dubey 	pmu_context = devm_kzalloc(&pdev->dev,
127bfce552dSPankaj Dubey 			sizeof(struct exynos_pmu_context),
128bfce552dSPankaj Dubey 			GFP_KERNEL);
1291da6de33SMarek Szyprowski 	if (!pmu_context)
130bfce552dSPankaj Dubey 		return -ENOMEM;
131bfce552dSPankaj Dubey 	pmu_context->dev = dev;
132ec7cc5b1SMarek Szyprowski 	pmu_context->pmu_data = of_device_get_match_data(dev);
133bfce552dSPankaj Dubey 
134fa59aa70SMarek Szyprowski 	if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init)
135bfce552dSPankaj Dubey 		pmu_context->pmu_data->pmu_init();
136bfce552dSPankaj Dubey 
137bfce552dSPankaj Dubey 	platform_set_drvdata(pdev, pmu_context);
138bfce552dSPankaj Dubey 
13993618e34SKrzysztof Kozlowski 	ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, exynos_pmu_devs,
14093618e34SKrzysztof Kozlowski 				   ARRAY_SIZE(exynos_pmu_devs), NULL, 0, NULL);
14193618e34SKrzysztof Kozlowski 	if (ret)
14293618e34SKrzysztof Kozlowski 		return ret;
14393618e34SKrzysztof Kozlowski 
1447353c546SKrzysztof Kozlowski 	if (devm_of_platform_populate(dev))
1457353c546SKrzysztof Kozlowski 		dev_err(dev, "Error populating children, reboot and poweroff might not work properly\n");
1467353c546SKrzysztof Kozlowski 
147bfce552dSPankaj Dubey 	dev_dbg(dev, "Exynos PMU Driver probe done\n");
148bfce552dSPankaj Dubey 	return 0;
149bfce552dSPankaj Dubey }
150bfce552dSPankaj Dubey 
151bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = {
152bfce552dSPankaj Dubey 	.driver  = {
153bfce552dSPankaj Dubey 		.name   = "exynos-pmu",
154bfce552dSPankaj Dubey 		.of_match_table = exynos_pmu_of_device_ids,
155bfce552dSPankaj Dubey 	},
156bfce552dSPankaj Dubey 	.probe = exynos_pmu_probe,
157bfce552dSPankaj Dubey };
158bfce552dSPankaj Dubey 
159bfce552dSPankaj Dubey static int __init exynos_pmu_init(void)
160bfce552dSPankaj Dubey {
161bfce552dSPankaj Dubey 	return platform_driver_register(&exynos_pmu_driver);
162bfce552dSPankaj Dubey 
163bfce552dSPankaj Dubey }
164bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init);
165