Jongpill Lee | 7d44d2b | 2012-02-17 09:51:31 +0900 | [diff] [blame] | 1 | /* |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 2 | * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 3 | * http://www.samsung.com/ |
| 4 | * |
Jongpill Lee | 7d44d2b | 2012-02-17 09:51:31 +0900 | [diff] [blame] | 5 | * EXYNOS - CPU PMU(Power Management Unit) support |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 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 | |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 12 | #include <linux/of.h> |
Pankaj Dubey | 8cfc7fd | 2014-11-22 23:10:23 +0900 | [diff] [blame] | 13 | #include <linux/of_address.h> |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Abhilash Kesavan | af2e0a0 | 2014-11-07 09:27:33 +0900 | [diff] [blame] | 15 | #include <linux/delay.h> |
| 16 | |
Pankaj Dubey | 2262d6e | 2015-12-18 09:02:11 +0530 | [diff] [blame] | 17 | #include <linux/soc/samsung/exynos-regs-pmu.h> |
| 18 | #include <linux/soc/samsung/exynos-pmu.h> |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 19 | |
Pankaj Dubey | c21100c | 2015-12-18 09:02:12 +0530 | [diff] [blame] | 20 | #include "exynos-pmu.h" |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 21 | |
| 22 | struct exynos_pmu_context { |
| 23 | struct device *dev; |
| 24 | const struct exynos_pmu_data *pmu_data; |
| 25 | }; |
| 26 | |
Pankaj Dubey | c21100c | 2015-12-18 09:02:12 +0530 | [diff] [blame] | 27 | void __iomem *pmu_base_addr; |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 28 | static struct exynos_pmu_context *pmu_context; |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 29 | |
Pankaj Dubey | c21100c | 2015-12-18 09:02:12 +0530 | [diff] [blame] | 30 | void pmu_raw_writel(u32 val, u32 offset) |
Pankaj Dubey | 6b7bfd8 | 2014-11-07 09:26:47 +0900 | [diff] [blame] | 31 | { |
| 32 | writel_relaxed(val, pmu_base_addr + offset); |
| 33 | } |
| 34 | |
Pankaj Dubey | c21100c | 2015-12-18 09:02:12 +0530 | [diff] [blame] | 35 | u32 pmu_raw_readl(u32 offset) |
Pankaj Dubey | 6b7bfd8 | 2014-11-07 09:26:47 +0900 | [diff] [blame] | 36 | { |
| 37 | return readl_relaxed(pmu_base_addr + offset); |
| 38 | } |
| 39 | |
Jongpill Lee | 7d44d2b | 2012-02-17 09:51:31 +0900 | [diff] [blame] | 40 | void exynos_sys_powerdown_conf(enum sys_powerdown mode) |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 41 | { |
Jongpill Lee | 0dba4dc | 2011-09-27 07:22:11 +0900 | [diff] [blame] | 42 | unsigned int i; |
Pankaj Dubey | ce36f6a | 2015-11-13 14:59:36 +0530 | [diff] [blame] | 43 | const struct exynos_pmu_data *pmu_data; |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 44 | |
Pankaj Dubey | ce36f6a | 2015-11-13 14:59:36 +0530 | [diff] [blame] | 45 | if (!pmu_context) |
| 46 | return; |
| 47 | |
| 48 | pmu_data = pmu_context->pmu_data; |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 49 | |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 50 | if (pmu_data->powerdown_conf) |
| 51 | pmu_data->powerdown_conf(mode); |
Inderpal Singh | 5ddfa84 | 2012-05-15 00:20:09 +0900 | [diff] [blame] | 52 | |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 53 | 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 Zolnierkiewicz | 8fcc774 | 2014-11-22 23:03:40 +0900 | [diff] [blame] | 59 | if (pmu_data->powerdown_conf_extra) |
| 60 | pmu_data->powerdown_conf_extra(mode); |
| 61 | |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 62 | 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 Singh | 5ddfa84 | 2012-05-15 00:20:09 +0900 | [diff] [blame] | 66 | } |
Jaecheol Lee | e28e301 | 2011-07-18 19:21:23 +0900 | [diff] [blame] | 67 | } |
Jongpill Lee | 0dba4dc | 2011-09-27 07:22:11 +0900 | [diff] [blame] | 68 | |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 69 | /* |
| 70 | * PMU platform driver and devicetree bindings. |
| 71 | */ |
| 72 | static const struct of_device_id exynos_pmu_of_device_ids[] = { |
| 73 | { |
Bartlomiej Zolnierkiewicz | 8fcc774 | 2014-11-22 23:03:40 +0900 | [diff] [blame] | 74 | .compatible = "samsung,exynos3250-pmu", |
| 75 | .data = &exynos3250_pmu_data, |
| 76 | }, { |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 77 | .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 Kesavan | af2e0a0 | 2014-11-07 09:27:33 +0900 | [diff] [blame] | 88 | }, { |
| 89 | .compatible = "samsung,exynos5420-pmu", |
| 90 | .data = &exynos5420_pmu_data, |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 91 | }, |
| 92 | { /*sentinel*/ }, |
| 93 | }; |
| 94 | |
| 95 | static 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 | |
| 128 | static struct platform_driver exynos_pmu_driver = { |
| 129 | .driver = { |
| 130 | .name = "exynos-pmu", |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 131 | .of_match_table = exynos_pmu_of_device_ids, |
| 132 | }, |
| 133 | .probe = exynos_pmu_probe, |
| 134 | }; |
| 135 | |
Jongpill Lee | 7d44d2b | 2012-02-17 09:51:31 +0900 | [diff] [blame] | 136 | static int __init exynos_pmu_init(void) |
Jongpill Lee | 0dba4dc | 2011-09-27 07:22:11 +0900 | [diff] [blame] | 137 | { |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 138 | return platform_driver_register(&exynos_pmu_driver); |
Jonghwan Choi | 7d896aa | 2012-06-27 09:47:35 +0900 | [diff] [blame] | 139 | |
Jongpill Lee | 0dba4dc | 2011-09-27 07:22:11 +0900 | [diff] [blame] | 140 | } |
Pankaj Dubey | 14fc8b9 | 2014-11-07 09:26:40 +0900 | [diff] [blame] | 141 | postcore_initcall(exynos_pmu_init); |