blob: 87023752e398aee706a0326e37aa07d435ab7cfe [file] [log] [blame]
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -07001/*
Rajesh Bharathwaj5d993172020-03-17 22:09:17 -07002 * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -07003 *
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 Li898b1bf2017-02-09 18:03:28 -080024#include <drm/msm_drm.h>
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070025
26#include "dsi_defs.h"
27#include "dsi_ctrl_hw.h"
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +053028#include "dsi_clk.h"
29#include "dsi_pwr.h"
Lloyd Atkinsone53b7372017-03-22 17:16:47 -040030#include "msm_drv.h"
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070031
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +053032#define MAX_BL_LEVEL 4096
Xu Yangd566d222017-05-19 17:18:12 +080033#define MAX_BL_SCALE_LEVEL 1024
34#define MAX_AD_BL_SCALE_LEVEL 65535
Alexander Beykunac182352017-02-27 17:46:51 -050035#define DSI_CMD_PPS_SIZE 135
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +053036
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -070037#define DSI_MODE_MAX 5
38
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070039enum 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 Parmar4fa53172016-05-16 17:54:30 -070046enum 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 Soma87208052018-05-18 20:52:10 +053054enum bl_update_flag {
55 BL_UPDATE_DELAY_UNTIL_FIRST_FRAME,
56 BL_UPDATE_NONE,
57};
58
Padmanabhan Komanduruedfe6ff2016-12-19 12:37:04 +053059enum {
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 Sankarana7c7bbe2017-05-31 18:12:05 -070067enum dsi_dms_mode {
68 DSI_DMS_MODE_DISABLED = 0,
69 DSI_DMS_MODE_RES_SWITCH_IMMEDIATE,
70};
71
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070072struct dsi_dfps_capabilities {
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070073 enum dsi_dfps_type type;
74 u32 min_refresh_rate;
75 u32 max_refresh_rate;
Sandeep Panda97c89dd2018-10-25 15:49:16 +053076 u32 *dfps_list;
77 u32 dfps_list_len;
78 bool dfps_support;
79};
80
81struct dsi_dyn_clk_caps {
82 bool dyn_clk_support;
83 u32 *bit_clk_list;
84 u32 bit_clk_list_len;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070085};
86
87struct dsi_pinctrl_info {
88 struct pinctrl *pinctrl;
89 struct pinctrl_state *active;
90 struct pinctrl_state *suspend;
91};
92
93struct dsi_panel_phy_props {
94 u32 panel_width_mm;
95 u32 panel_height_mm;
96 enum dsi_panel_rotation rotation;
97};
98
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070099struct dsi_backlight_config {
100 enum dsi_backlight_type type;
Tharun Raj Soma87208052018-05-18 20:52:10 +0530101 enum bl_update_flag bl_update;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700102
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530103 u32 bl_min_level;
104 u32 bl_max_level;
105 u32 brightness_max_level;
Xu Yangd566d222017-05-19 17:18:12 +0800106 u32 bl_level;
107 u32 bl_scale;
108 u32 bl_scale_ad;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700109
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 Prodduturi75b96802016-10-17 18:45:55 +0530119 struct backlight_device *bd;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700120};
121
122struct dsi_reset_seq {
123 u32 level;
124 u32 sleep_ms;
125};
126
127struct dsi_panel_reset_config {
128 struct dsi_reset_seq *sequence;
129 u32 count;
130
131 int reset_gpio;
132 int disp_en_gpio;
Padmanabhan Komanduruedfe6ff2016-12-19 12:37:04 +0530133 int lcd_mode_sel_gpio;
134 u32 mode_sel_state;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700135};
136
Sandeep Panda14666d12017-05-08 17:11:03 +0530137enum 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
144struct drm_panel_esd_config {
145 bool esd_enabled;
Yuan Zhao0bccca62018-05-24 18:47:04 +0800146 bool cmd_channel;
Sandeep Panda14666d12017-05-08 17:11:03 +0530147
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 Panda79450002017-05-08 17:14:24 +0530153 u8 *return_buf;
154 u8 *status_buf;
Sandeep Panda14666d12017-05-08 17:11:03 +0530155 u32 groups;
156};
157
Ray Zhanga8a5dfe2018-01-22 10:29:01 +0800158enum dsi_panel_type {
159 DSI_PANEL = 0,
160 EXT_BRIDGE,
161 DSI_PANEL_TYPE_MAX,
162};
163
Rajesh Bharathwaj5d993172020-03-17 22:09:17 -0700164/* Extended Panel config for panels with additional gpios */
165struct 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 Parmar4fa53172016-05-16 17:54:30 -0700175struct dsi_panel {
176 const char *name;
Ray Zhanga8a5dfe2018-01-22 10:29:01 +0800177 enum dsi_panel_type type;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700178 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 Sankaran446a5f12017-05-09 20:30:39 -0700189 enum dsi_op_mode panel_mode;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700190
191 struct dsi_dfps_capabilities dfps_caps;
Sandeep Panda97c89dd2018-10-25 15:49:16 +0530192 struct dsi_dyn_clk_caps dyn_clk_caps;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700193 struct dsi_panel_phy_props phy_props;
194
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700195 struct dsi_display_mode *cur_mode;
196 u32 num_timing_nodes;
Padmanabhan Komanduruee89d212016-12-19 12:51:31 +0530197
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700198 struct dsi_regulator_info power_info;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700199 struct dsi_backlight_config bl_config;
200 struct dsi_panel_reset_config reset_config;
201 struct dsi_pinctrl_info pinctrl;
Ping Li898b1bf2017-02-09 18:03:28 -0800202 struct drm_panel_hdr_properties hdr_props;
Sandeep Panda14666d12017-05-08 17:11:03 +0530203 struct drm_panel_esd_config esd_config;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700204
205 bool lp11_init;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530206 bool ulps_enabled;
Lei Chen529da982017-10-24 16:23:42 +0800207 bool ulps_suspend_enabled;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530208 bool allow_phy_power_off;
Sandeep Pandabcb37312018-07-04 11:30:34 +0530209 atomic_t esd_recovery_pending;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530210
211 bool panel_initialized;
Narendra Muppallad4081e12017-04-20 19:24:08 -0700212 bool te_using_watchdog_timer;
Alexander Beykunac182352017-02-27 17:46:51 -0500213
Alexander Beykunac182352017-02-27 17:46:51 -0500214 char dsc_pps_cmd[DSI_CMD_PPS_SIZE];
Jeykumar Sankarana7c7bbe2017-05-31 18:12:05 -0700215 enum dsi_dms_mode dms_mode;
Sandeep Panda14666d12017-05-08 17:11:03 +0530216
217 bool sync_broadcast_en;
Rajesh Bharathwaj5d993172020-03-17 22:09:17 -0700218
219 struct dsi_panel_exd_config exd_config;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700220};
221
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530222static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel)
223{
224 return panel->ulps_enabled;
225}
226
227static inline bool dsi_panel_initialized(struct dsi_panel *panel)
228{
229 return panel->panel_initialized;
230}
231
Veera Sundaram Sankarana2d50582017-10-19 17:49:48 -0700232static inline void dsi_panel_acquire_panel_lock(struct dsi_panel *panel)
233{
234 mutex_lock(&panel->panel_lock);
235}
236
237static inline void dsi_panel_release_panel_lock(struct dsi_panel *panel)
238{
239 mutex_unlock(&panel->panel_lock);
240}
241
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700242struct dsi_panel *dsi_panel_get(struct device *parent,
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -0700243 struct device_node *of_node,
Ray Zhanga8a5dfe2018-01-22 10:29:01 +0800244 int topology_override,
245 enum dsi_panel_type type);
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700246
Shashank Babu Chinta Venkatafeac9722018-01-17 18:02:08 -0800247int dsi_panel_trigger_esd_attack(struct dsi_panel *panel);
248
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700249void dsi_panel_put(struct dsi_panel *panel);
250
251int dsi_panel_drv_init(struct dsi_panel *panel, struct mipi_dsi_host *host);
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700252
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700253int dsi_panel_drv_deinit(struct dsi_panel *panel);
254
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700255int dsi_panel_get_mode_count(struct dsi_panel *panel,
256 struct device_node *of_node);
257
258void dsi_panel_put_mode(struct dsi_display_mode *mode);
259
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700260int dsi_panel_get_mode(struct dsi_panel *panel,
261 u32 index,
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700262 struct dsi_display_mode *mode,
263 int topology_override);
264
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700265int dsi_panel_validate_mode(struct dsi_panel *panel,
266 struct dsi_display_mode *mode);
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700267
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700268int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
269 struct dsi_display_mode *mode,
270 struct dsi_host_config *config);
271
272int dsi_panel_get_phy_props(struct dsi_panel *panel,
273 struct dsi_panel_phy_props *phy_props);
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700274int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
275 struct dsi_dfps_capabilities *dfps_caps);
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700276
277int dsi_panel_pre_prepare(struct dsi_panel *panel);
278
Clarence Ip5f00c0602017-08-02 14:26:31 -0400279int dsi_panel_set_lp1(struct dsi_panel *panel);
280
281int dsi_panel_set_lp2(struct dsi_panel *panel);
282
283int dsi_panel_set_nolp(struct dsi_panel *panel);
284
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700285int dsi_panel_prepare(struct dsi_panel *panel);
286
287int dsi_panel_enable(struct dsi_panel *panel);
288
289int dsi_panel_post_enable(struct dsi_panel *panel);
290
291int dsi_panel_pre_disable(struct dsi_panel *panel);
292
293int dsi_panel_disable(struct dsi_panel *panel);
294
295int dsi_panel_unprepare(struct dsi_panel *panel);
296
297int dsi_panel_post_unprepare(struct dsi_panel *panel);
298
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530299int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl);
Alexander Beykunac182352017-02-27 17:46:51 -0500300
301int dsi_panel_update_pps(struct dsi_panel *panel);
Lloyd Atkinsone53b7372017-03-22 17:16:47 -0400302
303int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx,
304 struct dsi_rect *roi);
305
Jeykumar Sankarana7c7bbe2017-05-31 18:12:05 -0700306int dsi_panel_switch(struct dsi_panel *panel);
307
308int dsi_panel_post_switch(struct dsi_panel *panel);
309
Lloyd Atkinson16e96de2017-04-19 11:18:14 -0400310void dsi_dsc_pclk_param_calc(struct msm_display_dsc_info *dsc, int intf_width);
311
Ray Zhanga8a5dfe2018-01-22 10:29:01 +0800312struct dsi_panel *dsi_panel_ext_bridge_get(struct device *parent,
313 struct device_node *of_node,
314 int topology_override);
315
Shashank Babu Chinta Venkatab7e79bc2018-02-16 16:27:22 -0800316int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel,
317 struct device_node *of_node);
318
Ray Zhanga8a5dfe2018-01-22 10:29:01 +0800319void dsi_panel_ext_bridge_put(struct dsi_panel *panel);
320
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700321#endif /* _DSI_PANEL_H_ */