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> 1476640b84SMarek Szyprowski #include <linux/mfd/syscon.h> 15bfce552dSPankaj Dubey #include <linux/platform_device.h> 16bfce552dSPankaj Dubey #include <linux/delay.h> 17bfce552dSPankaj Dubey 18bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-regs-pmu.h> 19bfce552dSPankaj Dubey #include <linux/soc/samsung/exynos-pmu.h> 20bfce552dSPankaj Dubey 21bfce552dSPankaj Dubey #include "exynos-pmu.h" 22bfce552dSPankaj Dubey 23bfce552dSPankaj Dubey struct exynos_pmu_context { 24bfce552dSPankaj Dubey struct device *dev; 25bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 26bfce552dSPankaj Dubey }; 27bfce552dSPankaj Dubey 28bfce552dSPankaj Dubey void __iomem *pmu_base_addr; 29bfce552dSPankaj Dubey static struct exynos_pmu_context *pmu_context; 30bfce552dSPankaj Dubey 31bfce552dSPankaj Dubey void pmu_raw_writel(u32 val, u32 offset) 32bfce552dSPankaj Dubey { 33bfce552dSPankaj Dubey writel_relaxed(val, pmu_base_addr + offset); 34bfce552dSPankaj Dubey } 35bfce552dSPankaj Dubey 36bfce552dSPankaj Dubey u32 pmu_raw_readl(u32 offset) 37bfce552dSPankaj Dubey { 38bfce552dSPankaj Dubey return readl_relaxed(pmu_base_addr + offset); 39bfce552dSPankaj Dubey } 40bfce552dSPankaj Dubey 41bfce552dSPankaj Dubey void exynos_sys_powerdown_conf(enum sys_powerdown mode) 42bfce552dSPankaj Dubey { 43bfce552dSPankaj Dubey unsigned int i; 44bfce552dSPankaj Dubey const struct exynos_pmu_data *pmu_data; 45bfce552dSPankaj Dubey 46bfce552dSPankaj Dubey if (!pmu_context) 47bfce552dSPankaj Dubey return; 48bfce552dSPankaj Dubey 49bfce552dSPankaj Dubey pmu_data = pmu_context->pmu_data; 50bfce552dSPankaj Dubey 51bfce552dSPankaj Dubey if (pmu_data->powerdown_conf) 52bfce552dSPankaj Dubey pmu_data->powerdown_conf(mode); 53bfce552dSPankaj Dubey 54bfce552dSPankaj Dubey if (pmu_data->pmu_config) { 55bfce552dSPankaj Dubey for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++) 56bfce552dSPankaj Dubey pmu_raw_writel(pmu_data->pmu_config[i].val[mode], 57bfce552dSPankaj Dubey pmu_data->pmu_config[i].offset); 58bfce552dSPankaj Dubey } 59bfce552dSPankaj Dubey 60bfce552dSPankaj Dubey if (pmu_data->powerdown_conf_extra) 61bfce552dSPankaj Dubey pmu_data->powerdown_conf_extra(mode); 62bfce552dSPankaj Dubey 63bfce552dSPankaj Dubey if (pmu_data->pmu_config_extra) { 64bfce552dSPankaj Dubey for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++) 65bfce552dSPankaj Dubey pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode], 66bfce552dSPankaj Dubey pmu_data->pmu_config_extra[i].offset); 67bfce552dSPankaj Dubey } 68bfce552dSPankaj Dubey } 69bfce552dSPankaj Dubey 70bfce552dSPankaj Dubey /* 71bfce552dSPankaj Dubey * PMU platform driver and devicetree bindings. 72bfce552dSPankaj Dubey */ 73bfce552dSPankaj Dubey static const struct of_device_id exynos_pmu_of_device_ids[] = { 74bfce552dSPankaj Dubey { 75bfce552dSPankaj Dubey .compatible = "samsung,exynos3250-pmu", 76bfce552dSPankaj Dubey .data = &exynos3250_pmu_data, 77bfce552dSPankaj Dubey }, { 78bfce552dSPankaj Dubey .compatible = "samsung,exynos4210-pmu", 79bfce552dSPankaj Dubey .data = &exynos4210_pmu_data, 80bfce552dSPankaj Dubey }, { 81bfce552dSPankaj Dubey .compatible = "samsung,exynos4212-pmu", 82bfce552dSPankaj Dubey .data = &exynos4212_pmu_data, 83bfce552dSPankaj Dubey }, { 84bfce552dSPankaj Dubey .compatible = "samsung,exynos4412-pmu", 85bfce552dSPankaj Dubey .data = &exynos4412_pmu_data, 86bfce552dSPankaj Dubey }, { 87bfce552dSPankaj Dubey .compatible = "samsung,exynos5250-pmu", 88bfce552dSPankaj Dubey .data = &exynos5250_pmu_data, 89bfce552dSPankaj Dubey }, { 90bfce552dSPankaj Dubey .compatible = "samsung,exynos5420-pmu", 91bfce552dSPankaj Dubey .data = &exynos5420_pmu_data, 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 const struct of_device_id *match; 109bfce552dSPankaj Dubey struct device *dev = &pdev->dev; 110bfce552dSPankaj Dubey struct resource *res; 111bfce552dSPankaj Dubey 112bfce552dSPankaj Dubey res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 113bfce552dSPankaj Dubey pmu_base_addr = devm_ioremap_resource(dev, res); 114bfce552dSPankaj Dubey if (IS_ERR(pmu_base_addr)) 115bfce552dSPankaj Dubey return PTR_ERR(pmu_base_addr); 116bfce552dSPankaj Dubey 117bfce552dSPankaj Dubey pmu_context = devm_kzalloc(&pdev->dev, 118bfce552dSPankaj Dubey sizeof(struct exynos_pmu_context), 119bfce552dSPankaj Dubey GFP_KERNEL); 120bfce552dSPankaj Dubey if (!pmu_context) { 121bfce552dSPankaj Dubey dev_err(dev, "Cannot allocate memory.\n"); 122bfce552dSPankaj Dubey return -ENOMEM; 123bfce552dSPankaj Dubey } 124bfce552dSPankaj Dubey pmu_context->dev = dev; 125bfce552dSPankaj Dubey 126bfce552dSPankaj Dubey match = of_match_node(exynos_pmu_of_device_ids, dev->of_node); 127bfce552dSPankaj Dubey 128bfce552dSPankaj Dubey pmu_context->pmu_data = match->data; 129bfce552dSPankaj Dubey 130bfce552dSPankaj Dubey if (pmu_context->pmu_data->pmu_init) 131bfce552dSPankaj Dubey pmu_context->pmu_data->pmu_init(); 132bfce552dSPankaj Dubey 133bfce552dSPankaj Dubey platform_set_drvdata(pdev, pmu_context); 134bfce552dSPankaj Dubey 135bfce552dSPankaj Dubey dev_dbg(dev, "Exynos PMU Driver probe done\n"); 136bfce552dSPankaj Dubey return 0; 137bfce552dSPankaj Dubey } 138bfce552dSPankaj Dubey 139bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = { 140bfce552dSPankaj Dubey .driver = { 141bfce552dSPankaj Dubey .name = "exynos-pmu", 142bfce552dSPankaj Dubey .of_match_table = exynos_pmu_of_device_ids, 143bfce552dSPankaj Dubey }, 144bfce552dSPankaj Dubey .probe = exynos_pmu_probe, 145bfce552dSPankaj Dubey }; 146bfce552dSPankaj Dubey 147bfce552dSPankaj Dubey static int __init exynos_pmu_init(void) 148bfce552dSPankaj Dubey { 149bfce552dSPankaj Dubey return platform_driver_register(&exynos_pmu_driver); 150bfce552dSPankaj Dubey 151bfce552dSPankaj Dubey } 152bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init); 153