lcm_util.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #if defined(MTK_LCM_DEVICE_TREE_SUPPORT)
  2. #include <linux/string.h>
  3. #include <linux/wait.h>
  4. #include "lcm_define.h"
  5. #include "lcm_drv.h"
  6. #include "lcm_util.h"
  7. static LCM_STATUS _lcm_util_check_data(char type, const LCM_DATA_T1 *t1)
  8. {
  9. switch (type) {
  10. case LCM_UTIL_RESET:
  11. switch (t1->data) {
  12. case LCM_UTIL_RESET_LOW:
  13. case LCM_UTIL_RESET_HIGH:
  14. break;
  15. default:
  16. return LCM_STATUS_ERROR;
  17. }
  18. break;
  19. case LCM_UTIL_MDELAY:
  20. case LCM_UTIL_UDELAY:
  21. case LCM_UTIL_RAR:
  22. /* no limitation */
  23. break;
  24. default:
  25. return LCM_STATUS_ERROR;
  26. }
  27. return LCM_STATUS_OK;
  28. }
  29. static LCM_STATUS _lcm_util_check_write_cmd_v1(const LCM_DATA_T5 *t5)
  30. {
  31. if (t5 == NULL)
  32. return LCM_STATUS_ERROR;
  33. if (t5->cmd == NULL)
  34. return LCM_STATUS_ERROR;
  35. if (t5->size == 0)
  36. return LCM_STATUS_ERROR;
  37. return LCM_STATUS_OK;
  38. }
  39. static LCM_STATUS _lcm_util_check_write_cmd_v2(const LCM_DATA_T3 *t3)
  40. {
  41. if (t3 == NULL)
  42. return LCM_STATUS_ERROR;
  43. if ((t3->size > 0) && (t3->data == NULL))
  44. return LCM_STATUS_ERROR;
  45. return LCM_STATUS_OK;
  46. }
  47. static LCM_STATUS _lcm_util_check_read_cmd_v2(const LCM_DATA_T4 *t4)
  48. {
  49. if (t4 == NULL)
  50. return LCM_STATUS_ERROR;
  51. return LCM_STATUS_OK;
  52. }
  53. LCM_STATUS lcm_util_set_data(const LCM_UTIL_FUNCS *lcm_util, char type, LCM_DATA_T1 *t1)
  54. {
  55. /* check parameter is valid */
  56. if (LCM_STATUS_OK == _lcm_util_check_data(type, t1)) {
  57. switch (type) {
  58. case LCM_UTIL_RESET:
  59. lcm_util->set_reset_pin((unsigned int)t1->data);
  60. break;
  61. case LCM_UTIL_MDELAY:
  62. lcm_util->mdelay((unsigned int)t1->data);
  63. break;
  64. case LCM_UTIL_UDELAY:
  65. lcm_util->udelay((unsigned int)t1->data);
  66. break;
  67. case LCM_UTIL_RAR:
  68. lcm_util->rar((unsigned int)t1->data);
  69. break;
  70. default:
  71. pr_debug("[LCM][ERROR] %s/%d: %d\n", __func__, __LINE__, type);
  72. return LCM_STATUS_ERROR;
  73. }
  74. } else {
  75. pr_debug("[LCM][ERROR] %s/%d: 0x%x, 0x%x\n", __func__, __LINE__, type, t1->data);
  76. return LCM_STATUS_ERROR;
  77. }
  78. return LCM_STATUS_OK;
  79. }
  80. LCM_STATUS lcm_util_set_write_cmd_v1(const LCM_UTIL_FUNCS *lcm_util, LCM_DATA_T5 *t5,
  81. unsigned char force_update)
  82. {
  83. unsigned int i;
  84. unsigned int cmd[32];
  85. /* check parameter is valid */
  86. if (LCM_STATUS_OK == _lcm_util_check_write_cmd_v1(t5)) {
  87. memset(cmd, 0x0, sizeof(unsigned int) * 32);
  88. for (i = 0; i < t5->size; i++)
  89. cmd[i] = (t5->cmd[i * 4 + 3] << 24)
  90. | (t5->cmd[i * 4 + 2] << 16)
  91. | (t5->cmd[i * 4 + 1] << 8)
  92. | (t5->cmd[i * 4]);
  93. lcm_util->dsi_set_cmdq(cmd, (unsigned int)t5->size, force_update);
  94. } else {
  95. pr_debug("[LCM][ERROR] %s/%d: 0x%p, %d\n", __func__, __LINE__, t5->cmd, t5->size);
  96. return LCM_STATUS_ERROR;
  97. }
  98. return LCM_STATUS_OK;
  99. }
  100. LCM_STATUS lcm_util_set_write_cmd_v2(const LCM_UTIL_FUNCS *lcm_util, LCM_DATA_T3 *t3,
  101. unsigned char force_update)
  102. {
  103. /* check parameter is valid */
  104. if (LCM_STATUS_OK == _lcm_util_check_write_cmd_v2(t3)) {
  105. if (t3->cmd == LCM_UTIL_WRITE_CMD_V2_NULL) {
  106. lcm_util->dsi_set_null((unsigned char)t3->cmd, (unsigned char)t3->size,
  107. (unsigned char *)t3->data, force_update);
  108. } else {
  109. lcm_util->dsi_set_cmdq_V2((unsigned char)t3->cmd, (unsigned char)t3->size,
  110. (unsigned char *)t3->data, force_update);
  111. }
  112. } else {
  113. pr_debug("[LCM][ERROR] %s/%d: 0x%x, %d, 0x%p\n", __func__, __LINE__, t3->cmd,
  114. t3->size, t3->data);
  115. return LCM_STATUS_ERROR;
  116. }
  117. return LCM_STATUS_OK;
  118. }
  119. LCM_STATUS lcm_util_set_read_cmd_v2(const LCM_UTIL_FUNCS *lcm_util, LCM_DATA_T4 *t4,
  120. unsigned int *compare)
  121. {
  122. if (compare == NULL) {
  123. pr_debug("[LCM][ERROR] %s/%d: NULL parameter\n", __func__, __LINE__);
  124. return LCM_STATUS_ERROR;
  125. }
  126. *compare = 0;
  127. /* check parameter is valid */
  128. if (LCM_STATUS_OK == _lcm_util_check_read_cmd_v2(t4)) {
  129. unsigned char buffer[4];
  130. lcm_util->dsi_dcs_read_lcm_reg_v2((unsigned char)t4->cmd, buffer, 4);
  131. if (buffer[(unsigned int)t4->location] == ((unsigned char)t4->data))
  132. *compare = 1;
  133. } else {
  134. pr_debug("[LCM][ERROR] %s/%d: 0x%x, %d, 0x%x\n", __func__, __LINE__, t4->cmd,
  135. t4->location, t4->data);
  136. return LCM_STATUS_ERROR;
  137. }
  138. return LCM_STATUS_OK;
  139. }
  140. #endif