blob: 0acdfd82e7510189bc8bb4a254c653667d012e89 [file] [log] [blame]
Jongpill Lee7d44d2b2012-02-17 09:51:31 +09001/*
Pankaj Dubey14fc8b92014-11-07 09:26:40 +09002 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
Jaecheol Leee28e3012011-07-18 19:21:23 +09003 * http://www.samsung.com/
4 *
Jongpill Lee7d44d2b2012-02-17 09:51:31 +09005 * EXYNOS - CPU PMU(Power Management Unit) support
Jaecheol Leee28e3012011-07-18 19:21:23 +09006 *
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
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090012#include <linux/of.h>
Pankaj Dubey8cfc7fd2014-11-22 23:10:23 +090013#include <linux/of_address.h>
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090014#include <linux/platform_device.h>
Abhilash Kesavanaf2e0a02014-11-07 09:27:33 +090015#include <linux/delay.h>
16
Pankaj Dubey2262d6e2015-12-18 09:02:11 +053017#include <linux/soc/samsung/exynos-regs-pmu.h>
18#include <linux/soc/samsung/exynos-pmu.h>
Jaecheol Leee28e3012011-07-18 19:21:23 +090019
Pankaj Dubeyc21100c2015-12-18 09:02:12 +053020#include "exynos-pmu.h"
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090021
22struct exynos_pmu_context {
23 struct device *dev;
24 const struct exynos_pmu_data *pmu_data;
25};
26
Pankaj Dubeyc21100c2015-12-18 09:02:12 +053027void __iomem *pmu_base_addr;
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090028static struct exynos_pmu_context *pmu_context;
Jaecheol Leee28e3012011-07-18 19:21:23 +090029
Pankaj Dubeyc21100c2015-12-18 09:02:12 +053030void pmu_raw_writel(u32 val, u32 offset)
Pankaj Dubey6b7bfd82014-11-07 09:26:47 +090031{
32 writel_relaxed(val, pmu_base_addr + offset);
33}
34
Pankaj Dubeyc21100c2015-12-18 09:02:12 +053035u32 pmu_raw_readl(u32 offset)
Pankaj Dubey6b7bfd82014-11-07 09:26:47 +090036{
37 return readl_relaxed(pmu_base_addr + offset);
38}
39
Jongpill Lee7d44d2b2012-02-17 09:51:31 +090040void exynos_sys_powerdown_conf(enum sys_powerdown mode)
Jaecheol Leee28e3012011-07-18 19:21:23 +090041{
Jongpill Lee0dba4dc2011-09-27 07:22:11 +090042 unsigned int i;
Pankaj Dubeyce36f6a2015-11-13 14:59:36 +053043 const struct exynos_pmu_data *pmu_data;
Jaecheol Leee28e3012011-07-18 19:21:23 +090044
Pankaj Dubeyce36f6a2015-11-13 14:59:36 +053045 if (!pmu_context)
46 return;
47
48 pmu_data = pmu_context->pmu_data;
Jongpill Lee60e49ca2012-02-17 12:23:51 +090049
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090050 if (pmu_data->powerdown_conf)
51 pmu_data->powerdown_conf(mode);
Inderpal Singh5ddfa842012-05-15 00:20:09 +090052
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090053 if (pmu_data->pmu_config) {
54 for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
55 pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
56 pmu_data->pmu_config[i].offset);
57 }
58
Bartlomiej Zolnierkiewicz8fcc7742014-11-22 23:03:40 +090059 if (pmu_data->powerdown_conf_extra)
60 pmu_data->powerdown_conf_extra(mode);
61
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090062 if (pmu_data->pmu_config_extra) {
63 for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++)
64 pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode],
65 pmu_data->pmu_config_extra[i].offset);
Inderpal Singh5ddfa842012-05-15 00:20:09 +090066 }
Jaecheol Leee28e3012011-07-18 19:21:23 +090067}
Jongpill Lee0dba4dc2011-09-27 07:22:11 +090068
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090069/*
70 * PMU platform driver and devicetree bindings.
71 */
72static const struct of_device_id exynos_pmu_of_device_ids[] = {
73 {
Bartlomiej Zolnierkiewicz8fcc7742014-11-22 23:03:40 +090074 .compatible = "samsung,exynos3250-pmu",
75 .data = &exynos3250_pmu_data,
76 }, {
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090077 .compatible = "samsung,exynos4210-pmu",
78 .data = &exynos4210_pmu_data,
79 }, {
80 .compatible = "samsung,exynos4212-pmu",
81 .data = &exynos4212_pmu_data,
82 }, {
83 .compatible = "samsung,exynos4412-pmu",
84 .data = &exynos4412_pmu_data,
85 }, {
86 .compatible = "samsung,exynos5250-pmu",
87 .data = &exynos5250_pmu_data,
Abhilash Kesavanaf2e0a02014-11-07 09:27:33 +090088 }, {
89 .compatible = "samsung,exynos5420-pmu",
90 .data = &exynos5420_pmu_data,
Pankaj Dubey14fc8b92014-11-07 09:26:40 +090091 },
92 { /*sentinel*/ },
93};
94
95static int exynos_pmu_probe(struct platform_device *pdev)
96{
97 const struct of_device_id *match;
98 struct device *dev = &pdev->dev;
99 struct resource *res;
100
101 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
102 pmu_base_addr = devm_ioremap_resource(dev, res);
103 if (IS_ERR(pmu_base_addr))
104 return PTR_ERR(pmu_base_addr);
105
106 pmu_context = devm_kzalloc(&pdev->dev,
107 sizeof(struct exynos_pmu_context),
108 GFP_KERNEL);
109 if (!pmu_context) {
110 dev_err(dev, "Cannot allocate memory.\n");
111 return -ENOMEM;
112 }
113 pmu_context->dev = dev;
114
115 match = of_match_node(exynos_pmu_of_device_ids, dev->of_node);
116
117 pmu_context->pmu_data = match->data;
118
119 if (pmu_context->pmu_data->pmu_init)
120 pmu_context->pmu_data->pmu_init();
121
122 platform_set_drvdata(pdev, pmu_context);
123
124 dev_dbg(dev, "Exynos PMU Driver probe done\n");
125 return 0;
126}
127
128static struct platform_driver exynos_pmu_driver = {
129 .driver = {
130 .name = "exynos-pmu",
Pankaj Dubey14fc8b92014-11-07 09:26:40 +0900131 .of_match_table = exynos_pmu_of_device_ids,
132 },
133 .probe = exynos_pmu_probe,
134};
135
Jongpill Lee7d44d2b2012-02-17 09:51:31 +0900136static int __init exynos_pmu_init(void)
Jongpill Lee0dba4dc2011-09-27 07:22:11 +0900137{
Pankaj Dubey14fc8b92014-11-07 09:26:40 +0900138 return platform_driver_register(&exynos_pmu_driver);
Jonghwan Choi7d896aa2012-06-27 09:47:35 +0900139
Jongpill Lee0dba4dc2011-09-27 07:22:11 +0900140}
Pankaj Dubey14fc8b92014-11-07 09:26:40 +0900141postcore_initcall(exynos_pmu_init);