am437x-vpfe.h 7.1 KB

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