blob: 386e8a9fcb16bd4a9ae233eecccdea7227d17aac [file] [log] [blame]
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -07001/*
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +05302 * Copyright (c) 2016-2017, 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>
24#include <drm/drm_mipi_dsi.h>
25
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"
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070030
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +053031#define MAX_BL_LEVEL 4096
32
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070033enum dsi_panel_rotation {
34 DSI_PANEL_ROTATE_NONE = 0,
35 DSI_PANEL_ROTATE_HV_FLIP,
36 DSI_PANEL_ROTATE_H_FLIP,
37 DSI_PANEL_ROTATE_V_FLIP
38};
39
40enum dsi_cmd_set_type {
41 DSI_CMD_SET_PRE_ON = 0,
42 DSI_CMD_SET_ON,
43 DSI_CMD_SET_POST_ON,
44 DSI_CMD_SET_PRE_OFF,
45 DSI_CMD_SET_OFF,
46 DSI_CMD_SET_POST_OFF,
47 DSI_CMD_SET_PRE_RES_SWITCH,
48 DSI_CMD_SET_RES_SWITCH,
49 DSI_CMD_SET_POST_RES_SWITCH,
50 DSI_CMD_SET_CMD_TO_VID_SWITCH,
51 DSI_CMD_SET_POST_CMD_TO_VID_SWITCH,
52 DSI_CMD_SET_VID_TO_CMD_SWITCH,
53 DSI_CMD_SET_POST_VID_TO_CMD_SWITCH,
54 DSI_CMD_SET_PANEL_STATUS,
55 DSI_CMD_SET_MAX
56};
57
58enum dsi_cmd_set_state {
59 DSI_CMD_SET_STATE_LP = 0,
60 DSI_CMD_SET_STATE_HS,
61 DSI_CMD_SET_STATE_MAX
62};
63
64enum dsi_backlight_type {
65 DSI_BACKLIGHT_PWM = 0,
66 DSI_BACKLIGHT_WLED,
67 DSI_BACKLIGHT_DCS,
68 DSI_BACKLIGHT_UNKNOWN,
69 DSI_BACKLIGHT_MAX,
70};
71
Padmanabhan Komanduruedfe6ff2016-12-19 12:37:04 +053072enum {
73 MODE_GPIO_NOT_VALID = 0,
74 MODE_SEL_DUAL_PORT,
75 MODE_SEL_SINGLE_PORT,
76 MODE_GPIO_HIGH,
77 MODE_GPIO_LOW,
78};
79
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -070080struct dsi_dfps_capabilities {
81 bool dfps_support;
82 enum dsi_dfps_type type;
83 u32 min_refresh_rate;
84 u32 max_refresh_rate;
85};
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
99struct dsi_cmd_desc {
100 struct mipi_dsi_msg msg;
101 bool last_command;
102 u32 post_wait_ms;
103};
104
105struct dsi_panel_cmd_set {
106 enum dsi_cmd_set_type type;
107 enum dsi_cmd_set_state state;
108 u32 count;
109 struct dsi_cmd_desc *cmds;
110};
111
112struct dsi_backlight_config {
113 enum dsi_backlight_type type;
114
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530115 u32 bl_min_level;
116 u32 bl_max_level;
117 u32 brightness_max_level;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700118
119 int en_gpio;
120 /* PWM params */
121 bool pwm_pmi_control;
122 u32 pwm_pmic_bank;
123 u32 pwm_period_usecs;
124 int pwm_gpio;
125
126 /* WLED params */
127 struct led_trigger *wled;
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530128 struct backlight_device *bd;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700129};
130
131struct dsi_reset_seq {
132 u32 level;
133 u32 sleep_ms;
134};
135
136struct dsi_panel_reset_config {
137 struct dsi_reset_seq *sequence;
138 u32 count;
139
140 int reset_gpio;
141 int disp_en_gpio;
Padmanabhan Komanduruedfe6ff2016-12-19 12:37:04 +0530142 int lcd_mode_sel_gpio;
143 u32 mode_sel_state;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700144};
145
146struct dsi_panel {
147 const char *name;
148 struct device_node *panel_of_node;
149 struct mipi_dsi_device mipi_device;
150
151 struct mutex panel_lock;
152 struct drm_panel drm_panel;
153 struct mipi_dsi_host *host;
154 struct device *parent;
155
156 struct dsi_host_common_cfg host_config;
157 struct dsi_video_engine_cfg video_config;
158 struct dsi_cmd_engine_cfg cmd_config;
159
160 struct dsi_dfps_capabilities dfps_caps;
161
162 struct dsi_panel_cmd_set cmd_sets[DSI_CMD_SET_MAX];
163 struct dsi_panel_phy_props phy_props;
164
Padmanabhan Komanduruee89d212016-12-19 12:51:31 +0530165 u32 *phy_timing_val;
166 u32 phy_timing_len;
167
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700168 struct dsi_regulator_info power_info;
169 struct dsi_display_mode mode;
170
171 struct dsi_backlight_config bl_config;
172 struct dsi_panel_reset_config reset_config;
173 struct dsi_pinctrl_info pinctrl;
174
175 bool lp11_init;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530176 bool ulps_enabled;
177 bool allow_phy_power_off;
178
Dhaval Patel60e1ff52017-02-18 21:03:40 -0800179 u32 panel_jitter;
180 u32 panel_prefill_lines;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530181 bool panel_initialized;
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700182};
183
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530184static inline bool dsi_panel_ulps_feature_enabled(struct dsi_panel *panel)
185{
186 return panel->ulps_enabled;
187}
188
189static inline bool dsi_panel_initialized(struct dsi_panel *panel)
190{
191 return panel->panel_initialized;
192}
193
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700194struct dsi_panel *dsi_panel_get(struct device *parent,
195 struct device_node *of_node);
196void dsi_panel_put(struct dsi_panel *panel);
197
198int dsi_panel_drv_init(struct dsi_panel *panel, struct mipi_dsi_host *host);
199int dsi_panel_drv_deinit(struct dsi_panel *panel);
200
201int dsi_panel_get_mode_count(struct dsi_panel *panel, u32 *count);
202int dsi_panel_get_mode(struct dsi_panel *panel,
203 u32 index,
204 struct dsi_display_mode *mode);
205int dsi_panel_validate_mode(struct dsi_panel *panel,
206 struct dsi_display_mode *mode);
207int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
208 struct dsi_display_mode *mode,
209 struct dsi_host_config *config);
210
211int dsi_panel_get_phy_props(struct dsi_panel *panel,
212 struct dsi_panel_phy_props *phy_props);
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700213int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
214 struct dsi_dfps_capabilities *dfps_caps);
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700215
216int dsi_panel_pre_prepare(struct dsi_panel *panel);
217
218int dsi_panel_prepare(struct dsi_panel *panel);
219
220int dsi_panel_enable(struct dsi_panel *panel);
221
222int dsi_panel_post_enable(struct dsi_panel *panel);
223
224int dsi_panel_pre_disable(struct dsi_panel *panel);
225
226int dsi_panel_disable(struct dsi_panel *panel);
227
228int dsi_panel_unprepare(struct dsi_panel *panel);
229
230int dsi_panel_post_unprepare(struct dsi_panel *panel);
231
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530232int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl);
Ajay Singh Parmar4fa53172016-05-16 17:54:30 -0700233#endif /* _DSI_PANEL_H_ */