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 (*enable_vblank)(struct device *dev,
52 			      void (*vblank_cb)(void *),
53 			      void *vblank_cb_data);
54 	void (*disable_vblank)(struct device *dev);
55 	unsigned int (*supported_rotations)(struct device *dev);
56 	unsigned int (*layer_nr)(struct device *dev);
57 	int (*layer_check)(struct device *dev,
58 			   unsigned int idx,
59 			   struct mtk_plane_state *state);
60 	void (*layer_config)(struct device *dev, unsigned int idx,
61 			     struct mtk_plane_state *state,
62 			     struct cmdq_pkt *cmdq_pkt);
63 	void (*gamma_set)(struct device *dev,
64 			  struct drm_crtc_state *state);
65 	void (*bgclr_in_on)(struct device *dev);
66 	void (*bgclr_in_off)(struct device *dev);
67 	void (*ctm_set)(struct device *dev,
68 			struct drm_crtc_state *state);
69 };
70 
71 struct mtk_ddp_comp {
72 	struct device *dev;
73 	int irq;
74 	struct device *larb_dev;
75 	enum mtk_ddp_comp_id id;
76 	const struct mtk_ddp_comp_funcs *funcs;
77 };
78 
79 static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
80 {
81 	if (comp->funcs && comp->funcs->clk_enable)
82 		return comp->funcs->clk_enable(comp->dev);
83 
84 	return 0;
85 }
86 
87 static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
88 {
89 	if (comp->funcs && comp->funcs->clk_disable)
90 		comp->funcs->clk_disable(comp->dev);
91 }
92 
93 static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
94 				       unsigned int w, unsigned int h,
95 				       unsigned int vrefresh, unsigned int bpc,
96 				       struct cmdq_pkt *cmdq_pkt)
97 {
98 	if (comp->funcs && comp->funcs->config)
99 		comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
100 }
101 
102 static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
103 {
104 	if (comp->funcs && comp->funcs->start)
105 		comp->funcs->start(comp->dev);
106 }
107 
108 static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
109 {
110 	if (comp->funcs && comp->funcs->stop)
111 		comp->funcs->stop(comp->dev);
112 }
113 
114 static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp,
115 					      void (*vblank_cb)(void *),
116 					      void *vblank_cb_data)
117 {
118 	if (comp->funcs && comp->funcs->enable_vblank)
119 		comp->funcs->enable_vblank(comp->dev, vblank_cb, vblank_cb_data);
120 }
121 
122 static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
123 {
124 	if (comp->funcs && comp->funcs->disable_vblank)
125 		comp->funcs->disable_vblank(comp->dev);
126 }
127 
128 static inline
129 unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
130 {
131 	if (comp->funcs && comp->funcs->supported_rotations)
132 		return comp->funcs->supported_rotations(comp->dev);
133 
134 	return 0;
135 }
136 
137 static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
138 {
139 	if (comp->funcs && comp->funcs->layer_nr)
140 		return comp->funcs->layer_nr(comp->dev);
141 
142 	return 0;
143 }
144 
145 static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
146 					   unsigned int idx,
147 					   struct mtk_plane_state *state)
148 {
149 	if (comp->funcs && comp->funcs->layer_check)
150 		return comp->funcs->layer_check(comp->dev, idx, state);
151 	return 0;
152 }
153 
154 static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
155 					     unsigned int idx,
156 					     struct mtk_plane_state *state,
157 					     struct cmdq_pkt *cmdq_pkt)
158 {
159 	if (comp->funcs && comp->funcs->layer_config)
160 		comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
161 }
162 
163 static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
164 				     struct drm_crtc_state *state)
165 {
166 	if (comp->funcs && comp->funcs->gamma_set)
167 		comp->funcs->gamma_set(comp->dev, state);
168 }
169 
170 static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
171 {
172 	if (comp->funcs && comp->funcs->bgclr_in_on)
173 		comp->funcs->bgclr_in_on(comp->dev);
174 }
175 
176 static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
177 {
178 	if (comp->funcs && comp->funcs->bgclr_in_off)
179 		comp->funcs->bgclr_in_off(comp->dev);
180 }
181 
182 static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
183 				   struct drm_crtc_state *state)
184 {
185 	if (comp->funcs && comp->funcs->ctm_set)
186 		comp->funcs->ctm_set(comp->dev, state);
187 }
188 
189 int mtk_ddp_comp_get_id(struct device_node *node,
190 			enum mtk_ddp_comp_type comp_type);
191 unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
192 						struct device *dev);
193 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
194 		      enum mtk_ddp_comp_id comp_id);
195 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
196 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
197 		   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
198 		   unsigned int offset);
199 void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
200 			   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
201 			   unsigned int offset);
202 void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
203 			struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
204 			unsigned int offset, unsigned int mask);
205 #endif /* MTK_DRM_DDP_COMP_H */
206