jpeg-core.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* linux/drivers/media/platform/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. #ifndef JPEG_CORE_H_
  13. #define JPEG_CORE_H_
  14. #include <linux/interrupt.h>
  15. #include <media/v4l2-device.h>
  16. #include <media/v4l2-fh.h>
  17. #include <media/v4l2-ctrls.h>
  18. #define S5P_JPEG_M2M_NAME "s5p-jpeg"
  19. #define JPEG_MAX_CLOCKS 4
  20. /* JPEG compression quality setting */
  21. #define S5P_JPEG_COMPR_QUAL_BEST 0
  22. #define S5P_JPEG_COMPR_QUAL_WORST 3
  23. /* JPEG RGB to YCbCr conversion matrix coefficients */
  24. #define S5P_JPEG_COEF11 0x4d
  25. #define S5P_JPEG_COEF12 0x97
  26. #define S5P_JPEG_COEF13 0x1e
  27. #define S5P_JPEG_COEF21 0x2c
  28. #define S5P_JPEG_COEF22 0x57
  29. #define S5P_JPEG_COEF23 0x83
  30. #define S5P_JPEG_COEF31 0x83
  31. #define S5P_JPEG_COEF32 0x6e
  32. #define S5P_JPEG_COEF33 0x13
  33. #define EXYNOS3250_IRQ_TIMEOUT 0x10000000
  34. /* a selection of JPEG markers */
  35. #define TEM 0x01
  36. #define SOF0 0xc0
  37. #define DHT 0xc4
  38. #define RST 0xd0
  39. #define SOI 0xd8
  40. #define EOI 0xd9
  41. #define SOS 0xda
  42. #define DQT 0xdb
  43. #define DHP 0xde
  44. /* Flags that indicate a format can be used for capture/output */
  45. #define SJPEG_FMT_FLAG_ENC_CAPTURE (1 << 0)
  46. #define SJPEG_FMT_FLAG_ENC_OUTPUT (1 << 1)
  47. #define SJPEG_FMT_FLAG_DEC_CAPTURE (1 << 2)
  48. #define SJPEG_FMT_FLAG_DEC_OUTPUT (1 << 3)
  49. #define SJPEG_FMT_FLAG_S5P (1 << 4)
  50. #define SJPEG_FMT_FLAG_EXYNOS3250 (1 << 5)
  51. #define SJPEG_FMT_FLAG_EXYNOS4 (1 << 6)
  52. #define SJPEG_FMT_RGB (1 << 7)
  53. #define SJPEG_FMT_NON_RGB (1 << 8)
  54. #define S5P_JPEG_ENCODE 0
  55. #define S5P_JPEG_DECODE 1
  56. #define FMT_TYPE_OUTPUT 0
  57. #define FMT_TYPE_CAPTURE 1
  58. #define SJPEG_SUBSAMPLING_444 0x11
  59. #define SJPEG_SUBSAMPLING_422 0x21
  60. #define SJPEG_SUBSAMPLING_420 0x22
  61. #define S5P_JPEG_MAX_MARKER 4
  62. /* Version numbers */
  63. enum sjpeg_version {
  64. SJPEG_S5P,
  65. SJPEG_EXYNOS3250,
  66. SJPEG_EXYNOS4,
  67. SJPEG_EXYNOS5420,
  68. SJPEG_EXYNOS5433,
  69. };
  70. enum exynos4_jpeg_result {
  71. OK_ENC_OR_DEC,
  72. ERR_PROT,
  73. ERR_DEC_INVALID_FORMAT,
  74. ERR_MULTI_SCAN,
  75. ERR_FRAME,
  76. ERR_UNKNOWN,
  77. };
  78. enum exynos4_jpeg_img_quality_level {
  79. QUALITY_LEVEL_1 = 0, /* high */
  80. QUALITY_LEVEL_2,
  81. QUALITY_LEVEL_3,
  82. QUALITY_LEVEL_4, /* low */
  83. };
  84. /**
  85. * struct s5p_jpeg - JPEG IP abstraction
  86. * @lock: the mutex protecting this structure
  87. * @slock: spinlock protecting the device contexts
  88. * @v4l2_dev: v4l2 device for mem2mem mode
  89. * @vfd_encoder: video device node for encoder mem2mem mode
  90. * @vfd_decoder: video device node for decoder mem2mem mode
  91. * @m2m_dev: v4l2 mem2mem device data
  92. * @regs: JPEG IP registers mapping
  93. * @irq: JPEG IP irq
  94. * @clocks: JPEG IP clock(s)
  95. * @dev: JPEG IP struct device
  96. * @alloc_ctx: videobuf2 memory allocator's context
  97. * @variant: driver variant to be used
  98. * @irq_status interrupt flags set during single encode/decode
  99. operation
  100. */
  101. struct s5p_jpeg {
  102. struct mutex lock;
  103. spinlock_t slock;
  104. struct v4l2_device v4l2_dev;
  105. struct video_device *vfd_encoder;
  106. struct video_device *vfd_decoder;
  107. struct v4l2_m2m_dev *m2m_dev;
  108. void __iomem *regs;
  109. unsigned int irq;
  110. enum exynos4_jpeg_result irq_ret;
  111. struct clk *clocks[JPEG_MAX_CLOCKS];
  112. struct device *dev;
  113. void *alloc_ctx;
  114. struct s5p_jpeg_variant *variant;
  115. u32 irq_status;
  116. };
  117. struct s5p_jpeg_variant {
  118. unsigned int version;
  119. unsigned int fmt_ver_flag;
  120. unsigned int hw3250_compat:1;
  121. unsigned int htbl_reinit:1;
  122. unsigned int hw_ex4_compat:1;
  123. struct v4l2_m2m_ops *m2m_ops;
  124. irqreturn_t (*jpeg_irq)(int irq, void *priv);
  125. const char *clk_names[JPEG_MAX_CLOCKS];
  126. int num_clocks;
  127. };
  128. /**
  129. * struct jpeg_fmt - driver's internal color format data
  130. * @name: format descritpion
  131. * @fourcc: the fourcc code, 0 if not applicable
  132. * @depth: number of bits per pixel
  133. * @colplanes: number of color planes (1 for packed formats)
  134. * @h_align: horizontal alignment order (align to 2^h_align)
  135. * @v_align: vertical alignment order (align to 2^v_align)
  136. * @flags: flags describing format applicability
  137. */
  138. struct s5p_jpeg_fmt {
  139. char *name;
  140. u32 fourcc;
  141. int depth;
  142. int colplanes;
  143. int memplanes;
  144. int h_align;
  145. int v_align;
  146. int subsampling;
  147. u32 flags;
  148. };
  149. /**
  150. * s5p_jpeg_marker - collection of markers from jpeg header
  151. * @marker: markers' positions relative to the buffer beginning
  152. * @len: markers' payload lengths (without length field)
  153. * @n: number of markers in collection
  154. */
  155. struct s5p_jpeg_marker {
  156. u32 marker[S5P_JPEG_MAX_MARKER];
  157. u32 len[S5P_JPEG_MAX_MARKER];
  158. u32 n;
  159. };
  160. /**
  161. * s5p_jpeg_q_data - parameters of one queue
  162. * @fmt: driver-specific format of this queue
  163. * @w: image width
  164. * @h: image height
  165. * @sos: SOS marker's position relative to the buffer beginning
  166. * @dht: DHT markers' positions relative to the buffer beginning
  167. * @dqt: DQT markers' positions relative to the buffer beginning
  168. * @sof: SOF0 marker's postition relative to the buffer beginning
  169. * @sof_len: SOF0 marker's payload length (without length field itself)
  170. * @components: number of image components
  171. * @size: image buffer size in bytes
  172. */
  173. struct s5p_jpeg_q_data {
  174. struct s5p_jpeg_fmt *fmt;
  175. u32 w;
  176. u32 h;
  177. u32 sos;
  178. struct s5p_jpeg_marker dht;
  179. struct s5p_jpeg_marker dqt;
  180. u32 sof;
  181. u32 sof_len;
  182. u32 components;
  183. u32 size;
  184. };
  185. /**
  186. * s5p_jpeg_ctx - the device context data
  187. * @jpeg: JPEG IP device for this context
  188. * @mode: compression (encode) operation or decompression (decode)
  189. * @compr_quality: destination image quality in compression (encode) mode
  190. * @restart_interval: JPEG restart interval for JPEG encoding
  191. * @subsampling: subsampling of a raw format or a JPEG
  192. * @out_q: source (output) queue information
  193. * @cap_q: destination (capture) queue queue information
  194. * @scale_factor: scale factor for JPEG decoding
  195. * @crop_rect: a rectangle representing crop area of the output buffer
  196. * @fh: V4L2 file handle
  197. * @hdr_parsed: set if header has been parsed during decompression
  198. * @crop_altered: set if crop rectangle has been altered by the user space
  199. * @ctrl_handler: controls handler
  200. */
  201. struct s5p_jpeg_ctx {
  202. struct s5p_jpeg *jpeg;
  203. unsigned int mode;
  204. unsigned short compr_quality;
  205. unsigned short restart_interval;
  206. unsigned short subsampling;
  207. struct s5p_jpeg_q_data out_q;
  208. struct s5p_jpeg_q_data cap_q;
  209. unsigned int scale_factor;
  210. struct v4l2_rect crop_rect;
  211. struct v4l2_fh fh;
  212. bool hdr_parsed;
  213. bool crop_altered;
  214. struct v4l2_ctrl_handler ctrl_handler;
  215. };
  216. /**
  217. * s5p_jpeg_buffer - description of memory containing input JPEG data
  218. * @size: buffer size
  219. * @curr: current position in the buffer
  220. * @data: pointer to the data
  221. */
  222. struct s5p_jpeg_buffer {
  223. unsigned long size;
  224. unsigned long curr;
  225. unsigned long data;
  226. };
  227. /**
  228. * struct s5p_jpeg_addr - JPEG converter physical address set for DMA
  229. * @y: luminance plane physical address
  230. * @cb: Cb plane physical address
  231. * @cr: Cr plane physical address
  232. */
  233. struct s5p_jpeg_addr {
  234. u32 y;
  235. u32 cb;
  236. u32 cr;
  237. };
  238. #endif /* JPEG_CORE_H */