106512c53SKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0 206512c53SKrzysztof Kozlowski // 306512c53SKrzysztof Kozlowski // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. 406512c53SKrzysztof Kozlowski // http://www.samsung.com/ 506512c53SKrzysztof Kozlowski // 606512c53SKrzysztof Kozlowski // EXYNOS - CPU PMU(Power Management Unit) support 7bfce552dSPankaj Dubey 8bfce552dSPankaj Dubey #include <linux/of.h> 9bfce552dSPankaj Dubey #include <linux/of_address.h> 10ec7cc5b1SMarek Szyprowski #include <linux/of_device.h> 1176640b84SMarek Szyprowski #include <linux/mfd/syscon.h> 12bfce552dSPankaj Dubey #include <linux/platform_device.h> 13bfce552dSPankaj Dubey #include <linux/delay.h> 14bfce552dSPankaj Dubey 15bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h> 16bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-pmu.h> 17bfce552dSPankaj Dubey 18bfce552dSPankaj Dubey #include "exynos-pmu.h" 19bfce552dSPankaj Dubey 20bfce552dSPankaj Dubey struct exynos_pmu_context { 21bfce552dSPankaj Dubey struct device *dev; 22bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 23bfce552dSPankaj Dubey }; 24bfce552dSPankaj Dubey 25bfce552dSPankaj Dubey void __iomem *pmu_base_addr; 26bfce552dSPankaj Dubey static struct exynos_pmu_context *pmu_context; 27bfce552dSPankaj Dubey 28bfce552dSPankaj Dubey void pmu_raw_writel(u32 val, u32 offset) 29bfce552dSPankaj Dubey { 30bfce552dSPankaj Dubey writel_relaxed(val, pmu_base_addr + offset); 31bfce552dSPankaj Dubey } 32bfce552dSPankaj Dubey 33bfce552dSPankaj Dubey u32 pmu_raw_readl(u32 offset) 34bfce552dSPankaj Dubey { 35bfce552dSPankaj Dubey return readl_relaxed(pmu_base_addr + offset); 36bfce552dSPankaj Dubey } 37bfce552dSPankaj Dubey 38bfce552dSPankaj Dubey void exynos_sys_powerdown_conf(enum sys_powerdown mode) 39bfce552dSPankaj Dubey { 40bfce552dSPankaj Dubey unsigned int i; 41bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 42bfce552dSPankaj Dubey 43fa59aa70SMarek Szyprowski if (!pmu_context || !pmu_context->pmu_data) 44bfce552dSPankaj Dubey return; 45bfce552dSPankaj Dubey 46bfce552dSPankaj Dubey pmu_data = pmu_context->pmu_data; 47bfce552dSPankaj Dubey 48bfce552dSPankaj Dubey if (pmu_data->powerdown_conf) 49bfce552dSPankaj Dubey pmu_data->powerdown_conf(mode); 50bfce552dSPankaj Dubey 51bfce552dSPankaj Dubey if (pmu_data->pmu_config) { 52bfce552dSPankaj Dubey for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++) 53bfce552dSPankaj Dubey pmu_raw_writel(pmu_data->pmu_config[i].val[mode], 54bfce552dSPankaj Dubey pmu_data->pmu_config[i].offset); 55bfce552dSPankaj Dubey } 56bfce552dSPankaj Dubey 57bfce552dSPankaj Dubey if (pmu_data->powerdown_conf_extra) 58bfce552dSPankaj Dubey pmu_data->powerdown_conf_extra(mode); 59bfce552dSPankaj Dubey } 60bfce552dSPankaj Dubey 61bfce552dSPankaj Dubey /* 62a0ebf662SKrzysztof Kozlowski * Split the data between ARM architectures because it is relatively big 63a0ebf662SKrzysztof Kozlowski * and useless on other arch. 64a0ebf662SKrzysztof Kozlowski */ 65a0ebf662SKrzysztof Kozlowski #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS 66a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data) (&data) 67a0ebf662SKrzysztof Kozlowski #else 68a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data) NULL 69a0ebf662SKrzysztof Kozlowski #endif 70a0ebf662SKrzysztof Kozlowski 71a0ebf662SKrzysztof Kozlowski /* 72bfce552dSPankaj Dubey * PMU platform driver and devicetree bindings. 73bfce552dSPankaj Dubey */ 74bfce552dSPankaj Dubey static const struct of_device_id exynos_pmu_of_device_ids[] = { 75bfce552dSPankaj Dubey { 76bfce552dSPankaj Dubey .compatible = "samsung,exynos3250-pmu", 77a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data), 78bfce552dSPankaj Dubey }, { 79bfce552dSPankaj Dubey .compatible = "samsung,exynos4210-pmu", 80a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data), 81bfce552dSPankaj Dubey }, { 82bfce552dSPankaj Dubey .compatible = "samsung,exynos4412-pmu", 83a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data), 84bfce552dSPankaj Dubey }, { 85bfce552dSPankaj Dubey .compatible = "samsung,exynos5250-pmu", 86a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data), 87bfce552dSPankaj Dubey }, { 88*7353c546SKrzysztof Kozlowski .compatible = "samsung,exynos5410-pmu", 89*7353c546SKrzysztof Kozlowski }, { 90bfce552dSPankaj Dubey .compatible = "samsung,exynos5420-pmu", 91a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data), 92fa59aa70SMarek Szyprowski }, { 93fa59aa70SMarek Szyprowski .compatible = "samsung,exynos5433-pmu", 94*7353c546SKrzysztof Kozlowski }, { 95*7353c546SKrzysztof Kozlowski .compatible = "samsung,exynos7-pmu", 96bfce552dSPankaj Dubey }, 97bfce552dSPankaj Dubey { /*sentinel*/ }, 98bfce552dSPankaj Dubey }; 99bfce552dSPankaj Dubey 10076640b84SMarek Szyprowski struct regmap *exynos_get_pmu_regmap(void) 10176640b84SMarek Szyprowski { 10276640b84SMarek Szyprowski struct device_node *np = of_find_matching_node(NULL, 10376640b84SMarek Szyprowski exynos_pmu_of_device_ids); 10476640b84SMarek Szyprowski if (np) 10576640b84SMarek Szyprowski return syscon_node_to_regmap(np); 10676640b84SMarek Szyprowski return ERR_PTR(-ENODEV); 10776640b84SMarek Szyprowski } 10876640b84SMarek Szyprowski EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); 10976640b84SMarek Szyprowski 110bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev) 111bfce552dSPankaj Dubey { 112bfce552dSPankaj Dubey struct device *dev = &pdev->dev; 113bfce552dSPankaj Dubey struct resource *res; 114bfce552dSPankaj Dubey 115bfce552dSPankaj Dubey res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 116bfce552dSPankaj Dubey pmu_base_addr = devm_ioremap_resource(dev, res); 117bfce552dSPankaj Dubey if (IS_ERR(pmu_base_addr)) 118bfce552dSPankaj Dubey return PTR_ERR(pmu_base_addr); 119bfce552dSPankaj Dubey 120bfce552dSPankaj Dubey pmu_context = devm_kzalloc(&pdev->dev, 121bfce552dSPankaj Dubey sizeof(struct exynos_pmu_context), 122bfce552dSPankaj Dubey GFP_KERNEL); 1231da6de33SMarek Szyprowski if (!pmu_context) 124bfce552dSPankaj Dubey return -ENOMEM; 125bfce552dSPankaj Dubey pmu_context->dev = dev; 126ec7cc5b1SMarek Szyprowski pmu_context->pmu_data = of_device_get_match_data(dev); 127bfce552dSPankaj Dubey 128fa59aa70SMarek Szyprowski if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init) 129bfce552dSPankaj Dubey pmu_context->pmu_data->pmu_init(); 130bfce552dSPankaj Dubey 131bfce552dSPankaj Dubey platform_set_drvdata(pdev, pmu_context); 132bfce552dSPankaj Dubey 133*7353c546SKrzysztof Kozlowski if (devm_of_platform_populate(dev)) 134*7353c546SKrzysztof Kozlowski dev_err(dev, "Error populating children, reboot and poweroff might not work properly\n"); 135*7353c546SKrzysztof Kozlowski 136bfce552dSPankaj Dubey dev_dbg(dev, "Exynos PMU Driver probe done\n"); 137bfce552dSPankaj Dubey return 0; 138bfce552dSPankaj Dubey } 139bfce552dSPankaj Dubey 140bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = { 141bfce552dSPankaj Dubey .driver = { 142bfce552dSPankaj Dubey .name = "exynos-pmu", 143bfce552dSPankaj Dubey .of_match_table = exynos_pmu_of_device_ids, 144bfce552dSPankaj Dubey }, 145bfce552dSPankaj Dubey .probe = exynos_pmu_probe, 146bfce552dSPankaj Dubey }; 147bfce552dSPankaj Dubey 148bfce552dSPankaj Dubey static int __init exynos_pmu_init(void) 149bfce552dSPankaj Dubey { 150bfce552dSPankaj Dubey return platform_driver_register(&exynos_pmu_driver); 151bfce552dSPankaj Dubey 152bfce552dSPankaj Dubey } 153bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init); 154