1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015 MediaTek Inc.
4  */
5 
6 #ifndef MTK_DRM_DDP_COMP_H
7 #define MTK_DRM_DDP_COMP_H
8 
9 #include <linux/io.h>
10 #include <linux/soc/mediatek/mtk-cmdq.h>
11 #include <linux/soc/mediatek/mtk-mmsys.h>
12 
13 struct device;
14 struct device_node;
15 struct drm_crtc;
16 struct drm_device;
17 struct mtk_plane_state;
18 struct drm_crtc_state;
19 
20 enum mtk_ddp_comp_type {
21 	MTK_DISP_AAL,
22 	MTK_DISP_BLS,
23 	MTK_DISP_CCORR,
24 	MTK_DISP_COLOR,
25 	MTK_DISP_DITHER,
26 	MTK_DISP_GAMMA,
27 	MTK_DISP_MUTEX,
28 	MTK_DISP_OD,
29 	MTK_DISP_OVL,
30 	MTK_DISP_OVL_2L,
31 	MTK_DISP_POSTMASK,
32 	MTK_DISP_PWM,
33 	MTK_DISP_RDMA,
34 	MTK_DISP_UFOE,
35 	MTK_DISP_WDMA,
36 	MTK_DPI,
37 	MTK_DSI,
38 	MTK_DDP_COMP_TYPE_MAX,
39 };
40 
41 struct mtk_ddp_comp;
42 struct cmdq_pkt;
43 struct mtk_ddp_comp_funcs {
44 	int (*clk_enable)(struct device *dev);
45 	void (*clk_disable)(struct device *dev);
46 	void (*config)(struct device *dev, unsigned int w,
47 		       unsigned int h, unsigned int vrefresh,
48 		       unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
49 	void (*start)(struct device *dev);
50 	void (*stop)(struct device *dev);
51 	void (*register_vblank_cb)(struct device *dev,
52 				   void (*vblank_cb)(void *),
53 				   void *vblank_cb_data);
54 	void (*unregister_vblank_cb)(struct device *dev);
55 	void (*enable_vblank)(struct device *dev);
56 	void (*disable_vblank)(struct device *dev);
57 	unsigned int (*supported_rotations)(struct device *dev);
58 	unsigned int (*layer_nr)(struct device *dev);
59 	int (*layer_check)(struct device *dev,
60 			   unsigned int idx,
61 			   struct mtk_plane_state *state);
62 	void (*layer_config)(struct device *dev, unsigned int idx,
63 			     struct mtk_plane_state *state,
64 			     struct cmdq_pkt *cmdq_pkt);
65 	void (*gamma_set)(struct device *dev,
66 			  struct drm_crtc_state *state);
67 	void (*bgclr_in_on)(struct device *dev);
68 	void (*bgclr_in_off)(struct device *dev);
69 	void (*ctm_set)(struct device *dev,
70 			struct drm_crtc_state *state);
71 };
72 
73 struct mtk_ddp_comp {
74 	struct device *dev;
75 	int irq;
76 	enum mtk_ddp_comp_id id;
77 	const struct mtk_ddp_comp_funcs *funcs;
78 };
79 
80 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
81 {
82 	if (comp->funcs && comp->funcs->clk_enable)
83 		return comp->funcs->clk_enable(comp->dev);
84 
85 	return 0;
86 }
87 
88 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
89 {
90 	if (comp->funcs && comp->funcs->clk_disable)
91 		comp->funcs->clk_disable(comp->dev);
92 }
93 
94 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
95 				       unsigned int w, unsigned int h,
96 				       unsigned int vrefresh, unsigned int bpc,
97 				       struct cmdq_pkt *cmdq_pkt)
98 {
99 	if (comp->funcs && comp->funcs->config)
100 		comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
101 }
102 
103 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
104 {
105 	if (comp->funcs && comp->funcs->start)
106 		comp->funcs->start(comp->dev);
107 }
108 
109 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
110 {
111 	if (comp->funcs && comp->funcs->stop)
112 		comp->funcs->stop(comp->dev);
113 }
114 
115 static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
116 						   void (*vblank_cb)(void *),
117 						   void *vblank_cb_data)
118 {
119 	if (comp->funcs && comp->funcs->register_vblank_cb)
120 		comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
121 						vblank_cb_data);
122 }
123 
124 static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
125 {
126 	if (comp->funcs && comp->funcs->unregister_vblank_cb)
127 		comp->funcs->unregister_vblank_cb(comp->dev);
128 }
129 
130 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
131 {
132 	if (comp->funcs && comp->funcs->enable_vblank)
133 		comp->funcs->enable_vblank(comp->dev);
134 }
135 
136 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
137 {
138 	if (comp->funcs && comp->funcs->disable_vblank)
139 		comp->funcs->disable_vblank(comp->dev);
140 }
141 
142 static inline
143 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
144 {
145 	if (comp->funcs && comp->funcs->supported_rotations)
146 		return comp->funcs->supported_rotations(comp->dev);
147 
148 	return 0;
149 }
150 
151 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
152 {
153 	if (comp->funcs && comp->funcs->layer_nr)
154 		return comp->funcs->layer_nr(comp->dev);
155 
156 	return 0;
157 }
158 
159 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
160 					   unsigned int idx,
161 					   struct mtk_plane_state *state)
162 {
163 	if (comp->funcs && comp->funcs->layer_check)
164 		return comp->funcs->layer_check(comp->dev, idx, state);
165 	return 0;
166 }
167 
168 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
169 					     unsigned int idx,
170 					     struct mtk_plane_state *state,
171 					     struct cmdq_pkt *cmdq_pkt)
172 {
173 	if (comp->funcs && comp->funcs->layer_config)
174 		comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
175 }
176 
177 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
178 				     struct drm_crtc_state *state)
179 {
180 	if (comp->funcs && comp->funcs->gamma_set)
181 		comp->funcs->gamma_set(comp->dev, state);
182 }
183 
184 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
185 {
186 	if (comp->funcs && comp->funcs->bgclr_in_on)
187 		comp->funcs->bgclr_in_on(comp->dev);
188 }
189 
190 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
191 {
192 	if (comp->funcs && comp->funcs->bgclr_in_off)
193 		comp->funcs->bgclr_in_off(comp->dev);
194 }
195 
196 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
197 				   struct drm_crtc_state *state)
198 {
199 	if (comp->funcs && comp->funcs->ctm_set)
200 		comp->funcs->ctm_set(comp->dev, state);
201 }
202 
203 int mtk_ddp_comp_get_id(struct device_node *node,
204 			enum mtk_ddp_comp_type comp_type);
205 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
206 						struct device *dev);
207 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
208 		      enum mtk_ddp_comp_id comp_id);
209 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
210 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
211 		   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
212 		   unsigned int offset);
213 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
214 			   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
215 			   unsigned int offset);
216 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
217 			struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
218 			unsigned int offset, unsigned int mask);
219 #endif /* MTK_DRM_DDP_COMP_H */
220