blob: 15a3f46a7ca1a2de53fbbfefcc12a8bff3549421 [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
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -070033#define DSI_DISPLAY_MAX_LEN 512
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -070034/*
35 * DSI Validate Mode modifiers
36 * @DSI_VALIDATE_FLAG_ALLOW_ADJUST: Allow mode validation to also do fixup
37 */
38#define DSI_VALIDATE_FLAG_ALLOW_ADJUST 0x1
39
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070040/**
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -070041 * enum dsi_display_selection_type - enumerates DSI display selection types
42 * @DSI_PRIMARY: primary DSI display selected from module parameter
43 * @DSI_SECONDARY: Secondary DSI display selected from module parameter
44 * @MAX_DSI_ACTIVE_DISPLAY: Maximum acive displays that can be selected
45 */
46enum dsi_display_selection_type {
47 DSI_PRIMARY = 0,
48 DSI_SECONDARY,
49 MAX_DSI_ACTIVE_DISPLAY,
50};
51
52/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070053 * enum dsi_display_type - enumerates DSI display types
54 * @DSI_DISPLAY_SINGLE: A panel connected on a single DSI interface.
55 * @DSI_DISPLAY_EXT_BRIDGE: A bridge is connected between panel and DSI host.
56 * It utilizes a single DSI interface.
57 * @DSI_DISPLAY_SPLIT: A panel that utilizes more than one DSI
58 * interfaces.
59 * @DSI_DISPLAY_SPLIT_EXT_BRIDGE: A bridge is present between panel and DSI
60 * host. It utilizes more than one DSI interface.
61 */
62enum dsi_display_type {
63 DSI_DISPLAY_SINGLE = 0,
64 DSI_DISPLAY_EXT_BRIDGE,
65 DSI_DISPLAY_SPLIT,
66 DSI_DISPLAY_SPLIT_EXT_BRIDGE,
67 DSI_DISPLAY_MAX,
68};
69
70/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070071 * struct dsi_display_ctrl - dsi ctrl/phy information for the display
72 * @ctrl: Handle to the DSI controller device.
73 * @ctrl_of_node: pHandle to the DSI controller device.
74 * @dsi_ctrl_idx: DSI controller instance id.
75 * @power_state: Current power state of the DSI controller.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070076 * @phy: Handle to the DSI PHY device.
77 * @phy_of_node: pHandle to the DSI PHY device.
78 * @phy_enabled: PHY power status.
79 */
80struct dsi_display_ctrl {
81 /* controller info */
82 struct dsi_ctrl *ctrl;
83 struct device_node *ctrl_of_node;
84 u32 dsi_ctrl_idx;
85
86 enum dsi_power_state power_state;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -070087
88 /* phy info */
89 struct msm_dsi_phy *phy;
90 struct device_node *phy_of_node;
91
92 bool phy_enabled;
93};
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -070094/**
95 * struct dsi_display_boot_param - defines DSI boot display selection
96 * @name:Name of DSI display selected as a boot param.
97 * @boot_disp_en:bool to indicate dtsi availability of display node
98 * @is_primary:bool to indicate whether current display is primary display
99 * @length:length of DSI display.
100 */
101struct dsi_display_boot_param {
102 char name[DSI_DISPLAY_MAX_LEN];
103 bool boot_disp_en;
104 bool is_primary;
105 int length;
106 struct device_node *node;
107
108};
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700109
110/**
111 * struct dsi_display_clk_info - dsi display clock source information
112 * @src_clks: Source clocks for DSI display.
113 * @mux_clks: Mux clocks used for DFPS.
114 * @shadow_clks: Used for DFPS.
115 */
116struct dsi_display_clk_info {
117 struct dsi_clk_link_set src_clks;
118 struct dsi_clk_link_set mux_clks;
119 struct dsi_clk_link_set shadow_clks;
120};
121
122/**
123 * struct dsi_display - dsi display information
124 * @pdev: Pointer to platform device.
125 * @drm_dev: DRM device associated with the display.
126 * @name: Name of the display.
127 * @display_type: Display type as defined in device tree.
128 * @list: List pointer.
129 * @is_active: Is display active.
130 * @display_lock: Mutex for dsi_display interface.
131 * @ctrl_count: Number of DSI interfaces required by panel.
132 * @ctrl: Controller information for DSI display.
133 * @panel: Handle to DSI panel.
134 * @panel_of: pHandle to DSI panel.
135 * @type: DSI display type.
136 * @clk_master_idx: The master controller for controlling clocks. This is an
137 * index into the ctrl[MAX_DSI_CTRLS_PER_DISPLAY] array.
138 * @cmd_master_idx: The master controller for sending DSI commands to panel.
139 * @video_master_idx: The master controller for enabling video engine.
140 * @clock_info: Clock sourcing for DSI display.
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530141 * @config: DSI host configuration information.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700142 * @lane_map: Lane mapping between DSI host and Panel.
143 * @num_of_modes: Number of modes supported by display.
144 * @is_tpg_enabled: TPG state.
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530145 * @ulps_enabled: ulps state.
146 * @clamp_enabled: clamp state.
147 * @phy_idle_power_off: PHY power state.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700148 * @host: DRM MIPI DSI Host.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700149 * @bridge: Pointer to DRM bridge object.
Lloyd Atkinsone404caf2016-07-13 17:26:45 -0400150 * @cmd_engine_refcount: Reference count enforcing single instance of cmd eng
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530151 * @clk_mngr: DSI clock manager.
152 * @dsi_clk_handle: DSI clock handle.
153 * @mdp_clk_handle: MDP clock handle.
154 * @root: Debugfs root directory
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700155 */
156struct dsi_display {
157 struct platform_device *pdev;
158 struct drm_device *drm_dev;
159
160 const char *name;
161 const char *display_type;
162 struct list_head list;
163 bool is_active;
164 struct mutex display_lock;
165
166 u32 ctrl_count;
167 struct dsi_display_ctrl ctrl[MAX_DSI_CTRLS_PER_DISPLAY];
168
169 /* panel info */
170 struct dsi_panel *panel;
171 struct device_node *panel_of;
172
173 enum dsi_display_type type;
174 u32 clk_master_idx;
175 u32 cmd_master_idx;
176 u32 video_master_idx;
177
178 struct dsi_display_clk_info clock_info;
179 struct dsi_host_config config;
Padmanabhan Komanduru8ee8ee52016-12-19 12:10:51 +0530180 struct dsi_lane_map lane_map;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700181 u32 num_of_modes;
182 bool is_tpg_enabled;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530183 bool ulps_enabled;
184 bool clamp_enabled;
185 bool phy_idle_power_off;
Shashank Babu Chinta Venkata82109522017-05-09 18:59:21 -0700186 struct drm_gem_object *tx_cmd_buf;
187 u32 cmd_buffer_size;
188 u32 cmd_buffer_iova;
189 void *vaddr;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700190
191 struct mipi_dsi_host host;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700192 struct dsi_bridge *bridge;
Ajay Singh Parmaraa9152d2016-05-16 18:02:07 -0700193 u32 cmd_engine_refcount;
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700194
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530195 void *clk_mngr;
196 void *dsi_clk_handle;
197 void *mdp_clk_handle;
198
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700199 /* DEBUG FS */
200 struct dentry *root;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700201};
202
203int dsi_display_dev_probe(struct platform_device *pdev);
204int dsi_display_dev_remove(struct platform_device *pdev);
205
206/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700207 * dsi_display_get_num_of_displays() - returns number of display devices
208 * supported.
209 *
210 * Return: number of displays.
211 */
Clarence Ip3649f8b2016-10-31 09:59:44 -0400212int dsi_display_get_num_of_displays(void);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700213
214/**
Clarence Ipa36c92e2016-07-26 14:33:46 -0400215 * dsi_display_get_active_displays - returns pointers for active display devices
216 * @display_array: Pointer to display array to be filled
217 * @max_display_count: Size of display_array
218 * @Returns: Number of display entries filled
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700219 */
Clarence Ipa36c92e2016-07-26 14:33:46 -0400220int dsi_display_get_active_displays(void **display_array,
221 u32 max_display_count);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700222
223/**
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700224 * dsi_display_get_boot_display()- get DSI boot display name
225 * @index: index of display selection
226 *
227 * Return: returns the display node pointer
228 */
229struct device_node *dsi_display_get_boot_display(int index);
230
231/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700232 * dsi_display_get_display_by_name()- finds display by name
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700233 * @name: name of the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700234 *
235 * Return: handle to the display or error code.
236 */
237struct dsi_display *dsi_display_get_display_by_name(const char *name);
238
239/**
240 * dsi_display_set_active_state() - sets the state of the display
241 * @display: Handle to display.
242 * @is_active: state
243 */
244void dsi_display_set_active_state(struct dsi_display *display, bool is_active);
245
246/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400247 * dsi_display_drm_bridge_init() - initializes DRM bridge object for DSI
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700248 * @display: Handle to the display.
249 * @encoder: Pointer to the encoder object which is connected to the
250 * display.
251 *
252 * Return: error code.
253 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400254int dsi_display_drm_bridge_init(struct dsi_display *display,
255 struct drm_encoder *enc);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700256
257/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400258 * dsi_display_drm_bridge_deinit() - destroys DRM bridge for the display
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700259 * @display: Handle to the display.
260 *
261 * Return: error code.
262 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400263int dsi_display_drm_bridge_deinit(struct dsi_display *display);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700264
265/**
266 * dsi_display_get_info() - returns the display properties
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700267 * @info: Pointer to the structure where info is stored.
Clarence Ipa4039322016-07-15 16:23:59 -0400268 * @disp: Handle to the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700269 *
270 * Return: error code.
271 */
Clarence Ipa4039322016-07-15 16:23:59 -0400272int dsi_display_get_info(struct msm_display_info *info, void *disp);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700273
274/**
275 * dsi_display_get_modes() - get modes supported by display
276 * @display: Handle to display.
277 * @modes; Pointer to array of modes. Memory allocated should be
278 * big enough to store (count * struct dsi_display_mode)
279 * elements. If modes pointer is NULL, number of modes will
280 * be stored in the memory pointed to by count.
281 * @count: If modes is NULL, number of modes will be stored. If
282 * not, mode information will be copied (number of modes
283 * copied will be equal to *count).
284 *
285 * Return: error code.
286 */
287int dsi_display_get_modes(struct dsi_display *display,
288 struct dsi_display_mode *modes,
289 u32 *count);
290
291/**
292 * dsi_display_validate_mode() - validates if mode is supported by display
293 * @display: Handle to display.
294 * @mode: Mode to be validated.
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700295 * @flags: Modifier flags.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700296 *
297 * Return: 0 if supported or error code.
298 */
299int dsi_display_validate_mode(struct dsi_display *display,
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700300 struct dsi_display_mode *mode,
301 u32 flags);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700302
303/**
304 * dsi_display_set_mode() - Set mode on the display.
305 * @display: Handle to display.
306 * @mode: mode to be set.
307 * @flags: Modifier flags.
308 *
309 * Return: error code.
310 */
311int dsi_display_set_mode(struct dsi_display *display,
312 struct dsi_display_mode *mode,
313 u32 flags);
314
315/**
316 * dsi_display_prepare() - prepare display
317 * @display: Handle to display.
318 *
319 * Prepare will perform power up sequences for the host and panel hardware.
320 * Power and clock resources might be turned on (depending on the panel mode).
321 * The video engine is not enabled.
322 *
323 * Return: error code.
324 */
325int dsi_display_prepare(struct dsi_display *display);
326
327/**
328 * dsi_display_enable() - enable display
329 * @display: Handle to display.
330 *
331 * Enable will turn on the host engine and the panel. At the end of the enable
332 * function, Host and panel hardware are ready to accept pixel data from
333 * upstream.
334 *
335 * Return: error code.
336 */
337int dsi_display_enable(struct dsi_display *display);
338
339/**
340 * dsi_display_post_enable() - perform post enable operations.
341 * @display: Handle to display.
342 *
343 * Some panels might require some commands to be sent after pixel data
344 * transmission has started. Such commands are sent as part of the post_enable
345 * function.
346 *
347 * Return: error code.
348 */
349int dsi_display_post_enable(struct dsi_display *display);
350
351/**
352 * dsi_display_pre_disable() - perform pre disable operations.
353 * @display: Handle to display.
354 *
355 * If a panel requires commands to be sent before pixel data transmission is
356 * stopped, those can be sent as part of pre_disable.
357 *
358 * Return: error code.
359 */
360int dsi_display_pre_disable(struct dsi_display *display);
361
362/**
363 * dsi_display_disable() - disable panel and host hardware.
364 * @display: Handle to display.
365 *
366 * Disable host and panel hardware and pixel data transmission can not continue.
367 *
368 * Return: error code.
369 */
370int dsi_display_disable(struct dsi_display *display);
371
372/**
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530373 * dsi_pre_clkoff_cb() - Callback before clock is turned off
374 * @priv: private data pointer.
375 * @clk_type: clock which is being turned on.
376 * @new_state: next state for the clock.
377 *
378 * @return: error code.
379 */
380int dsi_pre_clkoff_cb(void *priv, enum dsi_clk_type clk_type,
381 enum dsi_clk_state new_state);
382
383/**
Alexander Beykunac182352017-02-27 17:46:51 -0500384 * dsi_display_update_pps() - update PPS buffer.
385 * @pps_cmd: PPS buffer.
386 * @display: Handle to display.
387 *
388 * Copies new PPS buffer into display structure.
389 *
390 * Return: error code.
391 */
392int dsi_display_update_pps(char *pps_cmd, void *display);
393
394/**
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530395 * dsi_post_clkoff_cb() - Callback after clock is turned off
396 * @priv: private data pointer.
397 * @clk_type: clock which is being turned on.
398 * @curr_state: current state for the clock.
399 *
400 * @return: error code.
401 */
402int dsi_post_clkoff_cb(void *priv, enum dsi_clk_type clk_type,
403 enum dsi_clk_state curr_state);
404
405/**
406 * dsi_post_clkon_cb() - Callback after clock is turned on
407 * @priv: private data pointer.
408 * @clk_type: clock which is being turned on.
409 * @curr_state: current state for the clock.
410 *
411 * @return: error code.
412 */
413int dsi_post_clkon_cb(void *priv, enum dsi_clk_type clk_type,
414 enum dsi_clk_state curr_state);
415
416
417/**
418 * dsi_pre_clkon_cb() - Callback before clock is turned on
419 * @priv: private data pointer.
420 * @clk_type: clock which is being turned on.
421 * @new_state: next state for the clock.
422 *
423 * @return: error code.
424 */
425int dsi_pre_clkon_cb(void *priv, enum dsi_clk_type clk_type,
426 enum dsi_clk_state new_state);
427
428/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700429 * dsi_display_unprepare() - power off display hardware.
430 * @display: Handle to display.
431 *
432 * Host and panel hardware is turned off. Panel will be in reset state at the
433 * end of the function.
434 *
435 * Return: error code.
436 */
437int dsi_display_unprepare(struct dsi_display *display);
438
439int dsi_display_set_tpg_state(struct dsi_display *display, bool enable);
440
441int dsi_display_clock_gate(struct dsi_display *display, bool enable);
442int dsi_dispaly_static_frame(struct dsi_display *display, bool enable);
443
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530444int dsi_display_set_backlight(void *display, u32 bl_lvl);
Lloyd Atkinson8c49c582016-11-18 14:23:54 -0500445
446/**
447 * dsi_display_soft_reset() - perform a soft reset on DSI controller
448 * @display: Handle to display
449 *
450 * The video, command and controller engines will be disabled before the
451 * reset is triggered. After, the engines will be re-enabled to the same state
452 * as before the reset.
453 *
454 * If the reset is done while MDP timing engine is turned on, the video
455 * engine should be re-enabled only during the vertical blanking time.
456 *
457 * Return: error code
458 */
459int dsi_display_soft_reset(void *display);
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500460
461/*
462 * dsi_display_pre_kickoff - program kickoff-time features
463 * @display: Pointer to private display structure
464 * @params: Parameters for kickoff-time programming
465 * Returns: Zero on success
466 */
467int dsi_display_pre_kickoff(struct dsi_display *display,
468 struct msm_display_kickoff_params *params);
469
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700470#endif /* _DSI_DISPLAY_H_ */