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>
17 #include <video/videomode.h>
18 #include <video/display_timing.h>
21 * struct komeda_plane - komeda instance of drm_plane
24 /** @base: &drm_plane */
25 struct drm_plane base;
29 * represents available layer input pipelines for this plane.
32 * the layer is not for a specific Layer, but indicate a group of
33 * Layers with same capabilities.
35 struct komeda_layer *layer;
37 /** @prop_img_enhancement: for on/off image enhancement */
38 struct drm_property *prop_img_enhancement;
42 * struct komeda_plane_state
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
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;
53 /* @img_enhancement: on/off image enhancement */
54 u8 img_enhancement : 1;
58 * struct komeda_wb_connector
60 struct komeda_wb_connector {
61 /** @base: &drm_writeback_connector */
62 struct drm_writeback_connector base;
64 /** @wb_layer: represents associated writeback pipeline of komeda */
65 struct komeda_layer *wb_layer;
72 /** @base: &drm_crtc */
74 /** @master: only master has display output */
75 struct komeda_pipeline *master;
79 * Doesn't have its own display output, the handled data flow will
80 * merge into the master.
82 struct komeda_pipeline *slave;
84 /** @wb_conn: komeda write back connector */
85 struct komeda_wb_connector *wb_conn;
87 /** @disable_done: this flip_done is for tracing the disable */
88 struct completion *disable_done;
90 /** @clock_ratio_property: property for ratio of (aclk << 32)/pxlclk */
91 struct drm_property *clock_ratio_property;
95 * struct komeda_crtc_state
97 struct komeda_crtc_state {
98 /** @base: &drm_crtc_state */
99 struct drm_crtc_state base;
101 /* private properties */
103 /* computed state which are used by validate/check */
106 * the affected pipelines in once display instance
111 * the active pipelines in once display instance
115 /** @clock_ratio: ratio of (aclk << 32)/pxlclk */
119 /** struct komeda_kms_dev - for gather KMS related things */
120 struct komeda_kms_dev {
121 /** @base: &drm_device */
122 struct drm_device base;
124 /** @n_crtcs: valid numbers of crtcs in &komeda_kms_dev.crtcs */
126 /** @crtcs: crtcs list */
127 struct komeda_crtc crtcs[KOMEDA_MAX_PIPELINES];
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)
138 static inline bool is_writeback_only(struct drm_crtc_state *st)
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;
143 return conn && (st->connector_mask == BIT(drm_connector_index(conn)));
147 is_only_changed_connector(struct drm_crtc_state *st, struct drm_connector *conn)
149 struct drm_crtc_state *old_st;
150 u32 changed_connectors;
152 old_st = drm_atomic_get_old_crtc_state(st->state, st->crtc);
153 changed_connectors = st->connector_mask ^ old_st->connector_mask;
155 return BIT(drm_connector_index(conn)) == changed_connectors;
158 unsigned long komeda_calc_aclk(struct komeda_crtc_state *kcrtc_st);
160 int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
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);
170 void komeda_crtc_handle_event(struct komeda_crtc *kcrtc,
171 struct komeda_events *evts);
173 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev);
174 void komeda_kms_detach(struct komeda_kms_dev *kms);
176 #endif /*_KOMEDA_KMS_H_*/