summaryrefslogtreecommitdiff
path: root/drivers/media/platform/imx8/mxc-isi-core.h
blob: ebb1e09276471de32bac0281311c7f2266430710 (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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
 * Copyright 2017-2018 NXP
 */
/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

#ifndef MXC_ISI_CORE_H_
#define MXC_ISI_CORE_H_

#include <media/v4l2-device.h>
#include <media/v4l2-subdev.h>
#include <media/v4l2-ctrls.h>
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>

#define MXC_ISI_DRIVER_NAME	"mxc-isi"
#define MXC_ISI_MAX_DEVS	8

#define ISI_OF_NODE_NAME	"isi"

#define MXC_ISI_SD_PAD_SINK_MIPI0_VC0		0
#define MXC_ISI_SD_PAD_SINK_MIPI0_VC1		1
#define MXC_ISI_SD_PAD_SINK_MIPI0_VC2		2
#define MXC_ISI_SD_PAD_SINK_MIPI0_VC3		3
#define MXC_ISI_SD_PAD_SINK_MIPI1_VC0		4
#define MXC_ISI_SD_PAD_SINK_MIPI1_VC1		5
#define MXC_ISI_SD_PAD_SINK_MIPI1_VC2		6
#define MXC_ISI_SD_PAD_SINK_MIPI1_VC3		7
#if 0
#define MXC_ISI_SD_PAD_SINK_MIPI_CSI0	0
#define MXC_ISI_SD_PAD_SINK_MIPI_CSI1	1
#endif
#define MXC_ISI_SD_PAD_SINK_DC0				8
#define MXC_ISI_SD_PAD_SINK_DC1				9
#define MXC_ISI_SD_PAD_SINK_HDMI			10
#define MXC_ISI_SD_PAD_SINK_MEM				11
#define MXC_ISI_SD_PAD_SOURCE_MEM			12
#define MXC_ISI_SD_PAD_SOURCE_DC0			13
#define MXC_ISI_SD_PAD_SOURCE_DC1			14
#define MXC_ISI_SD_PAD_SINK_PARALLEL_CSI	15
#define MXC_ISI_SD_PADS_NUM					16

#define MXC_MAX_PLANES		3

enum isi_input_interface {
	ISI_INPUT_INTERFACE_DC0 = 0,
	ISI_INPUT_INTERFACE_DC1,
	ISI_INPUT_INTERFACE_MIPI0_CSI2,
	ISI_INPUT_INTERFACE_MIPI1_CSI2,
	ISI_INPUT_INTERFACE_HDMI,
	ISI_INPUT_INTERFACE_MEM,
	ISI_INPUT_INTERFACE_PARALLEL_CSI,
	ISI_INPUT_INTERFACE_MAX,
};

enum isi_input_sub_interface {
	ISI_INPUT_SUB_INTERFACE_VC0 = 0,
	ISI_INPUT_SUB_INTERFACE_VC1,
	ISI_INPUT_SUB_INTERFACE_VC2,
	ISI_INPUT_SUB_INTERFACE_VC3,
};

enum isi_output_interface {
	ISI_OUTPUT_INTERFACE_DC0 = 0,
	ISI_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_FMT_YUV422_2P10,
	MXC_ISI_OUT_FMT_YUV422_3P10,
	MXC_ISI_OUT_FMT_YUV422_1P10P = 0x28,
	MXC_ISI_OUT_FMT_YUV422_2P10P,
	MXC_ISI_OUT_FMT_YUV422_3P10P,
	MXC_ISI_OUT_FMT_YUV422_1P12 = 0x2C,
	MXC_ISI_OUT_FMT_YUV422_2P12,
	MXC_ISI_OUT_FMT_YUV422_3P12,
	MXC_ISI_OUT_FMT_YUV420_2P8P = 0x31,
	MXC_ISI_OUT_FMT_YUV420_3P8P,
	MXC_ISI_OUT_FMT_YUV420_2P10 = 0x35,
	MXC_ISI_OUT_FMT_YUV420_3P10,
	MXC_ISI_OUT_FMT_YUV420_2P10P = 0x39,
	MXC_ISI_OUT_FMT_YUV420_3P10P,
	MXC_ISI_OUT_FMT_YUV420_2P12 = 0x3D,
	MXC_ISI_OUT_FMT_YUV420_3P12,
};

enum mxc_isi_in_fmt {
	MXC_ISI_IN_FMT_BGR8P	= 0x0,
};

enum mxc_isi_m2m_in_fmt {
	MXC_ISI_M2M_IN_FMT_BGR8P	= 0x0,
	MXC_ISI_M2M_IN_FMT_RGB8P,
	MXC_ISI_M2M_IN_FMT_XRGB8,
	MXC_ISI_M2M_IN_FMT_RGBX8,
	MXC_ISI_M2M_IN_FMT_XBGR8,
	MXC_ISI_M2M_IN_FMT_RGB565,
	MXC_ISI_M2M_IN_FMT_A2BGR10,
	MXC_ISI_M2M_IN_FMT_A2RGB10,
	MXC_ISI_M2M_IN_FMT_YUV444_1P8P,
	MXC_ISI_M2M_IN_FMT_YUV444_1P10,
	MXC_ISI_M2M_IN_FMT_YUV444_1P10P,
	MXC_ISI_M2M_IN_FMT_YUV444_1P12,
	MXC_ISI_M2M_IN_FMT_YUV444_1P8,
	MXC_ISI_M2M_IN_FMT_YUV422_1P8P,
	MXC_ISI_M2M_IN_FMT_YUV422_1P10,
	MXC_ISI_M2M_IN_FMT_YUV422_1P10P,
};

struct mxc_isi_fmt {
	char	*name;
	u32 mbus_code;
	u32	fourcc;
	u32	color;
	u16	memplanes;
	u16	colplanes;
	u8	colorspace;
	u8	depth[MXC_MAX_PLANES];
	u16	mdataplanes;
	u16	flags;
};

struct mxc_isi_ctrls {
	struct v4l2_ctrl_handler handler;
	struct v4l2_ctrl *hflip;
	struct v4l2_ctrl *vflip;
	struct v4l2_ctrl *alpha;
	bool ready;
};

/**
 * struct addr -  physical address set for DMA
 * @y:	 luminance plane physical address
 * @cb:	 Cb plane physical address
 * @cr:	 Cr plane physical address
 */
struct frame_addr {
	u32	y;
	u32	cb;
	u32	cr;
};

/**
 * struct mxc_isi_frame - source/target frame properties
 * o_width:	 original image width from sensor
 * o_height: original image height from sensor
 * c_width:	 crop image width set by g_selection
 * c_height: crop image height set by g_selection
 * h_off:	crop horizontal pixel offset
 * v_off:	crop vertical pixel offset
 * width:	out image pixel width
 * height:	out image pixel weight
 * bytesperline: bytesperline value for each plane
 * paddr:	image frame buffer physical addresses
 * fmt:	color format pointer
 */
struct mxc_isi_frame {
	u32	o_width;
	u32	o_height;
	u32 c_width;
	u32 c_height;
	u32	h_off;
	u32	v_off;
	u32	width;
	u32	height;
	unsigned int	sizeimage[MXC_MAX_PLANES];
	unsigned int	bytesperline[MXC_MAX_PLANES];
	struct mxc_isi_fmt	*fmt;
};

struct mxc_isi_roi_alpha {
	u8 alpha;
	struct v4l2_rect rect;
};

struct mxc_isi_buffer {
	struct vb2_v4l2_buffer v4l2_buf;
	struct list_head	list;
	struct frame_addr	paddr;
};

struct mxc_isi_m2m_dev {
	struct video_device		vdev;
	struct v4l2_m2m_dev		*m2m_dev;
	struct v4l2_fh			fh;

	struct mxc_isi_frame	src_f;
	struct mxc_isi_frame	dst_f;
};

struct mxc_isi_cap_dev {
	struct v4l2_subdev		sd;
	struct video_device		vdev;
	struct v4l2_fh			fh;
	struct media_pad		cap_pad;
	struct media_pad		sd_pads[MXC_ISI_SD_PADS_NUM];
	struct vb2_queue		vb2_q;
	struct list_head		out_pending;
	struct list_head		out_active;

	struct mxc_isi_frame	src_f;
	struct mxc_isi_frame	dst_f;
	u32						frame_count;

	u32 buf_index;

};

struct mxc_isi_dev {
	spinlock_t				slock;
	struct mutex			lock;
	wait_queue_head_t		irq_queue;

	int						id;
	void __iomem			*regs;
	unsigned long			state;

	struct platform_device		*pdev;
	struct v4l2_device			*v4l2_dev;
	struct mxc_isi_m2m_dev		m2m;
	struct mxc_isi_cap_dev		isi_cap;
	struct clk		*clk;

	u32 interface[MAX_PORTS];
	u32 flags;
	u8 chain_buf;

	/* scale factor */
	u32	xfactor;
	u32	yfactor;
	u32	pre_dec_x;
	u32	pre_dec_y;

	unsigned int		hflip:1;
	unsigned int		vflip:1;

	unsigned int		cscen:1;
	unsigned int		scale:1;
	unsigned int		alphaen:1;
	unsigned int		crop:1;
	unsigned int		deinterlace:1;
	unsigned int		parallel_csi:1;

	struct mxc_isi_ctrls ctrls;
	u8			alpha;		/* goable alpha */
	struct mxc_isi_roi_alpha alpha_roi[5];		/* ROI alpha */
};

static inline void set_frame_bounds(struct mxc_isi_frame *f, u32 width, u32 height)
{
	f->o_width  = width;
	f->o_height = height;
	f->c_width  = width;
	f->c_height = height;
	f->width  = width;
	f->height = height;
}

static inline void set_frame_out(struct mxc_isi_frame *f, u32 width, u32 height)
{
	f->c_width  = width;
	f->c_height = height;
	f->width  = width;
	f->height = height;
}

static inline void set_frame_crop(struct mxc_isi_frame *f,
				  u32 left, u32 top, u32 width, u32 height)
{
	f->h_off = left;
	f->v_off = top;
	f->c_width  = width;
	f->c_height = height;
}

#endif