Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  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>
 28#include <drm/drm_mode_object.h>
 29
 30/**
 31 * struct drm_encoder_funcs - encoder controls
 32 *
 33 * Encoders sit between CRTCs and connectors.
 34 */
 35struct drm_encoder_funcs {
 36	/**
 37	 * @reset:
 38	 *
 39	 * Reset encoder hardware and software state to off. This function isn't
 40	 * called by the core directly, only through drm_mode_config_reset().
 41	 * It's not a helper hook only for historical reasons.
 42	 */
 43	void (*reset)(struct drm_encoder *encoder);
 44
 45	/**
 46	 * @destroy:
 47	 *
 48	 * Clean up encoder resources. This is only called at driver unload time
 49	 * through drm_mode_config_cleanup() since an encoder cannot be
 50	 * hotplugged in DRM.
 51	 */
 52	void (*destroy)(struct drm_encoder *encoder);
 53
 54	/**
 55	 * @late_register:
 56	 *
 57	 * This optional hook can be used to register additional userspace
 58	 * interfaces attached to the encoder like debugfs interfaces.
 59	 * It is called late in the driver load sequence from drm_dev_register().
 60	 * Everything added from this callback should be unregistered in
 61	 * the early_unregister callback.
 62	 *
 63	 * Returns:
 64	 *
 65	 * 0 on success, or a negative error code on failure.
 66	 */
 67	int (*late_register)(struct drm_encoder *encoder);
 68
 69	/**
 70	 * @early_unregister:
 71	 *
 72	 * This optional hook should be used to unregister the additional
 73	 * userspace interfaces attached to the encoder from
 74	 * late_unregister(). It is called from drm_dev_unregister(),
 75	 * early in the driver unload sequence to disable userspace access
 76	 * before data structures are torndown.
 77	 */
 78	void (*early_unregister)(struct drm_encoder *encoder);
 79};
 80
 81/**
 82 * struct drm_encoder - central DRM encoder structure
 83 * @dev: parent DRM device
 84 * @head: list management
 85 * @base: base KMS object
 86 * @name: human readable name, can be overwritten by the driver
 87 * @crtc: currently bound CRTC
 88 * @bridge: bridge associated to the encoder
 89 * @funcs: control functions
 90 * @helper_private: mid-layer private data
 91 *
 92 * CRTCs drive pixels to encoders, which convert them into signals
 93 * appropriate for a given connector or set of connectors.
 94 */
 95struct drm_encoder {
 96	struct drm_device *dev;
 97	struct list_head head;
 98
 99	struct drm_mode_object base;
100	char *name;
101	/**
102	 * @encoder_type:
103	 *
104	 * One of the DRM_MODE_ENCODER_<foo> types in drm_mode.h. The following
105	 * encoder types are defined thus far:
106	 *
107	 * - DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A.
108	 *
109	 * - DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort.
110	 *
111	 * - DRM_MODE_ENCODER_LVDS for display panels, or in general any panel
112	 *   with a proprietary parallel connector.
113	 *
114	 * - DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video,
115	 *   Component, SCART).
116	 *
117	 * - DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
118	 *
119	 * - DRM_MODE_ENCODER_DSI for panels connected using the DSI serial bus.
120	 *
121	 * - DRM_MODE_ENCODER_DPI for panels connected using the DPI parallel
122	 *   bus.
123	 *
124	 * - DRM_MODE_ENCODER_DPMST for special fake encoders used to allow
125	 *   mutliple DP MST streams to share one physical encoder.
126	 */
127	int encoder_type;
128
129	/**
130	 * @index: Position inside the mode_config.list, can be used as an array
131	 * index. It is invariant over the lifetime of the encoder.
132	 */
133	unsigned index;
134
135	/**
136	 * @possible_crtcs: Bitmask of potential CRTC bindings, using
137	 * drm_crtc_index() as the index into the bitfield. The driver must set
138	 * the bits for all &drm_crtc objects this encoder can be connected to
139	 * before calling drm_encoder_init().
140	 *
141	 * In reality almost every driver gets this wrong.
142	 *
143	 * Note that since CRTC objects can't be hotplugged the assigned indices
144	 * are stable and hence known before registering all objects.
145	 */
146	uint32_t possible_crtcs;
147
148	/**
149	 * @possible_clones: Bitmask of potential sibling encoders for cloning,
150	 * using drm_encoder_index() as the index into the bitfield. The driver
151	 * must set the bits for all &drm_encoder objects which can clone a
152	 * &drm_crtc together with this encoder before calling
153	 * drm_encoder_init(). Drivers should set the bit representing the
154	 * encoder itself, too. Cloning bits should be set such that when two
155	 * encoders can be used in a cloned configuration, they both should have
156	 * each another bits set.
157	 *
158	 * In reality almost every driver gets this wrong.
159	 *
160	 * Note that since encoder objects can't be hotplugged the assigned indices
161	 * are stable and hence known before registering all objects.
162	 */
163	uint32_t possible_clones;
164
165	struct drm_crtc *crtc;
166	struct drm_bridge *bridge;
167	const struct drm_encoder_funcs *funcs;
168	const struct drm_encoder_helper_funcs *helper_private;
169};
170
171#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
172
173__printf(5, 6)
174int drm_encoder_init(struct drm_device *dev,
175		     struct drm_encoder *encoder,
176		     const struct drm_encoder_funcs *funcs,
177		     int encoder_type, const char *name, ...);
178
179/**
180 * drm_encoder_index - find the index of a registered encoder
181 * @encoder: encoder to find index for
182 *
183 * Given a registered encoder, return the index of that encoder within a DRM
184 * device's list of encoders.
185 */
186static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
187{
188	return encoder->index;
189}
190
191/* FIXME: We have an include file mess still, drm_crtc.h needs untangling. */
192static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc);
193
194/**
195 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
196 * @encoder: encoder to test
197 * @crtc: crtc to test
198 *
199 * Returns false if @encoder can't be driven by @crtc, true otherwise.
200 */
201static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
202				       struct drm_crtc *crtc)
203{
204	return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
205}
206
207/**
208 * drm_encoder_find - find a &drm_encoder
209 * @dev: DRM device
210 * @id: encoder id
211 *
212 * Returns the encoder with @id, NULL if it doesn't exist. Simple wrapper around
213 * drm_mode_object_find().
214 */
215static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
216						   uint32_t id)
217{
218	struct drm_mode_object *mo;
219
220	mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
221
222	return mo ? obj_to_encoder(mo) : NULL;
223}
224
225void drm_encoder_cleanup(struct drm_encoder *encoder);
226
227/**
228 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
229 * @encoder: the loop cursor
230 * @dev: the DRM device
231 * @encoder_mask: bitmask of encoder indices
232 *
233 * Iterate over all encoders specified by bitmask.
234 */
235#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
236	list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
237		for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
238
239/**
240 * drm_for_each_encoder - iterate over all encoders
241 * @encoder: the loop cursor
242 * @dev: the DRM device
243 *
244 * Iterate over all encoders of @dev.
245 */
246#define drm_for_each_encoder(encoder, dev) \
247	list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
248
249#endif