dsi_panel.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _DSI_PANEL_H_
  6. #define _DSI_PANEL_H_
  7. #include <linux/of_device.h>
  8. #include <linux/types.h>
  9. #include <linux/bitops.h>
  10. #include <linux/errno.h>
  11. #include <linux/backlight.h>
  12. #include <drm/drm_panel.h>
  13. #include <drm/msm_drm.h>
  14. #include "dsi_defs.h"
  15. #include "dsi_ctrl_hw.h"
  16. #include "dsi_clk.h"
  17. #include "dsi_pwr.h"
  18. #include "dsi_parser.h"
  19. #include "msm_drv.h"
  20. #define MAX_BL_LEVEL 4096
  21. #define MAX_BL_SCALE_LEVEL 1024
  22. #define MAX_SV_BL_SCALE_LEVEL 65535
  23. #define DSI_CMD_PPS_SIZE 135
  24. #define DSI_CMD_PPS_HDR_SIZE 7
  25. #define DSI_MODE_MAX 32
  26. enum dsi_panel_rotation {
  27. DSI_PANEL_ROTATE_NONE = 0,
  28. DSI_PANEL_ROTATE_HV_FLIP,
  29. DSI_PANEL_ROTATE_H_FLIP,
  30. DSI_PANEL_ROTATE_V_FLIP
  31. };
  32. enum dsi_backlight_type {
  33. DSI_BACKLIGHT_PWM = 0,
  34. DSI_BACKLIGHT_WLED,
  35. DSI_BACKLIGHT_DCS,
  36. DSI_BACKLIGHT_EXTERNAL,
  37. DSI_BACKLIGHT_UNKNOWN,
  38. DSI_BACKLIGHT_MAX,
  39. };
  40. enum bl_update_flag {
  41. BL_UPDATE_DELAY_UNTIL_FIRST_FRAME,
  42. BL_UPDATE_NONE,
  43. };
  44. enum {
  45. MODE_GPIO_NOT_VALID = 0,
  46. MODE_SEL_DUAL_PORT,
  47. MODE_SEL_SINGLE_PORT,
  48. MODE_GPIO_HIGH,
  49. MODE_GPIO_LOW,
  50. };
  51. enum dsi_dms_mode {
  52. DSI_DMS_MODE_DISABLED = 0,
  53. DSI_DMS_MODE_RES_SWITCH_IMMEDIATE,
  54. };
  55. enum dsi_panel_physical_type {
  56. DSI_DISPLAY_PANEL_TYPE_LCD = 0,
  57. DSI_DISPLAY_PANEL_TYPE_OLED,
  58. DSI_DISPLAY_PANEL_TYPE_MAX,
  59. };
  60. struct dsi_dfps_capabilities {
  61. enum dsi_dfps_type type;
  62. u32 min_refresh_rate;
  63. u32 max_refresh_rate;
  64. u32 *dfps_list;
  65. u32 dfps_list_len;
  66. bool dfps_support;
  67. };
  68. struct dsi_dyn_clk_caps {
  69. bool dyn_clk_support;
  70. u32 *bit_clk_list;
  71. u32 bit_clk_list_len;
  72. enum dsi_dyn_clk_feature_type type;
  73. bool maintain_const_fps;
  74. };
  75. struct dsi_pinctrl_info {
  76. struct pinctrl *pinctrl;
  77. struct pinctrl_state *active;
  78. struct pinctrl_state *suspend;
  79. };
  80. struct dsi_panel_phy_props {
  81. u32 panel_width_mm;
  82. u32 panel_height_mm;
  83. enum dsi_panel_rotation rotation;
  84. };
  85. struct dsi_backlight_config {
  86. enum dsi_backlight_type type;
  87. enum bl_update_flag bl_update;
  88. u32 bl_min_level;
  89. u32 bl_max_level;
  90. u32 brightness_max_level;
  91. u32 bl_level;
  92. u32 bl_scale;
  93. u32 bl_scale_sv;
  94. int en_gpio;
  95. /* PWM params */
  96. struct pwm_device *pwm_bl;
  97. bool pwm_enabled;
  98. u32 pwm_period_usecs;
  99. /* WLED params */
  100. struct led_trigger *wled;
  101. struct backlight_device *raw_bd;
  102. };
  103. struct dsi_reset_seq {
  104. u32 level;
  105. u32 sleep_ms;
  106. };
  107. struct dsi_panel_reset_config {
  108. struct dsi_reset_seq *sequence;
  109. u32 count;
  110. int reset_gpio;
  111. int disp_en_gpio;
  112. int lcd_mode_sel_gpio;
  113. u32 mode_sel_state;
  114. };
  115. enum esd_check_status_mode {
  116. ESD_MODE_REG_READ,
  117. ESD_MODE_SW_BTA,
  118. ESD_MODE_PANEL_TE,
  119. ESD_MODE_SW_SIM_SUCCESS,
  120. ESD_MODE_SW_SIM_FAILURE,
  121. ESD_MODE_MAX
  122. };
  123. struct drm_panel_esd_config {
  124. bool esd_enabled;
  125. enum esd_check_status_mode status_mode;
  126. struct dsi_panel_cmd_set status_cmd;
  127. u32 *status_cmds_rlen;
  128. u32 *status_valid_params;
  129. u32 *status_value;
  130. u8 *return_buf;
  131. u8 *status_buf;
  132. u32 groups;
  133. };
  134. struct dsi_panel_spr_info {
  135. bool enable;
  136. enum msm_display_spr_pack_type pack_type;
  137. };
  138. struct dsi_panel {
  139. const char *name;
  140. const char *type;
  141. struct device_node *panel_of_node;
  142. struct mipi_dsi_device mipi_device;
  143. struct mutex panel_lock;
  144. struct drm_panel drm_panel;
  145. struct mipi_dsi_host *host;
  146. struct device *parent;
  147. struct dsi_host_common_cfg host_config;
  148. struct dsi_video_engine_cfg video_config;
  149. struct dsi_cmd_engine_cfg cmd_config;
  150. enum dsi_op_mode panel_mode;
  151. bool panel_mode_switch_enabled;
  152. bool poms_align_vsync;
  153. struct dsi_dfps_capabilities dfps_caps;
  154. struct dsi_dyn_clk_caps dyn_clk_caps;
  155. struct dsi_panel_phy_props phy_props;
  156. struct dsi_display_mode *cur_mode;
  157. u32 num_timing_nodes;
  158. u32 num_display_modes;
  159. struct dsi_regulator_info power_info;
  160. struct dsi_backlight_config bl_config;
  161. struct dsi_panel_reset_config reset_config;
  162. struct dsi_pinctrl_info pinctrl;
  163. struct drm_panel_hdr_properties hdr_props;
  164. struct drm_panel_esd_config esd_config;
  165. struct dsi_parser_utils utils;
  166. bool lp11_init;
  167. bool ulps_feature_enabled;
  168. bool ulps_suspend_enabled;
  169. bool allow_phy_power_off;
  170. atomic_t esd_recovery_pending;
  171. bool panel_initialized;
  172. bool te_using_watchdog_timer;
  173. u32 qsync_min_fps;
  174. char dce_pps_cmd[DSI_CMD_PPS_SIZE];
  175. enum dsi_dms_mode dms_mode;
  176. struct dsi_panel_spr_info spr_info;
  177. bool sync_broadcast_en;
  178. int panel_test_gpio;
  179. int power_mode;
  180. enum dsi_panel_physical_type panel_type;
  181. };
  182. static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel)
  183. {
  184. return panel->ulps_feature_enabled;
  185. }
  186. static inline bool dsi_panel_initialized(struct dsi_panel *panel)
  187. {
  188. return panel->panel_initialized;
  189. }
  190. static inline void dsi_panel_acquire_panel_lock(struct dsi_panel *panel)
  191. {
  192. mutex_lock(&panel->panel_lock);
  193. }
  194. static inline void dsi_panel_release_panel_lock(struct dsi_panel *panel)
  195. {
  196. mutex_unlock(&panel->panel_lock);
  197. }
  198. static inline bool dsi_panel_is_type_oled(struct dsi_panel *panel)
  199. {
  200. return (panel->panel_type == DSI_DISPLAY_PANEL_TYPE_OLED);
  201. }
  202. struct dsi_panel *dsi_panel_get(struct device *parent,
  203. struct device_node *of_node,
  204. struct device_node *parser_node,
  205. const char *type,
  206. int topology_override);
  207. int dsi_panel_trigger_esd_attack(struct dsi_panel *panel);
  208. void dsi_panel_put(struct dsi_panel *panel);
  209. int dsi_panel_drv_init(struct dsi_panel *panel, struct mipi_dsi_host *host);
  210. int dsi_panel_drv_deinit(struct dsi_panel *panel);
  211. int dsi_panel_get_mode_count(struct dsi_panel *panel);
  212. void dsi_panel_put_mode(struct dsi_display_mode *mode);
  213. int dsi_panel_get_mode(struct dsi_panel *panel,
  214. u32 index,
  215. struct dsi_display_mode *mode,
  216. int topology_override);
  217. int dsi_panel_validate_mode(struct dsi_panel *panel,
  218. struct dsi_display_mode *mode);
  219. int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
  220. struct dsi_display_mode *mode,
  221. struct dsi_host_config *config);
  222. int dsi_panel_get_phy_props(struct dsi_panel *panel,
  223. struct dsi_panel_phy_props *phy_props);
  224. int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
  225. struct dsi_dfps_capabilities *dfps_caps);
  226. int dsi_panel_pre_prepare(struct dsi_panel *panel);
  227. int dsi_panel_set_lp1(struct dsi_panel *panel);
  228. int dsi_panel_set_lp2(struct dsi_panel *panel);
  229. int dsi_panel_set_nolp(struct dsi_panel *panel);
  230. int dsi_panel_prepare(struct dsi_panel *panel);
  231. int dsi_panel_enable(struct dsi_panel *panel);
  232. int dsi_panel_post_enable(struct dsi_panel *panel);
  233. int dsi_panel_pre_disable(struct dsi_panel *panel);
  234. int dsi_panel_disable(struct dsi_panel *panel);
  235. int dsi_panel_unprepare(struct dsi_panel *panel);
  236. int dsi_panel_post_unprepare(struct dsi_panel *panel);
  237. int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl);
  238. int dsi_panel_update_pps(struct dsi_panel *panel);
  239. int dsi_panel_send_qsync_on_dcs(struct dsi_panel *panel,
  240. int ctrl_idx);
  241. int dsi_panel_send_qsync_off_dcs(struct dsi_panel *panel,
  242. int ctrl_idx);
  243. int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx,
  244. struct dsi_rect *roi);
  245. int dsi_panel_pre_mode_switch_to_video(struct dsi_panel *panel);
  246. int dsi_panel_pre_mode_switch_to_cmd(struct dsi_panel *panel);
  247. int dsi_panel_mode_switch_to_cmd(struct dsi_panel *panel);
  248. int dsi_panel_mode_switch_to_vid(struct dsi_panel *panel);
  249. int dsi_panel_switch(struct dsi_panel *panel);
  250. int dsi_panel_post_switch(struct dsi_panel *panel);
  251. void dsi_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, int intf_width);
  252. void dsi_panel_bl_handoff(struct dsi_panel *panel);
  253. struct dsi_panel *dsi_panel_ext_bridge_get(struct device *parent,
  254. struct device_node *of_node,
  255. int topology_override);
  256. int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel);
  257. void dsi_panel_ext_bridge_put(struct dsi_panel *panel);
  258. void dsi_panel_calc_dsi_transfer_time(struct dsi_host_common_cfg *config,
  259. struct dsi_display_mode *mode, u32 frame_threshold_us);
  260. #endif /* _DSI_PANEL_H_ */