11802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2119f5173SCK Hu /*
3119f5173SCK Hu * Copyright (c) 2015 MediaTek Inc.
4119f5173SCK Hu */
5119f5173SCK Hu
6119f5173SCK Hu #ifndef MTK_DRM_DDP_COMP_H
7119f5173SCK Hu #define MTK_DRM_DDP_COMP_H
8119f5173SCK Hu
9119f5173SCK Hu #include <linux/io.h>
10f22a565dSCK Hu #include <linux/soc/mediatek/mtk-cmdq.h>
1151c0e618SYongqiang Niu #include <linux/soc/mediatek/mtk-mmsys.h>
12*0d9eee91SNancy.Lin #include <linux/soc/mediatek/mtk-mutex.h>
13119f5173SCK Hu
14119f5173SCK Hu struct device;
15119f5173SCK Hu struct device_node;
16119f5173SCK Hu struct drm_crtc;
17119f5173SCK Hu struct drm_device;
18119f5173SCK Hu struct mtk_plane_state;
192f3f4ddaSBibby Hsieh struct drm_crtc_state;
20119f5173SCK Hu
21119f5173SCK Hu enum mtk_ddp_comp_type {
22119f5173SCK Hu MTK_DISP_AAL,
2373d37247Sjason-jh.lin MTK_DISP_BLS,
2473d37247Sjason-jh.lin MTK_DISP_CCORR,
2573d37247Sjason-jh.lin MTK_DISP_COLOR,
2673d37247Sjason-jh.lin MTK_DISP_DITHER,
27b7fb767bSjason-jh.lin MTK_DISP_DSC,
28119f5173SCK Hu MTK_DISP_GAMMA,
29bd448b88Sjason-jh.lin MTK_DISP_MERGE,
30119f5173SCK Hu MTK_DISP_MUTEX,
31119f5173SCK Hu MTK_DISP_OD,
3273d37247Sjason-jh.lin MTK_DISP_OVL,
3373d37247Sjason-jh.lin MTK_DISP_OVL_2L,
34*0d9eee91SNancy.Lin MTK_DISP_OVL_ADAPTOR,
3573d37247Sjason-jh.lin MTK_DISP_POSTMASK,
3673d37247Sjason-jh.lin MTK_DISP_PWM,
3773d37247Sjason-jh.lin MTK_DISP_RDMA,
3873d37247Sjason-jh.lin MTK_DISP_UFOE,
3973d37247Sjason-jh.lin MTK_DISP_WDMA,
4073d37247Sjason-jh.lin MTK_DPI,
41d86c1568SGuillaume Ranquet MTK_DP_INTF,
4273d37247Sjason-jh.lin MTK_DSI,
43119f5173SCK Hu MTK_DDP_COMP_TYPE_MAX,
44119f5173SCK Hu };
45119f5173SCK Hu
46119f5173SCK Hu struct mtk_ddp_comp;
47d0afe37fSBibby Hsieh struct cmdq_pkt;
48119f5173SCK Hu struct mtk_ddp_comp_funcs {
49c0d36de8SCK Hu int (*clk_enable)(struct device *dev);
50c0d36de8SCK Hu void (*clk_disable)(struct device *dev);
514d510659SCK Hu void (*config)(struct device *dev, unsigned int w,
52d0afe37fSBibby Hsieh unsigned int h, unsigned int vrefresh,
53d0afe37fSBibby Hsieh unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
544d510659SCK Hu void (*start)(struct device *dev);
554d510659SCK Hu void (*stop)(struct device *dev);
56b74d921bSRex-BC Chen void (*register_vblank_cb)(struct device *dev,
579b070498SCK Hu void (*vblank_cb)(void *),
589b070498SCK Hu void *vblank_cb_data);
59b74d921bSRex-BC Chen void (*unregister_vblank_cb)(struct device *dev);
60b74d921bSRex-BC Chen void (*enable_vblank)(struct device *dev);
614d510659SCK Hu void (*disable_vblank)(struct device *dev);
624d510659SCK Hu unsigned int (*supported_rotations)(struct device *dev);
634d510659SCK Hu unsigned int (*layer_nr)(struct device *dev);
644d510659SCK Hu int (*layer_check)(struct device *dev,
65f7c710d1SSean Paul unsigned int idx,
66f7c710d1SSean Paul struct mtk_plane_state *state);
674d510659SCK Hu void (*layer_config)(struct device *dev, unsigned int idx,
68d0afe37fSBibby Hsieh struct mtk_plane_state *state,
69d0afe37fSBibby Hsieh struct cmdq_pkt *cmdq_pkt);
704d510659SCK Hu void (*gamma_set)(struct device *dev,
712f3f4ddaSBibby Hsieh struct drm_crtc_state *state);
724d510659SCK Hu void (*bgclr_in_on)(struct device *dev);
734d510659SCK Hu void (*bgclr_in_off)(struct device *dev);
744d510659SCK Hu void (*ctm_set)(struct device *dev,
7584abcf12SYongqiang Niu struct drm_crtc_state *state);
76cb1d6bccSNancy.Lin struct device * (*dma_dev_get)(struct device *dev);
77f287c66aSJustin Green const u32 *(*get_formats)(struct device *dev);
78f287c66aSJustin Green size_t (*get_num_formats)(struct device *dev);
79*0d9eee91SNancy.Lin void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
80*0d9eee91SNancy.Lin void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
81*0d9eee91SNancy.Lin void (*add)(struct device *dev, struct mtk_mutex *mutex);
82*0d9eee91SNancy.Lin void (*remove)(struct device *dev, struct mtk_mutex *mutex);
83119f5173SCK Hu };
84119f5173SCK Hu
85119f5173SCK Hu struct mtk_ddp_comp {
86c0d36de8SCK Hu struct device *dev;
87119f5173SCK Hu int irq;
88*0d9eee91SNancy.Lin unsigned int id;
89119f5173SCK Hu const struct mtk_ddp_comp_funcs *funcs;
90119f5173SCK Hu };
91119f5173SCK Hu
mtk_ddp_comp_clk_enable(struct mtk_ddp_comp * comp)92c0d36de8SCK Hu static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
93c0d36de8SCK Hu {
94c0d36de8SCK Hu if (comp->funcs && comp->funcs->clk_enable)
95c0d36de8SCK Hu return comp->funcs->clk_enable(comp->dev);
96c0d36de8SCK Hu
97c0d36de8SCK Hu return 0;
98c0d36de8SCK Hu }
99c0d36de8SCK Hu
mtk_ddp_comp_clk_disable(struct mtk_ddp_comp * comp)100c0d36de8SCK Hu static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
101c0d36de8SCK Hu {
102c0d36de8SCK Hu if (comp->funcs && comp->funcs->clk_disable)
103c0d36de8SCK Hu comp->funcs->clk_disable(comp->dev);
104c0d36de8SCK Hu }
105c0d36de8SCK Hu
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)106119f5173SCK Hu static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
107119f5173SCK Hu unsigned int w, unsigned int h,
108d0afe37fSBibby Hsieh unsigned int vrefresh, unsigned int bpc,
109d0afe37fSBibby Hsieh struct cmdq_pkt *cmdq_pkt)
110119f5173SCK Hu {
111119f5173SCK Hu if (comp->funcs && comp->funcs->config)
1124d510659SCK Hu comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
113119f5173SCK Hu }
114119f5173SCK Hu
mtk_ddp_comp_start(struct mtk_ddp_comp * comp)115119f5173SCK Hu static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
116119f5173SCK Hu {
117119f5173SCK Hu if (comp->funcs && comp->funcs->start)
1184d510659SCK Hu comp->funcs->start(comp->dev);
119119f5173SCK Hu }
120119f5173SCK Hu
mtk_ddp_comp_stop(struct mtk_ddp_comp * comp)121119f5173SCK Hu static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
122119f5173SCK Hu {
123119f5173SCK Hu if (comp->funcs && comp->funcs->stop)
1244d510659SCK Hu comp->funcs->stop(comp->dev);
125119f5173SCK Hu }
126119f5173SCK Hu
mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp * comp,void (* vblank_cb)(void *),void * vblank_cb_data)127b74d921bSRex-BC Chen static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
1289b070498SCK Hu void (*vblank_cb)(void *),
1299b070498SCK Hu void *vblank_cb_data)
130119f5173SCK Hu {
131b74d921bSRex-BC Chen if (comp->funcs && comp->funcs->register_vblank_cb)
132b74d921bSRex-BC Chen comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
133b74d921bSRex-BC Chen vblank_cb_data);
134b74d921bSRex-BC Chen }
135b74d921bSRex-BC Chen
mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp * comp)136b74d921bSRex-BC Chen static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
137b74d921bSRex-BC Chen {
138b74d921bSRex-BC Chen if (comp->funcs && comp->funcs->unregister_vblank_cb)
139b74d921bSRex-BC Chen comp->funcs->unregister_vblank_cb(comp->dev);
140b74d921bSRex-BC Chen }
141b74d921bSRex-BC Chen
mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp * comp)142b74d921bSRex-BC Chen static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
143b74d921bSRex-BC Chen {
144119f5173SCK Hu if (comp->funcs && comp->funcs->enable_vblank)
145b74d921bSRex-BC Chen comp->funcs->enable_vblank(comp->dev);
146119f5173SCK Hu }
147119f5173SCK Hu
mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp * comp)148119f5173SCK Hu static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
149119f5173SCK Hu {
150119f5173SCK Hu if (comp->funcs && comp->funcs->disable_vblank)
1514d510659SCK Hu comp->funcs->disable_vblank(comp->dev);
152119f5173SCK Hu }
153119f5173SCK Hu
154ef87d3e2SSean Paul static inline
mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp * comp)155ef87d3e2SSean Paul unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
156ef87d3e2SSean Paul {
157ef87d3e2SSean Paul if (comp->funcs && comp->funcs->supported_rotations)
1584d510659SCK Hu return comp->funcs->supported_rotations(comp->dev);
159ef87d3e2SSean Paul
160ef87d3e2SSean Paul return 0;
161ef87d3e2SSean Paul }
162ef87d3e2SSean Paul
mtk_ddp_comp_layer_nr(struct mtk_ddp_comp * comp)163650afd49SStu Hsieh static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
164650afd49SStu Hsieh {
165650afd49SStu Hsieh if (comp->funcs && comp->funcs->layer_nr)
1664d510659SCK Hu return comp->funcs->layer_nr(comp->dev);
167650afd49SStu Hsieh
168650afd49SStu Hsieh return 0;
169650afd49SStu Hsieh }
170650afd49SStu Hsieh
mtk_ddp_comp_layer_check(struct mtk_ddp_comp * comp,unsigned int idx,struct mtk_plane_state * state)171f7c710d1SSean Paul static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
172f7c710d1SSean Paul unsigned int idx,
173f7c710d1SSean Paul struct mtk_plane_state *state)
174f7c710d1SSean Paul {
175f7c710d1SSean Paul if (comp->funcs && comp->funcs->layer_check)
1764d510659SCK Hu return comp->funcs->layer_check(comp->dev, idx, state);
177f7c710d1SSean Paul return 0;
178f7c710d1SSean Paul }
179f7c710d1SSean Paul
mtk_ddp_comp_layer_config(struct mtk_ddp_comp * comp,unsigned int idx,struct mtk_plane_state * state,struct cmdq_pkt * cmdq_pkt)180119f5173SCK Hu static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
181119f5173SCK Hu unsigned int idx,
182d0afe37fSBibby Hsieh struct mtk_plane_state *state,
183d0afe37fSBibby Hsieh struct cmdq_pkt *cmdq_pkt)
184119f5173SCK Hu {
185119f5173SCK Hu if (comp->funcs && comp->funcs->layer_config)
1864d510659SCK Hu comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
187119f5173SCK Hu }
188119f5173SCK Hu
mtk_ddp_gamma_set(struct mtk_ddp_comp * comp,struct drm_crtc_state * state)1892f3f4ddaSBibby Hsieh static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
1902f3f4ddaSBibby Hsieh struct drm_crtc_state *state)
1912f3f4ddaSBibby Hsieh {
1922f3f4ddaSBibby Hsieh if (comp->funcs && comp->funcs->gamma_set)
1934d510659SCK Hu comp->funcs->gamma_set(comp->dev, state);
1942f3f4ddaSBibby Hsieh }
1952f3f4ddaSBibby Hsieh
mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp * comp)196132c6e25SYongqiang Niu static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
197132c6e25SYongqiang Niu {
198132c6e25SYongqiang Niu if (comp->funcs && comp->funcs->bgclr_in_on)
1994d510659SCK Hu comp->funcs->bgclr_in_on(comp->dev);
200132c6e25SYongqiang Niu }
201132c6e25SYongqiang Niu
mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp * comp)202132c6e25SYongqiang Niu static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
203132c6e25SYongqiang Niu {
204132c6e25SYongqiang Niu if (comp->funcs && comp->funcs->bgclr_in_off)
2054d510659SCK Hu comp->funcs->bgclr_in_off(comp->dev);
206132c6e25SYongqiang Niu }
207132c6e25SYongqiang Niu
mtk_ddp_ctm_set(struct mtk_ddp_comp * comp,struct drm_crtc_state * state)20884abcf12SYongqiang Niu static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
20984abcf12SYongqiang Niu struct drm_crtc_state *state)
21084abcf12SYongqiang Niu {
21184abcf12SYongqiang Niu if (comp->funcs && comp->funcs->ctm_set)
2124d510659SCK Hu comp->funcs->ctm_set(comp->dev, state);
21384abcf12SYongqiang Niu }
21484abcf12SYongqiang Niu
mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp * comp)215cb1d6bccSNancy.Lin static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
216cb1d6bccSNancy.Lin {
217cb1d6bccSNancy.Lin if (comp->funcs && comp->funcs->dma_dev_get)
218cb1d6bccSNancy.Lin return comp->funcs->dma_dev_get(comp->dev);
219cb1d6bccSNancy.Lin return comp->dev;
220cb1d6bccSNancy.Lin }
221cb1d6bccSNancy.Lin
222f287c66aSJustin Green static inline
mtk_ddp_comp_get_formats(struct mtk_ddp_comp * comp)223f287c66aSJustin Green const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
224f287c66aSJustin Green {
225f287c66aSJustin Green if (comp->funcs && comp->funcs->get_formats)
226f287c66aSJustin Green return comp->funcs->get_formats(comp->dev);
227f287c66aSJustin Green
228f287c66aSJustin Green return NULL;
229f287c66aSJustin Green }
230f287c66aSJustin Green
231f287c66aSJustin Green static inline
mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp * comp)232f287c66aSJustin Green size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
233f287c66aSJustin Green {
234f287c66aSJustin Green if (comp->funcs && comp->funcs->get_num_formats)
235f287c66aSJustin Green return comp->funcs->get_num_formats(comp->dev);
236f287c66aSJustin Green
237f287c66aSJustin Green return 0;
238f287c66aSJustin Green }
239f287c66aSJustin Green
mtk_ddp_comp_add(struct mtk_ddp_comp * comp,struct mtk_mutex * mutex)240*0d9eee91SNancy.Lin static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
241*0d9eee91SNancy.Lin {
242*0d9eee91SNancy.Lin if (comp->funcs && comp->funcs->add) {
243*0d9eee91SNancy.Lin comp->funcs->add(comp->dev, mutex);
244*0d9eee91SNancy.Lin return true;
245*0d9eee91SNancy.Lin }
246*0d9eee91SNancy.Lin return false;
247*0d9eee91SNancy.Lin }
248*0d9eee91SNancy.Lin
mtk_ddp_comp_remove(struct mtk_ddp_comp * comp,struct mtk_mutex * mutex)249*0d9eee91SNancy.Lin static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
250*0d9eee91SNancy.Lin {
251*0d9eee91SNancy.Lin if (comp->funcs && comp->funcs->remove) {
252*0d9eee91SNancy.Lin comp->funcs->remove(comp->dev, mutex);
253*0d9eee91SNancy.Lin return true;
254*0d9eee91SNancy.Lin }
255*0d9eee91SNancy.Lin return false;
256*0d9eee91SNancy.Lin }
257*0d9eee91SNancy.Lin
mtk_ddp_comp_connect(struct mtk_ddp_comp * comp,struct device * mmsys_dev,unsigned int next)258*0d9eee91SNancy.Lin static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
259*0d9eee91SNancy.Lin unsigned int next)
260*0d9eee91SNancy.Lin {
261*0d9eee91SNancy.Lin if (comp->funcs && comp->funcs->connect) {
262*0d9eee91SNancy.Lin comp->funcs->connect(comp->dev, mmsys_dev, next);
263*0d9eee91SNancy.Lin return true;
264*0d9eee91SNancy.Lin }
265*0d9eee91SNancy.Lin return false;
266*0d9eee91SNancy.Lin }
267*0d9eee91SNancy.Lin
mtk_ddp_comp_disconnect(struct mtk_ddp_comp * comp,struct device * mmsys_dev,unsigned int next)268*0d9eee91SNancy.Lin static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
269*0d9eee91SNancy.Lin unsigned int next)
270*0d9eee91SNancy.Lin {
271*0d9eee91SNancy.Lin if (comp->funcs && comp->funcs->disconnect) {
272*0d9eee91SNancy.Lin comp->funcs->disconnect(comp->dev, mmsys_dev, next);
273*0d9eee91SNancy.Lin return true;
274*0d9eee91SNancy.Lin }
275*0d9eee91SNancy.Lin return false;
276*0d9eee91SNancy.Lin }
277*0d9eee91SNancy.Lin
278119f5173SCK Hu int mtk_ddp_comp_get_id(struct device_node *node,
279119f5173SCK Hu enum mtk_ddp_comp_type comp_type);
2805aa8e764SStu Hsieh unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
281ff139560SCK Hu struct device *dev);
2826ea6f827SChun-Kuang Hu int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
283*0d9eee91SNancy.Lin unsigned int comp_id);
284*0d9eee91SNancy.Lin enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
285d0afe37fSBibby Hsieh void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
286616443caSCK Hu struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
2873c87daefSCK Hu unsigned int offset);
288d0afe37fSBibby Hsieh void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
289616443caSCK Hu struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
2903c87daefSCK Hu unsigned int offset);
291d0afe37fSBibby Hsieh void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
292616443caSCK Hu struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
2933c87daefSCK Hu unsigned int offset, unsigned int mask);
294119f5173SCK Hu #endif /* MTK_DRM_DDP_COMP_H */
295