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