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