jpeg-core.h 6.0 KB

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