vpdma.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (c) 2013 Texas Instruments Inc.
  3. *
  4. * David Griego, <dagriego@biglakesoftware.com>
  5. * Dale Farnsworth, <dale@farnsworth.org>
  6. * Archit Taneja, <archit@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published by
  10. * the Free Software Foundation.
  11. */
  12. #ifndef __TI_VPDMA_H_
  13. #define __TI_VPDMA_H_
  14. /*
  15. * A vpdma_buf tracks the size, DMA address and mapping status of each
  16. * driver DMA area.
  17. */
  18. struct vpdma_buf {
  19. void *addr;
  20. dma_addr_t dma_addr;
  21. size_t size;
  22. bool mapped;
  23. };
  24. struct vpdma_desc_list {
  25. struct vpdma_buf buf;
  26. void *next;
  27. int type;
  28. };
  29. struct vpdma_data {
  30. void __iomem *base;
  31. struct platform_device *pdev;
  32. /* callback to VPE driver when the firmware is loaded */
  33. void (*cb)(struct platform_device *pdev);
  34. };
  35. enum vpdma_data_format_type {
  36. VPDMA_DATA_FMT_TYPE_YUV,
  37. VPDMA_DATA_FMT_TYPE_RGB,
  38. VPDMA_DATA_FMT_TYPE_MISC,
  39. };
  40. struct vpdma_data_format {
  41. enum vpdma_data_format_type type;
  42. int data_type;
  43. u8 depth;
  44. };
  45. #define VPDMA_DESC_ALIGN 16 /* 16-byte descriptor alignment */
  46. #define VPDMA_STRIDE_ALIGN 16 /*
  47. * line stride of source and dest
  48. * buffers should be 16 byte aligned
  49. */
  50. #define VPDMA_DTD_DESC_SIZE 32 /* 8 words */
  51. #define VPDMA_CFD_CTD_DESC_SIZE 16 /* 4 words */
  52. #define VPDMA_LIST_TYPE_NORMAL 0
  53. #define VPDMA_LIST_TYPE_SELF_MODIFYING 1
  54. #define VPDMA_LIST_TYPE_DOORBELL 2
  55. enum vpdma_yuv_formats {
  56. VPDMA_DATA_FMT_Y444 = 0,
  57. VPDMA_DATA_FMT_Y422,
  58. VPDMA_DATA_FMT_Y420,
  59. VPDMA_DATA_FMT_C444,
  60. VPDMA_DATA_FMT_C422,
  61. VPDMA_DATA_FMT_C420,
  62. VPDMA_DATA_FMT_YC422,
  63. VPDMA_DATA_FMT_YC444,
  64. VPDMA_DATA_FMT_CY422,
  65. };
  66. enum vpdma_rgb_formats {
  67. VPDMA_DATA_FMT_RGB565 = 0,
  68. VPDMA_DATA_FMT_ARGB16_1555,
  69. VPDMA_DATA_FMT_ARGB16,
  70. VPDMA_DATA_FMT_RGBA16_5551,
  71. VPDMA_DATA_FMT_RGBA16,
  72. VPDMA_DATA_FMT_ARGB24,
  73. VPDMA_DATA_FMT_RGB24,
  74. VPDMA_DATA_FMT_ARGB32,
  75. VPDMA_DATA_FMT_RGBA24,
  76. VPDMA_DATA_FMT_RGBA32,
  77. VPDMA_DATA_FMT_BGR565,
  78. VPDMA_DATA_FMT_ABGR16_1555,
  79. VPDMA_DATA_FMT_ABGR16,
  80. VPDMA_DATA_FMT_BGRA16_5551,
  81. VPDMA_DATA_FMT_BGRA16,
  82. VPDMA_DATA_FMT_ABGR24,
  83. VPDMA_DATA_FMT_BGR24,
  84. VPDMA_DATA_FMT_ABGR32,
  85. VPDMA_DATA_FMT_BGRA24,
  86. VPDMA_DATA_FMT_BGRA32,
  87. };
  88. enum vpdma_misc_formats {
  89. VPDMA_DATA_FMT_MV = 0,
  90. };
  91. extern const struct vpdma_data_format vpdma_yuv_fmts[];
  92. extern const struct vpdma_data_format vpdma_rgb_fmts[];
  93. extern const struct vpdma_data_format vpdma_misc_fmts[];
  94. enum vpdma_frame_start_event {
  95. VPDMA_FSEVENT_HDMI_FID = 0,
  96. VPDMA_FSEVENT_DVO2_FID,
  97. VPDMA_FSEVENT_HDCOMP_FID,
  98. VPDMA_FSEVENT_SD_FID,
  99. VPDMA_FSEVENT_LM_FID0,
  100. VPDMA_FSEVENT_LM_FID1,
  101. VPDMA_FSEVENT_LM_FID2,
  102. VPDMA_FSEVENT_CHANNEL_ACTIVE,
  103. };
  104. /*
  105. * VPDMA channel numbers
  106. */
  107. enum vpdma_channel {
  108. VPE_CHAN_LUMA1_IN,
  109. VPE_CHAN_CHROMA1_IN,
  110. VPE_CHAN_LUMA2_IN,
  111. VPE_CHAN_CHROMA2_IN,
  112. VPE_CHAN_LUMA3_IN,
  113. VPE_CHAN_CHROMA3_IN,
  114. VPE_CHAN_MV_IN,
  115. VPE_CHAN_MV_OUT,
  116. VPE_CHAN_LUMA_OUT,
  117. VPE_CHAN_CHROMA_OUT,
  118. VPE_CHAN_RGB_OUT,
  119. };
  120. /* flags for VPDMA data descriptors */
  121. #define VPDMA_DATA_ODD_LINE_SKIP (1 << 0)
  122. #define VPDMA_DATA_EVEN_LINE_SKIP (1 << 1)
  123. #define VPDMA_DATA_FRAME_1D (1 << 2)
  124. #define VPDMA_DATA_MODE_TILED (1 << 3)
  125. /*
  126. * client identifiers used for configuration descriptors
  127. */
  128. #define CFD_MMR_CLIENT 0
  129. #define CFD_SC_CLIENT 4
  130. /* Address data block header format */
  131. struct vpdma_adb_hdr {
  132. u32 offset;
  133. u32 nwords;
  134. u32 reserved0;
  135. u32 reserved1;
  136. };
  137. /* helpers for creating ADB headers for config descriptors MMRs as client */
  138. #define ADB_ADDR(dma_buf, str, fld) ((dma_buf)->addr + offsetof(str, fld))
  139. #define MMR_ADB_ADDR(buf, str, fld) ADB_ADDR(&(buf), struct str, fld)
  140. #define VPDMA_SET_MMR_ADB_HDR(buf, str, hdr, regs, offset_a) \
  141. do { \
  142. struct vpdma_adb_hdr *h; \
  143. struct str *adb = NULL; \
  144. h = MMR_ADB_ADDR(buf, str, hdr); \
  145. h->offset = (offset_a); \
  146. h->nwords = sizeof(adb->regs) >> 2; \
  147. } while (0)
  148. /* vpdma descriptor buffer allocation and management */
  149. int vpdma_alloc_desc_buf(struct vpdma_buf *buf, size_t size);
  150. void vpdma_free_desc_buf(struct vpdma_buf *buf);
  151. int vpdma_map_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf);
  152. void vpdma_unmap_desc_buf(struct vpdma_data *vpdma, struct vpdma_buf *buf);
  153. /* vpdma descriptor list funcs */
  154. int vpdma_create_desc_list(struct vpdma_desc_list *list, size_t size, int type);
  155. void vpdma_reset_desc_list(struct vpdma_desc_list *list);
  156. void vpdma_free_desc_list(struct vpdma_desc_list *list);
  157. int vpdma_submit_descs(struct vpdma_data *vpdma, struct vpdma_desc_list *list);
  158. /* helpers for creating vpdma descriptors */
  159. void vpdma_add_cfd_block(struct vpdma_desc_list *list, int client,
  160. struct vpdma_buf *blk, u32 dest_offset);
  161. void vpdma_add_cfd_adb(struct vpdma_desc_list *list, int client,
  162. struct vpdma_buf *adb);
  163. void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list *list,
  164. enum vpdma_channel chan);
  165. void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
  166. const struct v4l2_rect *c_rect,
  167. const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
  168. enum vpdma_channel chan, u32 flags);
  169. void vpdma_add_in_dtd(struct vpdma_desc_list *list, int width,
  170. const struct v4l2_rect *c_rect,
  171. const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
  172. enum vpdma_channel chan, int field, u32 flags, int frame_width,
  173. int frame_height, int start_h, int start_v);
  174. /* vpdma list interrupt management */
  175. void vpdma_enable_list_complete_irq(struct vpdma_data *vpdma, int list_num,
  176. bool enable);
  177. void vpdma_clear_list_stat(struct vpdma_data *vpdma);
  178. /* vpdma client configuration */
  179. void vpdma_set_line_mode(struct vpdma_data *vpdma, int line_mode,
  180. enum vpdma_channel chan);
  181. void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
  182. enum vpdma_frame_start_event fs_event, enum vpdma_channel chan);
  183. void vpdma_dump_regs(struct vpdma_data *vpdma);
  184. /* initialize vpdma, passed with VPE's platform device pointer */
  185. struct vpdma_data *vpdma_create(struct platform_device *pdev,
  186. void (*cb)(struct platform_device *pdev));
  187. #endif