s5p_mfc_pm.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 = -ENOENT;
  38. goto err_g_ip_clk;
  39. }
  40. pm->clock = clk_get(&dev->plat_dev->dev, MFC_CLKNAME);
  41. if (IS_ERR(pm->clock)) {
  42. mfc_err("Failed to get MFC clock\n");
  43. ret = -ENOENT;
  44. goto err_g_ip_clk_2;
  45. }
  46. atomic_set(&pm->power, 0);
  47. #ifdef CONFIG_PM_RUNTIME
  48. pm->device = &dev->plat_dev->dev;
  49. pm_runtime_enable(pm->device);
  50. #endif
  51. #ifdef CLK_DEBUG
  52. atomic_set(&clk_ref, 0);
  53. #endif
  54. return 0;
  55. err_g_ip_clk_2:
  56. clk_put(pm->clock_gate);
  57. err_g_ip_clk:
  58. return ret;
  59. }
  60. void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
  61. {
  62. clk_put(pm->clock_gate);
  63. clk_put(pm->clock);
  64. #ifdef CONFIG_PM_RUNTIME
  65. pm_runtime_disable(pm->device);
  66. #endif
  67. }
  68. int s5p_mfc_clock_on(void)
  69. {
  70. int ret;
  71. #ifdef CLK_DEBUG
  72. atomic_inc(&clk_ref);
  73. mfc_debug(3, "+ %d", atomic_read(&clk_ref));
  74. #endif
  75. ret = clk_enable(pm->clock_gate);
  76. return ret;
  77. }
  78. void s5p_mfc_clock_off(void)
  79. {
  80. #ifdef CLK_DEBUG
  81. atomic_dec(&clk_ref);
  82. mfc_debug(3, "- %d", atomic_read(&clk_ref));
  83. #endif
  84. clk_disable(pm->clock_gate);
  85. }
  86. int s5p_mfc_power_on(void)
  87. {
  88. #ifdef CONFIG_PM_RUNTIME
  89. return pm_runtime_get_sync(pm->device);
  90. #else
  91. atomic_set(&pm->power, 1);
  92. return 0;
  93. #endif
  94. }
  95. int s5p_mfc_power_off(void)
  96. {
  97. #ifdef CONFIG_PM_RUNTIME
  98. return pm_runtime_put_sync(pm->device);
  99. #else
  100. atomic_set(&pm->power, 0);
  101. return 0;
  102. #endif
  103. }