blob: 764b32de326b2cd4e31ab0b5bc4b5641b260e09d [file] [log] [blame]
Mauro Carvalho Chehab2c3fb082012-08-14 17:31:16 -03001/* linux/drivers/media/platform/s5p-jpeg/jpeg-core.h
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -03002 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef JPEG_CORE_H_
14#define JPEG_CORE_H_
15
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030016#include <linux/interrupt.h>
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030017#include <media/v4l2-device.h>
Sylwester Nawrocki275de242012-02-17 11:38:09 -030018#include <media/v4l2-fh.h>
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -030019#include <media/v4l2-ctrls.h>
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030020
21#define S5P_JPEG_M2M_NAME "s5p-jpeg"
22
23/* JPEG compression quality setting */
24#define S5P_JPEG_COMPR_QUAL_BEST 0
25#define S5P_JPEG_COMPR_QUAL_WORST 3
26
27/* JPEG RGB to YCbCr conversion matrix coefficients */
28#define S5P_JPEG_COEF11 0x4d
29#define S5P_JPEG_COEF12 0x97
30#define S5P_JPEG_COEF13 0x1e
31#define S5P_JPEG_COEF21 0x2c
32#define S5P_JPEG_COEF22 0x57
33#define S5P_JPEG_COEF23 0x83
34#define S5P_JPEG_COEF31 0x83
35#define S5P_JPEG_COEF32 0x6e
36#define S5P_JPEG_COEF33 0x13
37
Jacek Anaszewski3246fda2014-07-11 12:19:42 -030038#define EXYNOS3250_IRQ_TIMEOUT 0x10000000
39
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030040/* a selection of JPEG markers */
41#define TEM 0x01
42#define SOF0 0xc0
43#define RST 0xd0
44#define SOI 0xd8
45#define EOI 0xd9
46#define DHP 0xde
47
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030048/* Flags that indicate a format can be used for capture/output */
49#define SJPEG_FMT_FLAG_ENC_CAPTURE (1 << 0)
50#define SJPEG_FMT_FLAG_ENC_OUTPUT (1 << 1)
51#define SJPEG_FMT_FLAG_DEC_CAPTURE (1 << 2)
52#define SJPEG_FMT_FLAG_DEC_OUTPUT (1 << 3)
53#define SJPEG_FMT_FLAG_S5P (1 << 4)
Jacek Anaszewski3246fda2014-07-11 12:19:42 -030054#define SJPEG_FMT_FLAG_EXYNOS3250 (1 << 5)
55#define SJPEG_FMT_FLAG_EXYNOS4 (1 << 6)
56#define SJPEG_FMT_RGB (1 << 7)
57#define SJPEG_FMT_NON_RGB (1 << 8)
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030058
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030059#define S5P_JPEG_ENCODE 0
60#define S5P_JPEG_DECODE 1
61
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030062#define FMT_TYPE_OUTPUT 0
63#define FMT_TYPE_CAPTURE 1
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030064
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030065#define SJPEG_SUBSAMPLING_444 0x11
66#define SJPEG_SUBSAMPLING_422 0x21
67#define SJPEG_SUBSAMPLING_420 0x22
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030068
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030069/* Version numbers */
70
Jacek Anaszewski3246fda2014-07-11 12:19:42 -030071#define SJPEG_S5P 1
72#define SJPEG_EXYNOS3250 2
73#define SJPEG_EXYNOS4 3
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030074
75enum exynos4_jpeg_result {
76 OK_ENC_OR_DEC,
77 ERR_PROT,
78 ERR_DEC_INVALID_FORMAT,
79 ERR_MULTI_SCAN,
80 ERR_FRAME,
81 ERR_UNKNOWN,
82};
83
84enum exynos4_jpeg_img_quality_level {
85 QUALITY_LEVEL_1 = 0, /* high */
86 QUALITY_LEVEL_2,
87 QUALITY_LEVEL_3,
88 QUALITY_LEVEL_4, /* low */
89};
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030090
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030091/**
92 * struct s5p_jpeg - JPEG IP abstraction
93 * @lock: the mutex protecting this structure
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -030094 * @slock: spinlock protecting the device contexts
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030095 * @v4l2_dev: v4l2 device for mem2mem mode
96 * @vfd_encoder: video device node for encoder mem2mem mode
97 * @vfd_decoder: video device node for decoder mem2mem mode
98 * @m2m_dev: v4l2 mem2mem device data
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030099 * @regs: JPEG IP registers mapping
100 * @irq: JPEG IP irq
101 * @clk: JPEG IP clock
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300102 * @sclk: Exynos3250 JPEG IP special clock
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300103 * @dev: JPEG IP struct device
104 * @alloc_ctx: videobuf2 memory allocator's context
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300105 * @variant: driver variant to be used
106 * @irq_status interrupt flags set during single encode/decode
107 operation
108
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300109 */
110struct s5p_jpeg {
111 struct mutex lock;
Luis R. Rodrigueza75831f2012-11-29 16:45:08 -0300112 spinlock_t slock;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300113
114 struct v4l2_device v4l2_dev;
115 struct video_device *vfd_encoder;
116 struct video_device *vfd_decoder;
117 struct v4l2_m2m_dev *m2m_dev;
118
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300119 void __iomem *regs;
120 unsigned int irq;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300121 enum exynos4_jpeg_result irq_ret;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300122 struct clk *clk;
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300123 struct clk *sclk;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300124 struct device *dev;
125 void *alloc_ctx;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300126 struct s5p_jpeg_variant *variant;
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300127 u32 irq_status;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300128};
129
130struct s5p_jpeg_variant {
Jacek Anaszewskibf689bb2014-04-10 04:32:13 -0300131 unsigned int version;
132 unsigned int fmt_ver_flag;
133 struct v4l2_m2m_ops *m2m_ops;
134 irqreturn_t (*jpeg_irq)(int irq, void *priv);
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300135};
136
137/**
138 * struct jpeg_fmt - driver's internal color format data
139 * @name: format descritpion
140 * @fourcc: the fourcc code, 0 if not applicable
141 * @depth: number of bits per pixel
142 * @colplanes: number of color planes (1 for packed formats)
143 * @h_align: horizontal alignment order (align to 2^h_align)
144 * @v_align: vertical alignment order (align to 2^v_align)
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300145 * @flags: flags describing format applicability
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300146 */
147struct s5p_jpeg_fmt {
148 char *name;
149 u32 fourcc;
150 int depth;
151 int colplanes;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300152 int memplanes;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300153 int h_align;
154 int v_align;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300155 int subsampling;
156 u32 flags;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300157};
158
159/**
160 * s5p_jpeg_q_data - parameters of one queue
161 * @fmt: driver-specific format of this queue
162 * @w: image width
163 * @h: image height
164 * @size: image buffer size in bytes
165 */
166struct s5p_jpeg_q_data {
167 struct s5p_jpeg_fmt *fmt;
168 u32 w;
169 u32 h;
170 u32 size;
171};
172
173/**
174 * s5p_jpeg_ctx - the device context data
175 * @jpeg: JPEG IP device for this context
176 * @mode: compression (encode) operation or decompression (decode)
177 * @compr_quality: destination image quality in compression (encode) mode
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300178 * @restart_interval: JPEG restart interval for JPEG encoding
179 * @subsampling: subsampling of a raw format or a JPEG
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300180 * @out_q: source (output) queue information
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300181 * @cap_q: destination (capture) queue queue information
182 * @scale_factor: scale factor for JPEG decoding
183 * @crop_rect: a rectangle representing crop area of the output buffer
184 * @fh: V4L2 file handle
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300185 * @hdr_parsed: set if header has been parsed during decompression
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300186 * @crop_altered: set if crop rectangle has been altered by the user space
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300187 * @ctrl_handler: controls handler
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300188 */
189struct s5p_jpeg_ctx {
190 struct s5p_jpeg *jpeg;
191 unsigned int mode;
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300192 unsigned short compr_quality;
193 unsigned short restart_interval;
194 unsigned short subsampling;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300195 struct s5p_jpeg_q_data out_q;
196 struct s5p_jpeg_q_data cap_q;
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300197 unsigned int scale_factor;
198 struct v4l2_rect crop_rect;
Sylwester Nawrocki275de242012-02-17 11:38:09 -0300199 struct v4l2_fh fh;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300200 bool hdr_parsed;
Jacek Anaszewski3246fda2014-07-11 12:19:42 -0300201 bool crop_altered;
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300202 struct v4l2_ctrl_handler ctrl_handler;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300203};
204
205/**
206 * s5p_jpeg_buffer - description of memory containing input JPEG data
207 * @size: buffer size
208 * @curr: current position in the buffer
209 * @data: pointer to the data
210 */
211struct s5p_jpeg_buffer {
212 unsigned long size;
213 unsigned long curr;
214 unsigned long data;
215};
216
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300217/**
218 * struct s5p_jpeg_addr - JPEG converter physical address set for DMA
219 * @y: luminance plane physical address
220 * @cb: Cb plane physical address
221 * @cr: Cr plane physical address
222 */
223struct s5p_jpeg_addr {
224 u32 y;
225 u32 cb;
226 u32 cr;
227};
228
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300229#endif /* JPEG_CORE_H */