st7701s.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* drivers/video/sunxi/disp2/disp/lcd/ST7796S.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. *
  15. * lcd_driver_name = "st7701s"
  16. *
  17. * lcd_bl_0_percent = 0
  18. * lcd_bl_40_percent = 23
  19. * lcd_bl_100_percent = 100
  20. * lcd_backlight = 88
  21. *
  22. * lcd_if = 4
  23. * lcd_x = 480
  24. * lcd_y = 640
  25. * lcd_width = 36
  26. * lcd_height = 65
  27. * lcd_dclk_freq = 25
  28. *
  29. * lcd_pwm_used = 1
  30. * lcd_pwm_ch = 8
  31. * lcd_pwm_freq = 50000
  32. * lcd_pwm_pol = 1
  33. * lcd_pwm_max_limit = 255
  34. *
  35. * lcd_hbp = 70
  36. * lcd_ht = 615
  37. * lcd_hspw = 8
  38. * lcd_vbp = 30
  39. * lcd_vt = 690
  40. * lcd_vspw = 10
  41. *
  42. * lcd_dsi_if = 0
  43. * lcd_dsi_lane = 2
  44. * lcd_dsi_format = 0
  45. * lcd_dsi_te = 0
  46. * lcd_dsi_eotp = 0
  47. *
  48. * lcd_frm = 0
  49. * lcd_io_phase = 0x0000
  50. * lcd_hv_clk_phase = 0
  51. * lcd_hv_sync_polarity= 0
  52. * lcd_gamma_en = 0
  53. * lcd_bright_curve_en = 0
  54. * lcd_cmap_en = 0
  55. *
  56. * lcdgamma4iep = 22
  57. *
  58. * ;lcd_bl_en = port:PD09<1><0><default><1>
  59. * lcd_power = "vcc-lcd"
  60. * lcd_pin_power = "vcc18-dsi"
  61. * lcd_pin_power1 = "vcc-pd"
  62. *
  63. * ;reset
  64. * lcd_gpio_0 = port:PD09<1><0><default><1>
  65. */
  66. #include "st7701s.h"
  67. static void lcd_power_on(u32 sel);
  68. static void lcd_power_off(u32 sel);
  69. static void lcd_bl_open(u32 sel);
  70. static void lcd_bl_close(u32 sel);
  71. static void lcd_panel_init(u32 sel);
  72. static void lcd_panel_exit(u32 sel);
  73. #define panel_reset(sel, val) sunxi_lcd_gpio_set_value(sel, 0, val)
  74. static void lcd_cfg_panel_info(struct panel_extend_para *info)
  75. {
  76. u32 i = 0, j = 0;
  77. u32 items;
  78. u8 lcd_gamma_tbl[][2] = {
  79. {0, 0}, {15, 15}, {30, 30}, {45, 45}, {60, 60},
  80. {75, 75}, {90, 90}, {105, 105}, {120, 120}, {135, 135},
  81. {150, 150}, {165, 165}, {180, 180}, {195, 195}, {210, 210},
  82. {225, 225}, {240, 240}, {255, 255},
  83. };
  84. u32 lcd_cmap_tbl[2][3][4] = {
  85. {
  86. {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
  87. {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
  88. {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
  89. },
  90. {
  91. {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
  92. {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
  93. {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
  94. },
  95. };
  96. items = sizeof(lcd_gamma_tbl) / 2;
  97. for (i = 0; i < items - 1; i++) {
  98. u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
  99. for (j = 0; j < num; j++) {
  100. u32 value = 0;
  101. value =
  102. lcd_gamma_tbl[i][1] +
  103. ((lcd_gamma_tbl[i + 1][1] - lcd_gamma_tbl[i][1]) *
  104. j) /
  105. num;
  106. info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
  107. (value << 16) + (value << 8) + value;
  108. }
  109. }
  110. info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items - 1][1] << 16) +
  111. (lcd_gamma_tbl[items - 1][1] << 8) +
  112. lcd_gamma_tbl[items - 1][1];
  113. memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
  114. }
  115. static s32 lcd_open_flow(u32 sel)
  116. {
  117. LCD_OPEN_FUNC(sel, lcd_power_on, 0);
  118. LCD_OPEN_FUNC(sel, lcd_panel_init, 10);
  119. LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 10);
  120. LCD_OPEN_FUNC(sel, lcd_bl_open, 0);
  121. return 0;
  122. }
  123. static s32 lcd_close_flow(u32 sel)
  124. {
  125. LCD_CLOSE_FUNC(sel, lcd_bl_close, 0);
  126. LCD_CLOSE_FUNC(sel, lcd_panel_exit, 10);
  127. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
  128. LCD_CLOSE_FUNC(sel, lcd_power_off, 0);
  129. return 0;
  130. }
  131. static void lcd_power_on(u32 sel)
  132. {
  133. sunxi_lcd_pin_cfg(sel, 1);
  134. sunxi_lcd_power_enable(sel, 0);
  135. // sunxi_lcd_power_enable(sel, 1);
  136. sunxi_lcd_delay_ms(10);
  137. /* reset lcd by gpio */
  138. panel_reset(sel, 1);
  139. sunxi_lcd_delay_ms(1);
  140. panel_reset(sel, 0);
  141. sunxi_lcd_delay_ms(1);
  142. panel_reset(sel, 1);
  143. sunxi_lcd_delay_ms(10);
  144. }
  145. static void lcd_power_off(u32 sel)
  146. {
  147. sunxi_lcd_pin_cfg(sel, 0);
  148. sunxi_lcd_delay_ms(1);
  149. panel_reset(sel, 0);
  150. sunxi_lcd_delay_ms(1);
  151. sunxi_lcd_power_disable(sel, 0);
  152. }
  153. static void lcd_bl_open(u32 sel)
  154. {
  155. sunxi_lcd_pwm_enable(sel);
  156. sunxi_lcd_backlight_enable(sel);
  157. }
  158. static void lcd_bl_close(u32 sel)
  159. {
  160. sunxi_lcd_backlight_disable(sel);
  161. sunxi_lcd_pwm_disable(sel);
  162. }
  163. #define REGFLAG_DELAY 0XFE
  164. #define REGFLAG_END_OF_TABLE 0xFC /* END OF REGISTERS MARKER */
  165. struct LCM_setting_table {
  166. u8 cmd;
  167. u32 count;
  168. u8 para_list[18];
  169. };
  170. static struct LCM_setting_table lcm_initialization_setting[] = {
  171. {0x11, 1, {0x00} },
  172. {REGFLAG_DELAY, 60, {} },
  173. {0xff, 5, {0x77, 0x01, 0x00, 0x00, 0x10} },
  174. {0xc0, 2, {0x4f, 0x00} },
  175. {0xc1, 2, {0x07, 0x02} },
  176. {0xc2, 2, {0x31, 0x05} },
  177. {0xcc, 1, {0x10} },
  178. {0xb0, 16, {0x00, 0x0a, 0x11, 0x0c, 0x10, 0x05, 0x00, 0x08, 0x08, 0x1f,
  179. 0x07, 0x13, 0x10, 0xa9, 0x30, 0x18} },
  180. {0xb1, 16, {0x00, 0x0b, 0x11, 0x0d, 0x0f, 0x05, 0x02, 0x07, 0x06, 0x20,
  181. 0x05, 0x15, 0x13, 0xa9, 0x30, 0x18} },
  182. {0xff, 5, {0x77, 0x01, 0x00, 0x00, 0x11} },
  183. {0xb0, 1, {0x53} },
  184. {0xb1, 1, {0x60} },
  185. {0xb2, 1, {0x07} },
  186. {0xb3, 1, {0x08} },
  187. {0xb5, 1, {0x49} },
  188. {0xb7, 1, {0x85} },
  189. {0xb8, 1, {0x21} },
  190. {0xb9, 1, {0x10} },
  191. {0xc1, 1, {0x78} },
  192. {0xc2, 1, {0x78} },
  193. {REGFLAG_DELAY, 50, {} },
  194. {0xd0, 1, {0x88} },
  195. {0xe0, 3, {0x00, 0x00, 0x02} },
  196. {0xe1, 11, {0x03, 0xa0, 0x00, 0x00, 0x02, 0xa0, 0x00, 0x00, 0x00, 0x33,
  197. 0x33} },
  198. {0xe2, 12, {0x22, 0x22, 0x33, 0x33, 0x88, 0xa0, 0x00, 0x00, 0x87, 0xa0,
  199. 0x00, 0x00} },
  200. {0xe3, 4, {0x00, 0x00, 0x22, 0x22} },
  201. {0xe4, 2, {0x44, 0x44} },
  202. {0xe5, 16, {0x04, 0x84, 0xa0, 0xa0, 0x06, 0x86, 0xa0, 0xa0, 0x08, 0x88,
  203. 0xa0, 0xa0, 0x0a, 0x8a, 0xa0, 0xa0} },
  204. {0xe6, 4, {0x00, 0x00, 0x22, 0x22} },
  205. {0xe7, 2, {0x44, 0x44} },
  206. {0xe8, 16, {0x03, 0x83, 0xa0, 0xa0, 0x05, 0x85, 0xa0, 0xa0, 0x07, 0x87,
  207. 0xa0, 0xa0, 0x09, 0x89, 0xa0, 0xa0} },
  208. {0xeb, 7, {0x00, 0x01, 0xe4, 0xe4, 0x88, 0x00, 0x40} },
  209. {0xec, 2, {0x3c, 0x01} },
  210. {0xed, 16, {0xab, 0x89, 0x76, 0x54, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff,
  211. 0xff, 0x20, 0x45, 0x67, 0x98, 0xba} },
  212. {0xff, 5, {0x77, 0x01, 0x00, 0x00, 0x00} },
  213. {REGFLAG_DELAY, 50, {} },
  214. {0x29, 1, {0x00} },
  215. {REGFLAG_END_OF_TABLE, 0x00, {} }
  216. };
  217. static void lcd_panel_init(u32 sel)
  218. {
  219. u32 i = 0;
  220. sunxi_lcd_dsi_clk_enable(sel);
  221. sunxi_lcd_delay_ms(10);
  222. for (i = 0;; i++) {
  223. if (lcm_initialization_setting[i].cmd == REGFLAG_END_OF_TABLE)
  224. break;
  225. else if (lcm_initialization_setting[i].cmd == REGFLAG_DELAY)
  226. sunxi_lcd_delay_ms(lcm_initialization_setting[i].count);
  227. else {
  228. dsi_dcs_wr(0, lcm_initialization_setting[i].cmd,
  229. lcm_initialization_setting[i].para_list,
  230. lcm_initialization_setting[i].count);
  231. }
  232. }
  233. }
  234. static void lcd_panel_exit(u32 sel)
  235. {
  236. sunxi_lcd_dsi_dcs_write_0para(sel, 0x28);
  237. sunxi_lcd_delay_ms(10);
  238. sunxi_lcd_dsi_dcs_write_0para(sel, 0x10);
  239. sunxi_lcd_delay_ms(10);
  240. }
  241. /*sel: 0:lcd0; 1:lcd1*/
  242. static s32 lcd_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
  243. {
  244. return 0;
  245. }
  246. struct __lcd_panel st7701s_panel = {
  247. /* panel driver name, must mach the name of
  248. * lcd_drv_name in sys_config.fex
  249. */
  250. .name = "st7701s",
  251. .func = {
  252. .cfg_panel_info = lcd_cfg_panel_info,
  253. .cfg_open_flow = lcd_open_flow,
  254. .cfg_close_flow = lcd_close_flow,
  255. .lcd_user_defined_func = lcd_user_defined_func,
  256. },
  257. };