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 }, { 88bfce552dSPankaj Dubey .compatible = "samsung,exynos5420-pmu", 89a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data), 90fa59aa70SMarek Szyprowski }, { 91fa59aa70SMarek Szyprowski .compatible = "samsung,exynos5433-pmu", 92bfce552dSPankaj Dubey }, 93bfce552dSPankaj Dubey { /*sentinel*/ }, 94bfce552dSPankaj Dubey }; 95bfce552dSPankaj Dubey 9676640b84SMarek Szyprowski struct regmap *exynos_get_pmu_regmap(void) 9776640b84SMarek Szyprowski { 9876640b84SMarek Szyprowski struct device_node *np = of_find_matching_node(NULL, 9976640b84SMarek Szyprowski exynos_pmu_of_device_ids); 10076640b84SMarek Szyprowski if (np) 10176640b84SMarek Szyprowski return syscon_node_to_regmap(np); 10276640b84SMarek Szyprowski return ERR_PTR(-ENODEV); 10376640b84SMarek Szyprowski } 10476640b84SMarek Szyprowski EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); 10576640b84SMarek Szyprowski 106bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev) 107bfce552dSPankaj Dubey { 108bfce552dSPankaj Dubey struct device *dev = &pdev->dev; 109bfce552dSPankaj Dubey struct resource *res; 110bfce552dSPankaj Dubey 111bfce552dSPankaj Dubey res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 112bfce552dSPankaj Dubey pmu_base_addr = devm_ioremap_resource(dev, res); 113bfce552dSPankaj Dubey if (IS_ERR(pmu_base_addr)) 114bfce552dSPankaj Dubey return PTR_ERR(pmu_base_addr); 115bfce552dSPankaj Dubey 116bfce552dSPankaj Dubey pmu_context = devm_kzalloc(&pdev->dev, 117bfce552dSPankaj Dubey sizeof(struct exynos_pmu_context), 118bfce552dSPankaj Dubey GFP_KERNEL); 1191da6de33SMarek Szyprowski if (!pmu_context) 120bfce552dSPankaj Dubey return -ENOMEM; 121bfce552dSPankaj Dubey pmu_context->dev = dev; 122ec7cc5b1SMarek Szyprowski pmu_context->pmu_data = of_device_get_match_data(dev); 123bfce552dSPankaj Dubey 124fa59aa70SMarek Szyprowski if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init) 125bfce552dSPankaj Dubey pmu_context->pmu_data->pmu_init(); 126bfce552dSPankaj Dubey 127bfce552dSPankaj Dubey platform_set_drvdata(pdev, pmu_context); 128bfce552dSPankaj Dubey 129bfce552dSPankaj Dubey dev_dbg(dev, "Exynos PMU Driver probe done\n"); 130bfce552dSPankaj Dubey return 0; 131bfce552dSPankaj Dubey } 132bfce552dSPankaj Dubey 133bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = { 134bfce552dSPankaj Dubey .driver = { 135bfce552dSPankaj Dubey .name = "exynos-pmu", 136bfce552dSPankaj Dubey .of_match_table = exynos_pmu_of_device_ids, 137bfce552dSPankaj Dubey }, 138bfce552dSPankaj Dubey .probe = exynos_pmu_probe, 139bfce552dSPankaj Dubey }; 140bfce552dSPankaj Dubey 141bfce552dSPankaj Dubey static int __init exynos_pmu_init(void) 142bfce552dSPankaj Dubey { 143bfce552dSPankaj Dubey return platform_driver_register(&exynos_pmu_driver); 144bfce552dSPankaj Dubey 145bfce552dSPankaj Dubey } 146bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init); 147