1 /* SPDX-License-Identifier: GPL-2.0 */
3 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4 * Author: James.Qian.Wang <james.qian.wang@arm.com>
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>
19 * struct komeda_plane - komeda instance of drm_plane
22 /** @base: &drm_plane */
23 struct drm_plane base
;
27 * represents available layer input pipelines for this plane.
30 * the layer is not for a specific Layer, but indicate a group of
31 * Layers with same capabilities.
33 struct komeda_layer
*layer
;
37 * struct komeda_plane_state
39 * The plane_state can be split into two data flow (left/right) and handled
40 * by two layers &komeda_plane.layer and &komeda_plane.layer.right
42 struct komeda_plane_state
{
43 /** @base: &drm_plane_state */
44 struct drm_plane_state base
;
45 /** @zlist_node: zorder list node */
46 struct list_head zlist_node
;
48 /** @layer_split: on/off layer_split */
53 * struct komeda_wb_connector
55 struct komeda_wb_connector
{
56 /** @base: &drm_writeback_connector */
57 struct drm_writeback_connector base
;
59 /** @wb_layer: represents associated writeback pipeline of komeda */
60 struct komeda_layer
*wb_layer
;
67 /** @base: &drm_crtc */
69 /** @master: only master has display output */
70 struct komeda_pipeline
*master
;
74 * Doesn't have its own display output, the handled data flow will
75 * merge into the master.
77 struct komeda_pipeline
*slave
;
79 /** @slave_planes: komeda slave planes mask */
82 /** @wb_conn: komeda write back connector */
83 struct komeda_wb_connector
*wb_conn
;
85 /** @disable_done: this flip_done is for tracing the disable */
86 struct completion
*disable_done
;
90 * struct komeda_crtc_state
92 struct komeda_crtc_state
{
93 /** @base: &drm_crtc_state */
94 struct drm_crtc_state base
;
96 /* private properties */
98 /* computed state which are used by validate/check */
101 * the affected pipelines in once display instance
106 * the active pipelines in once display instance
110 /** @clock_ratio: ratio of (aclk << 32)/pxlclk */
113 /** @max_slave_zorder: the maximum of slave zorder */
114 u32 max_slave_zorder
;
117 /** struct komeda_kms_dev - for gather KMS related things */
118 struct komeda_kms_dev
{
119 /** @base: &drm_device */
120 struct drm_device base
;
122 /** @n_crtcs: valid numbers of crtcs in &komeda_kms_dev.crtcs */
124 /** @crtcs: crtcs list */
125 struct komeda_crtc crtcs
[KOMEDA_MAX_PIPELINES
];
128 #define to_kplane(p) container_of(p, struct komeda_plane, base)
129 #define to_kplane_st(p) container_of(p, struct komeda_plane_state, base)
130 #define to_kconn(p) container_of(p, struct komeda_wb_connector, base)
131 #define to_kcrtc(p) container_of(p, struct komeda_crtc, base)
132 #define to_kcrtc_st(p) container_of(p, struct komeda_crtc_state, base)
133 #define to_kdev(p) container_of(p, struct komeda_kms_dev, base)
134 #define to_wb_conn(x) container_of(x, struct drm_writeback_connector, base)
136 static inline bool is_writeback_only(struct drm_crtc_state
*st
)
138 struct komeda_wb_connector
*wb_conn
= to_kcrtc(st
->crtc
)->wb_conn
;
139 struct drm_connector
*conn
= wb_conn
? &wb_conn
->base
.base
: NULL
;
141 return conn
&& (st
->connector_mask
== BIT(drm_connector_index(conn
)));
145 is_only_changed_connector(struct drm_crtc_state
*st
, struct drm_connector
*conn
)
147 struct drm_crtc_state
*old_st
;
148 u32 changed_connectors
;
150 old_st
= drm_atomic_get_old_crtc_state(st
->state
, st
->crtc
);
151 changed_connectors
= st
->connector_mask
^ old_st
->connector_mask
;
153 return BIT(drm_connector_index(conn
)) == changed_connectors
;
156 static inline bool has_flip_h(u32 rot
)
158 u32 rotation
= drm_rotation_simplify(rot
,
161 DRM_MODE_REFLECT_MASK
);
163 if (rotation
& DRM_MODE_ROTATE_90
)
164 return !!(rotation
& DRM_MODE_REFLECT_Y
);
166 return !!(rotation
& DRM_MODE_REFLECT_X
);
169 void komeda_crtc_get_color_config(struct drm_crtc_state
*crtc_st
,
170 u32
*color_depths
, u32
*color_formats
);
171 unsigned long komeda_crtc_get_aclk(struct komeda_crtc_state
*kcrtc_st
);
173 int komeda_kms_setup_crtcs(struct komeda_kms_dev
*kms
, struct komeda_dev
*mdev
);
175 int komeda_kms_add_crtcs(struct komeda_kms_dev
*kms
, struct komeda_dev
*mdev
);
176 int komeda_kms_add_planes(struct komeda_kms_dev
*kms
, struct komeda_dev
*mdev
);
177 int komeda_kms_add_private_objs(struct komeda_kms_dev
*kms
,
178 struct komeda_dev
*mdev
);
179 int komeda_kms_add_wb_connectors(struct komeda_kms_dev
*kms
,
180 struct komeda_dev
*mdev
);
181 void komeda_kms_cleanup_private_objs(struct komeda_kms_dev
*kms
);
183 void komeda_crtc_handle_event(struct komeda_crtc
*kcrtc
,
184 struct komeda_events
*evts
);
186 struct komeda_kms_dev
*komeda_kms_attach(struct komeda_dev
*mdev
);
187 void komeda_kms_detach(struct komeda_kms_dev
*kms
);
189 #endif /*_KOMEDA_KMS_H_*/