1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2015 MediaTek Inc.
6 #ifndef MTK_DRM_DDP_COMP_H
7 #define MTK_DRM_DDP_COMP_H
10 #include <linux/soc/mediatek/mtk-mmsys.h>
16 struct mtk_plane_state
;
17 struct drm_crtc_state
;
19 enum mtk_ddp_comp_type
{
36 MTK_DDP_COMP_TYPE_MAX
,
41 struct mtk_ddp_comp_funcs
{
42 void (*config
)(struct mtk_ddp_comp
*comp
, unsigned int w
,
43 unsigned int h
, unsigned int vrefresh
,
44 unsigned int bpc
, struct cmdq_pkt
*cmdq_pkt
);
45 void (*start
)(struct mtk_ddp_comp
*comp
);
46 void (*stop
)(struct mtk_ddp_comp
*comp
);
47 void (*enable_vblank
)(struct mtk_ddp_comp
*comp
, struct drm_crtc
*crtc
);
48 void (*disable_vblank
)(struct mtk_ddp_comp
*comp
);
49 unsigned int (*supported_rotations
)(struct mtk_ddp_comp
*comp
);
50 unsigned int (*layer_nr
)(struct mtk_ddp_comp
*comp
);
51 int (*layer_check
)(struct mtk_ddp_comp
*comp
,
53 struct mtk_plane_state
*state
);
54 void (*layer_config
)(struct mtk_ddp_comp
*comp
, unsigned int idx
,
55 struct mtk_plane_state
*state
,
56 struct cmdq_pkt
*cmdq_pkt
);
57 void (*gamma_set
)(struct mtk_ddp_comp
*comp
,
58 struct drm_crtc_state
*state
);
59 void (*bgclr_in_on
)(struct mtk_ddp_comp
*comp
);
60 void (*bgclr_in_off
)(struct mtk_ddp_comp
*comp
);
61 void (*ctm_set
)(struct mtk_ddp_comp
*comp
,
62 struct drm_crtc_state
*state
);
69 struct device
*larb_dev
;
70 enum mtk_ddp_comp_id id
;
71 const struct mtk_ddp_comp_funcs
*funcs
;
72 resource_size_t regs_pa
;
76 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp
*comp
,
77 unsigned int w
, unsigned int h
,
78 unsigned int vrefresh
, unsigned int bpc
,
79 struct cmdq_pkt
*cmdq_pkt
)
81 if (comp
->funcs
&& comp
->funcs
->config
)
82 comp
->funcs
->config(comp
, w
, h
, vrefresh
, bpc
, cmdq_pkt
);
85 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp
*comp
)
87 if (comp
->funcs
&& comp
->funcs
->start
)
88 comp
->funcs
->start(comp
);
91 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp
*comp
)
93 if (comp
->funcs
&& comp
->funcs
->stop
)
94 comp
->funcs
->stop(comp
);
97 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp
*comp
,
98 struct drm_crtc
*crtc
)
100 if (comp
->funcs
&& comp
->funcs
->enable_vblank
)
101 comp
->funcs
->enable_vblank(comp
, crtc
);
104 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp
*comp
)
106 if (comp
->funcs
&& comp
->funcs
->disable_vblank
)
107 comp
->funcs
->disable_vblank(comp
);
111 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp
*comp
)
113 if (comp
->funcs
&& comp
->funcs
->supported_rotations
)
114 return comp
->funcs
->supported_rotations(comp
);
119 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp
*comp
)
121 if (comp
->funcs
&& comp
->funcs
->layer_nr
)
122 return comp
->funcs
->layer_nr(comp
);
127 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp
*comp
,
129 struct mtk_plane_state
*state
)
131 if (comp
->funcs
&& comp
->funcs
->layer_check
)
132 return comp
->funcs
->layer_check(comp
, idx
, state
);
136 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp
*comp
,
138 struct mtk_plane_state
*state
,
139 struct cmdq_pkt
*cmdq_pkt
)
141 if (comp
->funcs
&& comp
->funcs
->layer_config
)
142 comp
->funcs
->layer_config(comp
, idx
, state
, cmdq_pkt
);
145 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp
*comp
,
146 struct drm_crtc_state
*state
)
148 if (comp
->funcs
&& comp
->funcs
->gamma_set
)
149 comp
->funcs
->gamma_set(comp
, state
);
152 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp
*comp
)
154 if (comp
->funcs
&& comp
->funcs
->bgclr_in_on
)
155 comp
->funcs
->bgclr_in_on(comp
);
158 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp
*comp
)
160 if (comp
->funcs
&& comp
->funcs
->bgclr_in_off
)
161 comp
->funcs
->bgclr_in_off(comp
);
164 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp
*comp
,
165 struct drm_crtc_state
*state
)
167 if (comp
->funcs
&& comp
->funcs
->ctm_set
)
168 comp
->funcs
->ctm_set(comp
, state
);
171 int mtk_ddp_comp_get_id(struct device_node
*node
,
172 enum mtk_ddp_comp_type comp_type
);
173 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device
*drm
,
174 struct mtk_ddp_comp ddp_comp
);
175 int mtk_ddp_comp_init(struct device
*dev
, struct device_node
*comp_node
,
176 struct mtk_ddp_comp
*comp
, enum mtk_ddp_comp_id comp_id
,
177 const struct mtk_ddp_comp_funcs
*funcs
);
178 int mtk_ddp_comp_register(struct drm_device
*drm
, struct mtk_ddp_comp
*comp
);
179 void mtk_ddp_comp_unregister(struct drm_device
*drm
, struct mtk_ddp_comp
*comp
);
180 void mtk_dither_set(struct mtk_ddp_comp
*comp
, unsigned int bpc
,
181 unsigned int CFG
, struct cmdq_pkt
*cmdq_pkt
);
182 enum mtk_ddp_comp_type
mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id
);
183 void mtk_ddp_write(struct cmdq_pkt
*cmdq_pkt
, unsigned int value
,
184 struct mtk_ddp_comp
*comp
, unsigned int offset
);
185 void mtk_ddp_write_relaxed(struct cmdq_pkt
*cmdq_pkt
, unsigned int value
,
186 struct mtk_ddp_comp
*comp
, unsigned int offset
);
187 void mtk_ddp_write_mask(struct cmdq_pkt
*cmdq_pkt
, unsigned int value
,
188 struct mtk_ddp_comp
*comp
, unsigned int offset
,
190 #endif /* MTK_DRM_DDP_COMP_H */