panel_gc9c01.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <sys/byteorder.h>
  7. #include "panel_gc9c01.h"
  8. #include "panel_device.h"
  9. /*********************
  10. * DEFINES
  11. *********************/
  12. /**********************
  13. * TYPEDEFS
  14. **********************/
  15. /**********************
  16. * STATIC PROTOTYPES
  17. **********************/
  18. /**********************
  19. * STATIC VARIABLES
  20. **********************/
  21. /**********************
  22. * MACROS
  23. **********************/
  24. /**********************
  25. * FUNCTIONS
  26. **********************/
  27. static void _panel_transmit(const struct device *dev, uint32_t cmd,
  28. const uint8_t *tx_data, size_t tx_count)
  29. {
  30. struct lcd_panel_data *data = dev->data;
  31. assert(data->transfering == 0);
  32. display_controller_write_config(data->lcdc_dev, (0x02 << 24) | (cmd << 8), tx_data, tx_count);
  33. }
  34. static inline void _panel_transmit_cmd(const struct device *dev, uint32_t cmd)
  35. {
  36. _panel_transmit(dev, cmd, NULL, 0);
  37. }
  38. static inline void _panel_transmit_p1(const struct device *dev, uint32_t cmd, uint8_t tx_data)
  39. {
  40. _panel_transmit(dev, cmd, &tx_data, 1);
  41. }
  42. static void _panel_exit_sleep(const struct device *dev)
  43. {
  44. struct lcd_panel_data *data = dev->data;
  45. _panel_transmit_cmd(dev, DDIC_CMD_SLPOUT);
  46. k_msleep(120);
  47. data->in_sleep = 0;
  48. }
  49. static void _panel_init_te(const struct device *dev)
  50. {
  51. const struct lcd_panel_config *config = dev->config;
  52. if (config->videomode.flags & (DISPLAY_FLAGS_TE_HIGH | DISPLAY_FLAGS_TE_LOW)) {
  53. uint8_t tmp[2];
  54. tmp[0] = 0x10;
  55. _panel_transmit(dev, 0x84, tmp, 1);
  56. tmp[0] = 0x02; /* pulse width: 3 line time */
  57. tmp[1] = (config->videomode.flags & DISPLAY_FLAGS_TE_LOW) ? 1 : 0;
  58. _panel_transmit(dev, DDIC_CMD_TECTL, tmp, 2);
  59. sys_put_be16(CONFIG_PANEL_TE_SCANLINE, tmp);
  60. _panel_transmit(dev, DDIC_CMD_STESL, tmp, 2);
  61. tmp[0] = 0; /* only output vsync */
  62. _panel_transmit(dev, DDIC_CMD_TEON, tmp, 1);
  63. } else {
  64. _panel_transmit(dev, DDIC_CMD_TEOFF, NULL, 0);
  65. }
  66. }
  67. static int _panel_init(const struct device *dev)
  68. {
  69. _panel_exit_sleep(dev);
  70. // internal reg enable
  71. _panel_transmit(dev, DDIC_CMD_INTERREG_EN1, NULL, 0);
  72. _panel_transmit(dev, DDIC_CMD_INTERREG_EN2, NULL, 0);
  73. //reg_en for 70\74
  74. _panel_transmit_p1(dev, 0x80, 0x11);
  75. //reg_en for 7C\7D\7E
  76. _panel_transmit_p1(dev, 0x81, 0x70);
  77. //reg_en for 90\93
  78. _panel_transmit_p1(dev, 0x82, 0x09);
  79. //reg_en for 98\99
  80. _panel_transmit_p1(dev, 0x83, 0x03);
  81. //reg_en for B5
  82. _panel_transmit_p1(dev, 0x84, 0x20);
  83. //reg_en for B9\BE
  84. _panel_transmit_p1(dev, 0x85, 0x42);
  85. //reg_en for C2~7
  86. _panel_transmit_p1(dev, 0x86, 0xfc);
  87. //reg_en for C8\CB
  88. _panel_transmit_p1(dev, 0x87, 0x09);
  89. //reg_en for EC
  90. _panel_transmit_p1(dev, 0x89, 0x10);
  91. //reg_en for F0~3\F6
  92. _panel_transmit_p1(dev, 0x8A, 0x4f);
  93. //reg_en for 60\63\64\66
  94. _panel_transmit_p1(dev, 0x8C, 0x59);
  95. //reg_en for 68\6C\6E
  96. _panel_transmit_p1(dev, 0x8D, 0x51);
  97. //reg_en for A1~3\A5\A7
  98. _panel_transmit_p1(dev, 0x8E, 0xae);
  99. //reg_en for AC~F\A8\A9
  100. _panel_transmit_p1(dev, 0x8F, 0xf3);
  101. _panel_transmit_p1(dev, DDIC_CMD_MADCTL, 0x00);
  102. // 565 frame
  103. _panel_transmit_p1(dev, DDIC_CMD_COLMOD, 0x05);
  104. // 2COL
  105. _panel_transmit_p1(dev, DDIC_CMD_INVERSION, 0x77);
  106. // rtn 60Hz
  107. const uint8_t rtn_data[] = { 0x01, 0x80, 0x00, 0x00, 0x00, 0x00 };
  108. _panel_transmit(dev, 0x74, rtn_data, sizeof(rtn_data));
  109. // bvdd 3x
  110. _panel_transmit_p1(dev, 0x98, 0x3E);
  111. // bvee -2x
  112. _panel_transmit_p1(dev, 0x99, 0x3E);
  113. // VBP
  114. //_panel_transmit_p1(p_gc9c01, 0xC3, 0x2A);
  115. _panel_transmit_p1(dev, 0xC3, 0x3A + 4);
  116. // VBN
  117. //_panel_transmit_p1(p_gc9c01, 0xC4, 0x18);
  118. _panel_transmit_p1(dev, 0xC4, 0x16 + 4);
  119. const uint8_t data_0xA1A2[] = { 0x01, 0x04 };
  120. _panel_transmit(dev, 0xA1, data_0xA1A2, sizeof(data_0xA1A2));
  121. _panel_transmit(dev, 0xA2, data_0xA1A2, sizeof(data_0xA1A2));
  122. // IREF
  123. _panel_transmit_p1(dev, 0xA9, 0x1C);
  124. const uint8_t data_0xA5[] = { 0x11, 0x09 }; //VDDMA,VDDML
  125. _panel_transmit(dev, 0xA5, data_0xA5, sizeof(data_0xA5));
  126. // RTERM
  127. _panel_transmit_p1(dev, 0xB9, 0x8A);
  128. //VBG_BUF, DVDD
  129. _panel_transmit_p1(dev, 0xA8, 0x5E);
  130. _panel_transmit_p1(dev, 0xA7, 0x40);
  131. //VDDSOU ,VDDGM
  132. _panel_transmit_p1(dev, 0xAF, 0x73);
  133. //VREE,VRDD
  134. _panel_transmit_p1(dev, 0xAE, 0x44);
  135. //VRGL ,VDDSF
  136. _panel_transmit_p1(dev, 0xAD, 0x38);
  137. //VRGL ,VDDSF (adjust refresh rate about 60.1~60.6 fps)
  138. _panel_transmit_p1(dev, 0xA3, 0x67);
  139. //VREG_VREF
  140. _panel_transmit_p1(dev, 0xC2, 0x02);
  141. //VREG1A
  142. _panel_transmit_p1(dev, 0xC5, 0x11);
  143. //VREG1B
  144. _panel_transmit_p1(dev, 0xC6, 0x0E);
  145. //VREG2A
  146. _panel_transmit_p1(dev, 0xC7, 0x13);
  147. //VREG2B
  148. _panel_transmit_p1(dev, 0xC8, 0x0D);
  149. //bvdd ref_ad
  150. _panel_transmit_p1(dev, 0xCB, 0x02);
  151. const uint8_t data_0x7C[] = { 0xB6, 0x26 };
  152. _panel_transmit(dev, 0x7C, data_0x7C, sizeof(data_0x7C));
  153. //VGLO
  154. _panel_transmit_p1(dev, 0xAC, 0x24);
  155. //EPF=2
  156. _panel_transmit_p1(dev, 0xF6, 0x80);
  157. //gip start
  158. const uint8_t data_0xB5[] = { 0x09, 0x09 }; //VFP VBP
  159. _panel_transmit(dev, 0xB5, data_0xB5, sizeof(data_0xB5));
  160. const uint8_t data_0x60[] = { 0x38, 0x0B, 0x5B, 0x56 }; //STV1&2
  161. _panel_transmit(dev, 0x60, data_0x60, sizeof(data_0x60));
  162. const uint8_t data_0x63[] = { 0x3A, 0xE0, 0x5B, 0x56 }; //STV3&4
  163. _panel_transmit(dev, 0x63, data_0x63, sizeof(data_0x63));
  164. const uint8_t data_0x64[] = { 0x38, 0x0D, 0x72, 0xDD, 0x5B, 0x56 }; //CLK_group1
  165. _panel_transmit(dev, 0x64, data_0x64, sizeof(data_0x64));
  166. const uint8_t data_0x66[] = { 0x38, 0x11, 0x72, 0xE1, 0x5B, 0x56 }; //CLK_group1
  167. _panel_transmit(dev, 0x66, data_0x66, sizeof(data_0x66));
  168. const uint8_t data_0x68[] = { 0x3B, 0x08, 0x08, 0x00, 0x08, 0x29, 0x5B }; //FLC&FLV 1~2
  169. _panel_transmit(dev, 0x68, data_0x68, sizeof(data_0x68));
  170. const uint8_t data_0x6E[] = {
  171. 0x00, 0x00, 0x00, 0x07, 0x01, 0x13, 0x11, 0x0B, 0x09, 0x16, 0x15, 0x1D,
  172. 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x1D, 0x15, 0x16, 0x0A,
  173. 0x0C, 0x12, 0x14, 0x02, 0x08, 0x00, 0x00, 0x00,
  174. };
  175. _panel_transmit(dev, 0x6E, data_0x6E, sizeof(data_0x6E));
  176. //gip end
  177. //SOU_BIAS_FIX
  178. _panel_transmit_p1(dev, 0xBE, 0x11);
  179. const uint8_t data_0x6C[] = { 0xCC, 0x0C, 0xCC, 0x84, 0xCC, 0x04, 0x50 }; //precharge GATE
  180. _panel_transmit(dev, 0x6C, data_0x6C, sizeof(data_0x6C));
  181. _panel_transmit_p1(dev, 0x7D, 0x72);
  182. _panel_transmit_p1(dev, 0x7E, 0x38);
  183. const uint8_t data_0x70[] = { 0x02, 0x03, 0x09, 0x05, 0x0C, 0x06, 0x09, 0x05, 0x0C, 0x06 };
  184. _panel_transmit(dev, 0x70, data_0x70, sizeof(data_0x70));
  185. const uint8_t data_0x90[] = { 0x06, 0x06, 0x05, 0x06 };
  186. _panel_transmit(dev, 0x90, data_0x90, sizeof(data_0x90));
  187. const uint8_t data_0x93[] = { 0x45, 0xFF, 0x00 };
  188. _panel_transmit(dev, 0x93, data_0x93, sizeof(data_0x93));
  189. const uint8_t data_0xF0[] = { 0x46, 0x0B, 0x0F, 0x0A, 0x10, 0x3F };
  190. _panel_transmit(dev, DDIC_CMD_GAMSET1, data_0xF0, sizeof(data_0xF0));
  191. const uint8_t data_0xF1[] = { 0x52, 0x9A, 0x4F, 0x36, 0x37, 0xFF };
  192. _panel_transmit(dev, DDIC_CMD_GAMSET2, data_0xF1, sizeof(data_0xF1));
  193. const uint8_t data_0xF2[] = { 0x46, 0x0B, 0x0F, 0x0A, 0x10, 0x3F };
  194. _panel_transmit(dev, DDIC_CMD_GAMSET3, data_0xF2, sizeof(data_0xF2));
  195. const uint8_t data_0xF3[] = { 0x52, 0x9A, 0x4F, 0x36, 0x37, 0xFF };
  196. _panel_transmit(dev, DDIC_CMD_GAMSET4, data_0xF3, sizeof(data_0xF3));
  197. _panel_init_te(dev);
  198. return 0;
  199. }
  200. static int _panel_set_mem_area(const struct device *dev, uint16_t x, uint16_t y, uint16_t w,
  201. uint16_t h)
  202. {
  203. uint16_t cmd_data[2];
  204. x += CONFIG_PANEL_MEM_OFFSET_X;
  205. y += CONFIG_PANEL_MEM_OFFSET_Y;
  206. cmd_data[0] = sys_cpu_to_be16(x);
  207. cmd_data[1] = sys_cpu_to_be16(x + w - 1);
  208. _panel_transmit(dev, DDIC_CMD_CASET, (uint8_t *)&cmd_data[0], 4);
  209. cmd_data[0] = sys_cpu_to_be16(y);
  210. cmd_data[1] = sys_cpu_to_be16(y + h - 1);
  211. _panel_transmit(dev, DDIC_CMD_RASET, (uint8_t *)&cmd_data[0], 4);
  212. return 0;
  213. }
  214. static int _panel_blanking_on(const struct device *dev)
  215. {
  216. _panel_transmit_cmd(dev, DDIC_CMD_DISPOFF);
  217. _panel_transmit_cmd(dev, DDIC_CMD_SLPIN);
  218. return 0;
  219. }
  220. static int _panel_blanking_off(const struct device *dev)
  221. {
  222. struct lcd_panel_data *data = dev->data;
  223. if (data->in_sleep)
  224. _panel_exit_sleep(dev);
  225. _panel_transmit_cmd(dev, DDIC_CMD_DISPON);
  226. k_msleep(120);
  227. return 0;
  228. }
  229. static const struct lcd_panel_ops lcd_panel_ops = {
  230. .init = _panel_init,
  231. .blanking_on = _panel_blanking_on,
  232. .blanking_off = _panel_blanking_off,
  233. .write_prepare = _panel_set_mem_area,
  234. };
  235. const struct lcd_panel_config lcd_panel_gc9c01_config = {
  236. .videoport = PANEL_VIDEO_PORT_INITIALIZER,
  237. .videomode = PANEL_VIDEO_MODE_INITIALIZER,
  238. .ops = &lcd_panel_ops,
  239. .cmd_ramwr = (0x32 << 24 | DDIC_CMD_RAMWR << 8),
  240. .cmd_ramwc = (0x32 << 24 | DDIC_CMD_RAMWRC << 8),
  241. .tw_reset = 10,
  242. .ts_reset = 120,
  243. };