Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 1 | /* |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, 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 | |
Padmanabhan Komanduru | edfe6ff | 2016-12-19 12:37:04 +0530 | [diff] [blame] | 54 | enum { |
| 55 | MODE_GPIO_NOT_VALID = 0, |
| 56 | MODE_SEL_DUAL_PORT, |
| 57 | MODE_SEL_SINGLE_PORT, |
| 58 | MODE_GPIO_HIGH, |
| 59 | MODE_GPIO_LOW, |
| 60 | }; |
| 61 | |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 62 | enum dsi_dms_mode { |
| 63 | DSI_DMS_MODE_DISABLED = 0, |
| 64 | DSI_DMS_MODE_RES_SWITCH_IMMEDIATE, |
| 65 | }; |
| 66 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 67 | struct dsi_dfps_capabilities { |
| 68 | bool dfps_support; |
| 69 | enum dsi_dfps_type type; |
| 70 | u32 min_refresh_rate; |
| 71 | u32 max_refresh_rate; |
| 72 | }; |
| 73 | |
| 74 | struct dsi_pinctrl_info { |
| 75 | struct pinctrl *pinctrl; |
| 76 | struct pinctrl_state *active; |
| 77 | struct pinctrl_state *suspend; |
| 78 | }; |
| 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 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 86 | struct dsi_backlight_config { |
| 87 | enum dsi_backlight_type type; |
| 88 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 89 | u32 bl_min_level; |
| 90 | u32 bl_max_level; |
| 91 | u32 brightness_max_level; |
Xu Yang | d566d22 | 2017-05-19 17:18:12 +0800 | [diff] [blame] | 92 | u32 bl_level; |
| 93 | u32 bl_scale; |
| 94 | u32 bl_scale_ad; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 95 | |
| 96 | int en_gpio; |
| 97 | /* PWM params */ |
| 98 | bool pwm_pmi_control; |
| 99 | u32 pwm_pmic_bank; |
| 100 | u32 pwm_period_usecs; |
| 101 | int pwm_gpio; |
| 102 | |
| 103 | /* WLED params */ |
| 104 | struct led_trigger *wled; |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 105 | struct backlight_device *bd; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | struct dsi_reset_seq { |
| 109 | u32 level; |
| 110 | u32 sleep_ms; |
| 111 | }; |
| 112 | |
| 113 | struct dsi_panel_reset_config { |
| 114 | struct dsi_reset_seq *sequence; |
| 115 | u32 count; |
| 116 | |
| 117 | int reset_gpio; |
| 118 | int disp_en_gpio; |
Padmanabhan Komanduru | edfe6ff | 2016-12-19 12:37:04 +0530 | [diff] [blame] | 119 | int lcd_mode_sel_gpio; |
| 120 | u32 mode_sel_state; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 123 | enum esd_check_status_mode { |
| 124 | ESD_MODE_REG_READ, |
| 125 | ESD_MODE_SW_BTA, |
| 126 | ESD_MODE_PANEL_TE, |
| 127 | ESD_MODE_MAX |
| 128 | }; |
| 129 | |
| 130 | struct drm_panel_esd_config { |
| 131 | bool esd_enabled; |
| 132 | |
| 133 | enum esd_check_status_mode status_mode; |
| 134 | struct dsi_panel_cmd_set status_cmd; |
| 135 | u32 *status_cmds_rlen; |
| 136 | u32 *status_valid_params; |
| 137 | u32 *status_value; |
Sandeep Panda | 7945000 | 2017-05-08 17:14:24 +0530 | [diff] [blame] | 138 | u8 *return_buf; |
| 139 | u8 *status_buf; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 140 | u32 groups; |
| 141 | }; |
| 142 | |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 143 | enum dsi_panel_type { |
| 144 | DSI_PANEL = 0, |
| 145 | EXT_BRIDGE, |
| 146 | DSI_PANEL_TYPE_MAX, |
| 147 | }; |
| 148 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 149 | struct dsi_panel { |
| 150 | const char *name; |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 151 | enum dsi_panel_type type; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 152 | struct device_node *panel_of_node; |
| 153 | struct mipi_dsi_device mipi_device; |
| 154 | |
| 155 | struct mutex panel_lock; |
| 156 | struct drm_panel drm_panel; |
| 157 | struct mipi_dsi_host *host; |
| 158 | struct device *parent; |
| 159 | |
| 160 | struct dsi_host_common_cfg host_config; |
| 161 | struct dsi_video_engine_cfg video_config; |
| 162 | struct dsi_cmd_engine_cfg cmd_config; |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 163 | enum dsi_op_mode panel_mode; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 164 | |
| 165 | struct dsi_dfps_capabilities dfps_caps; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 166 | struct dsi_panel_phy_props phy_props; |
| 167 | |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 168 | struct dsi_display_mode *cur_mode; |
| 169 | u32 num_timing_nodes; |
Padmanabhan Komanduru | ee89d21 | 2016-12-19 12:51:31 +0530 | [diff] [blame] | 170 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 171 | struct dsi_regulator_info power_info; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 172 | struct dsi_backlight_config bl_config; |
| 173 | struct dsi_panel_reset_config reset_config; |
| 174 | struct dsi_pinctrl_info pinctrl; |
Ping Li | 898b1bf | 2017-02-09 18:03:28 -0800 | [diff] [blame] | 175 | struct drm_panel_hdr_properties hdr_props; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 176 | struct drm_panel_esd_config esd_config; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 177 | |
| 178 | bool lp11_init; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 179 | bool ulps_enabled; |
Lei Chen | 529da98 | 2017-10-24 16:23:42 +0800 | [diff] [blame] | 180 | bool ulps_suspend_enabled; |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 181 | bool allow_phy_power_off; |
| 182 | |
| 183 | bool panel_initialized; |
Narendra Muppalla | d4081e1 | 2017-04-20 19:24:08 -0700 | [diff] [blame] | 184 | bool te_using_watchdog_timer; |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 185 | |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 186 | char dsc_pps_cmd[DSI_CMD_PPS_SIZE]; |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 187 | enum dsi_dms_mode dms_mode; |
Sandeep Panda | 14666d1 | 2017-05-08 17:11:03 +0530 | [diff] [blame] | 188 | |
| 189 | bool sync_broadcast_en; |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
Padmanabhan Komanduru | dbd2fb0 | 2016-12-02 15:18:49 +0530 | [diff] [blame] | 192 | static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel) |
| 193 | { |
| 194 | return panel->ulps_enabled; |
| 195 | } |
| 196 | |
| 197 | static inline bool dsi_panel_initialized(struct dsi_panel *panel) |
| 198 | { |
| 199 | return panel->panel_initialized; |
| 200 | } |
| 201 | |
Veera Sundaram Sankaran | a2d5058 | 2017-10-19 17:49:48 -0700 | [diff] [blame] | 202 | static inline void dsi_panel_acquire_panel_lock(struct dsi_panel *panel) |
| 203 | { |
| 204 | mutex_lock(&panel->panel_lock); |
| 205 | } |
| 206 | |
| 207 | static inline void dsi_panel_release_panel_lock(struct dsi_panel *panel) |
| 208 | { |
| 209 | mutex_unlock(&panel->panel_lock); |
| 210 | } |
| 211 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 212 | struct dsi_panel *dsi_panel_get(struct device *parent, |
Chandan Uddaraju | 7e9613a | 2017-06-01 13:10:55 -0700 | [diff] [blame] | 213 | struct device_node *of_node, |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 214 | int topology_override, |
| 215 | enum dsi_panel_type type); |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 216 | |
Shashank Babu Chinta Venkata | feac972 | 2018-01-17 18:02:08 -0800 | [diff] [blame] | 217 | int dsi_panel_trigger_esd_attack(struct dsi_panel *panel); |
| 218 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 219 | void dsi_panel_put(struct dsi_panel *panel); |
| 220 | |
| 221 | 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] | 222 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 223 | int dsi_panel_drv_deinit(struct dsi_panel *panel); |
| 224 | |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 225 | int dsi_panel_get_mode_count(struct dsi_panel *panel, |
| 226 | struct device_node *of_node); |
| 227 | |
| 228 | void dsi_panel_put_mode(struct dsi_display_mode *mode); |
| 229 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 230 | int dsi_panel_get_mode(struct dsi_panel *panel, |
| 231 | u32 index, |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 232 | struct dsi_display_mode *mode, |
| 233 | int topology_override); |
| 234 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 235 | int dsi_panel_validate_mode(struct dsi_panel *panel, |
| 236 | struct dsi_display_mode *mode); |
Jeykumar Sankaran | 446a5f1 | 2017-05-09 20:30:39 -0700 | [diff] [blame] | 237 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 238 | int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel, |
| 239 | struct dsi_display_mode *mode, |
| 240 | struct dsi_host_config *config); |
| 241 | |
| 242 | int dsi_panel_get_phy_props(struct dsi_panel *panel, |
| 243 | struct dsi_panel_phy_props *phy_props); |
Ajay Singh Parmar | 62f795b | 2016-06-10 23:20:23 -0700 | [diff] [blame] | 244 | int dsi_panel_get_dfps_caps(struct dsi_panel *panel, |
| 245 | struct dsi_dfps_capabilities *dfps_caps); |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 246 | |
| 247 | int dsi_panel_pre_prepare(struct dsi_panel *panel); |
| 248 | |
Clarence Ip | 5f00c060 | 2017-08-02 14:26:31 -0400 | [diff] [blame] | 249 | int dsi_panel_set_lp1(struct dsi_panel *panel); |
| 250 | |
| 251 | int dsi_panel_set_lp2(struct dsi_panel *panel); |
| 252 | |
| 253 | int dsi_panel_set_nolp(struct dsi_panel *panel); |
| 254 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 255 | int dsi_panel_prepare(struct dsi_panel *panel); |
| 256 | |
| 257 | int dsi_panel_enable(struct dsi_panel *panel); |
| 258 | |
| 259 | int dsi_panel_post_enable(struct dsi_panel *panel); |
| 260 | |
| 261 | int dsi_panel_pre_disable(struct dsi_panel *panel); |
| 262 | |
| 263 | int dsi_panel_disable(struct dsi_panel *panel); |
| 264 | |
| 265 | int dsi_panel_unprepare(struct dsi_panel *panel); |
| 266 | |
| 267 | int dsi_panel_post_unprepare(struct dsi_panel *panel); |
| 268 | |
Vishnuvardhan Prodduturi | 75b9680 | 2016-10-17 18:45:55 +0530 | [diff] [blame] | 269 | int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl); |
Alexander Beykun | ac18235 | 2017-02-27 17:46:51 -0500 | [diff] [blame] | 270 | |
| 271 | int dsi_panel_update_pps(struct dsi_panel *panel); |
Lloyd Atkinson | e53b737 | 2017-03-22 17:16:47 -0400 | [diff] [blame] | 272 | |
| 273 | int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx, |
| 274 | struct dsi_rect *roi); |
| 275 | |
Jeykumar Sankaran | a7c7bbe | 2017-05-31 18:12:05 -0700 | [diff] [blame] | 276 | int dsi_panel_switch(struct dsi_panel *panel); |
| 277 | |
| 278 | int dsi_panel_post_switch(struct dsi_panel *panel); |
| 279 | |
Lloyd Atkinson | 16e96de | 2017-04-19 11:18:14 -0400 | [diff] [blame] | 280 | void dsi_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, int intf_width); |
| 281 | |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 282 | struct dsi_panel *dsi_panel_ext_bridge_get(struct device *parent, |
| 283 | struct device_node *of_node, |
| 284 | int topology_override); |
| 285 | |
Shashank Babu Chinta Venkata | b7e79bc | 2018-02-16 16:27:22 -0800 | [diff] [blame] | 286 | int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel, |
| 287 | struct device_node *of_node); |
| 288 | |
Ray Zhang | a8a5dfe | 2018-01-22 10:29:01 +0800 | [diff] [blame] | 289 | void dsi_panel_ext_bridge_put(struct dsi_panel *panel); |
| 290 | |
Ajay Singh Parmar | 4fa5317 | 2016-05-16 17:54:30 -0700 | [diff] [blame] | 291 | #endif /* _DSI_PANEL_H_ */ |