arm64: dts: marvell: mcbin: enable uart headers
[linux-2.6-block.git] / include / drm / drm_encoder.h
CommitLineData
321a95ae
DV
1/*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef __DRM_ENCODER_H__
24#define __DRM_ENCODER_H__
25
26#include <linux/list.h>
27#include <linux/ctype.h>
2407d1dc 28#include <drm/drm_crtc.h>
9338203c 29#include <drm/drm_mode.h>
949619f3 30#include <drm/drm_mode_object.h>
321a95ae 31
9338203c
LP
32struct drm_encoder;
33
321a95ae
DV
34/**
35 * struct drm_encoder_funcs - encoder controls
36 *
37 * Encoders sit between CRTCs and connectors.
38 */
39struct drm_encoder_funcs {
40 /**
41 * @reset:
42 *
43 * Reset encoder hardware and software state to off. This function isn't
44 * called by the core directly, only through drm_mode_config_reset().
45 * It's not a helper hook only for historical reasons.
46 */
47 void (*reset)(struct drm_encoder *encoder);
48
49 /**
50 * @destroy:
51 *
52 * Clean up encoder resources. This is only called at driver unload time
53 * through drm_mode_config_cleanup() since an encoder cannot be
54 * hotplugged in DRM.
55 */
56 void (*destroy)(struct drm_encoder *encoder);
57
58 /**
59 * @late_register:
60 *
61 * This optional hook can be used to register additional userspace
62 * interfaces attached to the encoder like debugfs interfaces.
63 * It is called late in the driver load sequence from drm_dev_register().
64 * Everything added from this callback should be unregistered in
65 * the early_unregister callback.
66 *
67 * Returns:
68 *
69 * 0 on success, or a negative error code on failure.
70 */
71 int (*late_register)(struct drm_encoder *encoder);
72
73 /**
74 * @early_unregister:
75 *
76 * This optional hook should be used to unregister the additional
77 * userspace interfaces attached to the encoder from
559bdaf7 78 * @late_register. It is called from drm_dev_unregister(),
321a95ae
DV
79 * early in the driver unload sequence to disable userspace access
80 * before data structures are torndown.
81 */
82 void (*early_unregister)(struct drm_encoder *encoder);
83};
84
85/**
86 * struct drm_encoder - central DRM encoder structure
87 * @dev: parent DRM device
88 * @head: list management
89 * @base: base KMS object
90 * @name: human readable name, can be overwritten by the driver
321a95ae
DV
91 * @bridge: bridge associated to the encoder
92 * @funcs: control functions
93 * @helper_private: mid-layer private data
94 *
95 * CRTCs drive pixels to encoders, which convert them into signals
96 * appropriate for a given connector or set of connectors.
97 */
98struct drm_encoder {
99 struct drm_device *dev;
100 struct list_head head;
101
102 struct drm_mode_object base;
103 char *name;
e03e6de0
DV
104 /**
105 * @encoder_type:
106 *
107 * One of the DRM_MODE_ENCODER_<foo> types in drm_mode.h. The following
108 * encoder types are defined thus far:
109 *
110 * - DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A.
111 *
112 * - DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort.
113 *
114 * - DRM_MODE_ENCODER_LVDS for display panels, or in general any panel
115 * with a proprietary parallel connector.
116 *
117 * - DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video,
118 * Component, SCART).
119 *
120 * - DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
121 *
122 * - DRM_MODE_ENCODER_DSI for panels connected using the DSI serial bus.
123 *
124 * - DRM_MODE_ENCODER_DPI for panels connected using the DPI parallel
125 * bus.
126 *
127 * - DRM_MODE_ENCODER_DPMST for special fake encoders used to allow
128 * mutliple DP MST streams to share one physical encoder.
129 */
321a95ae
DV
130 int encoder_type;
131
132 /**
133 * @index: Position inside the mode_config.list, can be used as an array
134 * index. It is invariant over the lifetime of the encoder.
135 */
136 unsigned index;
137
e03e6de0
DV
138 /**
139 * @possible_crtcs: Bitmask of potential CRTC bindings, using
140 * drm_crtc_index() as the index into the bitfield. The driver must set
141 * the bits for all &drm_crtc objects this encoder can be connected to
142 * before calling drm_encoder_init().
143 *
144 * In reality almost every driver gets this wrong.
145 *
146 * Note that since CRTC objects can't be hotplugged the assigned indices
147 * are stable and hence known before registering all objects.
148 */
321a95ae 149 uint32_t possible_crtcs;
e03e6de0
DV
150
151 /**
152 * @possible_clones: Bitmask of potential sibling encoders for cloning,
153 * using drm_encoder_index() as the index into the bitfield. The driver
154 * must set the bits for all &drm_encoder objects which can clone a
155 * &drm_crtc together with this encoder before calling
156 * drm_encoder_init(). Drivers should set the bit representing the
157 * encoder itself, too. Cloning bits should be set such that when two
158 * encoders can be used in a cloned configuration, they both should have
159 * each another bits set.
160 *
161 * In reality almost every driver gets this wrong.
162 *
163 * Note that since encoder objects can't be hotplugged the assigned indices
164 * are stable and hence known before registering all objects.
165 */
321a95ae
DV
166 uint32_t possible_clones;
167
2e2b96ef
DV
168 /**
169 * @crtc: Currently bound CRTC, only really meaningful for non-atomic
170 * drivers. Atomic drivers should instead check
171 * &drm_connector_state.crtc.
172 */
321a95ae
DV
173 struct drm_crtc *crtc;
174 struct drm_bridge *bridge;
175 const struct drm_encoder_funcs *funcs;
176 const struct drm_encoder_helper_funcs *helper_private;
177};
178
179#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
180
181__printf(5, 6)
182int drm_encoder_init(struct drm_device *dev,
183 struct drm_encoder *encoder,
184 const struct drm_encoder_funcs *funcs,
185 int encoder_type, const char *name, ...);
186
187/**
188 * drm_encoder_index - find the index of a registered encoder
189 * @encoder: encoder to find index for
190 *
191 * Given a registered encoder, return the index of that encoder within a DRM
192 * device's list of encoders.
193 */
194static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
195{
196 return encoder->index;
197}
198
321a95ae
DV
199/**
200 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
201 * @encoder: encoder to test
202 * @crtc: crtc to test
203 *
e03e6de0 204 * Returns false if @encoder can't be driven by @crtc, true otherwise.
321a95ae
DV
205 */
206static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
207 struct drm_crtc *crtc)
208{
209 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
210}
211
e03e6de0
DV
212/**
213 * drm_encoder_find - find a &drm_encoder
214 * @dev: DRM device
e7e62c7e 215 * @file_priv: drm file to check for lease against.
e03e6de0
DV
216 * @id: encoder id
217 *
218 * Returns the encoder with @id, NULL if it doesn't exist. Simple wrapper around
219 * drm_mode_object_find().
220 */
321a95ae 221static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
418da172 222 struct drm_file *file_priv,
e03e6de0 223 uint32_t id)
321a95ae
DV
224{
225 struct drm_mode_object *mo;
e03e6de0 226
418da172 227 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_ENCODER);
e03e6de0 228
321a95ae
DV
229 return mo ? obj_to_encoder(mo) : NULL;
230}
231
232void drm_encoder_cleanup(struct drm_encoder *encoder);
233
afb21ea6
DV
234/**
235 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
236 * @encoder: the loop cursor
237 * @dev: the DRM device
238 * @encoder_mask: bitmask of encoder indices
239 *
240 * Iterate over all encoders specified by bitmask.
241 */
242#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
243 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
244 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
245
246/**
247 * drm_for_each_encoder - iterate over all encoders
248 * @encoder: the loop cursor
249 * @dev: the DRM device
250 *
251 * Iterate over all encoders of @dev.
252 */
253#define drm_for_each_encoder(encoder, dev) \
254 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
255
321a95ae 256#endif