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