bdisp.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
  4. * License terms: GNU General Public License (GPL), version 2
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/ktime.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/spinlock.h>
  10. #include <media/v4l2-ctrls.h>
  11. #include <media/v4l2-device.h>
  12. #include <media/v4l2-mem2mem.h>
  13. #include <media/videobuf2-dma-contig.h>
  14. #define BDISP_NAME "bdisp"
  15. /*
  16. * Max nb of nodes in node-list:
  17. * - 2 nodes to handle wide 4K pictures
  18. * - 2 nodes to handle two planes (Y & CbCr) */
  19. #define MAX_OUTPUT_PLANES 2
  20. #define MAX_VERTICAL_STRIDES 2
  21. #define MAX_NB_NODE (MAX_OUTPUT_PLANES * MAX_VERTICAL_STRIDES)
  22. /* struct bdisp_ctrls - bdisp control set
  23. * @hflip: horizontal flip
  24. * @vflip: vertical flip
  25. */
  26. struct bdisp_ctrls {
  27. struct v4l2_ctrl *hflip;
  28. struct v4l2_ctrl *vflip;
  29. };
  30. /**
  31. * struct bdisp_fmt - driver's internal color format data
  32. * @pixelformat:fourcc code for this format
  33. * @nb_planes: number of planes (ex: [0]=RGB/Y - [1]=Cb/Cr, ...)
  34. * @bpp: bits per pixel (general)
  35. * @bpp_plane0: byte per pixel for the 1st plane
  36. * @w_align: width alignment in pixel (multiple of)
  37. * @h_align: height alignment in pixel (multiple of)
  38. */
  39. struct bdisp_fmt {
  40. u32 pixelformat;
  41. u8 nb_planes;
  42. u8 bpp;
  43. u8 bpp_plane0;
  44. u8 w_align;
  45. u8 h_align;
  46. };
  47. /**
  48. * struct bdisp_frame - frame properties
  49. *
  50. * @width: frame width (including padding)
  51. * @height: frame height (including padding)
  52. * @fmt: pointer to frame format descriptor
  53. * @field: frame / field type
  54. * @bytesperline: stride of the 1st plane
  55. * @sizeimage: image size in bytes
  56. * @colorspace: colorspace
  57. * @crop: crop area
  58. * @paddr: image physical addresses per plane ([0]=RGB/Y - [1]=Cb/Cr, ...)
  59. */
  60. struct bdisp_frame {
  61. u32 width;
  62. u32 height;
  63. const struct bdisp_fmt *fmt;
  64. enum v4l2_field field;
  65. u32 bytesperline;
  66. u32 sizeimage;
  67. enum v4l2_colorspace colorspace;
  68. struct v4l2_rect crop;
  69. dma_addr_t paddr[4];
  70. };
  71. /**
  72. * struct bdisp_request - bdisp request
  73. *
  74. * @src: source frame properties
  75. * @dst: destination frame properties
  76. * @hflip: horizontal flip
  77. * @vflip: vertical flip
  78. * @nb_req: number of run request
  79. */
  80. struct bdisp_request {
  81. struct bdisp_frame src;
  82. struct bdisp_frame dst;
  83. unsigned int hflip:1;
  84. unsigned int vflip:1;
  85. int nb_req;
  86. };
  87. /**
  88. * struct bdisp_ctx - device context data
  89. *
  90. * @src: source frame properties
  91. * @dst: destination frame properties
  92. * @state: flags to keep track of user configuration
  93. * @hflip: horizontal flip
  94. * @vflip: vertical flip
  95. * @bdisp_dev: the device this context applies to
  96. * @node: node array
  97. * @node_paddr: node physical address array
  98. * @fh: v4l2 file handle
  99. * @ctrl_handler: v4l2 controls handler
  100. * @bdisp_ctrls: bdisp control set
  101. * @ctrls_rdy: true if the control handler is initialized
  102. */
  103. struct bdisp_ctx {
  104. struct bdisp_frame src;
  105. struct bdisp_frame dst;
  106. u32 state;
  107. unsigned int hflip:1;
  108. unsigned int vflip:1;
  109. struct bdisp_dev *bdisp_dev;
  110. struct bdisp_node *node[MAX_NB_NODE];
  111. dma_addr_t node_paddr[MAX_NB_NODE];
  112. struct v4l2_fh fh;
  113. struct v4l2_ctrl_handler ctrl_handler;
  114. struct bdisp_ctrls bdisp_ctrls;
  115. bool ctrls_rdy;
  116. };
  117. /**
  118. * struct bdisp_m2m_device - v4l2 memory-to-memory device data
  119. *
  120. * @vdev: video device node for v4l2 m2m mode
  121. * @m2m_dev: v4l2 m2m device data
  122. * @ctx: hardware context data
  123. * @refcnt: reference counter
  124. */
  125. struct bdisp_m2m_device {
  126. struct video_device *vdev;
  127. struct v4l2_m2m_dev *m2m_dev;
  128. struct bdisp_ctx *ctx;
  129. int refcnt;
  130. };
  131. /**
  132. * struct bdisp_dbg - debug info
  133. *
  134. * @debugfs_entry: debugfs
  135. * @copy_node: array of last used nodes
  136. * @copy_request: last bdisp request
  137. * @hw_start: start time of last HW request
  138. * @last_duration: last HW processing duration in microsecs
  139. * @min_duration: min HW processing duration in microsecs
  140. * @max_duration: max HW processing duration in microsecs
  141. * @tot_duration: total HW processing duration in microsecs
  142. */
  143. struct bdisp_dbg {
  144. struct dentry *debugfs_entry;
  145. struct bdisp_node *copy_node[MAX_NB_NODE];
  146. struct bdisp_request copy_request;
  147. ktime_t hw_start;
  148. s64 last_duration;
  149. s64 min_duration;
  150. s64 max_duration;
  151. s64 tot_duration;
  152. };
  153. /**
  154. * struct bdisp_dev - abstraction for bdisp entity
  155. *
  156. * @v4l2_dev: v4l2 device
  157. * @vdev: video device
  158. * @pdev: platform device
  159. * @dev: device
  160. * @lock: mutex protecting this data structure
  161. * @slock: spinlock protecting this data structure
  162. * @id: device index
  163. * @m2m: memory-to-memory V4L2 device information
  164. * @state: flags used to synchronize m2m and capture mode operation
  165. * @alloc_ctx: videobuf2 memory allocator context
  166. * @clock: IP clock
  167. * @regs: registers
  168. * @irq_queue: interrupt handler waitqueue
  169. * @work_queue: workqueue to handle timeouts
  170. * @timeout_work: IRQ timeout structure
  171. * @dbg: debug info
  172. */
  173. struct bdisp_dev {
  174. struct v4l2_device v4l2_dev;
  175. struct video_device vdev;
  176. struct platform_device *pdev;
  177. struct device *dev;
  178. spinlock_t slock;
  179. struct mutex lock;
  180. u16 id;
  181. struct bdisp_m2m_device m2m;
  182. unsigned long state;
  183. struct vb2_alloc_ctx *alloc_ctx;
  184. struct clk *clock;
  185. void __iomem *regs;
  186. wait_queue_head_t irq_queue;
  187. struct workqueue_struct *work_queue;
  188. struct delayed_work timeout_work;
  189. struct bdisp_dbg dbg;
  190. };
  191. void bdisp_hw_free_nodes(struct bdisp_ctx *ctx);
  192. int bdisp_hw_alloc_nodes(struct bdisp_ctx *ctx);
  193. void bdisp_hw_free_filters(struct device *dev);
  194. int bdisp_hw_alloc_filters(struct device *dev);
  195. int bdisp_hw_reset(struct bdisp_dev *bdisp);
  196. int bdisp_hw_get_and_clear_irq(struct bdisp_dev *bdisp);
  197. int bdisp_hw_update(struct bdisp_ctx *ctx);
  198. void bdisp_debugfs_remove(struct bdisp_dev *bdisp);
  199. int bdisp_debugfs_create(struct bdisp_dev *bdisp);
  200. void bdisp_dbg_perf_begin(struct bdisp_dev *bdisp);
  201. void bdisp_dbg_perf_end(struct bdisp_dev *bdisp);