s5p_mfc_pm.c 2.7 KB

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