xref: /openbmc/linux/drivers/soc/samsung/exynos-pmu.c (revision 249592bf)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
4 //		http://www.samsung.com/
5 //
6 // Exynos - CPU PMU(Power Management Unit) support
7 
8 #include <linux/of.h>
9 #include <linux/of_address.h>
10 #include <linux/of_device.h>
11 #include <linux/mfd/core.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 
16 #include <linux/soc/samsung/exynos-regs-pmu.h>
17 #include <linux/soc/samsung/exynos-pmu.h>
18 
19 #include "exynos-pmu.h"
20 
21 struct exynos_pmu_context {
22 	struct device *dev;
23 	const struct exynos_pmu_data *pmu_data;
24 };
25 
26 void __iomem *pmu_base_addr;
27 static struct exynos_pmu_context *pmu_context;
28 
29 void pmu_raw_writel(u32 val, u32 offset)
30 {
31 	writel_relaxed(val, pmu_base_addr + offset);
32 }
33 
34 u32 pmu_raw_readl(u32 offset)
35 {
36 	return readl_relaxed(pmu_base_addr + offset);
37 }
38 
39 void exynos_sys_powerdown_conf(enum sys_powerdown mode)
40 {
41 	unsigned int i;
42 	const struct exynos_pmu_data *pmu_data;
43 
44 	if (!pmu_context || !pmu_context->pmu_data)
45 		return;
46 
47 	pmu_data = pmu_context->pmu_data;
48 
49 	if (pmu_data->powerdown_conf)
50 		pmu_data->powerdown_conf(mode);
51 
52 	if (pmu_data->pmu_config) {
53 		for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
54 			pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
55 					pmu_data->pmu_config[i].offset);
56 	}
57 
58 	if (pmu_data->powerdown_conf_extra)
59 		pmu_data->powerdown_conf_extra(mode);
60 }
61 
62 /*
63  * Split the data between ARM architectures because it is relatively big
64  * and useless on other arch.
65  */
66 #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS
67 #define exynos_pmu_data_arm_ptr(data)	(&data)
68 #else
69 #define exynos_pmu_data_arm_ptr(data)	NULL
70 #endif
71 
72 /*
73  * PMU platform driver and devicetree bindings.
74  */
75 static const struct of_device_id exynos_pmu_of_device_ids[] = {
76 	{
77 		.compatible = "samsung,exynos3250-pmu",
78 		.data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data),
79 	}, {
80 		.compatible = "samsung,exynos4210-pmu",
81 		.data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data),
82 	}, {
83 		.compatible = "samsung,exynos4412-pmu",
84 		.data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data),
85 	}, {
86 		.compatible = "samsung,exynos5250-pmu",
87 		.data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data),
88 	}, {
89 		.compatible = "samsung,exynos5410-pmu",
90 	}, {
91 		.compatible = "samsung,exynos5420-pmu",
92 		.data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data),
93 	}, {
94 		.compatible = "samsung,exynos5433-pmu",
95 	}, {
96 		.compatible = "samsung,exynos7-pmu",
97 	},
98 	{ /*sentinel*/ },
99 };
100 
101 static const struct mfd_cell exynos_pmu_devs[] = {
102 	{ .name = "exynos-clkout", },
103 };
104 
105 struct regmap *exynos_get_pmu_regmap(void)
106 {
107 	struct device_node *np = of_find_matching_node(NULL,
108 						      exynos_pmu_of_device_ids);
109 	if (np)
110 		return syscon_node_to_regmap(np);
111 	return ERR_PTR(-ENODEV);
112 }
113 EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap);
114 
115 static int exynos_pmu_probe(struct platform_device *pdev)
116 {
117 	struct device *dev = &pdev->dev;
118 	int ret;
119 
120 	pmu_base_addr = devm_platform_ioremap_resource(pdev, 0);
121 	if (IS_ERR(pmu_base_addr))
122 		return PTR_ERR(pmu_base_addr);
123 
124 	pmu_context = devm_kzalloc(&pdev->dev,
125 			sizeof(struct exynos_pmu_context),
126 			GFP_KERNEL);
127 	if (!pmu_context)
128 		return -ENOMEM;
129 	pmu_context->dev = dev;
130 	pmu_context->pmu_data = of_device_get_match_data(dev);
131 
132 	if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init)
133 		pmu_context->pmu_data->pmu_init();
134 
135 	platform_set_drvdata(pdev, pmu_context);
136 
137 	ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, exynos_pmu_devs,
138 				   ARRAY_SIZE(exynos_pmu_devs), NULL, 0, NULL);
139 	if (ret)
140 		return ret;
141 
142 	if (devm_of_platform_populate(dev))
143 		dev_err(dev, "Error populating children, reboot and poweroff might not work properly\n");
144 
145 	dev_dbg(dev, "Exynos PMU Driver probe done\n");
146 	return 0;
147 }
148 
149 static struct platform_driver exynos_pmu_driver = {
150 	.driver  = {
151 		.name   = "exynos-pmu",
152 		.of_match_table = exynos_pmu_of_device_ids,
153 	},
154 	.probe = exynos_pmu_probe,
155 };
156 
157 static int __init exynos_pmu_init(void)
158 {
159 	return platform_driver_register(&exynos_pmu_driver);
160 
161 }
162 postcore_initcall(exynos_pmu_init);
163