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 // 694500540SKrzysztof Kozlowski // Exynos - CPU PMU(Power Management Unit) support 7bfce552dSPankaj Dubey 8bfce552dSPankaj Dubey #include <linux/of.h> 9bfce552dSPankaj Dubey #include <linux/of_address.h> 1093618e34SKrzysztof Kozlowski #include <linux/mfd/core.h> 1176640b84SMarek Szyprowski #include <linux/mfd/syscon.h> 12*4c445837SRob Herring #include <linux/of_platform.h> 13bfce552dSPankaj Dubey #include <linux/platform_device.h> 14bfce552dSPankaj Dubey #include <linux/delay.h> 15bfce552dSPankaj Dubey 16bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h> 17bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-pmu.h> 18bfce552dSPankaj Dubey 19bfce552dSPankaj Dubey #include "exynos-pmu.h" 20bfce552dSPankaj Dubey 21bfce552dSPankaj Dubey struct exynos_pmu_context { 22bfce552dSPankaj Dubey struct device *dev; 23bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 24bfce552dSPankaj Dubey }; 25bfce552dSPankaj Dubey 26bfce552dSPankaj Dubey void __iomem *pmu_base_addr; 27bfce552dSPankaj Dubey static struct exynos_pmu_context *pmu_context; 28bfce552dSPankaj Dubey 29bfce552dSPankaj Dubey void pmu_raw_writel(u32 val, u32 offset) 30bfce552dSPankaj Dubey { 31bfce552dSPankaj Dubey writel_relaxed(val, pmu_base_addr + offset); 32bfce552dSPankaj Dubey } 33bfce552dSPankaj Dubey 34bfce552dSPankaj Dubey u32 pmu_raw_readl(u32 offset) 35bfce552dSPankaj Dubey { 36bfce552dSPankaj Dubey return readl_relaxed(pmu_base_addr + offset); 37bfce552dSPankaj Dubey } 38bfce552dSPankaj Dubey 39bfce552dSPankaj Dubey void exynos_sys_powerdown_conf(enum sys_powerdown mode) 40bfce552dSPankaj Dubey { 41bfce552dSPankaj Dubey unsigned int i; 42bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 43bfce552dSPankaj Dubey 44fa59aa70SMarek Szyprowski if (!pmu_context || !pmu_context->pmu_data) 45bfce552dSPankaj Dubey return; 46bfce552dSPankaj Dubey 47bfce552dSPankaj Dubey pmu_data = pmu_context->pmu_data; 48bfce552dSPankaj Dubey 49bfce552dSPankaj Dubey if (pmu_data->powerdown_conf) 50bfce552dSPankaj Dubey pmu_data->powerdown_conf(mode); 51bfce552dSPankaj Dubey 52bfce552dSPankaj Dubey if (pmu_data->pmu_config) { 53bfce552dSPankaj Dubey for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++) 54bfce552dSPankaj Dubey pmu_raw_writel(pmu_data->pmu_config[i].val[mode], 55bfce552dSPankaj Dubey pmu_data->pmu_config[i].offset); 56bfce552dSPankaj Dubey } 57bfce552dSPankaj Dubey 58bfce552dSPankaj Dubey if (pmu_data->powerdown_conf_extra) 59bfce552dSPankaj Dubey pmu_data->powerdown_conf_extra(mode); 60514a935fSArtur Weber 61514a935fSArtur Weber if (pmu_data->pmu_config_extra) { 62514a935fSArtur Weber for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++) 63514a935fSArtur Weber pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode], 64514a935fSArtur Weber pmu_data->pmu_config_extra[i].offset); 65514a935fSArtur Weber } 66bfce552dSPankaj Dubey } 67bfce552dSPankaj Dubey 68bfce552dSPankaj Dubey /* 69a0ebf662SKrzysztof Kozlowski * Split the data between ARM architectures because it is relatively big 70a0ebf662SKrzysztof Kozlowski * and useless on other arch. 71a0ebf662SKrzysztof Kozlowski */ 72a0ebf662SKrzysztof Kozlowski #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS 73a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data) (&data) 74a0ebf662SKrzysztof Kozlowski #else 75a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data) NULL 76a0ebf662SKrzysztof Kozlowski #endif 77a0ebf662SKrzysztof Kozlowski 78a0ebf662SKrzysztof Kozlowski /* 79bfce552dSPankaj Dubey * PMU platform driver and devicetree bindings. 80bfce552dSPankaj Dubey */ 81bfce552dSPankaj Dubey static const struct of_device_id exynos_pmu_of_device_ids[] = { 82bfce552dSPankaj Dubey { 83bfce552dSPankaj Dubey .compatible = "samsung,exynos3250-pmu", 84a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data), 85bfce552dSPankaj Dubey }, { 86bfce552dSPankaj Dubey .compatible = "samsung,exynos4210-pmu", 87a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data), 88bfce552dSPankaj Dubey }, { 89514a935fSArtur Weber .compatible = "samsung,exynos4212-pmu", 90514a935fSArtur Weber .data = exynos_pmu_data_arm_ptr(exynos4212_pmu_data), 91514a935fSArtur Weber }, { 92bfce552dSPankaj Dubey .compatible = "samsung,exynos4412-pmu", 93a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data), 94bfce552dSPankaj Dubey }, { 95bfce552dSPankaj Dubey .compatible = "samsung,exynos5250-pmu", 96a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data), 97bfce552dSPankaj Dubey }, { 987353c546SKrzysztof Kozlowski .compatible = "samsung,exynos5410-pmu", 997353c546SKrzysztof Kozlowski }, { 100bfce552dSPankaj Dubey .compatible = "samsung,exynos5420-pmu", 101a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data), 102fa59aa70SMarek Szyprowski }, { 103fa59aa70SMarek Szyprowski .compatible = "samsung,exynos5433-pmu", 1047353c546SKrzysztof Kozlowski }, { 1057353c546SKrzysztof Kozlowski .compatible = "samsung,exynos7-pmu", 106f5dc0140SSam Protsenko }, { 107f5dc0140SSam Protsenko .compatible = "samsung,exynos850-pmu", 108bfce552dSPankaj Dubey }, 109bfce552dSPankaj Dubey { /*sentinel*/ }, 110bfce552dSPankaj Dubey }; 111bfce552dSPankaj Dubey 11293618e34SKrzysztof Kozlowski static const struct mfd_cell exynos_pmu_devs[] = { 11393618e34SKrzysztof Kozlowski { .name = "exynos-clkout", }, 11493618e34SKrzysztof Kozlowski }; 11593618e34SKrzysztof Kozlowski 11676640b84SMarek Szyprowski struct regmap *exynos_get_pmu_regmap(void) 11776640b84SMarek Szyprowski { 11876640b84SMarek Szyprowski struct device_node *np = of_find_matching_node(NULL, 11976640b84SMarek Szyprowski exynos_pmu_of_device_ids); 12076640b84SMarek Szyprowski if (np) 12176640b84SMarek Szyprowski return syscon_node_to_regmap(np); 12276640b84SMarek Szyprowski return ERR_PTR(-ENODEV); 12376640b84SMarek Szyprowski } 12476640b84SMarek Szyprowski EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); 12576640b84SMarek Szyprowski 126bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev) 127bfce552dSPankaj Dubey { 128bfce552dSPankaj Dubey struct device *dev = &pdev->dev; 12993618e34SKrzysztof Kozlowski int ret; 130bfce552dSPankaj Dubey 13181a0efb7SYangtao Li pmu_base_addr = devm_platform_ioremap_resource(pdev, 0); 132bfce552dSPankaj Dubey if (IS_ERR(pmu_base_addr)) 133bfce552dSPankaj Dubey return PTR_ERR(pmu_base_addr); 134bfce552dSPankaj Dubey 135bfce552dSPankaj Dubey pmu_context = devm_kzalloc(&pdev->dev, 136bfce552dSPankaj Dubey sizeof(struct exynos_pmu_context), 137bfce552dSPankaj Dubey GFP_KERNEL); 1381da6de33SMarek Szyprowski if (!pmu_context) 139bfce552dSPankaj Dubey return -ENOMEM; 140bfce552dSPankaj Dubey pmu_context->dev = dev; 141ec7cc5b1SMarek Szyprowski pmu_context->pmu_data = of_device_get_match_data(dev); 142bfce552dSPankaj Dubey 143fa59aa70SMarek Szyprowski if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init) 144bfce552dSPankaj Dubey pmu_context->pmu_data->pmu_init(); 145bfce552dSPankaj Dubey 146bfce552dSPankaj Dubey platform_set_drvdata(pdev, pmu_context); 147bfce552dSPankaj Dubey 14893618e34SKrzysztof Kozlowski ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, exynos_pmu_devs, 14993618e34SKrzysztof Kozlowski ARRAY_SIZE(exynos_pmu_devs), NULL, 0, NULL); 15093618e34SKrzysztof Kozlowski if (ret) 15193618e34SKrzysztof Kozlowski return ret; 15293618e34SKrzysztof Kozlowski 1537353c546SKrzysztof Kozlowski if (devm_of_platform_populate(dev)) 1547353c546SKrzysztof Kozlowski dev_err(dev, "Error populating children, reboot and poweroff might not work properly\n"); 1557353c546SKrzysztof Kozlowski 156bfce552dSPankaj Dubey dev_dbg(dev, "Exynos PMU Driver probe done\n"); 157bfce552dSPankaj Dubey return 0; 158bfce552dSPankaj Dubey } 159bfce552dSPankaj Dubey 160bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = { 161bfce552dSPankaj Dubey .driver = { 162bfce552dSPankaj Dubey .name = "exynos-pmu", 163bfce552dSPankaj Dubey .of_match_table = exynos_pmu_of_device_ids, 164bfce552dSPankaj Dubey }, 165bfce552dSPankaj Dubey .probe = exynos_pmu_probe, 166bfce552dSPankaj Dubey }; 167bfce552dSPankaj Dubey 168bfce552dSPankaj Dubey static int __init exynos_pmu_init(void) 169bfce552dSPankaj Dubey { 170bfce552dSPankaj Dubey return platform_driver_register(&exynos_pmu_driver); 171bfce552dSPankaj Dubey 172bfce552dSPankaj Dubey } 173bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init); 174