blob: 9aa31139fe91496b99396b4b1036c57f898f5587 [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
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -070033#define MAX_CMDLINE_PARAM_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.
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -0700100 * @cmdline_topology: Display topology shared from kernel command line.
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700101 */
102struct dsi_display_boot_param {
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -0700103 char name[MAX_CMDLINE_PARAM_LEN];
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700104 bool boot_disp_en;
105 bool is_primary;
106 int length;
107 struct device_node *node;
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -0700108 int cmdline_topology;
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700109};
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700110
111/**
112 * struct dsi_display_clk_info - dsi display clock source information
113 * @src_clks: Source clocks for DSI display.
114 * @mux_clks: Mux clocks used for DFPS.
115 * @shadow_clks: Used for DFPS.
116 */
117struct dsi_display_clk_info {
118 struct dsi_clk_link_set src_clks;
119 struct dsi_clk_link_set mux_clks;
120 struct dsi_clk_link_set shadow_clks;
121};
122
123/**
124 * struct dsi_display - dsi display information
125 * @pdev: Pointer to platform device.
126 * @drm_dev: DRM device associated with the display.
127 * @name: Name of the display.
128 * @display_type: Display type as defined in device tree.
129 * @list: List pointer.
130 * @is_active: Is display active.
131 * @display_lock: Mutex for dsi_display interface.
132 * @ctrl_count: Number of DSI interfaces required by panel.
133 * @ctrl: Controller information for DSI display.
134 * @panel: Handle to DSI panel.
135 * @panel_of: pHandle to DSI panel.
136 * @type: DSI display type.
137 * @clk_master_idx: The master controller for controlling clocks. This is an
138 * index into the ctrl[MAX_DSI_CTRLS_PER_DISPLAY] array.
139 * @cmd_master_idx: The master controller for sending DSI commands to panel.
140 * @video_master_idx: The master controller for enabling video engine.
141 * @clock_info: Clock sourcing for DSI display.
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530142 * @config: DSI host configuration information.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700143 * @lane_map: Lane mapping between DSI host and Panel.
144 * @num_of_modes: Number of modes supported by display.
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -0700145 * @cmdline_topology: Display topology shared from kernel command line.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700146 * @is_tpg_enabled: TPG state.
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530147 * @ulps_enabled: ulps state.
148 * @clamp_enabled: clamp state.
149 * @phy_idle_power_off: PHY power state.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700150 * @host: DRM MIPI DSI Host.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700151 * @bridge: Pointer to DRM bridge object.
Lloyd Atkinsone404caf2016-07-13 17:26:45 -0400152 * @cmd_engine_refcount: Reference count enforcing single instance of cmd eng
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530153 * @clk_mngr: DSI clock manager.
154 * @dsi_clk_handle: DSI clock handle.
155 * @mdp_clk_handle: MDP clock handle.
156 * @root: Debugfs root directory
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700157 */
158struct dsi_display {
159 struct platform_device *pdev;
160 struct drm_device *drm_dev;
161
162 const char *name;
163 const char *display_type;
164 struct list_head list;
165 bool is_active;
166 struct mutex display_lock;
167
168 u32 ctrl_count;
169 struct dsi_display_ctrl ctrl[MAX_DSI_CTRLS_PER_DISPLAY];
170
171 /* panel info */
172 struct dsi_panel *panel;
173 struct device_node *panel_of;
174
175 enum dsi_display_type type;
176 u32 clk_master_idx;
177 u32 cmd_master_idx;
178 u32 video_master_idx;
179
180 struct dsi_display_clk_info clock_info;
181 struct dsi_host_config config;
Padmanabhan Komanduru8ee8ee52016-12-19 12:10:51 +0530182 struct dsi_lane_map lane_map;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700183 u32 num_of_modes;
Chandan Uddaraju7e9613a2017-06-01 13:10:55 -0700184 int cmdline_topology;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700185 bool is_tpg_enabled;
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530186 bool ulps_enabled;
187 bool clamp_enabled;
188 bool phy_idle_power_off;
Shashank Babu Chinta Venkata82109522017-05-09 18:59:21 -0700189 struct drm_gem_object *tx_cmd_buf;
190 u32 cmd_buffer_size;
191 u32 cmd_buffer_iova;
192 void *vaddr;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700193
194 struct mipi_dsi_host host;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700195 struct dsi_bridge *bridge;
Ajay Singh Parmaraa9152d2016-05-16 18:02:07 -0700196 u32 cmd_engine_refcount;
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700197
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530198 void *clk_mngr;
199 void *dsi_clk_handle;
200 void *mdp_clk_handle;
201
Ajay Singh Parmar48ea4272016-06-27 11:44:34 -0700202 /* DEBUG FS */
203 struct dentry *root;
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700204};
205
206int dsi_display_dev_probe(struct platform_device *pdev);
207int dsi_display_dev_remove(struct platform_device *pdev);
208
209/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700210 * dsi_display_get_num_of_displays() - returns number of display devices
211 * supported.
212 *
213 * Return: number of displays.
214 */
Clarence Ip3649f8b2016-10-31 09:59:44 -0400215int dsi_display_get_num_of_displays(void);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700216
217/**
Clarence Ipa36c92e2016-07-26 14:33:46 -0400218 * dsi_display_get_active_displays - returns pointers for active display devices
219 * @display_array: Pointer to display array to be filled
220 * @max_display_count: Size of display_array
221 * @Returns: Number of display entries filled
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700222 */
Clarence Ipa36c92e2016-07-26 14:33:46 -0400223int dsi_display_get_active_displays(void **display_array,
224 u32 max_display_count);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700225
226/**
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700227 * dsi_display_get_boot_display()- get DSI boot display name
228 * @index: index of display selection
229 *
230 * Return: returns the display node pointer
231 */
232struct device_node *dsi_display_get_boot_display(int index);
233
234/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700235 * dsi_display_get_display_by_name()- finds display by name
Shashank Babu Chinta Venkataded9c562017-03-15 14:43:46 -0700236 * @name: name of the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700237 *
238 * Return: handle to the display or error code.
239 */
240struct dsi_display *dsi_display_get_display_by_name(const char *name);
241
242/**
243 * dsi_display_set_active_state() - sets the state of the display
244 * @display: Handle to display.
245 * @is_active: state
246 */
247void dsi_display_set_active_state(struct dsi_display *display, bool is_active);
248
249/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400250 * dsi_display_drm_bridge_init() - initializes DRM bridge object for DSI
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700251 * @display: Handle to the display.
252 * @encoder: Pointer to the encoder object which is connected to the
253 * display.
254 *
255 * Return: error code.
256 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400257int dsi_display_drm_bridge_init(struct dsi_display *display,
258 struct drm_encoder *enc);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700259
260/**
Clarence Ip40d7d592016-07-15 16:02:26 -0400261 * dsi_display_drm_bridge_deinit() - destroys DRM bridge for the display
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700262 * @display: Handle to the display.
263 *
264 * Return: error code.
265 */
Clarence Ip40d7d592016-07-15 16:02:26 -0400266int dsi_display_drm_bridge_deinit(struct dsi_display *display);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700267
268/**
269 * dsi_display_get_info() - returns the display properties
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700270 * @info: Pointer to the structure where info is stored.
Clarence Ipa4039322016-07-15 16:23:59 -0400271 * @disp: Handle to the display.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700272 *
273 * Return: error code.
274 */
Clarence Ipa4039322016-07-15 16:23:59 -0400275int dsi_display_get_info(struct msm_display_info *info, void *disp);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700276
277/**
278 * dsi_display_get_modes() - get modes supported by display
279 * @display: Handle to display.
280 * @modes; Pointer to array of modes. Memory allocated should be
281 * big enough to store (count * struct dsi_display_mode)
282 * elements. If modes pointer is NULL, number of modes will
283 * be stored in the memory pointed to by count.
284 * @count: If modes is NULL, number of modes will be stored. If
285 * not, mode information will be copied (number of modes
286 * copied will be equal to *count).
287 *
288 * Return: error code.
289 */
290int dsi_display_get_modes(struct dsi_display *display,
291 struct dsi_display_mode *modes,
292 u32 *count);
293
294/**
295 * dsi_display_validate_mode() - validates if mode is supported by display
296 * @display: Handle to display.
297 * @mode: Mode to be validated.
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700298 * @flags: Modifier flags.
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700299 *
300 * Return: 0 if supported or error code.
301 */
302int dsi_display_validate_mode(struct dsi_display *display,
Ajay Singh Parmar62f795b2016-06-10 23:20:23 -0700303 struct dsi_display_mode *mode,
304 u32 flags);
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700305
306/**
307 * dsi_display_set_mode() - Set mode on the display.
308 * @display: Handle to display.
309 * @mode: mode to be set.
310 * @flags: Modifier flags.
311 *
312 * Return: error code.
313 */
314int dsi_display_set_mode(struct dsi_display *display,
315 struct dsi_display_mode *mode,
316 u32 flags);
317
318/**
319 * dsi_display_prepare() - prepare display
320 * @display: Handle to display.
321 *
322 * Prepare will perform power up sequences for the host and panel hardware.
323 * Power and clock resources might be turned on (depending on the panel mode).
324 * The video engine is not enabled.
325 *
326 * Return: error code.
327 */
328int dsi_display_prepare(struct dsi_display *display);
329
330/**
331 * dsi_display_enable() - enable display
332 * @display: Handle to display.
333 *
334 * Enable will turn on the host engine and the panel. At the end of the enable
335 * function, Host and panel hardware are ready to accept pixel data from
336 * upstream.
337 *
338 * Return: error code.
339 */
340int dsi_display_enable(struct dsi_display *display);
341
342/**
343 * dsi_display_post_enable() - perform post enable operations.
344 * @display: Handle to display.
345 *
346 * Some panels might require some commands to be sent after pixel data
347 * transmission has started. Such commands are sent as part of the post_enable
348 * function.
349 *
350 * Return: error code.
351 */
352int dsi_display_post_enable(struct dsi_display *display);
353
354/**
355 * dsi_display_pre_disable() - perform pre disable operations.
356 * @display: Handle to display.
357 *
358 * If a panel requires commands to be sent before pixel data transmission is
359 * stopped, those can be sent as part of pre_disable.
360 *
361 * Return: error code.
362 */
363int dsi_display_pre_disable(struct dsi_display *display);
364
365/**
366 * dsi_display_disable() - disable panel and host hardware.
367 * @display: Handle to display.
368 *
369 * Disable host and panel hardware and pixel data transmission can not continue.
370 *
371 * Return: error code.
372 */
373int dsi_display_disable(struct dsi_display *display);
374
375/**
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530376 * dsi_pre_clkoff_cb() - Callback before clock is turned off
377 * @priv: private data pointer.
378 * @clk_type: clock which is being turned on.
379 * @new_state: next state for the clock.
380 *
381 * @return: error code.
382 */
383int dsi_pre_clkoff_cb(void *priv, enum dsi_clk_type clk_type,
384 enum dsi_clk_state new_state);
385
386/**
Alexander Beykunac182352017-02-27 17:46:51 -0500387 * dsi_display_update_pps() - update PPS buffer.
388 * @pps_cmd: PPS buffer.
389 * @display: Handle to display.
390 *
391 * Copies new PPS buffer into display structure.
392 *
393 * Return: error code.
394 */
395int dsi_display_update_pps(char *pps_cmd, void *display);
396
397/**
Padmanabhan Komandurudbd2fb02016-12-02 15:18:49 +0530398 * dsi_post_clkoff_cb() - Callback after clock is turned off
399 * @priv: private data pointer.
400 * @clk_type: clock which is being turned on.
401 * @curr_state: current state for the clock.
402 *
403 * @return: error code.
404 */
405int dsi_post_clkoff_cb(void *priv, enum dsi_clk_type clk_type,
406 enum dsi_clk_state curr_state);
407
408/**
409 * dsi_post_clkon_cb() - Callback after clock is turned on
410 * @priv: private data pointer.
411 * @clk_type: clock which is being turned on.
412 * @curr_state: current state for the clock.
413 *
414 * @return: error code.
415 */
416int dsi_post_clkon_cb(void *priv, enum dsi_clk_type clk_type,
417 enum dsi_clk_state curr_state);
418
419
420/**
421 * dsi_pre_clkon_cb() - Callback before clock is turned on
422 * @priv: private data pointer.
423 * @clk_type: clock which is being turned on.
424 * @new_state: next state for the clock.
425 *
426 * @return: error code.
427 */
428int dsi_pre_clkon_cb(void *priv, enum dsi_clk_type clk_type,
429 enum dsi_clk_state new_state);
430
431/**
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700432 * dsi_display_unprepare() - power off display hardware.
433 * @display: Handle to display.
434 *
435 * Host and panel hardware is turned off. Panel will be in reset state at the
436 * end of the function.
437 *
438 * Return: error code.
439 */
440int dsi_display_unprepare(struct dsi_display *display);
441
442int dsi_display_set_tpg_state(struct dsi_display *display, bool enable);
443
444int dsi_display_clock_gate(struct dsi_display *display, bool enable);
445int dsi_dispaly_static_frame(struct dsi_display *display, bool enable);
446
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530447int dsi_display_set_backlight(void *display, u32 bl_lvl);
Lloyd Atkinson8c49c582016-11-18 14:23:54 -0500448
449/**
450 * dsi_display_soft_reset() - perform a soft reset on DSI controller
451 * @display: Handle to display
452 *
453 * The video, command and controller engines will be disabled before the
454 * reset is triggered. After, the engines will be re-enabled to the same state
455 * as before the reset.
456 *
457 * If the reset is done while MDP timing engine is turned on, the video
458 * engine should be re-enabled only during the vertical blanking time.
459 *
460 * Return: error code
461 */
462int dsi_display_soft_reset(void *display);
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500463
464/*
465 * dsi_display_pre_kickoff - program kickoff-time features
466 * @display: Pointer to private display structure
467 * @params: Parameters for kickoff-time programming
468 * Returns: Zero on success
469 */
470int dsi_display_pre_kickoff(struct dsi_display *display,
471 struct msm_display_kickoff_params *params);
472
Ajay Singh Parmar571e3012016-05-16 17:55:52 -0700473#endif /* _DSI_DISPLAY_H_ */