mtk_panel_ext.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * Copyright (C) 2019 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __MTK_PANEL_EXT_H__
  14. #define __MTK_PANEL_EXT_H__
  15. #include <drm/drm_panel.h>
  16. #define RT_MAX_NUM 10
  17. #define ESD_CHECK_NUM 3
  18. #define MAX_TX_CMD_NUM 20
  19. #define MAX_RX_CMD_NUM 20
  20. #define READ_DDIC_SLOT_NUM 4
  21. #define MAX_DYN_CMD_NUM 20
  22. struct mtk_dsi;
  23. struct cmdq_pkt;
  24. struct mtk_panel_para_table {
  25. u8 count;
  26. u8 para_list[64];
  27. };
  28. /*
  29. * DSI data type:
  30. * DSI_DCS_WRITE_SHORT_PACKET_NO_PARAM 0x05
  31. * DSI_DCS_WRITE_SHORT_PACKET_1_PARAM 0x15
  32. * DSI_DCS_WRITE_LONG_PACKET 0x39
  33. * DSI_DCS_READ_NO_PARAM 0x06
  34. * DSI_GERNERIC_WRITE_SHORT_NO_PARAM 0x03
  35. * DSI_GERNERIC_WRITE_SHORT_1_PARAM 0x13
  36. * DSI_GERNERIC_WRITE_SHORT_1_PARAM 0x23
  37. * DSI_GERNERIC_WRITE_LONG_PACKET 0x29
  38. * DSI_GERNERIC_READ_NO_PARAM 0x04
  39. * DSI_GERNERIC_READ_1_PARAM 0x14
  40. * DSI_GERNERIC_READ_2_PARAM 0x24
  41. */
  42. /**
  43. * struct mtk_ddic_dsi_msg - MTK write/read DDIC RG cmd buffer
  44. * @channel: virtual channel id
  45. * @flags: flags controlling this message transmission
  46. * @type: payload data type array
  47. * @tx_len: length of @tx_buf
  48. * @tx_buf: data array to be written
  49. * @tx_cmd_num: tx cmd number
  50. * @rx_len: length of @rx_buf
  51. * @rx_buf: data array to be read, or NULL
  52. * @rx_cmd_num: rx cmd number
  53. */
  54. struct mtk_ddic_dsi_msg {
  55. u8 channel;
  56. u16 flags;
  57. u8 type[MAX_TX_CMD_NUM];
  58. size_t tx_len[MAX_TX_CMD_NUM];
  59. const void *tx_buf[MAX_TX_CMD_NUM];
  60. size_t tx_cmd_num;
  61. size_t rx_len[MAX_RX_CMD_NUM];
  62. void *rx_buf[MAX_RX_CMD_NUM];
  63. size_t rx_cmd_num;
  64. };
  65. struct DSI_RX_DATA_REG {
  66. unsigned char byte0;
  67. unsigned char byte1;
  68. unsigned char byte2;
  69. unsigned char byte3;
  70. };
  71. typedef void (*dcs_write_gce) (struct mtk_dsi *dsi, struct cmdq_pkt *handle,
  72. const void *data, size_t len);
  73. typedef void (*dcs_grp_write_gce) (struct mtk_dsi *dsi, struct cmdq_pkt *handle,
  74. struct mtk_panel_para_table *para_table,
  75. unsigned int para_size);
  76. typedef int (*panel_tch_rst) (void);
  77. enum MTK_PANEL_OUTPUT_MODE {
  78. MTK_PANEL_SINGLE_PORT = 0x0,
  79. MTK_PANEL_DSC_SINGLE_PORT,
  80. MTK_PANEL_DUAL_PORT,
  81. };
  82. struct esd_check_item {
  83. unsigned char cmd;
  84. unsigned char count;
  85. unsigned char para_list[RT_MAX_NUM];
  86. unsigned char mask_list[RT_MAX_NUM];
  87. };
  88. enum MTK_PANEL_MODE_SWITCH_STAGE {
  89. BEFORE_DSI_POWERDOWN,
  90. AFTER_DSI_POWERON,
  91. };
  92. enum MIPITX_PHY_PORT {
  93. MIPITX_PHY_PORT_0 = 0,
  94. MIPITX_PHY_PORT_1,
  95. MIPITX_PHY_PORT_NUM
  96. };
  97. enum MIPITX_PHY_LANE_SWAP {
  98. MIPITX_PHY_LANE_0 = 0,
  99. MIPITX_PHY_LANE_1,
  100. MIPITX_PHY_LANE_2,
  101. MIPITX_PHY_LANE_3,
  102. MIPITX_PHY_LANE_CK,
  103. MIPITX_PHY_LANE_RX,
  104. MIPITX_PHY_LANE_NUM
  105. };
  106. enum FPS_CHANGE_INDEX {
  107. DYNFPS_NOT_DEFINED = 0,
  108. DYNFPS_DSI_VFP = 1,
  109. DYNFPS_DSI_HFP = 2,
  110. DYNFPS_DSI_MIPI_CLK = 4,
  111. };
  112. struct mtk_panel_dsc_params {
  113. unsigned int enable;
  114. unsigned int ver; /* [7:4] major [3:0] minor */
  115. unsigned int slice_mode;
  116. unsigned int rgb_swap;
  117. unsigned int dsc_cfg;
  118. unsigned int rct_on;
  119. unsigned int bit_per_channel;
  120. unsigned int dsc_line_buf_depth;
  121. unsigned int bp_enable;
  122. unsigned int bit_per_pixel;
  123. unsigned int pic_height; /* need to check */
  124. unsigned int pic_width; /* need to check */
  125. unsigned int slice_height;
  126. unsigned int slice_width;
  127. unsigned int chunk_size;
  128. unsigned int xmit_delay;
  129. unsigned int dec_delay;
  130. unsigned int scale_value;
  131. unsigned int increment_interval;
  132. unsigned int decrement_interval;
  133. unsigned int line_bpg_offset;
  134. unsigned int nfl_bpg_offset;
  135. unsigned int slice_bpg_offset;
  136. unsigned int initial_offset;
  137. unsigned int final_offset;
  138. unsigned int flatness_minqp;
  139. unsigned int flatness_maxqp;
  140. unsigned int rc_model_size;
  141. unsigned int rc_edge_factor;
  142. unsigned int rc_quant_incr_limit0;
  143. unsigned int rc_quant_incr_limit1;
  144. unsigned int rc_tgt_offset_hi;
  145. unsigned int rc_tgt_offset_lo;
  146. };
  147. struct mtk_dsi_phy_timcon {
  148. unsigned int hs_trail;
  149. unsigned int hs_prpr;
  150. unsigned int hs_zero;
  151. unsigned int lpx;
  152. unsigned int ta_get;
  153. unsigned int ta_sure;
  154. unsigned int ta_go;
  155. unsigned int da_hs_exit;
  156. unsigned int clk_trail;
  157. unsigned int cont_det;
  158. unsigned int da_hs_sync;
  159. unsigned int clk_zero;
  160. unsigned int clk_hs_prpr;
  161. unsigned int clk_hs_exit;
  162. unsigned int clk_hs_post;
  163. };
  164. struct dynamic_mipi_params {
  165. unsigned int switch_en;
  166. unsigned int pll_clk;
  167. unsigned int data_rate;
  168. unsigned int vsa;
  169. unsigned int vbp;
  170. unsigned int vfp;
  171. unsigned int vfp_lp_dyn;
  172. unsigned int hsa;
  173. unsigned int hbp;
  174. unsigned int hfp;
  175. };
  176. struct dfps_switch_cmd {
  177. unsigned int src_fps;
  178. unsigned int cmd_num;
  179. unsigned char para_list[64];
  180. };
  181. struct dynamic_fps_params {
  182. unsigned int switch_en;
  183. unsigned int vact_timing_fps;
  184. struct dfps_switch_cmd dfps_cmd_table[MAX_DYN_CMD_NUM];
  185. unsigned int lfr_enable;
  186. unsigned int lfr_minimum_fps;
  187. };
  188. struct mtk_panel_params {
  189. unsigned int pll_clk;
  190. unsigned int data_rate;
  191. struct mtk_dsi_phy_timcon phy_timcon;
  192. unsigned int vfp_low_power;
  193. struct dynamic_mipi_params dyn;
  194. struct dynamic_fps_params dyn_fps;
  195. unsigned int cust_esd_check;
  196. unsigned int esd_check_enable;
  197. struct esd_check_item lcm_esd_check_table[ESD_CHECK_NUM];
  198. unsigned int ssc_disable;
  199. unsigned int ssc_range;
  200. int lcm_color_mode;
  201. unsigned int min_luminance;
  202. unsigned int average_luminance;
  203. unsigned int max_luminance;
  204. unsigned int round_corner_en;
  205. unsigned int corner_pattern_height;
  206. unsigned int corner_pattern_height_bot;
  207. unsigned int corner_pattern_tp_size;
  208. void *corner_pattern_lt_addr;
  209. unsigned int physical_width_um;
  210. unsigned int physical_height_um;
  211. unsigned int lane_swap_en;
  212. unsigned int is_cphy;
  213. enum MIPITX_PHY_LANE_SWAP
  214. lane_swap[MIPITX_PHY_PORT_NUM][MIPITX_PHY_LANE_NUM];
  215. struct mtk_panel_dsc_params dsc_params;
  216. unsigned int output_mode;
  217. unsigned int hbm_en_time;
  218. unsigned int hbm_dis_time;
  219. unsigned int lcm_index;
  220. unsigned int wait_sof_before_dec_vfp;
  221. unsigned int doze_delay;
  222. };
  223. struct mtk_panel_ext {
  224. struct mtk_panel_funcs *funcs;
  225. struct mtk_panel_params *params;
  226. };
  227. struct mtk_panel_ctx {
  228. struct drm_panel *panel;
  229. struct mtk_panel_ext *ext;
  230. struct list_head list;
  231. };
  232. struct mtk_panel_funcs {
  233. int (*set_backlight_cmdq)(void *dsi_drv, dcs_write_gce cb,
  234. void *handle, unsigned int level);
  235. int (*set_aod_light_mode)(void *dsi_drv, dcs_write_gce cb,
  236. void *handle, unsigned int mode);
  237. int (*set_backlight_grp_cmdq)(void *dsi_drv, dcs_grp_write_gce cb,
  238. void *handle, unsigned int level);
  239. int (*reset)(struct drm_panel *panel, int on);
  240. int (*ata_check)(struct drm_panel *panel);
  241. int (*ext_param_set)(struct drm_panel *panel, unsigned int mode);
  242. int (*ext_param_get)(struct mtk_panel_params *ext_para,
  243. unsigned int mode);
  244. int (*mode_switch)(struct drm_panel *panel, unsigned int cur_mode,
  245. unsigned int dst_mode, enum MTK_PANEL_MODE_SWITCH_STAGE stage);
  246. int (*get_virtual_heigh)(void);
  247. int (*get_virtual_width)(void);
  248. /**
  249. * @doze_enable_start:
  250. *
  251. * Call the @doze_enable_start before starting AOD mode.
  252. * The LCM off may add here to avoid panel show unexpected
  253. * content when switching to specific panel low power mode.
  254. */
  255. int (*doze_enable_start)(struct drm_panel *panel,
  256. void *dsi_drv, dcs_write_gce cb, void *handle);
  257. /**
  258. * @doze_enable:
  259. *
  260. * Call the @doze_enable starts AOD mode.
  261. */
  262. int (*doze_enable)(struct drm_panel *panel,
  263. void *dsi_drv, dcs_write_gce cb, void *handle);
  264. /**
  265. * @doze_disable:
  266. *
  267. * Call the @doze_disable before ending AOD mode.
  268. */
  269. int (*doze_disable)(struct drm_panel *panel,
  270. void *dsi_drv, dcs_write_gce cb, void *handle);
  271. /**
  272. * @doze_post_disp_on:
  273. *
  274. * In some situation, the LCM off may set in @doze_enable & @disable.
  275. * After LCM switch to the new mode stable, system call
  276. * @doze_post_disp_on to turn on panel.
  277. */
  278. int (*doze_post_disp_on)(struct drm_panel *panel,
  279. void *dsi_drv, dcs_write_gce cb, void *handle);
  280. /**
  281. * @doze_area:
  282. *
  283. * Send the panel area in command here.
  284. */
  285. int (*doze_area)(struct drm_panel *panel,
  286. void *dsi_drv, dcs_write_gce cb, void *handle);
  287. /**
  288. * @doze_get_mode_flags:
  289. *
  290. * If CV switch is needed for doze mode, fill the mode_flags in this
  291. * function for both CMD and VDO mode.
  292. */
  293. unsigned long (*doze_get_mode_flags)(
  294. struct drm_panel *panel, int aod_en);
  295. int (*hbm_set_cmdq)(struct drm_panel *panel, void *dsi_drv,
  296. dcs_write_gce cb, void *handle, bool en);
  297. void (*hbm_get_state)(struct drm_panel *panel, bool *state);
  298. void (*hbm_get_wait_state)(struct drm_panel *panel, bool *wait);
  299. bool (*hbm_set_wait_state)(struct drm_panel *panel, bool wait);
  300. };
  301. void mtk_panel_init(struct mtk_panel_ctx *ctx);
  302. void mtk_panel_add(struct mtk_panel_ctx *ctx);
  303. void mtk_panel_remove(struct mtk_panel_ctx *ctx);
  304. int mtk_panel_attach(struct mtk_panel_ctx *ctx, struct drm_panel *panel);
  305. int mtk_panel_detach(struct mtk_panel_ctx *ctx);
  306. struct mtk_panel_ext *find_panel_ext(struct drm_panel *panel);
  307. int mtk_panel_ext_create(struct device *dev,
  308. struct mtk_panel_params *ext_params,
  309. struct mtk_panel_funcs *ext_funcs,
  310. struct drm_panel *panel);
  311. int mtk_panel_tch_handle_reg(struct drm_panel *panel);
  312. void **mtk_panel_tch_handle_init(void);
  313. int mtk_panel_tch_rst(struct drm_panel *panel);
  314. #endif