exynos-pmu.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/platform_device.h>
  14. #include <linux/delay.h>
  15. #include <linux/soc/samsung/exynos-regs-pmu.h>
  16. #include <linux/soc/samsung/exynos-pmu.h>
  17. #include "exynos-pmu.h"
  18. struct exynos_pmu_context {
  19. struct device *dev;
  20. const struct exynos_pmu_data *pmu_data;
  21. };
  22. void __iomem *pmu_base_addr;
  23. static struct exynos_pmu_context *pmu_context;
  24. void pmu_raw_writel(u32 val, u32 offset)
  25. {
  26. writel_relaxed(val, pmu_base_addr + offset);
  27. }
  28. u32 pmu_raw_readl(u32 offset)
  29. {
  30. return readl_relaxed(pmu_base_addr + offset);
  31. }
  32. void exynos_sys_powerdown_conf(enum sys_powerdown mode)
  33. {
  34. unsigned int i;
  35. const struct exynos_pmu_data *pmu_data;
  36. if (!pmu_context)
  37. return;
  38. pmu_data = pmu_context->pmu_data;
  39. if (pmu_data->powerdown_conf)
  40. pmu_data->powerdown_conf(mode);
  41. if (pmu_data->pmu_config) {
  42. for (i = 0; (pmu_data->pmu_config[i].offset != PMU_TABLE_END); i++)
  43. pmu_raw_writel(pmu_data->pmu_config[i].val[mode],
  44. pmu_data->pmu_config[i].offset);
  45. }
  46. if (pmu_data->powerdown_conf_extra)
  47. pmu_data->powerdown_conf_extra(mode);
  48. if (pmu_data->pmu_config_extra) {
  49. for (i = 0; pmu_data->pmu_config_extra[i].offset != PMU_TABLE_END; i++)
  50. pmu_raw_writel(pmu_data->pmu_config_extra[i].val[mode],
  51. pmu_data->pmu_config_extra[i].offset);
  52. }
  53. }
  54. /*
  55. * PMU platform driver and devicetree bindings.
  56. */
  57. static const struct of_device_id exynos_pmu_of_device_ids[] = {
  58. {
  59. .compatible = "samsung,exynos3250-pmu",
  60. .data = &exynos3250_pmu_data,
  61. }, {
  62. .compatible = "samsung,exynos4210-pmu",
  63. .data = &exynos4210_pmu_data,
  64. }, {
  65. .compatible = "samsung,exynos4212-pmu",
  66. .data = &exynos4212_pmu_data,
  67. }, {
  68. .compatible = "samsung,exynos4412-pmu",
  69. .data = &exynos4412_pmu_data,
  70. }, {
  71. .compatible = "samsung,exynos5250-pmu",
  72. .data = &exynos5250_pmu_data,
  73. }, {
  74. .compatible = "samsung,exynos5420-pmu",
  75. .data = &exynos5420_pmu_data,
  76. },
  77. { /*sentinel*/ },
  78. };
  79. static int exynos_pmu_probe(struct platform_device *pdev)
  80. {
  81. const struct of_device_id *match;
  82. struct device *dev = &pdev->dev;
  83. struct resource *res;
  84. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  85. pmu_base_addr = devm_ioremap_resource(dev, res);
  86. if (IS_ERR(pmu_base_addr))
  87. return PTR_ERR(pmu_base_addr);
  88. pmu_context = devm_kzalloc(&pdev->dev,
  89. sizeof(struct exynos_pmu_context),
  90. GFP_KERNEL);
  91. if (!pmu_context) {
  92. dev_err(dev, "Cannot allocate memory.\n");
  93. return -ENOMEM;
  94. }
  95. pmu_context->dev = dev;
  96. match = of_match_node(exynos_pmu_of_device_ids, dev->of_node);
  97. pmu_context->pmu_data = match->data;
  98. if (pmu_context->pmu_data->pmu_init)
  99. pmu_context->pmu_data->pmu_init();
  100. platform_set_drvdata(pdev, pmu_context);
  101. dev_dbg(dev, "Exynos PMU Driver probe done\n");
  102. return 0;
  103. }
  104. static struct platform_driver exynos_pmu_driver = {
  105. .driver = {
  106. .name = "exynos-pmu",
  107. .of_match_table = exynos_pmu_of_device_ids,
  108. },
  109. .probe = exynos_pmu_probe,
  110. };
  111. static int __init exynos_pmu_init(void)
  112. {
  113. return platform_driver_register(&exynos_pmu_driver);
  114. }
  115. postcore_initcall(exynos_pmu_init);