dsi_panel.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _DSI_PANEL_H_
  7. #define _DSI_PANEL_H_
  8. #include <linux/of_device.h>
  9. #include <linux/types.h>
  10. #include <linux/bitops.h>
  11. #include <linux/errno.h>
  12. #include <linux/backlight.h>
  13. #include <drm/drm_panel.h>
  14. #include <drm/msm_drm.h>
  15. #include <drm/msm_drm_pp.h>
  16. #include "dsi_defs.h"
  17. #include "dsi_ctrl_hw.h"
  18. #include "dsi_clk.h"
  19. #include "dsi_pwr.h"
  20. #include "dsi_parser.h"
  21. #include "msm_drv.h"
  22. #define MAX_BL_LEVEL 4096
  23. #define MAX_BL_SCALE_LEVEL 1024
  24. #define MAX_SV_BL_SCALE_LEVEL 65535
  25. #define SV_BL_SCALE_CAP (MAX_SV_BL_SCALE_LEVEL * 4)
  26. #define DSI_CMD_PPS_SIZE 135
  27. #define DSI_CMD_PPS_HDR_SIZE 7
  28. #define DSI_MODE_MAX 32
  29. /*
  30. * Defining custom dsi msg flag.
  31. * Using upper byte of flag field for custom DSI flags.
  32. * Lower byte flags specified in drm_mipi_dsi.h.
  33. */
  34. #define MIPI_DSI_MSG_ASYNC_OVERRIDE BIT(4)
  35. #define MIPI_DSI_MSG_CMD_DMA_SCHED BIT(5)
  36. #define MIPI_DSI_MSG_BATCH_COMMAND BIT(6)
  37. #define MIPI_DSI_MSG_UNICAST_COMMAND BIT(7)
  38. enum dsi_panel_rotation {
  39. DSI_PANEL_ROTATE_NONE = 0,
  40. DSI_PANEL_ROTATE_HV_FLIP,
  41. DSI_PANEL_ROTATE_H_FLIP,
  42. DSI_PANEL_ROTATE_V_FLIP
  43. };
  44. enum dsi_backlight_type {
  45. DSI_BACKLIGHT_PWM = 0,
  46. DSI_BACKLIGHT_WLED,
  47. DSI_BACKLIGHT_DCS,
  48. DSI_BACKLIGHT_EXTERNAL,
  49. DSI_BACKLIGHT_UNKNOWN,
  50. DSI_BACKLIGHT_MAX,
  51. };
  52. enum bl_update_flag {
  53. BL_UPDATE_DELAY_UNTIL_FIRST_FRAME,
  54. BL_UPDATE_NONE,
  55. };
  56. enum {
  57. MODE_GPIO_NOT_VALID = 0,
  58. MODE_SEL_DUAL_PORT,
  59. MODE_SEL_SINGLE_PORT,
  60. MODE_GPIO_HIGH,
  61. MODE_GPIO_LOW,
  62. };
  63. enum dsi_dms_mode {
  64. DSI_DMS_MODE_DISABLED = 0,
  65. DSI_DMS_MODE_RES_SWITCH_IMMEDIATE,
  66. };
  67. enum dsi_panel_physical_type {
  68. DSI_DISPLAY_PANEL_TYPE_LCD = 0,
  69. DSI_DISPLAY_PANEL_TYPE_OLED,
  70. DSI_DISPLAY_PANEL_TYPE_MAX,
  71. };
  72. struct dsi_dfps_capabilities {
  73. enum dsi_dfps_type type;
  74. u32 min_refresh_rate;
  75. u32 max_refresh_rate;
  76. u32 *dfps_list;
  77. u32 dfps_list_len;
  78. bool dfps_support;
  79. };
  80. struct dsi_qsync_capabilities {
  81. bool qsync_support;
  82. u32 qsync_min_fps;
  83. u32 *qsync_min_fps_list;
  84. int qsync_min_fps_list_len;
  85. };
  86. struct dsi_avr_capabilities {
  87. u32 avr_step_fps;
  88. u32 *avr_step_fps_list;
  89. u32 avr_step_fps_list_len;
  90. };
  91. struct dsi_dyn_clk_caps {
  92. bool dyn_clk_support;
  93. enum dsi_dyn_clk_feature_type type;
  94. bool maintain_const_fps;
  95. };
  96. struct dsi_pinctrl_info {
  97. struct pinctrl *pinctrl;
  98. struct pinctrl_state *active;
  99. struct pinctrl_state *suspend;
  100. struct pinctrl_state *pwm_pin;
  101. };
  102. struct dsi_panel_phy_props {
  103. u32 panel_width_mm;
  104. u32 panel_height_mm;
  105. enum dsi_panel_rotation rotation;
  106. };
  107. struct dsi_backlight_config {
  108. enum dsi_backlight_type type;
  109. enum bl_update_flag bl_update;
  110. u32 bl_min_level;
  111. u32 bl_max_level;
  112. u32 brightness_max_level;
  113. /* current brightness value */
  114. u32 brightness;
  115. u32 bl_level;
  116. u32 bl_scale;
  117. u32 bl_scale_sv;
  118. bool bl_inverted_dbv;
  119. /* digital dimming backlight LUT */
  120. struct drm_msm_dimming_bl_lut *dimming_bl_lut;
  121. u32 dimming_min_bl;
  122. u32 dimming_status;
  123. bool user_disable_notification;
  124. int en_gpio;
  125. /* PWM params */
  126. struct pwm_device *pwm_bl;
  127. bool pwm_enabled;
  128. u32 pwm_period_usecs;
  129. /* WLED params */
  130. struct led_trigger *wled;
  131. struct backlight_device *raw_bd;
  132. /* DCS params */
  133. bool lp_mode;
  134. };
  135. struct dsi_reset_seq {
  136. u32 level;
  137. u32 sleep_ms;
  138. };
  139. struct dsi_panel_reset_config {
  140. struct dsi_reset_seq *sequence;
  141. u32 count;
  142. int reset_gpio;
  143. int disp_en_gpio;
  144. int lcd_mode_sel_gpio;
  145. u32 mode_sel_state;
  146. };
  147. enum esd_check_status_mode {
  148. ESD_MODE_REG_READ,
  149. ESD_MODE_SW_BTA,
  150. ESD_MODE_PANEL_TE,
  151. ESD_MODE_SW_SIM_SUCCESS,
  152. ESD_MODE_SW_SIM_FAILURE,
  153. ESD_MODE_MAX
  154. };
  155. struct drm_panel_esd_config {
  156. bool esd_enabled;
  157. enum esd_check_status_mode status_mode;
  158. struct dsi_panel_cmd_set status_cmd;
  159. u32 *status_cmds_rlen;
  160. u32 *status_valid_params;
  161. u32 *status_value;
  162. u8 *return_buf;
  163. u8 *status_buf;
  164. u32 groups;
  165. };
  166. struct dsi_panel_spr_info {
  167. bool enable;
  168. enum msm_display_spr_pack_type pack_type;
  169. };
  170. struct dsi_panel;
  171. struct dsi_panel_ops {
  172. int (*pinctrl_init)(struct dsi_panel *panel);
  173. int (*gpio_request)(struct dsi_panel *panel);
  174. int (*pinctrl_deinit)(struct dsi_panel *panel);
  175. int (*gpio_release)(struct dsi_panel *panel);
  176. int (*bl_register)(struct dsi_panel *panel);
  177. int (*bl_unregister)(struct dsi_panel *panel);
  178. int (*parse_gpios)(struct dsi_panel *panel);
  179. int (*parse_power_cfg)(struct dsi_panel *panel);
  180. int (*trigger_esd_attack)(struct dsi_panel *panel);
  181. };
  182. struct dsi_panel {
  183. const char *name;
  184. const char *type;
  185. struct device_node *panel_of_node;
  186. struct mipi_dsi_device mipi_device;
  187. bool panel_ack_disabled;
  188. struct mutex panel_lock;
  189. struct drm_panel drm_panel;
  190. struct mipi_dsi_host *host;
  191. struct device *parent;
  192. struct dsi_host_common_cfg host_config;
  193. struct dsi_video_engine_cfg video_config;
  194. struct dsi_cmd_engine_cfg cmd_config;
  195. enum dsi_op_mode panel_mode;
  196. bool panel_mode_switch_enabled;
  197. bool poms_align_vsync;
  198. struct dsi_dfps_capabilities dfps_caps;
  199. struct dsi_dyn_clk_caps dyn_clk_caps;
  200. struct dsi_panel_phy_props phy_props;
  201. bool dsc_switch_supported;
  202. struct dsi_display_mode *cur_mode;
  203. u32 num_timing_nodes;
  204. u32 num_display_modes;
  205. struct dsi_regulator_info power_info;
  206. struct dsi_backlight_config bl_config;
  207. struct dsi_panel_reset_config reset_config;
  208. struct dsi_pinctrl_info pinctrl;
  209. struct drm_panel_hdr_properties hdr_props;
  210. struct drm_panel_esd_config esd_config;
  211. struct dsi_parser_utils utils;
  212. bool lp11_init;
  213. bool ulps_feature_enabled;
  214. bool ulps_suspend_enabled;
  215. bool allow_phy_power_off;
  216. bool reset_gpio_always_on;
  217. atomic_t esd_recovery_pending;
  218. bool panel_initialized;
  219. bool te_using_watchdog_timer;
  220. struct dsi_qsync_capabilities qsync_caps;
  221. struct dsi_avr_capabilities avr_caps;
  222. char dce_pps_cmd[DSI_CMD_PPS_SIZE];
  223. enum dsi_dms_mode dms_mode;
  224. struct dsi_panel_spr_info spr_info;
  225. bool sync_broadcast_en;
  226. u32 dsc_count;
  227. u32 lm_count;
  228. int panel_test_gpio;
  229. int power_mode;
  230. enum dsi_panel_physical_type panel_type;
  231. struct dsi_panel_ops panel_ops;
  232. };
  233. static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel)
  234. {
  235. return panel->ulps_feature_enabled;
  236. }
  237. static inline bool dsi_panel_initialized(struct dsi_panel *panel)
  238. {
  239. return panel->panel_initialized;
  240. }
  241. static inline void dsi_panel_acquire_panel_lock(struct dsi_panel *panel)
  242. {
  243. mutex_lock(&panel->panel_lock);
  244. }
  245. static inline void dsi_panel_release_panel_lock(struct dsi_panel *panel)
  246. {
  247. mutex_unlock(&panel->panel_lock);
  248. }
  249. static inline bool dsi_panel_is_type_oled(struct dsi_panel *panel)
  250. {
  251. return (panel->panel_type == DSI_DISPLAY_PANEL_TYPE_OLED);
  252. }
  253. struct dsi_panel *dsi_panel_get(struct device *parent,
  254. struct device_node *of_node,
  255. struct device_node *parser_node,
  256. const char *type,
  257. int topology_override,
  258. bool trusted_vm_env);
  259. void dsi_panel_put(struct dsi_panel *panel);
  260. int dsi_panel_drv_init(struct dsi_panel *panel, struct mipi_dsi_host *host);
  261. int dsi_panel_drv_deinit(struct dsi_panel *panel);
  262. int dsi_panel_get_mode_count(struct dsi_panel *panel);
  263. void dsi_panel_put_mode(struct dsi_display_mode *mode);
  264. int dsi_panel_get_mode(struct dsi_panel *panel,
  265. u32 index,
  266. struct dsi_display_mode *mode,
  267. int topology_override);
  268. int dsi_panel_validate_mode(struct dsi_panel *panel,
  269. struct dsi_display_mode *mode);
  270. int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
  271. struct dsi_display_mode *mode,
  272. struct dsi_host_config *config);
  273. int dsi_panel_get_phy_props(struct dsi_panel *panel,
  274. struct dsi_panel_phy_props *phy_props);
  275. int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
  276. struct dsi_dfps_capabilities *dfps_caps);
  277. int dsi_panel_pre_prepare(struct dsi_panel *panel);
  278. int dsi_panel_set_lp1(struct dsi_panel *panel);
  279. int dsi_panel_set_lp2(struct dsi_panel *panel);
  280. int dsi_panel_set_nolp(struct dsi_panel *panel);
  281. int dsi_panel_prepare(struct dsi_panel *panel);
  282. int dsi_panel_enable(struct dsi_panel *panel);
  283. int dsi_panel_post_enable(struct dsi_panel *panel);
  284. int dsi_panel_pre_disable(struct dsi_panel *panel);
  285. int dsi_panel_disable(struct dsi_panel *panel);
  286. int dsi_panel_unprepare(struct dsi_panel *panel);
  287. int dsi_panel_post_unprepare(struct dsi_panel *panel);
  288. int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl);
  289. int dsi_panel_update_pps(struct dsi_panel *panel);
  290. int dsi_panel_send_qsync_on_dcs(struct dsi_panel *panel,
  291. int ctrl_idx);
  292. int dsi_panel_send_qsync_off_dcs(struct dsi_panel *panel,
  293. int ctrl_idx);
  294. int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx,
  295. struct dsi_rect *roi);
  296. int dsi_panel_switch_video_mode_out(struct dsi_panel *panel);
  297. int dsi_panel_switch_cmd_mode_out(struct dsi_panel *panel);
  298. int dsi_panel_switch_cmd_mode_in(struct dsi_panel *panel);
  299. int dsi_panel_switch_video_mode_in(struct dsi_panel *panel);
  300. int dsi_panel_switch(struct dsi_panel *panel);
  301. int dsi_panel_post_switch(struct dsi_panel *panel);
  302. void dsi_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, int intf_width);
  303. void dsi_panel_bl_handoff(struct dsi_panel *panel);
  304. struct dsi_panel *dsi_panel_ext_bridge_get(struct device *parent,
  305. struct device_node *of_node,
  306. int topology_override);
  307. int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel);
  308. void dsi_panel_ext_bridge_put(struct dsi_panel *panel);
  309. int dsi_panel_get_io_resources(struct dsi_panel *panel,
  310. struct msm_io_res *io_res);
  311. void dsi_panel_calc_dsi_transfer_time(struct dsi_host_common_cfg *config,
  312. struct dsi_display_mode *mode, u32 frame_threshold_us);
  313. int dsi_panel_get_cmd_pkt_count(const char *data, u32 length, u32 *cnt);
  314. int dsi_panel_alloc_cmd_packets(struct dsi_panel_cmd_set *cmd,
  315. u32 packet_count);
  316. int dsi_panel_create_cmd_packets(const char *data, u32 length, u32 count,
  317. struct dsi_cmd_desc *cmd);
  318. void dsi_panel_destroy_cmd_packets(struct dsi_panel_cmd_set *set);
  319. void dsi_panel_dealloc_cmd_packets(struct dsi_panel_cmd_set *set);
  320. #endif /* _DSI_PANEL_H_ */