s5p_mfc_pm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * linux/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
  3. *
  4. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com/
  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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/err.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/pm_runtime.h>
  16. #include "s5p_mfc_common.h"
  17. #include "s5p_mfc_debug.h"
  18. #include "s5p_mfc_pm.h"
  19. #define MFC_GATE_CLK_NAME "mfc"
  20. #define MFC_SCLK_NAME "sclk_mfc"
  21. #define MFC_SCLK_RATE (200 * 1000000)
  22. #define CLK_DEBUG
  23. static struct s5p_mfc_pm *pm;
  24. static struct s5p_mfc_dev *p_dev;
  25. #ifdef CLK_DEBUG
  26. static atomic_t clk_ref;
  27. #endif
  28. int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
  29. {
  30. int ret = 0;
  31. pm = &dev->pm;
  32. p_dev = dev;
  33. pm->clock_gate = clk_get(&dev->plat_dev->dev, MFC_GATE_CLK_NAME);
  34. if (IS_ERR(pm->clock_gate)) {
  35. mfc_err("Failed to get clock-gating control\n");
  36. ret = PTR_ERR(pm->clock_gate);
  37. goto err_g_ip_clk;
  38. }
  39. ret = clk_prepare(pm->clock_gate);
  40. if (ret) {
  41. mfc_err("Failed to prepare clock-gating control\n");
  42. goto err_p_ip_clk;
  43. }
  44. if (dev->variant->version != MFC_VERSION_V6) {
  45. pm->clock = clk_get(&dev->plat_dev->dev, MFC_SCLK_NAME);
  46. if (IS_ERR(pm->clock)) {
  47. mfc_info("Failed to get MFC special clock control\n");
  48. pm->clock = NULL;
  49. } else {
  50. clk_set_rate(pm->clock, MFC_SCLK_RATE);
  51. ret = clk_prepare_enable(pm->clock);
  52. if (ret) {
  53. mfc_err("Failed to enable MFC special clock\n");
  54. goto err_s_clk;
  55. }
  56. }
  57. }
  58. atomic_set(&pm->power, 0);
  59. #ifdef CONFIG_PM
  60. pm->device = &dev->plat_dev->dev;
  61. pm_runtime_enable(pm->device);
  62. #endif
  63. #ifdef CLK_DEBUG
  64. atomic_set(&clk_ref, 0);
  65. #endif
  66. return 0;
  67. err_s_clk:
  68. clk_put(pm->clock);
  69. pm->clock = NULL;
  70. err_p_ip_clk:
  71. clk_put(pm->clock_gate);
  72. pm->clock_gate = NULL;
  73. err_g_ip_clk:
  74. return ret;
  75. }
  76. void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
  77. {
  78. if (dev->variant->version != MFC_VERSION_V6 &&
  79. pm->clock) {
  80. clk_disable_unprepare(pm->clock);
  81. clk_put(pm->clock);
  82. pm->clock = NULL;
  83. }
  84. clk_unprepare(pm->clock_gate);
  85. clk_put(pm->clock_gate);
  86. pm->clock_gate = NULL;
  87. #ifdef CONFIG_PM
  88. pm_runtime_disable(pm->device);
  89. #endif
  90. }
  91. int s5p_mfc_clock_on(void)
  92. {
  93. int ret = 0;
  94. #ifdef CLK_DEBUG
  95. atomic_inc(&clk_ref);
  96. mfc_debug(3, "+ %d\n", atomic_read(&clk_ref));
  97. #endif
  98. if (!IS_ERR_OR_NULL(pm->clock_gate))
  99. ret = clk_enable(pm->clock_gate);
  100. return ret;
  101. }
  102. void s5p_mfc_clock_off(void)
  103. {
  104. #ifdef CLK_DEBUG
  105. atomic_dec(&clk_ref);
  106. mfc_debug(3, "- %d\n", atomic_read(&clk_ref));
  107. #endif
  108. if (!IS_ERR_OR_NULL(pm->clock_gate))
  109. clk_disable(pm->clock_gate);
  110. }
  111. int s5p_mfc_power_on(void)
  112. {
  113. #ifdef CONFIG_PM
  114. return pm_runtime_get_sync(pm->device);
  115. #else
  116. atomic_set(&pm->power, 1);
  117. return 0;
  118. #endif
  119. }
  120. int s5p_mfc_power_off(void)
  121. {
  122. #ifdef CONFIG_PM
  123. return pm_runtime_put_sync(pm->device);
  124. #else
  125. atomic_set(&pm->power, 0);
  126. return 0;
  127. #endif
  128. }