dsi_panel.h 7.1 KB

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