Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 1 | /* |
Rajesh Bharathwaj | 5d99317 | 2020-03-17 22:09:17 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 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 and |
| 6 | * only version 2 as 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 | */ |
| 14 | |
| 15 | #ifndef _DSI_PANEL_H_ |
| 16 | #define _DSI_PANEL_H_ |
| 17 | |
| 18 | #include <linux/of_device.h> |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/bitops.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/leds.h> |
| 23 | #include <drm/drm_panel.h> |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 24 | #include <drm/msm_drm.h> |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 25 | |
| 26 | #include "dsi_defs.h" |
| 27 | #include "dsi_ctrl_hw.h" |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 28 | #include "dsi_clk.h" |
| 29 | #include "dsi_pwr.h" |
Lloyd Atkinson | e53b737 | 2017-03-22 17:16:47 -0400 | [diff] [blame] | 30 | #include "msm_drv.h" |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 31 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 32 | #define MAX_BL_LEVEL 4096 |
Xu Yang | d566d22 | 2017-05-19 17:18:12 +0800 | [diff] [blame] | 33 | #define MAX_BL_SCALE_LEVEL 1024 |
| 34 | #define MAX_AD_BL_SCALE_LEVEL 65535 |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 35 | #define DSI_CMD_PPS_SIZE 135 |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 36 | |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 37 | #define DSI_MODE_MAX 5 |
| 38 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 39 | enum dsi_panel_rotation { |
| 40 | DSI_PANEL_ROTATE_NONE = 0, |
| 41 | DSI_PANEL_ROTATE_HV_FLIP, |
| 42 | DSI_PANEL_ROTATE_H_FLIP, |
| 43 | DSI_PANEL_ROTATE_V_FLIP |
| 44 | }; |
| 45 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 46 | enum dsi_backlight_type { |
| 47 | DSI_BACKLIGHT_PWM = 0, |
| 48 | DSI_BACKLIGHT_WLED, |
| 49 | DSI_BACKLIGHT_DCS, |
| 50 | DSI_BACKLIGHT_UNKNOWN, |
| 51 | DSI_BACKLIGHT_MAX, |
| 52 | }; |
| 53 | |
Tharun Raj Soma | 8720805 | 2018-05-18 20:52:10 +0530 | [diff] [blame] | 54 | enum bl_update_flag { |
| 55 | BL_UPDATE_DELAY_UNTIL_FIRST_FRAME, |
| 56 | BL_UPDATE_NONE, |
| 57 | }; |
| 58 | |
Padmanabhan Komanduru | edfe6ff | 2016-12-19 12:37:04 +0530 | [diff] [blame] | 59 | enum { |
| 60 | MODE_GPIO_NOT_VALID = 0, |
| 61 | MODE_SEL_DUAL_PORT, |
| 62 | MODE_SEL_SINGLE_PORT, |
| 63 | MODE_GPIO_HIGH, |
| 64 | MODE_GPIO_LOW, |
| 65 | }; |
| 66 | |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 67 | enum dsi_dms_mode { |
| 68 | DSI_DMS_MODE_DISABLED = 0, |
| 69 | DSI_DMS_MODE_RES_SWITCH_IMMEDIATE, |
| 70 | }; |
| 71 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 72 | struct dsi_dfps_capabilities { |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 73 | enum dsi_dfps_type type; |
| 74 | u32 min_refresh_rate; |
| 75 | u32 max_refresh_rate; |
Sandeep Panda | 97c89dd | 2018-10-25 15:49:16 +0530 | [diff] [blame] | 76 | u32 *dfps_list; |
| 77 | u32 dfps_list_len; |
| 78 | bool dfps_support; |
| 79 | }; |
| 80 | |
| 81 | struct dsi_dyn_clk_caps { |
| 82 | bool dyn_clk_support; |
| 83 | u32 *bit_clk_list; |
| 84 | u32 bit_clk_list_len; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | struct dsi_pinctrl_info { |
| 88 | struct pinctrl *pinctrl; |
| 89 | struct pinctrl_state *active; |
| 90 | struct pinctrl_state *suspend; |
| 91 | }; |
| 92 | |
| 93 | struct dsi_panel_phy_props { |
| 94 | u32 panel_width_mm; |
| 95 | u32 panel_height_mm; |
| 96 | enum dsi_panel_rotation rotation; |
| 97 | }; |
| 98 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 99 | struct dsi_backlight_config { |
| 100 | enum dsi_backlight_type type; |
Tharun Raj Soma | 8720805 | 2018-05-18 20:52:10 +0530 | [diff] [blame] | 101 | enum bl_update_flag bl_update; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 102 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 103 | u32 bl_min_level; |
| 104 | u32 bl_max_level; |
| 105 | u32 brightness_max_level; |
Xu Yang | d566d22 | 2017-05-19 17:18:12 +0800 | [diff] [blame] | 106 | u32 bl_level; |
| 107 | u32 bl_scale; |
| 108 | u32 bl_scale_ad; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 109 | |
| 110 | int en_gpio; |
| 111 | /* PWM params */ |
| 112 | bool pwm_pmi_control; |
| 113 | u32 pwm_pmic_bank; |
| 114 | u32 pwm_period_usecs; |
| 115 | int pwm_gpio; |
| 116 | |
| 117 | /* WLED params */ |
| 118 | struct led_trigger *wled; |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 119 | struct backlight_device *bd; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | struct dsi_reset_seq { |
| 123 | u32 level; |
| 124 | u32 sleep_ms; |
| 125 | }; |
| 126 | |
| 127 | struct dsi_panel_reset_config { |
| 128 | struct dsi_reset_seq *sequence; |
| 129 | u32 count; |
| 130 | |
| 131 | int reset_gpio; |
| 132 | int disp_en_gpio; |
Padmanabhan Komanduru | edfe6ff | 2016-12-19 12:37:04 +0530 | [diff] [blame] | 133 | int lcd_mode_sel_gpio; |
| 134 | u32 mode_sel_state; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 137 | enum esd_check_status_mode { |
| 138 | ESD_MODE_REG_READ, |
| 139 | ESD_MODE_SW_BTA, |
| 140 | ESD_MODE_PANEL_TE, |
| 141 | ESD_MODE_MAX |
| 142 | }; |
| 143 | |
| 144 | struct drm_panel_esd_config { |
| 145 | bool esd_enabled; |
Yuan Zhao | 0bccca6 | 2018-05-24 18:47:04 +0800 | [diff] [blame] | 146 | bool cmd_channel; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 147 | |
| 148 | enum esd_check_status_mode status_mode; |
| 149 | struct dsi_panel_cmd_set status_cmd; |
| 150 | u32 *status_cmds_rlen; |
| 151 | u32 *status_valid_params; |
| 152 | u32 *status_value; |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 153 | u8 *return_buf; |
| 154 | u8 *status_buf; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 155 | u32 groups; |
| 156 | }; |
| 157 | |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 158 | enum dsi_panel_type { |
| 159 | DSI_PANEL = 0, |
| 160 | EXT_BRIDGE, |
| 161 | DSI_PANEL_TYPE_MAX, |
| 162 | }; |
| 163 | |
Rajesh Bharathwaj | 5d99317 | 2020-03-17 22:09:17 -0700 | [diff] [blame] | 164 | /* Extended Panel config for panels with additional gpios */ |
| 165 | struct dsi_panel_exd_config { |
| 166 | int display_1p8_en; |
| 167 | int led_5v_en; |
| 168 | int switch_power; |
| 169 | int led_en1; |
| 170 | int led_en2; |
| 171 | int oenab; |
| 172 | int selab; |
| 173 | }; |
| 174 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 175 | struct dsi_panel { |
| 176 | const char *name; |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 177 | enum dsi_panel_type type; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 178 | struct device_node *panel_of_node; |
| 179 | struct mipi_dsi_device mipi_device; |
| 180 | |
| 181 | struct mutex panel_lock; |
| 182 | struct drm_panel drm_panel; |
| 183 | struct mipi_dsi_host *host; |
| 184 | struct device *parent; |
| 185 | |
| 186 | struct dsi_host_common_cfg host_config; |
| 187 | struct dsi_video_engine_cfg video_config; |
| 188 | struct dsi_cmd_engine_cfg cmd_config; |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 189 | enum dsi_op_mode panel_mode; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 190 | |
| 191 | struct dsi_dfps_capabilities dfps_caps; |
Sandeep Panda | 97c89dd | 2018-10-25 15:49:16 +0530 | [diff] [blame] | 192 | struct dsi_dyn_clk_caps dyn_clk_caps; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 193 | struct dsi_panel_phy_props phy_props; |
| 194 | |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 195 | struct dsi_display_mode *cur_mode; |
| 196 | u32 num_timing_nodes; |
Padmanabhan Komanduru | ee89d21 | 2016-12-19 12:51:31 +0530 | [diff] [blame] | 197 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 198 | struct dsi_regulator_info power_info; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 199 | struct dsi_backlight_config bl_config; |
| 200 | struct dsi_panel_reset_config reset_config; |
| 201 | struct dsi_pinctrl_info pinctrl; |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 202 | struct drm_panel_hdr_properties hdr_props; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 203 | struct drm_panel_esd_config esd_config; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 204 | |
| 205 | bool lp11_init; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 206 | bool ulps_enabled; |
Lei Chen | 529da98 | 2017-10-24 16:23:42 +0800 | [diff] [blame] | 207 | bool ulps_suspend_enabled; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 208 | bool allow_phy_power_off; |
Sandeep Panda | bcb3731 | 2018-07-04 11:30:34 +0530 | [diff] [blame] | 209 | atomic_t esd_recovery_pending; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 210 | |
| 211 | bool panel_initialized; |
Narendra Muppalla | d4081e1 | 2017-04-20 19:24:08 -0700 | [diff] [blame] | 212 | bool te_using_watchdog_timer; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 213 | |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 214 | char dsc_pps_cmd[DSI_CMD_PPS_SIZE]; |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 215 | enum dsi_dms_mode dms_mode; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 216 | |
| 217 | bool sync_broadcast_en; |
Rajesh Bharathwaj | 5d99317 | 2020-03-17 22:09:17 -0700 | [diff] [blame] | 218 | |
| 219 | struct dsi_panel_exd_config exd_config; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 220 | }; |
| 221 | |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 222 | static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel) |
| 223 | { |
| 224 | return panel->ulps_enabled; |
| 225 | } |
| 226 | |
| 227 | static inline bool dsi_panel_initialized(struct dsi_panel *panel) |
| 228 | { |
| 229 | return panel->panel_initialized; |
| 230 | } |
| 231 | |
Veera Sundaram Sankaran | a2d5058 | 2017-10-19 17:49:48 -0700 | [diff] [blame] | 232 | static inline void dsi_panel_acquire_panel_lock(struct dsi_panel *panel) |
| 233 | { |
| 234 | mutex_lock(&panel->panel_lock); |
| 235 | } |
| 236 | |
| 237 | static inline void dsi_panel_release_panel_lock(struct dsi_panel *panel) |
| 238 | { |
| 239 | mutex_unlock(&panel->panel_lock); |
| 240 | } |
| 241 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 242 | struct dsi_panel *dsi_panel_get(struct device *parent, |
Chandan Uddaraju | 7e9613a | 2017-06-01 13:10:55 -0700 | [diff] [blame] | 243 | struct device_node *of_node, |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 244 | int topology_override, |
| 245 | enum dsi_panel_type type); |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 246 | |
Shashank Babu Chinta Venkata | feac972 | 2018-01-17 18:02:08 -0800 | [diff] [blame] | 247 | int dsi_panel_trigger_esd_attack(struct dsi_panel *panel); |
| 248 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 249 | void dsi_panel_put(struct dsi_panel *panel); |
| 250 | |
| 251 | int dsi_panel_drv_init(struct dsi_panel *panel, struct mipi_dsi_host *host); |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 252 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 253 | int dsi_panel_drv_deinit(struct dsi_panel *panel); |
| 254 | |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 255 | int dsi_panel_get_mode_count(struct dsi_panel *panel, |
| 256 | struct device_node *of_node); |
| 257 | |
| 258 | void dsi_panel_put_mode(struct dsi_display_mode *mode); |
| 259 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 260 | int dsi_panel_get_mode(struct dsi_panel *panel, |
| 261 | u32 index, |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 262 | struct dsi_display_mode *mode, |
| 263 | int topology_override); |
| 264 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 265 | int dsi_panel_validate_mode(struct dsi_panel *panel, |
| 266 | struct dsi_display_mode *mode); |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 267 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 268 | int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel, |
| 269 | struct dsi_display_mode *mode, |
| 270 | struct dsi_host_config *config); |
| 271 | |
| 272 | int dsi_panel_get_phy_props(struct dsi_panel *panel, |
| 273 | struct dsi_panel_phy_props *phy_props); |
Ajay Singh Parmar | 62f795b | 2016-06-10 23:20:23 -0700 | [diff] [blame] | 274 | int dsi_panel_get_dfps_caps(struct dsi_panel *panel, |
| 275 | struct dsi_dfps_capabilities *dfps_caps); |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 276 | |
| 277 | int dsi_panel_pre_prepare(struct dsi_panel *panel); |
| 278 | |
Clarence Ip | 5f00c060 | 2017-08-02 14:26:31 -0400 | [diff] [blame] | 279 | int dsi_panel_set_lp1(struct dsi_panel *panel); |
| 280 | |
| 281 | int dsi_panel_set_lp2(struct dsi_panel *panel); |
| 282 | |
| 283 | int dsi_panel_set_nolp(struct dsi_panel *panel); |
| 284 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 285 | int dsi_panel_prepare(struct dsi_panel *panel); |
| 286 | |
| 287 | int dsi_panel_enable(struct dsi_panel *panel); |
| 288 | |
| 289 | int dsi_panel_post_enable(struct dsi_panel *panel); |
| 290 | |
| 291 | int dsi_panel_pre_disable(struct dsi_panel *panel); |
| 292 | |
| 293 | int dsi_panel_disable(struct dsi_panel *panel); |
| 294 | |
| 295 | int dsi_panel_unprepare(struct dsi_panel *panel); |
| 296 | |
| 297 | int dsi_panel_post_unprepare(struct dsi_panel *panel); |
| 298 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 299 | int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl); |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 300 | |
| 301 | int dsi_panel_update_pps(struct dsi_panel *panel); |
Lloyd Atkinson | e53b737 | 2017-03-22 17:16:47 -0400 | [diff] [blame] | 302 | |
| 303 | int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx, |
| 304 | struct dsi_rect *roi); |
| 305 | |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 306 | int dsi_panel_switch(struct dsi_panel *panel); |
| 307 | |
| 308 | int dsi_panel_post_switch(struct dsi_panel *panel); |
| 309 | |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 310 | void dsi_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, int intf_width); |
| 311 | |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 312 | struct dsi_panel *dsi_panel_ext_bridge_get(struct device *parent, |
| 313 | struct device_node *of_node, |
| 314 | int topology_override); |
| 315 | |
Shashank Babu Chinta Venkata | b7e79bc | 2018-02-16 16:27:22 -0800 | [diff] [blame] | 316 | int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel, |
| 317 | struct device_node *of_node); |
| 318 | |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 319 | void dsi_panel_ext_bridge_put(struct dsi_panel *panel); |
| 320 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 321 | #endif /* _DSI_PANEL_H_ */ |