summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
blob: 0797b3ac75d8c41d424fcdf53cfa1de500d50a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2015 MediaTek Inc.
 */

#ifndef MTK_DRM_DDP_COMP_H
#define MTK_DRM_DDP_COMP_H

#include <linux/io.h>
#include <linux/soc/mediatek/mtk-cmdq.h>
#include <linux/soc/mediatek/mtk-mmsys.h>
#include <linux/soc/mediatek/mtk-mutex.h>

struct device;
struct device_node;
struct drm_crtc;
struct drm_device;
struct mtk_plane_state;
struct drm_crtc_state;

enum mtk_ddp_comp_type {
	MTK_DISP_AAL,
	MTK_DISP_BLS,
	MTK_DISP_CCORR,
	MTK_DISP_COLOR,
	MTK_DISP_DITHER,
	MTK_DISP_DSC,
	MTK_DISP_GAMMA,
	MTK_DISP_MERGE,
	MTK_DISP_MUTEX,
	MTK_DISP_OD,
	MTK_DISP_OVL,
	MTK_DISP_OVL_2L,
	MTK_DISP_OVL_ADAPTOR,
	MTK_DISP_POSTMASK,
	MTK_DISP_PWM,
	MTK_DISP_RDMA,
	MTK_DISP_UFOE,
	MTK_DISP_WDMA,
	MTK_DPI,
	MTK_DP_INTF,
	MTK_DSI,
	MTK_DDP_COMP_TYPE_MAX,
};

struct mtk_ddp_comp;
struct cmdq_pkt;
struct mtk_ddp_comp_funcs {
	int (*clk_enable)(struct device *dev);
	void (*clk_disable)(struct device *dev);
	void (*config)(struct device *dev, unsigned int w,
		       unsigned int h, unsigned int vrefresh,
		       unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
	void (*start)(struct device *dev);
	void (*stop)(struct device *dev);
	void (*register_vblank_cb)(struct device *dev,
				   void (*vblank_cb)(void *),
				   void *vblank_cb_data);
	void (*unregister_vblank_cb)(struct device *dev);
	void (*enable_vblank)(struct device *dev);
	void (*disable_vblank)(struct device *dev);
	unsigned int (*supported_rotations)(struct device *dev);
	unsigned int (*layer_nr)(struct device *dev);
	int (*layer_check)(struct device *dev,
			   unsigned int idx,
			   struct mtk_plane_state *state);
	void (*layer_config)(struct device *dev, unsigned int idx,
			     struct mtk_plane_state *state,
			     struct cmdq_pkt *cmdq_pkt);
	void (*gamma_set)(struct device *dev,
			  struct drm_crtc_state *state);
	void (*bgclr_in_on)(struct device *dev);
	void (*bgclr_in_off)(struct device *dev);
	void (*ctm_set)(struct device *dev,
			struct drm_crtc_state *state);
	struct device * (*dma_dev_get)(struct device *dev);
	const u32 *(*get_formats)(struct device *dev);
	size_t (*get_num_formats)(struct device *dev);
	void (*connect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
	void (*disconnect)(struct device *dev, struct device *mmsys_dev, unsigned int next);
	void (*add)(struct device *dev, struct mtk_mutex *mutex);
	void (*remove)(struct device *dev, struct mtk_mutex *mutex);
	unsigned int (*encoder_index)(struct device *dev);
};

struct mtk_ddp_comp {
	struct device *dev;
	int irq;
	unsigned int id;
	int encoder_index;
	const struct mtk_ddp_comp_funcs *funcs;
};

static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->clk_enable)
		return comp->funcs->clk_enable(comp->dev);

	return 0;
}

static inline void mtk_ddp_comp_clk_disable(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->clk_disable)
		comp->funcs->clk_disable(comp->dev);
}

static inline void 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)
{
	if (comp->funcs && comp->funcs->config)
		comp->funcs->config(comp->dev, w, h, vrefresh, bpc, cmdq_pkt);
}

static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->start)
		comp->funcs->start(comp->dev);
}

static inline void mtk_ddp_comp_stop(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->stop)
		comp->funcs->stop(comp->dev);
}

