1bfce552dSPankaj Dubey /* 2bfce552dSPankaj Dubey * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. 3bfce552dSPankaj Dubey * http://www.samsung.com/ 4bfce552dSPankaj Dubey * 5bfce552dSPankaj Dubey * EXYNOS - CPU PMU(Power Management Unit) support 6bfce552dSPankaj Dubey * 7bfce552dSPankaj Dubey * This program is free software; you can redistribute it and/or modify 8bfce552dSPankaj Dubey * it under the terms of the GNU General Public License version 2 as 9bfce552dSPankaj Dubey * published by the Free Software Foundation. 10bfce552dSPankaj Dubey */ 11bfce552dSPankaj Dubey 12bfce552dSPankaj Dubey #include <linux/of.h> 13bfce552dSPankaj Dubey #include <linux/of_address.h> 14ec7cc5b1SMarek Szyprowski #include <linux/of_device.h> 1576640b84SMarek Szyprowski #include <linux/mfd/syscon.h> 16bfce552dSPankaj Dubey #include <linux/platform_device.h> 17bfce552dSPankaj Dubey #include <linux/delay.h> 18bfce552dSPankaj Dubey 19bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h> 20bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-pmu.h> 21bfce552dSPankaj Dubey 22bfce552dSPankaj Dubey #include "exynos-pmu.h" 23bfce552dSPankaj Dubey 24bfce552dSPankaj Dubey struct exynos_pmu_context { 25bfce552dSPankaj Dubey struct device *dev; 26bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 27bfce552dSPankaj Dubey }; 28bfce552dSPankaj Dubey 29bfce552dSPankaj Dubey void __iomem *pmu_base_addr; 30bfce552dSPankaj Dubey static struct exynos_pmu_context *pmu_context; 31bfce552dSPankaj Dubey 32bfce552dSPankaj Dubey void pmu_raw_writel(u32 val, u32 offset) 33bfce552dSPankaj Dubey { 34bfce552dSPankaj Dubey writel_relaxed(val, pmu_base_addr + offset); 35bfce552dSPankaj Dubey } 36bfce552dSPankaj Dubey 37bfce552dSPankaj Dubey u32 pmu_raw_readl(u32 offset) 38bfce552dSPankaj Dubey { 39bfce552dSPankaj Dubey return readl_relaxed(pmu_base_addr + offset); 40bfce552dSPankaj Dubey } 41bfce552dSPankaj Dubey 42bfce552dSPankaj Dubey void exynos_sys_powerdown_conf(enum sys_powerdown mode) 43bfce552dSPankaj Dubey { 44bfce552dSPankaj Dubey unsigned int i; 45bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 46bfce552dSPankaj Dubey 47fa59aa70SMarek Szyprowski if (!pmu_context || !pmu_context->pmu_data) 48bfce552dSPankaj Dubey return; 49bfce552dSPankaj Dubey 50bfce552dSPankaj Dubey pmu_data = pmu_context->pmu_data; 51bfce552dSPankaj Dubey 52bfce552dSPankaj Dubey if (pmu_data->powerdown_conf) 53bfce552dSPankaj Dubey pmu_data->powerdown_conf(mode); 54bfce552dSPankaj Dubey 55bfce552dSPankaj Dubey if (pmu_data->pmu_config) { 56bfce552dSPankaj Dubey for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++) 57bfce552dSPankaj Dubey pmu_raw_writel(pmu_data->pmu_config[i].val[mode], 58bfce552dSPankaj Dubey pmu_data->pmu_config[i].offset); 59bfce552dSPankaj Dubey } 60bfce552dSPankaj Dubey 61bfce552dSPankaj Dubey if (pmu_data->powerdown_conf_extra) 62bfce552dSPankaj Dubey pmu_data->powerdown_conf_extra(mode); 63bfce552dSPankaj Dubey 64bfce552dSPankaj Dubey if (pmu_data->pmu_config_extra) { 65bfce552dSPankaj Dubey for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++) 66bfce552dSPankaj Dubey pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode], 67bfce552dSPankaj Dubey pmu_data->pmu_config_extra[i].offset); 68bfce552dSPankaj Dubey } 69bfce552dSPankaj Dubey } 70bfce552dSPankaj Dubey 71bfce552dSPankaj Dubey /* 72*a0ebf662SKrzysztof Kozlowski * Split the data between ARM architectures because it is relatively big 73*a0ebf662SKrzysztof Kozlowski * and useless on other arch. 74*a0ebf662SKrzysztof Kozlowski */ 75*a0ebf662SKrzysztof Kozlowski #ifdef CONFIG_EXYNOS_PMU_ARM_DRIVERS 76*a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data) (&data) 77*a0ebf662SKrzysztof Kozlowski #else 78*a0ebf662SKrzysztof Kozlowski #define exynos_pmu_data_arm_ptr(data) NULL 79*a0ebf662SKrzysztof Kozlowski #endif 80*a0ebf662SKrzysztof Kozlowski 81*a0ebf662SKrzysztof Kozlowski /* 82bfce552dSPankaj Dubey * PMU platform driver and devicetree bindings. 83bfce552dSPankaj Dubey */ 84bfce552dSPankaj Dubey static const struct of_device_id exynos_pmu_of_device_ids[] = { 85bfce552dSPankaj Dubey { 86bfce552dSPankaj Dubey .compatible = "samsung,exynos3250-pmu", 87*a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos3250_pmu_data), 88bfce552dSPankaj Dubey }, { 89bfce552dSPankaj Dubey .compatible = "samsung,exynos4210-pmu", 90*a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4210_pmu_data), 91bfce552dSPankaj Dubey }, { 92bfce552dSPankaj Dubey .compatible = "samsung,exynos4212-pmu", 93*a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4212_pmu_data), 94bfce552dSPankaj Dubey }, { 95bfce552dSPankaj Dubey .compatible = "samsung,exynos4412-pmu", 96*a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos4412_pmu_data), 97bfce552dSPankaj Dubey }, { 98bfce552dSPankaj Dubey .compatible = "samsung,exynos5250-pmu", 99*a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5250_pmu_data), 100bfce552dSPankaj Dubey }, { 101bfce552dSPankaj Dubey .compatible = "samsung,exynos5420-pmu", 102*a0ebf662SKrzysztof Kozlowski .data = exynos_pmu_data_arm_ptr(exynos5420_pmu_data), 103fa59aa70SMarek Szyprowski }, { 104fa59aa70SMarek Szyprowski .compatible = "samsung,exynos5433-pmu", 105bfce552dSPankaj Dubey }, 106bfce552dSPankaj Dubey { /*sentinel*/ }, 107bfce552dSPankaj Dubey }; 108bfce552dSPankaj Dubey 10976640b84SMarek Szyprowski struct regmap *exynos_get_pmu_regmap(void) 11076640b84SMarek Szyprowski { 11176640b84SMarek Szyprowski struct device_node *np = of_find_matching_node(NULL, 11276640b84SMarek Szyprowski exynos_pmu_of_device_ids); 11376640b84SMarek Szyprowski if (np) 11476640b84SMarek Szyprowski return syscon_node_to_regmap(np); 11576640b84SMarek Szyprowski return ERR_PTR(-ENODEV); 11676640b84SMarek Szyprowski } 11776640b84SMarek Szyprowski EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); 11876640b84SMarek Szyprowski 119bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev) 120bfce552dSPankaj Dubey { 121bfce552dSPankaj Dubey struct device *dev = &pdev->dev; 122bfce552dSPankaj Dubey struct resource *res; 123bfce552dSPankaj Dubey 124bfce552dSPankaj Dubey res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 125bfce552dSPankaj Dubey pmu_base_addr = devm_ioremap_resource(dev, res); 126bfce552dSPankaj Dubey if (IS_ERR(pmu_base_addr)) 127bfce552dSPankaj Dubey return PTR_ERR(pmu_base_addr); 128bfce552dSPankaj Dubey 129bfce552dSPankaj Dubey pmu_context = devm_kzalloc(&pdev->dev, 130bfce552dSPankaj Dubey sizeof(struct exynos_pmu_context), 131bfce552dSPankaj Dubey GFP_KERNEL); 1321da6de33SMarek Szyprowski if (!pmu_context) 133bfce552dSPankaj Dubey return -ENOMEM; 134bfce552dSPankaj Dubey pmu_context->dev = dev; 135ec7cc5b1SMarek Szyprowski pmu_context->pmu_data = of_device_get_match_data(dev); 136bfce552dSPankaj Dubey 137fa59aa70SMarek Szyprowski if (pmu_context->pmu_data && pmu_context->pmu_data->pmu_init) 138bfce552dSPankaj Dubey pmu_context->pmu_data->pmu_init(); 139bfce552dSPankaj Dubey 140bfce552dSPankaj Dubey platform_set_drvdata(pdev, pmu_context); 141bfce552dSPankaj Dubey 142bfce552dSPankaj Dubey dev_dbg(dev, "Exynos PMU Driver probe done\n"); 143bfce552dSPankaj Dubey return 0; 144bfce552dSPankaj Dubey } 145bfce552dSPankaj Dubey 146bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = { 147bfce552dSPankaj Dubey .driver = { 148bfce552dSPankaj Dubey .name = "exynos-pmu", 149bfce552dSPankaj Dubey .of_match_table = exynos_pmu_of_device_ids, 150bfce552dSPankaj Dubey }, 151bfce552dSPankaj Dubey .probe = exynos_pmu_probe, 152bfce552dSPankaj Dubey }; 153bfce552dSPankaj Dubey 154bfce552dSPankaj Dubey static int __init exynos_pmu_init(void) 155bfce552dSPankaj Dubey { 156bfce552dSPankaj Dubey return platform_driver_register(&exynos_pmu_driver); 157bfce552dSPankaj Dubey 158bfce552dSPankaj Dubey } 159bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init); 160