diff options
Diffstat (limited to 'drivers/media/platform/exynos4-is/fimc-lite.h')
-rw-r--r-- | drivers/media/platform/exynos4-is/fimc-lite.h | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h new file mode 100644 index 000000000000..4c2345086366 --- /dev/null +++ b/drivers/media/platform/exynos4-is/fimc-lite.h | |||
@@ -0,0 +1,217 @@ | |||
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 | |||
9 | #ifndef FIMC_LITE_H_ | ||
10 | #define FIMC_LITE_H_ | ||
11 | |||
12 | #include <linux/sizes.h> | ||
13 | #include <linux/io.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> | ||
20 | |||
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> | ||
27 | |||
28 | #define FIMC_LITE_DRV_NAME "exynos-fimc-lite" | ||
29 | #define FLITE_CLK_NAME "flite" | ||
30 | #define FIMC_LITE_MAX_DEVS 2 | ||
31 | #define FLITE_REQ_BUFS_MIN 2 | ||
32 | |||
33 | /* Bit index definitions for struct fimc_lite::state */ | ||
34 | enum { | ||
35 | ST_FLITE_LPM, | ||
36 | ST_FLITE_PENDING, | ||
37 | ST_FLITE_RUN, | ||
38 | ST_FLITE_STREAM, | ||
39 | ST_FLITE_SUSPENDED, | ||
40 | ST_FLITE_OFF, | ||
41 | ST_FLITE_IN_USE, | ||
42 | ST_FLITE_CONFIG, | ||
43 | ST_SENSOR_STREAM, | ||
44 | }; | ||
45 | |||
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 | ||
50 | |||
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; | ||
57 | }; | ||
58 | |||
59 | struct flite_drvdata { | ||
60 | struct flite_variant *variant[FIMC_LITE_MAX_DEVS]; | ||
61 | }; | ||
62 | |||
63 | #define fimc_lite_get_drvdata(_pdev) \ | ||
64 | ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data) | ||
65 | |||
66 | struct fimc_lite_events { | ||
67 | unsigned int data_overflow; | ||
68 | }; | ||
69 | |||
70 | #define FLITE_MAX_PLANES 1 | ||
71 | |||
72 | /** | ||
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 | ||
77 | */ | ||
78 | struct flite_frame { | ||
79 | u16 f_width; | ||
80 | u16 f_height; | ||
81 | struct v4l2_rect rect; | ||
82 | }; | ||
83 | |||
84 | /** | ||
85 | * struct flite_buffer - video buffer structure | ||
86 | * @vb: vb2 buffer | ||
87 | * @list: list head for the buffers queue | ||
88 | * @paddr: precalculated physical address | ||
89 | */ | ||
90 | struct flite_buffer { | ||
91 | struct vb2_buffer vb; | ||
92 | struct list_head list; | ||
93 | dma_addr_t paddr; | ||
94 | }; | ||
95 | |||
96 | /** | ||
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 | * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS | ||
108 | * @ctrl_handler: v4l2 control handler | ||
109 | * @test_pattern: test pattern controls | ||
110 | * @index: FIMC-LITE platform device index | ||
111 | * @pipeline: video capture pipeline data structure | ||
112 | * @pipeline_ops: media pipeline ops for the video node driver | ||
113 | * @slock: spinlock protecting this data structure and the hw registers | ||
114 | * @lock: mutex serializing video device and the subdev operations | ||
115 | * @clock: FIMC-LITE gate clock | ||
116 | * @regs: memory mapped io registers | ||
117 | * @irq_queue: interrupt handler waitqueue | ||
118 | * @fmt: pointer to color format description structure | ||
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 | * @active_buf_count: number of video buffers scheduled in hardware | ||
129 | * @frame_count: the captured frames counter | ||
130 | * @reqbufs_count: the number of buffers requested with REQBUFS ioctl | ||
131 | * @ref_count: driver's private reference counter | ||
132 | */ | ||
133 | struct fimc_lite { | ||
134 | struct platform_device *pdev; | ||
135 | struct flite_variant *variant; | ||
136 | struct v4l2_device *v4l2_dev; | ||
137 | struct video_device vfd; | ||
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 | u32 index; | ||
147 | struct fimc_pipeline pipeline; | ||
148 | const struct fimc_pipeline_ops *pipeline_ops; | ||
149 | |||
150 | struct mutex lock; | ||
151 | spinlock_t slock; | ||
152 | |||
153 | struct clk *clock; | ||
154 | void __iomem *regs; | ||
155 | wait_queue_head_t irq_queue; | ||
156 | |||
157 | const struct fimc_fmt *fmt; | ||
158 | unsigned long payload[FLITE_MAX_PLANES]; | ||
159 | struct flite_frame inp_frame; | ||
160 | struct flite_frame out_frame; | ||
161 | atomic_t out_path; | ||
162 | unsigned int source_subdev_grp_id; | ||
163 | |||
164 | unsigned long state; | ||
165 | struct list_head pending_buf_q; | ||
166 | struct list_head active_buf_q; | ||
167 | struct vb2_queue vb_queue; | ||
168 | unsigned int frame_count; | ||
169 | unsigned int reqbufs_count; | ||
170 | int ref_count; | ||
171 | |||
172 | struct fimc_lite_events events; | ||
173 | }; | ||
174 | |||
175 | static inline bool fimc_lite_active(struct fimc_lite *fimc) | ||
176 | { | ||
177 | unsigned long flags; | ||
178 | bool ret; | ||
179 | |||
180 | spin_lock_irqsave(&fimc->slock, flags); | ||
181 | ret = fimc->state & (1 << ST_FLITE_RUN) || | ||
182 | fimc->state & (1 << ST_FLITE_PENDING); | ||
183 | spin_unlock_irqrestore(&fimc->slock, flags); | ||
184 | return ret; | ||
185 | } | ||
186 | |||
187 | static inline void fimc_lite_active_queue_add(struct fimc_lite *dev, | ||
188 | struct flite_buffer *buf) | ||
189 | { | ||
190 | list_add_tail(&buf->list, &dev->active_buf_q); | ||
191 | } | ||
192 | |||
193 | static inline struct flite_buffer *fimc_lite_active_queue_pop( | ||
194 | struct fimc_lite *dev) | ||
195 | { | ||
196 | struct flite_buffer *buf = list_entry(dev->active_buf_q.next, | ||
197 | struct flite_buffer, list); | ||
198 | list_del(&buf->list); | ||
199 | return buf; | ||
200 | } | ||
201 | |||
202 | static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev, | ||
203 | struct flite_buffer *buf) | ||
204 | { | ||
205 | list_add_tail(&buf->list, &dev->pending_buf_q); | ||
206 | } | ||
207 | |||
208 | static inline struct flite_buffer *fimc_lite_pending_queue_pop( | ||
209 | struct fimc_lite *dev) | ||
210 | { | ||
211 | struct flite_buffer *buf = list_entry(dev->pending_buf_q.next, | ||
212 | struct flite_buffer, list); | ||
213 | list_del(&buf->list); | ||
214 | return buf; | ||
215 | } | ||
216 | |||
217 | #endif /* FIMC_LITE_H_ */ | ||