blob: 7baadf395e90d256ede43ffe1545c18665d708a0 [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
16#include <media/v4l2-device.h>
Sylwester Nawrocki275de242012-02-17 11:38:09 -030017#include <media/v4l2-fh.h>
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -030018#include <media/v4l2-ctrls.h>
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030019
20#define S5P_JPEG_M2M_NAME "s5p-jpeg"
21
22/* JPEG compression quality setting */
23#define S5P_JPEG_COMPR_QUAL_BEST 0
24#define S5P_JPEG_COMPR_QUAL_WORST 3
25
26/* JPEG RGB to YCbCr conversion matrix coefficients */
27#define S5P_JPEG_COEF11 0x4d
28#define S5P_JPEG_COEF12 0x97
29#define S5P_JPEG_COEF13 0x1e
30#define S5P_JPEG_COEF21 0x2c
31#define S5P_JPEG_COEF22 0x57
32#define S5P_JPEG_COEF23 0x83
33#define S5P_JPEG_COEF31 0x83
34#define S5P_JPEG_COEF32 0x6e
35#define S5P_JPEG_COEF33 0x13
36
37/* a selection of JPEG markers */
38#define TEM 0x01
39#define SOF0 0xc0
40#define RST 0xd0
41#define SOI 0xd8
42#define EOI 0xd9
43#define DHP 0xde
44
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030045#define S5P_JPEG_ENCODE 0
46#define S5P_JPEG_DECODE 1
47
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030048/* Flags that indicate a format can be used for capture/output */
49#define MEM2MEM_CAPTURE (1 << 0)
50#define MEM2MEM_OUTPUT (1 << 1)
51
Jacek Anaszewski9f7b62d2013-12-18 09:32:50 -030052
53
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030054/**
55 * struct s5p_jpeg - JPEG IP abstraction
56 * @lock: the mutex protecting this structure
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -030057 * @slock: spinlock protecting the device contexts
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030058 * @v4l2_dev: v4l2 device for mem2mem mode
59 * @vfd_encoder: video device node for encoder mem2mem mode
60 * @vfd_decoder: video device node for decoder mem2mem mode
61 * @m2m_dev: v4l2 mem2mem device data
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030062 * @regs: JPEG IP registers mapping
63 * @irq: JPEG IP irq
64 * @clk: JPEG IP clock
65 * @dev: JPEG IP struct device
66 * @alloc_ctx: videobuf2 memory allocator's context
67 */
68struct s5p_jpeg {
69 struct mutex lock;
Luis R. Rodrigueza75831f2012-11-29 16:45:08 -030070 spinlock_t slock;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030071
72 struct v4l2_device v4l2_dev;
73 struct video_device *vfd_encoder;
74 struct video_device *vfd_decoder;
75 struct v4l2_m2m_dev *m2m_dev;
76
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030077 void __iomem *regs;
78 unsigned int irq;
79 struct clk *clk;
80 struct device *dev;
81 void *alloc_ctx;
82};
83
84/**
85 * struct jpeg_fmt - driver's internal color format data
86 * @name: format descritpion
87 * @fourcc: the fourcc code, 0 if not applicable
88 * @depth: number of bits per pixel
89 * @colplanes: number of color planes (1 for packed formats)
90 * @h_align: horizontal alignment order (align to 2^h_align)
91 * @v_align: vertical alignment order (align to 2^v_align)
92 * @types: types of queue this format is applicable to
93 */
94struct s5p_jpeg_fmt {
95 char *name;
96 u32 fourcc;
97 int depth;
98 int colplanes;
99 int h_align;
100 int v_align;
101 u32 types;
102};
103
104/**
105 * s5p_jpeg_q_data - parameters of one queue
106 * @fmt: driver-specific format of this queue
107 * @w: image width
108 * @h: image height
109 * @size: image buffer size in bytes
110 */
111struct s5p_jpeg_q_data {
112 struct s5p_jpeg_fmt *fmt;
113 u32 w;
114 u32 h;
115 u32 size;
116};
117
118/**
119 * s5p_jpeg_ctx - the device context data
120 * @jpeg: JPEG IP device for this context
121 * @mode: compression (encode) operation or decompression (decode)
122 * @compr_quality: destination image quality in compression (encode) mode
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300123 * @out_q: source (output) queue information
124 * @cap_fmt: destination (capture) queue queue information
125 * @hdr_parsed: set if header has been parsed during decompression
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300126 * @ctrl_handler: controls handler
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300127 */
128struct s5p_jpeg_ctx {
129 struct s5p_jpeg *jpeg;
130 unsigned int mode;
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300131 unsigned short compr_quality;
132 unsigned short restart_interval;
133 unsigned short subsampling;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300134 struct s5p_jpeg_q_data out_q;
135 struct s5p_jpeg_q_data cap_q;
Sylwester Nawrocki275de242012-02-17 11:38:09 -0300136 struct v4l2_fh fh;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300137 bool hdr_parsed;
Sylwester Nawrocki15f4bc32012-02-17 11:39:36 -0300138 struct v4l2_ctrl_handler ctrl_handler;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300139};
140
141/**
142 * s5p_jpeg_buffer - description of memory containing input JPEG data
143 * @size: buffer size
144 * @curr: current position in the buffer
145 * @data: pointer to the data
146 */
147struct s5p_jpeg_buffer {
148 unsigned long size;
149 unsigned long curr;
150 unsigned long data;
151};
152
153#endif /* JPEG_CORE_H */