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