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/mfd/core.h>
11 #include <linux/mfd/syscon.h>
12 #include <linux/of_platform.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
pmu_raw_writel(u32 val,u32 offset)29 void pmu_raw_writel(u32 val, u32 offset)
30 {
31 writel_relaxed(val, pmu_base_addr + offset);
32 }
33
pmu_raw_readl(u32 offset)34 u32 pmu_raw_readl(u32 offset)
35 {
36 return readl_relaxed(pmu_base_addr + offset);
37 }
38
exynos_sys_powerdown_conf(enum sys_powerdown mode)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 if (pmu_data->pmu_config_extra) {
62 for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++)
63 pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode],
64 pmu_data->pmu_config_extra[i].offset);
65 }
66 }
67
68 /*
69 * Split the data between ARM architectures because it is relatively big
70 * and useless on other arch.
71 */
72 #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS
73 #define exynos_pmu_data_arm_ptr(data) (&data)
74 #else
75 #define exynos_pmu_data_arm_ptr(data) NULL
76 #endif
77
78 /*
79 * PMU platform driver and devicetree bindings.
80 */
81 static const struct of_device_id exynos_pmu_of_device_ids[] = {
82 {
83 .compatible = "samsung,exynos3250-pmu",
84 .data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data),
85 }, {
86 .compatible = "samsung,exynos4210-pmu",
87 .data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data),
88 }, {
89 .compatible = "samsung,exynos4212-pmu",
90 .data = exynos_pmu_data_arm_ptr(exynos4212_pmu_data),
91 }, {
92 .compatible = "samsung,exynos4412-pmu",
93 .data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data),
94 }, {
95 .compatible = "samsung,exynos5250-pmu",
96 .data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data),
97 }, {
98 .compatible = "samsung,exynos5410-pmu",
99 }, {
100 .compatible = "samsung,exynos5420-pmu",
101 .data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data),
102 }, {
103 .compatible = "samsung,exynos5433-pmu",
104 }, {
105 .compatible = "samsung,exynos7-pmu",
106 }, {
107 .compatible = "samsung,exynos850-pmu",
108 },
109 { /*sentinel*/ },
110 };
111
112 static const struct mfd_cell exynos_pmu_devs[] = {
113 { .name = "exynos-clkout", },
114 };
115
exynos_get_pmu_regmap(void)116 struct regmap *exynos_get_pmu_regmap(void)
117 {
118 struct device_node *np = of_find_matching_node(NULL,
119 exynos_pmu_of_device_ids);
120 if (np)
121 return syscon_node_to_regmap(np);
122 return ERR_PTR(-ENODEV);
123 }
124 EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap);
125
exynos_pmu_probe(struct platform_device * pdev)126 static int exynos_pmu_probe(struct platform_device *pdev)
127 {
128 struct device *dev = &pdev->dev;
129 int ret;
130
131 pmu_base_addr = devm_platform_ioremap_resource(pdev, 0);
132 if (IS_ERR(pmu_base_addr))
133 return PTR_ERR(pmu_base_addr);
134
135 pmu_context = devm_kzalloc(&pdev->dev,
136 sizeof(struct exynos_pmu_context),
137 GFP_KERNEL);
138 if (!pmu_context)
139 return -ENOMEM;
140 pmu_context->dev = dev;
141 pmu_context->pmu_data = of_device_get_match_data(dev);
142
143 if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init)
144 pmu_context->pmu_data->pmu_init();
145
146 platform_set_drvdata(pdev, pmu_context);
147
148 ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, exynos_pmu_devs,
149 ARRAY_SIZE(exynos_pmu_devs), NULL, 0, NULL);
150 if (ret)
151 return ret;
152
153 if (devm_of_platform_populate(dev))
154 dev_err(dev, "Error populating children, reboot and poweroff might not work properly\n");
155
156 dev_dbg(dev, "Exynos PMU Driver probe done\n");
157 return 0;
158 }
159
160 static struct platform_driver exynos_pmu_driver = {
161 .driver = {
162 .name = "exynos-pmu",
163 .of_match_table = exynos_pmu_of_device_ids,
164 },
165 .probe = exynos_pmu_probe,
166 };
167
exynos_pmu_init(void)168 static int __init exynos_pmu_init(void)
169 {
170 return platform_driver_register(&exynos_pmu_driver);
171
172 }
173 postcore_initcall(exynos_pmu_init);
174