blob: 2543822570600acfcd0891f6b480a99c1e219d87 [file] [log] [blame]
Narender Ankam1afbd172020-03-16 17:27:44 +05301/* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
Clarence Ipdd8021c2016-07-20 16:39:47 -04002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _SDE_CONNECTOR_H_
14#define _SDE_CONNECTOR_H_
15
Ping Li8430ee12017-02-24 14:14:44 -080016#include <uapi/drm/msm_drm_pp.h>
Clarence Ipdd8021c2016-07-20 16:39:47 -040017#include <drm/drmP.h>
18#include <drm/drm_atomic.h>
19#include <drm/drm_panel.h>
20
Clarence Ipcb3afd42016-07-15 16:25:34 -040021#include "msm_drv.h"
Clarence Ipdd8021c2016-07-20 16:39:47 -040022#include "msm_prop.h"
23#include "sde_kms.h"
Clarence Ipe59fb3f2016-07-26 13:39:59 -040024#include "sde_fence.h"
Clarence Ipdd8021c2016-07-20 16:39:47 -040025
26#define SDE_CONNECTOR_NAME_SIZE 16
27
28struct sde_connector;
29struct sde_connector_state;
30
31/**
32 * struct sde_connector_ops - callback functions for generic sde connector
33 * Individual callbacks documented below.
34 */
35struct sde_connector_ops {
36 /**
37 * post_init - perform additional initialization steps
38 * @connector: Pointer to drm connector structure
Alan Kwong769fba92017-11-13 16:50:36 -050039 * @display: Pointer to private display handle
40 * Returns: Zero on success
41 */
42 int (*post_init)(struct drm_connector *connector,
43 void *display);
44
45 /**
46 * set_info_blob - initialize given info blob
47 * @connector: Pointer to drm connector structure
Clarence Ipdd8021c2016-07-20 16:39:47 -040048 * @info: Pointer to sde connector info structure
49 * @display: Pointer to private display handle
Jeykumar Sankaran736d79d2017-10-05 17:44:24 -070050 * @mode_info: Pointer to mode info structure
Clarence Ipdd8021c2016-07-20 16:39:47 -040051 * Returns: Zero on success
52 */
Alan Kwong769fba92017-11-13 16:50:36 -050053 int (*set_info_blob)(struct drm_connector *connector,
Clarence Ipdd8021c2016-07-20 16:39:47 -040054 void *info,
Jeykumar Sankaran736d79d2017-10-05 17:44:24 -070055 void *display,
56 struct msm_mode_info *mode_info);
Clarence Ipdd8021c2016-07-20 16:39:47 -040057
58 /**
59 * detect - determine if connector is connected
60 * @connector: Pointer to drm connector structure
61 * @force: Force detect setting from drm framework
62 * @display: Pointer to private display handle
63 * Returns: Connector 'is connected' status
64 */
65 enum drm_connector_status (*detect)(struct drm_connector *connector,
66 bool force,
67 void *display);
68
69 /**
70 * get_modes - add drm modes via drm_mode_probed_add()
71 * @connector: Pointer to drm connector structure
72 * @display: Pointer to private display handle
73 * Returns: Number of modes added
74 */
75 int (*get_modes)(struct drm_connector *connector,
76 void *display);
77
78 /**
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -070079 * put_modes - free up drm modes of the connector
80 * @connector: Pointer to drm connector structure
81 * @display: Pointer to private display handle
82 */
83 void (*put_modes)(struct drm_connector *connector,
84 void *display);
85
86 /**
Jeykumar Sankaran5c2f0702017-03-09 18:03:15 -080087 * update_pps - update pps command for the display panel
88 * @pps_cmd: Pointer to pps command
89 * @display: Pointer to private display handle
90 * Returns: Zero on success
91 */
92 int (*update_pps)(char *pps_cmd, void *display);
93
94 /**
Clarence Ipdd8021c2016-07-20 16:39:47 -040095 * mode_valid - determine if specified mode is valid
96 * @connector: Pointer to drm connector structure
97 * @mode: Pointer to drm mode structure
98 * @display: Pointer to private display handle
99 * Returns: Validity status for specified mode
100 */
101 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
102 struct drm_display_mode *mode,
103 void *display);
104
105 /**
106 * set_property - set property value
107 * @connector: Pointer to drm connector structure
108 * @state: Pointer to drm connector state structure
109 * @property_index: DRM property index
110 * @value: Incoming property value
111 * @display: Pointer to private display structure
112 * Returns: Zero on success
113 */
114 int (*set_property)(struct drm_connector *connector,
115 struct drm_connector_state *state,
116 int property_index,
117 uint64_t value,
118 void *display);
119
120 /**
121 * get_property - get property value
122 * @connector: Pointer to drm connector structure
123 * @state: Pointer to drm connector state structure
124 * @property_index: DRM property index
125 * @value: Pointer to variable for accepting property value
126 * @display: Pointer to private display structure
127 * Returns: Zero on success
128 */
129 int (*get_property)(struct drm_connector *connector,
130 struct drm_connector_state *state,
131 int property_index,
132 uint64_t *value,
133 void *display);
Clarence Ipcb3afd42016-07-15 16:25:34 -0400134
135 /**
136 * get_info - get display information
137 * @info: Pointer to msm display info structure
138 * @display: Pointer to private display structure
139 * Returns: Zero on success
140 */
141 int (*get_info)(struct msm_display_info *info, void *display);
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530142
Clarence Ipa18d4832017-03-13 12:35:44 -0700143 /**
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700144 * get_mode_info - retrieve mode information
Jeykumar Sankaran6b345ac2017-03-15 19:17:19 -0700145 * @drm_mode: Display mode set for the display
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700146 * @mode_info: Out parameter. information of the display mode
Jeykumar Sankaran6b345ac2017-03-15 19:17:19 -0700147 * @max_mixer_width: max width supported by HW layer mixer
Alan Kwongb1bca602017-09-18 17:28:45 -0400148 * @display: Pointer to private display structure
Jeykumar Sankaran6b345ac2017-03-15 19:17:19 -0700149 * Returns: Zero on success
150 */
Jeykumar Sankaran446a5f12017-05-09 20:30:39 -0700151 int (*get_mode_info)(const struct drm_display_mode *drm_mode,
152 struct msm_mode_info *mode_info,
Alan Kwongb1bca602017-09-18 17:28:45 -0400153 u32 max_mixer_width, void *display);
Jeykumar Sankaran6b345ac2017-03-15 19:17:19 -0700154
155 /**
Clarence Ipa18d4832017-03-13 12:35:44 -0700156 * enable_event - notify display of event registration/unregistration
157 * @connector: Pointer to drm connector structure
158 * @event_idx: SDE connector event index
159 * @enable: Whether the event is being enabled/disabled
160 * @display: Pointer to private display structure
161 */
162 void (*enable_event)(struct drm_connector *connector,
163 uint32_t event_idx, bool enable, void *display);
164
Vishnuvardhan Prodduturi75b96802016-10-17 18:45:55 +0530165 int (*set_backlight)(void *display, u32 bl_lvl);
Lloyd Atkinson8c49c582016-11-18 14:23:54 -0500166
167 /**
168 * soft_reset - perform a soft reset on the connector
169 * @display: Pointer to private display structure
170 * Return: Zero on success, -ERROR otherwise
171 */
172 int (*soft_reset)(void *display);
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500173
174 /**
175 * pre_kickoff - trigger display to program kickoff-time features
176 * @connector: Pointer to drm connector structure
177 * @display: Pointer to private display structure
178 * @params: Parameter bundle of connector-stored information for
179 * kickoff-time programming into the display
180 * Returns: Zero on success
181 */
182 int (*pre_kickoff)(struct drm_connector *connector,
183 void *display,
184 struct msm_display_kickoff_params *params);
Veera Sundaram Sankaranbb2bf9a2017-03-29 18:56:47 -0700185
186 /**
Chirag Khuranace2aa512019-11-20 18:27:03 +0530187 * mode_needs_full_range - does the mode need full range
188 * quantization
189 * @display: Pointer to private display structure
190 * Returns: true or false based on whether full range is needed
191 */
192 bool (*mode_needs_full_range)(void *display);
193
194 /**
Veera Sundaram Sankaranbb2bf9a2017-03-29 18:56:47 -0700195 * clk_ctrl - perform clk enable/disable on the connector
196 * @handle: Pointer to clk handle
197 * @type: Type of clks
198 * @enable: State of clks
199 */
200 int (*clk_ctrl)(void *handle, u32 type, u32 state);
Narender Ankam1afbd172020-03-16 17:27:44 +0530201 /**
202 * get_csc_type - returns the CSC type to be used
203 * by the CDM block based on HDR state
204 * @connector: Pointer to drm connector structure
205 * @display: Pointer to private display structure
206 * Returns: type of CSC matrix to be used
207 */
208 enum sde_csc_type (*get_csc_type)(struct drm_connector *connector,
209 void *display);
Clarence Ip90b282d2017-05-04 10:00:32 -0700210
211 /**
212 * set_power - update dpms setting
213 * @connector: Pointer to drm connector structure
214 * @power_mode: One of the following,
215 * SDE_MODE_DPMS_ON
216 * SDE_MODE_DPMS_LP1
217 * SDE_MODE_DPMS_LP2
218 * SDE_MODE_DPMS_OFF
219 * @display: Pointer to private display structure
220 * Returns: Zero on success
221 */
222 int (*set_power)(struct drm_connector *connector,
223 int power_mode, void *display);
Ping Li8430ee12017-02-24 14:14:44 -0800224
225 /**
226 * get_dst_format - get dst_format from display
227 * @display: Pointer to private display handle
228 * Returns: dst_format of display
229 */
230 enum dsi_pixel_format (*get_dst_format)(void *display);
Raviteja Tamatam68892de2017-06-20 04:47:19 +0530231
232 /**
233 * post_kickoff - display to program post kickoff-time features
234 * @connector: Pointer to drm connector structure
235 * Returns: Zero on success
236 */
237 int (*post_kickoff)(struct drm_connector *connector);
238
Padmanabhan Komanduru71aec2d2017-08-30 20:07:59 +0530239 /**
Ajay Singh Parmar315e5852017-11-23 21:47:32 -0800240 * post_open - calls connector to process post open functionalities
Padmanabhan Komanduru71aec2d2017-08-30 20:07:59 +0530241 * @display: Pointer to private display structure
242 */
Ajay Singh Parmar315e5852017-11-23 21:47:32 -0800243 void (*post_open)(void *display);
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530244
245 /**
246 * check_status - check status of connected display panel
247 * @display: Pointer to private display handle
Sandeep Panda979009e2018-02-13 17:58:05 +0530248 * @te_check_override: Whether check TE from panel or default check
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530249 * Returns: positive value for success, negetive or zero for failure
250 */
Sandeep Panda979009e2018-02-13 17:58:05 +0530251 int (*check_status)(void *display, bool te_check_override);
Govinda Rajulu Chennab95b9c32017-10-13 15:00:32 -0400252
253 /**
254 * cmd_transfer - Transfer command to the connected display panel
255 * @display: Pointer to private display handle
256 * @cmd_buf: Command buffer
257 * @cmd_buf_len: Command buffer length in bytes
258 * Returns: Zero for success, negetive for failure
259 */
260 int (*cmd_transfer)(void *display, const char *cmd_buf,
261 u32 cmd_buf_len);
Ajay Singh Parmar87af50b2017-12-22 22:22:55 -0800262
263 /**
264 * config_hdr - configure HDR
265 * @display: Pointer to private display handle
266 * @c_state: Pointer to connector state
267 * Returns: Zero on success, negative error code for failures
268 */
269 int (*config_hdr)(void *display,
270 struct sde_connector_state *c_state);
271
Sandeep Panda8693e8f2018-03-08 08:16:44 +0530272 /**
273 * cont_splash_config - initialize splash resources
274 * @display: Pointer to private display handle
275 * Returns: zero for success, negetive for failure
276 */
277 int (*cont_splash_config)(void *display);
Kalyan Thota6a9f3b72018-01-18 18:00:02 +0530278
279 /**
280 * get_panel_vfp - returns original panel vfp
281 * @display: Pointer to private display handle
282 * @h_active: width
283 * @v_active: height
284 * Returns: v_front_porch on success error-code on failure
285 */
286 int (*get_panel_vfp)(void *display, int h_active, int v_active);
Clarence Ipdd8021c2016-07-20 16:39:47 -0400287};
288
289/**
Clarence Ipa18d4832017-03-13 12:35:44 -0700290 * enum sde_connector_events - list of recognized connector events
291 */
292enum sde_connector_events {
293 SDE_CONN_EVENT_VID_DONE, /* video mode frame done */
294 SDE_CONN_EVENT_CMD_DONE, /* command mode frame done */
Sandeep Panda11b20d82017-06-19 12:57:27 +0530295 SDE_CONN_EVENT_VID_FIFO_OVERFLOW, /* dsi fifo overflow error */
296 SDE_CONN_EVENT_CMD_FIFO_UNDERFLOW, /* dsi fifo underflow error */
Clarence Ipa18d4832017-03-13 12:35:44 -0700297 SDE_CONN_EVENT_COUNT,
298};
299
300/**
301 * struct sde_connector_evt - local event registration entry structure
302 * @cb_func: Pointer to desired callback function
303 * @usr: User pointer to pass to callback on event trigger
Sandeep Panda11b20d82017-06-19 12:57:27 +0530304 * Returns: Zero success, negetive for failure
Clarence Ipa18d4832017-03-13 12:35:44 -0700305 */
306struct sde_connector_evt {
Sandeep Panda11b20d82017-06-19 12:57:27 +0530307 int (*cb_func)(uint32_t event_idx,
Clarence Ipa18d4832017-03-13 12:35:44 -0700308 uint32_t instance_idx, void *usr,
309 uint32_t data0, uint32_t data1,
310 uint32_t data2, uint32_t data3);
311 void *usr;
312};
313
314/**
Clarence Ipdd8021c2016-07-20 16:39:47 -0400315 * struct sde_connector - local sde connector structure
316 * @base: Base drm connector structure
317 * @connector_type: Set to one of DRM_MODE_CONNECTOR_ types
318 * @encoder: Pointer to preferred drm encoder
319 * @panel: Pointer to drm panel, if present
320 * @display: Pointer to private display data structure
Alan Kwongdfa8c082016-07-29 04:10:00 -0400321 * @mmu_secure: MMU id for secure buffers
322 * @mmu_unsecure: MMU id for unsecure buffers
Clarence Ipdd8021c2016-07-20 16:39:47 -0400323 * @name: ASCII name of connector
Clarence Ip90b282d2017-05-04 10:00:32 -0700324 * @lock: Mutex lock object for this structure
Dhaval Patel39323d42017-03-01 23:48:24 -0800325 * @retire_fence: Retire fence context reference
Clarence Ipdd8021c2016-07-20 16:39:47 -0400326 * @ops: Local callback function pointer table
Clarence Ip90b282d2017-05-04 10:00:32 -0700327 * @dpms_mode: DPMS property setting from user space
328 * @lp_mode: LP property setting from user space
329 * @last_panel_power_mode: Last consolidated dpms/lp mode setting
Clarence Ipdd8021c2016-07-20 16:39:47 -0400330 * @property_info: Private structure for generic property handling
331 * @property_data: Array of private data for generic property handling
Dhaval Patel4e574842016-08-23 15:11:37 -0700332 * @blob_caps: Pointer to blob structure for 'capabilities' property
Ping Li898b1bf2017-02-09 18:03:28 -0800333 * @blob_hdr: Pointer to blob structure for 'hdr_properties' property
Ajay Singh Parmare927aa42017-11-01 00:33:20 -0700334 * @blob_ext_hdr: Pointer to blob structure for 'ext_hdr_properties' property
Ping Li8430ee12017-02-24 14:14:44 -0800335 * @blob_dither: Pointer to blob structure for default dither config
Jeykumar Sankaran83ddcb02017-10-27 11:34:50 -0700336 * @blob_mode_info: Pointer to blob structure for mode info
Alan Kwong578cdaf2017-01-28 17:25:43 -0800337 * @fb_kmap: true if kernel mapping of framebuffer is requested
Clarence Ipa18d4832017-03-13 12:35:44 -0700338 * @event_table: Array of registered events
339 * @event_lock: Lock object for event_table
Dhaval Patel959fdab2017-08-25 15:15:39 -0700340 * @bl_device: backlight device node
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530341 * @status_work: work object to perform status checks
Sandeep Pandaf2274d12017-09-08 19:52:33 +0530342 * @force_panel_dead: variable to trigger forced ESD recovery
Jayant Shekhar2c95cfe2018-03-09 11:14:39 +0530343 * @esd_status_interval: variable to change ESD check interval in millisec
Sandeep Panda9eee1932018-04-25 11:25:42 +0530344 * @panel_dead: Flag to indicate if panel has gone bad
345 * @esd_status_check: Flag to indicate if ESD thread is scheduled or not
Xu Yang92377312017-11-23 13:48:08 +0800346 * @bl_scale_dirty: Flag to indicate PP BL scale value(s) is changed
347 * @bl_scale: BL scale value for ABA feature
348 * @bl_scale_ad: BL scale value for AD feature
Tharun Raj Soma87208052018-05-18 20:52:10 +0530349 * @unset_bl_level: BL level that needs to be set later
350 * @allow_bl_update: Flag to indicate if BL update is allowed currently or not
351 * @last_cmd_tx_sts: status of the last command transfer
Clarence Ipdd8021c2016-07-20 16:39:47 -0400352 */
353struct sde_connector {
354 struct drm_connector base;
355
356 int connector_type;
357
358 struct drm_encoder *encoder;
359 struct drm_panel *panel;
360 void *display;
361
Jordan Croused8e96522017-02-13 10:14:16 -0700362 struct msm_gem_address_space *aspace[SDE_IOMMU_DOMAIN_MAX];
Clarence Ipdd8021c2016-07-20 16:39:47 -0400363
364 char name[SDE_CONNECTOR_NAME_SIZE];
365
Clarence Ip90b282d2017-05-04 10:00:32 -0700366 struct mutex lock;
Dhaval Patel39323d42017-03-01 23:48:24 -0800367 struct sde_fence_context retire_fence;
Clarence Ipdd8021c2016-07-20 16:39:47 -0400368 struct sde_connector_ops ops;
Clarence Ip90b282d2017-05-04 10:00:32 -0700369 int dpms_mode;
370 int lp_mode;
371 int last_panel_power_mode;
Clarence Ipdd8021c2016-07-20 16:39:47 -0400372
373 struct msm_property_info property_info;
374 struct msm_property_data property_data[CONNECTOR_PROP_COUNT];
Dhaval Patel4e574842016-08-23 15:11:37 -0700375 struct drm_property_blob *blob_caps;
Ping Li898b1bf2017-02-09 18:03:28 -0800376 struct drm_property_blob *blob_hdr;
Srikanth Rajagopalan30384d12017-06-08 15:23:31 -0700377 struct drm_property_blob *blob_ext_hdr;
Ping Li8430ee12017-02-24 14:14:44 -0800378 struct drm_property_blob *blob_dither;
Jeykumar Sankaran83ddcb02017-10-27 11:34:50 -0700379 struct drm_property_blob *blob_mode_info;
Alan Kwong578cdaf2017-01-28 17:25:43 -0800380
381 bool fb_kmap;
Clarence Ipa18d4832017-03-13 12:35:44 -0700382 struct sde_connector_evt event_table[SDE_CONN_EVENT_COUNT];
383 spinlock_t event_lock;
Dhaval Patel959fdab2017-08-25 15:15:39 -0700384
385 struct backlight_device *bl_device;
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530386 struct delayed_work status_work;
Sandeep Pandaf2274d12017-09-08 19:52:33 +0530387 u32 force_panel_dead;
Jayant Shekhar2c95cfe2018-03-09 11:14:39 +0530388 u32 esd_status_interval;
Sandeep Panda9eee1932018-04-25 11:25:42 +0530389 bool panel_dead;
Tharun Raj Somaa658c2e2018-03-16 06:14:08 +0530390 bool esd_status_check;
391
Xu Yang92377312017-11-23 13:48:08 +0800392 bool bl_scale_dirty;
393 u32 bl_scale;
394 u32 bl_scale_ad;
Tharun Raj Soma87208052018-05-18 20:52:10 +0530395 u32 unset_bl_level;
396 bool allow_bl_update;
Govinda Rajulu Chennab95b9c32017-10-13 15:00:32 -0400397
398 bool last_cmd_tx_sts;
Clarence Ipdd8021c2016-07-20 16:39:47 -0400399};
400
401/**
402 * to_sde_connector - convert drm_connector pointer to sde connector pointer
403 * @X: Pointer to drm_connector structure
404 * Returns: Pointer to sde_connector structure
405 */
406#define to_sde_connector(x) container_of((x), struct sde_connector, base)
407
408/**
409 * sde_connector_get_display - get sde connector's private display pointer
410 * @C: Pointer to drm connector structure
411 * Returns: Pointer to associated private display structure
412 */
413#define sde_connector_get_display(C) \
Jeykumar Sankaran586d0922017-09-18 15:01:33 -0700414 ((C) ? to_sde_connector((C))->display : NULL)
Clarence Ipdd8021c2016-07-20 16:39:47 -0400415
416/**
417 * sde_connector_get_panel - get sde connector's private panel pointer
418 * @C: Pointer to drm connector structure
419 * Returns: Pointer to associated private display structure
420 */
421#define sde_connector_get_panel(C) \
Ajay Singh Parmar0d6250b2017-04-02 14:08:51 -0700422 ((C) ? to_sde_connector((C))->panel : NULL)
Clarence Ipdd8021c2016-07-20 16:39:47 -0400423
424/**
425 * sde_connector_get_encoder - get sde connector's private encoder pointer
426 * @C: Pointer to drm connector structure
427 * Returns: Pointer to associated private encoder structure
428 */
429#define sde_connector_get_encoder(C) \
Jeykumar Sankaran586d0922017-09-18 15:01:33 -0700430 ((C) ? to_sde_connector((C))->encoder : NULL)
Clarence Ipdd8021c2016-07-20 16:39:47 -0400431
432/**
433 * sde_connector_get_propinfo - get sde connector's property info pointer
434 * @C: Pointer to drm connector structure
435 * Returns: Pointer to associated private property info structure
436 */
437#define sde_connector_get_propinfo(C) \
Jeykumar Sankaran586d0922017-09-18 15:01:33 -0700438 ((C) ? &to_sde_connector((C))->property_info : NULL)
Clarence Ipdd8021c2016-07-20 16:39:47 -0400439
440/**
441 * struct sde_connector_state - private connector status structure
442 * @base: Base drm connector structure
443 * @out_fb: Pointer to output frame buffer, if applicable
Clarence Ip4a2955d2017-07-04 18:04:33 -0400444 * @property_state: Local storage for msm_prop properties
Clarence Ipdd8021c2016-07-20 16:39:47 -0400445 * @property_values: Local cache of current connector property values
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500446 * @rois: Regions of interest structure for mapping CRTC to Connector output
Ping Li8430ee12017-02-24 14:14:44 -0800447 * @property_blobs: blob properties
Jeykumar Sankaran905ba332017-10-19 10:45:02 -0700448 * @mode_info: local copy of msm_mode_info struct
Ajay Singh Parmare927aa42017-11-01 00:33:20 -0700449 * @hdr_meta: HDR metadata info passed from userspace
Lloyd Atkinson4ced69e2017-11-03 12:16:09 -0400450 * @old_topology_name: topology of previous atomic state. remove this in later
451 * kernel versions which provide drm_atomic_state old_state pointers
Clarence Ipdd8021c2016-07-20 16:39:47 -0400452 */
453struct sde_connector_state {
454 struct drm_connector_state base;
455 struct drm_framebuffer *out_fb;
Clarence Ip4a2955d2017-07-04 18:04:33 -0400456 struct msm_property_state property_state;
457 struct msm_property_value property_values[CONNECTOR_PROP_COUNT];
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500458
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400459 struct msm_roi_list rois;
Ping Li8430ee12017-02-24 14:14:44 -0800460 struct drm_property_blob *property_blobs[CONNECTOR_PROP_BLOBCOUNT];
Jeykumar Sankaran905ba332017-10-19 10:45:02 -0700461 struct msm_mode_info mode_info;
Ajay Singh Parmare927aa42017-11-01 00:33:20 -0700462 struct drm_msm_ext_hdr_metadata hdr_meta;
Lloyd Atkinson4ced69e2017-11-03 12:16:09 -0400463 enum sde_rm_topology_name old_topology_name;
Clarence Ipdd8021c2016-07-20 16:39:47 -0400464};
465
466/**
467 * to_sde_connector_state - convert drm_connector_state pointer to
468 * sde connector state pointer
469 * @X: Pointer to drm_connector_state structure
470 * Returns: Pointer to sde_connector_state structure
471 */
472#define to_sde_connector_state(x) \
473 container_of((x), struct sde_connector_state, base)
474
475/**
476 * sde_connector_get_property - query integer value of connector property
477 * @S: Pointer to drm connector state
478 * @X: Property index, from enum msm_mdp_connector_property
479 * Returns: Integer value of requested property
480 */
481#define sde_connector_get_property(S, X) \
482 ((S) && ((X) < CONNECTOR_PROP_COUNT) ? \
Clarence Ip4a2955d2017-07-04 18:04:33 -0400483 (to_sde_connector_state((S))->property_values[(X)].value) : 0)
Clarence Ipdd8021c2016-07-20 16:39:47 -0400484
485/**
Clarence Ip4a2955d2017-07-04 18:04:33 -0400486 * sde_connector_get_property_state - retrieve property state cache
Lloyd Atkinson13cee812016-08-16 16:10:31 -0400487 * @S: Pointer to drm connector state
Clarence Ip4a2955d2017-07-04 18:04:33 -0400488 * Returns: Pointer to local property state structure
Lloyd Atkinson13cee812016-08-16 16:10:31 -0400489 */
Clarence Ip4a2955d2017-07-04 18:04:33 -0400490#define sde_connector_get_property_state(S) \
491 ((S) ? (&to_sde_connector_state((S))->property_state) : NULL)
Lloyd Atkinson13cee812016-08-16 16:10:31 -0400492
493/**
Clarence Ipdd8021c2016-07-20 16:39:47 -0400494 * sde_connector_get_out_fb - query out_fb value from sde connector state
495 * @S: Pointer to drm connector state
496 * Returns: Output fb associated with specified connector state
497 */
498#define sde_connector_get_out_fb(S) \
499 ((S) ? to_sde_connector_state((S))->out_fb : 0)
500
501/**
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400502 * sde_connector_get_topology_name - helper accessor to retrieve topology_name
503 * @connector: pointer to drm connector
504 * Returns: value of the CONNECTOR_PROP_TOPOLOGY_NAME property or 0
505 */
506static inline uint64_t sde_connector_get_topology_name(
507 struct drm_connector *connector)
508{
509 if (!connector || !connector->state)
510 return 0;
511 return sde_connector_get_property(connector->state,
512 CONNECTOR_PROP_TOPOLOGY_NAME);
513}
514
515/**
Lloyd Atkinson4ced69e2017-11-03 12:16:09 -0400516 * sde_connector_get_old_topology_name - helper accessor to retrieve
517 * topology_name for the previous mode
518 * @connector: pointer to drm connector state
519 * Returns: cached value of the previous topology, or SDE_RM_TOPOLOGY_NONE
520 */
521static inline enum sde_rm_topology_name sde_connector_get_old_topology_name(
522 struct drm_connector_state *state)
523{
524 struct sde_connector_state *c_state = to_sde_connector_state(state);
525
526 if (!state)
527 return SDE_RM_TOPOLOGY_NONE;
528
529 return c_state->old_topology_name;
530}
531
532/**
533 * sde_connector_set_old_topology_name - helper to cache value of previous
534 * mode's topology
535 * @connector: pointer to drm connector state
536 * Returns: 0 on success, negative errno on failure
537 */
538static inline int sde_connector_set_old_topology_name(
539 struct drm_connector_state *state,
540 enum sde_rm_topology_name top)
541{
542 struct sde_connector_state *c_state = to_sde_connector_state(state);
543
544 if (!state)
545 return -EINVAL;
546
547 c_state->old_topology_name = top;
548
549 return 0;
550}
551
552/**
Clarence Ip89628132017-07-27 13:33:51 -0400553 * sde_connector_get_lp - helper accessor to retrieve LP state
554 * @connector: pointer to drm connector
555 * Returns: value of the CONNECTOR_PROP_LP property or 0
556 */
557static inline uint64_t sde_connector_get_lp(
558 struct drm_connector *connector)
559{
560 if (!connector || !connector->state)
561 return 0;
562 return sde_connector_get_property(connector->state,
563 CONNECTOR_PROP_LP);
564}
565
566/**
Clarence Ipd86f6e42017-08-08 18:31:00 -0400567 * sde_connector_set_property_for_commit - add property set to atomic state
568 * Add a connector state property update for the specified property index
569 * to the atomic state in preparation for a drm_atomic_commit.
570 * @connector: Pointer to drm connector
571 * @atomic_state: Pointer to DRM atomic state structure for commit
572 * @property_idx: Connector property index
573 * @value: Updated property value
574 * Returns: Zero on success
575 */
576int sde_connector_set_property_for_commit(struct drm_connector *connector,
577 struct drm_atomic_state *atomic_state,
578 uint32_t property_idx, uint64_t value);
579
580/**
Clarence Ipdd8021c2016-07-20 16:39:47 -0400581 * sde_connector_init - create drm connector object for a given display
582 * @dev: Pointer to drm device struct
583 * @encoder: Pointer to associated encoder
584 * @panel: Pointer to associated panel, can be NULL
585 * @display: Pointer to associated display object
586 * @ops: Pointer to callback operations function table
587 * @connector_poll: Set to appropriate DRM_CONNECTOR_POLL_ setting
588 * @connector_type: Set to appropriate DRM_MODE_CONNECTOR_ type
589 * Returns: Pointer to newly created drm connector struct
590 */
591struct drm_connector *sde_connector_init(struct drm_device *dev,
592 struct drm_encoder *encoder,
593 struct drm_panel *panel,
594 void *display,
595 const struct sde_connector_ops *ops,
596 int connector_poll,
597 int connector_type);
598
Clarence Ipe59fb3f2016-07-26 13:39:59 -0400599/**
600 * sde_connector_prepare_fence - prepare fence support for current commit
601 * @connector: Pointer to drm connector object
602 */
603void sde_connector_prepare_fence(struct drm_connector *connector);
604
605/**
606 * sde_connector_complete_commit - signal completion of current commit
607 * @connector: Pointer to drm connector object
Veera Sundaram Sankaran675ff622017-06-21 21:44:46 -0700608 * @ts: timestamp to be updated in the fence signalling
Prabhanjan Kandula33151182018-03-28 11:44:09 -0700609 * @fence_event: enum value to indicate nature of fence event
Clarence Ipe59fb3f2016-07-26 13:39:59 -0400610 */
Prabhanjan Kandula33151182018-03-28 11:44:09 -0700611void sde_connector_complete_commit(struct drm_connector *connector,
612 ktime_t ts, enum sde_fence_event fence_event);
Clarence Ipe59fb3f2016-07-26 13:39:59 -0400613
Clarence Ipcb3afd42016-07-15 16:25:34 -0400614/**
Dhaval Patelfd8f7742017-08-10 13:11:22 -0700615 * sde_connector_commit_reset - reset the completion signal
616 * @connector: Pointer to drm connector object
617 * @ts: timestamp to be updated in the fence signalling
618 */
619void sde_connector_commit_reset(struct drm_connector *connector, ktime_t ts);
620
621/**
Clarence Ipcb3afd42016-07-15 16:25:34 -0400622 * sde_connector_get_info - query display specific information
623 * @connector: Pointer to drm connector object
624 * @info: Pointer to msm display information structure
625 * Returns: Zero on success
626 */
627int sde_connector_get_info(struct drm_connector *connector,
628 struct msm_display_info *info);
629
Clarence Ipa18d4832017-03-13 12:35:44 -0700630/**
Veera Sundaram Sankaranbb2bf9a2017-03-29 18:56:47 -0700631 * sde_connector_clk_ctrl - enables/disables the connector clks
632 * @connector: Pointer to drm connector object
633 * @enable: true/false to enable/disable
Alan Kwong1124f1f2017-11-10 18:14:39 -0500634 * Returns: Zero on success
Veera Sundaram Sankaranbb2bf9a2017-03-29 18:56:47 -0700635 */
Alan Kwong1124f1f2017-11-10 18:14:39 -0500636int sde_connector_clk_ctrl(struct drm_connector *connector, bool enable);
Veera Sundaram Sankaranbb2bf9a2017-03-29 18:56:47 -0700637
638/**
Clarence Ip90b282d2017-05-04 10:00:32 -0700639 * sde_connector_get_dpms - query dpms setting
640 * @connector: Pointer to drm connector structure
641 * Returns: Current DPMS setting for connector
642 */
643int sde_connector_get_dpms(struct drm_connector *connector);
644
645/**
Clarence Ipa18d4832017-03-13 12:35:44 -0700646 * sde_connector_trigger_event - indicate that an event has occurred
647 * Any callbacks that have been registered against this event will
648 * be called from the same thread context.
649 * @connector: Pointer to drm connector structure
650 * @event_idx: Index of event to trigger
651 * @instance_idx: Event-specific "instance index" to pass to callback
652 * @data0: Event-specific "data" to pass to callback
653 * @data1: Event-specific "data" to pass to callback
654 * @data2: Event-specific "data" to pass to callback
655 * @data3: Event-specific "data" to pass to callback
656 * Returns: Zero on success
657 */
658int sde_connector_trigger_event(void *drm_connector,
659 uint32_t event_idx, uint32_t instance_idx,
660 uint32_t data0, uint32_t data1,
661 uint32_t data2, uint32_t data3);
662
663/**
664 * sde_connector_register_event - register a callback function for an event
665 * @connector: Pointer to drm connector structure
666 * @event_idx: Index of event to register
667 * @cb_func: Pointer to desired callback function
668 * @usr: User pointer to pass to callback on event trigger
669 * Returns: Zero on success
670 */
671int sde_connector_register_event(struct drm_connector *connector,
672 uint32_t event_idx,
Sandeep Panda11b20d82017-06-19 12:57:27 +0530673 int (*cb_func)(uint32_t event_idx,
Clarence Ipa18d4832017-03-13 12:35:44 -0700674 uint32_t instance_idx, void *usr,
675 uint32_t data0, uint32_t data1,
676 uint32_t data2, uint32_t data3),
677 void *usr);
678
679/**
680 * sde_connector_unregister_event - unregister all callbacks for an event
681 * @connector: Pointer to drm connector structure
682 * @event_idx: Index of event to register
683 */
684void sde_connector_unregister_event(struct drm_connector *connector,
685 uint32_t event_idx);
686
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700687/**
688 * sde_connector_register_custom_event - register for async events
689 * @kms: Pointer to sde_kms
690 * @conn_drm: Pointer to drm connector object
691 * @event: Event for which request is being sent
692 * @en: Flag to enable/disable the event
693 * Returns: Zero on success
694 */
695int sde_connector_register_custom_event(struct sde_kms *kms,
696 struct drm_connector *conn_drm, u32 event, bool en);
697
Lloyd Atkinson05d75512017-01-17 14:45:51 -0500698/**
699 * sde_connector_pre_kickoff - trigger kickoff time feature programming
700 * @connector: Pointer to drm connector object
701 * Returns: Zero on success
702 */
703int sde_connector_pre_kickoff(struct drm_connector *connector);
704
Dhaval Patel5cb59be2017-04-20 20:00:56 -0700705/**
706 * sde_connector_needs_offset - adjust the output fence offset based on
707 * display type
708 * @connector: Pointer to drm connector object
709 * Returns: true if offset is required, false for all other cases.
710 */
711static inline bool sde_connector_needs_offset(struct drm_connector *connector)
712{
713 struct sde_connector *c_conn;
714
715 if (!connector)
716 return false;
717
718 c_conn = to_sde_connector(connector);
719 return (c_conn->connector_type != DRM_MODE_CONNECTOR_VIRTUAL);
720}
721
Ping Li8430ee12017-02-24 14:14:44 -0800722/**
Chirag Khuranace2aa512019-11-20 18:27:03 +0530723 * sde_connector_mode_needs_full_range - query quantization type
724 * for the connector mode
725 * @connector: Pointer to drm connector object
726 * Returns: true OR false based on connector mode
727 */
728bool sde_connector_mode_needs_full_range(struct drm_connector *connector);
729
730/**
Narender Ankam1afbd172020-03-16 17:27:44 +0530731 * sde_connector_get_csc_type - query csc type
732 * to be used for the connector
733 * @connector: Pointer to drm connector object
734 * Returns: csc type based on connector HDR state
735 */
736enum sde_csc_type sde_connector_get_csc_type(struct drm_connector *conn);
737
738/**
Ping Li8430ee12017-02-24 14:14:44 -0800739 * sde_connector_get_dither_cfg - get dither property data
740 * @conn: Pointer to drm_connector struct
741 * @state: Pointer to drm_connector_state struct
742 * @cfg: Pointer to pointer to dither cfg
743 * @len: length of the dither data
744 * Returns: Zero on success
745 */
746int sde_connector_get_dither_cfg(struct drm_connector *conn,
747 struct drm_connector_state *state, void **cfg, size_t *len);
Clarence Ipdd8021c2016-07-20 16:39:47 -0400748
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530749/**
Jeykumar Sankaran83ddcb02017-10-27 11:34:50 -0700750 * sde_connector_set_blob_data - set connector blob property data
Jeykumar Sankaran736d79d2017-10-05 17:44:24 -0700751 * @conn: Pointer to drm_connector struct
Jeykumar Sankaran905ba332017-10-19 10:45:02 -0700752 * @state: Pointer to the drm_connector_state struct
Jeykumar Sankaran83ddcb02017-10-27 11:34:50 -0700753 * @prop_id: property id to be populated
Jeykumar Sankaran736d79d2017-10-05 17:44:24 -0700754 * Returns: Zero on success
755 */
Jeykumar Sankaran83ddcb02017-10-27 11:34:50 -0700756int sde_connector_set_blob_data(struct drm_connector *conn,
757 struct drm_connector_state *state,
758 enum msm_mdp_conn_property prop_id);
Jeykumar Sankaran736d79d2017-10-05 17:44:24 -0700759
760/**
761 * sde_connector_roi_v1_check_roi - validate connector ROI
762 * @conn_state: Pointer to drm_connector_state struct
763 * Returns: Zero on success
764 */
765int sde_connector_roi_v1_check_roi(struct drm_connector_state *conn_state);
766
767/**
Sandeep Panda98d6ab22017-09-05 08:03:16 +0530768 * sde_connector_schedule_status_work - manage ESD thread
769 * conn: Pointer to drm_connector struct
770 * @en: flag to start/stop ESD thread
771 */
772void sde_connector_schedule_status_work(struct drm_connector *conn, bool en);
773
Lloyd Atkinsone08229c2017-10-02 17:53:30 -0400774/**
775 * sde_connector_helper_reset_properties - reset properties to default values in
776 * the given DRM connector state object
777 * @connector: Pointer to DRM connector object
778 * @connector_state: Pointer to DRM connector state object
779 * Returns: 0 on success, negative errno on failure
780 */
781int sde_connector_helper_reset_custom_properties(
782 struct drm_connector *connector,
783 struct drm_connector_state *connector_state);
784
Jeykumar Sankaran905ba332017-10-19 10:45:02 -0700785/**
786 * sde_connector_get_mode_info - get information of the current mode in the
787 * given connector state.
788 * conn_state: Pointer to the DRM connector state object
789 * mode_info: Pointer to the mode info structure
790 */
791int sde_connector_get_mode_info(struct drm_connector_state *conn_state,
792 struct msm_mode_info *mode_info);
793
Dhaval Patel2a3c37a2017-10-25 12:30:36 -0700794/**
795 * sde_conn_timeline_status - current buffer timeline status
796 * conn: Pointer to drm_connector struct
797 */
798void sde_conn_timeline_status(struct drm_connector *conn);
Clarence Ip458a5d02017-11-27 18:15:16 -0500799
800/**
801 * sde_connector_helper_bridge_disable - helper function for drm bridge disable
802 * @connector: Pointer to DRM connector object
803 */
804void sde_connector_helper_bridge_disable(struct drm_connector *connector);
805
Kalyan Thota6a9f3b72018-01-18 18:00:02 +0530806/**
Sandeep Panda9eee1932018-04-25 11:25:42 +0530807 * sde_connector_helper_bridge_enable - helper function for drm bridge enable
808 * @connector: Pointer to DRM connector object
809 */
810void sde_connector_helper_bridge_enable(struct drm_connector *connector);
811
812/**
Kalyan Thota6a9f3b72018-01-18 18:00:02 +0530813 * sde_connector_get_panel_vfp - helper to get panel vfp
814 * @connector: pointer to drm connector
815 * @h_active: panel width
816 * @v_active: panel heigth
817 * Returns: v_front_porch on success error-code on failure
818 */
819int sde_connector_get_panel_vfp(struct drm_connector *connector,
820 struct drm_display_mode *mode);
Sandeep Panda979009e2018-02-13 17:58:05 +0530821
822/**
823 * sde_connector_esd_status - helper function to check te status
824 * @connector: Pointer to DRM connector object
825 */
826int sde_connector_esd_status(struct drm_connector *connector);
827
Ping Li8430ee12017-02-24 14:14:44 -0800828#endif /* _SDE_CONNECTOR_H_ */