extd_factory.c 9.7 KB

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