]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/arm/display/komeda/komeda_kms.h
drm/komeda: Rename main engine clk name "mclk" to "aclk"
[linux.git] / drivers / gpu / drm / arm / display / komeda / komeda_kms.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4  * Author: James.Qian.Wang <james.qian.wang@arm.com>
5  *
6  */
7 #ifndef _KOMEDA_KMS_H_
8 #define _KOMEDA_KMS_H_
9
10 #include <linux/list.h>
11 #include <drm/drm_atomic.h>
12 #include <drm/drm_atomic_helper.h>
13 #include <drm/drm_crtc_helper.h>
14 #include <drm/drm_device.h>
15 #include <drm/drm_writeback.h>
16 #include <drm/drm_print.h>
17 #include <video/videomode.h>
18 #include <video/display_timing.h>
19
20 /**
21  * struct komeda_plane - komeda instance of drm_plane
22  */
23 struct komeda_plane {
24         /** @base: &drm_plane */
25         struct drm_plane base;
26         /**
27          * @layer:
28          *
29          * represents available layer input pipelines for this plane.
30          *
31          * NOTE:
32          * the layer is not for a specific Layer, but indicate a group of
33          * Layers with same capabilities.
34          */
35         struct komeda_layer *layer;
36
37         /** @prop_img_enhancement: for on/off image enhancement */
38         struct drm_property *prop_img_enhancement;
39 };
40
41 /**
42  * struct komeda_plane_state
43  *
44  * The plane_state can be split into two data flow (left/right) and handled
45  * by two layers &komeda_plane.layer and &komeda_plane.layer.right
46  */
47 struct komeda_plane_state {
48         /** @base: &drm_plane_state */
49         struct drm_plane_state base;
50         /** @zlist_node: zorder list node */
51         struct list_head zlist_node;
52
53         /* @img_enhancement: on/off image enhancement */
54         u8 img_enhancement : 1;
55 };
56
57 /**
58  * struct komeda_wb_connector
59  */
60 struct komeda_wb_connector {
61         /** @base: &drm_writeback_connector */
62         struct drm_writeback_connector base;
63
64         /** @wb_layer: represents associated writeback pipeline of komeda */
65         struct komeda_layer *wb_layer;
66 };
67
68 /**
69  * struct komeda_crtc
70  */
71 struct komeda_crtc {
72         /** @base: &drm_crtc */
73         struct drm_crtc base;
74         /** @master: only master has display output */
75         struct komeda_pipeline *master;
76         /**
77          * @slave: optional
78          *
79          * Doesn't have its own display output, the handled data flow will
80          * merge into the master.
81          */
82         struct komeda_pipeline *slave;
83
84         /** @wb_conn: komeda write back connector */
85         struct komeda_wb_connector *wb_conn;
86
87         /** @disable_done: this flip_done is for tracing the disable */
88         struct completion *disable_done;
89
90         /** @clock_ratio_property: property for ratio of (aclk << 32)/pxlclk */
91         struct drm_property *clock_ratio_property;
92 };
93
94 /**
95  * struct komeda_crtc_state
96  */
97 struct komeda_crtc_state {
98         /** @base: &drm_crtc_state */
99         struct drm_crtc_state base;
100
101         /* private properties */
102
103         /* computed state which are used by validate/check */
104         /**
105          * @affected_pipes:
106          * the affected pipelines in once display instance
107          */
108         u32 affected_pipes;
109         /**
110          * @active_pipes:
111          * the active pipelines in once display instance
112          */
113         u32 active_pipes;
114
115         /** @clock_ratio: ratio of (aclk << 32)/pxlclk */
116         u64 clock_ratio;
117 };
118
119 /** struct komeda_kms_dev - for gather KMS related things */
120 struct komeda_kms_dev {
121         /** @base: &drm_device */
122         struct drm_device base;
123
124         /** @n_crtcs: valid numbers of crtcs in &komeda_kms_dev.crtcs */
125         int n_crtcs;
126         /** @crtcs: crtcs list */
127         struct komeda_crtc crtcs[KOMEDA_MAX_PIPELINES];
128 };
129
130 #define to_kplane(p)    container_of(p, struct komeda_plane, base)
131 #define to_kplane_st(p) container_of(p, struct komeda_plane_state, base)
132 #define to_kconn(p)     container_of(p, struct komeda_wb_connector, base)
133 #define to_kcrtc(p)     container_of(p, struct komeda_crtc, base)
134 #define to_kcrtc_st(p)  container_of(p, struct komeda_crtc_state, base)
135 #define to_kdev(p)      container_of(p, struct komeda_kms_dev, base)
136 #define to_wb_conn(x)   container_of(x, struct drm_writeback_connector, base)
137
138 static inline bool is_writeback_only(struct drm_crtc_state *st)
139 {
140         struct komeda_wb_connector *wb_conn = to_kcrtc(st->crtc)->wb_conn;
141         struct drm_connector *conn = wb_conn ? &wb_conn->base.base : NULL;
142
143         return conn && (st->connector_mask == BIT(drm_connector_index(conn)));
144 }
145
146 static inline bool
147 is_only_changed_connector(struct drm_crtc_state *st, struct drm_connector *conn)
148 {
149         struct drm_crtc_state *old_st;
150         u32 changed_connectors;
151
152         old_st = drm_atomic_get_old_crtc_state(st->state, st->crtc);
153         changed_connectors = st->connector_mask ^ old_st->connector_mask;
154
155         return BIT(drm_connector_index(conn)) == changed_connectors;
156 }
157
158 unsigned long komeda_calc_aclk(struct komeda_crtc_state *kcrtc_st);
159
160 int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
161
162 int komeda_kms_add_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
163 int komeda_kms_add_planes(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
164 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
165                                 struct komeda_dev *mdev);
166 int komeda_kms_add_wb_connectors(struct komeda_kms_dev *kms,
167                                  struct komeda_dev *mdev);
168 void komeda_kms_cleanup_private_objs(struct komeda_kms_dev *kms);
169
170 void komeda_crtc_handle_event(struct komeda_crtc   *kcrtc,
171                               struct komeda_events *evts);
172
173 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev);
174 void komeda_kms_detach(struct komeda_kms_dev *kms);
175
176 #endif /*_KOMEDA_KMS_H_*/