Mauro Carvalho Chehab | 2c3fb08 | 2012-08-14 17:31:16 -0300 | [diff] [blame] | 1 | /* linux/drivers/media/platform/s5p-jpeg/jpeg-core.h |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 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 | |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 17 | #include <media/v4l2-device.h> |
Sylwester Nawrocki | 275de24 | 2012-02-17 11:38:09 -0300 | [diff] [blame] | 18 | #include <media/v4l2-fh.h> |
Sylwester Nawrocki | 15f4bc3 | 2012-02-17 11:39:36 -0300 | [diff] [blame] | 19 | #include <media/v4l2-ctrls.h> |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 20 | |
| 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 Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 38 | #define EXYNOS3250_IRQ_TIMEOUT 0x10000000 |
| 39 | |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 40 | /* 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 Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 48 | /* 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 Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 54 | #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 Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 58 | |
Jacek Anaszewski | 9f7b62d | 2013-12-18 09:32:50 -0300 | [diff] [blame] | 59 | #define S5P_JPEG_ENCODE 0 |
| 60 | #define S5P_JPEG_DECODE 1 |
| 61 | |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 62 | #define FMT_TYPE_OUTPUT 0 |
| 63 | #define FMT_TYPE_CAPTURE 1 |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 64 | |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 65 | #define SJPEG_SUBSAMPLING_444 0x11 |
| 66 | #define SJPEG_SUBSAMPLING_422 0x21 |
| 67 | #define SJPEG_SUBSAMPLING_420 0x22 |
Jacek Anaszewski | 9f7b62d | 2013-12-18 09:32:50 -0300 | [diff] [blame] | 68 | |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 69 | /* Version numbers */ |
Andrzej Pietrasiewicz | 7c15fd4 | 2015-03-09 09:32:46 -0300 | [diff] [blame^] | 70 | enum sjpeg_version { |
| 71 | SJPEG_S5P, |
| 72 | SJPEG_EXYNOS3250, |
| 73 | SJPEG_EXYNOS4, |
| 74 | SJPEG_EXYNOS5420, |
| 75 | }; |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 76 | |
| 77 | enum exynos4_jpeg_result { |
| 78 | OK_ENC_OR_DEC, |
| 79 | ERR_PROT, |
| 80 | ERR_DEC_INVALID_FORMAT, |
| 81 | ERR_MULTI_SCAN, |
| 82 | ERR_FRAME, |
| 83 | ERR_UNKNOWN, |
| 84 | }; |
| 85 | |
| 86 | enum exynos4_jpeg_img_quality_level { |
| 87 | QUALITY_LEVEL_1 = 0, /* high */ |
| 88 | QUALITY_LEVEL_2, |
| 89 | QUALITY_LEVEL_3, |
| 90 | QUALITY_LEVEL_4, /* low */ |
| 91 | }; |
Jacek Anaszewski | 9f7b62d | 2013-12-18 09:32:50 -0300 | [diff] [blame] | 92 | |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 93 | /** |
| 94 | * struct s5p_jpeg - JPEG IP abstraction |
| 95 | * @lock: the mutex protecting this structure |
Sylwester Nawrocki | 15f4bc3 | 2012-02-17 11:39:36 -0300 | [diff] [blame] | 96 | * @slock: spinlock protecting the device contexts |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 97 | * @v4l2_dev: v4l2 device for mem2mem mode |
| 98 | * @vfd_encoder: video device node for encoder mem2mem mode |
| 99 | * @vfd_decoder: video device node for decoder mem2mem mode |
| 100 | * @m2m_dev: v4l2 mem2mem device data |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 101 | * @regs: JPEG IP registers mapping |
| 102 | * @irq: JPEG IP irq |
| 103 | * @clk: JPEG IP clock |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 104 | * @sclk: Exynos3250 JPEG IP special clock |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 105 | * @dev: JPEG IP struct device |
| 106 | * @alloc_ctx: videobuf2 memory allocator's context |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 107 | * @variant: driver variant to be used |
| 108 | * @irq_status interrupt flags set during single encode/decode |
| 109 | operation |
| 110 | |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 111 | */ |
| 112 | struct s5p_jpeg { |
| 113 | struct mutex lock; |
Luis R. Rodriguez | a75831f | 2012-11-29 16:45:08 -0300 | [diff] [blame] | 114 | spinlock_t slock; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 115 | |
| 116 | struct v4l2_device v4l2_dev; |
| 117 | struct video_device *vfd_encoder; |
| 118 | struct video_device *vfd_decoder; |
| 119 | struct v4l2_m2m_dev *m2m_dev; |
| 120 | |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 121 | void __iomem *regs; |
| 122 | unsigned int irq; |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 123 | enum exynos4_jpeg_result irq_ret; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 124 | struct clk *clk; |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 125 | struct clk *sclk; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 126 | struct device *dev; |
| 127 | void *alloc_ctx; |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 128 | struct s5p_jpeg_variant *variant; |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 129 | u32 irq_status; |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | struct s5p_jpeg_variant { |
Jacek Anaszewski | bf689bb | 2014-04-10 04:32:13 -0300 | [diff] [blame] | 133 | unsigned int version; |
| 134 | unsigned int fmt_ver_flag; |
Andrzej Pietrasiewicz | 7c15fd4 | 2015-03-09 09:32:46 -0300 | [diff] [blame^] | 135 | unsigned int hw3250_compat:1; |
| 136 | unsigned int htbl_reinit:1; |
Jacek Anaszewski | bf689bb | 2014-04-10 04:32:13 -0300 | [diff] [blame] | 137 | struct v4l2_m2m_ops *m2m_ops; |
| 138 | irqreturn_t (*jpeg_irq)(int irq, void *priv); |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * struct jpeg_fmt - driver's internal color format data |
| 143 | * @name: format descritpion |
| 144 | * @fourcc: the fourcc code, 0 if not applicable |
| 145 | * @depth: number of bits per pixel |
| 146 | * @colplanes: number of color planes (1 for packed formats) |
| 147 | * @h_align: horizontal alignment order (align to 2^h_align) |
| 148 | * @v_align: vertical alignment order (align to 2^v_align) |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 149 | * @flags: flags describing format applicability |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 150 | */ |
| 151 | struct s5p_jpeg_fmt { |
| 152 | char *name; |
| 153 | u32 fourcc; |
| 154 | int depth; |
| 155 | int colplanes; |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 156 | int memplanes; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 157 | int h_align; |
| 158 | int v_align; |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 159 | int subsampling; |
| 160 | u32 flags; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | /** |
| 164 | * s5p_jpeg_q_data - parameters of one queue |
| 165 | * @fmt: driver-specific format of this queue |
| 166 | * @w: image width |
| 167 | * @h: image height |
| 168 | * @size: image buffer size in bytes |
| 169 | */ |
| 170 | struct s5p_jpeg_q_data { |
| 171 | struct s5p_jpeg_fmt *fmt; |
| 172 | u32 w; |
| 173 | u32 h; |
| 174 | u32 size; |
| 175 | }; |
| 176 | |
| 177 | /** |
| 178 | * s5p_jpeg_ctx - the device context data |
| 179 | * @jpeg: JPEG IP device for this context |
| 180 | * @mode: compression (encode) operation or decompression (decode) |
| 181 | * @compr_quality: destination image quality in compression (encode) mode |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 182 | * @restart_interval: JPEG restart interval for JPEG encoding |
| 183 | * @subsampling: subsampling of a raw format or a JPEG |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 184 | * @out_q: source (output) queue information |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 185 | * @cap_q: destination (capture) queue queue information |
| 186 | * @scale_factor: scale factor for JPEG decoding |
| 187 | * @crop_rect: a rectangle representing crop area of the output buffer |
| 188 | * @fh: V4L2 file handle |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 189 | * @hdr_parsed: set if header has been parsed during decompression |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 190 | * @crop_altered: set if crop rectangle has been altered by the user space |
Sylwester Nawrocki | 15f4bc3 | 2012-02-17 11:39:36 -0300 | [diff] [blame] | 191 | * @ctrl_handler: controls handler |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 192 | */ |
| 193 | struct s5p_jpeg_ctx { |
| 194 | struct s5p_jpeg *jpeg; |
| 195 | unsigned int mode; |
Sylwester Nawrocki | 15f4bc3 | 2012-02-17 11:39:36 -0300 | [diff] [blame] | 196 | unsigned short compr_quality; |
| 197 | unsigned short restart_interval; |
| 198 | unsigned short subsampling; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 199 | struct s5p_jpeg_q_data out_q; |
| 200 | struct s5p_jpeg_q_data cap_q; |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 201 | unsigned int scale_factor; |
| 202 | struct v4l2_rect crop_rect; |
Sylwester Nawrocki | 275de24 | 2012-02-17 11:38:09 -0300 | [diff] [blame] | 203 | struct v4l2_fh fh; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 204 | bool hdr_parsed; |
Jacek Anaszewski | 3246fda | 2014-07-11 12:19:42 -0300 | [diff] [blame] | 205 | bool crop_altered; |
Sylwester Nawrocki | 15f4bc3 | 2012-02-17 11:39:36 -0300 | [diff] [blame] | 206 | struct v4l2_ctrl_handler ctrl_handler; |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | /** |
| 210 | * s5p_jpeg_buffer - description of memory containing input JPEG data |
| 211 | * @size: buffer size |
| 212 | * @curr: current position in the buffer |
| 213 | * @data: pointer to the data |
| 214 | */ |
| 215 | struct s5p_jpeg_buffer { |
| 216 | unsigned long size; |
| 217 | unsigned long curr; |
| 218 | unsigned long data; |
| 219 | }; |
| 220 | |
Jacek Anaszewski | 80529ae | 2013-12-18 11:04:44 -0300 | [diff] [blame] | 221 | /** |
| 222 | * struct s5p_jpeg_addr - JPEG converter physical address set for DMA |
| 223 | * @y: luminance plane physical address |
| 224 | * @cb: Cb plane physical address |
| 225 | * @cr: Cr plane physical address |
| 226 | */ |
| 227 | struct s5p_jpeg_addr { |
| 228 | u32 y; |
| 229 | u32 cb; |
| 230 | u32 cr; |
| 231 | }; |
| 232 | |
Andrzej Pietrasiewicz | bb677f3 | 2011-11-24 11:15:23 -0300 | [diff] [blame] | 233 | #endif /* JPEG_CORE_H */ |