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-device.h>
24 #include <media/v4l2-mediabus.h>
25 #include <media/s5p_fimc.h>
27 #include "fimc-core.h"
29 #define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
30 #define FLITE_CLK_NAME "flite"
31 #define FIMC_LITE_MAX_DEVS 2
32 #define FLITE_REQ_BUFS_MIN 2
34 /* Bit index definitions for struct fimc_lite::state */
47 #define FLITE_SD_PAD_SINK 0
48 #define FLITE_SD_PAD_SOURCE 1
49 #define FLITE_SD_PADS_NUM 2
51 struct flite_variant
{
52 unsigned short max_width
;
53 unsigned short max_height
;
54 unsigned short out_width_align
;
55 unsigned short win_hor_offs_align
;
56 unsigned short out_hor_offs_align
;
59 struct flite_drvdata
{
60 struct flite_variant
*variant
[FIMC_LITE_MAX_DEVS
];
63 #define fimc_lite_get_drvdata(_pdev) \
64 ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data)
66 struct fimc_lite_events
{
67 unsigned int data_overflow
;
70 #define FLITE_MAX_PLANES 1
73 * struct flite_frame - source/target frame properties
74 * @f_width: full pixel width
75 * @f_height: full pixel height
76 * @rect: crop/composition rectangle
81 struct v4l2_rect rect
;
85 * struct flite_buffer - video buffer structure
87 * @list: list head for the buffers queue
88 * @paddr: precalculated physical address
92 struct list_head list
;
97 * struct fimc_lite - fimc lite structure
98 * @pdev: pointer to FIMC-LITE platform device
99 * @variant: variant information for this IP
100 * @v4l2_dev: pointer to top the level v4l2_device
101 * @vfd: video device node
102 * @fh: v4l2 file handle
103 * @alloc_ctx: videobuf2 memory allocator context
104 * @subdev: FIMC-LITE subdev
105 * @vd_pad: media (sink) pad for the capture video node
106 * @subdev_pads: the subdev media pads
107 * @ctrl_handler: v4l2 control handler
108 * @test_pattern: test pattern controls
109 * @index: FIMC-LITE platform device index
110 * @pipeline: video capture pipeline data structure
111 * @pipeline_ops: media pipeline ops for the video node driver
112 * @slock: spinlock protecting this data structure and the hw registers
113 * @lock: mutex serializing video device and the subdev operations
114 * @clock: FIMC-LITE gate clock
115 * @regs: memory mapped io registers
116 * @irq_queue: interrupt handler waitqueue
117 * @fmt: pointer to color format description structure
118 * @payload: image size in bytes (w x h x bpp)
119 * @inp_frame: camera input frame structure
120 * @out_frame: DMA output frame structure
121 * @out_path: output data path (DMA or FIFO)
122 * @source_subdev_grp_id: source subdev group id
123 * @state: driver state flags
124 * @pending_buf_q: pending buffers queue head
125 * @active_buf_q: the queue head of buffers scheduled in hardware
126 * @vb_queue: vb2 buffers queue
127 * @active_buf_count: number of video buffers scheduled in hardware
128 * @frame_count: the captured frames counter
129 * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
130 * @ref_count: driver's private reference counter
133 struct platform_device
*pdev
;
134 struct flite_variant
*variant
;
135 struct v4l2_device
*v4l2_dev
;
136 struct video_device vfd
;
138 struct vb2_alloc_ctx
*alloc_ctx
;
139 struct v4l2_subdev subdev
;
140 struct media_pad vd_pad
;
141 struct media_pad subdev_pads
[FLITE_SD_PADS_NUM
];
142 struct v4l2_ctrl_handler ctrl_handler
;
143 struct v4l2_ctrl
*test_pattern
;
145 struct fimc_pipeline pipeline
;
146 const struct fimc_pipeline_ops
*pipeline_ops
;
153 wait_queue_head_t irq_queue
;
155 const struct fimc_fmt
*fmt
;
156 unsigned long payload
[FLITE_MAX_PLANES
];
157 struct flite_frame inp_frame
;
158 struct flite_frame out_frame
;
159 enum fimc_datapath out_path
;
160 unsigned int source_subdev_grp_id
;
163 struct list_head pending_buf_q
;
164 struct list_head active_buf_q
;
165 struct vb2_queue vb_queue
;
166 unsigned int frame_count
;
167 unsigned int reqbufs_count
;
170 struct fimc_lite_events events
;
173 static inline bool fimc_lite_active(struct fimc_lite
*fimc
)
178 spin_lock_irqsave(&fimc
->slock
, flags
);
179 ret
= fimc
->state
& (1 << ST_FLITE_RUN
) ||
180 fimc
->state
& (1 << ST_FLITE_PENDING
);
181 spin_unlock_irqrestore(&fimc
->slock
, flags
);
185 static inline void fimc_lite_active_queue_add(struct fimc_lite
*dev
,
186 struct flite_buffer
*buf
)
188 list_add_tail(&buf
->list
, &dev
->active_buf_q
);
191 static inline struct flite_buffer
*fimc_lite_active_queue_pop(
192 struct fimc_lite
*dev
)
194 struct flite_buffer
*buf
= list_entry(dev
->active_buf_q
.next
,
195 struct flite_buffer
, list
);
196 list_del(&buf
->list
);
200 static inline void fimc_lite_pending_queue_add(struct fimc_lite
*dev
,
201 struct flite_buffer
*buf
)
203 list_add_tail(&buf
->list
, &dev
->pending_buf_q
);
206 static inline struct flite_buffer
*fimc_lite_pending_queue_pop(
207 struct fimc_lite
*dev
)
209 struct flite_buffer
*buf
= list_entry(dev
->pending_buf_q
.next
,
210 struct flite_buffer
, list
);
211 list_del(&buf
->list
);
215 #endif /* FIMC_LITE_H_ */