Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io>
0004  */
0005 
0006 #ifndef _SUNXI_ENGINE_H_
0007 #define _SUNXI_ENGINE_H_
0008 
0009 struct drm_plane;
0010 struct drm_device;
0011 struct drm_crtc_state;
0012 struct drm_display_mode;
0013 
0014 struct sunxi_engine;
0015 
0016 /**
0017  * struct sunxi_engine_ops - helper operations for sunXi engines
0018  *
0019  * These hooks are used by the common part of the DRM driver to
0020  * implement the proper behaviour.
0021  */
0022 struct sunxi_engine_ops {
0023     /**
0024      * @atomic_begin:
0025      *
0026      * This callback allows to prepare our engine for an atomic
0027      * update. This is mirroring the
0028      * &drm_crtc_helper_funcs.atomic_begin callback, so any
0029      * documentation there applies.
0030      *
0031      * This function is optional.
0032      */
0033     void (*atomic_begin)(struct sunxi_engine *engine,
0034                  struct drm_crtc_state *old_state);
0035 
0036     /**
0037      * @atomic_check:
0038      *
0039      * This callback allows to validate plane-update related CRTC
0040      * constraints specific to engines. This is mirroring the
0041      * &drm_crtc_helper_funcs.atomic_check callback, so any
0042      * documentation there applies.
0043      *
0044      * This function is optional.
0045      *
0046      * RETURNS:
0047      *
0048      * 0 on success or a negative error code.
0049      */
0050     int (*atomic_check)(struct sunxi_engine *engine,
0051                 struct drm_crtc_state *state);
0052 
0053     /**
0054      * @commit:
0055      *
0056      * This callback will trigger the hardware switch to commit
0057      * the new configuration that has been setup during the next
0058      * vblank period.
0059      *
0060      * This function is optional.
0061      */
0062     void (*commit)(struct sunxi_engine *engine);
0063 
0064     /**
0065      * @layers_init:
0066      *
0067      * This callback is used to allocate, initialize and register
0068      * the layers supported by that engine.
0069      *
0070      * This function is mandatory.
0071      *
0072      * RETURNS:
0073      *
0074      * The array of struct drm_plane backing the layers, or an
0075      * error pointer on failure.
0076      */
0077     struct drm_plane **(*layers_init)(struct drm_device *drm,
0078                       struct sunxi_engine *engine);
0079 
0080     /**
0081      * @apply_color_correction:
0082      *
0083      * This callback will enable the color correction in the
0084      * engine. This is useful only for the composite output.
0085      *
0086      * This function is optional.
0087      */
0088     void (*apply_color_correction)(struct sunxi_engine *engine);
0089 
0090     /**
0091      * @disable_color_correction:
0092      *
0093      * This callback will stop the color correction in the
0094      * engine. This is useful only for the composite output.
0095      *
0096      * This function is optional.
0097      */
0098     void (*disable_color_correction)(struct sunxi_engine *engine);
0099 
0100     /**
0101      * @vblank_quirk:
0102      *
0103      * This callback is used to implement engine-specific
0104      * behaviour part of the VBLANK event. It is run with all the
0105      * constraints of an interrupt (can't sleep, all local
0106      * interrupts disabled) and therefore should be as fast as
0107      * possible.
0108      *
0109      * This function is optional.
0110      */
0111     void (*vblank_quirk)(struct sunxi_engine *engine);
0112 
0113     /**
0114      * @mode_set
0115      *
0116      * This callback is used to set mode related parameters
0117      * like interlacing, screen size, etc. once per mode set.
0118      *
0119      * This function is optional.
0120      */
0121     void (*mode_set)(struct sunxi_engine *engine,
0122              const struct drm_display_mode *mode);
0123 };
0124 
0125 /**
0126  * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
0127  * @ops:    the operations of the engine
0128  * @node:   the of device node of the engine
0129  * @regs:   the regmap of the engine
0130  * @id:     the id of the engine (-1 if not used)
0131  */
0132 struct sunxi_engine {
0133     const struct sunxi_engine_ops   *ops;
0134 
0135     struct device_node      *node;
0136     struct regmap           *regs;
0137 
0138     int id;
0139 
0140     /* Engine list management */
0141     struct list_head        list;
0142 };
0143 
0144 /**
0145  * sunxi_engine_commit() - commit all changes of the engine
0146  * @engine: pointer to the engine
0147  */
0148 static inline void
0149 sunxi_engine_commit(struct sunxi_engine *engine)
0150 {
0151     if (engine->ops && engine->ops->commit)
0152         engine->ops->commit(engine);
0153 }
0154 
0155 /**
0156  * sunxi_engine_layers_init() - Create planes (layers) for the engine
0157  * @drm:    pointer to the drm_device for which planes will be created
0158  * @engine: pointer to the engine
0159  */
0160 static inline struct drm_plane **
0161 sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
0162 {
0163     if (engine->ops && engine->ops->layers_init)
0164         return engine->ops->layers_init(drm, engine);
0165     return ERR_PTR(-ENOSYS);
0166 }
0167 
0168 /**
0169  * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
0170  * @engine: pointer to the engine
0171  *
0172  * This functionality is optional for an engine, however, if the engine is
0173  * intended to be used with TV Encoder, the output will be incorrect
0174  * without the color correction, due to TV Encoder expects the engine to
0175  * output directly YUV signal.
0176  */
0177 static inline void
0178 sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
0179 {
0180     if (engine->ops && engine->ops->apply_color_correction)
0181         engine->ops->apply_color_correction(engine);
0182 }
0183 
0184 /**
0185  * sunxi_engine_disable_color_correction - Disable the color space correction
0186  * @engine: pointer to the engine
0187  *
0188  * This function is paired with apply_color_correction().
0189  */
0190 static inline void
0191 sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
0192 {
0193     if (engine->ops && engine->ops->disable_color_correction)
0194         engine->ops->disable_color_correction(engine);
0195 }
0196 
0197 /**
0198  * sunxi_engine_mode_set - Inform engine of a new mode
0199  * @engine: pointer to the engine
0200  * @mode:   new mode
0201  *
0202  * Engine can use this functionality to set specifics once per mode change.
0203  */
0204 static inline void
0205 sunxi_engine_mode_set(struct sunxi_engine *engine,
0206               const struct drm_display_mode *mode)
0207 {
0208     if (engine->ops && engine->ops->mode_set)
0209         engine->ops->mode_set(engine, mode);
0210 }
0211 #endif /* _SUNXI_ENGINE_H_ */