blob: cca934d529145cfc431ff82beaaf3250d98366a9 [file] [log] [blame]
Clarence Ipdd8021c2016-07-20 16:39:47 -04001/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
2 *
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
16#include <drm/drmP.h>
17#include <drm/drm_atomic.h>
18#include <drm/drm_panel.h>
19
Clarence Ipcb3afd42016-07-15 16:25:34 -040020#include "msm_drv.h"
Clarence Ipdd8021c2016-07-20 16:39:47 -040021#include "msm_prop.h"
22#include "sde_kms.h"
Clarence Ipe59fb3f2016-07-26 13:39:59 -040023#include "sde_fence.h"
Clarence Ipdd8021c2016-07-20 16:39:47 -040024
25#define SDE_CONNECTOR_NAME_SIZE 16
26
27struct sde_connector;
28struct sde_connector_state;
29
30/**
31 * struct sde_connector_ops - callback functions for generic sde connector
32 * Individual callbacks documented below.
33 */
34struct sde_connector_ops {
35 /**
36 * post_init - perform additional initialization steps
37 * @connector: Pointer to drm connector structure
38 * @info: Pointer to sde connector info structure
39 * @display: Pointer to private display handle
40 * Returns: Zero on success
41 */
42 int (*post_init)(struct drm_connector *connector,
43 void *info,
44 void *display);
45
46 /**
47 * detect - determine if connector is connected
48 * @connector: Pointer to drm connector structure
49 * @force: Force detect setting from drm framework
50 * @display: Pointer to private display handle
51 * Returns: Connector 'is connected' status
52 */
53 enum drm_connector_status (*detect)(struct drm_connector *connector,
54 bool force,
55 void *display);
56
57 /**
58 * get_modes - add drm modes via drm_mode_probed_add()
59 * @connector: Pointer to drm connector structure
60 * @display: Pointer to private display handle
61 * Returns: Number of modes added
62 */
63 int (*get_modes)(struct drm_connector *connector,
64 void *display);
65
66 /**
67 * mode_valid - determine if specified mode is valid
68 * @connector: Pointer to drm connector structure
69 * @mode: Pointer to drm mode structure
70 * @display: Pointer to private display handle
71 * Returns: Validity status for specified mode
72 */
73 enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
74 struct drm_display_mode *mode,
75 void *display);
76
77 /**
78 * set_property - set property value
79 * @connector: Pointer to drm connector structure
80 * @state: Pointer to drm connector state structure
81 * @property_index: DRM property index
82 * @value: Incoming property value
83 * @display: Pointer to private display structure
84 * Returns: Zero on success
85 */
86 int (*set_property)(struct drm_connector *connector,
87 struct drm_connector_state *state,
88 int property_index,
89 uint64_t value,
90 void *display);
91
92 /**
93 * get_property - get property value
94 * @connector: Pointer to drm connector structure
95 * @state: Pointer to drm connector state structure
96 * @property_index: DRM property index
97 * @value: Pointer to variable for accepting property value
98 * @display: Pointer to private display structure
99 * Returns: Zero on success
100 */
101 int (*get_property)(struct drm_connector *connector,
102 struct drm_connector_state *state,
103 int property_index,
104 uint64_t *value,
105 void *display);
Clarence Ipcb3afd42016-07-15 16:25:34 -0400106
107 /**
108 * get_info - get display information
109 * @info: Pointer to msm display info structure
110 * @display: Pointer to private display structure
111 * Returns: Zero on success
112 */
113 int (*get_info)(struct msm_display_info *info, void *display);
Clarence Ipdd8021c2016-07-20 16:39:47 -0400114};
115
116/**
117 * struct sde_connector - local sde connector structure
118 * @base: Base drm connector structure
119 * @connector_type: Set to one of DRM_MODE_CONNECTOR_ types
120 * @encoder: Pointer to preferred drm encoder
121 * @panel: Pointer to drm panel, if present
122 * @display: Pointer to private display data structure
Alan Kwongdfa8c082016-07-29 04:10:00 -0400123 * @mmu_secure: MMU id for secure buffers
124 * @mmu_unsecure: MMU id for unsecure buffers
Clarence Ipdd8021c2016-07-20 16:39:47 -0400125 * @name: ASCII name of connector
Clarence Ipe59fb3f2016-07-26 13:39:59 -0400126 * @retire_fence: Retire fence reference
Clarence Ipdd8021c2016-07-20 16:39:47 -0400127 * @ops: Local callback function pointer table
128 * @property_info: Private structure for generic property handling
129 * @property_data: Array of private data for generic property handling
Dhaval Patel4e574842016-08-23 15:11:37 -0700130 * @blob_caps: Pointer to blob structure for 'capabilities' property
Clarence Ipdd8021c2016-07-20 16:39:47 -0400131 */
132struct sde_connector {
133 struct drm_connector base;
134
135 int connector_type;
136
137 struct drm_encoder *encoder;
138 struct drm_panel *panel;
139 void *display;
140
Alan Kwongdfa8c082016-07-29 04:10:00 -0400141 int mmu_id[SDE_IOMMU_DOMAIN_MAX];
Clarence Ipdd8021c2016-07-20 16:39:47 -0400142
143 char name[SDE_CONNECTOR_NAME_SIZE];
144
Clarence Ipe59fb3f2016-07-26 13:39:59 -0400145 struct sde_fence retire_fence;
Clarence Ipdd8021c2016-07-20 16:39:47 -0400146 struct sde_connector_ops ops;
147
148 struct msm_property_info property_info;
149 struct msm_property_data property_data[CONNECTOR_PROP_COUNT];
Dhaval Patel4e574842016-08-23 15:11:37 -0700150 struct drm_property_blob *blob_caps;
Clarence Ipdd8021c2016-07-20 16:39:47 -0400151};
152
153/**
154 * to_sde_connector - convert drm_connector pointer to sde connector pointer
155 * @X: Pointer to drm_connector structure
156 * Returns: Pointer to sde_connector structure
157 */
158#define to_sde_connector(x) container_of((x), struct sde_connector, base)
159
160/**
161 * sde_connector_get_display - get sde connector's private display pointer
162 * @C: Pointer to drm connector structure
163 * Returns: Pointer to associated private display structure
164 */
165#define sde_connector_get_display(C) \
166 ((C) ? to_sde_connector((C))->display : 0)
167
168/**
169 * sde_connector_get_panel - get sde connector's private panel pointer
170 * @C: Pointer to drm connector structure
171 * Returns: Pointer to associated private display structure
172 */
173#define sde_connector_get_panel(C) \
174 ((C) ? to_sde_connector((C))->panel : 0)
175
176/**
177 * sde_connector_get_encoder - get sde connector's private encoder pointer
178 * @C: Pointer to drm connector structure
179 * Returns: Pointer to associated private encoder structure
180 */
181#define sde_connector_get_encoder(C) \
182 ((C) ? to_sde_connector((C))->encoder : 0)
183
184/**
185 * sde_connector_get_propinfo - get sde connector's property info pointer
186 * @C: Pointer to drm connector structure
187 * Returns: Pointer to associated private property info structure
188 */
189#define sde_connector_get_propinfo(C) \
190 ((C) ? &to_sde_connector((C))->property_info : 0)
191
192/**
193 * struct sde_connector_state - private connector status structure
194 * @base: Base drm connector structure
195 * @out_fb: Pointer to output frame buffer, if applicable
196 * @mmu_id: MMU ID for accessing frame buffer objects, if applicable
197 * @property_values: Local cache of current connector property values
198 */
199struct sde_connector_state {
200 struct drm_connector_state base;
201 struct drm_framebuffer *out_fb;
202 int mmu_id;
203 uint64_t property_values[CONNECTOR_PROP_COUNT];
204};
205
206/**
207 * to_sde_connector_state - convert drm_connector_state pointer to
208 * sde connector state pointer
209 * @X: Pointer to drm_connector_state structure
210 * Returns: Pointer to sde_connector_state structure
211 */
212#define to_sde_connector_state(x) \
213 container_of((x), struct sde_connector_state, base)
214
215/**
216 * sde_connector_get_property - query integer value of connector property
217 * @S: Pointer to drm connector state
218 * @X: Property index, from enum msm_mdp_connector_property
219 * Returns: Integer value of requested property
220 */
221#define sde_connector_get_property(S, X) \
222 ((S) && ((X) < CONNECTOR_PROP_COUNT) ? \
223 (to_sde_connector_state((S))->property_values[(X)]) : 0)
224
225/**
Lloyd Atkinson13cee812016-08-16 16:10:31 -0400226 * sde_connector_get_property_values - retrieve property values cache
227 * @S: Pointer to drm connector state
228 * Returns: Integer value of requested property
229 */
230#define sde_connector_get_property_values(S) \
231 ((S) ? (to_sde_connector_state((S))->property_values) : 0)
232
233/**
Clarence Ipdd8021c2016-07-20 16:39:47 -0400234 * sde_connector_get_out_fb - query out_fb value from sde connector state
235 * @S: Pointer to drm connector state
236 * Returns: Output fb associated with specified connector state
237 */
238#define sde_connector_get_out_fb(S) \
239 ((S) ? to_sde_connector_state((S))->out_fb : 0)
240
241/**
Lloyd Atkinson55987b02016-08-16 16:57:46 -0400242 * sde_connector_get_topology_name - helper accessor to retrieve topology_name
243 * @connector: pointer to drm connector
244 * Returns: value of the CONNECTOR_PROP_TOPOLOGY_NAME property or 0
245 */
246static inline uint64_t sde_connector_get_topology_name(
247 struct drm_connector *connector)
248{
249 if (!connector || !connector->state)
250 return 0;
251 return sde_connector_get_property(connector->state,
252 CONNECTOR_PROP_TOPOLOGY_NAME);
253}
254
255/**
Clarence Ipdd8021c2016-07-20 16:39:47 -0400256 * sde_connector_init - create drm connector object for a given display
257 * @dev: Pointer to drm device struct
258 * @encoder: Pointer to associated encoder
259 * @panel: Pointer to associated panel, can be NULL
260 * @display: Pointer to associated display object
261 * @ops: Pointer to callback operations function table
262 * @connector_poll: Set to appropriate DRM_CONNECTOR_POLL_ setting
263 * @connector_type: Set to appropriate DRM_MODE_CONNECTOR_ type
264 * Returns: Pointer to newly created drm connector struct
265 */
266struct drm_connector *sde_connector_init(struct drm_device *dev,
267 struct drm_encoder *encoder,
268 struct drm_panel *panel,
269 void *display,
270 const struct sde_connector_ops *ops,
271 int connector_poll,
272 int connector_type);
273
Clarence Ipe59fb3f2016-07-26 13:39:59 -0400274/**
275 * sde_connector_prepare_fence - prepare fence support for current commit
276 * @connector: Pointer to drm connector object
277 */
278void sde_connector_prepare_fence(struct drm_connector *connector);
279
280/**
281 * sde_connector_complete_commit - signal completion of current commit
282 * @connector: Pointer to drm connector object
283 */
284void sde_connector_complete_commit(struct drm_connector *connector);
285
Clarence Ipcb3afd42016-07-15 16:25:34 -0400286/**
287 * sde_connector_get_info - query display specific information
288 * @connector: Pointer to drm connector object
289 * @info: Pointer to msm display information structure
290 * Returns: Zero on success
291 */
292int sde_connector_get_info(struct drm_connector *connector,
293 struct msm_display_info *info);
294
Clarence Ipdd8021c2016-07-20 16:39:47 -0400295#endif /* _SDE_CONNECTOR_H_ */
296