1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * R-Car Display Unit Planes
4  *
5  * Copyright (C) 2013-2014 Renesas Electronics Corporation
6  *
7  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8  */
9 
10 #ifndef __RCAR_DU_PLANE_H__
11 #define __RCAR_DU_PLANE_H__
12 
13 #include <drm/drm_plane.h>
14 
15 struct rcar_du_format_info;
16 struct rcar_du_group;
17 
18 /*
19  * The RCAR DU has 8 hardware planes, shared between primary and overlay planes.
20  * As using overlay planes requires at least one of the CRTCs being enabled, no
21  * more than 7 overlay planes can be available. We thus create 1 primary plane
22  * per CRTC and 7 overlay planes, for a total of up to 9 KMS planes.
23  */
24 #define RCAR_DU_NUM_KMS_PLANES		9
25 #define RCAR_DU_NUM_HW_PLANES		8
26 
27 enum rcar_du_plane_source {
28 	RCAR_DU_PLANE_MEMORY,
29 	RCAR_DU_PLANE_VSPD0,
30 	RCAR_DU_PLANE_VSPD1,
31 };
32 
33 struct rcar_du_plane {
34 	struct drm_plane plane;
35 	struct rcar_du_group *group;
36 };
37 
38 static inline struct rcar_du_plane *to_rcar_plane(struct drm_plane *plane)
39 {
40 	return container_of(plane, struct rcar_du_plane, plane);
41 }
42 
43 /**
44  * struct rcar_du_plane_state - Driver-specific plane state
45  * @state: base DRM plane state
46  * @format: information about the pixel format used by the plane
47  * @hwindex: 0-based hardware plane index, -1 means unused
48  * @colorkey: value of the plane colorkey property
49  */
50 struct rcar_du_plane_state {
51 	struct drm_plane_state state;
52 
53 	const struct rcar_du_format_info *format;
54 	int hwindex;
55 	enum rcar_du_plane_source source;
56 
57 	unsigned int colorkey;
58 };
59 
60 static inline struct rcar_du_plane_state *
61 to_rcar_plane_state(struct drm_plane_state *state)
62 {
63 	return container_of(state, struct rcar_du_plane_state, state);
64 }
65 
66 int rcar_du_atomic_check_planes(struct drm_device *dev,
67 				struct drm_atomic_state *state);
68 
69 int __rcar_du_plane_atomic_check(struct drm_plane *plane,
70 				 struct drm_plane_state *state,
71 				 const struct rcar_du_format_info **format);
72 
73 int rcar_du_planes_init(struct rcar_du_group *rgrp);
74 
75 void __rcar_du_plane_setup(struct rcar_du_group *rgrp,
76 			   const struct rcar_du_plane_state *state);
77 
78 static inline void rcar_du_plane_setup(struct rcar_du_plane *plane)
79 {
80 	struct rcar_du_plane_state *state =
81 		to_rcar_plane_state(plane->plane.state);
82 
83 	return __rcar_du_plane_setup(plane->group, state);
84 }
85 
86 #endif /* __RCAR_DU_PLANE_H__ */
87