am437x-vpfe.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
  3. *
  4. * Benoit Parrot <bparrot@ti.com>
  5. * Lad, Prabhakar <prabhakar.csengg@gmail.com>
  6. *
  7. * This program is free software; you may redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  12. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  13. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  14. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  15. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  16. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. * SOFTWARE.
  19. */
  20. #ifndef AM437X_VPFE_H
  21. #define AM437X_VPFE_H
  22. #include <linux/am437x-vpfe.h>
  23. #include <linux/clk.h>
  24. #include <linux/device.h>
  25. #include <linux/io.h>
  26. #include <linux/i2c.h>
  27. #include <linux/videodev2.h>
  28. #include <media/v4l2-dev.h>
  29. #include <media/v4l2-device.h>
  30. #include <media/v4l2-ioctl.h>
  31. #include <media/videobuf2-v4l2.h>
  32. #include <media/videobuf2-dma-contig.h>
  33. #include "am437x-vpfe_regs.h"
  34. enum vpfe_pin_pol {
  35. VPFE_PINPOL_POSITIVE = 0,
  36. VPFE_PINPOL_NEGATIVE,
  37. };
  38. enum vpfe_hw_if_type {
  39. /* Raw Bayer */
  40. VPFE_RAW_BAYER = 0,
  41. /* BT656 - 8 bit */
  42. VPFE_BT656,
  43. /* BT656 - 10 bit */
  44. VPFE_BT656_10BIT,
  45. /* YCbCr - 8 bit with external sync */
  46. VPFE_YCBCR_SYNC_8,
  47. /* YCbCr - 16 bit with external sync */
  48. VPFE_YCBCR_SYNC_16,
  49. };
  50. /* interface description */
  51. struct vpfe_hw_if_param {
  52. enum vpfe_hw_if_type if_type;
  53. enum vpfe_pin_pol hdpol;
  54. enum vpfe_pin_pol vdpol;
  55. unsigned int bus_width;
  56. };
  57. #define VPFE_MAX_SUBDEV 1
  58. #define VPFE_MAX_INPUTS 1
  59. struct vpfe_pixel_format {
  60. struct v4l2_fmtdesc fmtdesc;
  61. /* bytes per pixel */
  62. int bpp;
  63. };
  64. struct vpfe_std_info {
  65. int active_pixels;
  66. int active_lines;
  67. /* current frame format */
  68. int frame_format;
  69. };
  70. struct vpfe_route {
  71. u32 input;
  72. u32 output;
  73. };
  74. struct vpfe_subdev_info {
  75. /* Sub device group id */
  76. int grp_id;
  77. /* inputs available at the sub device */
  78. struct v4l2_input inputs[VPFE_MAX_INPUTS];
  79. /* Sub dev routing information for each input */
  80. struct vpfe_route *routes;
  81. /* check if sub dev supports routing */
  82. int can_route;
  83. /* ccdc bus/interface configuration */
  84. struct vpfe_hw_if_param vpfe_param;
  85. struct v4l2_subdev *sd;
  86. };
  87. struct vpfe_config {
  88. /* information about each subdev */
  89. struct vpfe_subdev_info sub_devs[VPFE_MAX_SUBDEV];
  90. /* Flat array, arranged in groups */
  91. struct v4l2_async_subdev *asd[VPFE_MAX_SUBDEV];
  92. };
  93. struct vpfe_cap_buffer {
  94. struct vb2_v4l2_buffer vb;
  95. struct list_head list;
  96. };
  97. enum ccdc_pixfmt {
  98. CCDC_PIXFMT_RAW = 0,
  99. CCDC_PIXFMT_YCBCR_16BIT,
  100. CCDC_PIXFMT_YCBCR_8BIT,
  101. };
  102. enum ccdc_frmfmt {
  103. CCDC_FRMFMT_PROGRESSIVE = 0,
  104. CCDC_FRMFMT_INTERLACED,
  105. };
  106. /* PIXEL ORDER IN MEMORY from LSB to MSB */
  107. /* only applicable for 8-bit input mode */
  108. enum ccdc_pixorder {
  109. CCDC_PIXORDER_YCBYCR,
  110. CCDC_PIXORDER_CBYCRY,
  111. };
  112. enum ccdc_buftype {
  113. CCDC_BUFTYPE_FLD_INTERLEAVED,
  114. CCDC_BUFTYPE_FLD_SEPARATED
  115. };
  116. /* returns the highest bit used for the gamma */
  117. static inline u8 ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width)
  118. {
  119. return 15 - width;
  120. }
  121. /* returns the highest bit used for this data size */
  122. static inline u8 ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz)
  123. {
  124. return sz == VPFE_CCDC_DATA_8BITS ? 7 : 15 - sz;
  125. }
  126. /* Structure for CCDC configuration parameters for raw capture mode */
  127. struct ccdc_params_raw {
  128. /* pixel format */
  129. enum ccdc_pixfmt pix_fmt;
  130. /* progressive or interlaced frame */
  131. enum ccdc_frmfmt frm_fmt;
  132. struct v4l2_rect win;
  133. /* Current Format Bytes Per Pixels */
  134. unsigned int bytesperpixel;
  135. /* Current Format Bytes per Lines
  136. * (Aligned to 32 bytes) used for HORZ_INFO
  137. */
  138. unsigned int bytesperline;
  139. /* field id polarity */
  140. enum vpfe_pin_pol fid_pol;
  141. /* vertical sync polarity */
  142. enum vpfe_pin_pol vd_pol;
  143. /* horizontal sync polarity */
  144. enum vpfe_pin_pol hd_pol;
  145. /* interleaved or separated fields */
  146. enum ccdc_buftype buf_type;
  147. /*
  148. * enable to store the image in inverse
  149. * order in memory(bottom to top)
  150. */
  151. unsigned char image_invert_enable;
  152. /* configurable parameters */
  153. struct vpfe_ccdc_config_params_raw config_params;
  154. };
  155. struct ccdc_params_ycbcr {
  156. /* pixel format */
  157. enum ccdc_pixfmt pix_fmt;
  158. /* progressive or interlaced frame */
  159. enum ccdc_frmfmt frm_fmt;
  160. struct v4l2_rect win;
  161. /* Current Format Bytes Per Pixels */
  162. unsigned int bytesperpixel;
  163. /* Current Format Bytes per Lines
  164. * (Aligned to 32 bytes) used for HORZ_INFO
  165. */
  166. unsigned int bytesperline;
  167. /* field id polarity */
  168. enum vpfe_pin_pol fid_pol;
  169. /* vertical sync polarity */
  170. enum vpfe_pin_pol vd_pol;
  171. /* horizontal sync polarity */
  172. enum vpfe_pin_pol hd_pol;
  173. /* enable BT.656 embedded sync mode */
  174. int bt656_enable;
  175. /* cb:y:cr:y or y:cb:y:cr in memory */
  176. enum ccdc_pixorder pix_order;
  177. /* interleaved or separated fields */
  178. enum ccdc_buftype buf_type;
  179. };
  180. /*
  181. * CCDC operational configuration
  182. */
  183. struct ccdc_config {
  184. /* CCDC interface type */
  185. enum vpfe_hw_if_type if_type;
  186. /* Raw Bayer configuration */
  187. struct ccdc_params_raw bayer;
  188. /* YCbCr configuration */
  189. struct ccdc_params_ycbcr ycbcr;
  190. /* ccdc base address */
  191. void __iomem *base_addr;
  192. };
  193. struct vpfe_ccdc {
  194. struct ccdc_config ccdc_cfg;
  195. u32 ccdc_ctx[VPFE_REG_END / sizeof(u32)];
  196. };
  197. struct vpfe_device {
  198. /* V4l2 specific parameters */
  199. /* Identifies video device for this channel */
  200. struct video_device video_dev;
  201. /* sub devices */
  202. struct v4l2_subdev **sd;
  203. /* vpfe cfg */
  204. struct vpfe_config *cfg;
  205. /* V4l2 device */
  206. struct v4l2_device v4l2_dev;
  207. /* parent device */
  208. struct device *pdev;
  209. /* subdevice async Notifier */
  210. struct v4l2_async_notifier notifier;
  211. /* Indicates id of the field which is being displayed */
  212. unsigned field;
  213. unsigned sequence;
  214. /* current interface type */
  215. struct vpfe_hw_if_param vpfe_if_params;
  216. /* ptr to currently selected sub device */
  217. struct vpfe_subdev_info *current_subdev;
  218. /* current input at the sub device */
  219. int current_input;
  220. /* Keeps track of the information about the standard */
  221. struct vpfe_std_info std_info;
  222. /* std index into std table */
  223. int std_index;
  224. /* IRQs used when CCDC output to SDRAM */
  225. unsigned int irq;
  226. /* Pointer pointing to current v4l2_buffer */
  227. struct vpfe_cap_buffer *cur_frm;
  228. /* Pointer pointing to next v4l2_buffer */
  229. struct vpfe_cap_buffer *next_frm;
  230. /* Used to store pixel format */
  231. struct v4l2_format fmt;
  232. /* Used to store current bytes per pixel based on current format */
  233. unsigned int bpp;
  234. /*
  235. * used when IMP is chained to store the crop window which
  236. * is different from the image window
  237. */
  238. struct v4l2_rect crop;
  239. /* Buffer queue used in video-buf */
  240. struct vb2_queue buffer_queue;
  241. /* Allocator-specific contexts for each plane */
  242. struct vb2_alloc_ctx *alloc_ctx;
  243. /* Queue of filled frames */
  244. struct list_head dma_queue;
  245. /* IRQ lock for DMA queue */
  246. spinlock_t dma_queue_lock;
  247. /* lock used to access this structure */
  248. struct mutex lock;
  249. /*
  250. * offset where second field starts from the starting of the
  251. * buffer for field separated YCbCr formats
  252. */
  253. u32 field_off;
  254. struct vpfe_ccdc ccdc;
  255. };
  256. #endif /* AM437X_VPFE_H */