s5p_mfc_pm.c 2.8 KB

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