exynos-pmu.c 4.0 KB

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