2012-08-15 04:31:16 +08:00
|
|
|
/* linux/drivers/media/platform/s5p-jpeg/jpeg-core.h
|
2011-11-24 22:15:23 +08:00
|
|
|
*
|
|
|
|
* 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_
|
|
|
|
|
2013-12-18 22:04:44 +08:00
|
|
|
#include <linux/interrupt.h>
|
2011-11-24 22:15:23 +08:00
|
|
|
#include <media/v4l2-device.h>
|
2012-02-17 22:38:09 +08:00
|
|
|
#include <media/v4l2-fh.h>
|
2012-02-17 22:39:36 +08:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2011-11-24 22:15:23 +08:00
|
|
|
|
|
|
|
#define S5P_JPEG_M2M_NAME "s5p-jpeg"
|
|
|
|
|
2015-09-18 22:20:57 +08:00
|
|
|
#define JPEG_MAX_CLOCKS 4
|
|
|
|
|
2011-11-24 22:15:23 +08:00
|
|
|
/* 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
|
|
|
|
|
2014-07-11 23:19:42 +08:00
|
|
|
#define EXYNOS3250_IRQ_TIMEOUT 0x10000000
|
|
|
|
|
2011-11-24 22:15:23 +08:00
|
|
|
/* a selection of JPEG markers */
|
|
|
|
#define TEM 0x01
|
|
|
|
#define SOF0 0xc0
|
|
|
|
#define RST 0xd0
|
|
|
|
#define SOI 0xd8
|
|
|
|
#define EOI 0xd9
|
|
|
|
#define DHP 0xde
|
|
|
|
|
2013-12-18 22:04:44 +08:00
|
|
|
/* 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)
|
2014-07-11 23:19:42 +08:00
|
|
|
#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)
|
2013-12-18 22:04:44 +08:00
|
|
|
|
2013-12-18 20:32:50 +08:00
|
|
|
#define S5P_JPEG_ENCODE 0
|
|
|
|
#define S5P_JPEG_DECODE 1
|
|
|
|
|
2013-12-18 22:04:44 +08:00
|
|
|
#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
|
2011-11-24 22:15:23 +08:00
|
|
|
|
2013-12-18 22:04:44 +08:00
|
|
|
/* Version numbers */
|
2015-03-09 20:32:46 +08:00
|
|
|
enum sjpeg_version {
|
|
|
|
SJPEG_S5P,
|
|
|
|
SJPEG_EXYNOS3250,
|
|
|
|
SJPEG_EXYNOS4,
|
|
|
|
SJPEG_EXYNOS5420,
|
|
|
|
};
|
2013-12-18 22:04:44 +08:00
|
|
|
|
|
|
|
enum exynos4_jpeg_result {
|
|
|
|
OK_ENC_OR_DEC,
|
|
|
|
ERR_PROT,
|
|
|
|
ERR_DEC_INVALID_FORMAT,
|
|
|
|
ERR_MULTI_SCAN,
|
|
|
|
ERR_FRAME,
|
|
|
|
ERR_UNKNOWN,
|
|
|
|
};
|
2013-12-18 20:32:50 +08:00
|
|
|
|
2013-12-18 22:04:44 +08:00
|
|
|
enum exynos4_jpeg_img_quality_level {
|
|
|
|
QUALITY_LEVEL_1 = 0, /* high */
|
|
|
|
QUALITY_LEVEL_2,
|
|
|
|
QUALITY_LEVEL_3,
|
|
|
|
QUALITY_LEVEL_4, /* low */
|
|
|
|
};
|
2013-12-18 20:32:50 +08:00
|
|
|
|
2011-11-24 22:15:23 +08:00
|
|
|
/**
|
|
|
|
* struct s5p_jpeg - JPEG IP abstraction
|
|
|
|
* @lock: the mutex protecting this structure
|
2012-02-17 22:39:36 +08:00
|
|
|
* @slock: spinlock protecting the device contexts
|
2011-11-24 22:15:23 +08:00
|
|
|
* @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
|
2015-09-18 22:20:57 +08:00
|
|
|
* @clocks: JPEG IP clock(s)
|
2011-11-24 22:15:23 +08:00
|
|
|
* @dev: JPEG IP struct device
|
|
|
|
* @alloc_ctx: videobuf2 memory allocator's context
|
2014-07-11 23:19:42 +08:00
|
|
|
* @variant: driver variant to be used
|
|
|
|
* @irq_status interrupt flags set during single encode/decode
|
|
|
|
operation
|
|
|
|
|
2011-11-24 22:15:23 +08:00
|
|
|
*/
|
|
|
|
struct s5p_jpeg {
|
|
|
|
struct mutex lock;
|
2012-11-30 03:45:08 +08:00
|
|
|
spinlock_t slock;
|
2011-11-24 22:15:23 +08:00
|
|
|
|
|
|
|
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;
|
2013-12-18 22:04:44 +08:00
|
|
|
enum exynos4_jpeg_result irq_ret;
|
2015-09-18 22:20:57 +08:00
|
|
|
struct clk *clocks[JPEG_MAX_CLOCKS];
|
2011-11-24 22:15:23 +08:00
|
|
|
struct device *dev;
|
|
|
|
void *alloc_ctx;
|
2013-12-18 22:04:44 +08:00
|
|
|
struct s5p_jpeg_variant *variant;
|
2014-07-11 23:19:42 +08:00
|
|
|
u32 irq_status;
|
2013-12-18 22:04:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct s5p_jpeg_variant {
|
2014-04-10 15:32:13 +08:00
|
|
|
unsigned int version;
|
|
|
|
unsigned int fmt_ver_flag;
|
2015-03-09 20:32:46 +08:00
|
|
|
unsigned int hw3250_compat:1;
|
|
|
|
unsigned int htbl_reinit:1;
|
2014-04-10 15:32:13 +08:00
|
|
|
struct v4l2_m2m_ops *m2m_ops;
|
|
|
|
irqreturn_t (*jpeg_irq)(int irq, void *priv);
|
2015-09-18 22:20:57 +08:00
|
|
|
const char *clk_names[JPEG_MAX_CLOCKS];
|
|
|
|
int num_clocks;
|
2011-11-24 22:15:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
2013-12-18 22:04:44 +08:00
|
|
|
* @flags: flags describing format applicability
|
2011-11-24 22:15:23 +08:00
|
|
|
*/
|
|
|
|
struct s5p_jpeg_fmt {
|
|
|
|
char *name;
|
|
|
|
u32 fourcc;
|
|
|
|
int depth;
|
|
|
|
int colplanes;
|
2013-12-18 22:04:44 +08:00
|
|
|
int memplanes;
|
2011-11-24 22:15:23 +08:00
|
|
|
int h_align;
|
|
|
|
int v_align;
|
2013-12-18 22:04:44 +08:00
|
|
|
int subsampling;
|
|
|
|
u32 flags;
|
2011-11-24 22:15:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* s5p_jpeg_q_data - parameters of one queue
|
|
|
|
* @fmt: driver-specific format of this queue
|
|
|
|
* @w: image width
|
|
|
|
* @h: image height
|
|
|
|
* @size: image buffer size in bytes
|
|
|
|
*/
|
|
|
|
struct s5p_jpeg_q_data {
|
|
|
|
struct s5p_jpeg_fmt *fmt;
|
|
|
|
u32 w;
|
|
|
|
u32 h;
|
|
|
|
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
|
2014-07-11 23:19:42 +08:00
|
|
|
* @restart_interval: JPEG restart interval for JPEG encoding
|
|
|
|
* @subsampling: subsampling of a raw format or a JPEG
|
2011-11-24 22:15:23 +08:00
|
|
|
* @out_q: source (output) queue information
|
2014-07-11 23:19:42 +08:00
|
|
|
* @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
|
2011-11-24 22:15:23 +08:00
|
|
|
* @hdr_parsed: set if header has been parsed during decompression
|
2014-07-11 23:19:42 +08:00
|
|
|
* @crop_altered: set if crop rectangle has been altered by the user space
|
2012-02-17 22:39:36 +08:00
|
|
|
* @ctrl_handler: controls handler
|
2011-11-24 22:15:23 +08:00
|
|
|
*/
|
|
|
|
struct s5p_jpeg_ctx {
|
|
|
|
struct s5p_jpeg *jpeg;
|
|
|
|
unsigned int mode;
|
2012-02-17 22:39:36 +08:00
|
|
|
unsigned short compr_quality;
|
|
|
|
unsigned short restart_interval;
|
|
|
|
unsigned short subsampling;
|
2011-11-24 22:15:23 +08:00
|
|
|
struct s5p_jpeg_q_data out_q;
|
|
|
|
struct s5p_jpeg_q_data cap_q;
|
2014-07-11 23:19:42 +08:00
|
|
|
unsigned int scale_factor;
|
|
|
|
struct v4l2_rect crop_rect;
|
2012-02-17 22:38:09 +08:00
|
|
|
struct v4l2_fh fh;
|
2011-11-24 22:15:23 +08:00
|
|
|
bool hdr_parsed;
|
2014-07-11 23:19:42 +08:00
|
|
|
bool crop_altered;
|
2012-02-17 22:39:36 +08:00
|
|
|
struct v4l2_ctrl_handler ctrl_handler;
|
2011-11-24 22:15:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
2013-12-18 22:04:44 +08:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
2011-11-24 22:15:23 +08:00
|
|
|
#endif /* JPEG_CORE_H */
|