exynos-pmu.c 3.7 KB

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