WilliamLcd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * drivers/video/sunxi/disp2/disp/lcd/WilliamLcd.c
  3. *
  4. * Allwinner SoCs display driver.
  5. *
  6. * WilliamLcd panel driver
  7. *
  8. * Copyright (C) 2016 Allwinner.
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. */
  14. #include "WilliamLcd.h"
  15. #define panel_reset(val) sunxi_lcd_gpio_set_value(sel, 0, val)
  16. #define panel_power_en(val) sunxi_lcd_gpio_set_value(sel, 1, val)
  17. static void LCD_power_on(u32 sel);
  18. static void LCD_power_off(u32 sel);
  19. static void LCD_bl_open(u32 sel);
  20. static void LCD_bl_close(u32 sel);
  21. static void LCD_panel_init(u32 sel);
  22. static void LCD_panel_exit(u32 sel);
  23. static void LCD_cfg_panel_info(struct panel_extend_para *info)
  24. {
  25. u32 i = 0, j = 0;
  26. u32 items;
  27. u8 lcd_gamma_tbl[][2] = {
  28. /* {input value, corrected value} */
  29. {0, 0},
  30. {15, 15},
  31. {30, 30},
  32. {45, 45},
  33. {60, 60},
  34. {75, 75},
  35. {90, 90},
  36. {105, 105},
  37. {120, 120},
  38. {135, 135},
  39. {150, 150},
  40. {165, 165},
  41. {180, 180},
  42. {195, 195},
  43. {210, 210},
  44. {225, 225},
  45. {240, 240},
  46. {255, 255},
  47. };
  48. u32 lcd_cmap_tbl[2][3][4] = {
  49. {
  50. {LCD_CMAP_G0, LCD_CMAP_B1, LCD_CMAP_G2, LCD_CMAP_B3},
  51. {LCD_CMAP_B0, LCD_CMAP_R1, LCD_CMAP_B2, LCD_CMAP_R3},
  52. {LCD_CMAP_R0, LCD_CMAP_G1, LCD_CMAP_R2, LCD_CMAP_G3},
  53. },
  54. {
  55. {LCD_CMAP_B3, LCD_CMAP_G2, LCD_CMAP_B1, LCD_CMAP_G0},
  56. {LCD_CMAP_R3, LCD_CMAP_B2, LCD_CMAP_R1, LCD_CMAP_B0},
  57. {LCD_CMAP_G3, LCD_CMAP_R2, LCD_CMAP_G1, LCD_CMAP_R0},
  58. },
  59. };
  60. items = sizeof(lcd_gamma_tbl)/2;
  61. for (i = 0; i < items - 1; i++) {
  62. u32 num = lcd_gamma_tbl[i+1][0] - lcd_gamma_tbl[i][0];
  63. for (j = 0; j < num; j++) {
  64. u32 value = 0;
  65. value = lcd_gamma_tbl[i][1] + ((lcd_gamma_tbl[i+1][1] - lcd_gamma_tbl[i][1]) * j)/num;
  66. info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] = (value<<16) + (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) + lcd_gamma_tbl[items-1][1];
  71. memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));
  72. }
  73. static __s32 LCD_open_flow(u32 sel)
  74. {
  75. /* open lcd power, and delay 50ms */
  76. LCD_OPEN_FUNC(sel, LCD_power_on, 50);
  77. /* open lcd power, than delay 200ms */
  78. LCD_OPEN_FUNC(sel, LCD_panel_init, 200);
  79. /* open lcd controller, and delay 100ms */
  80. LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 100);
  81. /* open lcd backlight, and delay 0ms */
  82. LCD_OPEN_FUNC(sel, LCD_bl_open, 0);
  83. return 0;
  84. }
  85. static __s32 LCD_close_flow(u32 sel)
  86. {
  87. /* close lcd backlight, and delay 0ms */
  88. LCD_CLOSE_FUNC(sel, LCD_bl_close, 0);
  89. /* close lcd controller, and delay 0ms */
  90. LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);
  91. /* open lcd power, than delay 200ms */
  92. LCD_CLOSE_FUNC(sel, LCD_panel_exit, 20);
  93. /* cose lcd power, and delay 500ms */
  94. LCD_CLOSE_FUNC(sel, LCD_power_off, 50);
  95. return 0;
  96. }
  97. static void LCD_power_on(u32 sel)
  98. {
  99. /* config lcd_power pin to open lcd power0 */
  100. sunxi_lcd_power_enable(sel, 1);
  101. sunxi_lcd_delay_ms(5);
  102. /* config lcd_power pin to open lcd power1 */
  103. sunxi_lcd_power_enable(sel, 0);
  104. sunxi_lcd_delay_ms(5);
  105. panel_power_en(1);
  106. sunxi_lcd_pin_cfg(sel, 1);
  107. sunxi_lcd_delay_ms(10);
  108. panel_reset(1);
  109. sunxi_lcd_delay_ms(10);
  110. panel_reset(0);
  111. sunxi_lcd_delay_ms(20);
  112. panel_reset(1);
  113. }
  114. static void LCD_power_off(u32 sel)
  115. {
  116. sunxi_lcd_pin_cfg(sel, 0);
  117. panel_power_en(0);
  118. /* config lcd_power pin to close lcd power1 */
  119. sunxi_lcd_power_disable(sel, 0);
  120. /* config lcd_power pin to close lcd power0 */
  121. sunxi_lcd_power_disable(sel, 1);
  122. sunxi_lcd_pwm_disable(sel); /*close pwm module */
  123. }
  124. static void LCD_bl_open(u32 sel)
  125. {
  126. /* open pwm module */
  127. sunxi_lcd_pwm_enable(sel);
  128. /* config lcd_bl_en pin to open lcd backlight */
  129. sunxi_lcd_backlight_enable(sel);
  130. }
  131. static void LCD_bl_close(u32 sel)
  132. {
  133. /* config lcd_bl_en pin to close lcd backlight */
  134. sunxi_lcd_backlight_disable(sel);
  135. /* close pwm module */
  136. sunxi_lcd_pwm_disable(sel);
  137. }
  138. #if 1
  139. #define REGFLAG_DELAY 0XFF
  140. #define REGFLAG_END_OF_TABLE 0xFE /* END OF REGISTERS MARKER */
  141. struct LCM_setting_table {
  142. u8 cmd;
  143. u32 count;
  144. u8 para_list[64];
  145. };
  146. static struct LCM_setting_table lcm_initialization_setting[] = {
  147. {0xE0, 1, {0x00} },
  148. {0xE1, 1, {0x93} },
  149. {0xE2, 1, {0x65} },
  150. {0xE3, 1, {0xF8} },
  151. {0x80, 1, {0x03} }, /* 4Lanes */
  152. {0xE0, 1, {0x04} },
  153. {0x2D, 1, {0x03} }, /* 4Lanes */
  154. {0xE0, 1, {0x01} },
  155. {0x00, 1, {0x00} },
  156. {0x01, 1, {0x6F} },
  157. {0x03, 1, {0x00} },
  158. {0x04, 1, {0x6F} },
  159. {0x17, 1, {0x00} },
  160. {0x18, 1, {0xD7} }, /* VGMP=4.8V */
  161. {0x19, 1, {0x05} },
  162. {0x1A, 1, {0x00} },
  163. {0x1B, 1, {0xD7} }, /* VGMN=-4.8V */
  164. {0x1C, 1, {0x05} },
  165. {0x1F, 1, {0x79} }, /* VGH_REG=18V */
  166. {0x20, 1, {0x2D} }, /* VGL_REG=-12V */
  167. {0x21, 1, {0x2D} }, /* VGL_REG2=-12V */
  168. {0x22, 1, {0x4F} },
  169. {0x26, 1, {0xF1} }, /* VDDD from IOVCC */
  170. {0x37, 1, {0x09} }, /* SS=1, 1, {BGR=1 */
  171. {0x38, 1, {0x04} }, /* JDT=100 column inversion */
  172. {0x39, 1, {0x08} }, /* RGB_N_EQ1, 1, { modify 20140806 */
  173. {0x3A, 1, {0x12} }, /* RGB_N_EQ2, 1, { modify 20140806 */
  174. {0x3C, 1, {0x78} }, /* SET EQ3 for TE_H */
  175. {0x3E, 1, {0x80} }, /* SET CHGEN_OFF, 1, { modify 20140806 */
  176. {0x3F, 1, {0x80} }, /* SET CHGEN_OFF2, 1, { modify 20140806 */
  177. {0x40, 1, {0x06} }, /* RSO=800 RGB */
  178. {0x41, 1, {0xA0} }, /* LN=640->1280 line */
  179. {0x55, 1, {0x0F} }, /* DCDCM=1111, 1, { no output */
  180. {0x56, 1, {0x01} },
  181. {0x57, 1, {0xA8} }, /*[7:5]VGH_RT, 1, {[4:2]=VGL_RT, 1, {[1:0]=VCL_RT*/
  182. {0x58, 1, {0x0A} }, /* AVDD_S */
  183. {0x59, 1, {0x2A} }, /* VCL = -2.7V */
  184. {0x5A, 1, {0x37} }, /* VGH = 19V */
  185. {0x5B, 1, {0x19} },/* VGL = -12V */
  186. {0x5D, 1, {0x70} },
  187. {0x5E, 1, {0x50} },
  188. {0x5F, 1, {0x3F} },
  189. {0x60, 1, {0x31} },
  190. {0x61, 1, {0x2D} },
  191. {0x62, 1, {0x1D} },
  192. {0x63, 1, {0x22} },
  193. {0x64, 1, {0x0C} },
  194. {0x65, 1, {0x25} },
  195. {0x66, 1, {0x24} },
  196. {0x67, 1, {0x24} },
  197. {0x68, 1, {0x41} },
  198. {0x69, 1, {0x2F} },
  199. {0x6A, 1, {0x36} },
  200. {0x6B, 1, {0x28} },
  201. {0x6C, 1, {0x26} },
  202. {0x6D, 1, {0x1C} },
  203. {0x6E, 1, {0x08} },
  204. {0x6F, 1, {0x02} },
  205. {0x70, 1, {0x70} },
  206. {0x71, 1, {0x50} },
  207. {0x72, 1, {0x3F} },
  208. {0x73, 1, {0x31} },
  209. {0x74, 1, {0x2D} },
  210. {0x75, 1, {0x1D} },
  211. {0x76, 1, {0x22} },
  212. {0x77, 1, {0x0C} },
  213. {0x78, 1, {0x25} },
  214. {0x79, 1, {0x24} },
  215. {0x7A, 1, {0x24} },
  216. {0x7B, 1, {0x41} },
  217. {0x7C, 1, {0x2F} },
  218. {0x7D, 1, {0x36} },
  219. {0x7E, 1, {0x28} },
  220. {0x7F, 1, {0x26} },
  221. {0x80, 1, {0x1C} },
  222. {0x81, 1, {0x08} },
  223. {0x82, 1, {0x02} },
  224. {0xE0, 1, {0x02} },
  225. {0x00, 1, {0x00} },
  226. {0x01, 1, {0x04} },
  227. {0x02, 1, {0x06} },
  228. {0x03, 1, {0x08} },
  229. {0x04, 1, {0x0A} },
  230. {0x05, 1, {0x0C} },
  231. {0x06, 1, {0x0E} },
  232. {0x07, 1, {0x17} },
  233. {0x08, 1, {0x37} },
  234. {0x09, 1, {0x1F} },
  235. {0x0A, 1, {0x10} },
  236. {0x0B, 1, {0x1F} },
  237. {0x0C, 1, {0x1F} },
  238. {0x0D, 1, {0x1F} },
  239. {0x0E, 1, {0x1F} },
  240. {0x0F, 1, {0x1F} },
  241. {0x10, 1, {0x1F} },
  242. {0x11, 1, {0x1F} },
  243. {0x12, 1, {0x1F} },
  244. {0x13, 1, {0x12} },
  245. {0x14, 1, {0x1F} },
  246. {0x15, 1, {0x1F} },
  247. {0x16, 1, {0x01} },
  248. {0x17, 1, {0x05} },
  249. {0x18, 1, {0x07} },
  250. {0x19, 1, {0x09} },
  251. {0x1A, 1, {0x0B} },
  252. {0x1B, 1, {0x0D} },
  253. {0x1C, 1, {0x0F} },
  254. {0x1D, 1, {0x17} },
  255. {0x1E, 1, {0x37} },
  256. {0x1F, 1, {0x1F} },
  257. {0x20, 1, {0x11} },
  258. {0x21, 1, {0x1F} },
  259. {0x22, 1, {0x1F} },
  260. {0x23, 1, {0x1F} },
  261. {0x24, 1, {0x1F} },
  262. {0x25, 1, {0x1F} },
  263. {0x26, 1, {0x1F} },
  264. {0x27, 1, {0x1F} },
  265. {0x28, 1, {0x1F} },
  266. {0x29, 1, {0x13} },
  267. {0x2A, 1, {0x1F} },
  268. {0x2B, 1, {0x1F} },
  269. {0x2C, 1, {0x11} },
  270. {0x2D, 1, {0x0F} },
  271. {0x2E, 1, {0x0D} },
  272. {0x2F, 1, {0x0B} },
  273. {0x30, 1, {0x09} },
  274. {0x31, 1, {0x07} },
  275. {0x32, 1, {0x05} },
  276. {0x33, 1, {0x37} },
  277. {0x34, 1, {0x17} },
  278. {0x35, 1, {0x1F} },
  279. {0x36, 1, {0x01} },
  280. {0x37, 1, {0x1F} },
  281. {0x38, 1, {0x1F} },
  282. {0x39, 1, {0x1F} },
  283. {0x3A, 1, {0x1F} },
  284. {0x3B, 1, {0x1F} },
  285. {0x3C, 1, {0x1F} },
  286. {0x3D, 1, {0x1F} },
  287. {0x3E, 1, {0x1F} },
  288. {0x3F, 1, {0x13} },
  289. {0x40, 1, {0x1F} },
  290. {0x41, 1, {0x1F} },
  291. {0x42, 1, {0x10} },
  292. {0x43, 1, {0x0E} },
  293. {0x44, 1, {0x0C} },
  294. {0x45, 1, {0x0A} },
  295. {0x46, 1, {0x08} },
  296. {0x47, 1, {0x06} },
  297. {0x48, 1, {0x04} },
  298. {0x49, 1, {0x37} },
  299. {0x4A, 1, {0x17} },
  300. {0x4B, 1, {0x1F} },
  301. {0x4C, 1, {0x00} },
  302. {0x4D, 1, {0x1F} },
  303. {0x4E, 1, {0x1F} },
  304. {0x4F, 1, {0x1F} },
  305. {0x50, 1, {0x1F} },
  306. {0x51, 1, {0x1F} },
  307. {0x52, 1, {0x1F} },
  308. {0x53, 1, {0x1F} },
  309. {0x54, 1, {0x1F} },
  310. {0x55, 1, {0x12} },
  311. {0x56, 1, {0x1F} },
  312. {0x57, 1, {0x1F} },
  313. {0x58, 1, {0x10} },
  314. {0x59, 1, {0x00} },
  315. {0x5A, 1, {0x00} },
  316. {0x5B, 1, {0x10} },
  317. {0x5C, 1, {0x07} },
  318. {0x5D, 1, {0x30} },
  319. {0x5E, 1, {0x00} },
  320. {0x5F, 1, {0x00} },
  321. {0x60, 1, {0x30} },
  322. {0x61, 1, {0x03} },
  323. {0x62, 1, {0x04} },
  324. {0x63, 1, {0x03} },
  325. {0x64, 1, {0x6A} }, /* SETV_OFF, 1, { modify 20140806 */
  326. {0x65, 1, {0x75} },
  327. {0x66, 1, {0x0D} },
  328. {0x67, 1, {0xB3} },
  329. {0x68, 1, {0x09} },
  330. {0x69, 1, {0x06} },
  331. {0x6A, 1, {0x6A} }, /* CKV_OFF, 1, { modify 20140806 */
  332. {0x6B, 1, {0x04} },
  333. {0x6C, 1, {0x00} },
  334. {0x6D, 1, {0x04} },
  335. {0x6E, 1, {0x04} },
  336. {0x6F, 1, {0x88} },
  337. {0x70, 1, {0x00} },
  338. {0x71, 1, {0x00} },
  339. {0x72, 1, {0x06} },
  340. {0x73, 1, {0x7B} },
  341. {0x74, 1, {0x00} },
  342. {0x75, 1, {0xBC} },
  343. {0x76, 1, {0x00} },
  344. {0x77, 1, {0x0D} },
  345. {0x78, 1, {0x2C} },
  346. {0x79, 1, {0x00} },
  347. {0x7A, 1, {0x00} },
  348. {0x7B, 1, {0x00} },
  349. {0x7C, 1, {0x00} },
  350. {0x7D, 1, {0x03} },
  351. {0x7E, 1, {0x7B} },
  352. {0xE0, 1, {0x04} },
  353. {0x2B, 1, {0x2B} },
  354. {0x2E, 1, {0x44} },
  355. {0xE0, 1, {0x00} },
  356. {0xE6, 1, {0x02} }, /* Watch dog */
  357. {0xE7, 1, {0x02} }, /* Watch dog */
  358. {0x11, 1, {0x00} }, /* SLPOUT */
  359. {REGFLAG_DELAY, 120, {} },
  360. {0x29, 1, {0x00} }, /* DSPON */
  361. {REGFLAG_DELAY, 5, {} },
  362. {REGFLAG_END_OF_TABLE, 0x00, {} }
  363. };
  364. #endif
  365. static void LCD_panel_init(u32 sel)
  366. {
  367. u32 i;
  368. for (i = 0; ; i++) {
  369. if (lcm_initialization_setting[i].cmd == REGFLAG_END_OF_TABLE)
  370. break;
  371. else if (lcm_initialization_setting[i].cmd == REGFLAG_DELAY)
  372. sunxi_lcd_delay_ms(lcm_initialization_setting[i].count);
  373. else {
  374. #ifdef SUPPORT_DSI
  375. dsi_dcs_wr(0, lcm_initialization_setting[i].cmd,
  376. lcm_initialization_setting[i].para_list,
  377. lcm_initialization_setting[i].count);
  378. #endif
  379. }
  380. }
  381. /* Begin to translate data */
  382. sunxi_lcd_dsi_clk_enable(sel);
  383. return;
  384. }
  385. static void LCD_panel_exit(u32 sel)
  386. {
  387. sunxi_lcd_dsi_clk_disable(sel);
  388. /* panel_reset(0); */
  389. return;
  390. }
  391. /* sel: 0:lcd0; 1:lcd1 */
  392. static __s32 LCD_user_defined_func(u32 sel, u32 para1, u32 para2, u32 para3)
  393. {
  394. return 0;
  395. }
  396. struct __lcd_panel WilliamLcd_panel = {
  397. /* panel driver name, must mach the name of lcd_drv_name in sys_config.fex */
  398. .name = "WilliamLcd",
  399. .func = {
  400. .cfg_panel_info = LCD_cfg_panel_info,
  401. .cfg_open_flow = LCD_open_flow,
  402. .cfg_close_flow = LCD_close_flow,
  403. .lcd_user_defined_func = LCD_user_defined_func,
  404. },
  405. };