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> 14*ec7cc5b1SMarek 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 47bfce552dSPankaj Dubey if (!pmu_context) 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 /* 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", 77bfce552dSPankaj Dubey .data = &exynos3250_pmu_data, 78bfce552dSPankaj Dubey }, { 79bfce552dSPankaj Dubey .compatible = "samsung,exynos4210-pmu", 80bfce552dSPankaj Dubey .data = &exynos4210_pmu_data, 81bfce552dSPankaj Dubey }, { 82bfce552dSPankaj Dubey .compatible = "samsung,exynos4212-pmu", 83bfce552dSPankaj Dubey .data = &exynos4212_pmu_data, 84bfce552dSPankaj Dubey }, { 85bfce552dSPankaj Dubey .compatible = "samsung,exynos4412-pmu", 86bfce552dSPankaj Dubey .data = &exynos4412_pmu_data, 87bfce552dSPankaj Dubey }, { 88bfce552dSPankaj Dubey .compatible = "samsung,exynos5250-pmu", 89bfce552dSPankaj Dubey .data = &exynos5250_pmu_data, 90bfce552dSPankaj Dubey }, { 91bfce552dSPankaj Dubey .compatible = "samsung,exynos5420-pmu", 92bfce552dSPankaj Dubey .data = &exynos5420_pmu_data, 93bfce552dSPankaj Dubey }, 94bfce552dSPankaj Dubey { /*sentinel*/ }, 95bfce552dSPankaj Dubey }; 96bfce552dSPankaj Dubey 9776640b84SMarek Szyprowski struct regmap *exynos_get_pmu_regmap(void) 9876640b84SMarek Szyprowski { 9976640b84SMarek Szyprowski struct device_node *np = of_find_matching_node(NULL, 10076640b84SMarek Szyprowski exynos_pmu_of_device_ids); 10176640b84SMarek Szyprowski if (np) 10276640b84SMarek Szyprowski return syscon_node_to_regmap(np); 10376640b84SMarek Szyprowski return ERR_PTR(-ENODEV); 10476640b84SMarek Szyprowski } 10576640b84SMarek Szyprowski EXPORT_SYMBOL_GPL(exynos_get_pmu_regmap); 10676640b84SMarek Szyprowski 107bfce552dSPankaj Dubey static int exynos_pmu_probe(struct platform_device *pdev) 108bfce552dSPankaj Dubey { 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; 125*ec7cc5b1SMarek Szyprowski pmu_context->pmu_data = of_device_get_match_data(dev); 126bfce552dSPankaj Dubey 127bfce552dSPankaj Dubey if (pmu_context->pmu_data->pmu_init) 128bfce552dSPankaj Dubey pmu_context->pmu_data->pmu_init(); 129bfce552dSPankaj Dubey 130bfce552dSPankaj Dubey platform_set_drvdata(pdev, pmu_context); 131bfce552dSPankaj Dubey 132bfce552dSPankaj Dubey dev_dbg(dev, "Exynos PMU Driver probe done\n"); 133bfce552dSPankaj Dubey return 0; 134bfce552dSPankaj Dubey } 135bfce552dSPankaj Dubey 136bfce552dSPankaj Dubey static struct platform_driver exynos_pmu_driver = { 137bfce552dSPankaj Dubey .driver = { 138bfce552dSPankaj Dubey .name = "exynos-pmu", 139bfce552dSPankaj Dubey .of_match_table = exynos_pmu_of_device_ids, 140bfce552dSPankaj Dubey }, 141bfce552dSPankaj Dubey .probe = exynos_pmu_probe, 142bfce552dSPankaj Dubey }; 143bfce552dSPankaj Dubey 144bfce552dSPankaj Dubey static int __init exynos_pmu_init(void) 145bfce552dSPankaj Dubey { 146bfce552dSPankaj Dubey return platform_driver_register(&exynos_pmu_driver); 147bfce552dSPankaj Dubey 148bfce552dSPankaj Dubey } 149bfce552dSPankaj Dubey postcore_initcall(exynos_pmu_init); 150