blob: 3e4786329727087655a0121d52dd2bfd2831a0ca [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
38/* a selection of JPEG markers */
39#define TEM 0x01
40#define SOF0 0xc0
41#define RST 0xd0
42#define SOI 0xd8
43#define EOI 0xd9
44#define DHP 0xde
45
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030046/* Flags that indicate a format can be used for capture/output */
47#define SJPEG_FMT_FLAG_ENC_CAPTURE (1 << 0)
48#define SJPEG_FMT_FLAG_ENC_OUTPUT (1 << 1)
49#define SJPEG_FMT_FLAG_DEC_CAPTURE (1 << 2)
50#define SJPEG_FMT_FLAG_DEC_OUTPUT (1 << 3)
51#define SJPEG_FMT_FLAG_S5P (1 << 4)
52#define SJPEG_FMT_FLAG_EXYNOS4 (1 << 5)
53#define SJPEG_FMT_RGB (1 << 6)
54#define SJPEG_FMT_NON_RGB (1 << 7)
55
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030056#define S5P_JPEG_ENCODE 0
57#define S5P_JPEG_DECODE 1
58
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030059#define FMT_TYPE_OUTPUT 0
60#define FMT_TYPE_CAPTURE 1
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030061
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030062#define SJPEG_SUBSAMPLING_444 0x11
63#define SJPEG_SUBSAMPLING_422 0x21
64#define SJPEG_SUBSAMPLING_420 0x22
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030065
Jacek Anaszewski80529ae2013-12-18 11:04:44 -030066/* Version numbers */
67
68#define SJPEG_S5P 1
69#define SJPEG_EXYNOS4 2
70
71enum exynos4_jpeg_result {
72 OK_ENC_OR_DEC,
73 ERR_PROT,
74 ERR_DEC_INVALID_FORMAT,
75 ERR_MULTI_SCAN,
76 ERR_FRAME,
77 ERR_UNKNOWN,
78};
79
80enum exynos4_jpeg_img_quality_level {
81 QUALITY_LEVEL_1 = 0, /* high */
82 QUALITY_LEVEL_2,
83 QUALITY_LEVEL_3,
84 QUALITY_LEVEL_4, /* low */
85};
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030086
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030087/**
88 * struct s5p_jpeg - JPEG IP abstraction
89 * @lock: the mutex protecting this structure
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -030090 * @slock: spinlock protecting the device contexts
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030091 * @v4l2_dev: v4l2 device for mem2mem mode
92 * @vfd_encoder: video device node for encoder mem2mem mode
93 * @vfd_decoder: video device node for decoder mem2mem mode
94 * @m2m_dev: v4l2 mem2mem device data
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030095 * @regs: JPEG IP registers mapping
96 * @irq: JPEG IP irq
97 * @clk: JPEG IP clock
98 * @dev: JPEG IP struct device
99 * @alloc_ctx: videobuf2 memory allocator's context
100 */
101struct s5p_jpeg {
102 struct mutex lock;
Luis R. Rodrigueza75831f2012-11-29 16:45:08 -0300103 spinlock_t slock;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300104
105 struct v4l2_device v4l2_dev;
106 struct video_device *vfd_encoder;
107 struct video_device *vfd_decoder;
108 struct v4l2_m2m_dev *m2m_dev;
109
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300110 void __iomem *regs;
111 unsigned int irq;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300112 enum exynos4_jpeg_result irq_ret;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300113 struct clk *clk;
114 struct device *dev;
115 void *alloc_ctx;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300116 struct s5p_jpeg_variant *variant;
117};
118
119struct s5p_jpeg_variant {
Jacek Anaszewskibf689bb2014-04-10 04:32:13 -0300120 unsigned int version;
121 unsigned int fmt_ver_flag;
122 struct v4l2_m2m_ops *m2m_ops;
123 irqreturn_t (*jpeg_irq)(int irq, void *priv);
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300124};
125
126/**
127 * struct jpeg_fmt - driver's internal color format data
128 * @name: format descritpion
129 * @fourcc: the fourcc code, 0 if not applicable
130 * @depth: number of bits per pixel
131 * @colplanes: number of color planes (1 for packed formats)
132 * @h_align: horizontal alignment order (align to 2^h_align)
133 * @v_align: vertical alignment order (align to 2^v_align)
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300134 * @flags: flags describing format applicability
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300135 */
136struct s5p_jpeg_fmt {
137 char *name;
138 u32 fourcc;
139 int depth;
140 int colplanes;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300141 int memplanes;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300142 int h_align;
143 int v_align;
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300144 int subsampling;
145 u32 flags;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300146};
147
148/**
149 * s5p_jpeg_q_data - parameters of one queue
150 * @fmt: driver-specific format of this queue
151 * @w: image width
152 * @h: image height
153 * @size: image buffer size in bytes
154 */
155struct s5p_jpeg_q_data {
156 struct s5p_jpeg_fmt *fmt;
157 u32 w;
158 u32 h;
159 u32 size;
160};
161
162/**
163 * s5p_jpeg_ctx - the device context data
164 * @jpeg: JPEG IP device for this context
165 * @mode: compression (encode) operation or decompression (decode)
166 * @compr_quality: destination image quality in compression (encode) mode
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300167 * @out_q: source (output) queue information
168 * @cap_fmt: destination (capture) queue queue information
169 * @hdr_parsed: set if header has been parsed during decompression
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300170 * @ctrl_handler: controls handler
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300171 */
172struct s5p_jpeg_ctx {
173 struct s5p_jpeg *jpeg;
174 unsigned int mode;
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300175 unsigned short compr_quality;
176 unsigned short restart_interval;
177 unsigned short subsampling;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300178 struct s5p_jpeg_q_data out_q;
179 struct s5p_jpeg_q_data cap_q;
Sylwester Nawrocki275de242012-02-17 11:38:09 -0300180 struct v4l2_fh fh;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300181 bool hdr_parsed;
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300182 struct v4l2_ctrl_handler ctrl_handler;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300183};
184
185/**
186 * s5p_jpeg_buffer - description of memory containing input JPEG data
187 * @size: buffer size
188 * @curr: current position in the buffer
189 * @data: pointer to the data
190 */
191struct s5p_jpeg_buffer {
192 unsigned long size;
193 unsigned long curr;
194 unsigned long data;
195};
196
Jacek Anaszewski80529ae2013-12-18 11:04:44 -0300197/**
198 * struct s5p_jpeg_addr - JPEG converter physical address set for DMA
199 * @y: luminance plane physical address
200 * @cb: Cb plane physical address
201 * @cr: Cr plane physical address
202 */
203struct s5p_jpeg_addr {
204 u32 y;
205 u32 cb;
206 u32 cr;
207};
208
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300209#endif /* JPEG_CORE_H */