extd_factory.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #include <linux/delay.h>
  2. #include <asm/uaccess.h>
  3. #include "extd_log.h"
  4. #include "extd_factory.h"
  5. #include "extd_info.h"
  6. #include "external_display.h"
  7. #include "dpi_dvt_test.h"
  8. #if defined(CONFIG_MTK_HDMI_SUPPORT)
  9. static struct HDMI_DRIVER *hdmi_tx_drv;
  10. static int is_context_inited;
  11. disp_ddp_path_config hdmi_factory_dpi_params;
  12. struct DPI_PARAM_CONTEXT DPI_Params_Context;
  13. typedef struct _hdmi_factory_context {
  14. bool hdmi_factory_inited;
  15. bool hdmi_callback_returned;
  16. } hdmi_factory_context;
  17. static hdmi_factory_context *_get_context(void)
  18. {
  19. static hdmi_factory_context g_context;
  20. if (!is_context_inited) {
  21. memset((void *)&g_context, 0, sizeof(hdmi_factory_context));
  22. is_context_inited = 1;
  23. EXTD_FACTORY_LOG("[hdmi]_get_context set is_context_inited\n");
  24. }
  25. return &g_context;
  26. }
  27. #define pgc _get_context()
  28. static void hdmi_factory_callback(enum HDMI_STATE state)
  29. {
  30. EXTD_FACTORY_LOG("[hdmi]hdmi_factory_callback, state: %d\n", state);
  31. pgc->hdmi_callback_returned = state;
  32. }
  33. int hdmi_factory_mode_init(void)
  34. {
  35. EXTD_FACTORY_FUNC();
  36. hdmi_tx_drv = (struct HDMI_DRIVER *) HDMI_GetDriver();
  37. if (NULL == hdmi_tx_drv) {
  38. EXTD_FACTORY_ERR("[hdmi]%s, hdmi_init fail, can not get hdmi driver handle\n", __func__);
  39. return -1;
  40. }
  41. hdmi_tx_drv->register_callback(hdmi_factory_callback);
  42. pgc->hdmi_factory_inited = true;
  43. return 0;
  44. }
  45. void hdmi_factory_dpi_parameters(int arg, int io_driving)
  46. {
  47. enum HDMI_POLARITY clk_pol = HDMI_POLARITY_RISING, de_pol = HDMI_POLARITY_RISING,
  48. hsync_pol = HDMI_POLARITY_RISING, vsync_pol = HDMI_POLARITY_RISING;
  49. unsigned int dpi_clock = 0;
  50. unsigned int dpi_clk_div = 0, hsync_pulse_width = 0, hsync_back_porch = 0, hsync_front_porch = 0;
  51. unsigned int vsync_pulse_width = 0, vsync_back_porch = 0, vsync_front_porch = 0;
  52. switch (arg) {
  53. case HDMI_VIDEO_720x480p_60Hz:
  54. {
  55. clk_pol = HDMI_POLARITY_FALLING;
  56. de_pol = HDMI_POLARITY_RISING;
  57. hsync_pol = HDMI_POLARITY_RISING;
  58. vsync_pol = HDMI_POLARITY_RISING;
  59. dpi_clk_div = 2;
  60. hsync_pulse_width = 62;
  61. hsync_back_porch = 60;
  62. hsync_front_porch = 16;
  63. vsync_pulse_width = 6;
  64. vsync_back_porch = 30;
  65. vsync_front_porch = 9;
  66. DPI_Params_Context.bg_height = ((480 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  67. DPI_Params_Context.bg_width = ((720 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  68. DPI_Params_Context.hdmi_width = 720 - DPI_Params_Context.bg_width;
  69. DPI_Params_Context.hdmi_height = 480 - DPI_Params_Context.bg_height;
  70. DPI_Params_Context.output_video_resolution = HDMI_VIDEO_720x480p_60Hz;
  71. dpi_clock = 27027;
  72. break;
  73. }
  74. case HDMI_VIDEO_1280x720p_60Hz:
  75. {
  76. clk_pol = HDMI_POLARITY_FALLING;
  77. de_pol = HDMI_POLARITY_RISING;
  78. hsync_pol = HDMI_POLARITY_FALLING;
  79. vsync_pol = HDMI_POLARITY_FALLING;
  80. dpi_clk_div = 2;
  81. hsync_pulse_width = 40;
  82. hsync_back_porch = 220;
  83. hsync_front_porch = 110;
  84. vsync_pulse_width = 5;
  85. vsync_back_porch = 20;
  86. vsync_front_porch = 5;
  87. dpi_clock = 74250;
  88. DPI_Params_Context.bg_height = ((720 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  89. DPI_Params_Context.bg_width = ((1280 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  90. DPI_Params_Context.hdmi_width = 1280 - DPI_Params_Context.bg_width;
  91. DPI_Params_Context.hdmi_height = 720 - DPI_Params_Context.bg_height;
  92. DPI_Params_Context.output_video_resolution = HDMI_VIDEO_1280x720p_60Hz;
  93. break;
  94. }
  95. case HDMI_VIDEO_1920x1080p_30Hz:
  96. {
  97. clk_pol = HDMI_POLARITY_FALLING;
  98. de_pol = HDMI_POLARITY_RISING;
  99. hsync_pol = HDMI_POLARITY_FALLING;
  100. vsync_pol = HDMI_POLARITY_FALLING;
  101. dpi_clk_div = 2;
  102. hsync_pulse_width = 44;
  103. hsync_back_porch = 148;
  104. hsync_front_porch = 88;
  105. vsync_pulse_width = 5;
  106. vsync_back_porch = 36;
  107. vsync_front_porch = 4;
  108. DPI_Params_Context.bg_height = ((1080 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  109. DPI_Params_Context.bg_width = ((1920 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  110. DPI_Params_Context.hdmi_width = 1920 - DPI_Params_Context.bg_width;
  111. DPI_Params_Context.hdmi_height = 1080 - DPI_Params_Context.bg_height;
  112. DPI_Params_Context.output_video_resolution = HDMI_VIDEO_1920x1080p_30Hz;
  113. dpi_clock = 74250;
  114. break;
  115. }
  116. case HDMI_VIDEO_1920x1080p_60Hz:
  117. {
  118. clk_pol = HDMI_POLARITY_FALLING;
  119. de_pol = HDMI_POLARITY_RISING;
  120. hsync_pol = HDMI_POLARITY_FALLING;
  121. vsync_pol = HDMI_POLARITY_FALLING;
  122. dpi_clk_div = 2;
  123. hsync_pulse_width = 44;
  124. hsync_back_porch = 148;
  125. hsync_front_porch = 88;
  126. vsync_pulse_width = 5;
  127. vsync_back_porch = 36;
  128. vsync_front_porch = 4;
  129. DPI_Params_Context.bg_height = ((1080 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  130. DPI_Params_Context.bg_width = ((1920 * DPI_Params_Context.scaling_factor) / 100 >> 2) << 2;
  131. DPI_Params_Context.hdmi_width = 1920 - DPI_Params_Context.bg_width;
  132. DPI_Params_Context.hdmi_height = 1080 - DPI_Params_Context.bg_height;
  133. DPI_Params_Context.output_video_resolution = HDMI_VIDEO_1920x1080p_60Hz;
  134. dpi_clock = 148500;
  135. break;
  136. }
  137. default:
  138. break;
  139. }
  140. hdmi_factory_dpi_params.dispif_config.dpi.width = DPI_Params_Context.hdmi_width;
  141. hdmi_factory_dpi_params.dispif_config.dpi.height = DPI_Params_Context.hdmi_height;
  142. hdmi_factory_dpi_params.dispif_config.dpi.bg_width = DPI_Params_Context.bg_width;
  143. hdmi_factory_dpi_params.dispif_config.dpi.bg_height = DPI_Params_Context.bg_height;
  144. hdmi_factory_dpi_params.dispif_config.dpi.clk_pol = clk_pol;
  145. hdmi_factory_dpi_params.dispif_config.dpi.de_pol = de_pol;
  146. hdmi_factory_dpi_params.dispif_config.dpi.vsync_pol = vsync_pol;
  147. hdmi_factory_dpi_params.dispif_config.dpi.hsync_pol = hsync_pol;
  148. hdmi_factory_dpi_params.dispif_config.dpi.hsync_pulse_width = hsync_pulse_width;
  149. hdmi_factory_dpi_params.dispif_config.dpi.hsync_back_porch = hsync_back_porch;
  150. hdmi_factory_dpi_params.dispif_config.dpi.hsync_front_porch = hsync_front_porch;
  151. hdmi_factory_dpi_params.dispif_config.dpi.vsync_pulse_width = vsync_pulse_width;
  152. hdmi_factory_dpi_params.dispif_config.dpi.vsync_back_porch = vsync_back_porch;
  153. hdmi_factory_dpi_params.dispif_config.dpi.vsync_front_porch = vsync_front_porch;
  154. hdmi_factory_dpi_params.dispif_config.dpi.format = 0;
  155. hdmi_factory_dpi_params.dispif_config.dpi.rgb_order = 0;
  156. hdmi_factory_dpi_params.dispif_config.dpi.i2x_en = true;
  157. hdmi_factory_dpi_params.dispif_config.dpi.i2x_edge = 2;
  158. hdmi_factory_dpi_params.dispif_config.dpi.embsync = false;
  159. hdmi_factory_dpi_params.dispif_config.dpi.io_driving_current = (LCM_DRIVING_CURRENT) io_driving;
  160. hdmi_factory_dpi_params.dispif_config.dpi.dpi_clock = dpi_clock;
  161. EXTD_FACTORY_LOG("[hdmi]hdmi_factory_dpi_parameters:%d\n", arg);
  162. }
  163. int hdmi_factory_mode_test(enum HDMI_FACTORY_TEST test_step, void *info)
  164. {
  165. int ret = 0;
  166. if (pgc->hdmi_factory_inited == false)
  167. hdmi_factory_mode_init();
  168. switch (test_step) {
  169. case STEP1_CHIP_INIT:
  170. {
  171. EXTD_FACTORY_LOG("[hdmi] STEP1_CHIP_INIT\n");
  172. hdmi_tx_drv->power_on();
  173. hdmi_tx_drv->audio_enable(1);
  174. break;
  175. }
  176. case STEP2_JUDGE_CALLBACK:
  177. {
  178. int hdmi_status = (int)pgc->hdmi_callback_returned;
  179. EXTD_FACTORY_LOG("[hdmi] STEP2_JUDGE_CALLBACK: %d\n", pgc->hdmi_callback_returned);
  180. if (copy_to_user(info, &hdmi_status, sizeof(hdmi_status))) {
  181. EXTD_FACTORY_ERR("[HDMI]copy_to_user failed! line:%d\n", __LINE__);
  182. ret = -1;
  183. }
  184. break;
  185. }
  186. case STEP3_START_DPI_AND_CONFIG:
  187. {
  188. /*
  189. * test_type(24bit-31bit), resolution/
  190. * test_case(16bit-23bit), hsync/vsync/de/clk io drivint(8bit-15bit),
  191. * data io driving(0bit-7bit)
  192. * test_type (factory:0, HQA:1, DVT:2)
  193. */
  194. int test_type = ((long int)info >> 24);
  195. int resolution = (((long int)info >> 16) & 0xFF);
  196. int test_case = resolution;
  197. int io_driving = ((long int)info & 0xFFFF);
  198. EXTD_FACTORY_LOG("STEP3_START_DPI_AND_CONFIG +\n");
  199. EXTD_FACTORY_LOG("resolution/test case:%d, driving:0x%x\n", resolution, io_driving);
  200. if (test_type == 0) { /* Factory mode */
  201. hdmi_factory_dpi_parameters(resolution, io_driving);
  202. ext_disp_factory_test(0, (void *)&hdmi_factory_dpi_params);
  203. msleep(100);
  204. hdmi_tx_drv->video_config(resolution, HDMI_VIN_FORMAT_RGB888, HDMI_VOUT_FORMAT_RGB888);
  205. } else if (test_type == 1) { /* HQA */
  206. hdmi_factory_dpi_parameters(resolution, io_driving);
  207. ext_disp_factory_test(0, (void *)&hdmi_factory_dpi_params);
  208. EXTD_FACTORY_LOG("[hdmi] Not need video config for DPI HQA\n");
  209. } else if (test_type == 2) { /* DVT */
  210. EXTD_FACTORY_LOG("[hdmi] Start DPI DVT Test\n");
  211. dpi_dvt_ioctl(test_case);
  212. }
  213. break;
  214. }
  215. case STEP4_DPI_STOP_AND_POWER_OFF:
  216. {
  217. EXTD_FACTORY_LOG("[hdmi] STEP4_DPI_STOP_AND_POWER_OFF\n");
  218. hdmi_tx_drv->power_off();
  219. pgc->hdmi_factory_inited = false;
  220. is_context_inited = false;
  221. hdmi_tx_drv->unregister_callback(hdmi_factory_callback);
  222. break;
  223. }
  224. default:
  225. break;
  226. }
  227. return ret;
  228. }
  229. #endif /* CONFIG_MTK_HDMI_SUPPORT */
  230. const struct EXTD_DRIVER *EXTD_Factory_HDMI_Driver(void)
  231. {
  232. static const struct EXTD_DRIVER extd_factory_hdmi = {
  233. #if defined(CONFIG_MTK_HDMI_SUPPORT)
  234. .init = hdmi_factory_mode_init,
  235. .deinit = NULL,
  236. .enable = NULL,
  237. .power_enable = NULL,
  238. .set_audio_enable = NULL,
  239. .set_resolution = NULL,
  240. .get_dev_info = NULL,
  241. .get_capability = NULL,
  242. .get_edid = NULL,
  243. .wait_vsync = NULL,
  244. .fake_connect = NULL,
  245. .factory_mode_test = hdmi_factory_mode_test,
  246. .ioctl = NULL
  247. #else
  248. .init = 0
  249. #endif
  250. };
  251. return &extd_factory_hdmi;
  252. }
  253. const struct EXTD_DRIVER *EXTD_Factory_EPD_Driver(void)
  254. {
  255. static const struct EXTD_DRIVER extd_factory_epd = {
  256. #if defined(CONFIG_MTK_EPD_SUPPORT)
  257. .init = NULL,
  258. .deinit = NULL,
  259. .enable = NULL,
  260. .power_enable = NULL,
  261. .set_audio_enable = NULL,
  262. .set_resolution = NULL,
  263. .get_dev_info = NULL,
  264. .get_capability = NULL,
  265. .get_edid = NULL,
  266. .wait_vsync = NULL,
  267. .fake_connect = NULL,
  268. .factory_mode_test = epd_factory_mode_test,
  269. .ioctl = NULL
  270. #else
  271. .init = 0
  272. #endif
  273. };
  274. return &extd_factory_epd;
  275. }