1
0

to20t20000.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * drivers/video/fbdev/sunxi/disp2/disp/lcd/to20t20000/to20t20000.c
  3. *
  4. * Copyright (c) 2007-2018 Allwinnertech Co., Ltd.
  5. * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include "to20t20000.h"
  18. #define CPU_TRI_MODE
  19. static void lcd_panel_to20t20000_init(struct disp_panel_para *info);
  20. static void lcd_cpu_panel_fr(__u32 sel, __u32 w, __u32 h, __u32 x, __u32 y);
  21. static void LCD_power_on(u32 sel);
  22. static void LCD_power_off(u32 sel);
  23. static void LCD_bl_open(u32 sel);
  24. static void LCD_bl_close(u32 sel);
  25. static void LCD_panel_init(u32 sel);
  26. static void LCD_panel_exit(u32 sel);
  27. extern s32 tcon0_cpu_set_tri_mode(u32 sel);
  28. static void LCD_cfg_panel_info(struct panel_extend_para *info)
  29. {
  30. u32 i = 0, j = 0;
  31. u32 items;
  32. u8 lcd_gamma_tbl[][2] = {
  33. //{input value, corrected value}
  34. {0, 0}, {15, 15}, {30, 30}, {45, 45}, {60, 60},
  35. {75, 75}, {90, 90}, {105, 105}, {120, 120}, {135, 135},
  36. {150, 150}, {165, 165}, {180, 180}, {195, 195}, {210, 210},
  37. {225, 225}, {240, 240}, {255, 255},
  38. };
  39. u32 lcd_cmap_tbl[2][3][4] = {
  40. {
  41. {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
  42. {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
  43. {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
  44. },
  45. {
  46. {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
  47. {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
  48. {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
  49. },
  50. };
  51. items = sizeof(lcd_gamma_tbl) / 2;
  52. for (i = 0; i < items - 1; i++) {
  53. u32 num = lcd_gamma_tbl[i + 1][0] - lcd_gamma_tbl[i][0];
  54. for (j = 0; j < num; j++) {
  55. u32 value = 0;
  56. value =
  57. lcd_gamma_tbl[i][1] +
  58. ((lcd_gamma_tbl[i + 1][1] - lcd_gamma_tbl[i][1]) *
  59. j) /
  60. num;
  61. info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] =
  62. (value << 16) + (value << 8) + value;
  63. }
  64. }
  65. info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items - 1][1] << 16) +
  66. (lcd_gamma_tbl[items - 1][1] << 8) +
  67. lcd_gamma_tbl[items - 1][1];
  68. memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
  69. }
  70. static s32 LCD_open_flow(u32 sel)
  71. {
  72. LCD_OPEN_FUNC(sel, LCD_power_on, 40);
  73. #ifdef CPU_TRI_MODE
  74. LCD_OPEN_FUNC(sel, LCD_panel_init, 50);
  75. LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 50);
  76. #else
  77. LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 50);
  78. LCD_OPEN_FUNC(sel, LCD_panel_init, 50);
  79. #endif
  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, 50);
  86. #ifdef CPU_TRI_MODE
  87. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 10);
  88. LCD_CLOSE_FUNC(sel, LCD_panel_exit, 10);
  89. #else
  90. LCD_CLOSE_FUNC(sel, LCD_panel_exit, 10);
  91. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 10);
  92. #endif
  93. LCD_CLOSE_FUNC(sel, LCD_power_off, 10);
  94. return 0;
  95. }
  96. static void LCD_power_on(u32 sel)
  97. {
  98. sunxi_lcd_power_enable(sel,
  99. 0); // config lcd_power pin to open lcd power0
  100. sunxi_lcd_pin_cfg(sel, 1);
  101. }
  102. static void LCD_power_off(u32 sel)
  103. {
  104. sunxi_lcd_pin_cfg(sel, 0);
  105. sunxi_lcd_power_disable(sel,
  106. 0); // config lcd_power pin to close lcd power0
  107. }
  108. static void LCD_bl_open(u32 sel)
  109. {
  110. sunxi_lcd_pwm_enable(sel);
  111. sunxi_lcd_backlight_enable(
  112. sel); // config lcd_bl_en pin to open lcd backlight
  113. }
  114. static void LCD_bl_close(u32 sel)
  115. {
  116. sunxi_lcd_backlight_disable(
  117. sel); // config lcd_bl_en pin to close lcd backlight
  118. sunxi_lcd_pwm_disable(sel);
  119. }
  120. static void LCD_panel_init(u32 sel)
  121. {
  122. struct disp_panel_para *info =
  123. disp_sys_malloc(sizeof(struct disp_panel_para));
  124. bsp_disp_get_panel_info(sel, info);
  125. lcd_panel_to20t20000_init(info);
  126. if (LCD_CPU_AUTO_MODE == info->lcd_cpu_mode)
  127. sunxi_lcd_cpu_set_auto_mode(sel);
  128. disp_sys_free(info);
  129. return;
  130. }
  131. static void LCD_panel_exit(u32 sel)
  132. {
  133. struct disp_panel_para *info =
  134. disp_sys_malloc(sizeof(struct disp_panel_para));
  135. pr_info("%s: enter sleep\n", __func__);
  136. sunxi_lcd_cpu_write_index(0, 0x28);
  137. sunxi_lcd_cpu_write_index(0, 0x10);
  138. sunxi_lcd_delay_ms(300);
  139. bsp_disp_get_panel_info(sel, info);
  140. disp_sys_free(info);
  141. return;
  142. }
  143. static void lcd_dbi_wr_dcs(__u32 sel, __u8 cmd, __u8 *para, __u32 para_num)
  144. {
  145. __u8 index = cmd;
  146. __u8 *data_p = para;
  147. __u16 i;
  148. sunxi_lcd_cpu_write_index(sel, index);
  149. for (i = 0; i < para_num; i++) {
  150. sunxi_lcd_cpu_write_data(sel, *(data_p++));
  151. }
  152. }
  153. static void lcd_cpu_panel_fr(__u32 sel, __u32 w, __u32 h, __u32 x, __u32 y)
  154. {
  155. __u8 para[4];
  156. __u32 para_num;
  157. para[0] = (x >> 8) & 0xff;
  158. para[1] = (x >> 0) & 0xff;
  159. para[2] = ((x + w - 1) >> 8) & 0xff;
  160. para[3] = ((x + w - 1) >> 0) & 0xff;
  161. para_num = 4;
  162. lcd_dbi_wr_dcs(sel, DSI_DCS_SET_COLUMN_ADDRESS, para, para_num);
  163. para[0] = (y >> 8) & 0xff;
  164. para[1] = (y >> 0) & 0xff;
  165. para[2] = ((y + h - 1) >> 8) & 0xff;
  166. para[3] = ((y + h - 1) >> 0) & 0xff;
  167. para_num = 4;
  168. lcd_dbi_wr_dcs(sel, DSI_DCS_SET_PAGE_ADDRESS, para, para_num);
  169. para_num = 0;
  170. lcd_dbi_wr_dcs(sel, DSI_DCS_WRITE_MEMORY_START, para, para_num);
  171. }
  172. static int lcd_dismode, lcd_x, lcd_y;
  173. void lcd_rotation_to20t20000(int mode)
  174. {
  175. lcd_dismode = mode;
  176. }
  177. static void lcd_panel_to20t20000_init(struct disp_panel_para *info)
  178. {
  179. /* hardware reset */
  180. sunxi_lcd_gpio_set_value(0, 0, 1);
  181. sunxi_lcd_delay_ms(10);
  182. sunxi_lcd_gpio_set_value(0, 0, 0);
  183. sunxi_lcd_delay_ms(40);
  184. sunxi_lcd_gpio_set_value(0, 0, 1);
  185. sunxi_lcd_delay_ms(50); /* wait for io stable */
  186. sunxi_lcd_gpio_set_value(0, 1, 0);
  187. sunxi_lcd_cpu_write_index(0, 0x11); /* sleep out */
  188. sunxi_lcd_delay_ms(120);
  189. sunxi_lcd_cpu_write_index(0, 0xCF);
  190. sunxi_lcd_cpu_write_data(0, 0x00);
  191. sunxi_lcd_cpu_write_data(0, 0xAA);
  192. sunxi_lcd_cpu_write_data(0, 0xE0);
  193. sunxi_lcd_delay_ms(5);
  194. sunxi_lcd_cpu_write_index(0, 0xED);
  195. sunxi_lcd_cpu_write_data(0, 0x67);
  196. sunxi_lcd_cpu_write_data(0, 0x03);
  197. sunxi_lcd_cpu_write_data(0, 0x12);
  198. sunxi_lcd_cpu_write_data(0, 0x81);
  199. sunxi_lcd_delay_ms(5);
  200. sunxi_lcd_cpu_write_index(0, 0xE8);
  201. sunxi_lcd_cpu_write_data(0, 0x85);
  202. sunxi_lcd_cpu_write_data(0, 0x11);
  203. sunxi_lcd_cpu_write_data(0, 0x78);
  204. sunxi_lcd_delay_ms(5);
  205. sunxi_lcd_cpu_write_index(0, 0xCB);
  206. sunxi_lcd_cpu_write_data(0, 0x39);
  207. sunxi_lcd_cpu_write_data(0, 0x2C);
  208. sunxi_lcd_cpu_write_data(0, 0x00);
  209. sunxi_lcd_cpu_write_data(0, 0x34);
  210. sunxi_lcd_cpu_write_data(0, 0x02);
  211. sunxi_lcd_delay_ms(5);
  212. sunxi_lcd_cpu_write_index(0, 0xF7);
  213. sunxi_lcd_cpu_write_data(0, 0x20);
  214. sunxi_lcd_delay_ms(5);
  215. sunxi_lcd_cpu_write_index(0, 0xEA);
  216. sunxi_lcd_cpu_write_data(0, 0x00);
  217. sunxi_lcd_delay_ms(5);
  218. sunxi_lcd_cpu_write_index(0, 0xC0); // Power control
  219. sunxi_lcd_cpu_write_data(0, 0x21); // VRH[5:0]
  220. sunxi_lcd_delay_ms(5);
  221. sunxi_lcd_cpu_write_index(0, 0xC1); // Power control
  222. sunxi_lcd_cpu_write_data(0, 0x01); // SAP[2:0];BT[3:0]
  223. sunxi_lcd_delay_ms(5);
  224. sunxi_lcd_cpu_write_index(0, 0xC5); // VCM control
  225. sunxi_lcd_cpu_write_data(0, 0x24); // VMH 0x2a //0x24 max:0x7f
  226. sunxi_lcd_cpu_write_data(0, 0x2c); // VML 0x2f //0x2C max:0x64
  227. sunxi_lcd_delay_ms(5);
  228. sunxi_lcd_cpu_write_index(0, 0xC7); // VCM control2
  229. sunxi_lcd_cpu_write_data(0, 0xB6); // 0xB8 //0xB6 //0xBA
  230. sunxi_lcd_delay_ms(5);
  231. sunxi_lcd_cpu_write_index(0, 0x36); // Memory Access Control
  232. sunxi_lcd_cpu_write_data(0, 0xd8);
  233. sunxi_lcd_delay_ms(5);
  234. sunxi_lcd_cpu_write_index(0, 0x3A);
  235. sunxi_lcd_cpu_write_data(0, 0x55);
  236. sunxi_lcd_delay_ms(5);
  237. sunxi_lcd_cpu_write_index(0, 0xF2); // 3Gamma Function Disable
  238. sunxi_lcd_cpu_write_data(0, 0x00);
  239. sunxi_lcd_delay_ms(5);
  240. sunxi_lcd_cpu_write_index(0, 0x26); // Gamma curve selected
  241. sunxi_lcd_cpu_write_data(0, 0x01);
  242. sunxi_lcd_delay_ms(5);
  243. sunxi_lcd_cpu_write_index(0, 0xE0); // Set Gamma
  244. sunxi_lcd_cpu_write_data(0, 0x0F);
  245. sunxi_lcd_cpu_write_data(0, 0x27);
  246. sunxi_lcd_cpu_write_data(0, 0x23);
  247. sunxi_lcd_cpu_write_data(0, 0x0B);
  248. sunxi_lcd_cpu_write_data(0, 0x0F);
  249. sunxi_lcd_cpu_write_data(0, 0x05);
  250. sunxi_lcd_cpu_write_data(0, 0x50);
  251. sunxi_lcd_cpu_write_data(0, 0x86);
  252. sunxi_lcd_cpu_write_data(0, 0x41);
  253. sunxi_lcd_cpu_write_data(0, 0x0E);
  254. sunxi_lcd_cpu_write_data(0, 0x1B);
  255. sunxi_lcd_cpu_write_data(0, 0x35);
  256. sunxi_lcd_cpu_write_data(0, 0x00);
  257. sunxi_lcd_cpu_write_data(0, 0x00);
  258. sunxi_lcd_cpu_write_data(0, 0x00);
  259. sunxi_lcd_delay_ms(5);
  260. sunxi_lcd_cpu_write_index(0, 0xE1); // Set Gamma
  261. sunxi_lcd_cpu_write_data(0, 0x00);
  262. sunxi_lcd_cpu_write_data(0, 0x1A);
  263. sunxi_lcd_cpu_write_data(0, 0x1E);
  264. sunxi_lcd_cpu_write_data(0, 0x03);
  265. sunxi_lcd_cpu_write_data(0, 0x0F);
  266. sunxi_lcd_cpu_write_data(0, 0x05);
  267. sunxi_lcd_cpu_write_data(0, 0x2E);
  268. sunxi_lcd_cpu_write_data(0, 0x25);
  269. sunxi_lcd_cpu_write_data(0, 0x3E);
  270. sunxi_lcd_cpu_write_data(0, 0x01);
  271. sunxi_lcd_cpu_write_data(0, 0x04);
  272. sunxi_lcd_cpu_write_data(0, 0x0A);
  273. sunxi_lcd_cpu_write_data(0, 0x3F);
  274. sunxi_lcd_cpu_write_data(0, 0x3F);
  275. sunxi_lcd_cpu_write_data(0, 0x0F);
  276. sunxi_lcd_delay_ms(5);
  277. #if defined(CPU_TRI_MODE)
  278. /* enable te, mode 0 */
  279. sunxi_lcd_cpu_write_index(0, 0x35);
  280. sunxi_lcd_cpu_write_data(0, 0x00);
  281. /* Tear_Scanline */
  282. sunxi_lcd_cpu_write_index(0, 0x44);
  283. sunxi_lcd_cpu_write_data(0, 0x00);
  284. sunxi_lcd_cpu_write_data(0, 0x80);
  285. #endif
  286. sunxi_lcd_cpu_write_index(0, 0x29); // Display on
  287. sunxi_lcd_delay_ms(50);
  288. lcd_cpu_panel_fr(0, info->lcd_x, info->lcd_y, 0, 0);
  289. lcd_x = info->lcd_x;
  290. lcd_y = info->lcd_y;
  291. }
  292. // sel: 0:lcd0; 1:lcd1
  293. static s32 LCD_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
  294. {
  295. return 0;
  296. }
  297. struct __lcd_panel to20t20000_panel = {
  298. /* panel driver name, must mach the name of lcd_drv_name in sys_config.fex */
  299. .name = "to20t20000",
  300. .func = {
  301. .cfg_panel_info = LCD_cfg_panel_info,
  302. .cfg_open_flow = LCD_open_flow,
  303. .cfg_close_flow = LCD_close_flow,
  304. .lcd_user_defined_func = LCD_user_defined_func,
  305. //.reinit = lcd_reflush_to20t20000,
  306. },
  307. };