1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
4 // http://www.samsung.com/
6 // Exynos - CPU PMU(Power Management Unit) support
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>
16 #include <linux/soc/samsung/exynos-regs-pmu.h>
17 #include <linux/soc/samsung/exynos-pmu.h>
19 #include "exynos-pmu.h"
21 struct exynos_pmu_context
{
23 const struct exynos_pmu_data
*pmu_data
;
26 void __iomem
*pmu_base_addr
;
27 static struct exynos_pmu_context
*pmu_context
;
29 void pmu_raw_writel(u32 val
, u32 offset
)
31 writel_relaxed(val
, pmu_base_addr
+ offset
);
34 u32
pmu_raw_readl(u32 offset
)
36 return readl_relaxed(pmu_base_addr
+ offset
);
39 void exynos_sys_powerdown_conf(enum sys_powerdown mode
)
42 const struct exynos_pmu_data
*pmu_data
;
44 if (!pmu_context
|| !pmu_context
->pmu_data
)
47 pmu_data
= pmu_context
->pmu_data
;
49 if (pmu_data
->powerdown_conf
)
50 pmu_data
->powerdown_conf(mode
);
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
);
58 if (pmu_data
->powerdown_conf_extra
)
59 pmu_data
->powerdown_conf_extra(mode
);
63 * Split the data between ARM architectures because it is relatively big
64 * and useless on other arch.
66 #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS
67 #define exynos_pmu_data_arm_ptr(data) (&data)
69 #define exynos_pmu_data_arm_ptr(data) NULL
73 * PMU platform driver and devicetree bindings.
75 static const struct of_device_id exynos_pmu_of_device_ids
[] = {
77 .compatible
= "samsung,exynos3250-pmu",
78 .data
= exynos_pmu_data_arm_ptr(exynos3250_pmu_data
),
80 .compatible
= "samsung,exynos4210-pmu",
81 .data
= exynos_pmu_data_arm_ptr(exynos4210_pmu_data
),
83 .compatible
= "samsung,exynos4412-pmu",
84 .data
= exynos_pmu_data_arm_ptr(exynos4412_pmu_data
),
86 .compatible
= "samsung,exynos5250-pmu",
87 .data
= exynos_pmu_data_arm_ptr(exynos5250_pmu_data
),
89 .compatible
= "samsung,exynos5410-pmu",
91 .compatible
= "samsung,exynos5420-pmu",
92 .data
= exynos_pmu_data_arm_ptr(exynos5420_pmu_data
),
94 .compatible
= "samsung,exynos5433-pmu",
96 .compatible
= "samsung,exynos7-pmu",
101 static const struct mfd_cell exynos_pmu_devs
[] = {
102 { .name
= "exynos-clkout", },
105 struct regmap
*exynos_get_pmu_regmap(void)
107 struct device_node
*np
= of_find_matching_node(NULL
,
108 exynos_pmu_of_device_ids
);
110 return syscon_node_to_regmap(np
);
111 return ERR_PTR(-ENODEV
);
113 EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap
);
115 static int exynos_pmu_probe(struct platform_device
*pdev
)
117 struct device
*dev
= &pdev
->dev
;
120 pmu_base_addr
= devm_platform_ioremap_resource(pdev
, 0);
121 if (IS_ERR(pmu_base_addr
))
122 return PTR_ERR(pmu_base_addr
);
124 pmu_context
= devm_kzalloc(&pdev
->dev
,
125 sizeof(struct exynos_pmu_context
),
129 pmu_context
->dev
= dev
;
130 pmu_context
->pmu_data
= of_device_get_match_data(dev
);
132 if (pmu_context
->pmu_data
&& pmu_context
->pmu_data
->pmu_init
)
133 pmu_context
->pmu_data
->pmu_init();
135 platform_set_drvdata(pdev
, pmu_context
);
137 ret
= devm_mfd_add_devices(dev
, PLATFORM_DEVID_NONE
, exynos_pmu_devs
,
138 ARRAY_SIZE(exynos_pmu_devs
), NULL
, 0, NULL
);
142 if (devm_of_platform_populate(dev
))
143 dev_err(dev
, "Error populating children, reboot and poweroff might not work properly\n");
145 dev_dbg(dev
, "Exynos PMU Driver probe done\n");
149 static struct platform_driver exynos_pmu_driver
= {
151 .name
= "exynos-pmu",
152 .of_match_table
= exynos_pmu_of_device_ids
,
154 .probe
= exynos_pmu_probe
,
157 static int __init
exynos_pmu_init(void)
159 return platform_driver_register(&exynos_pmu_driver
);
162 postcore_initcall(exynos_pmu_init
);