jpeg-core.h 7.0 KB
Newer Older
1
/* linux/drivers/media/platform/s5p-jpeg/jpeg-core.h
2 3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef JPEG_CORE_H_
#define JPEG_CORE_H_

J
Jacek Anaszewski 已提交
16
#include <linux/interrupt.h>
17
#include <media/v4l2-device.h>
18
#include <media/v4l2-fh.h>
19
#include <media/v4l2-ctrls.h>
20 21 22

#define S5P_JPEG_M2M_NAME		"s5p-jpeg"

23 24
#define JPEG_MAX_CLOCKS			4

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
/* JPEG compression quality setting */
#define S5P_JPEG_COMPR_QUAL_BEST	0
#define S5P_JPEG_COMPR_QUAL_WORST	3

/* JPEG RGB to YCbCr conversion matrix coefficients */
#define S5P_JPEG_COEF11			0x4d
#define S5P_JPEG_COEF12			0x97
#define S5P_JPEG_COEF13			0x1e
#define S5P_JPEG_COEF21			0x2c
#define S5P_JPEG_COEF22			0x57
#define S5P_JPEG_COEF23			0x83
#define S5P_JPEG_COEF31			0x83
#define S5P_JPEG_COEF32			0x6e
#define S5P_JPEG_COEF33			0x13

40 41
#define EXYNOS3250_IRQ_TIMEOUT		0x10000000

42 43 44
/* a selection of JPEG markers */
#define TEM				0x01
#define SOF0				0xc0
45
#define DHT				0xc4
46 47 48
#define RST				0xd0
#define SOI				0xd8
#define EOI				0xd9
49 50
#define	SOS				0xda
#define DQT				0xdb
51 52
#define DHP				0xde

J
Jacek Anaszewski 已提交
53 54 55 56 57 58
/* Flags that indicate a format can be used for capture/output */
#define SJPEG_FMT_FLAG_ENC_CAPTURE	(1 << 0)
#define SJPEG_FMT_FLAG_ENC_OUTPUT	(1 << 1)
#define SJPEG_FMT_FLAG_DEC_CAPTURE	(1 << 2)
#define SJPEG_FMT_FLAG_DEC_OUTPUT	(1 << 3)
#define SJPEG_FMT_FLAG_S5P		(1 << 4)
59 60 61 62
#define SJPEG_FMT_FLAG_EXYNOS3250	(1 << 5)
#define SJPEG_FMT_FLAG_EXYNOS4		(1 << 6)
#define SJPEG_FMT_RGB			(1 << 7)
#define SJPEG_FMT_NON_RGB		(1 << 8)
J
Jacek Anaszewski 已提交
63

64 65 66
#define S5P_JPEG_ENCODE		0
#define S5P_JPEG_DECODE		1

J
Jacek Anaszewski 已提交
67 68 69 70 71 72
#define FMT_TYPE_OUTPUT		0
#define FMT_TYPE_CAPTURE	1

#define SJPEG_SUBSAMPLING_444	0x11
#define SJPEG_SUBSAMPLING_422	0x21
#define SJPEG_SUBSAMPLING_420	0x22
73

74 75
#define S5P_JPEG_MAX_MARKER	4

J
Jacek Anaszewski 已提交
76
/* Version numbers */
77 78 79 80 81
enum sjpeg_version {
	SJPEG_S5P,
	SJPEG_EXYNOS3250,
	SJPEG_EXYNOS4,
	SJPEG_EXYNOS5420,
82
	SJPEG_EXYNOS5433,
83
};
J
Jacek Anaszewski 已提交
84 85 86 87 88 89 90 91 92

enum exynos4_jpeg_result {
	OK_ENC_OR_DEC,
	ERR_PROT,
	ERR_DEC_INVALID_FORMAT,
	ERR_MULTI_SCAN,
	ERR_FRAME,
	ERR_UNKNOWN,
};
93

J
Jacek Anaszewski 已提交
94 95 96 97 98 99
enum  exynos4_jpeg_img_quality_level {
	QUALITY_LEVEL_1 = 0,	/* high */
	QUALITY_LEVEL_2,
	QUALITY_LEVEL_3,
	QUALITY_LEVEL_4,	/* low */
};
100

101 102 103 104 105
enum s5p_jpeg_ctx_state {
	JPEGCTX_RUNNING = 0,
	JPEGCTX_RESOLUTION_CHANGE,
};

106 107 108
/**
 * struct s5p_jpeg - JPEG IP abstraction
 * @lock:		the mutex protecting this structure
109
 * @slock:		spinlock protecting the device contexts
110 111 112 113 114 115
 * @v4l2_dev:		v4l2 device for mem2mem mode
 * @vfd_encoder:	video device node for encoder mem2mem mode
 * @vfd_decoder:	video device node for decoder mem2mem mode
 * @m2m_dev:		v4l2 mem2mem device data
 * @regs:		JPEG IP registers mapping
 * @irq:		JPEG IP irq
116
 * @clocks:		JPEG IP clock(s)
117
 * @dev:		JPEG IP struct device
118 119 120 121
 * @variant:		driver variant to be used
 * @irq_status		interrupt flags set during single encode/decode
			operation

122 123 124
 */
struct s5p_jpeg {
	struct mutex		lock;
125
	spinlock_t		slock;
126 127 128 129 130 131 132 133

	struct v4l2_device	v4l2_dev;
	struct video_device	*vfd_encoder;
	struct video_device	*vfd_decoder;
	struct v4l2_m2m_dev	*m2m_dev;

