ls029b3sx02.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* drivers/video/sunxi/disp2/disp/lcd/ls029b3sx02.c
  2. *
  3. * Copyright (c) 2017 Allwinnertech Co., Ltd.
  4. * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
  5. *
  6. * ls029b3sx02 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. #include "ls029b3sx02.h"
  13. static void lcd_power_on(u32 sel);
  14. static void lcd_power_off(u32 sel);
  15. static void lcd_bl_open(u32 sel);
  16. static void lcd_bl_close(u32 sel);
  17. static void lcd_panel_init(u32 sel);
  18. static void lcd_panel_exit(u32 sel);
  19. #define panel_reset(sel, 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. {0, 0},
  26. {15, 15},
  27. {30, 30},
  28. {45, 45},
  29. {60, 60},
  30. {75, 75},
  31. {90, 90},
  32. {105, 105},
  33. {120, 120},
  34. {135, 135},
  35. {150, 150},
  36. {165, 165},
  37. {180, 180},
  38. {195, 195},
  39. {210, 210},
  40. {225, 225},
  41. {240, 240},
  42. {255, 255},
  43. };
  44. u32 lcd_cmap_tbl[2][3][4] = {
  45. {
  46. {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
  47. {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
  48. {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
  49. },
  50. {
  51. {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
  52. {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
  53. {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
  54. },
  55. };
  56. items = sizeof(lcd_gamma_tbl) / 2;
  57. for (i = 0; i < items - 1; i++) {
  58. u32 num = lcd_gamma_tbl[i+1][0] - lcd_gamma_tbl[i][0];
  59. for (j = 0; j < num; j++) {
  60. u32 value = 0;
  61. value = lcd_gamma_tbl[i][1] +
  62. ((lcd_gamma_tbl[i+1][1] - lcd_gamma_tbl[i][1])
  63. * j) / num;
  64. info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
  65. (value<<16)
  66. + (value<<8) + value;
  67. }
  68. }
  69. info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items-1][1]<<16) +
  70. (lcd_gamma_tbl[items-1][1]<<8)
  71. + lcd_gamma_tbl[items-1][1];
  72. memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
  73. }
  74. static s32 lcd_open_flow(u32 sel)
  75. {
  76. /* set func to lcdp->openflow.func
  77. * set delay time to lcdp->openflow.delay*/
  78. LCD_OPEN_FUNC(sel, lcd_power_on, 10);
  79. LCD_OPEN_FUNC(sel, lcd_panel_init, 200);
  80. LCD_OPEN_FUNC(sel, lcd_bl_open, 0);
  81. return 0;
  82. }
  83. static s32 lcd_close_flow(u32 sel)
  84. {
  85. LCD_CLOSE_FUNC(sel, lcd_bl_close, 0);
  86. LCD_CLOSE_FUNC(sel, lcd_panel_exit, 200);
  87. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
  88. LCD_CLOSE_FUNC(sel, lcd_power_off, 500);
  89. return 0;
  90. }
  91. static void lcd_power_on(u32 sel)
  92. {
  93. /*[VDDI]-->[AVDD+]-->[AVDD]-->[rst h]
  94. * -->[rst l]-->[rst h]*/
  95. sunxi_lcd_power_enable(sel, 0);
  96. sunxi_lcd_delay_ms(10);
  97. sunxi_lcd_power_enable(sel, 1);
  98. sunxi_lcd_delay_ms(10);
  99. sunxi_lcd_power_enable(sel, 2);
  100. sunxi_lcd_delay_ms(10);
  101. sunxi_lcd_pin_cfg(sel, 1);
  102. sunxi_lcd_delay_ms(50);
  103. sunxi_lcd_gpio_set_value(sel, 1, 1);
  104. panel_reset(sel, 1);
  105. sunxi_lcd_delay_ms(10);
  106. panel_reset(sel, 0);
  107. sunxi_lcd_delay_ms(10);
  108. panel_reset(sel, 1);
  109. sunxi_lcd_delay_ms(20);
  110. }
  111. static void lcd_power_off(u32 sel)
  112. {
  113. /*[AVEE-]-->[AVDD+]-->[rst l]-->[VDDI]*/
  114. sunxi_lcd_pin_cfg(sel, 0);
  115. sunxi_lcd_delay_ms(20);
  116. sunxi_lcd_power_disable(sel, 2);
  117. sunxi_lcd_delay_ms(5);
  118. sunxi_lcd_power_disable(sel, 1);
  119. sunxi_lcd_delay_ms(5);
  120. panel_reset(sel, 0);
  121. sunxi_lcd_delay_ms(5);
  122. sunxi_lcd_power_disable(sel, 0);
  123. }
  124. static void lcd_bl_open(u32 sel)
  125. {
  126. sunxi_lcd_pwm_enable(sel);
  127. sunxi_lcd_backlight_enable(sel);
  128. }
  129. static void lcd_bl_close(u32 sel)
  130. {
  131. sunxi_lcd_backlight_disable(sel);
  132. sunxi_lcd_pwm_disable(sel);
  133. }
  134. static void lcd_panel_init(u32 sel)
  135. {
  136. sunxi_lcd_dsi_clk_enable(sel);
  137. sunxi_lcd_delay_ms(100);
  138. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_EXIT_SLEEP_MODE);
  139. sunxi_lcd_delay_ms(200);
  140. sunxi_lcd_tcon_enable(sel); /*tcon and dsi enable,start send data*/
  141. sunxi_lcd_delay_ms(400); /*FIXME modify this value*/
  142. sunxi_lcd_dsi_mode_switch(sel, 1, 1); /*close dsi,enable cmd mode*/
  143. sunxi_lcd_delay_ms(100);
  144. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_ON);
  145. sunxi_lcd_delay_ms(200);
  146. sunxi_lcd_dsi_mode_switch(sel, 0, 1); /*enable video mode*/
  147. return;
  148. }
  149. static void lcd_panel_exit(u32 sel)
  150. {
  151. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_SET_DISPLAY_OFF);
  152. sunxi_lcd_delay_ms(50);
  153. sunxi_lcd_dsi_dcs_write_0para(sel, DSI_DCS_ENTER_SLEEP_MODE);
  154. sunxi_lcd_delay_ms(80);
  155. return;
  156. }
  157. /*sel: 0:lcd0; 1:lcd1*/
  158. static s32 lcd_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
  159. {
  160. return 0;
  161. }
  162. /*
  163. static s32 LCD_set_bright(u32 sel, u32 bright)
  164. {
  165. return 0;
  166. }
  167. */
  168. struct __lcd_panel ls029b3sx02_panel = {
  169. /* panel driver name, must mach the name of lcd_drv_name
  170. * in sys_config.fex */
  171. .name = "ls029b3sx02",
  172. .func = {
  173. .cfg_panel_info = lcd_cfg_panel_info,
  174. .cfg_open_flow = lcd_open_flow,
  175. .cfg_close_flow = lcd_close_flow,
  176. .lcd_user_defined_func = lcd_user_defined_func,
  177. /* .set_bright = LCD_set_bright,*/
  178. },
  179. };