lt070me05000.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Allwinner SoCs display driver.
  3. *
  4. * Copyright (C) 2016 Allwinner.
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include "lt070me05000.h"
  11. static void LCD_power_on(u32 sel);
  12. static void LCD_power_off(u32 sel);
  13. static void LCD_bl_open(u32 sel);
  14. static void LCD_bl_close(u32 sel);
  15. static void LCD_panel_init(u32 sel);
  16. static void LCD_panel_exit(u32 sel);
  17. static u8 const mipi_dcs_pixel_format[4] = { 0x77, 0x66, 0x66, 0x55 };
  18. #define panel_reset(val) sunxi_lcd_gpio_set_value(sel, 1, val)
  19. #define power_en(val) sunxi_lcd_gpio_set_value(sel, 0, val)
  20. static void LCD_cfg_panel_info(struct panel_extend_para *info)
  21. {
  22. u32 i = 0, j = 0;
  23. u32 items;
  24. u8 lcd_gamma_tbl[][2] = {
  25. /* {input value, corrected value} */
  26. {0, 0},
  27. {15, 15},
  28. {30, 30},
  29. {45, 45},
  30. {60, 60},
  31. {75, 75},
  32. {90, 90},
  33. {105, 105},
  34. {120, 120},
  35. {135, 135},
  36. {150, 150},
  37. {165, 165},
  38. {180, 180},
  39. {195, 195},
  40. {210, 210},
  41. {225, 225},
  42. {240, 240},
  43. {255, 255},
  44. };
  45. u32 lcd_cmap_tbl[2][3][4] = {
  46. {
  47. {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
  48. {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
  49. {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
  50. },
  51. {
  52. {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
  53. {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
  54. {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
  55. },
  56. };
  57. items = sizeof(lcd_gamma_tbl) / 2;
  58. for (i = 0; i < items - 1; i++) {
  59. u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
  60. for (j = 0; j < num; j++) {
  61. u32 value = 0;
  62. value =
  63. lcd_gamma_tbl[i][1] +
  64. ((lcd_gamma_tbl[i + 1][1] -
  65. lcd_gamma_tbl[i][1]) * j) / num;
  66. info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
  67. (value << 16) + (value << 8) + value;
  68. }
  69. }
  70. info->lcd_gamma_tbl[255] =
  71. (lcd_gamma_tbl[items - 1][1] << 16) +
  72. (lcd_gamma_tbl[items - 1][1] << 8) + lcd_gamma_tbl[items - 1][1];
  73. memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
  74. }
  75. static s32 LCD_open_flow(u32 sel)
  76. {
  77. /* open lcd power, and delay 50ms */
  78. LCD_OPEN_FUNC(sel, LCD_power_on, 20);
  79. /* open lcd power, than delay 200ms */
  80. LCD_OPEN_FUNC(sel, LCD_panel_init, 10);
  81. /* open lcd controller, and delay 100ms */
  82. LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 20);
  83. /* open lcd backlight, and delay 0ms */
  84. LCD_OPEN_FUNC(sel, LCD_bl_open, 0);
  85. return 0;
  86. }
  87. static s32 LCD_close_flow(u32 sel)
  88. {
  89. /* close lcd backlight, and delay 0ms */
  90. LCD_CLOSE_FUNC(sel, LCD_bl_close, 0);
  91. /* close lcd controller, and delay 0ms */
  92. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
  93. /* open lcd power, than delay 200ms */
  94. LCD_CLOSE_FUNC(sel, LCD_panel_exit, 200);
  95. /* close lcd power, and delay 500ms */
  96. LCD_CLOSE_FUNC(sel, LCD_power_off, 500);
  97. return 0;
  98. }
  99. static void LCD_power_on(u32 sel)
  100. {
  101. /* config lcd_power pin to open lcd power */
  102. sunxi_lcd_power_enable(sel, 0);
  103. sunxi_lcd_delay_ms(5);
  104. /* config lcd_power pin to open lcd power0 */
  105. sunxi_lcd_power_enable(sel, 1);
  106. sunxi_lcd_delay_ms(5);
  107. /* config lcd_power pin to open lcd power2 */
  108. sunxi_lcd_power_enable(sel, 2);
  109. sunxi_lcd_delay_ms(5);
  110. power_en(1);
  111. sunxi_lcd_delay_ms(20);
  112. panel_reset(1);
  113. sunxi_lcd_delay_ms(5);
  114. sunxi_lcd_pin_cfg(sel, 1);
  115. }
  116. static void LCD_power_off(u32 sel)
  117. {
  118. sunxi_lcd_pin_cfg(sel, 0);
  119. power_en(0);
  120. sunxi_lcd_delay_ms(20);
  121. panel_reset(0);
  122. sunxi_lcd_delay_ms(5);
  123. /* config lcd_power pin to close lcd power2 */
  124. sunxi_lcd_power_disable(sel, 2);
  125. sunxi_lcd_delay_ms(5);
  126. /* config lcd_power pin to close lcd power1 */
  127. sunxi_lcd_power_disable(sel, 1);
  128. sunxi_lcd_delay_ms(5);
  129. /* config lcd_power pin to close lcd power */
  130. sunxi_lcd_power_disable(sel, 0);
  131. }
  132. static void LCD_bl_open(u32 sel)
  133. {
  134. sunxi_lcd_pwm_enable(sel);
  135. /* config lcd_bl_en pin to open lcd backlight */
  136. sunxi_lcd_backlight_enable(sel);
  137. }
  138. static void LCD_bl_close(u32 sel)
  139. {
  140. /* config lcd_bl_en pin to close lcd backlight */
  141. sunxi_lcd_backlight_disable(sel);
  142. sunxi_lcd_pwm_disable(sel);
  143. }
  144. static void LCD_panel_init(u32 sel)
  145. {
  146. struct disp_panel_para *panel_info =
  147. kmalloc(sizeof(struct disp_panel_para), GFP_KERNEL | __GFP_ZERO);
  148. u32 bright = 0;
  149. u8 para[9];
  150. bsp_disp_get_panel_info(sel, panel_info);
  151. bright = bsp_disp_lcd_get_bright(sel);
  152. sunxi_lcd_dsi_clk_enable(sel);
  153. sunxi_lcd_delay_ms(20);
  154. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SOFT_RESET);
  155. sunxi_lcd_delay_ms(10);
  156. sunxi_lcd_dsi_gen_write_1para(sel, 0xb0, 0x00);
  157. sunxi_lcd_dsi_gen_write_5para(sel, 0xb3, 0x04, 0x08, 0x00, 0x22, 0x00);
  158. sunxi_lcd_dsi_gen_write_1para(sel, 0xb4, 0x0c);
  159. sunxi_lcd_dsi_gen_write_2para(sel, 0xb6, 0x3a, 0xd3);
  160. sunxi_lcd_dsi_dcs_write_1para(sel, 0x51, bright);
  161. sunxi_lcd_dsi_dcs_write_1para(sel, 0x53, 0x2c);
  162. sunxi_lcd_dsi_dcs_write_1para(sel, DSI_DCS_SET_PIXEL_FORMAT, 0x77);
  163. sunxi_lcd_dsi_dcs_write_4para(sel, DSI_DCS_SET_COLUMN_ADDRESS, 0x00,
  164. 0x00, 0x04, 0xaf);
  165. sunxi_lcd_dsi_dcs_write_4para(sel, DSI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00,
  166. 0x07, 0x7f);
  167. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_EXIT_SLEEP_MODE);
  168. sunxi_lcd_delay_ms(120);
  169. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_ON);
  170. sunxi_lcd_dsi_gen_write_5para(sel, 0xb3, 0x14, 0x08, 0x00, 0x22, 0x00);
  171. sunxi_lcd_dsi_gen_write_1para(sel, 0xd6, 0x01);
  172. para[0] = 0x31;
  173. para[1] = 0xf7;
  174. para[2] = 0x80;
  175. para[3] = 0x00;
  176. para[4] = panel_info->lcd_vbp - 1;
  177. para[5] = 0x00;
  178. para[6] = 0x08;
  179. para[7] = 0x00;
  180. para[8] = 0x00;
  181. sunxi_lcd_dsi_gen_write(sel, 0xc2, para, 9);
  182. disp_sys_free(panel_info);
  183. }
  184. static void LCD_panel_exit(u32 sel)
  185. {
  186. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_OFF);
  187. sunxi_lcd_delay_ms(20);
  188. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_ENTER_SLEEP_MODE);
  189. sunxi_lcd_delay_ms(80);
  190. }
  191. /* sel: 0:lcd0; 1:lcd1 */
  192. static s32 LCD_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
  193. {
  194. return 0;
  195. }
  196. /* sel: 0:lcd0; 1:lcd1 */
  197. static s32 LCD_set_bright(u32 sel, u32 bright)
  198. {
  199. sunxi_lcd_dsi_dcs_write_1para(sel, 0x51, bright);
  200. return 0;
  201. }
  202. struct __lcd_panel lt070me05000_panel = {
  203. /* panel driver name, must mach the lcd_drv_name in sys_config.fex */
  204. .name = "lt070me05000",
  205. .func = {
  206. .cfg_panel_info = LCD_cfg_panel_info,
  207. .cfg_open_flow = LCD_open_flow,
  208. .cfg_close_flow = LCD_close_flow,
  209. .lcd_user_defined_func = LCD_user_defined_func,
  210. .set_bright = LCD_set_bright,
  211. }
  212. ,
  213. };