jpeg-core.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 S5P_JPEG_DISABLE -1
  57. #define FMT_TYPE_OUTPUT 0
  58. #define FMT_TYPE_CAPTURE 1
  59. #define SJPEG_SUBSAMPLING_444 0x11
  60. #define SJPEG_SUBSAMPLING_422 0x21
  61. #define SJPEG_SUBSAMPLING_420 0x22
  62. #define S5P_JPEG_MAX_MARKER 4
  63. /* Version numbers */
  64. enum sjpeg_version {
  65. SJPEG_S5P,
  66. SJPEG_EXYNOS3250,
  67. SJPEG_EXYNOS4,
  68. SJPEG_EXYNOS5420,
  69. SJPEG_EXYNOS5433,
  70. };
  71. enum exynos4_jpeg_result {
  72. OK_ENC_OR_DEC,
  73. ERR_PROT,
  74. ERR_DEC_INVALID_FORMAT,
  75. ERR_MULTI_SCAN,
  76. ERR_FRAME,
  77. ERR_UNKNOWN,
  78. };
  79. enum exynos4_jpeg_img_quality_level {
  80. QUALITY_LEVEL_1 = 0, /* high */
  81. QUALITY_LEVEL_2,
  82. QUALITY_LEVEL_3,
  83. QUALITY_LEVEL_4, /* low */
  84. };
  85. enum s5p_jpeg_ctx_state {
  86. JPEGCTX_RUNNING = 0,
  87. JPEGCTX_RESOLUTION_CHANGE,
  88. };
  89. /**
  90. * struct s5p_jpeg - JPEG IP abstraction
  91. * @lock: the mutex protecting this structure
  92. * @slock: spinlock protecting the device contexts
  93. * @v4l2_dev: v4l2 device for mem2mem mode
  94. * @vfd_encoder: video device node for encoder mem2mem mode
  95. * @vfd_decoder: video device node for decoder mem2mem mode
  96. * @m2m_dev: v4l2 mem2mem device data
  97. * @regs: JPEG IP registers mapping
  98. * @irq: JPEG IP irq
  99. * @clocks: JPEG IP clock(s)
  100. * @dev: JPEG IP struct device
  101. * @variant: driver variant to be used
  102. * @irq_status interrupt flags set during single encode/decode
  103. operation
  104. */
  105. struct s5p_jpeg {
  106. struct mutex lock;
  107. spinlock_t slock;
  108. struct v4l2_device v4l2_dev;
  109. struct video_device *vfd_encoder;
  110. struct video_device *vfd_decoder;
  111. struct v4l2_m2m_dev *m2m_dev;
  112. void __iomem *regs;
  113. unsigned int irq;
  114. enum exynos4_jpeg_result irq_ret;
  115. struct clk *clocks[JPEG_MAX_CLOCKS];
  116. struct device *dev;
  117. struct s5p_jpeg_variant *variant;
  118. u32 irq_status;
  119. };
  120. struct s5p_jpeg_variant {
  121. unsigned int version;
  122. unsigned int fmt_ver_flag;
  123. unsigned int hw3250_compat:1;
  124. unsigned int htbl_reinit:1;
  125. unsigned int hw_ex4_compat:1;
  126. struct v4l2_m2m_ops *m2m_ops;
  127. irqreturn_t (*jpeg_irq)(int irq, void *priv);
  128. const char *clk_names[JPEG_MAX_CLOCKS];
  129. int num_clocks;
  130. };
  131. /**
  132. * struct jpeg_fmt - driver's internal color format data
  133. * @name: format descritpion
  134. * @fourcc: the fourcc code, 0 if not applicable
  135. * @depth: number of bits per pixel
  136. * @colplanes: number of color planes (1 for packed formats)
  137. * @h_align: horizontal alignment order (align to 2^h_align)
  138. * @v_align: vertical alignment order (align to 2^v_align)
  139. * @flags: flags describing format applicability
  140. */
  141. struct s5p_jpeg_fmt {
  142. char *name;
  143. u32 fourcc;
  144. int depth;
  145. int colplanes;
  146. int memplanes;
  147. int h_align;
  148. int v_align;
  149. int subsampling;
  150. u32 flags;
  151. };
  152. /**
  153. * s5p_jpeg_marker - collection of markers from jpeg header
  154. * @marker: markers' positions relative to the buffer beginning
  155. * @len: markers' payload lengths (without length field)
  156. * @n: number of markers in collection
  157. */
  158. struct s5p_jpeg_marker {
  159. u32 marker[S5P_JPEG_MAX_MARKER];
  160. u32 len[S5P_JPEG_MAX_MARKER];
  161. u32 n;
  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. * @sos: SOS marker's position relative to the buffer beginning
  169. * @dht: DHT markers' positions relative to the buffer beginning
  170. * @dqt: DQT markers' positions relative to the buffer beginning
  171. * @sof: SOF0 marker's postition relative to the buffer beginning
  172. * @sof_len: SOF0 marker's payload length (without length field itself)
  173. * @components: number of image components
  174. * @size: image buffer size in bytes
  175. */
  176. struct s5p_jpeg_q_data {
  177. struct s5p_jpeg_fmt *fmt;
  178. u32 w;
  179. u32 h;
  180. u32 sos;
  181. struct s5p_jpeg_marker dht;
  182. struct s5p_jpeg_marker dqt;
  183. u32 sof;
  184. u32 sof_len;
  185. u32 components;
  186. u32 size;
  187. };
  188. /**
  189. * s5p_jpeg_ctx - the device context data
  190. * @jpeg: JPEG IP device for this context
  191. * @mode: compression (encode) operation or decompression (decode)
  192. * @compr_quality: destination image quality in compression (encode) mode
  193. * @restart_interval: JPEG restart interval for JPEG encoding
  194. * @subsampling: subsampling of a raw format or a JPEG
  195. * @out_q: source (output) queue information
  196. * @cap_q: destination (capture) queue queue information
  197. * @scale_factor: scale factor for JPEG decoding
  198. * @crop_rect: a rectangle representing crop area of the output buffer
  199. * @fh: V4L2 file handle
  200. * @hdr_parsed: set if header has been parsed during decompression
  201. * @crop_altered: set if crop rectangle has been altered by the user space
  202. * @ctrl_handler: controls handler
  203. * @state: state of the context
  204. */
  205. struct s5p_jpeg_ctx {
  206. struct s5p_jpeg *jpeg;
  207. unsigned int mode;
  208. unsigned short compr_quality;
  209. unsigned short restart_interval;
  210. unsigned short subsampling;
  211. struct s5p_jpeg_q_data out_q;
  212. struct s5p_jpeg_q_data cap_q;
  213. unsigned int scale_factor;
  214. struct v4l2_rect crop_rect;
  215. struct v4l2_fh fh;
  216. bool hdr_parsed;
  217. bool crop_altered;
  218. struct v4l2_ctrl_handler ctrl_handler;
  219. enum s5p_jpeg_ctx_state state;
  220. };
  221. /**
  222. * s5p_jpeg_buffer - description of memory containing input JPEG data
  223. * @size: buffer size
  224. * @curr: current position in the buffer
  225. * @data: pointer to the data
  226. */
  227. struct s5p_jpeg_buffer {
  228. unsigned long size;
  229. unsigned long curr;
  230. unsigned long data;
  231. };
  232. /**
  233. * struct s5p_jpeg_addr - JPEG converter physical address set for DMA
  234. * @y: luminance plane physical address
  235. * @cb: Cb plane physical address
  236. * @cr: Cr plane physical address
  237. */
  238. struct s5p_jpeg_addr {
  239. u32 y;
  240. u32 cb;
  241. u32 cr;
  242. };
  243. #endif /* JPEG_CORE_H */