static inline void mtk_ddp_comp_register_vblank_cb(struct mtk_ddp_comp *comp,
						   void (*vblank_cb)(void *),
						   void *vblank_cb_data)
{
	if (comp->funcs && comp->funcs->register_vblank_cb)
		comp->funcs->register_vblank_cb(comp->dev, vblank_cb,
						vblank_cb_data);
}

static inline void mtk_ddp_comp_unregister_vblank_cb(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->unregister_vblank_cb)
		comp->funcs->unregister_vblank_cb(comp->dev);
}

static inline void mtk_ddp_comp_enable_vblank(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->enable_vblank)
		comp->funcs->enable_vblank(comp->dev);
}

static inline void mtk_ddp_comp_disable_vblank(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->disable_vblank)
		comp->funcs->disable_vblank(comp->dev);
}

static inline
unsigned int mtk_ddp_comp_supported_rotations(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->supported_rotations)
		return comp->funcs->supported_rotations(comp->dev);

	return 0;
}

static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->layer_nr)
		return comp->funcs->layer_nr(comp->dev);

	return 0;
}

static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
					   unsigned int idx,
					   struct mtk_plane_state *state)
{
	if (comp->funcs && comp->funcs->layer_check)
		return comp->funcs->layer_check(comp->dev, idx, state);
	return 0;
}

static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
					     unsigned int idx,
					     struct mtk_plane_state *state,
					     struct cmdq_pkt *cmdq_pkt)
{
	if (comp->funcs && comp->funcs->layer_config)
		comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
}

static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
				     struct drm_crtc_state *state)
{
	if (comp->funcs && comp->funcs->gamma_set)
		comp->funcs->gamma_set(comp->dev, state);
}

static inline void mtk_ddp_comp_bgclr_in_on(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->bgclr_in_on)
		comp->funcs->bgclr_in_on(comp->dev);
}

static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->bgclr_in_off)
		comp->funcs->bgclr_in_off(comp->dev);
}

static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
				   struct drm_crtc_state *state)
{
	if (comp->funcs && comp->funcs->ctm_set)
		comp->funcs->ctm_set(comp->dev, state);
}

static inline struct device *mtk_ddp_comp_dma_dev_get(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->dma_dev_get)
		return comp->funcs->dma_dev_get(comp->dev);
	return comp->dev;
}

static inline
const u32 *mtk_ddp_comp_get_formats(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->get_formats)
		return comp->funcs->get_formats(comp->dev);

	return NULL;
}

static inline
size_t mtk_ddp_comp_get_num_formats(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->get_num_formats)
		return comp->funcs->get_num_formats(comp->dev);

	return 0;
}

static inline bool mtk_ddp_comp_add(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
{
	if (comp->funcs && comp->funcs->add) {
		comp->funcs->add(comp->dev, mutex);
		return true;
	}
	return false;
}

static inline bool mtk_ddp_comp_remove(struct mtk_ddp_comp *comp, struct mtk_mutex *mutex)
{
	if (comp->funcs && comp->funcs->remove) {
		comp->funcs->remove(comp->dev, mutex);
		return true;
	}
	return false;
}

static inline bool mtk_ddp_comp_connect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
					unsigned int next)
{
	if (comp->funcs && comp->funcs->connect) {
		comp->funcs->connect(comp->dev, mmsys_dev, next);
		return true;
	}
	return false;
}

static inline bool mtk_ddp_comp_disconnect(struct mtk_ddp_comp *comp, struct device *mmsys_dev,
					   unsigned int next)
{
	if (comp->funcs && comp->funcs->disconnect) {
		comp->funcs->disconnect(comp->dev, mmsys_dev, next);
		return true;
	}
	return false;
}

static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
{
	if (comp->funcs && comp->funcs->encoder_index)
		comp->encoder_index = (int)comp->funcs->encoder_index(comp->dev);
}

int mtk_ddp_comp_get_id(struct device_node *node,
			enum mtk_ddp_comp_type comp_type);
unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
						struct device *dev);
int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
		      unsigned int comp_id);
enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
		   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
		   unsigned int offset);
void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
			   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
			   unsigned int offset);
void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
			struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
			unsigned int offset, unsigned int mask);
#endif /* MTK_DRM_DDP_COMP_H */