Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  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/pm_runtime.h>
 11#include <linux/soc/mediatek/mtk-cmdq.h>
 12#include <linux/soc/mediatek/mtk-mmsys.h>
 13#include <linux/soc/mediatek/mtk-mutex.h>
 14
 15struct device;
 16struct device_node;
 17struct drm_crtc;
 18struct drm_device;
 19struct mtk_plane_state;
 20struct drm_crtc_state;
 21
 22enum mtk_ddp_comp_type {
 23	MTK_DISP_AAL,
 24	MTK_DISP_BLS,
 25	MTK_DISP_CCORR,
 26	MTK_DISP_COLOR,
 27	MTK_DISP_DITHER,
 28	MTK_DISP_DSC,
 29	MTK_DISP_GAMMA,
 30	MTK_DISP_MERGE,
 31	MTK_DISP_MUTEX,
 32	MTK_DISP_OD,
 33	MTK_DISP_OVL,
 34	MTK_DISP_OVL_2L,
 35	MTK_DISP_OVL_ADAPTOR,
 36	MTK_DISP_POSTMASK,
 37	MTK_DISP_PWM,
 38	MTK_DISP_RDMA,
 39	MTK_DISP_UFOE,
 40	MTK_DISP_WDMA,
 41	MTK_DPI,
 42	MTK_DP_INTF,
 43	MTK_DSI,
 44	MTK_DDP_COMP_TYPE_MAX,
 45};
 46
 47struct mtk_ddp_comp;
 48struct cmdq_pkt;
 49struct mtk_ddp_comp_funcs {
 50	int (*power_on)(struct device *dev);
 51	void (*power_off)(struct device *dev);
 52	int (*clk_enable)(struct device *dev);
 53	void (*clk_disable)(struct device *dev);
 54	void (*config)(struct device *dev, unsigned int w,
 55		       unsigned int h, unsigned int vrefresh,
 56		       unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
 57	void (*start)(struct device *dev);
 58	void (*stop)(struct device *dev);
 59	void (*register_vblank_cb)(struct device *dev,
 60				   void (*vblank_cb)(void *),
 61				   void *vblank_cb_data);
 62	void (*unregister_vblank_cb)(struct device *dev);
 63	void (*enable_vblank)(struct device *dev);
 64	void (*disable_vblank)(struct device *dev);
 65	unsigned int (*supported_rotations)(struct device *dev);
 66	unsigned int (*layer_nr)(struct device *dev);
 67	int (*layer_check)(struct device *dev,
 68			   unsigned int idx,
 69			   struct mtk_plane_state *state);
 70	void (*layer_config)(struct device *dev, unsigned int idx,
 71			     struct mtk_plane_state *state,
 72			     struct cmdq_pkt *cmdq_pkt);
 73	unsigned int (*gamma_get_lut_size)(struct device *dev);
 74	void (*gamma_set)(struct device *dev,
 75			  struct drm_crtc_state *state);
 76	void (*bgclr_in_on)(struct device *dev);
 77	void (*bgclr_in_off)(struct device *dev);
 78	void (*ctm_set)(struct device *dev,
 79			struct drm_crtc_state *state);
 80	struct device * (*dma_dev_get)(struct device *dev);
 81	const u32 *(*get_formats)(struct device *dev);
 82	size_t (*get_num_formats)(struct device *dev);
 83	void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
 84	void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
 85	void (*add)(struct device *dev, struct mtk_mutex *mutex);
 86	void (*remove)(struct device *dev, struct mtk_mutex *mutex);
 87	unsigned int (*encoder_index)(struct device *dev);
 88};
 89
 90struct mtk_ddp_comp {
 91	struct device *dev;
 92	int irq;
 93	unsigned int id;
 94	int encoder_index;
 95	const struct mtk_ddp_comp_funcs *funcs;
 96};
 97
 98static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
 99{
100	if (comp->funcs && comp->funcs->power_on)
101		return comp->funcs->power_on(comp->dev);
102	else
103		return pm_runtime_resume_and_get(comp->dev);
104	return 0;
105}
106
107static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
108{
109	if (comp->funcs && comp->funcs->power_off)
110		comp->funcs->power_off(comp->dev);
111	else
112		pm_runtime_put(comp->dev);
113}
114
115static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
116{
117	if (comp->funcs && comp->funcs->clk_enable)
118		return comp->funcs->clk_enable(comp->dev);
119
120	return 0;
121}
122
123static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
124{
125	if (comp->funcs && comp->funcs->clk_disable)
126		comp->funcs->clk_disable(comp->dev);
127}
128
129static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
130				       unsigned int w, unsigned int h,
131				       unsigned int vrefresh, unsigned int bpc,
132				       struct cmdq_pkt *cmdq_pkt)
133{
134	if (comp->funcs && comp->funcs->config)
135		comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
136}
137
138static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
139{
140	if (comp->funcs && comp->funcs->start)
141		comp->funcs->start(comp->dev);
142}
143
144static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
145{
146	if (comp->funcs && comp->funcs->stop)
147		comp->funcs->stop(comp->dev);
148}
149
150static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
151						   void (*vblank_cb)(void *),
152						   void *vblank_cb_data)
153{
154	if (comp->funcs && comp->funcs->register_vblank_cb)
155		comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
156						vblank_cb_data);
157}
158
159static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
160{
161	if (comp->funcs && comp->funcs->unregister_vblank_cb)
162		comp->funcs->unregister_vblank_cb(comp->dev);
163}
164
165static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
166{
167	if (comp->funcs && comp->funcs->enable_vblank)
168		comp->funcs->enable_vblank(comp->dev);
169}
170
171static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
172{
173	if (comp->funcs && comp->funcs->disable_vblank)
174		comp->funcs->disable_vblank(comp->dev);
175}
176
177static inline
178unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
179{
180	if (comp->funcs && comp->funcs->supported_rotations)
181		return comp->funcs->supported_rotations(comp->dev);
182
183	return 0;
184}
185
186static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
187{
188	if (comp->funcs && comp->funcs->layer_nr)
189		return comp->funcs->layer_nr(comp->dev);
190
191	return 0;
192}
193
194static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
195					   unsigned int idx,
196					   struct mtk_plane_state *state)
197{
198	if (comp->funcs && comp->funcs->layer_check)
199		return comp->funcs->layer_check(comp->dev, idx, state);
200	return 0;
201}
202
203static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
204					     unsigned int idx,
205					     struct mtk_plane_state *state,
206					     struct cmdq_pkt *cmdq_pkt)
207{
208	if (comp->funcs && comp->funcs->layer_config)
209		comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
210}
211
212static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
213{
214	if (comp->funcs && comp->funcs->gamma_get_lut_size)
215		return comp->funcs->gamma_get_lut_size(comp->dev);
216
217	return 0;
218}
219
220static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
221				     struct drm_crtc_state *state)
222{
223	if (comp->funcs && comp->funcs->gamma_set)
224		comp->funcs->gamma_set(comp->dev, state);
225}
226
227static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
228{
229	if (comp->funcs && comp->funcs->bgclr_in_on)
230		comp->funcs->bgclr_in_on(comp->dev);
231}
232
233static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
234{
235	if (comp->funcs && comp->funcs->bgclr_in_off)
236		comp->funcs->bgclr_in_off(comp->dev);
237}
238
239static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
240				   struct drm_crtc_state *state)
241{
242	if (comp->funcs && comp->funcs->ctm_set)
243		comp->funcs->ctm_set(comp->dev, state);
244}
245
246static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
247{
248	if (comp->funcs && comp->funcs->dma_dev_get)
249		return comp->funcs->dma_dev_get(comp->dev);
250	return comp->dev;
251}
252
253static inline
254const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
255{
256	if (comp->funcs && comp->funcs->get_formats)
257		return comp->funcs->get_formats(comp->dev);
258
259	return NULL;
260}
261
262static inline
263size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
264{
265	if (comp->funcs && comp->funcs->get_num_formats)
266		return comp->funcs->get_num_formats(comp->dev);
267
268	return 0;
269}
270
271static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
272{
273	if (comp->funcs && comp->funcs->add) {
274		comp->funcs->add(comp->dev, mutex);
275		return true;
276	}
277	return false;
278}
279
280static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
281{
282	if (comp->funcs && comp->funcs->remove) {
283		comp->funcs->remove(comp->dev, mutex);
284		return true;
285	}
286	return false;
287}
288
289static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
290					unsigned int next)
291{
292	if (comp->funcs && comp->funcs->connect) {
293		comp->funcs->connect(comp->dev, mmsys_dev, next);
294		return true;
295	}
296	return false;
297}
298
299static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
300					   unsigned int next)
301{
302	if (comp->funcs && comp->funcs->disconnect) {
303		comp->funcs->disconnect(comp->dev, mmsys_dev, next);
304		return true;
305	}
306	return false;
307}
308
309static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
310{
311	if (comp->funcs && comp->funcs->encoder_index)
312		comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
313}
314
315int mtk_ddp_comp_get_id(struct device_node *node,
316			enum mtk_ddp_comp_type comp_type);
317unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
318						struct device *dev);
319int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
320		      unsigned int comp_id);
321enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
322void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
323		   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
324		   unsigned int offset);
325void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
326			   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
327			   unsigned int offset);
328void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
329			struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
330			unsigned int offset, unsigned int mask);
331#endif /* MTK_DRM_DDP_COMP_H */