blob: b77bf268dbd18a3ed680efc388b78fa25d70944d [file] [log] [blame]
Ajay Singh Parmar571e3012016-05-16 17:55:52 -07001/*
2 * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
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_DISPLAY_H_
16#define _DSI_DISPLAY_H_
17
18#include <linux/types.h>
19#include <linux/bitops.h>
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -070020#include <linux/debugfs.h>
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070021#include <linux/of_device.h>
22#include <drm/drmP.h>
23#include <drm/drm_crtc.h>
24
Clarence Ipa4039322016-07-15 16:23:59 -040025#include "msm_drv.h"
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070026#include "dsi_defs.h"
27#include "dsi_ctrl.h"
28#include "dsi_phy.h"
29#include "dsi_panel.h"
30
31#define MAX_DSI_CTRLS_PER_DISPLAY 2
32
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -070033/*
34 * DSI Validate Mode modifiers
35 * @DSI_VALIDATE_FLAG_ALLOW_ADJUST: Allow mode validation to also do fixup
36 */
37#define DSI_VALIDATE_FLAG_ALLOW_ADJUST 0x1
38
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070039/**
40 * enum dsi_display_type - enumerates DSI display types
41 * @DSI_DISPLAY_SINGLE: A panel connected on a single DSI interface.
42 * @DSI_DISPLAY_EXT_BRIDGE: A bridge is connected between panel and DSI host.
43 * It utilizes a single DSI interface.
44 * @DSI_DISPLAY_SPLIT: A panel that utilizes more than one DSI
45 * interfaces.
46 * @DSI_DISPLAY_SPLIT_EXT_BRIDGE: A bridge is present between panel and DSI
47 * host. It utilizes more than one DSI interface.
48 */
49enum dsi_display_type {
50 DSI_DISPLAY_SINGLE = 0,
51 DSI_DISPLAY_EXT_BRIDGE,
52 DSI_DISPLAY_SPLIT,
53 DSI_DISPLAY_SPLIT_EXT_BRIDGE,
54 DSI_DISPLAY_MAX,
55};
56
57/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070058 * struct dsi_display_ctrl - dsi ctrl/phy information for the display
59 * @ctrl: Handle to the DSI controller device.
60 * @ctrl_of_node: pHandle to the DSI controller device.
61 * @dsi_ctrl_idx: DSI controller instance id.
62 * @power_state: Current power state of the DSI controller.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070063 * @phy: Handle to the DSI PHY device.
64 * @phy_of_node: pHandle to the DSI PHY device.
65 * @phy_enabled: PHY power status.
66 */
67struct dsi_display_ctrl {
68 /* controller info */
69 struct dsi_ctrl *ctrl;
70 struct device_node *ctrl_of_node;
71 u32 dsi_ctrl_idx;
72
73 enum dsi_power_state power_state;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070074
75 /* phy info */
76 struct msm_dsi_phy *phy;
77 struct device_node *phy_of_node;
78
79 bool phy_enabled;
80};
81
82/**
83 * struct dsi_display_clk_info - dsi display clock source information
84 * @src_clks: Source clocks for DSI display.
85 * @mux_clks: Mux clocks used for DFPS.
86 * @shadow_clks: Used for DFPS.
87 */
88struct dsi_display_clk_info {
89 struct dsi_clk_link_set src_clks;
90 struct dsi_clk_link_set mux_clks;
91 struct dsi_clk_link_set shadow_clks;
92};
93
94/**
95 * struct dsi_display - dsi display information
96 * @pdev: Pointer to platform device.
97 * @drm_dev: DRM device associated with the display.
98 * @name: Name of the display.
99 * @display_type: Display type as defined in device tree.
100 * @list: List pointer.
101 * @is_active: Is display active.
102 * @display_lock: Mutex for dsi_display interface.
103 * @ctrl_count: Number of DSI interfaces required by panel.
104 * @ctrl: Controller information for DSI display.
105 * @panel: Handle to DSI panel.
106 * @panel_of: pHandle to DSI panel.
107 * @type: DSI display type.
108 * @clk_master_idx: The master controller for controlling clocks. This is an
109 * index into the ctrl[MAX_DSI_CTRLS_PER_DISPLAY] array.
110 * @cmd_master_idx: The master controller for sending DSI commands to panel.
111 * @video_master_idx: The master controller for enabling video engine.
112 * @clock_info: Clock sourcing for DSI display.
113 * @lane_map: Lane mapping between DSI host and Panel.
114 * @num_of_modes: Number of modes supported by display.
115 * @is_tpg_enabled: TPG state.
116 * @host: DRM MIPI DSI Host.
117 * @connector: Pointer to DRM connector object.
118 * @bridge: Pointer to DRM bridge object.
Lloyd Atkinsone404caf2016-07-13 17:26:45 -0400119 * @cmd_engine_refcount: Reference count enforcing single instance of cmd eng
120 * @root: Debugfs root directory
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700121 */
122struct dsi_display {
123 struct platform_device *pdev;
124 struct drm_device *drm_dev;
125
126 const char *name;
127 const char *display_type;
128 struct list_head list;
129 bool is_active;
130 struct mutex display_lock;
131
132 u32 ctrl_count;
133 struct dsi_display_ctrl ctrl[MAX_DSI_CTRLS_PER_DISPLAY];
134
135 /* panel info */
136 struct dsi_panel *panel;
137 struct device_node *panel_of;
138
139 enum dsi_display_type type;
140 u32 clk_master_idx;
141 u32 cmd_master_idx;
142 u32 video_master_idx;
143
144 struct dsi_display_clk_info clock_info;
145 struct dsi_host_config config;
146 struct dsi_lane_mapping lane_map;
147 u32 num_of_modes;
148 bool is_tpg_enabled;
149
150 struct mipi_dsi_host host;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700151 struct dsi_bridge *bridge;
Ajay Singh Parmaraa9152d2016-05-16 18:02:07 -0700152 u32 cmd_engine_refcount;
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700153
154 /* DEBUG FS */
155 struct dentry *root;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700156};
157
158int dsi_display_dev_probe(struct platform_device *pdev);
159int dsi_display_dev_remove(struct platform_device *pdev);
160
161/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700162 * dsi_display_get_num_of_displays() - returns number of display devices
163 * supported.
164 *
165 * Return: number of displays.
166 */
Clarence Ip3649f8b2016-10-31 09:59:44 -0400167int dsi_display_get_num_of_displays(void);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700168
169/**
Clarence Ipa36c92e2016-07-26 14:33:46 -0400170 * dsi_display_get_active_displays - returns pointers for active display devices
171 * @display_array: Pointer to display array to be filled
172 * @max_display_count: Size of display_array
173 * @Returns: Number of display entries filled
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700174 */
Clarence Ipa36c92e2016-07-26 14:33:46 -0400175int dsi_display_get_active_displays(void **display_array,
176 u32 max_display_count);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700177
178/**
179 * dsi_display_get_display_by_name()- finds display by name
180 * @index: name of the display.
181 *
182 * Return: handle to the display or error code.
183 */
184struct dsi_display *dsi_display_get_display_by_name(const char *name);
185
186/**
187 * dsi_display_set_active_state() - sets the state of the display
188 * @display: Handle to display.
189 * @is_active: state
190 */
191void dsi_display_set_active_state(struct dsi_display *display, bool is_active);
192
193/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400194 * dsi_display_drm_bridge_init() - initializes DRM bridge object for DSI
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700195 * @display: Handle to the display.
196 * @encoder: Pointer to the encoder object which is connected to the
197 * display.
198 *
199 * Return: error code.
200 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400201int dsi_display_drm_bridge_init(struct dsi_display *display,
202 struct drm_encoder *enc);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700203
204/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400205 * dsi_display_drm_bridge_deinit() - destroys DRM bridge for the display
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700206 * @display: Handle to the display.
207 *
208 * Return: error code.
209 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400210int dsi_display_drm_bridge_deinit(struct dsi_display *display);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700211
212/**
213 * dsi_display_get_info() - returns the display properties
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700214 * @info: Pointer to the structure where info is stored.
Clarence Ipa4039322016-07-15 16:23:59 -0400215 * @disp: Handle to the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700216 *
217 * Return: error code.
218 */
Clarence Ipa4039322016-07-15 16:23:59 -0400219int dsi_display_get_info(struct msm_display_info *info, void *disp);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700220
221/**
222 * dsi_display_get_modes() - get modes supported by display
223 * @display: Handle to display.
224 * @modes; Pointer to array of modes. Memory allocated should be
225 * big enough to store (count * struct dsi_display_mode)
226 * elements. If modes pointer is NULL, number of modes will
227 * be stored in the memory pointed to by count.
228 * @count: If modes is NULL, number of modes will be stored. If
229 * not, mode information will be copied (number of modes
230 * copied will be equal to *count).
231 *
232 * Return: error code.
233 */
234int dsi_display_get_modes(struct dsi_display *display,
235 struct dsi_display_mode *modes,
236 u32 *count);
237
238/**
239 * dsi_display_validate_mode() - validates if mode is supported by display
240 * @display: Handle to display.
241 * @mode: Mode to be validated.
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700242 * @flags: Modifier flags.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700243 *
244 * Return: 0 if supported or error code.
245 */
246int dsi_display_validate_mode(struct dsi_display *display,
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700247 struct dsi_display_mode *mode,
248 u32 flags);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700249
250/**
251 * dsi_display_set_mode() - Set mode on the display.
252 * @display: Handle to display.
253 * @mode: mode to be set.
254 * @flags: Modifier flags.
255 *
256 * Return: error code.
257 */
258int dsi_display_set_mode(struct dsi_display *display,
259 struct dsi_display_mode *mode,
260 u32 flags);
261
262/**
263 * dsi_display_prepare() - prepare display
264 * @display: Handle to display.
265 *
266 * Prepare will perform power up sequences for the host and panel hardware.
267 * Power and clock resources might be turned on (depending on the panel mode).
268 * The video engine is not enabled.
269 *
270 * Return: error code.
271 */
272int dsi_display_prepare(struct dsi_display *display);
273
274/**
275 * dsi_display_enable() - enable display
276 * @display: Handle to display.
277 *
278 * Enable will turn on the host engine and the panel. At the end of the enable
279 * function, Host and panel hardware are ready to accept pixel data from
280 * upstream.
281 *
282 * Return: error code.
283 */
284int dsi_display_enable(struct dsi_display *display);
285
286/**
287 * dsi_display_post_enable() - perform post enable operations.
288 * @display: Handle to display.
289 *
290 * Some panels might require some commands to be sent after pixel data
291 * transmission has started. Such commands are sent as part of the post_enable
292 * function.
293 *
294 * Return: error code.
295 */
296int dsi_display_post_enable(struct dsi_display *display);
297
298/**
299 * dsi_display_pre_disable() - perform pre disable operations.
300 * @display: Handle to display.
301 *
302 * If a panel requires commands to be sent before pixel data transmission is
303 * stopped, those can be sent as part of pre_disable.
304 *
305 * Return: error code.
306 */
307int dsi_display_pre_disable(struct dsi_display *display);
308
309/**
310 * dsi_display_disable() - disable panel and host hardware.
311 * @display: Handle to display.
312 *
313 * Disable host and panel hardware and pixel data transmission can not continue.
314 *
315 * Return: error code.
316 */
317int dsi_display_disable(struct dsi_display *display);
318
319/**
320 * dsi_display_unprepare() - power off display hardware.
321 * @display: Handle to display.
322 *
323 * Host and panel hardware is turned off. Panel will be in reset state at the
324 * end of the function.
325 *
326 * Return: error code.
327 */
328int dsi_display_unprepare(struct dsi_display *display);
329
330int dsi_display_set_tpg_state(struct dsi_display *display, bool enable);
331
332int dsi_display_clock_gate(struct dsi_display *display, bool enable);
333int dsi_dispaly_static_frame(struct dsi_display *display, bool enable);
334
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530335int dsi_display_set_backlight(void *display, u32 bl_lvl);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700336#endif /* _DSI_DISPLAY_H_ */