exynos-pmu.c 4.0 KB

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