fimc-lite.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics Co., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef FIMC_LITE_H_
  9. #define FIMC_LITE_H_
  10. #include <linux/sizes.h>
  11. #include <linux/io.h>
  12. #include <linux/irqreturn.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/sched.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/types.h>
  17. #include <linux/videodev2.h>
  18. #include <media/media-entity.h>
  19. #include <media/videobuf2-v4l2.h>
  20. #include <media/v4l2-ctrls.h>
  21. #include <media/v4l2-device.h>
  22. #include <media/v4l2-mediabus.h>
  23. #include <media/exynos-fimc.h>
  24. #define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
  25. #define FLITE_CLK_NAME "flite"
  26. #define FIMC_LITE_MAX_DEVS 3
  27. #define FLITE_REQ_BUFS_MIN 2
  28. #define FLITE_DEFAULT_WIDTH 640
  29. #define FLITE_DEFAULT_HEIGHT 480
  30. /* Bit index definitions for struct fimc_lite::state */
  31. enum {
  32. ST_FLITE_LPM,
  33. ST_FLITE_PENDING,
  34. ST_FLITE_RUN,
  35. ST_FLITE_STREAM,
  36. ST_FLITE_SUSPENDED,
  37. ST_FLITE_OFF,
  38. ST_FLITE_IN_USE,
  39. ST_FLITE_CONFIG,
  40. ST_SENSOR_STREAM,
  41. };
  42. #define FLITE_SD_PAD_SINK 0
  43. #define FLITE_SD_PAD_SOURCE_DMA 1
  44. #define FLITE_SD_PAD_SOURCE_ISP 2
  45. #define FLITE_SD_PADS_NUM 3
  46. /**
  47. * struct flite_drvdata - FIMC-LITE IP variant data structure
  48. * @max_width: maximum camera interface input width in pixels
  49. * @max_height: maximum camera interface input height in pixels
  50. * @out_width_align: minimum output width alignment in pixels
  51. * @win_hor_offs_align: minimum camera interface crop window horizontal
  52. * offset alignment in pixels
  53. * @out_hor_offs_align: minimum output DMA compose rectangle horizontal
  54. * offset alignment in pixels
  55. * @max_dma_bufs: number of output DMA buffer start address registers
  56. * @num_instances: total number of FIMC-LITE IP instances available
  57. */
  58. struct flite_drvdata {
  59. unsigned short max_width;
  60. unsigned short max_height;
  61. unsigned short out_width_align;
  62. unsigned short win_hor_offs_align;
  63. unsigned short out_hor_offs_align;
  64. unsigned short max_dma_bufs;
  65. unsigned short num_instances;
  66. };
  67. struct fimc_lite_events {
  68. unsigned int data_overflow;
  69. };
  70. #define FLITE_MAX_PLANES 1
  71. /**
  72. * struct flite_frame - source/target frame properties
  73. * @f_width: full pixel width
  74. * @f_height: full pixel height
  75. * @rect: crop/composition rectangle
  76. * @fmt: pointer to pixel format description data structure
  77. */
  78. struct flite_frame {
  79. u16 f_width;
  80. u16 f_height;
  81. struct v4l2_rect rect;
  82. const struct fimc_fmt *fmt;
  83. };
  84. /**
  85. * struct flite_buffer - video buffer structure
  86. * @vb: vb2 buffer
  87. * @list: list head for the buffers queue
  88. * @paddr: DMA buffer start address
  89. * @index: DMA start address register's index
  90. */
  91. struct flite_buffer {
  92. struct vb2_v4l2_buffer vb;
  93. struct list_head list;
  94. dma_addr_t paddr;
  95. unsigned short index;
  96. };
  97. /**
  98. * struct fimc_lite - fimc lite structure
  99. * @pdev: pointer to FIMC-LITE platform device
  100. * @dd: SoC specific driver data structure
  101. * @ve: exynos video device entity structure
  102. * @v4l2_dev: pointer to top the level v4l2_device
  103. * @fh: v4l2 file handle
  104. * @alloc_ctx: videobuf2 memory allocator context
  105. * @subdev: FIMC-LITE subdev
  106. * @vd_pad: media (sink) pad for the capture video node
  107. * @subdev_pads: the subdev media pads
  108. * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
  109. * @ctrl_handler: v4l2 control handler
  110. * @test_pattern: test pattern controls
  111. * @index: FIMC-LITE platform device index
  112. * @pipeline: video capture pipeline data structure
  113. * @pipeline_ops: media pipeline ops for the video node driver
  114. * @slock: spinlock protecting this data structure and the hw registers
  115. * @lock: mutex serializing video device and the subdev operations
  116. * @clock: FIMC-LITE gate clock
  117. * @regs: memory mapped io registers
  118. * @irq_queue: interrupt handler waitqueue
  119. * @payload: image size in bytes (w x h x bpp)
  120. * @inp_frame: camera input frame structure
  121. * @out_frame: DMA output frame structure
  122. * @out_path: output data path (DMA or FIFO)
  123. * @source_subdev_grp_id: source subdev group id
  124. * @state: driver state flags
  125. * @pending_buf_q: pending buffers queue head
  126. * @active_buf_q: the queue head of buffers scheduled in hardware
  127. * @vb_queue: vb2 buffers queue
  128. * @buf_index: helps to keep track of the DMA start address register index
  129. * @active_buf_count: number of video buffers scheduled in hardware
  130. * @frame_count: the captured frames counter
  131. * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
  132. */
  133. struct fimc_lite {
  134. struct platform_device *pdev;
  135. struct flite_drvdata *dd;
  136. struct exynos_video_entity ve;
  137. struct v4l2_device *v4l2_dev;
  138. struct v4l2_fh fh;
  139. struct vb2_alloc_ctx *alloc_ctx;
  140. struct v4l2_subdev subdev;
  141. struct media_pad vd_pad;
  142. struct media_pad subdev_pads[FLITE_SD_PADS_NUM];
  143. struct v4l2_subdev *sensor;
  144. struct v4l2_ctrl_handler ctrl_handler;
  145. struct v4l2_ctrl *test_pattern;
  146. int index;
  147. struct mutex lock;
  148. spinlock_t slock;
  149. struct clk *clock;
  150. void __iomem *regs;
  151. wait_queue_head_t irq_queue;
  152. unsigned long payload[FLITE_MAX_PLANES];
  153. struct flite_frame inp_frame;
  154. struct flite_frame out_frame;
  155. atomic_t out_path;
  156. unsigned int source_subdev_grp_id;
  157. unsigned long state;
  158. struct list_head pending_buf_q;
  159. struct list_head active_buf_q;
  160. struct vb2_queue vb_queue;
  161. unsigned short buf_index;
  162. unsigned int frame_count;
  163. unsigned int reqbufs_count;
  164. struct fimc_lite_events events;
  165. bool streaming;
  166. };
  167. static inline bool fimc_lite_active(struct fimc_lite *fimc)
  168. {
  169. unsigned long flags;
  170. bool ret;
  171. spin_lock_irqsave(&fimc->slock, flags);
  172. ret = fimc->state & (1 << ST_FLITE_RUN) ||
  173. fimc->state & (1 << ST_FLITE_PENDING);
  174. spin_unlock_irqrestore(&fimc->slock, flags);
  175. return ret;
  176. }
  177. static inline void fimc_lite_active_queue_add(struct fimc_lite *dev,
  178. struct flite_buffer *buf)
  179. {
  180. list_add_tail(&buf->list, &dev->active_buf_q);
  181. }
  182. static inline struct flite_buffer *fimc_lite_active_queue_pop(
  183. struct fimc_lite *dev)
  184. {
  185. struct flite_buffer *buf = list_entry(dev->active_buf_q.next,
  186. struct flite_buffer, list);
  187. list_del(&buf->list);
  188. return buf;
  189. }
  190. static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev,
  191. struct flite_buffer *buf)
  192. {
  193. list_add_tail(&buf->list, &dev->pending_buf_q);
  194. }
  195. static inline struct flite_buffer *fimc_lite_pending_queue_pop(
  196. struct fimc_lite *dev)
  197. {
  198. struct flite_buffer *buf = list_entry(dev->pending_buf_q.next,
  199. struct flite_buffer, list);
  200. list_del(&buf->list);
  201. return buf;
  202. }
  203. #endif /* FIMC_LITE_H_ */