blob: 2712fd1a686b668510b37e3b48d97919167bd79d [file] [log] [blame]
Daniel Vetter321a95a2016-08-29 10:27:49 +02001/*
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_modeset.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 * @encoder_type: one of the DRM_MODE_ENCODER_<foo> types in drm_mode.h
88 * @possible_crtcs: bitmask of potential CRTC bindings
89 * @possible_clones: bitmask of potential sibling encoders for cloning
90 * @crtc: currently bound CRTC
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;
104 int encoder_type;
105
106 /**
107 * @index: Position inside the mode_config.list, can be used as an array
108 * index. It is invariant over the lifetime of the encoder.
109 */
110 unsigned index;
111
112 uint32_t possible_crtcs;
113 uint32_t possible_clones;
114
115 struct drm_crtc *crtc;
116 struct drm_bridge *bridge;
117 const struct drm_encoder_funcs *funcs;
118 const struct drm_encoder_helper_funcs *helper_private;
119};
120
121#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
122
123__printf(5, 6)
124int drm_encoder_init(struct drm_device *dev,
125 struct drm_encoder *encoder,
126 const struct drm_encoder_funcs *funcs,
127 int encoder_type, const char *name, ...);
128
129/**
130 * drm_encoder_index - find the index of a registered encoder
131 * @encoder: encoder to find index for
132 *
133 * Given a registered encoder, return the index of that encoder within a DRM
134 * device's list of encoders.
135 */
136static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
137{
138 return encoder->index;
139}
140
141/* FIXME: We have an include file mess still, drm_crtc.h needs untangling. */
142static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc);
143
144/**
145 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
146 * @encoder: encoder to test
147 * @crtc: crtc to test
148 *
149 * Return false if @encoder can't be driven by @crtc, true otherwise.
150 */
151static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
152 struct drm_crtc *crtc)
153{
154 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
155}
156
157static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
158 uint32_t id)
159{
160 struct drm_mode_object *mo;
161 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
162 return mo ? obj_to_encoder(mo) : NULL;
163}
164
165void drm_encoder_cleanup(struct drm_encoder *encoder);
166
167#endif