blob: a7ed16497903ef171caf128697900aa9700b3915 [file] [log] [blame]
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001/*
2 * Copyright (C) 2009 Texas Instruments Inc
Lad, Prabhakar96787eb2014-05-16 10:33:55 -03003 * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com>
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * TODO : add support for VBI & HBI data service
20 * add static buffer allocation
21 */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030022
Lad, Prabhakar012eef72013-04-19 05:53:29 -030023#include <linux/module.h>
24#include <linux/interrupt.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27
Lad, Prabhakar012eef72013-04-19 05:53:29 -030028#include <media/v4l2-ioctl.h>
29
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030030#include "vpif.h"
Lad, Prabhakar012eef72013-04-19 05:53:29 -030031#include "vpif_capture.h"
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030032
33MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
34MODULE_LICENSE("GPL");
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030035MODULE_VERSION(VPIF_CAPTURE_VERSION);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030036
37#define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
38#define vpif_dbg(level, debug, fmt, arg...) \
39 v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
40
41static int debug = 1;
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -030042static u32 ch0_numbuffers = 3;
43static u32 ch1_numbuffers = 3;
44static u32 ch0_bufsize = 1920 * 1080 * 2;
45static u32 ch1_bufsize = 720 * 576 * 2;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030046
47module_param(debug, int, 0644);
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -030048module_param(ch0_numbuffers, uint, S_IRUGO);
49module_param(ch1_numbuffers, uint, S_IRUGO);
50module_param(ch0_bufsize, uint, S_IRUGO);
51module_param(ch1_bufsize, uint, S_IRUGO);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030052
53MODULE_PARM_DESC(debug, "Debug level 0-1");
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -030054MODULE_PARM_DESC(ch2_numbuffers, "Channel0 buffer count (default:3)");
55MODULE_PARM_DESC(ch3_numbuffers, "Channel1 buffer count (default:3)");
56MODULE_PARM_DESC(ch2_bufsize, "Channel0 buffer size (default:1920 x 1080 x 2)");
57MODULE_PARM_DESC(ch3_bufsize, "Channel1 buffer size (default:720 x 576 x 2)");
58
59static struct vpif_config_params config_params = {
60 .min_numbuffers = 3,
61 .numbuffers[0] = 3,
62 .numbuffers[1] = 3,
63 .min_bufsize[0] = 720 * 480 * 2,
64 .min_bufsize[1] = 720 * 480 * 2,
65 .channel_bufsize[0] = 1920 * 1080 * 2,
66 .channel_bufsize[1] = 720 * 576 * 2,
67};
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030068
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -030069#define VPIF_DRIVER_NAME "vpif_capture"
70
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030071/* global variables */
72static struct vpif_device vpif_obj = { {NULL} };
73static struct device *vpif_dev;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030074static void vpif_calculate_offsets(struct channel_obj *ch);
75static void vpif_config_addr(struct channel_obj *ch, int muxmode);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030076
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030077static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
78
Lad, Prabhakarc66238f2014-05-16 10:33:45 -030079/* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */
80static int ycmux_mode;
81
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030082static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb)
83{
84 return container_of(vb, struct vpif_cap_buffer, vb);
85}
86
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030087/**
Lad, Prabhakar23e76a22014-05-16 10:33:37 -030088 * vpif_buffer_prepare : callback function for buffer prepare
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030089 * @vb: ptr to vb2_buffer
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030090 *
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030091 * This is the callback function for buffer prepare when vb2_qbuf()
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030092 * function is called. The buffer is prepared and user space virtual address
93 * or user address is converted into physical address
94 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030095static int vpif_buffer_prepare(struct vb2_buffer *vb)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030096{
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030097 struct vb2_queue *q = vb->vb2_queue;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030098 struct channel_obj *ch = vb2_get_drv_priv(q);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030099 struct common_obj *common;
100 unsigned long addr;
101
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300102 vpif_dbg(2, debug, "vpif_buffer_prepare\n");
103
104 common = &ch->common[VPIF_VIDEO_INDEX];
105
Lad, Prabhakar23e76a22014-05-16 10:33:37 -0300106 vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
107 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
108 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300109
Lad, Prabhakar23e76a22014-05-16 10:33:37 -0300110 vb->v4l2_buf.field = common->fmt.fmt.pix.field;
111
112 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
113 if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
114 !IS_ALIGNED((addr + common->ybtm_off), 8) ||
115 !IS_ALIGNED((addr + common->ctop_off), 8) ||
116 !IS_ALIGNED((addr + common->cbtm_off), 8)) {
117 vpif_dbg(1, debug, "offset is not aligned\n");
118 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300119 }
Lad, Prabhakar23e76a22014-05-16 10:33:37 -0300120
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300121 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300122}
123
124/**
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300125 * vpif_buffer_queue_setup : Callback function for buffer setup.
126 * @vq: vb2_queue ptr
127 * @fmt: v4l2 format
128 * @nbuffers: ptr to number of buffers requested by application
129 * @nplanes:: contains number of distinct video planes needed to hold a frame
130 * @sizes[]: contains the size (in bytes) of each plane.
131 * @alloc_ctxs: ptr to allocation context
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300132 *
133 * This callback function is called when reqbuf() is called to adjust
134 * the buffer count and buffer size
135 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300136static int vpif_buffer_queue_setup(struct vb2_queue *vq,
137 const struct v4l2_format *fmt,
138 unsigned int *nbuffers, unsigned int *nplanes,
139 unsigned int sizes[], void *alloc_ctxs[])
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300140{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300141 struct channel_obj *ch = vb2_get_drv_priv(vq);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300142 struct common_obj *common;
143
144 common = &ch->common[VPIF_VIDEO_INDEX];
145
146 vpif_dbg(2, debug, "vpif_buffer_setup\n");
147
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300148 if (fmt && fmt->fmt.pix.sizeimage < common->fmt.fmt.pix.sizeimage)
149 return -EINVAL;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300150
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300151 if (vq->num_buffers + *nbuffers < 3)
152 *nbuffers = 3 - vq->num_buffers;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300153
154 *nplanes = 1;
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300155 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : common->fmt.fmt.pix.sizeimage;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300156 alloc_ctxs[0] = common->alloc_ctx;
157
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300158 /* Calculate the offset for Y and C data in the buffer */
159 vpif_calculate_offsets(ch);
160
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300161 return 0;
162}
163
164/**
165 * vpif_buffer_queue : Callback function to add buffer to DMA queue
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300166 * @vb: ptr to vb2_buffer
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300167 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300168static void vpif_buffer_queue(struct vb2_buffer *vb)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300169{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300170 struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
171 struct vpif_cap_buffer *buf = to_vpif_buffer(vb);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300172 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300173 unsigned long flags;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300174
175 common = &ch->common[VPIF_VIDEO_INDEX];
176
177 vpif_dbg(2, debug, "vpif_buffer_queue\n");
178
Hans Verkuilaec96832012-11-16 12:03:06 -0300179 spin_lock_irqsave(&common->irqlock, flags);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300180 /* add the buffer to the DMA queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300181 list_add_tail(&buf->list, &common->dma_queue);
Hans Verkuilaec96832012-11-16 12:03:06 -0300182 spin_unlock_irqrestore(&common->irqlock, flags);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300183}
184
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300185/**
186 * vpif_start_streaming : Starts the DMA engine for streaming
187 * @vb: ptr to vb2_buffer
188 * @count: number of buffers
189 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300190static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
191{
192 struct vpif_capture_config *vpif_config_data =
193 vpif_dev->platform_data;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300194 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300195 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
196 struct vpif_params *vpif = &ch->vpifparams;
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300197 struct vpif_cap_buffer *buf, *tmp;
198 unsigned long addr, flags;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300199 int ret;
200
Hans Verkuilaec96832012-11-16 12:03:06 -0300201 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300202
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300203 /* Initialize field_id */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300204 ch->field_id = 0;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300205
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300206 /* configure 1 or 2 channel mode */
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300207 if (vpif_config_data->setup_input_channel_mode) {
208 ret = vpif_config_data->
209 setup_input_channel_mode(vpif->std_info.ycmux_mode);
210 if (ret < 0) {
211 vpif_dbg(1, debug, "can't set vpif channel mode\n");
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300212 goto err;
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300213 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300214 }
215
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300216 ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
217 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
218 vpif_dbg(1, debug, "stream on failed in subdev\n");
219 goto err;
220 }
221
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300222 /* Call vpif_set_params function to set the parameters and addresses */
223 ret = vpif_set_video_params(vpif, ch->channel_id);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300224 if (ret < 0) {
225 vpif_dbg(1, debug, "can't set video params\n");
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300226 goto err;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300227 }
228
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300229 ycmux_mode = ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300230 vpif_config_addr(ch, ret);
231
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300232 /* Get the next frame from the buffer queue */
233 common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
234 struct vpif_cap_buffer, list);
235 /* Remove buffer from the buffer queue */
236 list_del(&common->cur_frm->list);
237 spin_unlock_irqrestore(&common->irqlock, flags);
238 /* Mark state of the current frame to active */
239 common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
240
241 addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
242
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300243 common->set_addr(addr + common->ytop_off,
244 addr + common->ybtm_off,
245 addr + common->ctop_off,
246 addr + common->cbtm_off);
247
248 /**
249 * Set interrupt for both the fields in VPIF Register enable channel in
250 * VPIF register
251 */
Lad, Prabhakar9e184042012-09-14 10:22:24 -0300252 channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300253 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300254 channel0_intr_assert();
255 channel0_intr_enable(1);
256 enable_channel0(1);
257 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300258 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300259 ycmux_mode == 2) {
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300260 channel1_intr_assert();
261 channel1_intr_enable(1);
262 enable_channel1(1);
263 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300264
265 return 0;
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300266
267err:
268 list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
269 list_del(&buf->list);
270 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
271 }
272
273 return ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300274}
275
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300276/**
277 * vpif_stop_streaming : Stop the DMA engine
278 * @vq: ptr to vb2_queue
279 *
280 * This callback stops the DMA engine and any remaining buffers
281 * in the DMA queue are released.
282 */
Hans Verkuile37559b2014-04-17 02:47:21 -0300283static void vpif_stop_streaming(struct vb2_queue *vq)
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300284{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300285 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300286 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300287 unsigned long flags;
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300288 int ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300289
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300290 common = &ch->common[VPIF_VIDEO_INDEX];
291
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300292 /* Disable channel as per its device type and channel id */
293 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
294 enable_channel0(0);
295 channel0_intr_enable(0);
296 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300297 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300298 ycmux_mode == 2) {
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300299 enable_channel1(0);
300 channel1_intr_enable(0);
301 }
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300302
303 ycmux_mode = 0;
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300304
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300305 ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
306 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
307 vpif_dbg(1, debug, "stream off failed in subdev\n");
308
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300309 /* release all active buffers */
Hans Verkuilaec96832012-11-16 12:03:06 -0300310 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300311 if (common->cur_frm == common->next_frm) {
312 vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
313 } else {
314 if (common->cur_frm != NULL)
315 vb2_buffer_done(&common->cur_frm->vb,
316 VB2_BUF_STATE_ERROR);
317 if (common->next_frm != NULL)
318 vb2_buffer_done(&common->next_frm->vb,
319 VB2_BUF_STATE_ERROR);
320 }
321
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300322 while (!list_empty(&common->dma_queue)) {
323 common->next_frm = list_entry(common->dma_queue.next,
324 struct vpif_cap_buffer, list);
325 list_del(&common->next_frm->list);
326 vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
327 }
Hans Verkuilaec96832012-11-16 12:03:06 -0300328 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300329}
330
331static struct vb2_ops video_qops = {
332 .queue_setup = vpif_buffer_queue_setup,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300333 .buf_prepare = vpif_buffer_prepare,
334 .start_streaming = vpif_start_streaming,
335 .stop_streaming = vpif_stop_streaming,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300336 .buf_queue = vpif_buffer_queue,
337};
338
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300339/**
340 * vpif_process_buffer_complete: process a completed buffer
341 * @common: ptr to common channel object
342 *
343 * This function time stamp the buffer and mark it as DONE. It also
344 * wake up any process waiting on the QUEUE and set the next buffer
345 * as current
346 */
347static void vpif_process_buffer_complete(struct common_obj *common)
348{
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300349 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300350 vb2_buffer_done(&common->cur_frm->vb,
351 VB2_BUF_STATE_DONE);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300352 /* Make curFrm pointing to nextFrm */
353 common->cur_frm = common->next_frm;
354}
355
356/**
357 * vpif_schedule_next_buffer: set next buffer address for capture
358 * @common : ptr to common channel object
359 *
360 * This function will get next buffer from the dma queue and
361 * set the buffer address in the vpif register for capture.
362 * the buffer is marked active
363 */
364static void vpif_schedule_next_buffer(struct common_obj *common)
365{
366 unsigned long addr = 0;
367
Hans Verkuilaec96832012-11-16 12:03:06 -0300368 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300369 common->next_frm = list_entry(common->dma_queue.next,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300370 struct vpif_cap_buffer, list);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300371 /* Remove that buffer from the buffer queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300372 list_del(&common->next_frm->list);
Hans Verkuilaec96832012-11-16 12:03:06 -0300373 spin_unlock(&common->irqlock);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300374 common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
375 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300376
377 /* Set top and bottom field addresses in VPIF registers */
378 common->set_addr(addr + common->ytop_off,
379 addr + common->ybtm_off,
380 addr + common->ctop_off,
381 addr + common->cbtm_off);
382}
383
384/**
385 * vpif_channel_isr : ISR handler for vpif capture
386 * @irq: irq number
387 * @dev_id: dev_id ptr
388 *
389 * It changes status of the captured buffer, takes next buffer from the queue
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300390 * and sets its address in VPIF registers
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300391 */
392static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
393{
394 struct vpif_device *dev = &vpif_obj;
395 struct common_obj *common;
396 struct channel_obj *ch;
397 enum v4l2_field field;
398 int channel_id = 0;
399 int fid = -1, i;
400
401 channel_id = *(int *)(dev_id);
Manjunath Hadlib1fc4232012-04-13 04:43:10 -0300402 if (!vpif_intr_status(channel_id))
403 return IRQ_NONE;
404
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300405 ch = dev->dev[channel_id];
406
407 field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
408
409 for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
410 common = &ch->common[i];
411 /* skip If streaming is not started in this channel */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300412 /* Check the field format */
413 if (1 == ch->vpifparams.std_info.frm_fmt) {
414 /* Progressive mode */
Hans Verkuilaec96832012-11-16 12:03:06 -0300415 spin_lock(&common->irqlock);
416 if (list_empty(&common->dma_queue)) {
417 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300418 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300419 }
420 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300421
422 if (!channel_first_int[i][channel_id])
423 vpif_process_buffer_complete(common);
424
425 channel_first_int[i][channel_id] = 0;
426
427 vpif_schedule_next_buffer(common);
428
429
430 channel_first_int[i][channel_id] = 0;
431 } else {
432 /**
433 * Interlaced mode. If it is first interrupt, ignore
434 * it
435 */
436 if (channel_first_int[i][channel_id]) {
437 channel_first_int[i][channel_id] = 0;
438 continue;
439 }
440 if (0 == i) {
441 ch->field_id ^= 1;
442 /* Get field id from VPIF registers */
443 fid = vpif_channel_getfid(ch->channel_id);
444 if (fid != ch->field_id) {
445 /**
446 * If field id does not match stored
447 * field id, make them in sync
448 */
449 if (0 == fid)
450 ch->field_id = fid;
451 return IRQ_HANDLED;
452 }
453 }
454 /* device field id and local field id are in sync */
455 if (0 == fid) {
456 /* this is even field */
457 if (common->cur_frm == common->next_frm)
458 continue;
459
460 /* mark the current buffer as done */
461 vpif_process_buffer_complete(common);
462 } else if (1 == fid) {
463 /* odd field */
Hans Verkuilaec96832012-11-16 12:03:06 -0300464 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300465 if (list_empty(&common->dma_queue) ||
Hans Verkuilaec96832012-11-16 12:03:06 -0300466 (common->cur_frm != common->next_frm)) {
467 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300468 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300469 }
470 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300471
472 vpif_schedule_next_buffer(common);
473 }
474 }
475 }
476 return IRQ_HANDLED;
477}
478
479/**
480 * vpif_update_std_info() - update standard related info
481 * @ch: ptr to channel object
482 *
483 * For a given standard selected by application, update values
484 * in the device data structures
485 */
486static int vpif_update_std_info(struct channel_obj *ch)
487{
488 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
489 struct vpif_params *vpifparams = &ch->vpifparams;
490 const struct vpif_channel_config_params *config;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300491 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300492 struct video_obj *vid_ch = &ch->video;
493 int index;
494
495 vpif_dbg(2, debug, "vpif_update_std_info\n");
496
Mats Randgaardaa444402010-12-16 12:17:42 -0300497 for (index = 0; index < vpif_ch_params_count; index++) {
Lad, Prabhakarced9b212013-03-20 01:28:27 -0300498 config = &vpif_ch_params[index];
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300499 if (config->hd_sd == 0) {
500 vpif_dbg(2, debug, "SD format\n");
501 if (config->stdid & vid_ch->stdid) {
502 memcpy(std_info, config, sizeof(*config));
503 break;
504 }
505 } else {
506 vpif_dbg(2, debug, "HD format\n");
Hans Verkuil0598c172012-09-18 07:18:47 -0300507 if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
508 sizeof(vid_ch->dv_timings))) {
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300509 memcpy(std_info, config, sizeof(*config));
510 break;
511 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300512 }
513 }
514
515 /* standard not found */
Mats Randgaardaa444402010-12-16 12:17:42 -0300516 if (index == vpif_ch_params_count)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300517 return -EINVAL;
518
519 common->fmt.fmt.pix.width = std_info->width;
520 common->width = std_info->width;
521 common->fmt.fmt.pix.height = std_info->height;
522 common->height = std_info->height;
523 common->fmt.fmt.pix.bytesperline = std_info->width;
524 vpifparams->video_params.hpitch = std_info->width;
525 vpifparams->video_params.storage_mode = std_info->frm_fmt;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300526
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300527 return 0;
528}
529
530/**
531 * vpif_calculate_offsets : This function calculates buffers offsets
532 * @ch : ptr to channel object
533 *
534 * This function calculates buffer offsets for Y and C in the top and
535 * bottom field
536 */
537static void vpif_calculate_offsets(struct channel_obj *ch)
538{
539 unsigned int hpitch, vpitch, sizeimage;
540 struct video_obj *vid_ch = &(ch->video);
541 struct vpif_params *vpifparams = &ch->vpifparams;
542 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
543 enum v4l2_field field = common->fmt.fmt.pix.field;
544
545 vpif_dbg(2, debug, "vpif_calculate_offsets\n");
546
547 if (V4L2_FIELD_ANY == field) {
548 if (vpifparams->std_info.frm_fmt)
549 vid_ch->buf_field = V4L2_FIELD_NONE;
550 else
551 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
552 } else
553 vid_ch->buf_field = common->fmt.fmt.pix.field;
554
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300555 sizeimage = common->fmt.fmt.pix.sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300556
557 hpitch = common->fmt.fmt.pix.bytesperline;
558 vpitch = sizeimage / (hpitch * 2);
559
560 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
561 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
562 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
563 common->ytop_off = 0;
564 common->ybtm_off = hpitch;
565 common->ctop_off = sizeimage / 2;
566 common->cbtm_off = sizeimage / 2 + hpitch;
567 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
568 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
569 common->ytop_off = 0;
570 common->ybtm_off = sizeimage / 4;
571 common->ctop_off = sizeimage / 2;
572 common->cbtm_off = common->ctop_off + sizeimage / 4;
573 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
574 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
575 common->ybtm_off = 0;
576 common->ytop_off = sizeimage / 4;
577 common->cbtm_off = sizeimage / 2;
578 common->ctop_off = common->cbtm_off + sizeimage / 4;
579 }
580 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
581 (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
582 vpifparams->video_params.storage_mode = 1;
583 else
584 vpifparams->video_params.storage_mode = 0;
585
586 if (1 == vpifparams->std_info.frm_fmt)
587 vpifparams->video_params.hpitch =
588 common->fmt.fmt.pix.bytesperline;
589 else {
590 if ((field == V4L2_FIELD_ANY)
591 || (field == V4L2_FIELD_INTERLACED))
592 vpifparams->video_params.hpitch =
593 common->fmt.fmt.pix.bytesperline * 2;
594 else
595 vpifparams->video_params.hpitch =
596 common->fmt.fmt.pix.bytesperline;
597 }
598
599 ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
600}
601
602/**
603 * vpif_config_format: configure default frame format in the device
604 * ch : ptr to channel object
605 */
606static void vpif_config_format(struct channel_obj *ch)
607{
608 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
609
610 vpif_dbg(2, debug, "vpif_config_format\n");
611
612 common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -0300613 common->fmt.fmt.pix.sizeimage
614 = config_params.channel_bufsize[ch->channel_id];
615
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300616 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
617 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
618 else
619 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
620 common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
621}
622
623/**
624 * vpif_get_default_field() - Get default field type based on interface
625 * @vpif_params - ptr to vpif params
626 */
627static inline enum v4l2_field vpif_get_default_field(
628 struct vpif_interface *iface)
629{
630 return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
631 V4L2_FIELD_INTERLACED;
632}
633
634/**
635 * vpif_check_format() - check given pixel format for compatibility
636 * @ch - channel ptr
637 * @pixfmt - Given pixel format
638 * @update - update the values as per hardware requirement
639 *
640 * Check the application pixel format for S_FMT and update the input
641 * values as per hardware limits for TRY_FMT. The default pixel and
642 * field format is selected based on interface type.
643 */
644static int vpif_check_format(struct channel_obj *ch,
645 struct v4l2_pix_format *pixfmt,
646 int update)
647{
648 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
649 struct vpif_params *vpif_params = &ch->vpifparams;
650 enum v4l2_field field = pixfmt->field;
651 u32 sizeimage, hpitch, vpitch;
652 int ret = -EINVAL;
653
654 vpif_dbg(2, debug, "vpif_check_format\n");
655 /**
656 * first check for the pixel format. If if_type is Raw bayer,
657 * only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only
658 * V4L2_PIX_FMT_YUV422P is supported
659 */
660 if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
661 if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) {
662 if (!update) {
663 vpif_dbg(2, debug, "invalid pix format\n");
664 goto exit;
665 }
666 pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
667 }
668 } else {
669 if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) {
670 if (!update) {
671 vpif_dbg(2, debug, "invalid pixel format\n");
672 goto exit;
673 }
674 pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
675 }
676 }
677
678 if (!(VPIF_VALID_FIELD(field))) {
679 if (!update) {
680 vpif_dbg(2, debug, "invalid field format\n");
681 goto exit;
682 }
683 /**
684 * By default use FIELD_NONE for RAW Bayer capture
685 * and FIELD_INTERLACED for other interfaces
686 */
687 field = vpif_get_default_field(&vpif_params->iface);
688 } else if (field == V4L2_FIELD_ANY)
689 /* unsupported field. Use default */
690 field = vpif_get_default_field(&vpif_params->iface);
691
692 /* validate the hpitch */
693 hpitch = pixfmt->bytesperline;
694 if (hpitch < vpif_params->std_info.width) {
695 if (!update) {
696 vpif_dbg(2, debug, "invalid hpitch\n");
697 goto exit;
698 }
699 hpitch = vpif_params->std_info.width;
700 }
701
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300702 sizeimage = pixfmt->sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300703
704 vpitch = sizeimage / (hpitch * 2);
705
706 /* validate the vpitch */
707 if (vpitch < vpif_params->std_info.height) {
708 if (!update) {
709 vpif_dbg(2, debug, "Invalid vpitch\n");
710 goto exit;
711 }
712 vpitch = vpif_params->std_info.height;
713 }
714
715 /* Check for 8 byte alignment */
716 if (!ALIGN(hpitch, 8)) {
717 if (!update) {
718 vpif_dbg(2, debug, "invalid pitch alignment\n");
719 goto exit;
720 }
721 /* adjust to next 8 byte boundary */
722 hpitch = (((hpitch + 7) / 8) * 8);
723 }
724 /* if update is set, modify the bytesperline and sizeimage */
725 if (update) {
726 pixfmt->bytesperline = hpitch;
727 pixfmt->sizeimage = hpitch * vpitch * 2;
728 }
729 /**
730 * Image width and height is always based on current standard width and
731 * height
732 */
733 pixfmt->width = common->fmt.fmt.pix.width;
734 pixfmt->height = common->fmt.fmt.pix.height;
735 return 0;
736exit:
737 return ret;
738}
739
740/**
741 * vpif_config_addr() - function to configure buffer address in vpif
742 * @ch - channel ptr
743 * @muxmode - channel mux mode
744 */
745static void vpif_config_addr(struct channel_obj *ch, int muxmode)
746{
747 struct common_obj *common;
748
749 vpif_dbg(2, debug, "vpif_config_addr\n");
750
751 common = &(ch->common[VPIF_VIDEO_INDEX]);
752
753 if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
754 common->set_addr = ch1_set_videobuf_addr;
755 else if (2 == muxmode)
756 common->set_addr = ch0_set_videobuf_addr_yc_nmux;
757 else
758 common->set_addr = ch0_set_videobuf_addr;
759}
760
761/**
Hans Verkuil178cce12012-09-20 09:06:30 -0300762 * vpif_input_to_subdev() - Maps input to sub device
763 * @vpif_cfg - global config ptr
764 * @chan_cfg - channel config ptr
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300765 * @input_index - Given input index from application
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300766 *
767 * lookup the sub device information for a given input index.
768 * we report all the inputs to application. inputs table also
769 * has sub device name for the each input
770 */
Hans Verkuil178cce12012-09-20 09:06:30 -0300771static int vpif_input_to_subdev(
772 struct vpif_capture_config *vpif_cfg,
773 struct vpif_capture_chan_config *chan_cfg,
774 int input_index)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300775{
Hans Verkuil178cce12012-09-20 09:06:30 -0300776 struct vpif_subdev_info *subdev_info;
777 const char *subdev_name;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300778 int i;
779
Hans Verkuil178cce12012-09-20 09:06:30 -0300780 vpif_dbg(2, debug, "vpif_input_to_subdev\n");
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300781
Hans Verkuil178cce12012-09-20 09:06:30 -0300782 subdev_name = chan_cfg->inputs[input_index].subdev_name;
783 if (subdev_name == NULL)
784 return -1;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300785
786 /* loop through the sub device list to get the sub device info */
787 for (i = 0; i < vpif_cfg->subdev_count; i++) {
788 subdev_info = &vpif_cfg->subdev_info[i];
789 if (!strcmp(subdev_info->name, subdev_name))
Hans Verkuil178cce12012-09-20 09:06:30 -0300790 return i;
791 }
792 return -1;
793}
794
795/**
796 * vpif_set_input() - Select an input
797 * @vpif_cfg - global config ptr
798 * @ch - channel
799 * @_index - Given input index from application
800 *
801 * Select the given input.
802 */
803static int vpif_set_input(
804 struct vpif_capture_config *vpif_cfg,
805 struct channel_obj *ch,
806 int index)
807{
808 struct vpif_capture_chan_config *chan_cfg =
809 &vpif_cfg->chan_config[ch->channel_id];
810 struct vpif_subdev_info *subdev_info = NULL;
811 struct v4l2_subdev *sd = NULL;
812 u32 input = 0, output = 0;
813 int sd_index;
814 int ret;
815
816 sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
817 if (sd_index >= 0) {
818 sd = vpif_obj.sd[sd_index];
819 subdev_info = &vpif_cfg->subdev_info[sd_index];
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300820 }
821
Hans Verkuil178cce12012-09-20 09:06:30 -0300822 /* first setup input path from sub device to vpif */
823 if (sd && vpif_cfg->setup_input_path) {
824 ret = vpif_cfg->setup_input_path(ch->channel_id,
825 subdev_info->name);
826 if (ret < 0) {
827 vpif_dbg(1, debug, "couldn't setup input path for the" \
828 " sub device %s, for input index %d\n",
829 subdev_info->name, index);
830 return ret;
831 }
832 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300833
Hans Verkuil178cce12012-09-20 09:06:30 -0300834 if (sd) {
835 input = chan_cfg->inputs[index].input_route;
836 output = chan_cfg->inputs[index].output_route;
837 ret = v4l2_subdev_call(sd, video, s_routing,
838 input, output, 0);
839 if (ret < 0 && ret != -ENOIOCTLCMD) {
840 vpif_dbg(1, debug, "Failed to set input\n");
841 return ret;
842 }
843 }
844 ch->input_idx = index;
845 ch->sd = sd;
846 /* copy interface parameters to vpif */
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300847 ch->vpifparams.iface = chan_cfg->vpif_if;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300848
Hans Verkuil178cce12012-09-20 09:06:30 -0300849 /* update tvnorms from the sub device input info */
850 ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
851 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300852}
853
854/**
855 * vpif_querystd() - querystd handler
856 * @file: file ptr
857 * @priv: file handle
858 * @std_id: ptr to std id
859 *
860 * This function is called to detect standard at the selected input
861 */
862static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
863{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300864 struct video_device *vdev = video_devdata(file);
865 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300866 int ret = 0;
867
868 vpif_dbg(2, debug, "vpif_querystd\n");
869
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300870 /* Call querystd function of decoder device */
Hans Verkuil178cce12012-09-20 09:06:30 -0300871 ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300872
Hans Verkuil178cce12012-09-20 09:06:30 -0300873 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
874 return -ENODATA;
875 if (ret) {
876 vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
877 return ret;
878 }
879
880 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300881}
882
883/**
884 * vpif_g_std() - get STD handler
885 * @file: file ptr
886 * @priv: file handle
887 * @std_id: ptr to std id
888 */
889static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
890{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300891 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300892 struct video_device *vdev = video_devdata(file);
893 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300894 struct vpif_capture_chan_config *chan_cfg;
895 struct v4l2_input input;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300896
897 vpif_dbg(2, debug, "vpif_g_std\n");
898
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300899 if (config->chan_config[ch->channel_id].inputs == NULL)
900 return -ENODATA;
901
902 chan_cfg = &config->chan_config[ch->channel_id];
903 input = chan_cfg->inputs[ch->input_idx].input;
904 if (input.capabilities != V4L2_IN_CAP_STD)
905 return -ENODATA;
906
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300907 *std = ch->video.stdid;
908 return 0;
909}
910
911/**
912 * vpif_s_std() - set STD handler
913 * @file: file ptr
914 * @priv: file handle
915 * @std_id: ptr to std id
916 */
Hans Verkuil314527a2013-03-15 06:10:40 -0300917static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300918{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300919 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300920 struct video_device *vdev = video_devdata(file);
921 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300922 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300923 struct vpif_capture_chan_config *chan_cfg;
924 struct v4l2_input input;
925 int ret;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300926
927 vpif_dbg(2, debug, "vpif_s_std\n");
928
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300929 if (config->chan_config[ch->channel_id].inputs == NULL)
930 return -ENODATA;
931
932 chan_cfg = &config->chan_config[ch->channel_id];
933 input = chan_cfg->inputs[ch->input_idx].input;
934 if (input.capabilities != V4L2_IN_CAP_STD)
935 return -ENODATA;
936
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300937 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300938 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300939
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300940 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -0300941 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -0300942 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300943
944 /* Get the information about the standard */
945 if (vpif_update_std_info(ch)) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300946 vpif_err("Error getting the standard info\n");
Hans Verkuil46656af2011-01-04 06:51:35 -0300947 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300948 }
949
950 /* Configure the default format information */
951 vpif_config_format(ch);
952
953 /* set standard in the sub device */
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300954 ret = v4l2_subdev_call(ch->sd, video, s_std, std_id);
Hans Verkuil178cce12012-09-20 09:06:30 -0300955 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300956 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
Hans Verkuil178cce12012-09-20 09:06:30 -0300957 return ret;
958 }
959 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300960}
961
962/**
963 * vpif_enum_input() - ENUMINPUT handler
964 * @file: file ptr
965 * @priv: file handle
966 * @input: ptr to input structure
967 */
968static int vpif_enum_input(struct file *file, void *priv,
969 struct v4l2_input *input)
970{
971
972 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300973 struct video_device *vdev = video_devdata(file);
974 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300975 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300976
977 chan_cfg = &config->chan_config[ch->channel_id];
978
979 if (input->index >= chan_cfg->input_count) {
980 vpif_dbg(1, debug, "Invalid input index\n");
981 return -EINVAL;
982 }
983
984 memcpy(input, &chan_cfg->inputs[input->index].input,
985 sizeof(*input));
986 return 0;
987}
988
989/**
990 * vpif_g_input() - Get INPUT handler
991 * @file: file ptr
992 * @priv: file handle
993 * @index: ptr to input index
994 */
995static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
996{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300997 struct video_device *vdev = video_devdata(file);
998 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300999
Hans Verkuil6f47c6c2012-09-20 09:06:22 -03001000 *index = ch->input_idx;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001001 return 0;
1002}
1003
1004/**
1005 * vpif_s_input() - Set INPUT handler
1006 * @file: file ptr
1007 * @priv: file handle
1008 * @index: input index
1009 */
1010static int vpif_s_input(struct file *file, void *priv, unsigned int index)
1011{
1012 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001013 struct video_device *vdev = video_devdata(file);
1014 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001015 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001016 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001017
1018 chan_cfg = &config->chan_config[ch->channel_id];
1019
Hans Verkuil7aaad132012-09-20 09:06:25 -03001020 if (index >= chan_cfg->input_count)
1021 return -EINVAL;
1022
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001023 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001024 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001025
Hans Verkuil178cce12012-09-20 09:06:30 -03001026 return vpif_set_input(config, ch, index);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001027}
1028
1029/**
1030 * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
1031 * @file: file ptr
1032 * @priv: file handle
1033 * @index: input index
1034 */
1035static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
1036 struct v4l2_fmtdesc *fmt)
1037{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001038 struct video_device *vdev = video_devdata(file);
1039 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001040
1041 if (fmt->index != 0) {
1042 vpif_dbg(1, debug, "Invalid format index\n");
1043 return -EINVAL;
1044 }
1045
1046 /* Fill in the information about format */
1047 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
1048 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1049 strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
1050 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
1051 } else {
1052 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1053 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
1054 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
1055 }
1056 return 0;
1057}
1058
1059/**
1060 * vpif_try_fmt_vid_cap() - TRY_FMT handler
1061 * @file: file ptr
1062 * @priv: file handle
1063 * @fmt: ptr to v4l2 format structure
1064 */
1065static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
1066 struct v4l2_format *fmt)
1067{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001068 struct video_device *vdev = video_devdata(file);
1069 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001070 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
1071
1072 return vpif_check_format(ch, pixfmt, 1);
1073}
1074
1075
1076/**
1077 * vpif_g_fmt_vid_cap() - Set INPUT handler
1078 * @file: file ptr
1079 * @priv: file handle
1080 * @fmt: ptr to v4l2 format structure
1081 */
1082static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
1083 struct v4l2_format *fmt)
1084{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001085 struct video_device *vdev = video_devdata(file);
1086 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001087 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1088
1089 /* Check the validity of the buffer type */
1090 if (common->fmt.type != fmt->type)
1091 return -EINVAL;
1092
1093 /* Fill in the information about format */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001094 *fmt = common->fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001095 return 0;
1096}
1097
1098/**
1099 * vpif_s_fmt_vid_cap() - Set FMT handler
1100 * @file: file ptr
1101 * @priv: file handle
1102 * @fmt: ptr to v4l2 format structure
1103 */
1104static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
1105 struct v4l2_format *fmt)
1106{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001107 struct video_device *vdev = video_devdata(file);
1108 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001109 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1110 struct v4l2_pix_format *pixfmt;
1111 int ret = 0;
1112
Mats Randgaard2c0ddd12010-12-16 12:17:45 -03001113 vpif_dbg(2, debug, "%s\n", __func__);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001114
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001115 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001116 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001117
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001118 pixfmt = &fmt->fmt.pix;
1119 /* Check for valid field format */
1120 ret = vpif_check_format(ch, pixfmt, 0);
1121
1122 if (ret)
1123 return ret;
1124 /* store the format in the channel object */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001125 common->fmt = *fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001126 return 0;
1127}
1128
1129/**
1130 * vpif_querycap() - QUERYCAP handler
1131 * @file: file ptr
1132 * @priv: file handle
1133 * @cap: ptr to v4l2_capability structure
1134 */
1135static int vpif_querycap(struct file *file, void *priv,
1136 struct v4l2_capability *cap)
1137{
1138 struct vpif_capture_config *config = vpif_dev->platform_data;
1139
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001140 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1141 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001142 strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001143 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1144 dev_name(vpif_dev));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001145 strlcpy(cap->card, config->card_name, sizeof(cap->card));
1146
1147 return 0;
1148}
1149
1150/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001151 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001152 * @file: file ptr
1153 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001154 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001155 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001156static int
1157vpif_enum_dv_timings(struct file *file, void *priv,
1158 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001159{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001160 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001161 struct video_device *vdev = video_devdata(file);
1162 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001163 struct vpif_capture_chan_config *chan_cfg;
1164 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001165 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001166
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001167 if (config->chan_config[ch->channel_id].inputs == NULL)
1168 return -ENODATA;
1169
1170 chan_cfg = &config->chan_config[ch->channel_id];
1171 input = chan_cfg->inputs[ch->input_idx].input;
1172 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1173 return -ENODATA;
1174
Laurent Pinchart10d21462014-01-31 09:04:19 -03001175 timings->pad = 0;
1176
1177 ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001178 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001179 return -EINVAL;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001180
Hans Verkuil178cce12012-09-20 09:06:30 -03001181 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001182}
1183
1184/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001185 * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001186 * @file: file ptr
1187 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001188 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001189 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001190static int
1191vpif_query_dv_timings(struct file *file, void *priv,
1192 struct v4l2_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001193{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001194 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001195 struct video_device *vdev = video_devdata(file);
1196 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001197 struct vpif_capture_chan_config *chan_cfg;
1198 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001199 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001200
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001201 if (config->chan_config[ch->channel_id].inputs == NULL)
1202 return -ENODATA;
1203
1204 chan_cfg = &config->chan_config[ch->channel_id];
1205 input = chan_cfg->inputs[ch->input_idx].input;
1206 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1207 return -ENODATA;
1208
Hans Verkuil178cce12012-09-20 09:06:30 -03001209 ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001210 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001211 return -ENODATA;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001212
Hans Verkuil178cce12012-09-20 09:06:30 -03001213 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001214}
1215
Mats Randgaardc027e162010-12-16 12:17:44 -03001216/**
1217 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1218 * @file: file ptr
1219 * @priv: file handle
1220 * @timings: digital video timings
1221 */
1222static int vpif_s_dv_timings(struct file *file, void *priv,
1223 struct v4l2_dv_timings *timings)
1224{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001225 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001226 struct video_device *vdev = video_devdata(file);
1227 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001228 struct vpif_params *vpifparams = &ch->vpifparams;
1229 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001230 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Mats Randgaardc027e162010-12-16 12:17:44 -03001231 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001232 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001233 struct vpif_capture_chan_config *chan_cfg;
1234 struct v4l2_input input;
Mats Randgaardc027e162010-12-16 12:17:44 -03001235 int ret;
1236
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001237 if (config->chan_config[ch->channel_id].inputs == NULL)
1238 return -ENODATA;
1239
1240 chan_cfg = &config->chan_config[ch->channel_id];
1241 input = chan_cfg->inputs[ch->input_idx].input;
1242 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1243 return -ENODATA;
1244
Mats Randgaardc027e162010-12-16 12:17:44 -03001245 if (timings->type != V4L2_DV_BT_656_1120) {
1246 vpif_dbg(2, debug, "Timing type not defined\n");
1247 return -EINVAL;
1248 }
1249
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001250 if (vb2_is_busy(&common->buffer_queue))
1251 return -EBUSY;
1252
Mats Randgaardc027e162010-12-16 12:17:44 -03001253 /* Configure subdevice timings, if any */
Hans Verkuil178cce12012-09-20 09:06:30 -03001254 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
1255 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1256 ret = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001257 if (ret < 0) {
1258 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1259 return ret;
1260 }
1261
1262 if (!(timings->bt.width && timings->bt.height &&
1263 (timings->bt.hbackporch ||
1264 timings->bt.hfrontporch ||
1265 timings->bt.hsync) &&
1266 timings->bt.vfrontporch &&
1267 (timings->bt.vbackporch ||
1268 timings->bt.vsync))) {
1269 vpif_dbg(2, debug, "Timings for width, height, "
1270 "horizontal back porch, horizontal sync, "
1271 "horizontal front porch, vertical back porch, "
1272 "vertical sync and vertical back porch "
1273 "must be defined\n");
1274 return -EINVAL;
1275 }
1276
Hans Verkuil0598c172012-09-18 07:18:47 -03001277 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001278
1279 /* Configure video port timings */
1280
Hans Verkuile3655262013-07-29 08:41:00 -03001281 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001282 std_info->sav2eav = bt->width;
1283
1284 std_info->l1 = 1;
1285 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1286
Hans Verkuile3655262013-07-29 08:41:00 -03001287 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001288 if (bt->interlaced) {
1289 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001290 std_info->l5 = std_info->vsize/2 -
1291 (bt->vfrontporch - 1);
1292 std_info->l7 = std_info->vsize/2 + 1;
1293 std_info->l9 = std_info->l7 + bt->il_vsync +
1294 bt->il_vbackporch + 1;
1295 std_info->l11 = std_info->vsize -
1296 (bt->il_vfrontporch - 1);
1297 } else {
1298 vpif_dbg(2, debug, "Required timing values for "
1299 "interlaced BT format missing\n");
1300 return -EINVAL;
1301 }
1302 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001303 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1304 }
1305 strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1306 std_info->width = bt->width;
1307 std_info->height = bt->height;
1308 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1309 std_info->ycmux_mode = 0;
1310 std_info->capture_format = 0;
1311 std_info->vbi_supported = 0;
1312 std_info->hd_sd = 1;
1313 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001314
1315 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001316 return 0;
1317}
1318
1319/**
1320 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1321 * @file: file ptr
1322 * @priv: file handle
1323 * @timings: digital video timings
1324 */
1325static int vpif_g_dv_timings(struct file *file, void *priv,
1326 struct v4l2_dv_timings *timings)
1327{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001328 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001329 struct video_device *vdev = video_devdata(file);
1330 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001331 struct video_obj *vid_ch = &ch->video;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001332 struct vpif_capture_chan_config *chan_cfg;
1333 struct v4l2_input input;
1334
1335 if (config->chan_config[ch->channel_id].inputs == NULL)
1336 return -ENODATA;
1337
1338 chan_cfg = &config->chan_config[ch->channel_id];
1339 input = chan_cfg->inputs[ch->input_idx].input;
1340 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1341 return -ENODATA;
Mats Randgaardc027e162010-12-16 12:17:44 -03001342
Hans Verkuil0598c172012-09-18 07:18:47 -03001343 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001344
1345 return 0;
1346}
1347
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001348/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001349 * vpif_log_status() - Status information
1350 * @file: file ptr
1351 * @priv: file handle
1352 *
1353 * Returns zero.
1354 */
1355static int vpif_log_status(struct file *filep, void *priv)
1356{
1357 /* status for sub devices */
1358 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1359
1360 return 0;
1361}
1362
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001363/* vpif capture ioctl operations */
1364static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001365 .vidioc_querycap = vpif_querycap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001366 .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001367 .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001368 .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
1369 .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001370
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001371 .vidioc_enum_input = vpif_enum_input,
1372 .vidioc_s_input = vpif_s_input,
1373 .vidioc_g_input = vpif_g_input,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001374
1375 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1376 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1377 .vidioc_querybuf = vb2_ioctl_querybuf,
1378 .vidioc_qbuf = vb2_ioctl_qbuf,
1379 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1380 .vidioc_expbuf = vb2_ioctl_expbuf,
1381 .vidioc_streamon = vb2_ioctl_streamon,
1382 .vidioc_streamoff = vb2_ioctl_streamoff,
1383
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001384 .vidioc_querystd = vpif_querystd,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001385 .vidioc_s_std = vpif_s_std,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001386 .vidioc_g_std = vpif_g_std,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001387
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001388 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1389 .vidioc_query_dv_timings = vpif_query_dv_timings,
1390 .vidioc_s_dv_timings = vpif_s_dv_timings,
1391 .vidioc_g_dv_timings = vpif_g_dv_timings,
1392
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001393 .vidioc_log_status = vpif_log_status,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001394};
1395
1396/* vpif file operations */
1397static struct v4l2_file_operations vpif_fops = {
1398 .owner = THIS_MODULE,
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001399 .open = v4l2_fh_open,
1400 .release = vb2_fop_release,
Hans Verkuil46656af2011-01-04 06:51:35 -03001401 .unlocked_ioctl = video_ioctl2,
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001402 .mmap = vb2_fop_mmap,
1403 .poll = vb2_fop_poll
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001404};
1405
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001406/**
1407 * initialize_vpif() - Initialize vpif data structures
1408 *
1409 * Allocate memory for data structures and initialize them
1410 */
1411static int initialize_vpif(void)
1412{
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001413 int err = 0, i, j;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001414 int free_channel_objects_index;
1415
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001416 /* Default number of buffers should be 3 */
1417 if ((ch0_numbuffers > 0) &&
1418 (ch0_numbuffers < config_params.min_numbuffers))
1419 ch0_numbuffers = config_params.min_numbuffers;
1420 if ((ch1_numbuffers > 0) &&
1421 (ch1_numbuffers < config_params.min_numbuffers))
1422 ch1_numbuffers = config_params.min_numbuffers;
1423
1424 /* Set buffer size to min buffers size if it is invalid */
1425 if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
1426 ch0_bufsize =
1427 config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
1428 if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
1429 ch1_bufsize =
1430 config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
1431
1432 config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
1433 config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
1434 if (ch0_numbuffers) {
1435 config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
1436 = ch0_bufsize;
1437 }
1438 if (ch1_numbuffers) {
1439 config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
1440 = ch1_bufsize;
1441 }
1442
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001443 /* Allocate memory for six channel objects */
1444 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1445 vpif_obj.dev[i] =
1446 kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
1447 /* If memory allocation fails, return error */
1448 if (!vpif_obj.dev[i]) {
1449 free_channel_objects_index = i;
1450 err = -ENOMEM;
1451 goto vpif_init_free_channel_objects;
1452 }
1453 }
1454 return 0;
1455
1456vpif_init_free_channel_objects:
1457 for (j = 0; j < free_channel_objects_index; j++)
1458 kfree(vpif_obj.dev[j]);
1459 return err;
1460}
1461
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001462static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1463 struct v4l2_subdev *subdev,
1464 struct v4l2_async_subdev *asd)
1465{
1466 int i;
1467
1468 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1469 if (!strcmp(vpif_obj.config->subdev_info[i].name,
1470 subdev->name)) {
1471 vpif_obj.sd[i] = subdev;
1472 return 0;
1473 }
1474
1475 return -EINVAL;
1476}
1477
1478static int vpif_probe_complete(void)
1479{
1480 struct common_obj *common;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001481 struct video_device *vdev;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001482 struct channel_obj *ch;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001483 struct vb2_queue *q;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001484 int i, j, err, k;
1485
1486 for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
1487 ch = vpif_obj.dev[j];
1488 ch->channel_id = j;
1489 common = &(ch->common[VPIF_VIDEO_INDEX]);
1490 spin_lock_init(&common->irqlock);
1491 mutex_init(&common->lock);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001492
1493 /* select input 0 */
1494 err = vpif_set_input(vpif_obj.config, ch, 0);
1495 if (err)
1496 goto probe_out;
1497
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001498 /* Initialize vb2 queue */
1499 q = &common->buffer_queue;
1500 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1501 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1502 q->drv_priv = ch;
1503 q->ops = &video_qops;
1504 q->mem_ops = &vb2_dma_contig_memops;
1505 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1506 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1507 q->min_buffers_needed = 1;
Lad, Prabhakar999ba692014-05-16 10:33:33 -03001508 q->lock = &common->lock;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001509
1510 err = vb2_queue_init(q);
1511 if (err) {
1512 vpif_err("vpif_capture: vb2_queue_init() failed\n");
1513 goto probe_out;
1514 }
1515
1516 common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
1517 if (IS_ERR(common->alloc_ctx)) {
1518 vpif_err("Failed to get the context\n");
1519 err = PTR_ERR(common->alloc_ctx);
1520 goto probe_out;
1521 }
1522
1523 INIT_LIST_HEAD(&common->dma_queue);
1524
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001525 /* Initialize the video_device structure */
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001526 vdev = ch->video_dev;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001527 strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
1528 vdev->release = video_device_release;
1529 vdev->fops = &vpif_fops;
1530 vdev->ioctl_ops = &vpif_ioctl_ops;
1531 vdev->v4l2_dev = &vpif_obj.v4l2_dev;
1532 vdev->vfl_dir = VFL_DIR_RX;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001533 vdev->queue = q;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001534 vdev->lock = &common->lock;
1535 set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1536 video_set_drvdata(ch->video_dev, ch);
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001537 err = video_register_device(vdev,
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001538 VFL_TYPE_GRABBER, (j ? 1 : 0));
1539 if (err)
1540 goto probe_out;
1541 }
1542
1543 v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
1544 return 0;
1545
1546probe_out:
1547 for (k = 0; k < j; k++) {
1548 /* Get the pointer to the channel object */
1549 ch = vpif_obj.dev[k];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001550 common = &ch->common[k];
1551 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001552 /* Unregister video device */
1553 video_unregister_device(ch->video_dev);
1554 }
1555 kfree(vpif_obj.sd);
1556 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1557 ch = vpif_obj.dev[i];
1558 /* Note: does nothing if ch->video_dev == NULL */
1559 video_device_release(ch->video_dev);
1560 }
1561 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1562
1563 return err;
1564}
1565
1566static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1567{
1568 return vpif_probe_complete();
1569}
1570
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001571/**
1572 * vpif_probe : This function probes the vpif capture driver
1573 * @pdev: platform device pointer
1574 *
1575 * This creates device entries by register itself to the V4L2 driver and
1576 * initializes fields of each channel objects
1577 */
1578static __init int vpif_probe(struct platform_device *pdev)
1579{
1580 struct vpif_subdev_info *subdevdata;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001581 int i, j, err;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001582 int res_idx = 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001583 struct i2c_adapter *i2c_adap;
1584 struct channel_obj *ch;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001585 struct video_device *vfd;
1586 struct resource *res;
1587 int subdev_count;
1588
1589 vpif_dev = &pdev->dev;
1590
1591 err = initialize_vpif();
1592 if (err) {
1593 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1594 return err;
1595 }
1596
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001597 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1598 if (err) {
1599 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1600 return err;
1601 }
1602
Hans Verkuil5be452c2012-09-20 09:06:29 -03001603 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001604 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001605 IRQF_SHARED, VPIF_DRIVER_NAME,
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001606 (void *)(&vpif_obj.dev[res_idx]->
1607 channel_id));
1608 if (err) {
1609 err = -EINVAL;
1610 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001611 }
Hans Verkuil5be452c2012-09-20 09:06:29 -03001612 res_idx++;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001613 }
1614
1615 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1616 /* Get the pointer to the channel object */
1617 ch = vpif_obj.dev[i];
1618 /* Allocate memory for video device */
1619 vfd = video_device_alloc();
1620 if (NULL == vfd) {
1621 for (j = 0; j < i; j++) {
1622 ch = vpif_obj.dev[j];
1623 video_device_release(ch->video_dev);
1624 }
1625 err = -ENOMEM;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001626 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001627 }
1628
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001629 /* Set video_dev to the video device */
1630 ch->video_dev = vfd;
1631 }
1632
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001633 vpif_obj.config = pdev->dev.platform_data;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001634
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001635 subdev_count = vpif_obj.config->subdev_count;
Mats Randgaard1f8766b2010-08-30 10:30:37 -03001636 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001637 GFP_KERNEL);
1638 if (vpif_obj.sd == NULL) {
1639 vpif_err("unable to allocate memory for subdevice pointers\n");
1640 err = -ENOMEM;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001641 goto vpif_sd_error;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001642 }
1643
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001644 if (!vpif_obj.config->asd_sizes) {
1645 i2c_adap = i2c_get_adapter(1);
1646 for (i = 0; i < subdev_count; i++) {
1647 subdevdata = &vpif_obj.config->subdev_info[i];
1648 vpif_obj.sd[i] =
1649 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1650 i2c_adap,
1651 &subdevdata->
1652 board_info,
1653 NULL);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001654
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001655 if (!vpif_obj.sd[i]) {
1656 vpif_err("Error registering v4l2 subdevice\n");
Wei Yongjun2fcd9dc2013-09-02 05:06:10 -03001657 err = -ENODEV;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001658 goto probe_subdev_out;
1659 }
1660 v4l2_info(&vpif_obj.v4l2_dev,
1661 "registered sub device %s\n",
1662 subdevdata->name);
1663 }
1664 vpif_probe_complete();
1665 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001666 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001667 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1668 vpif_obj.notifier.bound = vpif_async_bound;
1669 vpif_obj.notifier.complete = vpif_async_complete;
1670 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1671 &vpif_obj.notifier);
1672 if (err) {
1673 vpif_err("Error registering async notifier\n");
1674 err = -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001675 goto probe_subdev_out;
1676 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001677 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001678
1679 return 0;
1680
Hans Verkuilb65814e2012-09-20 09:06:26 -03001681probe_subdev_out:
1682 /* free sub devices memory */
1683 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001684
Hans Verkuil5be452c2012-09-20 09:06:29 -03001685vpif_sd_error:
1686 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1687 ch = vpif_obj.dev[i];
1688 /* Note: does nothing if ch->video_dev == NULL */
1689 video_device_release(ch->video_dev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001690 }
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001691vpif_unregister:
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001692 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001693
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001694 return err;
1695}
1696
1697/**
1698 * vpif_remove() - driver remove handler
1699 * @device: ptr to platform device structure
1700 *
1701 * The vidoe device is unregistered
1702 */
1703static int vpif_remove(struct platform_device *device)
1704{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001705 struct common_obj *common;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001706 struct channel_obj *ch;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001707 int i;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001708
1709 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1710
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001711 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001712 /* un-register device */
1713 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1714 /* Get the pointer to the channel object */
1715 ch = vpif_obj.dev[i];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001716 common = &ch->common[i];
1717 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001718 /* Unregister video device */
1719 video_unregister_device(ch->video_dev);
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001720 kfree(vpif_obj.dev[i]);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001721 }
1722 return 0;
1723}
1724
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001725#ifdef CONFIG_PM_SLEEP
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001726/**
1727 * vpif_suspend: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001728 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001729static int vpif_suspend(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001730{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001731
1732 struct common_obj *common;
1733 struct channel_obj *ch;
1734 int i;
1735
1736 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1737 /* Get the pointer to the channel object */
1738 ch = vpif_obj.dev[i];
1739 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001740
1741 if (!vb2_is_streaming(&common->buffer_queue))
1742 continue;
1743
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001744 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001745 /* Disable channel */
1746 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1747 enable_channel0(0);
1748 channel0_intr_enable(0);
1749 }
1750 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1751 ycmux_mode == 2) {
1752 enable_channel1(0);
1753 channel1_intr_enable(0);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001754 }
1755 mutex_unlock(&common->lock);
1756 }
1757
1758 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001759}
1760
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001761/*
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001762 * vpif_resume: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001763 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001764static int vpif_resume(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001765{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001766 struct common_obj *common;
1767 struct channel_obj *ch;
1768 int i;
1769
1770 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1771 /* Get the pointer to the channel object */
1772 ch = vpif_obj.dev[i];
1773 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001774
1775 if (!vb2_is_streaming(&common->buffer_queue))
1776 continue;
1777
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001778 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001779 /* Enable channel */
1780 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1781 enable_channel0(1);
1782 channel0_intr_enable(1);
1783 }
1784 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1785 ycmux_mode == 2) {
1786 enable_channel1(1);
1787 channel1_intr_enable(1);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001788 }
1789 mutex_unlock(&common->lock);
1790 }
1791
1792 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001793}
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001794#endif
1795
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001796static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
1797
Mats Randgaardffa1b392010-08-30 10:30:36 -03001798static __refdata struct platform_driver vpif_driver = {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001799 .driver = {
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001800 .name = VPIF_DRIVER_NAME,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001801 .owner = THIS_MODULE,
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001802 .pm = &vpif_pm_ops,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001803 },
1804 .probe = vpif_probe,
1805 .remove = vpif_remove,
1806};
1807
Lad, Prabhakarfe424b22013-06-17 11:20:45 -03001808module_platform_driver(vpif_driver);