drm: simple_kms_helper: Add mode_valid() callback support
[linux-block.git] / include / drm / drm_simple_kms_helper.h
1 /*
2  * Copyright (C) 2016 Noralf Trønnes
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9
10 #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
11 #define __LINUX_DRM_SIMPLE_KMS_HELPER_H
12
13 #include <drm/drm_crtc.h>
14 #include <drm/drm_encoder.h>
15 #include <drm/drm_plane.h>
16
17 struct drm_simple_display_pipe;
18
19 /**
20  * struct drm_simple_display_pipe_funcs - helper operations for a simple
21  *                                        display pipeline
22  */
23 struct drm_simple_display_pipe_funcs {
24         /**
25          * @mode_valid:
26          *
27          * This function is called to filter out valid modes from the
28          * suggestions suggested by the bridge or display. This optional
29          * hook is passed in when initializing the pipeline.
30          *
31          * RETURNS:
32          *
33          * drm_mode_status Enum
34          */
35         enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
36                                            const struct drm_display_mode *mode);
37
38         /**
39          * @enable:
40          *
41          * This function should be used to enable the pipeline.
42          * It is called when the underlying crtc is enabled.
43          * This hook is optional.
44          */
45         void (*enable)(struct drm_simple_display_pipe *pipe,
46                        struct drm_crtc_state *crtc_state);
47         /**
48          * @disable:
49          *
50          * This function should be used to disable the pipeline.
51          * It is called when the underlying crtc is disabled.
52          * This hook is optional.
53          */
54         void (*disable)(struct drm_simple_display_pipe *pipe);
55
56         /**
57          * @check:
58          *
59          * This function is called in the check phase of an atomic update,
60          * specifically when the underlying plane is checked.
61          * The simple display pipeline helpers already check that the plane is
62          * not scaled, fills the entire visible area and is always enabled
63          * when the crtc is also enabled.
64          * This hook is optional.
65          *
66          * RETURNS:
67          *
68          * 0 on success, -EINVAL if the state or the transition can't be
69          * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
70          * attempt to obtain another state object ran into a &drm_modeset_lock
71          * deadlock.
72          */
73         int (*check)(struct drm_simple_display_pipe *pipe,
74                      struct drm_plane_state *plane_state,
75                      struct drm_crtc_state *crtc_state);
76         /**
77          * @update:
78          *
79          * This function is called when the underlying plane state is updated.
80          * This hook is optional.
81          *
82          * This is the function drivers should submit the
83          * &drm_pending_vblank_event from. Using either
84          * drm_crtc_arm_vblank_event(), when the driver supports vblank
85          * interrupt handling, or drm_crtc_send_vblank_event() directly in case
86          * the hardware lacks vblank support entirely.
87          */
88         void (*update)(struct drm_simple_display_pipe *pipe,
89                        struct drm_plane_state *old_plane_state);
90
91         /**
92          * @prepare_fb:
93          *
94          * Optional, called by &drm_plane_helper_funcs.prepare_fb.  Please read
95          * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for
96          * more details.
97          */
98         int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
99                           struct drm_plane_state *plane_state);
100
101         /**
102          * @cleanup_fb:
103          *
104          * Optional, called by &drm_plane_helper_funcs.cleanup_fb.  Please read
105          * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
106          * more details.
107          */
108         void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
109                            struct drm_plane_state *plane_state);
110 };
111
112 /**
113  * struct drm_simple_display_pipe - simple display pipeline
114  * @crtc: CRTC control structure
115  * @plane: Plane control structure
116  * @encoder: Encoder control structure
117  * @connector: Connector control structure
118  * @funcs: Pipeline control functions (optional)
119  *
120  * Simple display pipeline with plane, crtc and encoder collapsed into one
121  * entity. It should be initialized by calling drm_simple_display_pipe_init().
122  */
123 struct drm_simple_display_pipe {
124         struct drm_crtc crtc;
125         struct drm_plane plane;
126         struct drm_encoder encoder;
127         struct drm_connector *connector;
128
129         const struct drm_simple_display_pipe_funcs *funcs;
130 };
131
132 int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
133                                           struct drm_bridge *bridge);
134
135 int drm_simple_display_pipe_init(struct drm_device *dev,
136                         struct drm_simple_display_pipe *pipe,
137                         const struct drm_simple_display_pipe_funcs *funcs,
138                         const uint32_t *formats, unsigned int format_count,
139                         const uint64_t *format_modifiers,
140                         struct drm_connector *connector);
141
142 #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */