blob: 205ff24954918706249b1c0d9016bc5c3fe02577 [file] [log] [blame]
Jeykumar Sankarance08ec92017-04-14 14:59:55 -07001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Alan Kwongbb27c092016-07-20 16:41:25 -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_WB_H__
14#define __SDE_WB_H__
15
16#include <linux/platform_device.h>
17
18#include "msm_kms.h"
19#include "sde_kms.h"
Alan Kwong83285fb2016-10-21 20:51:17 -040020#include "sde_connector.h"
Alan Kwongbb27c092016-07-20 16:41:25 -040021
22/**
23 * struct sde_wb_device - Writeback device context
24 * @drm_dev: Pointer to controlling DRM device
25 * @index: Index of hardware instance from device tree
26 * @wb_idx: Writeback identifier of enum sde_wb
27 * @wb_cfg: Writeback configuration catalog
28 * @name: Name of writeback device from device tree
29 * @display_type: Display type from device tree
30 * @wb_list List of all writeback devices
31 * @wb_lock Serialization lock for writeback context structure
32 * @connector: Connector associated with writeback device
33 * @encoder: Encoder associated with writeback device
Jeykumar Sankarance08ec92017-04-14 14:59:55 -070034 * @max_mixer_width: Max width supported by SDE LM HW block
Alan Kwongbb27c092016-07-20 16:41:25 -040035 * @count_modes: Length of writeback connector modes array
36 * @modes: Writeback connector modes array
37 */
38struct sde_wb_device {
39 struct drm_device *drm_dev;
40
41 u32 index;
42 u32 wb_idx;
43 struct sde_wb_cfg *wb_cfg;
44 const char *name;
45
46 struct list_head wb_list;
47 struct mutex wb_lock;
48
49 struct drm_connector *connector;
50 struct drm_encoder *encoder;
51
52 enum drm_connector_status detect_status;
Jeykumar Sankarance08ec92017-04-14 14:59:55 -070053 u32 max_mixer_width;
54
Alan Kwongbb27c092016-07-20 16:41:25 -040055 u32 count_modes;
56 struct drm_mode_modeinfo *modes;
57};
58
59/**
60 * sde_wb_get_index - get device index of the given writeback device
61 * @wb_dev: Pointer to writeback device
62 * Returns: Index of hardware instance
63 */
64static inline
65int sde_wb_get_index(struct sde_wb_device *wb_dev)
66{
67 return wb_dev ? wb_dev->index : -1;
68}
69
70#ifdef CONFIG_DRM_SDE_WB
71/**
72 * sde_wb_get_output_fb - get framebuffer in current atomic state
73 * @wb_dev: Pointer to writeback device
74 * Returns: Pointer to framebuffer
75 */
76struct drm_framebuffer *sde_wb_get_output_fb(struct sde_wb_device *wb_dev);
77
78/**
79 * sde_wb_get_output_roi - get region-of-interest in current atomic state
80 * @wb_dev: Pointer to writeback device
81 * @roi: Pointer to region of interest
82 * Returns: 0 if success; error code otherwise
83 */
84int sde_wb_get_output_roi(struct sde_wb_device *wb_dev, struct sde_rect *roi);
85
86/**
87 * sde_wb_get_num_of_displays - get total number of writeback devices
88 * Returns: Number of writeback devices
89 */
90u32 sde_wb_get_num_of_displays(void);
91
92/**
93 * wb_display_get_displays - returns pointers for supported display devices
94 * @display_array: Pointer to display array to be filled
95 * @max_display_count: Size of display_array
96 * @Returns: Number of display entries filled
97 */
98int wb_display_get_displays(void **display_array, u32 max_display_count);
99
Clarence Ip3649f8b2016-10-31 09:59:44 -0400100void sde_wb_set_active_state(struct sde_wb_device *wb_dev, bool is_active);
101bool sde_wb_is_active(struct sde_wb_device *wb_dev);
Alan Kwongbb27c092016-07-20 16:41:25 -0400102
103/**
104 * sde_wb_drm_init - perform DRM initialization
105 * @wb_dev: Pointer to writeback device
106 * @encoder: Pointer to associated encoder
107 * Returns: 0 if success; error code otherwise
108 */
109int sde_wb_drm_init(struct sde_wb_device *wb_dev, struct drm_encoder *encoder);
110
111/**
112 * sde_wb_drm_deinit - perform DRM de-initialization
113 * @wb_dev: Pointer to writeback device
114 * Returns: 0 if success; error code otherwise
115 */
116int sde_wb_drm_deinit(struct sde_wb_device *wb_dev);
117
118/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400119 * sde_wb_config - setup connection status and available drm modes of the
120 * given writeback connector
121 * @drm_dev: Pointer to DRM device
122 * @data: Pointer to writeback configuration
123 * @file_priv: Pointer file private data
124 * Returns: 0 if success; error code otherwise
125 *
126 * This function will initiate hot-plug detection event.
127 */
128int sde_wb_config(struct drm_device *drm_dev, void *data,
129 struct drm_file *file_priv);
130
131/**
132 * sde_wb_connector_post_init - perform writeback specific initialization
133 * @connector: Pointer to drm connector structure
134 * @info: Pointer to connector info
135 * @display: Pointer to private display structure
136 * Returns: Zero on success
137 */
138int sde_wb_connector_post_init(struct drm_connector *connector,
139 void *info,
140 void *display);
141
142/**
143 * sde_wb_connector_detect - perform writeback connection status detection
144 * @connector: Pointer to connector
145 * @force: Indicate force detection
146 * @display: Pointer to writeback device
147 * Returns: connector status
148 */
149enum drm_connector_status
150sde_wb_connector_detect(struct drm_connector *connector,
151 bool force,
152 void *display);
153
154/**
155 * sde_wb_connector_get_modes - get display modes of connector
156 * @connector: Pointer to connector
157 * @display: Pointer to writeback device
158 * Returns: Number of modes
159 *
160 * If display modes are not specified in writeback configuration IOCTL, this
161 * function will install default EDID modes up to maximum resolution support.
162 */
163int sde_wb_connector_get_modes(struct drm_connector *connector, void *display);
164
165/**
166 * sde_wb_connector_set_property - set atomic connector property
167 * @connector: Pointer to drm connector structure
168 * @state: Pointer to drm connector state structure
169 * @property_index: DRM property index
170 * @value: Incoming property value
171 * @display: Pointer to private display structure
172 * Returns: Zero on success
173 */
174int sde_wb_connector_set_property(struct drm_connector *connector,
175 struct drm_connector_state *state,
176 int property_index,
177 uint64_t value,
178 void *display);
179
180/**
181 * sde_wb_get_info - retrieve writeback 'display' information
182 * @info: Pointer to display info structure
183 * @display: Pointer to private display structure
184 * Returns: Zero on success
185 */
186int sde_wb_get_info(struct msm_display_info *info, void *display);
187
188/**
Jeykumar Sankarance08ec92017-04-14 14:59:55 -0700189 * sde_wb_get_topology - retrieve current topology for the mode selected
190 * @drm_mode: Display mode set for the display
191 * @topology: Out parameter. Topology for the mode.
192 * @max_mixer_width: max width supported by HW layer mixer
193 * Returns: zero on success
194 */
195int sde_wb_get_topology(const struct drm_display_mode *drm_mode,
196 struct msm_display_topology *topology,
197 u32 max_mixer_width);
198
199/**
Alan Kwongbb27c092016-07-20 16:41:25 -0400200 * sde_wb_connector_get_wb - retrieve writeback device of the given connector
201 * @connector: Pointer to drm connector
202 * Returns: Pointer to writeback device on success; NULL otherwise
203 */
204static inline
205struct sde_wb_device *sde_wb_connector_get_wb(struct drm_connector *connector)
206{
207 if (!connector ||
208 (connector->connector_type != DRM_MODE_CONNECTOR_VIRTUAL)) {
209 SDE_ERROR("invalid params\n");
210 return NULL;
211 }
212
213 return sde_connector_get_display(connector);
214}
215
216/**
217 * sde_wb_connector_state_get_output_fb - get framebuffer of given state
218 * @state: Pointer to connector state
219 * Returns: Pointer to framebuffer
220 */
221struct drm_framebuffer *
222sde_wb_connector_state_get_output_fb(struct drm_connector_state *state);
223
224/**
225 * sde_wb_connector_state_get_output_roi - get roi from given atomic state
226 * @state: Pointer to atomic state
227 * @roi: Pointer to region of interest
228 * Returns: 0 if success; error code otherwise
229 */
230int sde_wb_connector_state_get_output_roi(struct drm_connector_state *state,
231 struct sde_rect *roi);
232
233#else
234static inline
235struct drm_framebuffer *sde_wb_get_output_fb(struct sde_wb_device *wb_dev)
236{
237 return NULL;
238}
239static inline
240int sde_wb_get_output_roi(struct sde_wb_device *wb_dev, struct sde_rect *roi)
241{
242 return 0;
243}
244static inline
245u32 sde_wb_get_num_of_displays(void)
246{
247 return 0;
248}
249static inline
250int wb_display_get_displays(void **display_array, u32 max_display_count)
251{
252 return 0;
253}
254static inline
Clarence Ip3649f8b2016-10-31 09:59:44 -0400255void sde_wb_set_active_state(struct sde_wb_device *wb_dev, bool is_active)
Alan Kwongbb27c092016-07-20 16:41:25 -0400256{
Alan Kwongbb27c092016-07-20 16:41:25 -0400257}
258static inline
Clarence Ip3649f8b2016-10-31 09:59:44 -0400259bool sde_wb_is_active(struct sde_wb_device *wb_dev)
Alan Kwongbb27c092016-07-20 16:41:25 -0400260{
Clarence Ip3649f8b2016-10-31 09:59:44 -0400261 return false;
Alan Kwongbb27c092016-07-20 16:41:25 -0400262}
263static inline
264int sde_wb_drm_init(struct sde_wb_device *wb_dev, struct drm_encoder *encoder)
265{
266 return 0;
267}
268static inline
269int sde_wb_drm_deinit(struct sde_wb_device *wb_dev)
270{
271 return 0;
272}
273static inline
Alan Kwongbb27c092016-07-20 16:41:25 -0400274int sde_wb_config(struct drm_device *drm_dev, void *data,
275 struct drm_file *file_priv)
276{
277 return 0;
278}
279static inline
280int sde_wb_connector_post_init(struct drm_connector *connector,
281 void *info,
282 void *display)
283{
284 return 0;
285}
286static inline
287enum drm_connector_status
288sde_wb_connector_detect(struct drm_connector *connector,
289 bool force,
290 void *display)
291{
292 return connector_status_disconnected;
293}
294static inline
295int sde_wb_connector_get_modes(struct drm_connector *connector, void *display)
296{
297 return -EINVAL;
298}
299static inline
300int sde_wb_connector_set_property(struct drm_connector *connector,
301 struct drm_connector_state *state,
302 int property_index,
303 uint64_t value,
304 void *display)
305{
306 return 0;
307}
308static inline
309int sde_wb_get_info(struct msm_display_info *info, void *display)
310{
311 return 0;
312}
313static inline
314struct sde_wb_device *sde_wb_connector_get_wb(struct drm_connector *connector)
315{
316 return NULL;
317}
318
319static inline
320struct drm_framebuffer *
321sde_wb_connector_state_get_output_fb(struct drm_connector_state *state)
322{
323 return NULL;
324}
325
326static inline
327int sde_wb_connector_state_get_output_roi(struct drm_connector_state *state,
328 struct sde_rect *roi)
329{
330 return 0;
331}
332
333#endif
334#endif /* __SDE_WB_H__ */
335