mtk_drm_arr.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <linux/mutex.h>
  2. #include "mtk_drm_arr.h"
  3. #include "mtk_log.h"
  4. static DEFINE_MUTEX(cb_table_lock);
  5. #define DISP_MAX_FPSCHG_CALLBACK 5
  6. static FPS_CHG_CALLBACK fps_chg_callback_table[DISP_MAX_FPSCHG_CALLBACK];
  7. /****************ARR function start************************/
  8. int drm_register_fps_chg_callback(FPS_CHG_CALLBACK fps_chg_cb)
  9. {
  10. int ret = 0;
  11. int i = 0;
  12. int j = 0;
  13. mutex_lock(&cb_table_lock);
  14. for (i = 0; i < DISP_MAX_FPSCHG_CALLBACK; i++) {
  15. if (fps_chg_callback_table[i] == fps_chg_cb) {
  16. DDPMSG("[fps]:%s re-register cb\n",
  17. __func__);
  18. mutex_unlock(&cb_table_lock);
  19. return ret;
  20. }
  21. }
  22. for (j = 0; j < DISP_MAX_FPSCHG_CALLBACK; j++) {
  23. if (fps_chg_callback_table[j] == NULL) {
  24. fps_chg_callback_table[j] = fps_chg_cb;
  25. DDPMSG("[fps]: %s, entry[%d] done!\n", __func__, j);
  26. break;
  27. }
  28. }
  29. if (j == DISP_MAX_FPSCHG_CALLBACK) {
  30. DDPPR_ERR("[fps]: %s no entries left for new cb!\n", __func__);
  31. ret = -1;
  32. }
  33. mutex_unlock(&cb_table_lock);
  34. return ret;
  35. }
  36. int drm_unregister_fps_chg_callback(FPS_CHG_CALLBACK fps_chg_cb)
  37. {
  38. int ret = 0;
  39. int i = 0;
  40. mutex_lock(&cb_table_lock);
  41. for (i = 0; i < DISP_MAX_FPSCHG_CALLBACK; i++) {
  42. if (fps_chg_callback_table[i] == fps_chg_cb) {
  43. fps_chg_callback_table[i] = NULL;
  44. DDPMSG("[fps]: %s, register cb %p\n",
  45. __func__, fps_chg_cb);
  46. }
  47. }
  48. if (i == DISP_MAX_FPSCHG_CALLBACK) {
  49. DDPPR_ERR("[fps]: %s, haven't registered cb %p\n",
  50. __func__, fps_chg_cb);
  51. ret = -1;
  52. }
  53. mutex_unlock(&cb_table_lock);
  54. return ret;
  55. }
  56. void drm_invoke_fps_chg_callbacks(unsigned int new_fps)
  57. {
  58. unsigned int i = 0;
  59. DDPMSG("[fps]: %s,new_fps =%d\n", __func__, new_fps);
  60. mutex_lock(&cb_table_lock);
  61. for (i = 0; i < DISP_MAX_FPSCHG_CALLBACK; i++) {
  62. if (fps_chg_callback_table[i]) {
  63. fps_chg_callback_table[i](new_fps);
  64. DDPINFO("%s callback %u\n", __func__, i);
  65. }
  66. }
  67. mutex_unlock(&cb_table_lock);
  68. }