blob: 89f31af96d6eb8e58adac1f18d3951c339969b2f [file] [log] [blame]
Ajay Singh Parmar571e3012016-05-16 17:55:52 -07001/*
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +05302 * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -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_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
Shashank Babu Chinta Venkata74a03f12017-02-28 11:24:51 -080032#define DSI_CLIENT_NAME_SIZE 20
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.
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530113 * @config: DSI host configuration information.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700114 * @lane_map: Lane mapping between DSI host and Panel.
115 * @num_of_modes: Number of modes supported by display.
116 * @is_tpg_enabled: TPG state.
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530117 * @ulps_enabled: ulps state.
118 * @clamp_enabled: clamp state.
119 * @phy_idle_power_off: PHY power state.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700120 * @host: DRM MIPI DSI Host.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700121 * @bridge: Pointer to DRM bridge object.
Lloyd Atkinsone404caf2016-07-13 17:26:45 -0400122 * @cmd_engine_refcount: Reference count enforcing single instance of cmd eng
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530123 * @clk_mngr: DSI clock manager.
124 * @dsi_clk_handle: DSI clock handle.
125 * @mdp_clk_handle: MDP clock handle.
126 * @root: Debugfs root directory
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700127 */
128struct dsi_display {
129 struct platform_device *pdev;
130 struct drm_device *drm_dev;
131
132 const char *name;
133 const char *display_type;
134 struct list_head list;
135 bool is_active;
136 struct mutex display_lock;
137
138 u32 ctrl_count;
139 struct dsi_display_ctrl ctrl[MAX_DSI_CTRLS_PER_DISPLAY];
140
141 /* panel info */
142 struct dsi_panel *panel;
143 struct device_node *panel_of;
144
145 enum dsi_display_type type;
146 u32 clk_master_idx;
147 u32 cmd_master_idx;
148 u32 video_master_idx;
149
150 struct dsi_display_clk_info clock_info;
151 struct dsi_host_config config;
Padmanabhan Komanduru8ee8ee52016-12-19 12:10:51 +0530152 struct dsi_lane_map lane_map;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700153 u32 num_of_modes;
154 bool is_tpg_enabled;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530155 bool ulps_enabled;
156 bool clamp_enabled;
157 bool phy_idle_power_off;
Shashank Babu Chinta Venkata82109522017-05-09 18:59:21 -0700158 struct drm_gem_object *tx_cmd_buf;
159 u32 cmd_buffer_size;
160 u32 cmd_buffer_iova;
161 void *vaddr;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700162
163 struct mipi_dsi_host host;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700164 struct dsi_bridge *bridge;
Ajay Singh Parmaraa9152d2016-05-16 18:02:07 -0700165 u32 cmd_engine_refcount;
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700166
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530167 void *clk_mngr;
168 void *dsi_clk_handle;
169 void *mdp_clk_handle;
170
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700171 /* DEBUG FS */
172 struct dentry *root;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700173};
174
175int dsi_display_dev_probe(struct platform_device *pdev);
176int dsi_display_dev_remove(struct platform_device *pdev);
177
178/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700179 * dsi_display_get_num_of_displays() - returns number of display devices
180 * supported.
181 *
182 * Return: number of displays.
183 */
Clarence Ip3649f8b2016-10-31 09:59:44 -0400184int dsi_display_get_num_of_displays(void);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700185
186/**
Clarence Ipa36c92e2016-07-26 14:33:46 -0400187 * dsi_display_get_active_displays - returns pointers for active display devices
188 * @display_array: Pointer to display array to be filled
189 * @max_display_count: Size of display_array
190 * @Returns: Number of display entries filled
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700191 */
Clarence Ipa36c92e2016-07-26 14:33:46 -0400192int dsi_display_get_active_displays(void **display_array,
193 u32 max_display_count);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700194
195/**
196 * dsi_display_get_display_by_name()- finds display by name
197 * @index: name of the display.
198 *
199 * Return: handle to the display or error code.
200 */
201struct dsi_display *dsi_display_get_display_by_name(const char *name);
202
203/**
204 * dsi_display_set_active_state() - sets the state of the display
205 * @display: Handle to display.
206 * @is_active: state
207 */
208void dsi_display_set_active_state(struct dsi_display *display, bool is_active);
209
210/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400211 * dsi_display_drm_bridge_init() - initializes DRM bridge object for DSI
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700212 * @display: Handle to the display.
213 * @encoder: Pointer to the encoder object which is connected to the
214 * display.
215 *
216 * Return: error code.
217 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400218int dsi_display_drm_bridge_init(struct dsi_display *display,
219 struct drm_encoder *enc);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700220
221/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400222 * dsi_display_drm_bridge_deinit() - destroys DRM bridge for the display
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700223 * @display: Handle to the display.
224 *
225 * Return: error code.
226 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400227int dsi_display_drm_bridge_deinit(struct dsi_display *display);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700228
229/**
230 * dsi_display_get_info() - returns the display properties
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700231 * @info: Pointer to the structure where info is stored.
Clarence Ipa4039322016-07-15 16:23:59 -0400232 * @disp: Handle to the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700233 *
234 * Return: error code.
235 */
Clarence Ipa4039322016-07-15 16:23:59 -0400236int dsi_display_get_info(struct msm_display_info *info, void *disp);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700237
238/**
239 * dsi_display_get_modes() - get modes supported by display
240 * @display: Handle to display.
241 * @modes; Pointer to array of modes. Memory allocated should be
242 * big enough to store (count * struct dsi_display_mode)
243 * elements. If modes pointer is NULL, number of modes will
244 * be stored in the memory pointed to by count.
245 * @count: If modes is NULL, number of modes will be stored. If
246 * not, mode information will be copied (number of modes
247 * copied will be equal to *count).
248 *
249 * Return: error code.
250 */
251int dsi_display_get_modes(struct dsi_display *display,
252 struct dsi_display_mode *modes,
253 u32 *count);
254
255/**
256 * dsi_display_validate_mode() - validates if mode is supported by display
257 * @display: Handle to display.
258 * @mode: Mode to be validated.
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700259 * @flags: Modifier flags.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700260 *
261 * Return: 0 if supported or error code.
262 */
263int dsi_display_validate_mode(struct dsi_display *display,
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700264 struct dsi_display_mode *mode,
265 u32 flags);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700266
267/**
268 * dsi_display_set_mode() - Set mode on the display.
269 * @display: Handle to display.
270 * @mode: mode to be set.
271 * @flags: Modifier flags.
272 *
273 * Return: error code.
274 */
275int dsi_display_set_mode(struct dsi_display *display,
276 struct dsi_display_mode *mode,
277 u32 flags);
278
279/**
280 * dsi_display_prepare() - prepare display
281 * @display: Handle to display.
282 *
283 * Prepare will perform power up sequences for the host and panel hardware.
284 * Power and clock resources might be turned on (depending on the panel mode).
285 * The video engine is not enabled.
286 *
287 * Return: error code.
288 */
289int dsi_display_prepare(struct dsi_display *display);
290
291/**
292 * dsi_display_enable() - enable display
293 * @display: Handle to display.
294 *
295 * Enable will turn on the host engine and the panel. At the end of the enable
296 * function, Host and panel hardware are ready to accept pixel data from
297 * upstream.
298 *
299 * Return: error code.
300 */
301int dsi_display_enable(struct dsi_display *display);
302
303/**
304 * dsi_display_post_enable() - perform post enable operations.
305 * @display: Handle to display.
306 *
307 * Some panels might require some commands to be sent after pixel data
308 * transmission has started. Such commands are sent as part of the post_enable
309 * function.
310 *
311 * Return: error code.
312 */
313int dsi_display_post_enable(struct dsi_display *display);
314
315/**
316 * dsi_display_pre_disable() - perform pre disable operations.
317 * @display: Handle to display.
318 *
319 * If a panel requires commands to be sent before pixel data transmission is
320 * stopped, those can be sent as part of pre_disable.
321 *
322 * Return: error code.
323 */
324int dsi_display_pre_disable(struct dsi_display *display);
325
326/**
327 * dsi_display_disable() - disable panel and host hardware.
328 * @display: Handle to display.
329 *
330 * Disable host and panel hardware and pixel data transmission can not continue.
331 *
332 * Return: error code.
333 */
334int dsi_display_disable(struct dsi_display *display);
335
336/**
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530337 * dsi_pre_clkoff_cb() - Callback before clock is turned off
338 * @priv: private data pointer.
339 * @clk_type: clock which is being turned on.
340 * @new_state: next state for the clock.
341 *
342 * @return: error code.
343 */
344int dsi_pre_clkoff_cb(void *priv, enum dsi_clk_type clk_type,
345 enum dsi_clk_state new_state);
346
347/**
Alexander Beykunac182352017-02-27 17:46:51 -0500348 * dsi_display_update_pps() - update PPS buffer.
349 * @pps_cmd: PPS buffer.
350 * @display: Handle to display.
351 *
352 * Copies new PPS buffer into display structure.
353 *
354 * Return: error code.
355 */
356int dsi_display_update_pps(char *pps_cmd, void *display);
357
358/**
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530359 * dsi_post_clkoff_cb() - Callback after clock is turned off
360 * @priv: private data pointer.
361 * @clk_type: clock which is being turned on.
362 * @curr_state: current state for the clock.
363 *
364 * @return: error code.
365 */
366int dsi_post_clkoff_cb(void *priv, enum dsi_clk_type clk_type,
367 enum dsi_clk_state curr_state);
368
369/**
370 * dsi_post_clkon_cb() - Callback after clock is turned on
371 * @priv: private data pointer.
372 * @clk_type: clock which is being turned on.
373 * @curr_state: current state for the clock.
374 *
375 * @return: error code.
376 */
377int dsi_post_clkon_cb(void *priv, enum dsi_clk_type clk_type,
378 enum dsi_clk_state curr_state);
379
380
381/**
382 * dsi_pre_clkon_cb() - Callback before clock is turned on
383 * @priv: private data pointer.
384 * @clk_type: clock which is being turned on.
385 * @new_state: next state for the clock.
386 *
387 * @return: error code.
388 */
389int dsi_pre_clkon_cb(void *priv, enum dsi_clk_type clk_type,
390 enum dsi_clk_state new_state);
391
392/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700393 * dsi_display_unprepare() - power off display hardware.
394 * @display: Handle to display.
395 *
396 * Host and panel hardware is turned off. Panel will be in reset state at the
397 * end of the function.
398 *
399 * Return: error code.
400 */
401int dsi_display_unprepare(struct dsi_display *display);
402
403int dsi_display_set_tpg_state(struct dsi_display *display, bool enable);
404
405int dsi_display_clock_gate(struct dsi_display *display, bool enable);
406int dsi_dispaly_static_frame(struct dsi_display *display, bool enable);
407
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530408int dsi_display_set_backlight(void *display, u32 bl_lvl);
Lloyd Atkinson8c49c582016-11-18 14:23:54 -0500409
410/**
411 * dsi_display_soft_reset() - perform a soft reset on DSI controller
412 * @display: Handle to display
413 *
414 * The video, command and controller engines will be disabled before the
415 * reset is triggered. After, the engines will be re-enabled to the same state
416 * as before the reset.
417 *
418 * If the reset is done while MDP timing engine is turned on, the video
419 * engine should be re-enabled only during the vertical blanking time.
420 *
421 * Return: error code
422 */
423int dsi_display_soft_reset(void *display);
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500424
425/*
426 * dsi_display_pre_kickoff - program kickoff-time features
427 * @display: Pointer to private display structure
428 * @params: Parameters for kickoff-time programming
429 * Returns: Zero on success
430 */
431int dsi_display_pre_kickoff(struct dsi_display *display,
432 struct msm_display_kickoff_params *params);
433
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700434#endif /* _DSI_DISPLAY_H_ */