rt2800: initialize BBP_R104 on proper subroutines
[linux/fpc-iii.git] / drivers / media / platform / exynos4-is / fimc-lite.h
blob47da5e04924775b385c83cc3ba3c42027eccc261
1 /*
2 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
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 */
9 #ifndef FIMC_LITE_H_
10 #define FIMC_LITE_H_
12 #include <linux/sizes.h>
13 #include <linux/io.h>
14 #include <linux/irqreturn.h>
15 #include <linux/platform_device.h>
16 #include <linux/sched.h>
17 #include <linux/spinlock.h>
18 #include <linux/types.h>
19 #include <linux/videodev2.h>
21 #include <media/media-entity.h>
22 #include <media/videobuf2-core.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-device.h>
25 #include <media/v4l2-mediabus.h>
26 #include <media/s5p_fimc.h>
28 #define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
29 #define FLITE_CLK_NAME "flite"
30 #define FIMC_LITE_MAX_DEVS 2
31 #define FLITE_REQ_BUFS_MIN 2
33 /* Bit index definitions for struct fimc_lite::state */
34 enum {
35 ST_FLITE_LPM,
36 ST_FLITE_PENDING,
37 ST_FLITE_RUN,
38 ST_FLITE_STREAM,
39 ST_FLITE_SUSPENDED,
40 ST_FLITE_OFF,
41 ST_FLITE_IN_USE,
42 ST_FLITE_CONFIG,
43 ST_SENSOR_STREAM,
46 #define FLITE_SD_PAD_SINK 0
47 #define FLITE_SD_PAD_SOURCE_DMA 1
48 #define FLITE_SD_PAD_SOURCE_ISP 2
49 #define FLITE_SD_PADS_NUM 3
51 struct flite_drvdata {
52 unsigned short max_width;
53 unsigned short max_height;
54 unsigned short out_width_align;
55 unsigned short win_hor_offs_align;
56 unsigned short out_hor_offs_align;
59 #define fimc_lite_get_drvdata(_pdev) \
60 ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data)
62 struct fimc_lite_events {
63 unsigned int data_overflow;
66 #define FLITE_MAX_PLANES 1
68 /**
69 * struct flite_frame - source/target frame properties
70 * @f_width: full pixel width
71 * @f_height: full pixel height
72 * @rect: crop/composition rectangle
73 * @fmt: pointer to pixel format description data structure
75 struct flite_frame {
76 u16 f_width;
77 u16 f_height;
78 struct v4l2_rect rect;
79 const struct fimc_fmt *fmt;
82 /**
83 * struct flite_buffer - video buffer structure
84 * @vb: vb2 buffer
85 * @list: list head for the buffers queue
86 * @paddr: precalculated physical address
88 struct flite_buffer {
89 struct vb2_buffer vb;
90 struct list_head list;
91 dma_addr_t paddr;
94 /**
95 * struct fimc_lite - fimc lite structure
96 * @pdev: pointer to FIMC-LITE platform device
97 * @dd: SoC specific driver data structure
98 * @v4l2_dev: pointer to top the level v4l2_device
99 * @vfd: video device node
100 * @fh: v4l2 file handle
101 * @alloc_ctx: videobuf2 memory allocator context
102 * @subdev: FIMC-LITE subdev
103 * @vd_pad: media (sink) pad for the capture video node
104 * @subdev_pads: the subdev media pads
105 * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
106 * @ctrl_handler: v4l2 control handler
107 * @test_pattern: test pattern controls
108 * @index: FIMC-LITE platform device index
109 * @pipeline: video capture pipeline data structure
110 * @pipeline_ops: media pipeline ops for the video node driver
111 * @slock: spinlock protecting this data structure and the hw registers
112 * @lock: mutex serializing video device and the subdev operations
113 * @clock: FIMC-LITE gate clock
114 * @regs: memory mapped io registers
115 * @irq_queue: interrupt handler waitqueue
116 * @payload: image size in bytes (w x h x bpp)
117 * @inp_frame: camera input frame structure
118 * @out_frame: DMA output frame structure
119 * @out_path: output data path (DMA or FIFO)
120 * @source_subdev_grp_id: source subdev group id
121 * @state: driver state flags
122 * @pending_buf_q: pending buffers queue head
123 * @active_buf_q: the queue head of buffers scheduled in hardware
124 * @vb_queue: vb2 buffers queue
125 * @active_buf_count: number of video buffers scheduled in hardware
126 * @frame_count: the captured frames counter
127 * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
128 * @ref_count: driver's private reference counter
130 struct fimc_lite {
131 struct platform_device *pdev;
132 struct flite_drvdata *dd;
133 struct v4l2_device *v4l2_dev;
134 struct video_device vfd;
135 struct v4l2_fh fh;
136 struct vb2_alloc_ctx *alloc_ctx;
137 struct v4l2_subdev subdev;
138 struct media_pad vd_pad;
139 struct media_pad subdev_pads[FLITE_SD_PADS_NUM];
140 struct v4l2_subdev *sensor;
141 struct v4l2_ctrl_handler ctrl_handler;
142 struct v4l2_ctrl *test_pattern;
143 int index;
144 struct fimc_pipeline pipeline;
145 const struct fimc_pipeline_ops *pipeline_ops;
147 struct mutex lock;
148 spinlock_t slock;
150 struct clk *clock;
151 void __iomem *regs;
152 wait_queue_head_t irq_queue;
154 unsigned long payload[FLITE_MAX_PLANES];
155 struct flite_frame inp_frame;
156 struct flite_frame out_frame;
157 atomic_t out_path;
158 unsigned int source_subdev_grp_id;
160 unsigned long state;
161 struct list_head pending_buf_q;
162 struct list_head active_buf_q;
163 struct vb2_queue vb_queue;
164 unsigned int frame_count;
165 unsigned int reqbufs_count;
166 int ref_count;
168 struct fimc_lite_events events;
169 bool streaming;
172 static inline bool fimc_lite_active(struct fimc_lite *fimc)
174 unsigned long flags;
175 bool ret;
177 spin_lock_irqsave(&fimc->slock, flags);
178 ret = fimc->state & (1 << ST_FLITE_RUN) ||
179 fimc->state & (1 << ST_FLITE_PENDING);
180 spin_unlock_irqrestore(&fimc->slock, flags);
181 return ret;
184 static inline void fimc_lite_active_queue_add(struct fimc_lite *dev,
185 struct flite_buffer *buf)
187 list_add_tail(&buf->list, &dev->active_buf_q);
190 static inline struct flite_buffer *fimc_lite_active_queue_pop(
191 struct fimc_lite *dev)
193 struct flite_buffer *buf = list_entry(dev->active_buf_q.next,
194 struct flite_buffer, list);
195 list_del(&buf->list);
196 return buf;
199 static inline void fimc_lite_pending_queue_add(struct fimc_lite *dev,
200 struct flite_buffer *buf)
202 list_add_tail(&buf->list, &dev->pending_buf_q);
205 static inline struct flite_buffer *fimc_lite_pending_queue_pop(
206 struct fimc_lite *dev)
208 struct flite_buffer *buf = list_entry(dev->pending_buf_q.next,
209 struct flite_buffer, list);
210 list_del(&buf->list);
211 return buf;
214 #endif /* FIMC_LITE_H_ */