2 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
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.
12 #include <linux/sizes.h>
14 #include <linux/irqreturn.h>
15 #include <linux/platform_device.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/types.h>
19 #include <linux/videodev2.h>
21 #include <media/media-entity.h>
22 #include <media/videobuf2-core.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-mediabus.h>
26 #include <media/s5p_fimc.h>
28 #define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
29 #define FLITE_CLK_NAME "flite"
30 #define FIMC_LITE_MAX_DEVS 3
31 #define FLITE_REQ_BUFS_MIN 2
33 /* Bit index definitions for struct fimc_lite::state */
46 #define FLITE_SD_PAD_SINK 0
47 #define FLITE_SD_PAD_SOURCE_DMA 1
48 #define FLITE_SD_PAD_SOURCE_ISP 2
49 #define FLITE_SD_PADS_NUM 3
52 * struct flite_drvdata - FIMC-LITE IP variant data structure
53 * @max_width: maximum camera interface input width in pixels
54 * @max_height: maximum camera interface input height in pixels
55 * @out_width_align: minimum output width alignment in pixels
56 * @win_hor_offs_align: minimum camera interface crop window horizontal
57 * offset alignment in pixels
58 * @out_hor_offs_align: minimum output DMA compose rectangle horizontal
59 * offset alignment in pixels
60 * @max_dma_bufs: number of output DMA buffer start address registers
61 * @num_instances: total number of FIMC-LITE IP instances available
63 struct flite_drvdata {
64 unsigned short max_width;
65 unsigned short max_height;
66 unsigned short out_width_align;
67 unsigned short win_hor_offs_align;
68 unsigned short out_hor_offs_align;
69 unsigned short max_dma_bufs;
70 unsigned short num_instances;
73 struct fimc_lite_events {
74 unsigned int data_overflow;
77 #define FLITE_MAX_PLANES 1
80 * struct flite_frame - source/target frame properties
81 * @f_width: full pixel width
82 * @f_height: full pixel height
83 * @rect: crop/composition rectangle
84 * @fmt: pointer to pixel format description data structure
89 struct v4l2_rect rect;
90 const struct fimc_fmt *fmt;
94 * struct flite_buffer - video buffer structure
96 * @list: list head for the buffers queue
97 * @paddr: DMA buffer start address
98 * @index: DMA start address register's index
100 struct flite_buffer {
101 struct vb2_buffer vb;
102 struct list_head list;
104 unsigned short index;
108 * struct fimc_lite - fimc lite structure
109 * @pdev: pointer to FIMC-LITE platform device
110 * @dd: SoC specific driver data structure
111 * @ve: exynos video device entity structure
112 * @v4l2_dev: pointer to top the level v4l2_device
113 * @fh: v4l2 file handle
114 * @alloc_ctx: videobuf2 memory allocator context
115 * @subdev: FIMC-LITE subdev
116 * @vd_pad: media (sink) pad for the capture video node
117 * @subdev_pads: the subdev media pads
118 * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
119 * @ctrl_handler: v4l2 control handler
120 * @test_pattern: test pattern controls
121 * @index: FIMC-LITE platform device index
122 * @pipeline: video capture pipeline data structure
123 * @pipeline_ops: media pipeline ops for the video node driver
124 * @slock: spinlock protecting this data structure and the hw registers
125 * @lock: mutex serializing video device and the subdev operations
126 * @clock: FIMC-LITE gate clock
127 * @regs: memory mapped io registers
128 * @irq_queue: interrupt handler waitqueue
129 * @payload: image size in bytes (w x h x bpp)
130 * @inp_frame: camera input frame structure
131 * @out_frame: DMA output frame structure
132 * @out_path: output data path (DMA or FIFO)
133 * @source_subdev_grp_id: source subdev group id
134 * @state: driver state flags
135 * @pending_buf_q: pending buffers queue head
136 * @active_buf_q: the queue head of buffers scheduled in hardware
137 * @vb_queue: vb2 buffers queue
138 * @buf_index: helps to keep track of the DMA start address register index
139 * @active_buf_count: number of video buffers scheduled in hardware
140 * @frame_count: the captured frames counter
141 * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
144 struct platform_device *pdev;
145 struct flite_drvdata *dd;
146 struct exynos_video_entity ve;
147 struct v4l2_device *v4l2_dev;
149 struct vb2_alloc_ctx *alloc_ctx;
150 struct v4l2_subdev subdev;
151 struct media_pad vd_pad;
152 struct media_pad subdev_pads[FLITE_SD_PADS_NUM];
153 struct v4l2_subdev *sensor;
154 struct v4l2_ctrl_handler ctrl_handler;
155 struct v4l2_ctrl *test_pattern;
163 wait_queue_head_t irq_queue;
165 unsigned long payload[FLITE_MAX_PLANES];
166 struct flite_frame inp_frame;
167 struct flite_frame out_frame;
169 unsigned int source_subdev_grp_id;
172 struct list_head pending_buf_q;
173 struct list_head active_buf_q;
174 struct vb2_queue vb_queue;
175 unsigned short buf_index;
176 unsigned int frame_count;
177 unsigned int reqbufs_count;
179 struct fimc_lite_events events;
183 static inline bool fimc_lite_active(struct fimc_lite *fimc)
188 spin_lock_irqsave(&fimc->slock, flags);
189 ret = fimc->state & (1 << ST_FLITE_RUN) ||
190 fimc->state & (1 << ST_FLITE_PENDING);
191 spin_unlock_irqrestore(&fimc->slock, flags);
195 static inline void fimc_lite_active_queue_add(struct fimc_lite *dev,
196 struct flite_buffer *buf)
198 list_add_tail(&buf->list, &dev->active_buf_q);
201 static inline struct flite_buffer *fimc_lite_active_queue_pop(
202 struct fimc_lite *dev)
204 struct flite_buffer *buf = list_entry(dev->active_buf_q.next,
205 struct flite_buffer, list);
206 list_del(&buf->list);
210 static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev,
211 struct flite_buffer *buf)
213 list_add_tail(&buf->list, &dev->pending_buf_q);
216 static inline struct flite_buffer *fimc_lite_pending_queue_pop(
217 struct fimc_lite *dev)
219 struct flite_buffer *buf = list_entry(dev->pending_buf_q.next,
220 struct flite_buffer, list);
221 list_del(&buf->list);
225 #endif /* FIMC_LITE_H_ */