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