h245qbn02.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* drivers/video/sunxi/disp2/disp/lcd/he0801a068.c
  2. *
  3. * Copyright (c) 2017 Allwinnertech Co., Ltd.
  4. * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
  5. *
  6. * he0801a-068 panel driver
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * [lcd0]
  13. * lcd_used = 1
  14. * lcd_driver_name = "h245qbn02"
  15. * lcd_bl_0_percent = 0
  16. * lcd_bl_40_percent = 23
  17. * lcd_bl_100_percent = 100
  18. * lcd_backlight = 100
  19. * lcd_if = 4
  20. * lcd_x = 240
  21. * lcd_y = 432
  22. * lcd_width = 52
  23. * lcd_height = 52
  24. * lcd_dclk_freq = 18
  25. * lcd_pwm_used = 1
  26. * lcd_pwm_ch = 0
  27. * lcd_pwm_freq = 50000
  28. * lcd_pwm_pol = 1
  29. * lcd_pwm_max_limit = 255
  30. * lcd_hbp = 96
  31. * lcd_ht = 480
  32. * lcd_hspw = 2
  33. * lcd_vbp = 21
  34. * lcd_vt = 514
  35. * lcd_vspw = 2
  36. * lcd_dsi_if = 1
  37. * lcd_dsi_lane = 1
  38. * lcd_dsi_format = 0
  39. * lcd_dsi_te = 1
  40. * lcd_dsi_eotp = 0
  41. * lcd_frm = 0
  42. * lcd_io_phase = 0x0000
  43. * lcd_hv_clk_phase = 0
  44. * lcd_hv_sync_polarity= 0
  45. * lcd_gamma_en = 0
  46. * lcd_bright_curve_en = 0
  47. * lcd_cmap_en = 0
  48. * lcdgamma4iep = 22
  49. * lcd_bl_en = port:PB03<1><0><default><1>
  50. * lcd_power = "axp233_dc1sw"
  51. * lcd_power1 = "axp233_eldo1"
  52. * lcd_gpio_0 = port:PB02<1><0><default><0>
  53. * lcd_vsync = port:PD21<2><0><3><default>
  54. */
  55. #include "h245qbn02.h"
  56. static void lcd_power_on(u32 sel);
  57. static void lcd_power_off(u32 sel);
  58. static void lcd_bl_open(u32 sel);
  59. static void lcd_bl_close(u32 sel);
  60. static void lcd_panel_init(u32 sel);
  61. static void lcd_panel_exit(u32 sel);
  62. #define panel_reset(sel, val) sunxi_lcd_gpio_set_value(sel, 0, val)
  63. static void lcd_cfg_panel_info(struct panel_extend_para *info)
  64. {
  65. u32 i = 0, j = 0;
  66. u32 items;
  67. u8 lcd_gamma_tbl[][2] = {
  68. {0, 0}, {15, 15}, {30, 30}, {45, 45}, {60, 60},
  69. {75, 75}, {90, 90}, {105, 105}, {120, 120}, {135, 135},
  70. {150, 150}, {165, 165}, {180, 180}, {195, 195}, {210, 210},
  71. {225, 225}, {240, 240}, {255, 255},
  72. };
  73. u32 lcd_cmap_tbl[2][3][4] = {
  74. {
  75. {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
  76. {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
  77. {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
  78. },
  79. {
  80. {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
  81. {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
  82. {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
  83. },
  84. };
  85. items = sizeof(lcd_gamma_tbl) / 2;
  86. for (i = 0; i < items - 1; i++) {
  87. u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
  88. for (j = 0; j < num; j++) {
  89. u32 value = 0;
  90. value =
  91. lcd_gamma_tbl[i][1] +
  92. ((lcd_gamma_tbl[i + 1][1] - lcd_gamma_tbl[i][1]) *
  93. j) /
  94. num;
  95. info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
  96. (value << 16) + (value << 8) + value;
  97. }
  98. }
  99. info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items - 1][1] << 16) +
  100. (lcd_gamma_tbl[items - 1][1] << 8) +
  101. lcd_gamma_tbl[items - 1][1];
  102. memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
  103. }
  104. static s32 lcd_open_flow(u32 sel)
  105. {
  106. LCD_OPEN_FUNC(sel, lcd_power_on, 10);
  107. LCD_OPEN_FUNC(sel, lcd_panel_init, 10);
  108. LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 50);
  109. LCD_OPEN_FUNC(sel, lcd_bl_open, 0);
  110. return 0;
  111. }
  112. static s32 lcd_close_flow(u32 sel)
  113. {
  114. LCD_CLOSE_FUNC(sel, lcd_bl_close, 0);
  115. LCD_CLOSE_FUNC(sel, lcd_panel_exit, 200);
  116. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
  117. LCD_CLOSE_FUNC(sel, lcd_power_off, 500);
  118. return 0;
  119. }
  120. static void lcd_power_on(u32 sel)
  121. {
  122. sunxi_lcd_pin_cfg(sel, 1);
  123. panel_reset(sel, 0);
  124. sunxi_lcd_delay_ms(10);
  125. /*3.3v*/
  126. sunxi_lcd_power_enable(sel, 0);
  127. panel_reset(sel, 1);
  128. sunxi_lcd_delay_ms(300);
  129. panel_reset(sel, 0);
  130. sunxi_lcd_delay_ms(20);
  131. panel_reset(sel, 1);
  132. sunxi_lcd_delay_ms(10);
  133. sunxi_lcd_power_enable(sel, 1);
  134. }
  135. static void lcd_power_off(u32 sel)
  136. {
  137. sunxi_lcd_pin_cfg(sel, 0);
  138. sunxi_lcd_delay_ms(20);
  139. panel_reset(sel, 0);
  140. sunxi_lcd_delay_ms(5);
  141. sunxi_lcd_power_disable(sel, 1);
  142. sunxi_lcd_delay_ms(5);
  143. sunxi_lcd_power_disable(sel, 0);
  144. }
  145. static void lcd_bl_open(u32 sel)
  146. {
  147. sunxi_lcd_pwm_enable(sel);
  148. sunxi_lcd_backlight_enable(sel);
  149. }
  150. static void lcd_bl_close(u32 sel)
  151. {
  152. sunxi_lcd_backlight_disable(sel);
  153. sunxi_lcd_pwm_disable(sel);
  154. }
  155. static void lcd_panel_init(u32 sel)
  156. {
  157. sunxi_lcd_dsi_clk_enable(sel);
  158. sunxi_lcd_delay_ms(200);
  159. sunxi_lcd_dsi_dcs_write_4para(sel, 0x2a, 0x00, 0x00, 0x00, 0xef);
  160. sunxi_lcd_dsi_dcs_write_4para(sel, 0x2b, 0x00, 0x00, 0x01, 0xaf);
  161. sunxi_lcd_dsi_dcs_write_0para(sel, 0x11);
  162. sunxi_lcd_dsi_dcs_write_1para(sel, 0x36, 0xd0);
  163. sunxi_lcd_delay_ms(120);
  164. sunxi_lcd_dsi_dcs_write_0para(sel, 0x2c);
  165. sunxi_lcd_dsi_dcs_write_0para(sel, 0x29);
  166. /*sunxi_lcd_dsi_dcs_write_2para(sel, 0xbd, 0x11, 0x00);*/
  167. /*sunxi_lcd_dsi_dcs_write_2para(sel, 0xbc, 0x00, 0x94);*/
  168. /*sunxi_lcd_dsi_dcs_write_2para(sel, 0xbe, 0xd0, 0x02);*/
  169. }
  170. static void lcd_panel_exit(u32 sel)
  171. {
  172. u8 para[20] = {0x0b, 0x00, 0x00, 0x00, 0x21, 0x4f, 0x01,
  173. 0x0e, 0x2a, 0x66, 0x05, 0x2a, 0x00, 0x05};
  174. sunxi_lcd_dsi_dcs_write_0para(sel, 0x28);
  175. sunxi_lcd_delay_ms(5);
  176. sunxi_lcd_dsi_dcs_write_2para(sel, 0xf1, 0x5a, 0x5a);
  177. dsi_dcs_wr(sel, 0xf4, para, 14);
  178. sunxi_lcd_dsi_dcs_write_2para(sel, 0xf1, 0xa5, 0xa5);
  179. sunxi_lcd_dsi_dcs_write_0para(sel, 0x10);
  180. sunxi_lcd_delay_ms(120);
  181. }
  182. /*sel: 0:lcd0; 1:lcd1*/
  183. static s32 lcd_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
  184. {
  185. return 0;
  186. }
  187. static int lcd_set_esd_info(struct disp_lcd_esd_info *p_info)
  188. {
  189. if (!p_info)
  190. return -1;
  191. p_info->level = 1;
  192. p_info->freq = 60;
  193. p_info->esd_check_func_pos = 1;
  194. return 0;
  195. }
  196. /**
  197. * @name :lcd_esd_check
  198. * @brief :check if panel is ok
  199. * @param[IN] :sel:index of dsi
  200. * @param[OUT] :none
  201. * @return :0 if ok, else not ok
  202. */
  203. static s32 lcd_esd_check(u32 sel)
  204. {
  205. tcon_reset(sel);
  206. return 0;
  207. }
  208. /**
  209. * @name :lcd_reset_panel
  210. * @brief :reset panel step
  211. * @param[IN] :sel:index of dsi
  212. * @param[OUT] :none
  213. * @return :0
  214. */
  215. static s32 lcd_reset_panel(u32 sel)
  216. {
  217. /*reset tcon*/
  218. return 0;
  219. }
  220. struct __lcd_panel h245qbn02_panel = {
  221. /* panel driver name, must mach the name of
  222. * lcd_drv_name in sys_config.fex
  223. */
  224. .name = "h245qbn02",
  225. .func = {
  226. .cfg_panel_info = lcd_cfg_panel_info,
  227. .cfg_open_flow = lcd_open_flow,
  228. .cfg_close_flow = lcd_close_flow,
  229. .lcd_user_defined_func = lcd_user_defined_func,
  230. .esd_check = lcd_esd_check,
  231. .reset_panel = lcd_reset_panel,
  232. .set_esd_info = lcd_set_esd_info,
  233. },
  234. };