fimc-lite.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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-core.h>
  20. #include <media/v4l2-device.h>
  21. #include <media/v4l2-mediabus.h>
  22. #include <media/s5p_fimc.h>
  23. #include "fimc-core.h"
  24. #define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
  25. #define FLITE_CLK_NAME "flite"
  26. #define FIMC_LITE_MAX_DEVS 2
  27. #define FLITE_REQ_BUFS_MIN 2
  28. /* Bit index definitions for struct fimc_lite::state */
  29. enum {
  30. ST_FLITE_LPM,
  31. ST_FLITE_PENDING,
  32. ST_FLITE_RUN,
  33. ST_FLITE_STREAM,
  34. ST_FLITE_SUSPENDED,
  35. ST_FLITE_OFF,
  36. ST_FLITE_IN_USE,
  37. ST_FLITE_CONFIG,
  38. ST_SENSOR_STREAM,
  39. };
  40. #define FLITE_SD_PAD_SINK 0
  41. #define FLITE_SD_PAD_SOURCE_DMA 1
  42. #define FLITE_SD_PAD_SOURCE_ISP 2
  43. #define FLITE_SD_PADS_NUM 3
  44. struct flite_variant {
  45. unsigned short max_width;
  46. unsigned short max_height;
  47. unsigned short out_width_align;
  48. unsigned short win_hor_offs_align;
  49. unsigned short out_hor_offs_align;
  50. };
  51. struct flite_drvdata {
  52. struct flite_variant *variant[FIMC_LITE_MAX_DEVS];
  53. };
  54. #define fimc_lite_get_drvdata(_pdev) \
  55. ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data)
  56. struct fimc_lite_events {
  57. unsigned int data_overflow;
  58. };
  59. #define FLITE_MAX_PLANES 1
  60. /**
  61. * struct flite_frame - source/target frame properties
  62. * @f_width: full pixel width
  63. * @f_height: full pixel height
  64. * @rect: crop/composition rectangle
  65. */
  66. struct flite_frame {
  67. u16 f_width;
  68. u16 f_height;
  69. struct v4l2_rect rect;
  70. };
  71. /**
  72. * struct flite_buffer - video buffer structure
  73. * @vb: vb2 buffer
  74. * @list: list head for the buffers queue
  75. * @paddr: precalculated physical address
  76. */
  77. struct flite_buffer {
  78. struct vb2_buffer vb;
  79. struct list_head list;
  80. dma_addr_t paddr;
  81. };
  82. /**
  83. * struct fimc_lite - fimc lite structure
  84. * @pdev: pointer to FIMC-LITE platform device
  85. * @variant: variant information for this IP
  86. * @v4l2_dev: pointer to top the level v4l2_device
  87. * @vfd: video device node
  88. * @fh: v4l2 file handle
  89. * @alloc_ctx: videobuf2 memory allocator context
  90. * @subdev: FIMC-LITE subdev
  91. * @vd_pad: media (sink) pad for the capture video node
  92. * @subdev_pads: the subdev media pads
  93. * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
  94. * @ctrl_handler: v4l2 control handler
  95. * @test_pattern: test pattern controls
  96. * @index: FIMC-LITE platform device index
  97. * @pipeline: video capture pipeline data structure
  98. * @pipeline_ops: media pipeline ops for the video node driver
  99. * @slock: spinlock protecting this data structure and the hw registers
  100. * @lock: mutex serializing video device and the subdev operations
  101. * @clock: FIMC-LITE gate clock
  102. * @regs: memory mapped io registers
  103. * @irq_queue: interrupt handler waitqueue
  104. * @fmt: pointer to color format description structure
  105. * @payload: image size in bytes (w x h x bpp)
  106. * @inp_frame: camera input frame structure
  107. * @out_frame: DMA output frame structure
  108. * @out_path: output data path (DMA or FIFO)
  109. * @source_subdev_grp_id: source subdev group id
  110. * @state: driver state flags
  111. * @pending_buf_q: pending buffers queue head
  112. * @active_buf_q: the queue head of buffers scheduled in hardware
  113. * @vb_queue: vb2 buffers queue
  114. * @active_buf_count: number of video buffers scheduled in hardware
  115. * @frame_count: the captured frames counter
  116. * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
  117. * @ref_count: driver's private reference counter
  118. */
  119. struct fimc_lite {
  120. struct platform_device *pdev;
  121. struct flite_variant *variant;
  122. struct v4l2_device *v4l2_dev;
  123. struct video_device vfd;
  124. struct v4l2_fh fh;
  125. struct vb2_alloc_ctx *alloc_ctx;
  126. struct v4l2_subdev subdev;
  127. struct media_pad vd_pad;
  128. struct media_pad subdev_pads[FLITE_SD_PADS_NUM];
  129. struct v4l2_subdev *sensor;
  130. struct v4l2_ctrl_handler ctrl_handler;
  131. struct v4l2_ctrl *test_pattern;
  132. u32 index;
  133. struct fimc_pipeline pipeline;
  134. const struct fimc_pipeline_ops *pipeline_ops;
  135. struct mutex lock;
  136. spinlock_t slock;
  137. struct clk *clock;
  138. void __iomem *regs;
  139. wait_queue_head_t irq_queue;
  140. const struct fimc_fmt *fmt;
  141. unsigned long payload[FLITE_MAX_PLANES];
  142. struct flite_frame inp_frame;
  143. struct flite_frame out_frame;
  144. atomic_t out_path;
  145. unsigned int source_subdev_grp_id;
  146. unsigned long state;
  147. struct list_head pending_buf_q;
  148. struct list_head active_buf_q;
  149. struct vb2_queue vb_queue;
  150. unsigned int frame_count;
  151. unsigned int reqbufs_count;
  152. int ref_count;
  153. struct fimc_lite_events events;
  154. };
  155. static inline bool fimc_lite_active(struct fimc_lite *fimc)
  156. {
  157. unsigned long flags;
  158. bool ret;
  159. spin_lock_irqsave(&fimc->slock, flags);
  160. ret = fimc->state & (1 << ST_FLITE_RUN) ||
  161. fimc->state & (1 << ST_FLITE_PENDING);
  162. spin_unlock_irqrestore(&fimc->slock, flags);
  163. return ret;
  164. }
  165. static inline void fimc_lite_active_queue_add(struct fimc_lite *dev,
  166. struct flite_buffer *buf)
  167. {
  168. list_add_tail(&buf->list, &dev->active_buf_q);
  169. }
  170. static inline struct flite_buffer *fimc_lite_active_queue_pop(
  171. struct fimc_lite *dev)
  172. {
  173. struct flite_buffer *buf = list_entry(dev->active_buf_q.next,
  174. struct flite_buffer, list);
  175. list_del(&buf->list);
  176. return buf;
  177. }
  178. static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev,
  179. struct flite_buffer *buf)
  180. {
  181. list_add_tail(&buf->list, &dev->pending_buf_q);
  182. }
  183. static inline struct flite_buffer *fimc_lite_pending_queue_pop(
  184. struct fimc_lite *dev)
  185. {
  186. struct flite_buffer *buf = list_entry(dev->pending_buf_q.next,
  187. struct flite_buffer, list);
  188. list_del(&buf->list);
  189. return buf;
  190. }
  191. #endif /* FIMC_LITE_H_ */