Commit | Line | Data |
---|---|---|
5fd8f738 | 1 | /* |
0c9204d3 | 2 | * Copyright (C) 2010 - 2012 Samsung Electronics Co., Ltd. |
5fd8f738 SN |
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_CORE_H_ | |
10 | #define FIMC_CORE_H_ | |
11 | ||
5f3cc447 SN |
12 | /*#define DEBUG*/ |
13 | ||
2319c539 | 14 | #include <linux/platform_device.h> |
88fa8311 | 15 | #include <linux/regmap.h> |
aee7126c | 16 | #include <linux/sched.h> |
4ecbf5d1 | 17 | #include <linux/spinlock.h> |
5fd8f738 | 18 | #include <linux/types.h> |
aee7126c | 19 | #include <linux/videodev2.h> |
2dab38e2 | 20 | #include <linux/io.h> |
25422781 | 21 | #include <linux/sizes.h> |
574e1717 SN |
22 | |
23 | #include <media/media-entity.h> | |
2dab38e2 | 24 | #include <media/videobuf2-core.h> |
131b6c61 | 25 | #include <media/v4l2-ctrls.h> |
5fd8f738 SN |
26 | #include <media/v4l2-device.h> |
27 | #include <media/v4l2-mem2mem.h> | |
5f3cc447 | 28 | #include <media/v4l2-mediabus.h> |
df7e09a3 | 29 | #include <media/s5p_fimc.h> |
aee7126c | 30 | |
5fd8f738 | 31 | #define dbg(fmt, args...) \ |
1e004695 | 32 | pr_debug("%s:%d: " fmt "\n", __func__, __LINE__, ##args) |
5fd8f738 | 33 | |
5f3cc447 SN |
34 | /* Time to wait for next frame VSYNC interrupt while stopping operation. */ |
35 | #define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000) | |
ebdfea81 | 36 | #define MAX_FIMC_CLOCKS 2 |
d3953223 | 37 | #define FIMC_MODULE_NAME "s5p-fimc" |
a7d5bbcf | 38 | #define FIMC_MAX_DEVS 4 |
5fd8f738 SN |
39 | #define FIMC_MAX_OUT_BUFS 4 |
40 | #define SCALER_MAX_HRATIO 64 | |
41 | #define SCALER_MAX_VRATIO 64 | |
548aafcd | 42 | #define DMA_MIN_SIZE 8 |
237e0265 | 43 | #define FIMC_CAMIF_MAX_HEIGHT 0x2000 |
14783d25 SN |
44 | #define FIMC_MAX_JPEG_BUF_SIZE (10 * SZ_1M) |
45 | #define FIMC_MAX_PLANES 3 | |
e80cb1fa SN |
46 | #define FIMC_PIX_LIMITS_MAX 4 |
47 | #define FIMC_DEF_MIN_SIZE 16 | |
48 | #define FIMC_DEF_HEIGHT_ALIGN 2 | |
49 | #define FIMC_DEF_HOR_OFFS_ALIGN 1 | |
5fd8f738 | 50 | |
a25be18d SN |
51 | /* indices to the clocks array */ |
52 | enum { | |
53 | CLK_BUS, | |
54 | CLK_GATE, | |
a25be18d SN |
55 | }; |
56 | ||
5f3cc447 | 57 | enum fimc_dev_flags { |
e9e21083 SN |
58 | ST_LPM, |
59 | /* m2m node */ | |
60 | ST_M2M_RUN, | |
5fd8f738 | 61 | ST_M2M_PEND, |
e9e21083 SN |
62 | ST_M2M_SUSPENDING, |
63 | ST_M2M_SUSPENDED, | |
64 | /* capture node */ | |
5f3cc447 SN |
65 | ST_CAPT_PEND, |
66 | ST_CAPT_RUN, | |
67 | ST_CAPT_STREAM, | |
4db5e27e | 68 | ST_CAPT_ISP_STREAM, |
3e4748d8 | 69 | ST_CAPT_SUSPENDED, |
5f3cc447 | 70 | ST_CAPT_SHUT, |
e9e21083 | 71 | ST_CAPT_BUSY, |
131b6c61 | 72 | ST_CAPT_APPLY_CFG, |
ee7160e5 | 73 | ST_CAPT_JPEG, |
5fd8f738 SN |
74 | }; |
75 | ||
e9e21083 | 76 | #define fimc_m2m_active(dev) test_bit(ST_M2M_RUN, &(dev)->state) |
5fd8f738 SN |
77 | #define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state) |
78 | ||
5f3cc447 SN |
79 | #define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state) |
80 | #define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state) | |
e9e21083 | 81 | #define fimc_capture_busy(dev) test_bit(ST_CAPT_BUSY, &(dev)->state) |
5f3cc447 | 82 | |
5fd8f738 | 83 | enum fimc_datapath { |
3d112d9a SN |
84 | FIMC_IO_NONE, |
85 | FIMC_IO_CAMERA, | |
86 | FIMC_IO_DMA, | |
87 | FIMC_IO_LCDFIFO, | |
88 | FIMC_IO_WRITEBACK, | |
89 | FIMC_IO_ISP, | |
5fd8f738 SN |
90 | }; |
91 | ||
92 | enum fimc_color_fmt { | |
14783d25 | 93 | FIMC_FMT_RGB444 = 0x10, |
3d112d9a SN |
94 | FIMC_FMT_RGB555, |
95 | FIMC_FMT_RGB565, | |
96 | FIMC_FMT_RGB666, | |
97 | FIMC_FMT_RGB888, | |
98 | FIMC_FMT_RGB30_LOCAL, | |
99 | FIMC_FMT_YCBCR420 = 0x20, | |
100 | FIMC_FMT_YCBYCR422, | |
101 | FIMC_FMT_YCRYCB422, | |
102 | FIMC_FMT_CBYCRY422, | |
103 | FIMC_FMT_CRYCBY422, | |
104 | FIMC_FMT_YCBCR444_LOCAL, | |
14783d25 | 105 | FIMC_FMT_RAW8 = 0x40, |
3d112d9a SN |
106 | FIMC_FMT_RAW10, |
107 | FIMC_FMT_RAW12, | |
14783d25 SN |
108 | FIMC_FMT_JPEG = 0x80, |
109 | FIMC_FMT_YUYV_JPEG = 0x100, | |
5fd8f738 SN |
110 | }; |
111 | ||
14783d25 | 112 | #define fimc_fmt_is_user_defined(x) (!!((x) & 0x180)) |
237e0265 | 113 | #define fimc_fmt_is_rgb(x) (!!((x) & 0x10)) |
548aafcd | 114 | |
4db5e27e SN |
115 | #define IS_M2M(__strt) ((__strt) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || \ |
116 | __strt == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) | |
117 | ||
5fd8f738 | 118 | /* The hardware context state. */ |
548aafcd | 119 | #define FIMC_PARAMS (1 << 0) |
81619ce1 | 120 | #define FIMC_COMPOSE (1 << 1) |
237e0265 SN |
121 | #define FIMC_CTX_M2M (1 << 16) |
122 | #define FIMC_CTX_CAP (1 << 17) | |
123 | #define FIMC_CTX_SHUT (1 << 18) | |
5fd8f738 SN |
124 | |
125 | /* Image conversion flags */ | |
126 | #define FIMC_IN_DMA_ACCESS_TILED (1 << 0) | |
127 | #define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0) | |
128 | #define FIMC_OUT_DMA_ACCESS_TILED (1 << 1) | |
129 | #define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1) | |
130 | #define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2) | |
131 | #define FIMC_SCAN_MODE_INTERLACED (1 << 2) | |
548aafcd SN |
132 | /* |
133 | * YCbCr data dynamic range for RGB-YUV color conversion. | |
134 | * Y/Cb/Cr: (0 ~ 255) */ | |
5fd8f738 SN |
135 | #define FIMC_COLOR_RANGE_WIDE (0 << 3) |
136 | /* Y (16 ~ 235), Cb/Cr (16 ~ 240) */ | |
137 | #define FIMC_COLOR_RANGE_NARROW (1 << 3) | |
138 | ||
5fd8f738 SN |
139 | /** |
140 | * struct fimc_dma_offset - pixel offset information for DMA | |
141 | * @y_h: y value horizontal offset | |
142 | * @y_v: y value vertical offset | |
143 | * @cb_h: cb value horizontal offset | |
144 | * @cb_v: cb value vertical offset | |
145 | * @cr_h: cr value horizontal offset | |
146 | * @cr_v: cr value vertical offset | |
147 | */ | |
148 | struct fimc_dma_offset { | |
149 | int y_h; | |
150 | int y_v; | |
151 | int cb_h; | |
152 | int cb_v; | |
153 | int cr_h; | |
154 | int cr_v; | |
155 | }; | |
156 | ||
157 | /** | |
3495dcef | 158 | * struct fimc_effect - color effect information |
5fd8f738 SN |
159 | * @type: effect type |
160 | * @pat_cb: cr value when type is "arbitrary" | |
161 | * @pat_cr: cr value when type is "arbitrary" | |
162 | */ | |
163 | struct fimc_effect { | |
164 | u32 type; | |
165 | u8 pat_cb; | |
166 | u8 pat_cr; | |
167 | }; | |
168 | ||
169 | /** | |
170 | * struct fimc_scaler - the configuration data for FIMC inetrnal scaler | |
548aafcd SN |
171 | * @scaleup_h: flag indicating scaling up horizontally |
172 | * @scaleup_v: flag indicating scaling up vertically | |
173 | * @copy_mode: flag indicating transparent DMA transfer (no scaling | |
174 | * and color format conversion) | |
175 | * @enabled: flag indicating if the scaler is used | |
5fd8f738 SN |
176 | * @hfactor: horizontal shift factor |
177 | * @vfactor: vertical shift factor | |
178 | * @pre_hratio: horizontal ratio of the prescaler | |
179 | * @pre_vratio: vertical ratio of the prescaler | |
180 | * @pre_dst_width: the prescaler's destination width | |
181 | * @pre_dst_height: the prescaler's destination height | |
5fd8f738 SN |
182 | * @main_hratio: the main scaler's horizontal ratio |
183 | * @main_vratio: the main scaler's vertical ratio | |
548aafcd SN |
184 | * @real_width: source pixel (width - offset) |
185 | * @real_height: source pixel (height - offset) | |
5fd8f738 SN |
186 | */ |
187 | struct fimc_scaler { | |
dda7ae78 SN |
188 | unsigned int scaleup_h:1; |
189 | unsigned int scaleup_v:1; | |
190 | unsigned int copy_mode:1; | |
191 | unsigned int enabled:1; | |
5fd8f738 SN |
192 | u32 hfactor; |
193 | u32 vfactor; | |
194 | u32 pre_hratio; | |
195 | u32 pre_vratio; | |
196 | u32 pre_dst_width; | |
197 | u32 pre_dst_height; | |
5fd8f738 SN |
198 | u32 main_hratio; |
199 | u32 main_vratio; | |
200 | u32 real_width; | |
201 | u32 real_height; | |
5fd8f738 SN |
202 | }; |
203 | ||
204 | /** | |
205 | * struct fimc_addr - the FIMC physical address set for DMA | |
5fd8f738 SN |
206 | * @y: luminance plane physical address |
207 | * @cb: Cb plane physical address | |
208 | * @cr: Cr plane physical address | |
209 | */ | |
210 | struct fimc_addr { | |
211 | u32 y; | |
212 | u32 cb; | |
213 | u32 cr; | |
214 | }; | |
215 | ||
216 | /** | |
217 | * struct fimc_vid_buffer - the driver's video buffer | |
5f3cc447 | 218 | * @vb: v4l videobuf buffer |
3495dcef | 219 | * @list: linked list structure for buffer queue |
5f3cc447 SN |
220 | * @paddr: precalculated physical address set |
221 | * @index: buffer index for the output DMA engine | |
5fd8f738 SN |
222 | */ |
223 | struct fimc_vid_buffer { | |
2dab38e2 SN |
224 | struct vb2_buffer vb; |
225 | struct list_head list; | |
5f3cc447 SN |
226 | struct fimc_addr paddr; |
227 | int index; | |
5fd8f738 SN |
228 | }; |
229 | ||
230 | /** | |
548aafcd | 231 | * struct fimc_frame - source/target frame properties |
5fd8f738 SN |
232 | * @f_width: image full width (virtual screen size) |
233 | * @f_height: image full height (virtual screen size) | |
234 | * @o_width: original image width as set by S_FMT | |
235 | * @o_height: original image height as set by S_FMT | |
236 | * @offs_h: image horizontal pixel offset | |
237 | * @offs_v: image vertical pixel offset | |
238 | * @width: image pixel width | |
239 | * @height: image pixel weight | |
ef7af59b | 240 | * @payload: image size in bytes (w x h x bpp) |
fa8880be | 241 | * @bytesperline: bytesperline value for each plane |
3495dcef | 242 | * @paddr: image frame buffer physical addresses |
5fd8f738 | 243 | * @dma_offset: DMA offset in bytes |
3495dcef | 244 | * @fmt: fimc color format pointer |
5fd8f738 SN |
245 | */ |
246 | struct fimc_frame { | |
247 | u32 f_width; | |
248 | u32 f_height; | |
249 | u32 o_width; | |
250 | u32 o_height; | |
251 | u32 offs_h; | |
252 | u32 offs_v; | |
253 | u32 width; | |
254 | u32 height; | |
14783d25 | 255 | unsigned int payload[VIDEO_MAX_PLANES]; |
fa8880be | 256 | unsigned int bytesperline[VIDEO_MAX_PLANES]; |
5fd8f738 SN |
257 | struct fimc_addr paddr; |
258 | struct fimc_dma_offset dma_offset; | |
259 | struct fimc_fmt *fmt; | |
dafb9c70 | 260 | u8 alpha; |
5fd8f738 SN |
261 | }; |
262 | ||
263 | /** | |
264 | * struct fimc_m2m_device - v4l2 memory-to-memory device data | |
265 | * @vfd: the video device node for v4l2 m2m mode | |
5fd8f738 SN |
266 | * @m2m_dev: v4l2 memory-to-memory device data |
267 | * @ctx: hardware context data | |
268 | * @refcnt: the reference counter | |
269 | */ | |
270 | struct fimc_m2m_device { | |
bbc5296f | 271 | struct video_device vfd; |
5fd8f738 SN |
272 | struct v4l2_m2m_dev *m2m_dev; |
273 | struct fimc_ctx *ctx; | |
274 | int refcnt; | |
275 | }; | |
276 | ||
88fa8311 SN |
277 | #define FIMC_SD_PAD_SINK_CAM 0 |
278 | #define FIMC_SD_PAD_SINK_FIFO 1 | |
279 | #define FIMC_SD_PAD_SOURCE 2 | |
280 | #define FIMC_SD_PADS_NUM 3 | |
237e0265 | 281 | |
5f3cc447 SN |
282 | /** |
283 | * struct fimc_vid_cap - camera capture device information | |
284 | * @ctx: hardware context data | |
285 | * @vfd: video device node for camera capture mode | |
237e0265 | 286 | * @subdev: subdev exposing the FIMC processing block |
574e1717 | 287 | * @vd_pad: fimc video capture node pad |
237e0265 | 288 | * @sd_pads: fimc video processing block pads |
88fa8311 SN |
289 | * @ci_fmt: image format at the FIMC camera input (and the scaler output) |
290 | * @wb_fmt: image format at the FIMC ISP Writeback input | |
291 | * @source_config: external image source related configuration structure | |
5f3cc447 SN |
292 | * @pending_buf_q: the pending buffer queue head |
293 | * @active_buf_q: the queue head of buffers scheduled in hardware | |
294 | * @vbq: the capture am video buffer queue | |
295 | * @active_buf_cnt: number of video buffers scheduled in hardware | |
296 | * @buf_index: index for managing the output DMA buffers | |
297 | * @frame_count: the frame counter for statistics | |
298 | * @reqbufs_count: the number of buffers requested in REQBUFS ioctl | |
299 | * @input_index: input (camera sensor) index | |
300 | * @refcnt: driver's private reference counter | |
d09a7dc8 | 301 | * @input: capture input type, grp_id of the attached subdev |
d3953223 | 302 | * @user_subdev_api: true if subdevs are not configured by the host driver |
5f3cc447 SN |
303 | */ |
304 | struct fimc_vid_cap { | |
305 | struct fimc_ctx *ctx; | |
2dab38e2 | 306 | struct vb2_alloc_ctx *alloc_ctx; |
31d34d9b | 307 | struct video_device vfd; |
693f5c40 | 308 | struct v4l2_subdev subdev; |
574e1717 | 309 | struct media_pad vd_pad; |
237e0265 | 310 | struct media_pad sd_pads[FIMC_SD_PADS_NUM]; |
88fa8311 SN |
311 | struct v4l2_mbus_framefmt ci_fmt; |
312 | struct v4l2_mbus_framefmt wb_fmt; | |
313 | struct fimc_source_info source_config; | |
5f3cc447 SN |
314 | struct list_head pending_buf_q; |
315 | struct list_head active_buf_q; | |
2dab38e2 | 316 | struct vb2_queue vbq; |
5f3cc447 SN |
317 | int active_buf_cnt; |
318 | int buf_index; | |
319 | unsigned int frame_count; | |
320 | unsigned int reqbufs_count; | |
321 | int input_index; | |
322 | int refcnt; | |
d09a7dc8 | 323 | u32 input; |
d3953223 | 324 | bool user_subdev_api; |
5f3cc447 SN |
325 | }; |
326 | ||
a7d5bbcf SN |
327 | /** |
328 | * struct fimc_pix_limit - image pixel size limits in various IP configurations | |
329 | * | |
330 | * @scaler_en_w: max input pixel width when the scaler is enabled | |
331 | * @scaler_dis_w: max input pixel width when the scaler is disabled | |
332 | * @in_rot_en_h: max input width with the input rotator is on | |
333 | * @in_rot_dis_w: max input width with the input rotator is off | |
334 | * @out_rot_en_w: max output width with the output rotator on | |
335 | * @out_rot_dis_w: max output width with the output rotator off | |
336 | */ | |
337 | struct fimc_pix_limit { | |
338 | u16 scaler_en_w; | |
339 | u16 scaler_dis_w; | |
340 | u16 in_rot_en_h; | |
341 | u16 in_rot_dis_w; | |
342 | u16 out_rot_en_w; | |
343 | u16 out_rot_dis_w; | |
344 | }; | |
345 | ||
5fd8f738 | 346 | /** |
bb7c276e | 347 | * struct fimc_variant - FIMC device variant information |
5fd8f738 SN |
348 | * @has_inp_rot: set if has input rotator |
349 | * @has_out_rot: set if has output rotator | |
b241c6d6 HK |
350 | * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register |
351 | * are present in this IP revision | |
d3953223 | 352 | * @has_cam_if: set if this instance has a camera input interface |
405f230c | 353 | * @has_isp_wb: set if this instance has ISP writeback input |
a7d5bbcf | 354 | * @pix_limit: pixel size constraints for the scaler |
5fd8f738 SN |
355 | * @min_inp_pixsize: minimum input pixel size |
356 | * @min_out_pixsize: minimum output pixel size | |
a7d5bbcf | 357 | * @hor_offs_align: horizontal pixel offset aligment |
9c63afcb | 358 | * @min_vsize_align: minimum vertical pixel size alignment |
5fd8f738 | 359 | */ |
bb7c276e | 360 | struct fimc_variant { |
5fd8f738 SN |
361 | unsigned int has_inp_rot:1; |
362 | unsigned int has_out_rot:1; | |
b241c6d6 | 363 | unsigned int has_mainscaler_ext:1; |
d3953223 | 364 | unsigned int has_cam_if:1; |
405f230c | 365 | unsigned int has_isp_wb:1; |
405f230c | 366 | const struct fimc_pix_limit *pix_limit; |
5fd8f738 SN |
367 | u16 min_inp_pixsize; |
368 | u16 min_out_pixsize; | |
a7d5bbcf | 369 | u16 hor_offs_align; |
9c63afcb | 370 | u16 min_vsize_align; |
5fd8f738 SN |
371 | }; |
372 | ||
373 | /** | |
bb7c276e SN |
374 | * struct fimc_drvdata - per device type driver data |
375 | * @variant: variant information for this device | |
376 | * @num_entities: number of fimc instances available in a SoC | |
377 | * @lclk_frequency: local bus clock frequency | |
e80cb1fa SN |
378 | * @cistatus2: 1 if the FIMC IPs have CISTATUS2 register |
379 | * @dma_pix_hoff: the horizontal DMA offset unit: 1 - pixels, 0 - bytes | |
380 | * @alpha_color: 1 if alpha color component is supported | |
381 | * @out_buf_count: maximum number of output DMA buffers supported | |
5fd8f738 | 382 | */ |
bb7c276e | 383 | struct fimc_drvdata { |
405f230c | 384 | const struct fimc_variant *variant[FIMC_MAX_DEVS]; |
bb7c276e SN |
385 | int num_entities; |
386 | unsigned long lclk_frequency; | |
e80cb1fa SN |
387 | /* Fields common to all FIMC IP instances */ |
388 | u8 cistatus2; | |
389 | u8 dma_pix_hoff; | |
390 | u8 alpha_color; | |
391 | u8 out_buf_count; | |
5fd8f738 SN |
392 | }; |
393 | ||
bb7c276e SN |
394 | #define fimc_get_drvdata(_pdev) \ |
395 | ((struct fimc_drvdata *) platform_get_device_id(_pdev)->driver_data) | |
d3953223 | 396 | |
5fd8f738 SN |
397 | struct fimc_ctx; |
398 | ||
399 | /** | |
548aafcd | 400 | * struct fimc_dev - abstraction for FIMC entity |
5fd8f738 SN |
401 | * @slock: the spinlock protecting this data structure |
402 | * @lock: the mutex protecting this data structure | |
403 | * @pdev: pointer to the FIMC platform device | |
5f3cc447 | 404 | * @pdata: pointer to the device platform data |
88fa8311 | 405 | * @sysreg: pointer to the SYSREG regmap |
3495dcef | 406 | * @variant: the IP variant information |
a25be18d | 407 | * @id: FIMC device index (0..FIMC_MAX_DEVS) |
3495dcef | 408 | * @clock: clocks required for FIMC operation |
5fd8f738 | 409 | * @regs: the mapped hardware registers |
3495dcef | 410 | * @irq_queue: interrupt handler waitqueue |
30c9939d | 411 | * @v4l2_dev: root v4l2_device |
5fd8f738 | 412 | * @m2m: memory-to-memory V4L2 device information |
5f3cc447 SN |
413 | * @vid_cap: camera capture device information |
414 | * @state: flags used to synchronize m2m and capture mode operation | |
3495dcef | 415 | * @alloc_ctx: videobuf2 memory allocator context |
d3953223 | 416 | * @pipeline: fimc video capture pipeline data structure |
5fd8f738 SN |
417 | */ |
418 | struct fimc_dev { | |
419 | spinlock_t slock; | |
420 | struct mutex lock; | |
421 | struct platform_device *pdev; | |
df7e09a3 | 422 | struct s5p_platform_fimc *pdata; |
88fa8311 | 423 | struct regmap *sysreg; |
405f230c | 424 | const struct fimc_variant *variant; |
e80cb1fa | 425 | const struct fimc_drvdata *drv_data; |
a25be18d | 426 | u16 id; |
a25be18d | 427 | struct clk *clock[MAX_FIMC_CLOCKS]; |
5fd8f738 | 428 | void __iomem *regs; |
5f3cc447 | 429 | wait_queue_head_t irq_queue; |
30c9939d | 430 | struct v4l2_device *v4l2_dev; |
5fd8f738 | 431 | struct fimc_m2m_device m2m; |
5f3cc447 | 432 | struct fimc_vid_cap vid_cap; |
5fd8f738 | 433 | unsigned long state; |
2dab38e2 | 434 | struct vb2_alloc_ctx *alloc_ctx; |
d3953223 | 435 | struct fimc_pipeline pipeline; |
b9ee31e6 | 436 | const struct fimc_pipeline_ops *pipeline_ops; |
5fd8f738 SN |
437 | }; |
438 | ||
9448ab7d SN |
439 | /** |
440 | * struct fimc_ctrls - v4l2 controls structure | |
441 | * @handler: the control handler | |
442 | * @colorfx: image effect control | |
443 | * @colorfx_cbcr: Cb/Cr coefficients control | |
444 | * @rotate: image rotation control | |
445 | * @hflip: horizontal flip control | |
446 | * @vflip: vertical flip control | |
447 | * @alpha: RGB alpha control | |
448 | * @ready: true if @handler is initialized | |
449 | */ | |
450 | struct fimc_ctrls { | |
451 | struct v4l2_ctrl_handler handler; | |
452 | struct { | |
453 | struct v4l2_ctrl *colorfx; | |
454 | struct v4l2_ctrl *colorfx_cbcr; | |
455 | }; | |
456 | struct v4l2_ctrl *rotate; | |
457 | struct v4l2_ctrl *hflip; | |
458 | struct v4l2_ctrl *vflip; | |
459 | struct v4l2_ctrl *alpha; | |
460 | bool ready; | |
461 | }; | |
462 | ||
5fd8f738 SN |
463 | /** |
464 | * fimc_ctx - the device context data | |
5fd8f738 SN |
465 | * @s_frame: source frame properties |
466 | * @d_frame: destination frame properties | |
467 | * @out_order_1p: output 1-plane YCBCR order | |
468 | * @out_order_2p: output 2-plane YCBCR order | |
469 | * @in_order_1p input 1-plane YCBCR order | |
470 | * @in_order_2p: input 2-plane YCBCR order | |
471 | * @in_path: input mode (DMA or camera) | |
472 | * @out_path: output mode (DMA or FIFO) | |
473 | * @scaler: image scaler properties | |
474 | * @effect: image effect | |
475 | * @rotation: image clockwise rotation in degrees | |
131b6c61 SN |
476 | * @hflip: indicates image horizontal flip if set |
477 | * @vflip: indicates image vertical flip if set | |
548aafcd | 478 | * @flags: additional flags for image conversion |
5fd8f738 SN |
479 | * @state: flags to keep track of user configuration |
480 | * @fimc_dev: the FIMC device this context applies to | |
481 | * @m2m_ctx: memory-to-memory device context | |
e578588e | 482 | * @fh: v4l2 file handle |
9448ab7d | 483 | * @ctrls: v4l2 controls structure |
5fd8f738 SN |
484 | */ |
485 | struct fimc_ctx { | |
5fd8f738 SN |
486 | struct fimc_frame s_frame; |
487 | struct fimc_frame d_frame; | |
488 | u32 out_order_1p; | |
489 | u32 out_order_2p; | |
490 | u32 in_order_1p; | |
491 | u32 in_order_2p; | |
492 | enum fimc_datapath in_path; | |
493 | enum fimc_datapath out_path; | |
494 | struct fimc_scaler scaler; | |
495 | struct fimc_effect effect; | |
496 | int rotation; | |
131b6c61 SN |
497 | unsigned int hflip:1; |
498 | unsigned int vflip:1; | |
5fd8f738 SN |
499 | u32 flags; |
500 | u32 state; | |
501 | struct fimc_dev *fimc_dev; | |
502 | struct v4l2_m2m_ctx *m2m_ctx; | |
e578588e | 503 | struct v4l2_fh fh; |
9448ab7d | 504 | struct fimc_ctrls ctrls; |
5fd8f738 SN |
505 | }; |
506 | ||
e578588e SN |
507 | #define fh_to_ctx(__fh) container_of(__fh, struct fimc_ctx, fh) |
508 | ||
237e0265 SN |
509 | static inline void set_frame_bounds(struct fimc_frame *f, u32 width, u32 height) |
510 | { | |
511 | f->o_width = width; | |
512 | f->o_height = height; | |
513 | f->f_width = width; | |
514 | f->f_height = height; | |
515 | } | |
516 | ||
517 | static inline void set_frame_crop(struct fimc_frame *f, | |
518 | u32 left, u32 top, u32 width, u32 height) | |
519 | { | |
520 | f->offs_h = left; | |
521 | f->offs_v = top; | |
522 | f->width = width; | |
523 | f->height = height; | |
524 | } | |
525 | ||
526 | static inline u32 fimc_get_format_depth(struct fimc_fmt *ff) | |
527 | { | |
528 | u32 i, depth = 0; | |
529 | ||
530 | if (ff != NULL) | |
531 | for (i = 0; i < ff->colplanes; i++) | |
532 | depth += ff->depth[i]; | |
533 | return depth; | |
534 | } | |
535 | ||
4ecbf5d1 SN |
536 | static inline bool fimc_capture_active(struct fimc_dev *fimc) |
537 | { | |
538 | unsigned long flags; | |
539 | bool ret; | |
540 | ||
541 | spin_lock_irqsave(&fimc->slock, flags); | |
542 | ret = !!(fimc->state & (1 << ST_CAPT_RUN) || | |
543 | fimc->state & (1 << ST_CAPT_PEND)); | |
544 | spin_unlock_irqrestore(&fimc->slock, flags); | |
545 | return ret; | |
546 | } | |
547 | ||
efb13c3d | 548 | static inline void fimc_ctx_state_set(u32 state, struct fimc_ctx *ctx) |
4ecbf5d1 SN |
549 | { |
550 | unsigned long flags; | |
551 | ||
efb13c3d | 552 | spin_lock_irqsave(&ctx->fimc_dev->slock, flags); |
4ecbf5d1 | 553 | ctx->state |= state; |
efb13c3d | 554 | spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags); |
4ecbf5d1 SN |
555 | } |
556 | ||
557 | static inline bool fimc_ctx_state_is_set(u32 mask, struct fimc_ctx *ctx) | |
558 | { | |
559 | unsigned long flags; | |
560 | bool ret; | |
561 | ||
efb13c3d | 562 | spin_lock_irqsave(&ctx->fimc_dev->slock, flags); |
4ecbf5d1 | 563 | ret = (ctx->state & mask) == mask; |
efb13c3d | 564 | spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags); |
4ecbf5d1 SN |
565 | return ret; |
566 | } | |
567 | ||
5fd8f738 SN |
568 | static inline int tiled_fmt(struct fimc_fmt *fmt) |
569 | { | |
ef7af59b | 570 | return fmt->fourcc == V4L2_PIX_FMT_NV12MT; |
5fd8f738 SN |
571 | } |
572 | ||
14783d25 SN |
573 | static inline bool fimc_jpeg_fourcc(u32 pixelformat) |
574 | { | |
575 | return (pixelformat == V4L2_PIX_FMT_JPEG || | |
576 | pixelformat == V4L2_PIX_FMT_S5C_UYVY_JPG); | |
577 | } | |
578 | ||
579 | static inline bool fimc_user_defined_mbus_fmt(u32 code) | |
580 | { | |
581 | return (code == V4L2_MBUS_FMT_JPEG_1X8 || | |
582 | code == V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8); | |
583 | } | |
584 | ||
dafb9c70 SN |
585 | /* Return the alpha component bit mask */ |
586 | static inline int fimc_get_alpha_mask(struct fimc_fmt *fmt) | |
587 | { | |
588 | switch (fmt->color) { | |
3d112d9a SN |
589 | case FIMC_FMT_RGB444: return 0x0f; |
590 | case FIMC_FMT_RGB555: return 0x01; | |
591 | case FIMC_FMT_RGB888: return 0xff; | |
dafb9c70 SN |
592 | default: return 0; |
593 | }; | |
594 | } | |
595 | ||
548aafcd SN |
596 | static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx, |
597 | enum v4l2_buf_type type) | |
03e30ca5 PO |
598 | { |
599 | struct fimc_frame *frame; | |
600 | ||
ef7af59b | 601 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) { |
4ecbf5d1 | 602 | if (fimc_ctx_state_is_set(FIMC_CTX_M2M, ctx)) |
5f3cc447 SN |
603 | frame = &ctx->s_frame; |
604 | else | |
605 | return ERR_PTR(-EINVAL); | |
ef7af59b | 606 | } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) { |
03e30ca5 PO |
607 | frame = &ctx->d_frame; |
608 | } else { | |
30c9939d | 609 | v4l2_err(ctx->fimc_dev->v4l2_dev, |
03e30ca5 PO |
610 | "Wrong buffer/video queue type (%d)\n", type); |
611 | return ERR_PTR(-EINVAL); | |
612 | } | |
613 | ||
614 | return frame; | |
615 | } | |
616 | ||
5f3cc447 SN |
617 | /* -----------------------------------------------------*/ |
618 | /* fimc-core.c */ | |
ef7af59b SN |
619 | int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv, |
620 | struct v4l2_fmtdesc *f); | |
131b6c61 SN |
621 | int fimc_ctrls_create(struct fimc_ctx *ctx); |
622 | void fimc_ctrls_delete(struct fimc_ctx *ctx); | |
623 | void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active); | |
dafb9c70 | 624 | void fimc_alpha_ctrl_update(struct fimc_ctx *ctx); |
fa8880be | 625 | void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f); |
4db5e27e SN |
626 | void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, |
627 | struct v4l2_pix_format_mplane *pix); | |
63746be5 | 628 | struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code, |
cf52df8a | 629 | unsigned int mask, int index); |
97d97422 | 630 | struct fimc_fmt *fimc_get_format(unsigned int index); |
5f3cc447 | 631 | |
ee7160e5 SN |
632 | int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh, |
633 | int dw, int dh, int rotation); | |
5f3cc447 SN |
634 | int fimc_set_scaler_info(struct fimc_ctx *ctx); |
635 | int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags); | |
2dab38e2 | 636 | int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb, |
5f3cc447 | 637 | struct fimc_frame *frame, struct fimc_addr *paddr); |
9e803a04 SN |
638 | void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f); |
639 | void fimc_set_yuv_order(struct fimc_ctx *ctx); | |
97d97422 | 640 | void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf); |
9e803a04 | 641 | |
30c9939d SN |
642 | int fimc_register_m2m_device(struct fimc_dev *fimc, |
643 | struct v4l2_device *v4l2_dev); | |
644 | void fimc_unregister_m2m_device(struct fimc_dev *fimc); | |
d3953223 SN |
645 | int fimc_register_driver(void); |
646 | void fimc_unregister_driver(void); | |
5f3cc447 | 647 | |
97d97422 SN |
648 | /* -----------------------------------------------------*/ |
649 | /* fimc-m2m.c */ | |
650 | void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state); | |
651 | ||
5f3cc447 SN |
652 | /* -----------------------------------------------------*/ |
653 | /* fimc-capture.c */ | |
693f5c40 SN |
654 | int fimc_initialize_capture_subdev(struct fimc_dev *fimc); |
655 | void fimc_unregister_capture_subdev(struct fimc_dev *fimc); | |
131b6c61 | 656 | int fimc_capture_ctrls_create(struct fimc_dev *fimc); |
e1d72f4d SN |
657 | void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification, |
658 | void *arg); | |
e9e21083 SN |
659 | int fimc_capture_suspend(struct fimc_dev *fimc); |
660 | int fimc_capture_resume(struct fimc_dev *fimc); | |
548aafcd | 661 | |
5f3cc447 | 662 | /* |
0295202c | 663 | * Buffer list manipulation functions. Must be called with fimc.slock held. |
5f3cc447 | 664 | */ |
0295202c SN |
665 | |
666 | /** | |
667 | * fimc_active_queue_add - add buffer to the capture active buffers queue | |
668 | * @buf: buffer to add to the active buffers list | |
669 | */ | |
670 | static inline void fimc_active_queue_add(struct fimc_vid_cap *vid_cap, | |
671 | struct fimc_vid_buffer *buf) | |
5f3cc447 | 672 | { |
2dab38e2 | 673 | list_add_tail(&buf->list, &vid_cap->active_buf_q); |
5f3cc447 SN |
674 | vid_cap->active_buf_cnt++; |
675 | } | |
676 | ||
0295202c SN |
677 | /** |
678 | * fimc_active_queue_pop - pop buffer from the capture active buffers queue | |
679 | * | |
680 | * The caller must assure the active_buf_q list is not empty. | |
5f3cc447 | 681 | */ |
0295202c SN |
682 | static inline struct fimc_vid_buffer *fimc_active_queue_pop( |
683 | struct fimc_vid_cap *vid_cap) | |
5f3cc447 SN |
684 | { |
685 | struct fimc_vid_buffer *buf; | |
686 | buf = list_entry(vid_cap->active_buf_q.next, | |
2dab38e2 SN |
687 | struct fimc_vid_buffer, list); |
688 | list_del(&buf->list); | |
5f3cc447 SN |
689 | vid_cap->active_buf_cnt--; |
690 | return buf; | |
691 | } | |
692 | ||
0295202c SN |
693 | /** |
694 | * fimc_pending_queue_add - add buffer to the capture pending buffers queue | |
695 | * @buf: buffer to add to the pending buffers list | |
696 | */ | |
5f3cc447 SN |
697 | static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap, |
698 | struct fimc_vid_buffer *buf) | |
699 | { | |
2dab38e2 | 700 | list_add_tail(&buf->list, &vid_cap->pending_buf_q); |
5f3cc447 SN |
701 | } |
702 | ||
0295202c SN |
703 | /** |
704 | * fimc_pending_queue_pop - pop buffer from the capture pending buffers queue | |
705 | * | |
706 | * The caller must assure the pending_buf_q list is not empty. | |
707 | */ | |
708 | static inline struct fimc_vid_buffer *fimc_pending_queue_pop( | |
709 | struct fimc_vid_cap *vid_cap) | |
5f3cc447 SN |
710 | { |
711 | struct fimc_vid_buffer *buf; | |
712 | buf = list_entry(vid_cap->pending_buf_q.next, | |
2dab38e2 SN |
713 | struct fimc_vid_buffer, list); |
714 | list_del(&buf->list); | |
5f3cc447 SN |
715 | return buf; |
716 | } | |
717 | ||
5fd8f738 | 718 | #endif /* FIMC_CORE_H_ */ |