blob: f941cd46feaf712d9fc4aae2f7f16af65baffa58 [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 Parmar64c19192016-06-10 16:44:56 -0700162 * dsi_display_register() - register dsi display platform driver
163 */
164void dsi_display_register(void);
165
166/**
167 * dsi_display_unregister() - unregister dsi display platform driver
168 */
169void dsi_display_unregister(void);
170
171/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700172 * dsi_display_get_num_of_displays() - returns number of display devices
173 * supported.
174 *
175 * Return: number of displays.
176 */
177u32 dsi_display_get_num_of_displays(void);
178
179/**
Clarence Ipa36c92e2016-07-26 14:33:46 -0400180 * dsi_display_get_active_displays - returns pointers for active display devices
181 * @display_array: Pointer to display array to be filled
182 * @max_display_count: Size of display_array
183 * @Returns: Number of display entries filled
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700184 */
Clarence Ipa36c92e2016-07-26 14:33:46 -0400185int dsi_display_get_active_displays(void **display_array,
186 u32 max_display_count);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700187
188/**
189 * dsi_display_get_display_by_name()- finds display by name
190 * @index: name of the display.
191 *
192 * Return: handle to the display or error code.
193 */
194struct dsi_display *dsi_display_get_display_by_name(const char *name);
195
196/**
197 * dsi_display_set_active_state() - sets the state of the display
198 * @display: Handle to display.
199 * @is_active: state
200 */
201void dsi_display_set_active_state(struct dsi_display *display, bool is_active);
202
203/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700204 * dsi_display_dev_init() - Initializes the display device
205 * @display: Handle to the display.
206 *
207 * Initialization will acquire references to the resources required for the
208 * display hardware to function.
209 *
210 * Return: error code.
211 */
212int dsi_display_dev_init(struct dsi_display *display);
213
214/**
215 * dsi_display_dev_deinit() - Desinitializes the display device
216 * @display: Handle to the display.
217 *
218 * All the resources acquired during device init will be released.
219 *
220 * Return: error code.
221 */
222int dsi_display_dev_deinit(struct dsi_display *display);
223
224/**
225 * dsi_display_bind() - Binds the display device to the DRM device
226 * @display: Handle to the display.
227 * @dev: Pointer to the DRM device.
228 *
229 * Return: error code.
230 */
231int dsi_display_bind(struct dsi_display *display, struct drm_device *dev);
232
233/**
234 * dsi_display_unbind() - Unbinds the display device from the DRM device
235 * @display: Handle to the display.
236 *
237 * Return: error code.
238 */
239int dsi_display_unbind(struct dsi_display *display);
240
241/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400242 * dsi_display_drm_bridge_init() - initializes DRM bridge object for DSI
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700243 * @display: Handle to the display.
244 * @encoder: Pointer to the encoder object which is connected to the
245 * display.
246 *
247 * Return: error code.
248 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400249int dsi_display_drm_bridge_init(struct dsi_display *display,
250 struct drm_encoder *enc);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700251
252/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400253 * dsi_display_drm_bridge_deinit() - destroys DRM bridge for the display
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700254 * @display: Handle to the display.
255 *
256 * Return: error code.
257 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400258int dsi_display_drm_bridge_deinit(struct dsi_display *display);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700259
260/**
261 * dsi_display_get_info() - returns the display properties
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700262 * @info: Pointer to the structure where info is stored.
Clarence Ipa4039322016-07-15 16:23:59 -0400263 * @disp: Handle to the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700264 *
265 * Return: error code.
266 */
Clarence Ipa4039322016-07-15 16:23:59 -0400267int dsi_display_get_info(struct msm_display_info *info, void *disp);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700268
269/**
270 * dsi_display_get_modes() - get modes supported by display
271 * @display: Handle to display.
272 * @modes; Pointer to array of modes. Memory allocated should be
273 * big enough to store (count * struct dsi_display_mode)
274 * elements. If modes pointer is NULL, number of modes will
275 * be stored in the memory pointed to by count.
276 * @count: If modes is NULL, number of modes will be stored. If
277 * not, mode information will be copied (number of modes
278 * copied will be equal to *count).
279 *
280 * Return: error code.
281 */
282int dsi_display_get_modes(struct dsi_display *display,
283 struct dsi_display_mode *modes,
284 u32 *count);
285
286/**
287 * dsi_display_validate_mode() - validates if mode is supported by display
288 * @display: Handle to display.
289 * @mode: Mode to be validated.
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700290 * @flags: Modifier flags.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700291 *
292 * Return: 0 if supported or error code.
293 */
294int dsi_display_validate_mode(struct dsi_display *display,
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700295 struct dsi_display_mode *mode,
296 u32 flags);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700297
298/**
299 * dsi_display_set_mode() - Set mode on the display.
300 * @display: Handle to display.
301 * @mode: mode to be set.
302 * @flags: Modifier flags.
303 *
304 * Return: error code.
305 */
306int dsi_display_set_mode(struct dsi_display *display,
307 struct dsi_display_mode *mode,
308 u32 flags);
309
310/**
311 * dsi_display_prepare() - prepare display
312 * @display: Handle to display.
313 *
314 * Prepare will perform power up sequences for the host and panel hardware.
315 * Power and clock resources might be turned on (depending on the panel mode).
316 * The video engine is not enabled.
317 *
318 * Return: error code.
319 */
320int dsi_display_prepare(struct dsi_display *display);
321
322/**
323 * dsi_display_enable() - enable display
324 * @display: Handle to display.
325 *
326 * Enable will turn on the host engine and the panel. At the end of the enable
327 * function, Host and panel hardware are ready to accept pixel data from
328 * upstream.
329 *
330 * Return: error code.
331 */
332int dsi_display_enable(struct dsi_display *display);
333
334/**
335 * dsi_display_post_enable() - perform post enable operations.
336 * @display: Handle to display.
337 *
338 * Some panels might require some commands to be sent after pixel data
339 * transmission has started. Such commands are sent as part of the post_enable
340 * function.
341 *
342 * Return: error code.
343 */
344int dsi_display_post_enable(struct dsi_display *display);
345
346/**
347 * dsi_display_pre_disable() - perform pre disable operations.
348 * @display: Handle to display.
349 *
350 * If a panel requires commands to be sent before pixel data transmission is
351 * stopped, those can be sent as part of pre_disable.
352 *
353 * Return: error code.
354 */
355int dsi_display_pre_disable(struct dsi_display *display);
356
357/**
358 * dsi_display_disable() - disable panel and host hardware.
359 * @display: Handle to display.
360 *
361 * Disable host and panel hardware and pixel data transmission can not continue.
362 *
363 * Return: error code.
364 */
365int dsi_display_disable(struct dsi_display *display);
366
367/**
368 * dsi_display_unprepare() - power off display hardware.
369 * @display: Handle to display.
370 *
371 * Host and panel hardware is turned off. Panel will be in reset state at the
372 * end of the function.
373 *
374 * Return: error code.
375 */
376int dsi_display_unprepare(struct dsi_display *display);
377
378int dsi_display_set_tpg_state(struct dsi_display *display, bool enable);
379
380int dsi_display_clock_gate(struct dsi_display *display, bool enable);
381int dsi_dispaly_static_frame(struct dsi_display *display, bool enable);
382
383#endif /* _DSI_DISPLAY_H_ */