dsi_panel.h 6.9 KB

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