blob: 4dd705fb99d5b6f5df9fc70f37335778c94bbe4c [file] [log] [blame]
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -03001/* linux/drivers/media/video/s5p-jpeg/jpeg-core.h
2 *
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>
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -030018
19#define S5P_JPEG_M2M_NAME "s5p-jpeg"
20
21/* JPEG compression quality setting */
22#define S5P_JPEG_COMPR_QUAL_BEST 0
23#define S5P_JPEG_COMPR_QUAL_WORST 3
24
25/* JPEG RGB to YCbCr conversion matrix coefficients */
26#define S5P_JPEG_COEF11 0x4d
27#define S5P_JPEG_COEF12 0x97
28#define S5P_JPEG_COEF13 0x1e
29#define S5P_JPEG_COEF21 0x2c
30#define S5P_JPEG_COEF22 0x57
31#define S5P_JPEG_COEF23 0x83
32#define S5P_JPEG_COEF31 0x83
33#define S5P_JPEG_COEF32 0x6e
34#define S5P_JPEG_COEF33 0x13
35
36/* a selection of JPEG markers */
37#define TEM 0x01
38#define SOF0 0xc0
39#define RST 0xd0
40#define SOI 0xd8
41#define EOI 0xd9
42#define DHP 0xde
43
44/* Flags that indicate a format can be used for capture/output */
45#define MEM2MEM_CAPTURE (1 << 0)
46#define MEM2MEM_OUTPUT (1 << 1)
47
48/**
49 * struct s5p_jpeg - JPEG IP abstraction
50 * @lock: the mutex protecting this structure
51 * @v4l2_dev: v4l2 device for mem2mem mode
52 * @vfd_encoder: video device node for encoder mem2mem mode
53 * @vfd_decoder: video device node for decoder mem2mem mode
54 * @m2m_dev: v4l2 mem2mem device data
55 * @ioarea: JPEG IP memory region
56 * @regs: JPEG IP registers mapping
57 * @irq: JPEG IP irq
58 * @clk: JPEG IP clock
59 * @dev: JPEG IP struct device
60 * @alloc_ctx: videobuf2 memory allocator's context
61 */
62struct s5p_jpeg {
63 struct mutex lock;
64
65 struct v4l2_device v4l2_dev;
66 struct video_device *vfd_encoder;
67 struct video_device *vfd_decoder;
68 struct v4l2_m2m_dev *m2m_dev;
69
70 struct resource *ioarea;
71 void __iomem *regs;
72 unsigned int irq;
73 struct clk *clk;
74 struct device *dev;
75 void *alloc_ctx;
76};
77
78/**
79 * struct jpeg_fmt - driver's internal color format data
80 * @name: format descritpion
81 * @fourcc: the fourcc code, 0 if not applicable
82 * @depth: number of bits per pixel
83 * @colplanes: number of color planes (1 for packed formats)
84 * @h_align: horizontal alignment order (align to 2^h_align)
85 * @v_align: vertical alignment order (align to 2^v_align)
86 * @types: types of queue this format is applicable to
87 */
88struct s5p_jpeg_fmt {
89 char *name;
90 u32 fourcc;
91 int depth;
92 int colplanes;
93 int h_align;
94 int v_align;
95 u32 types;
96};
97
98/**
99 * s5p_jpeg_q_data - parameters of one queue
100 * @fmt: driver-specific format of this queue
101 * @w: image width
102 * @h: image height
103 * @size: image buffer size in bytes
104 */
105struct s5p_jpeg_q_data {
106 struct s5p_jpeg_fmt *fmt;
107 u32 w;
108 u32 h;
109 u32 size;
110};
111
112/**
113 * s5p_jpeg_ctx - the device context data
114 * @jpeg: JPEG IP device for this context
115 * @mode: compression (encode) operation or decompression (decode)
116 * @compr_quality: destination image quality in compression (encode) mode
117 * @m2m_ctx: mem2mem device context
118 * @out_q: source (output) queue information
119 * @cap_fmt: destination (capture) queue queue information
120 * @hdr_parsed: set if header has been parsed during decompression
121 */
122struct s5p_jpeg_ctx {
123 struct s5p_jpeg *jpeg;
124 unsigned int mode;
125 unsigned int compr_quality;
126 struct v4l2_m2m_ctx *m2m_ctx;
127 struct s5p_jpeg_q_data out_q;
128 struct s5p_jpeg_q_data cap_q;
Sylwester Nawrocki275de242012-02-17 11:38:09 -0300129 struct v4l2_fh fh;
Andrzej Pietrasiewiczbb677f32011-11-24 11:15:23 -0300130 bool hdr_parsed;
131};
132
133/**
134 * s5p_jpeg_buffer - description of memory containing input JPEG data
135 * @size: buffer size
136 * @curr: current position in the buffer
137 * @data: pointer to the data
138 */
139struct s5p_jpeg_buffer {
140 unsigned long size;
141 unsigned long curr;
142 unsigned long data;
143};
144
145#endif /* JPEG_CORE_H */