fimc-lite.h 5.7 KB

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