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