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 <drm/drm_atomic.h>
11 #include <drm/drm_atomic_helper.h>
12 #include <drm/drm_crtc_helper.h>
13 #include <drm/drm_device.h>
14 #include <drm/drm_writeback.h>
15 
16 /** struct komeda_plane - komeda instance of drm_plane */
17 struct komeda_plane {
18 	/** @base: &drm_plane */
19 	struct drm_plane base;
20 	/**
21 	 * @layer:
22 	 *
23 	 * represents available layer input pipelines for this plane.
24 	 *
25 	 * NOTE:
26 	 * the layer is not for a specific Layer, but indicate a group of
27 	 * Layers with same capabilities.
28 	 */
29 	struct komeda_layer *layer;
30 };
31 
32 /**
33  * struct komeda_plane_state
34  *
35  * The plane_state can be split into two data flow (left/right) and handled
36  * by two layers &komeda_plane.layer and &komeda_plane.layer.right
37  */
38 struct komeda_plane_state {
39 	/** @base: &drm_plane_state */
40 	struct drm_plane_state base;
41 
42 	/* private properties */
43 };
44 
45 /**
46  * struct komeda_wb_connector
47  */
48 struct komeda_wb_connector {
49 	/** @base: &drm_writeback_connector */
50 	struct drm_writeback_connector base;
51 
52 	/** @wb_layer: represents associated writeback pipeline of komeda */
53 	struct komeda_layer *wb_layer;
54 };
55 
56 /**
57  * struct komeda_crtc
58  */
59 struct komeda_crtc {
60 	/** @base: &drm_crtc */
61 	struct drm_crtc base;
62 	/** @master: only master has display output */
63 	struct komeda_pipeline *master;
64 	/**
65 	 * @slave: optional
66 	 *
67 	 * Doesn't have its own display output, the handled data flow will
68 	 * merge into the master.
69 	 */
70 	struct komeda_pipeline *slave;
71 };
72 
73 /** struct komeda_crtc_state */
74 struct komeda_crtc_state {
75 	/** @base: &drm_crtc_state */
76 	struct drm_crtc_state base;
77 
78 	/* private properties */
79 
80 	/* computed state which are used by validate/check */
81 	u32 affected_pipes;
82 	u32 active_pipes;
83 };
84 
85 /** struct komeda_kms_dev - for gather KMS related things */
86 struct komeda_kms_dev {
87 	/** @base: &drm_device */
88 	struct drm_device base;
89 
90 	/** @n_crtcs: valid numbers of crtcs in &komeda_kms_dev.crtcs */
91 	int n_crtcs;
92 	/** @crtcs: crtcs list */
93 	struct komeda_crtc crtcs[KOMEDA_MAX_PIPELINES];
94 };
95 
96 #define to_kplane(p)	container_of(p, struct komeda_plane, base)
97 #define to_kplane_st(p)	container_of(p, struct komeda_plane_state, base)
98 #define to_kconn(p)	container_of(p, struct komeda_wb_connector, base)
99 #define to_kcrtc(p)	container_of(p, struct komeda_crtc, base)
100 #define to_kcrtc_st(p)	container_of(p, struct komeda_crtc_state, base)
101 #define to_kdev(p)	container_of(p, struct komeda_kms_dev, base)
102 
103 int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
104 
105 int komeda_kms_add_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
106 int komeda_kms_add_planes(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
107 int komeda_kms_add_private_objs(struct komeda_kms_dev *kms,
108 				struct komeda_dev *mdev);
109 void komeda_kms_cleanup_private_objs(struct komeda_dev *mdev);
110 
111 struct komeda_kms_dev *komeda_kms_attach(struct komeda_dev *mdev);
112 void komeda_kms_detach(struct komeda_kms_dev *kms);
113 
114 #endif /*_KOMEDA_KMS_H_*/
115