[media] s5p-fimc: Convert to use media pipeline operations
[deliverable/linux.git] / drivers / media / video / s5p-fimc / fimc-core.h
CommitLineData
5fd8f738 1/*
3a3f9449 2 * Copyright (C) 2010 - 2011 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>
aee7126c 15#include <linux/sched.h>
4ecbf5d1 16#include <linux/spinlock.h>
5fd8f738 17#include <linux/types.h>
aee7126c 18#include <linux/videodev2.h>
2dab38e2 19#include <linux/io.h>
574e1717
SN
20
21#include <media/media-entity.h>
2dab38e2 22#include <media/videobuf2-core.h>
131b6c61 23#include <media/v4l2-ctrls.h>
5fd8f738
SN
24#include <media/v4l2-device.h>
25#include <media/v4l2-mem2mem.h>
5f3cc447 26#include <media/v4l2-mediabus.h>
df7e09a3 27#include <media/s5p_fimc.h>
aee7126c 28
5fd8f738
SN
29#include "regs-fimc.h"
30
31#define err(fmt, args...) \
32 printk(KERN_ERR "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
33
5fd8f738 34#define dbg(fmt, args...) \
1e004695 35 pr_debug("%s:%d: " fmt "\n", __func__, __LINE__, ##args)
5fd8f738 36
5f3cc447
SN
37/* Time to wait for next frame VSYNC interrupt while stopping operation. */
38#define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000)
ebdfea81 39#define MAX_FIMC_CLOCKS 2
d3953223 40#define FIMC_MODULE_NAME "s5p-fimc"
a7d5bbcf 41#define FIMC_MAX_DEVS 4
5fd8f738
SN
42#define FIMC_MAX_OUT_BUFS 4
43#define SCALER_MAX_HRATIO 64
44#define SCALER_MAX_VRATIO 64
548aafcd 45#define DMA_MIN_SIZE 8
5fd8f738 46
a25be18d
SN
47/* indices to the clocks array */
48enum {
49 CLK_BUS,
50 CLK_GATE,
a25be18d
SN
51};
52
5f3cc447 53enum fimc_dev_flags {
e9e21083
SN
54 ST_LPM,
55 /* m2m node */
56 ST_M2M_RUN,
5fd8f738 57 ST_M2M_PEND,
e9e21083
SN
58 ST_M2M_SUSPENDING,
59 ST_M2M_SUSPENDED,
60 /* capture node */
5f3cc447
SN
61 ST_CAPT_PEND,
62 ST_CAPT_RUN,
63 ST_CAPT_STREAM,
4db5e27e 64 ST_CAPT_ISP_STREAM,
5f3cc447 65 ST_CAPT_SHUT,
e9e21083 66 ST_CAPT_BUSY,
131b6c61 67 ST_CAPT_APPLY_CFG,
5fd8f738
SN
68};
69
e9e21083 70#define fimc_m2m_active(dev) test_bit(ST_M2M_RUN, &(dev)->state)
5fd8f738
SN
71#define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
72
5f3cc447
SN
73#define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state)
74#define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state)
e9e21083 75#define fimc_capture_busy(dev) test_bit(ST_CAPT_BUSY, &(dev)->state)
5f3cc447 76
5fd8f738 77enum fimc_datapath {
5f3cc447 78 FIMC_CAMERA,
5fd8f738
SN
79 FIMC_DMA,
80 FIMC_LCDFIFO,
81 FIMC_WRITEBACK
82};
83
84enum fimc_color_fmt {
548aafcd 85 S5P_FIMC_RGB565 = 0x10,
5fd8f738
SN
86 S5P_FIMC_RGB666,
87 S5P_FIMC_RGB888,
548aafcd
SN
88 S5P_FIMC_RGB30_LOCAL,
89 S5P_FIMC_YCBCR420 = 0x20,
5fd8f738
SN
90 S5P_FIMC_YCBYCR422,
91 S5P_FIMC_YCRYCB422,
92 S5P_FIMC_CBYCRY422,
93 S5P_FIMC_CRYCBY422,
5fd8f738 94 S5P_FIMC_YCBCR444_LOCAL,
5fd8f738
SN
95};
96
548aafcd
SN
97#define fimc_fmt_is_rgb(x) ((x) & 0x10)
98
4db5e27e
SN
99#define IS_M2M(__strt) ((__strt) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || \
100 __strt == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
101
5fd8f738
SN
102/* Cb/Cr chrominance components order for 2 plane Y/CbCr 4:2:2 formats. */
103#define S5P_FIMC_LSB_CRCB S5P_CIOCTRL_ORDER422_2P_LSB_CRCB
104
105/* The embedded image effect selection */
106#define S5P_FIMC_EFFECT_ORIGINAL S5P_CIIMGEFF_FIN_BYPASS
107#define S5P_FIMC_EFFECT_ARBITRARY S5P_CIIMGEFF_FIN_ARBITRARY
108#define S5P_FIMC_EFFECT_NEGATIVE S5P_CIIMGEFF_FIN_NEGATIVE
109#define S5P_FIMC_EFFECT_ARTFREEZE S5P_CIIMGEFF_FIN_ARTFREEZE
110#define S5P_FIMC_EFFECT_EMBOSSING S5P_CIIMGEFF_FIN_EMBOSSING
111#define S5P_FIMC_EFFECT_SIKHOUETTE S5P_CIIMGEFF_FIN_SILHOUETTE
112
113/* The hardware context state. */
548aafcd
SN
114#define FIMC_PARAMS (1 << 0)
115#define FIMC_SRC_ADDR (1 << 1)
116#define FIMC_DST_ADDR (1 << 2)
117#define FIMC_SRC_FMT (1 << 3)
118#define FIMC_DST_FMT (1 << 4)
119#define FIMC_CTX_M2M (1 << 5)
120#define FIMC_CTX_CAP (1 << 6)
4ecbf5d1 121#define FIMC_CTX_SHUT (1 << 7)
5fd8f738
SN
122
123/* Image conversion flags */
124#define FIMC_IN_DMA_ACCESS_TILED (1 << 0)
125#define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0)
126#define FIMC_OUT_DMA_ACCESS_TILED (1 << 1)
127#define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1)
128#define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2)
129#define FIMC_SCAN_MODE_INTERLACED (1 << 2)
548aafcd
SN
130/*
131 * YCbCr data dynamic range for RGB-YUV color conversion.
132 * Y/Cb/Cr: (0 ~ 255) */
5fd8f738
SN
133#define FIMC_COLOR_RANGE_WIDE (0 << 3)
134/* Y (16 ~ 235), Cb/Cr (16 ~ 240) */
135#define FIMC_COLOR_RANGE_NARROW (1 << 3)
136
5fd8f738
SN
137/**
138 * struct fimc_fmt - the driver's internal color format data
5f3cc447 139 * @mbus_code: Media Bus pixel code, -1 if not applicable
5fd8f738 140 * @name: format description
5f3cc447 141 * @fourcc: the fourcc code for this format, 0 if not applicable
5fd8f738 142 * @color: the corresponding fimc_color_fmt
ef7af59b
SN
143 * @memplanes: number of physically non-contiguous data planes
144 * @colplanes: number of physically contiguous data planes
3495dcef
SN
145 * @depth: per plane driver's private 'number of bits per pixel'
146 * @flags: flags indicating which operation mode format applies to
5fd8f738
SN
147 */
148struct fimc_fmt {
5f3cc447 149 enum v4l2_mbus_pixelcode mbus_code;
5fd8f738
SN
150 char *name;
151 u32 fourcc;
152 u32 color;
ef7af59b
SN
153 u16 memplanes;
154 u16 colplanes;
155 u8 depth[VIDEO_MAX_PLANES];
5f3cc447
SN
156 u16 flags;
157#define FMT_FLAGS_CAM (1 << 0)
158#define FMT_FLAGS_M2M (1 << 1)
5fd8f738
SN
159};
160
161/**
162 * struct fimc_dma_offset - pixel offset information for DMA
163 * @y_h: y value horizontal offset
164 * @y_v: y value vertical offset
165 * @cb_h: cb value horizontal offset
166 * @cb_v: cb value vertical offset
167 * @cr_h: cr value horizontal offset
168 * @cr_v: cr value vertical offset
169 */
170struct fimc_dma_offset {
171 int y_h;
172 int y_v;
173 int cb_h;
174 int cb_v;
175 int cr_h;
176 int cr_v;
177};
178
179/**
3495dcef 180 * struct fimc_effect - color effect information
5fd8f738
SN
181 * @type: effect type
182 * @pat_cb: cr value when type is "arbitrary"
183 * @pat_cr: cr value when type is "arbitrary"
184 */
185struct fimc_effect {
186 u32 type;
187 u8 pat_cb;
188 u8 pat_cr;
189};
190
191/**
192 * struct fimc_scaler - the configuration data for FIMC inetrnal scaler
548aafcd
SN
193 * @scaleup_h: flag indicating scaling up horizontally
194 * @scaleup_v: flag indicating scaling up vertically
195 * @copy_mode: flag indicating transparent DMA transfer (no scaling
196 * and color format conversion)
197 * @enabled: flag indicating if the scaler is used
5fd8f738
SN
198 * @hfactor: horizontal shift factor
199 * @vfactor: vertical shift factor
200 * @pre_hratio: horizontal ratio of the prescaler
201 * @pre_vratio: vertical ratio of the prescaler
202 * @pre_dst_width: the prescaler's destination width
203 * @pre_dst_height: the prescaler's destination height
5fd8f738
SN
204 * @main_hratio: the main scaler's horizontal ratio
205 * @main_vratio: the main scaler's vertical ratio
548aafcd
SN
206 * @real_width: source pixel (width - offset)
207 * @real_height: source pixel (height - offset)
5fd8f738
SN
208 */
209struct fimc_scaler {
dda7ae78
SN
210 unsigned int scaleup_h:1;
211 unsigned int scaleup_v:1;
212 unsigned int copy_mode:1;
213 unsigned int enabled:1;
5fd8f738
SN
214 u32 hfactor;
215 u32 vfactor;
216 u32 pre_hratio;
217 u32 pre_vratio;
218 u32 pre_dst_width;
219 u32 pre_dst_height;
5fd8f738
SN
220 u32 main_hratio;
221 u32 main_vratio;
222 u32 real_width;
223 u32 real_height;
5fd8f738
SN
224};
225
226/**
227 * struct fimc_addr - the FIMC physical address set for DMA
5fd8f738
SN
228 * @y: luminance plane physical address
229 * @cb: Cb plane physical address
230 * @cr: Cr plane physical address
231 */
232struct fimc_addr {
233 u32 y;
234 u32 cb;
235 u32 cr;
236};
237
238/**
239 * struct fimc_vid_buffer - the driver's video buffer
5f3cc447 240 * @vb: v4l videobuf buffer
3495dcef 241 * @list: linked list structure for buffer queue
5f3cc447
SN
242 * @paddr: precalculated physical address set
243 * @index: buffer index for the output DMA engine
5fd8f738
SN
244 */
245struct fimc_vid_buffer {
2dab38e2
SN
246 struct vb2_buffer vb;
247 struct list_head list;
5f3cc447
SN
248 struct fimc_addr paddr;
249 int index;
5fd8f738
SN
250};
251
252/**
548aafcd 253 * struct fimc_frame - source/target frame properties
5fd8f738
SN
254 * @f_width: image full width (virtual screen size)
255 * @f_height: image full height (virtual screen size)
256 * @o_width: original image width as set by S_FMT
257 * @o_height: original image height as set by S_FMT
258 * @offs_h: image horizontal pixel offset
259 * @offs_v: image vertical pixel offset
260 * @width: image pixel width
261 * @height: image pixel weight
ef7af59b 262 * @payload: image size in bytes (w x h x bpp)
3495dcef 263 * @paddr: image frame buffer physical addresses
5fd8f738 264 * @dma_offset: DMA offset in bytes
3495dcef 265 * @fmt: fimc color format pointer
5fd8f738
SN
266 */
267struct fimc_frame {
268 u32 f_width;
269 u32 f_height;
270 u32 o_width;
271 u32 o_height;
272 u32 offs_h;
273 u32 offs_v;
274 u32 width;
275 u32 height;
ef7af59b 276 unsigned long payload[VIDEO_MAX_PLANES];
5fd8f738
SN
277 struct fimc_addr paddr;
278 struct fimc_dma_offset dma_offset;
279 struct fimc_fmt *fmt;
280};
281
282/**
283 * struct fimc_m2m_device - v4l2 memory-to-memory device data
284 * @vfd: the video device node for v4l2 m2m mode
5fd8f738
SN
285 * @m2m_dev: v4l2 memory-to-memory device data
286 * @ctx: hardware context data
287 * @refcnt: the reference counter
288 */
289struct fimc_m2m_device {
290 struct video_device *vfd;
5fd8f738
SN
291 struct v4l2_m2m_dev *m2m_dev;
292 struct fimc_ctx *ctx;
293 int refcnt;
294};
295
5f3cc447
SN
296/**
297 * struct fimc_vid_cap - camera capture device information
298 * @ctx: hardware context data
299 * @vfd: video device node for camera capture mode
574e1717 300 * @vd_pad: fimc video capture node pad
5f3cc447
SN
301 * @fmt: Media Bus format configured at selected image sensor
302 * @pending_buf_q: the pending buffer queue head
303 * @active_buf_q: the queue head of buffers scheduled in hardware
304 * @vbq: the capture am video buffer queue
305 * @active_buf_cnt: number of video buffers scheduled in hardware
306 * @buf_index: index for managing the output DMA buffers
307 * @frame_count: the frame counter for statistics
308 * @reqbufs_count: the number of buffers requested in REQBUFS ioctl
309 * @input_index: input (camera sensor) index
310 * @refcnt: driver's private reference counter
d09a7dc8 311 * @input: capture input type, grp_id of the attached subdev
d3953223 312 * @user_subdev_api: true if subdevs are not configured by the host driver
5f3cc447
SN
313 */
314struct fimc_vid_cap {
315 struct fimc_ctx *ctx;
2dab38e2 316 struct vb2_alloc_ctx *alloc_ctx;
5f3cc447 317 struct video_device *vfd;
574e1717 318 struct media_pad vd_pad;
5f3cc447
SN
319 struct v4l2_mbus_framefmt fmt;
320 struct list_head pending_buf_q;
321 struct list_head active_buf_q;
2dab38e2 322 struct vb2_queue vbq;
5f3cc447
SN
323 int active_buf_cnt;
324 int buf_index;
325 unsigned int frame_count;
326 unsigned int reqbufs_count;
327 int input_index;
328 int refcnt;
d09a7dc8 329 u32 input;
d3953223 330 bool user_subdev_api;
5f3cc447
SN
331};
332
a7d5bbcf
SN
333/**
334 * struct fimc_pix_limit - image pixel size limits in various IP configurations
335 *
336 * @scaler_en_w: max input pixel width when the scaler is enabled
337 * @scaler_dis_w: max input pixel width when the scaler is disabled
338 * @in_rot_en_h: max input width with the input rotator is on
339 * @in_rot_dis_w: max input width with the input rotator is off
340 * @out_rot_en_w: max output width with the output rotator on
341 * @out_rot_dis_w: max output width with the output rotator off
342 */
343struct fimc_pix_limit {
344 u16 scaler_en_w;
345 u16 scaler_dis_w;
346 u16 in_rot_en_h;
347 u16 in_rot_dis_w;
348 u16 out_rot_en_w;
349 u16 out_rot_dis_w;
350};
351
5fd8f738
SN
352/**
353 * struct samsung_fimc_variant - camera interface variant information
354 *
355 * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
356 * @has_inp_rot: set if has input rotator
357 * @has_out_rot: set if has output rotator
798174ab 358 * @has_cistatus2: 1 if CISTATUS2 register is present in this IP revision
b241c6d6
HK
359 * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register
360 * are present in this IP revision
d3953223 361 * @has_cam_if: set if this instance has a camera input interface
a7d5bbcf 362 * @pix_limit: pixel size constraints for the scaler
5fd8f738
SN
363 * @min_inp_pixsize: minimum input pixel size
364 * @min_out_pixsize: minimum output pixel size
a7d5bbcf
SN
365 * @hor_offs_align: horizontal pixel offset aligment
366 * @out_buf_count: the number of buffers in output DMA sequence
5fd8f738
SN
367 */
368struct samsung_fimc_variant {
369 unsigned int pix_hoff:1;
370 unsigned int has_inp_rot:1;
371 unsigned int has_out_rot:1;
798174ab 372 unsigned int has_cistatus2:1;
b241c6d6 373 unsigned int has_mainscaler_ext:1;
d3953223 374 unsigned int has_cam_if:1;
a7d5bbcf 375 struct fimc_pix_limit *pix_limit;
5fd8f738
SN
376 u16 min_inp_pixsize;
377 u16 min_out_pixsize;
a7d5bbcf
SN
378 u16 hor_offs_align;
379 u16 out_buf_count;
5fd8f738
SN
380};
381
382/**
548aafcd 383 * struct samsung_fimc_driverdata - per device type driver data for init time.
5fd8f738
SN
384 *
385 * @variant: the variant information for this driver.
386 * @dev_cnt: number of fimc sub-devices available in SoC
5f3cc447 387 * @lclk_frequency: fimc bus clock frequency
5fd8f738
SN
388 */
389struct samsung_fimc_driverdata {
390 struct samsung_fimc_variant *variant[FIMC_MAX_DEVS];
5f3cc447 391 unsigned long lclk_frequency;
a7d5bbcf 392 int num_entities;
5fd8f738
SN
393};
394
d3953223
SN
395struct fimc_pipeline {
396 struct media_pipeline *pipe;
397 struct v4l2_subdev *sensor;
398 struct v4l2_subdev *csis;
399};
400
5fd8f738
SN
401struct fimc_ctx;
402
403/**
548aafcd 404 * struct fimc_dev - abstraction for FIMC entity
5fd8f738
SN
405 * @slock: the spinlock protecting this data structure
406 * @lock: the mutex protecting this data structure
407 * @pdev: pointer to the FIMC platform device
5f3cc447 408 * @pdata: pointer to the device platform data
3495dcef 409 * @variant: the IP variant information
a25be18d
SN
410 * @id: FIMC device index (0..FIMC_MAX_DEVS)
411 * @num_clocks: the number of clocks managed by this device instance
3495dcef 412 * @clock: clocks required for FIMC operation
5fd8f738
SN
413 * @regs: the mapped hardware registers
414 * @regs_res: the resource claimed for IO registers
3495dcef
SN
415 * @irq: FIMC interrupt number
416 * @irq_queue: interrupt handler waitqueue
30c9939d 417 * @v4l2_dev: root v4l2_device
5fd8f738 418 * @m2m: memory-to-memory V4L2 device information
5f3cc447
SN
419 * @vid_cap: camera capture device information
420 * @state: flags used to synchronize m2m and capture mode operation
3495dcef 421 * @alloc_ctx: videobuf2 memory allocator context
d3953223 422 * @pipeline: fimc video capture pipeline data structure
5fd8f738
SN
423 */
424struct fimc_dev {
425 spinlock_t slock;
426 struct mutex lock;
427 struct platform_device *pdev;
df7e09a3 428 struct s5p_platform_fimc *pdata;
5fd8f738 429 struct samsung_fimc_variant *variant;
a25be18d
SN
430 u16 id;
431 u16 num_clocks;
432 struct clk *clock[MAX_FIMC_CLOCKS];
5fd8f738
SN
433 void __iomem *regs;
434 struct resource *regs_res;
435 int irq;
5f3cc447 436 wait_queue_head_t irq_queue;
30c9939d 437 struct v4l2_device *v4l2_dev;
5fd8f738 438 struct fimc_m2m_device m2m;
5f3cc447 439 struct fimc_vid_cap vid_cap;
5fd8f738 440 unsigned long state;
2dab38e2 441 struct vb2_alloc_ctx *alloc_ctx;
d3953223 442 struct fimc_pipeline pipeline;
5fd8f738
SN
443};
444
445/**
446 * fimc_ctx - the device context data
3495dcef 447 * @slock: spinlock protecting this data structure
5fd8f738
SN
448 * @s_frame: source frame properties
449 * @d_frame: destination frame properties
450 * @out_order_1p: output 1-plane YCBCR order
451 * @out_order_2p: output 2-plane YCBCR order
452 * @in_order_1p input 1-plane YCBCR order
453 * @in_order_2p: input 2-plane YCBCR order
454 * @in_path: input mode (DMA or camera)
455 * @out_path: output mode (DMA or FIFO)
456 * @scaler: image scaler properties
457 * @effect: image effect
458 * @rotation: image clockwise rotation in degrees
131b6c61
SN
459 * @hflip: indicates image horizontal flip if set
460 * @vflip: indicates image vertical flip if set
548aafcd 461 * @flags: additional flags for image conversion
5fd8f738
SN
462 * @state: flags to keep track of user configuration
463 * @fimc_dev: the FIMC device this context applies to
464 * @m2m_ctx: memory-to-memory device context
e578588e 465 * @fh: v4l2 file handle
131b6c61
SN
466 * @ctrl_handler: v4l2 controls handler
467 * @ctrl_rotate image rotation control
468 * @ctrl_hflip horizontal flip control
469 * @ctrl_vflip vartical flip control
470 * @ctrls_rdy: true if the control handler is initialized
5fd8f738
SN
471 */
472struct fimc_ctx {
473 spinlock_t slock;
474 struct fimc_frame s_frame;
475 struct fimc_frame d_frame;
476 u32 out_order_1p;
477 u32 out_order_2p;
478 u32 in_order_1p;
479 u32 in_order_2p;
480 enum fimc_datapath in_path;
481 enum fimc_datapath out_path;
482 struct fimc_scaler scaler;
483 struct fimc_effect effect;
484 int rotation;
131b6c61
SN
485 unsigned int hflip:1;
486 unsigned int vflip:1;
5fd8f738
SN
487 u32 flags;
488 u32 state;
489 struct fimc_dev *fimc_dev;
490 struct v4l2_m2m_ctx *m2m_ctx;
e578588e 491 struct v4l2_fh fh;
131b6c61
SN
492 struct v4l2_ctrl_handler ctrl_handler;
493 struct v4l2_ctrl *ctrl_rotate;
494 struct v4l2_ctrl *ctrl_hflip;
495 struct v4l2_ctrl *ctrl_vflip;
496 bool ctrls_rdy;
5fd8f738
SN
497};
498
e578588e
SN
499#define fh_to_ctx(__fh) container_of(__fh, struct fimc_ctx, fh)
500
4ecbf5d1
SN
501static inline bool fimc_capture_active(struct fimc_dev *fimc)
502{
503 unsigned long flags;
504 bool ret;
505
506 spin_lock_irqsave(&fimc->slock, flags);
507 ret = !!(fimc->state & (1 << ST_CAPT_RUN) ||
508 fimc->state & (1 << ST_CAPT_PEND));
509 spin_unlock_irqrestore(&fimc->slock, flags);
510 return ret;
511}
512
513static inline void fimc_ctx_state_lock_set(u32 state, struct fimc_ctx *ctx)
514{
515 unsigned long flags;
516
517 spin_lock_irqsave(&ctx->slock, flags);
518 ctx->state |= state;
519 spin_unlock_irqrestore(&ctx->slock, flags);
520}
521
522static inline bool fimc_ctx_state_is_set(u32 mask, struct fimc_ctx *ctx)
523{
524 unsigned long flags;
525 bool ret;
526
527 spin_lock_irqsave(&ctx->slock, flags);
528 ret = (ctx->state & mask) == mask;
529 spin_unlock_irqrestore(&ctx->slock, flags);
530 return ret;
531}
532
5fd8f738
SN
533static inline int tiled_fmt(struct fimc_fmt *fmt)
534{
ef7af59b 535 return fmt->fourcc == V4L2_PIX_FMT_NV12MT;
5fd8f738
SN
536}
537
538static inline void fimc_hw_clear_irq(struct fimc_dev *dev)
539{
540 u32 cfg = readl(dev->regs + S5P_CIGCTRL);
541 cfg |= S5P_CIGCTRL_IRQ_CLR;
542 writel(cfg, dev->regs + S5P_CIGCTRL);
543}
544
548aafcd 545static inline void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on)
5fd8f738
SN
546{
547 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
548aafcd
SN
548 if (on)
549 cfg |= S5P_CISCCTRL_SCALERSTART;
550 else
551 cfg &= ~S5P_CISCCTRL_SCALERSTART;
5fd8f738
SN
552 writel(cfg, dev->regs + S5P_CISCCTRL);
553}
554
548aafcd 555static inline void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on)
5fd8f738 556{
548aafcd
SN
557 u32 cfg = readl(dev->regs + S5P_MSCTRL);
558 if (on)
559 cfg |= S5P_MSCTRL_ENVID;
560 else
561 cfg &= ~S5P_MSCTRL_ENVID;
562 writel(cfg, dev->regs + S5P_MSCTRL);
5fd8f738
SN
563}
564
565static inline void fimc_hw_dis_capture(struct fimc_dev *dev)
566{
567 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
568 cfg &= ~(S5P_CIIMGCPT_IMGCPTEN | S5P_CIIMGCPT_IMGCPTEN_SC);
569 writel(cfg, dev->regs + S5P_CIIMGCPT);
570}
571
a7d5bbcf
SN
572/**
573 * fimc_hw_set_dma_seq - configure output DMA buffer sequence
574 * @mask: each bit corresponds to one of 32 output buffer registers set
575 * 1 to include buffer in the sequence, 0 to disable
576 *
577 * This function mask output DMA ring buffers, i.e. it allows to configure
578 * which of the output buffer address registers will be used by the DMA
579 * engine.
580 */
581static inline void fimc_hw_set_dma_seq(struct fimc_dev *dev, u32 mask)
582{
583 writel(mask, dev->regs + S5P_CIFCNTSEQ);
584}
585
548aafcd
SN
586static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
587 enum v4l2_buf_type type)
03e30ca5
PO
588{
589 struct fimc_frame *frame;
590
ef7af59b 591 if (V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE == type) {
4ecbf5d1 592 if (fimc_ctx_state_is_set(FIMC_CTX_M2M, ctx))
5f3cc447
SN
593 frame = &ctx->s_frame;
594 else
595 return ERR_PTR(-EINVAL);
ef7af59b 596 } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE == type) {
03e30ca5
PO
597 frame = &ctx->d_frame;
598 } else {
30c9939d 599 v4l2_err(ctx->fimc_dev->v4l2_dev,
03e30ca5
PO
600 "Wrong buffer/video queue type (%d)\n", type);
601 return ERR_PTR(-EINVAL);
602 }
603
604 return frame;
605}
606
798174ab 607/* Return an index to the buffer actually being written. */
5f3cc447
SN
608static inline u32 fimc_hw_get_frame_index(struct fimc_dev *dev)
609{
798174ab
SN
610 u32 reg;
611
612 if (dev->variant->has_cistatus2) {
613 reg = readl(dev->regs + S5P_CISTATUS2) & 0x3F;
614 return reg > 0 ? --reg : reg;
615 } else {
616 reg = readl(dev->regs + S5P_CISTATUS);
617 return (reg & S5P_CISTATUS_FRAMECNT_MASK) >>
618 S5P_CISTATUS_FRAMECNT_SHIFT;
619 }
5f3cc447
SN
620}
621
5fd8f738
SN
622/* -----------------------------------------------------*/
623/* fimc-reg.c */
548aafcd 624void fimc_hw_reset(struct fimc_dev *fimc);
5fd8f738
SN
625void fimc_hw_set_rotation(struct fimc_ctx *ctx);
626void fimc_hw_set_target_format(struct fimc_ctx *ctx);
627void fimc_hw_set_out_dma(struct fimc_ctx *ctx);
548aafcd
SN
628void fimc_hw_en_lastirq(struct fimc_dev *fimc, int enable);
629void fimc_hw_en_irq(struct fimc_dev *fimc, int enable);
b241c6d6
HK
630void fimc_hw_set_prescaler(struct fimc_ctx *ctx);
631void fimc_hw_set_mainscaler(struct fimc_ctx *ctx);
5fd8f738
SN
632void fimc_hw_en_capture(struct fimc_ctx *ctx);
633void fimc_hw_set_effect(struct fimc_ctx *ctx);
634void fimc_hw_set_in_dma(struct fimc_ctx *ctx);
635void fimc_hw_set_input_path(struct fimc_ctx *ctx);
636void fimc_hw_set_output_path(struct fimc_ctx *ctx);
548aafcd
SN
637void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *paddr);
638void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr,
ef7af59b 639 int index);
5f3cc447 640int fimc_hw_set_camera_source(struct fimc_dev *fimc,
df7e09a3 641 struct s5p_fimc_isp_info *cam);
5f3cc447
SN
642int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f);
643int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
df7e09a3 644 struct s5p_fimc_isp_info *cam);
5f3cc447 645int fimc_hw_set_camera_type(struct fimc_dev *fimc,
df7e09a3 646 struct s5p_fimc_isp_info *cam);
5f3cc447
SN
647
648/* -----------------------------------------------------*/
649/* fimc-core.c */
ef7af59b
SN
650int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
651 struct v4l2_fmtdesc *f);
5f3cc447 652int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr);
131b6c61
SN
653int fimc_ctrls_create(struct fimc_ctx *ctx);
654void fimc_ctrls_delete(struct fimc_ctx *ctx);
655void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
e578588e 656int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f);
4db5e27e
SN
657void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
658 struct v4l2_pix_format_mplane *pix);
cf52df8a
SN
659struct fimc_fmt *fimc_find_format(u32 *pixelformat, u32 *mbus_code,
660 unsigned int mask, int index);
5f3cc447 661
1b09f292 662int fimc_check_scaler_ratio(int sw, int sh, int dw, int dh, int rot);
5f3cc447
SN
663int fimc_set_scaler_info(struct fimc_ctx *ctx);
664int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags);
2dab38e2 665int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
5f3cc447 666 struct fimc_frame *frame, struct fimc_addr *paddr);
9e803a04
SN
667void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f);
668void fimc_set_yuv_order(struct fimc_ctx *ctx);
4db5e27e 669void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f);
9e803a04 670
30c9939d
SN
671int fimc_register_m2m_device(struct fimc_dev *fimc,
672 struct v4l2_device *v4l2_dev);
673void fimc_unregister_m2m_device(struct fimc_dev *fimc);
d3953223
SN
674int fimc_register_driver(void);
675void fimc_unregister_driver(void);
5f3cc447
SN
676
677/* -----------------------------------------------------*/
678/* fimc-capture.c */
30c9939d
SN
679int fimc_register_capture_device(struct fimc_dev *fimc,
680 struct v4l2_device *v4l2_dev);
5f3cc447 681void fimc_unregister_capture_device(struct fimc_dev *fimc);
131b6c61 682int fimc_capture_ctrls_create(struct fimc_dev *fimc);
5f3cc447
SN
683int fimc_vid_cap_buf_queue(struct fimc_dev *fimc,
684 struct fimc_vid_buffer *fimc_vb);
e9e21083
SN
685int fimc_capture_suspend(struct fimc_dev *fimc);
686int fimc_capture_resume(struct fimc_dev *fimc);
548aafcd
SN
687
688/* Locking: the caller holds fimc->slock */
689static inline void fimc_activate_capture(struct fimc_ctx *ctx)
690{
691 fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled);
692 fimc_hw_en_capture(ctx);
693}
694
695static inline void fimc_deactivate_capture(struct fimc_dev *fimc)
696{
697 fimc_hw_en_lastirq(fimc, true);
698 fimc_hw_dis_capture(fimc);
699 fimc_hw_enable_scaler(fimc, false);
700 fimc_hw_en_lastirq(fimc, false);
701}
5fd8f738 702
5f3cc447 703/*
2dab38e2
SN
704 * Add buf to the capture active buffers queue.
705 * Locking: Need to be called with fimc_dev::slock held.
5f3cc447
SN
706 */
707static inline void active_queue_add(struct fimc_vid_cap *vid_cap,
2dab38e2 708 struct fimc_vid_buffer *buf)
5f3cc447 709{
2dab38e2 710 list_add_tail(&buf->list, &vid_cap->active_buf_q);
5f3cc447
SN
711 vid_cap->active_buf_cnt++;
712}
713
714/*
715 * Pop a video buffer from the capture active buffers queue
2dab38e2 716 * Locking: Need to be called with fimc_dev::slock held.
5f3cc447
SN
717 */
718static inline struct fimc_vid_buffer *
719active_queue_pop(struct fimc_vid_cap *vid_cap)
720{
721 struct fimc_vid_buffer *buf;
722 buf = list_entry(vid_cap->active_buf_q.next,
2dab38e2
SN
723 struct fimc_vid_buffer, list);
724 list_del(&buf->list);
5f3cc447
SN
725 vid_cap->active_buf_cnt--;
726 return buf;
727}
728
729/* Add video buffer to the capture pending buffers queue */
730static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap,
731 struct fimc_vid_buffer *buf)
732{
2dab38e2 733 list_add_tail(&buf->list, &vid_cap->pending_buf_q);
5f3cc447
SN
734}
735
736/* Add video buffer to the capture pending buffers queue */
737static inline struct fimc_vid_buffer *
738pending_queue_pop(struct fimc_vid_cap *vid_cap)
739{
740 struct fimc_vid_buffer *buf;
741 buf = list_entry(vid_cap->pending_buf_q.next,
2dab38e2
SN
742 struct fimc_vid_buffer, list);
743 list_del(&buf->list);
5f3cc447
SN
744 return buf;
745}
746
5fd8f738 747#endif /* FIMC_CORE_H_ */
This page took 0.687591 seconds and 5 git commands to generate.