jpeg-core.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. * @variant: driver variant to be used
  97. * @irq_status interrupt flags set during single encode/decode
  98. operation
  99. */
  100. struct s5p_jpeg {
  101. struct mutex lock;
  102. spinlock_t slock;
  103. struct v4l2_device v4l2_dev;
  104. struct video_device *vfd_encoder;
  105. struct video_device *vfd_decoder;
  106. struct v4l2_m2m_dev *m2m_dev;
  107. void __iomem *regs;
  108. unsigned int irq;
  109. enum exynos4_jpeg_result irq_ret;
  110. struct clk *clocks[JPEG_MAX_CLOCKS];
  111. struct device *dev;
  112. struct s5p_jpeg_variant *variant;
  113. u32 irq_status;
  114. };
  115. struct s5p_jpeg_variant {
  116. unsigned int version;
  117. unsigned int fmt_ver_flag;
  118. unsigned int hw3250_compat:1;
  119. unsigned int htbl_reinit:1;
  120. unsigned int hw_ex4_compat:1;
  121. struct v4l2_m2m_ops *m2m_ops;
  122. irqreturn_t (*jpeg_irq)(int irq, void *priv);
  123. const char *clk_names[JPEG_MAX_CLOCKS];
  124. int num_clocks;
  125. };
  126. /**
  127. * struct jpeg_fmt - driver's internal color format data
  128. * @name: format descritpion
  129. * @fourcc: the fourcc code, 0 if not applicable
  130. * @depth: number of bits per pixel
  131. * @colplanes: number of color planes (1 for packed formats)
  132. * @h_align: horizontal alignment order (align to 2^h_align)
  133. * @v_align: vertical alignment order (align to 2^v_align)
  134. * @flags: flags describing format applicability
  135. */
  136. struct s5p_jpeg_fmt {
  137. char *name;
  138. u32 fourcc;
  139. int depth;
  140. int colplanes;
  141. int memplanes;
  142. int h_align;
  143. int v_align;
  144. int subsampling;
  145. u32 flags;
  146. };
  147. /**
  148. * s5p_jpeg_marker - collection of markers from jpeg header
  149. * @marker: markers' positions relative to the buffer beginning
  150. * @len: markers' payload lengths (without length field)
  151. * @n: number of markers in collection
  152. */
  153. struct s5p_jpeg_marker {
  154. u32 marker[S5P_JPEG_MAX_MARKER];
  155. u32 len[S5P_JPEG_MAX_MARKER];
  156. u32 n;
  157. };
  158. /**
  159. * s5p_jpeg_q_data - parameters of one queue
  160. * @fmt: driver-specific format of this queue
  161. * @w: image width
  162. * @h: image height
  163. * @sos: SOS marker's position relative to the buffer beginning
  164. * @dht: DHT markers' positions relative to the buffer beginning
  165. * @dqt: DQT markers' positions relative to the buffer beginning
  166. * @sof: SOF0 marker's postition relative to the buffer beginning
  167. * @sof_len: SOF0 marker's payload length (without length field itself)
  168. * @components: number of image components
  169. * @size: image buffer size in bytes
  170. */
  171. struct s5p_jpeg_q_data {
  172. struct s5p_jpeg_fmt *fmt;
  173. u32 w;
  174. u32 h;
  175. u32 sos;
  176. struct s5p_jpeg_marker dht;
  177. struct s5p_jpeg_marker dqt;
  178. u32 sof;
  179. u32 sof_len;
  180. u32 components;
  181. u32 size;
  182. };
  183. /**
  184. * s5p_jpeg_ctx - the device context data
  185. * @jpeg: JPEG IP device for this context
  186. * @mode: compression (encode) operation or decompression (decode)
  187. * @compr_quality: destination image quality in compression (encode) mode
  188. * @restart_interval: JPEG restart interval for JPEG encoding
  189. * @subsampling: subsampling of a raw format or a JPEG
  190. * @out_q: source (output) queue information
  191. * @cap_q: destination (capture) queue queue information
  192. * @scale_factor: scale factor for JPEG decoding
  193. * @crop_rect: a rectangle representing crop area of the output buffer
  194. * @fh: V4L2 file handle
  195. * @hdr_parsed: set if header has been parsed during decompression
  196. * @crop_altered: set if crop rectangle has been altered by the user space
  197. * @ctrl_handler: controls handler
  198. */
  199. struct s5p_jpeg_ctx {
  200. struct s5p_jpeg *jpeg;
  201. unsigned int mode;
  202. unsigned short compr_quality;
  203. unsigned short restart_interval;
  204. unsigned short subsampling;
  205. struct s5p_jpeg_q_data out_q;
  206. struct s5p_jpeg_q_data cap_q;
  207. unsigned int scale_factor;
  208. struct v4l2_rect crop_rect;
  209. struct v4l2_fh fh;
  210. bool hdr_parsed;
  211. bool crop_altered;
  212. struct v4l2_ctrl_handler ctrl_handler;
  213. };
  214. /**
  215. * s5p_jpeg_buffer - description of memory containing input JPEG data
  216. * @size: buffer size
  217. * @curr: current position in the buffer
  218. * @data: pointer to the data
  219. */
  220. struct s5p_jpeg_buffer {
  221. unsigned long size;
  222. unsigned long curr;
  223. unsigned long data;
  224. };
  225. /**
  226. * struct s5p_jpeg_addr - JPEG converter physical address set for DMA
  227. * @y: luminance plane physical address
  228. * @cb: Cb plane physical address
  229. * @cr: Cr plane physical address
  230. */
  231. struct s5p_jpeg_addr {
  232. u32 y;
  233. u32 cb;
  234. u32 cr;
  235. };
  236. #endif /* JPEG_CORE_H */