	void __iomem		*regs;
	unsigned int		irq;
J
Jacek Anaszewski 已提交
134
	enum exynos4_jpeg_result irq_ret;
135
	struct clk		*clocks[JPEG_MAX_CLOCKS];
136
	struct device		*dev;
J
Jacek Anaszewski 已提交
137
	struct s5p_jpeg_variant *variant;
138
	u32			irq_status;
J
Jacek Anaszewski 已提交
139 140 141
};

struct s5p_jpeg_variant {
142 143
	unsigned int		version;
	unsigned int		fmt_ver_flag;
144 145
	unsigned int		hw3250_compat:1;
	unsigned int		htbl_reinit:1;
146
	unsigned int		hw_ex4_compat:1;
147 148
	struct v4l2_m2m_ops	*m2m_ops;
	irqreturn_t		(*jpeg_irq)(int irq, void *priv);
149 150
	const char		*clk_names[JPEG_MAX_CLOCKS];
	int			num_clocks;
151 152 153 154 155 156 157 158 159 160
};

/**
 * struct jpeg_fmt - driver's internal color format data
 * @name:	format descritpion
 * @fourcc:	the fourcc code, 0 if not applicable
 * @depth:	number of bits per pixel
 * @colplanes:	number of color planes (1 for packed formats)
 * @h_align:	horizontal alignment order (align to 2^h_align)
 * @v_align:	vertical alignment order (align to 2^v_align)
J
Jacek Anaszewski 已提交
161
 * @flags:	flags describing format applicability
162 163 164 165 166 167
 */
struct s5p_jpeg_fmt {
	char	*name;
	u32	fourcc;
	int	depth;
	int	colplanes;
J
Jacek Anaszewski 已提交
168
	int	memplanes;
169 170
	int	h_align;
	int	v_align;
J
Jacek Anaszewski 已提交
171 172
	int	subsampling;
	u32	flags;
173 174
};

175 176 177 178 179 180 181 182 183 184 185 186
/**
 * s5p_jpeg_marker - collection of markers from jpeg header
 * @marker:	markers' positions relative to the buffer beginning
 * @len:	markers' payload lengths (without length field)
 * @n:		number of markers in collection
 */
struct s5p_jpeg_marker {
	u32	marker[S5P_JPEG_MAX_MARKER];
	u32	len[S5P_JPEG_MAX_MARKER];
	u32	n;
};

187 188 189 190 191
/**
 * s5p_jpeg_q_data - parameters of one queue
 * @fmt:	driver-specific format of this queue
 * @w:		image width
 * @h:		image height
192 193 194 195 196 197
 * @sos:	SOS marker's position relative to the buffer beginning
 * @dht:	DHT markers' positions relative to the buffer beginning
 * @dqt:	DQT markers' positions relative to the buffer beginning
 * @sof:	SOF0 marker's postition relative to the buffer beginning
 * @sof_len:	SOF0 marker's payload length (without length field itself)
 * @components:	number of image components
198 199 200 201 202 203
 * @size:	image buffer size in bytes
 */
struct s5p_jpeg_q_data {
	struct s5p_jpeg_fmt	*fmt;
	u32			w;
	u32			h;
204 205 206 207 208 209
	u32			sos;
	struct s5p_jpeg_marker	dht;
	struct s5p_jpeg_marker	dqt;
	u32			sof;
	u32			sof_len;
	u32			components;
210 211 212 213 214 215 216 217
	u32			size;
};

/**
 * s5p_jpeg_ctx - the device context data
 * @jpeg:		JPEG IP device for this context
 * @mode:		compression (encode) operation or decompression (decode)
 * @compr_quality:	destination image quality in compression (encode) mode
218 219
 * @restart_interval:	JPEG restart interval for JPEG encoding
 * @subsampling:	subsampling of a raw format or a JPEG
220
 * @out_q:		source (output) queue information
221 222 223 224
 * @cap_q:		destination (capture) queue queue information
 * @scale_factor:	scale factor for JPEG decoding
 * @crop_rect:		a rectangle representing crop area of the output buffer
 * @fh:			V4L2 file handle
225
 * @hdr_parsed:		set if header has been parsed during decompression
226
 * @crop_altered:	set if crop rectangle has been altered by the user space
227
 * @ctrl_handler:	controls handler
228
 * @state:		state of the context
229 230 231 232
 */
struct s5p_jpeg_ctx {
	struct s5p_jpeg		*jpeg;
	unsigned int		mode;
233 234 235
	unsigned short		compr_quality;
	unsigned short		restart_interval;
	unsigned short		subsampling;
236 237
	struct s5p_jpeg_q_data	out_q;
	struct s5p_jpeg_q_data	cap_q;
238 239
	unsigned int		scale_factor;
	struct v4l2_rect	crop_rect;
240
	struct v4l2_fh		fh;
241
	bool			hdr_parsed;
242
	bool			crop_altered;
243
	struct v4l2_ctrl_handler ctrl_handler;
244
	enum s5p_jpeg_ctx_state	state;
245 246 247 248 249 250 251 252 253 254 255 256 257 258
};

/**
 * s5p_jpeg_buffer - description of memory containing input JPEG data
 * @size:	buffer size
 * @curr:	current position in the buffer
 * @data:	pointer to the data
 */
struct s5p_jpeg_buffer {
	unsigned long size;
	unsigned long curr;
	unsigned long data;
};

J
Jacek Anaszewski 已提交
259 260 261 262 263 264 265 266 267 268 269 270
/**
 * struct s5p_jpeg_addr - JPEG converter physical address set for DMA
 * @y:   luminance plane physical address
 * @cb:  Cb plane physical address
 * @cr:  Cr plane physical address
 */
struct s5p_jpeg_addr {
	u32     y;
	u32     cb;
	u32     cr;
};

271
#endif /* JPEG_CORE_H */