blob: 1e4ec697fb1054c69becb4f4483f228508c2efe7 [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 }
Dan Carpenter92491962014-06-12 04:01:45 -0300272 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300273
274 return ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300275}
276
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300277/**
278 * vpif_stop_streaming : Stop the DMA engine
279 * @vq: ptr to vb2_queue
280 *
281 * This callback stops the DMA engine and any remaining buffers
282 * in the DMA queue are released.
283 */
Hans Verkuile37559b2014-04-17 02:47:21 -0300284static void vpif_stop_streaming(struct vb2_queue *vq)
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300285{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300286 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300287 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300288 unsigned long flags;
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300289 int ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300290
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300291 common = &ch->common[VPIF_VIDEO_INDEX];
292
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300293 /* Disable channel as per its device type and channel id */
294 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
295 enable_channel0(0);
296 channel0_intr_enable(0);
297 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300298 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300299 ycmux_mode == 2) {
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300300 enable_channel1(0);
301 channel1_intr_enable(0);
302 }
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300303
304 ycmux_mode = 0;
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300305
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300306 ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
307 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
308 vpif_dbg(1, debug, "stream off failed in subdev\n");
309
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300310 /* release all active buffers */
Hans Verkuilaec96832012-11-16 12:03:06 -0300311 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300312 if (common->cur_frm == common->next_frm) {
313 vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
314 } else {
315 if (common->cur_frm != NULL)
316 vb2_buffer_done(&common->cur_frm->vb,
317 VB2_BUF_STATE_ERROR);
318 if (common->next_frm != NULL)
319 vb2_buffer_done(&common->next_frm->vb,
320 VB2_BUF_STATE_ERROR);
321 }
322
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300323 while (!list_empty(&common->dma_queue)) {
324 common->next_frm = list_entry(common->dma_queue.next,
325 struct vpif_cap_buffer, list);
326 list_del(&common->next_frm->list);
327 vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
328 }
Hans Verkuilaec96832012-11-16 12:03:06 -0300329 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300330}
331
332static struct vb2_ops video_qops = {
333 .queue_setup = vpif_buffer_queue_setup,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300334 .buf_prepare = vpif_buffer_prepare,
335 .start_streaming = vpif_start_streaming,
336 .stop_streaming = vpif_stop_streaming,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300337 .buf_queue = vpif_buffer_queue,
338};
339
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300340/**
341 * vpif_process_buffer_complete: process a completed buffer
342 * @common: ptr to common channel object
343 *
344 * This function time stamp the buffer and mark it as DONE. It also
345 * wake up any process waiting on the QUEUE and set the next buffer
346 * as current
347 */
348static void vpif_process_buffer_complete(struct common_obj *common)
349{
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300350 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300351 vb2_buffer_done(&common->cur_frm->vb,
352 VB2_BUF_STATE_DONE);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300353 /* Make curFrm pointing to nextFrm */
354 common->cur_frm = common->next_frm;
355}
356
357/**
358 * vpif_schedule_next_buffer: set next buffer address for capture
359 * @common : ptr to common channel object
360 *
361 * This function will get next buffer from the dma queue and
362 * set the buffer address in the vpif register for capture.
363 * the buffer is marked active
364 */
365static void vpif_schedule_next_buffer(struct common_obj *common)
366{
367 unsigned long addr = 0;
368
Hans Verkuilaec96832012-11-16 12:03:06 -0300369 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300370 common->next_frm = list_entry(common->dma_queue.next,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300371 struct vpif_cap_buffer, list);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300372 /* Remove that buffer from the buffer queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300373 list_del(&common->next_frm->list);
Hans Verkuilaec96832012-11-16 12:03:06 -0300374 spin_unlock(&common->irqlock);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300375 common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
376 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300377
378 /* Set top and bottom field addresses in VPIF registers */
379 common->set_addr(addr + common->ytop_off,
380 addr + common->ybtm_off,
381 addr + common->ctop_off,
382 addr + common->cbtm_off);
383}
384
385/**
386 * vpif_channel_isr : ISR handler for vpif capture
387 * @irq: irq number
388 * @dev_id: dev_id ptr
389 *
390 * It changes status of the captured buffer, takes next buffer from the queue
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300391 * and sets its address in VPIF registers
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300392 */
393static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
394{
395 struct vpif_device *dev = &vpif_obj;
396 struct common_obj *common;
397 struct channel_obj *ch;
398 enum v4l2_field field;
399 int channel_id = 0;
400 int fid = -1, i;
401
402 channel_id = *(int *)(dev_id);
Manjunath Hadlib1fc4232012-04-13 04:43:10 -0300403 if (!vpif_intr_status(channel_id))
404 return IRQ_NONE;
405
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300406 ch = dev->dev[channel_id];
407
408 field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
409
410 for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
411 common = &ch->common[i];
412 /* skip If streaming is not started in this channel */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300413 /* Check the field format */
414 if (1 == ch->vpifparams.std_info.frm_fmt) {
415 /* Progressive mode */
Hans Verkuilaec96832012-11-16 12:03:06 -0300416 spin_lock(&common->irqlock);
417 if (list_empty(&common->dma_queue)) {
418 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300419 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300420 }
421 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300422
423 if (!channel_first_int[i][channel_id])
424 vpif_process_buffer_complete(common);
425
426 channel_first_int[i][channel_id] = 0;
427
428 vpif_schedule_next_buffer(common);
429
430
431 channel_first_int[i][channel_id] = 0;
432 } else {
433 /**
434 * Interlaced mode. If it is first interrupt, ignore
435 * it
436 */
437 if (channel_first_int[i][channel_id]) {
438 channel_first_int[i][channel_id] = 0;
439 continue;
440 }
441 if (0 == i) {
442 ch->field_id ^= 1;
443 /* Get field id from VPIF registers */
444 fid = vpif_channel_getfid(ch->channel_id);
445 if (fid != ch->field_id) {
446 /**
447 * If field id does not match stored
448 * field id, make them in sync
449 */
450 if (0 == fid)
451 ch->field_id = fid;
452 return IRQ_HANDLED;
453 }
454 }
455 /* device field id and local field id are in sync */
456 if (0 == fid) {
457 /* this is even field */
458 if (common->cur_frm == common->next_frm)
459 continue;
460
461 /* mark the current buffer as done */
462 vpif_process_buffer_complete(common);
463 } else if (1 == fid) {
464 /* odd field */
Hans Verkuilaec96832012-11-16 12:03:06 -0300465 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300466 if (list_empty(&common->dma_queue) ||
Hans Verkuilaec96832012-11-16 12:03:06 -0300467 (common->cur_frm != common->next_frm)) {
468 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300469 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300470 }
471 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300472
473 vpif_schedule_next_buffer(common);
474 }
475 }
476 }
477 return IRQ_HANDLED;
478}
479
480/**
481 * vpif_update_std_info() - update standard related info
482 * @ch: ptr to channel object
483 *
484 * For a given standard selected by application, update values
485 * in the device data structures
486 */
487static int vpif_update_std_info(struct channel_obj *ch)
488{
489 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
490 struct vpif_params *vpifparams = &ch->vpifparams;
491 const struct vpif_channel_config_params *config;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300492 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300493 struct video_obj *vid_ch = &ch->video;
494 int index;
495
496 vpif_dbg(2, debug, "vpif_update_std_info\n");
497
Mats Randgaardaa444402010-12-16 12:17:42 -0300498 for (index = 0; index < vpif_ch_params_count; index++) {
Lad, Prabhakarced9b212013-03-20 01:28:27 -0300499 config = &vpif_ch_params[index];
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300500 if (config->hd_sd == 0) {
501 vpif_dbg(2, debug, "SD format\n");
502 if (config->stdid & vid_ch->stdid) {
503 memcpy(std_info, config, sizeof(*config));
504 break;
505 }
506 } else {
507 vpif_dbg(2, debug, "HD format\n");
Hans Verkuil0598c172012-09-18 07:18:47 -0300508 if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
509 sizeof(vid_ch->dv_timings))) {
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300510 memcpy(std_info, config, sizeof(*config));
511 break;
512 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300513 }
514 }
515
516 /* standard not found */
Mats Randgaardaa444402010-12-16 12:17:42 -0300517 if (index == vpif_ch_params_count)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300518 return -EINVAL;
519
520 common->fmt.fmt.pix.width = std_info->width;
521 common->width = std_info->width;
522 common->fmt.fmt.pix.height = std_info->height;
523 common->height = std_info->height;
524 common->fmt.fmt.pix.bytesperline = std_info->width;
525 vpifparams->video_params.hpitch = std_info->width;
526 vpifparams->video_params.storage_mode = std_info->frm_fmt;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300527
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300528 return 0;
529}
530
531/**
532 * vpif_calculate_offsets : This function calculates buffers offsets
533 * @ch : ptr to channel object
534 *
535 * This function calculates buffer offsets for Y and C in the top and
536 * bottom field
537 */
538static void vpif_calculate_offsets(struct channel_obj *ch)
539{
540 unsigned int hpitch, vpitch, sizeimage;
541 struct video_obj *vid_ch = &(ch->video);
542 struct vpif_params *vpifparams = &ch->vpifparams;
543 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
544 enum v4l2_field field = common->fmt.fmt.pix.field;
545
546 vpif_dbg(2, debug, "vpif_calculate_offsets\n");
547
548 if (V4L2_FIELD_ANY == field) {
549 if (vpifparams->std_info.frm_fmt)
550 vid_ch->buf_field = V4L2_FIELD_NONE;
551 else
552 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
553 } else
554 vid_ch->buf_field = common->fmt.fmt.pix.field;
555
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300556 sizeimage = common->fmt.fmt.pix.sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300557
558 hpitch = common->fmt.fmt.pix.bytesperline;
559 vpitch = sizeimage / (hpitch * 2);
560
561 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
562 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
563 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
564 common->ytop_off = 0;
565 common->ybtm_off = hpitch;
566 common->ctop_off = sizeimage / 2;
567 common->cbtm_off = sizeimage / 2 + hpitch;
568 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
569 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
570 common->ytop_off = 0;
571 common->ybtm_off = sizeimage / 4;
572 common->ctop_off = sizeimage / 2;
573 common->cbtm_off = common->ctop_off + sizeimage / 4;
574 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
575 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
576 common->ybtm_off = 0;
577 common->ytop_off = sizeimage / 4;
578 common->cbtm_off = sizeimage / 2;
579 common->ctop_off = common->cbtm_off + sizeimage / 4;
580 }
581 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
582 (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
583 vpifparams->video_params.storage_mode = 1;
584 else
585 vpifparams->video_params.storage_mode = 0;
586
587 if (1 == vpifparams->std_info.frm_fmt)
588 vpifparams->video_params.hpitch =
589 common->fmt.fmt.pix.bytesperline;
590 else {
591 if ((field == V4L2_FIELD_ANY)
592 || (field == V4L2_FIELD_INTERLACED))
593 vpifparams->video_params.hpitch =
594 common->fmt.fmt.pix.bytesperline * 2;
595 else
596 vpifparams->video_params.hpitch =
597 common->fmt.fmt.pix.bytesperline;
598 }
599
600 ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
601}
602
603/**
604 * vpif_config_format: configure default frame format in the device
605 * ch : ptr to channel object
606 */
607static void vpif_config_format(struct channel_obj *ch)
608{
609 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
610
611 vpif_dbg(2, debug, "vpif_config_format\n");
612
613 common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -0300614 common->fmt.fmt.pix.sizeimage
615 = config_params.channel_bufsize[ch->channel_id];
616
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300617 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
618 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
619 else
620 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
621 common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
622}
623
624/**
625 * vpif_get_default_field() - Get default field type based on interface
626 * @vpif_params - ptr to vpif params
627 */
628static inline enum v4l2_field vpif_get_default_field(
629 struct vpif_interface *iface)
630{
631 return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
632 V4L2_FIELD_INTERLACED;
633}
634
635/**
636 * vpif_check_format() - check given pixel format for compatibility
637 * @ch - channel ptr
638 * @pixfmt - Given pixel format
639 * @update - update the values as per hardware requirement
640 *
641 * Check the application pixel format for S_FMT and update the input
642 * values as per hardware limits for TRY_FMT. The default pixel and
643 * field format is selected based on interface type.
644 */
645static int vpif_check_format(struct channel_obj *ch,
646 struct v4l2_pix_format *pixfmt,
647 int update)
648{
649 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
650 struct vpif_params *vpif_params = &ch->vpifparams;
651 enum v4l2_field field = pixfmt->field;
652 u32 sizeimage, hpitch, vpitch;
653 int ret = -EINVAL;
654
655 vpif_dbg(2, debug, "vpif_check_format\n");
656 /**
657 * first check for the pixel format. If if_type is Raw bayer,
658 * only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only
659 * V4L2_PIX_FMT_YUV422P is supported
660 */
661 if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
662 if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) {
663 if (!update) {
664 vpif_dbg(2, debug, "invalid pix format\n");
665 goto exit;
666 }
667 pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
668 }
669 } else {
670 if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) {
671 if (!update) {
672 vpif_dbg(2, debug, "invalid pixel format\n");
673 goto exit;
674 }
675 pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
676 }
677 }
678
679 if (!(VPIF_VALID_FIELD(field))) {
680 if (!update) {
681 vpif_dbg(2, debug, "invalid field format\n");
682 goto exit;
683 }
684 /**
685 * By default use FIELD_NONE for RAW Bayer capture
686 * and FIELD_INTERLACED for other interfaces
687 */
688 field = vpif_get_default_field(&vpif_params->iface);
689 } else if (field == V4L2_FIELD_ANY)
690 /* unsupported field. Use default */
691 field = vpif_get_default_field(&vpif_params->iface);
692
693 /* validate the hpitch */
694 hpitch = pixfmt->bytesperline;
695 if (hpitch < vpif_params->std_info.width) {
696 if (!update) {
697 vpif_dbg(2, debug, "invalid hpitch\n");
698 goto exit;
699 }
700 hpitch = vpif_params->std_info.width;
701 }
702
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300703 sizeimage = pixfmt->sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300704
705 vpitch = sizeimage / (hpitch * 2);
706
707 /* validate the vpitch */
708 if (vpitch < vpif_params->std_info.height) {
709 if (!update) {
710 vpif_dbg(2, debug, "Invalid vpitch\n");
711 goto exit;
712 }
713 vpitch = vpif_params->std_info.height;
714 }
715
716 /* Check for 8 byte alignment */
717 if (!ALIGN(hpitch, 8)) {
718 if (!update) {
719 vpif_dbg(2, debug, "invalid pitch alignment\n");
720 goto exit;
721 }
722 /* adjust to next 8 byte boundary */
723 hpitch = (((hpitch + 7) / 8) * 8);
724 }
725 /* if update is set, modify the bytesperline and sizeimage */
726 if (update) {
727 pixfmt->bytesperline = hpitch;
728 pixfmt->sizeimage = hpitch * vpitch * 2;
729 }
730 /**
731 * Image width and height is always based on current standard width and
732 * height
733 */
734 pixfmt->width = common->fmt.fmt.pix.width;
735 pixfmt->height = common->fmt.fmt.pix.height;
736 return 0;
737exit:
738 return ret;
739}
740
741/**
742 * vpif_config_addr() - function to configure buffer address in vpif
743 * @ch - channel ptr
744 * @muxmode - channel mux mode
745 */
746static void vpif_config_addr(struct channel_obj *ch, int muxmode)
747{
748 struct common_obj *common;
749
750 vpif_dbg(2, debug, "vpif_config_addr\n");
751
752 common = &(ch->common[VPIF_VIDEO_INDEX]);
753
754 if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
755 common->set_addr = ch1_set_videobuf_addr;
756 else if (2 == muxmode)
757 common->set_addr = ch0_set_videobuf_addr_yc_nmux;
758 else
759 common->set_addr = ch0_set_videobuf_addr;
760}
761
762/**
Hans Verkuil178cce12012-09-20 09:06:30 -0300763 * vpif_input_to_subdev() - Maps input to sub device
764 * @vpif_cfg - global config ptr
765 * @chan_cfg - channel config ptr
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300766 * @input_index - Given input index from application
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300767 *
768 * lookup the sub device information for a given input index.
769 * we report all the inputs to application. inputs table also
770 * has sub device name for the each input
771 */
Hans Verkuil178cce12012-09-20 09:06:30 -0300772static int vpif_input_to_subdev(
773 struct vpif_capture_config *vpif_cfg,
774 struct vpif_capture_chan_config *chan_cfg,
775 int input_index)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300776{
Hans Verkuil178cce12012-09-20 09:06:30 -0300777 struct vpif_subdev_info *subdev_info;
778 const char *subdev_name;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300779 int i;
780
Hans Verkuil178cce12012-09-20 09:06:30 -0300781 vpif_dbg(2, debug, "vpif_input_to_subdev\n");
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300782
Hans Verkuil178cce12012-09-20 09:06:30 -0300783 subdev_name = chan_cfg->inputs[input_index].subdev_name;
784 if (subdev_name == NULL)
785 return -1;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300786
787 /* loop through the sub device list to get the sub device info */
788 for (i = 0; i < vpif_cfg->subdev_count; i++) {
789 subdev_info = &vpif_cfg->subdev_info[i];
790 if (!strcmp(subdev_info->name, subdev_name))
Hans Verkuil178cce12012-09-20 09:06:30 -0300791 return i;
792 }
793 return -1;
794}
795
796/**
797 * vpif_set_input() - Select an input
798 * @vpif_cfg - global config ptr
799 * @ch - channel
800 * @_index - Given input index from application
801 *
802 * Select the given input.
803 */
804static int vpif_set_input(
805 struct vpif_capture_config *vpif_cfg,
806 struct channel_obj *ch,
807 int index)
808{
809 struct vpif_capture_chan_config *chan_cfg =
810 &vpif_cfg->chan_config[ch->channel_id];
811 struct vpif_subdev_info *subdev_info = NULL;
812 struct v4l2_subdev *sd = NULL;
813 u32 input = 0, output = 0;
814 int sd_index;
815 int ret;
816
817 sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
818 if (sd_index >= 0) {
819 sd = vpif_obj.sd[sd_index];
820 subdev_info = &vpif_cfg->subdev_info[sd_index];
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300821 }
822
Hans Verkuil178cce12012-09-20 09:06:30 -0300823 /* first setup input path from sub device to vpif */
824 if (sd && vpif_cfg->setup_input_path) {
825 ret = vpif_cfg->setup_input_path(ch->channel_id,
826 subdev_info->name);
827 if (ret < 0) {
828 vpif_dbg(1, debug, "couldn't setup input path for the" \
829 " sub device %s, for input index %d\n",
830 subdev_info->name, index);
831 return ret;
832 }
833 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300834
Hans Verkuil178cce12012-09-20 09:06:30 -0300835 if (sd) {
836 input = chan_cfg->inputs[index].input_route;
837 output = chan_cfg->inputs[index].output_route;
838 ret = v4l2_subdev_call(sd, video, s_routing,
839 input, output, 0);
840 if (ret < 0 && ret != -ENOIOCTLCMD) {
841 vpif_dbg(1, debug, "Failed to set input\n");
842 return ret;
843 }
844 }
845 ch->input_idx = index;
846 ch->sd = sd;
847 /* copy interface parameters to vpif */
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300848 ch->vpifparams.iface = chan_cfg->vpif_if;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300849
Hans Verkuil178cce12012-09-20 09:06:30 -0300850 /* update tvnorms from the sub device input info */
851 ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
852 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300853}
854
855/**
856 * vpif_querystd() - querystd handler
857 * @file: file ptr
858 * @priv: file handle
859 * @std_id: ptr to std id
860 *
861 * This function is called to detect standard at the selected input
862 */
863static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
864{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300865 struct video_device *vdev = video_devdata(file);
866 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300867 int ret = 0;
868
869 vpif_dbg(2, debug, "vpif_querystd\n");
870
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300871 /* Call querystd function of decoder device */
Hans Verkuil178cce12012-09-20 09:06:30 -0300872 ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300873
Hans Verkuil178cce12012-09-20 09:06:30 -0300874 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
875 return -ENODATA;
876 if (ret) {
877 vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
878 return ret;
879 }
880
881 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300882}
883
884/**
885 * vpif_g_std() - get STD handler
886 * @file: file ptr
887 * @priv: file handle
888 * @std_id: ptr to std id
889 */
890static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
891{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300892 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300893 struct video_device *vdev = video_devdata(file);
894 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300895 struct vpif_capture_chan_config *chan_cfg;
896 struct v4l2_input input;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300897
898 vpif_dbg(2, debug, "vpif_g_std\n");
899
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300900 if (config->chan_config[ch->channel_id].inputs == NULL)
901 return -ENODATA;
902
903 chan_cfg = &config->chan_config[ch->channel_id];
904 input = chan_cfg->inputs[ch->input_idx].input;
905 if (input.capabilities != V4L2_IN_CAP_STD)
906 return -ENODATA;
907
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300908 *std = ch->video.stdid;
909 return 0;
910}
911
912/**
913 * vpif_s_std() - set STD handler
914 * @file: file ptr
915 * @priv: file handle
916 * @std_id: ptr to std id
917 */
Hans Verkuil314527a2013-03-15 06:10:40 -0300918static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300919{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300920 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300921 struct video_device *vdev = video_devdata(file);
922 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300923 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300924 struct vpif_capture_chan_config *chan_cfg;
925 struct v4l2_input input;
926 int ret;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300927
928 vpif_dbg(2, debug, "vpif_s_std\n");
929
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300930 if (config->chan_config[ch->channel_id].inputs == NULL)
931 return -ENODATA;
932
933 chan_cfg = &config->chan_config[ch->channel_id];
934 input = chan_cfg->inputs[ch->input_idx].input;
935 if (input.capabilities != V4L2_IN_CAP_STD)
936 return -ENODATA;
937
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300938 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300939 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300940
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300941 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -0300942 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -0300943 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300944
945 /* Get the information about the standard */
946 if (vpif_update_std_info(ch)) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300947 vpif_err("Error getting the standard info\n");
Hans Verkuil46656af2011-01-04 06:51:35 -0300948 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300949 }
950
951 /* Configure the default format information */
952 vpif_config_format(ch);
953
954 /* set standard in the sub device */
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300955 ret = v4l2_subdev_call(ch->sd, video, s_std, std_id);
Hans Verkuil178cce12012-09-20 09:06:30 -0300956 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300957 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
Hans Verkuil178cce12012-09-20 09:06:30 -0300958 return ret;
959 }
960 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300961}
962
963/**
964 * vpif_enum_input() - ENUMINPUT handler
965 * @file: file ptr
966 * @priv: file handle
967 * @input: ptr to input structure
968 */
969static int vpif_enum_input(struct file *file, void *priv,
970 struct v4l2_input *input)
971{
972
973 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300974 struct video_device *vdev = video_devdata(file);
975 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300976 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300977
978 chan_cfg = &config->chan_config[ch->channel_id];
979
980 if (input->index >= chan_cfg->input_count) {
981 vpif_dbg(1, debug, "Invalid input index\n");
982 return -EINVAL;
983 }
984
985 memcpy(input, &chan_cfg->inputs[input->index].input,
986 sizeof(*input));
987 return 0;
988}
989
990/**
991 * vpif_g_input() - Get INPUT handler
992 * @file: file ptr
993 * @priv: file handle
994 * @index: ptr to input index
995 */
996static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
997{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300998 struct video_device *vdev = video_devdata(file);
999 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001000
Hans Verkuil6f47c6c2012-09-20 09:06:22 -03001001 *index = ch->input_idx;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001002 return 0;
1003}
1004
1005/**
1006 * vpif_s_input() - Set INPUT handler
1007 * @file: file ptr
1008 * @priv: file handle
1009 * @index: input index
1010 */
1011static int vpif_s_input(struct file *file, void *priv, unsigned int index)
1012{
1013 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001014 struct video_device *vdev = video_devdata(file);
1015 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001016 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001017 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001018
1019 chan_cfg = &config->chan_config[ch->channel_id];
1020
Hans Verkuil7aaad132012-09-20 09:06:25 -03001021 if (index >= chan_cfg->input_count)
1022 return -EINVAL;
1023
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001024 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001025 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001026
Hans Verkuil178cce12012-09-20 09:06:30 -03001027 return vpif_set_input(config, ch, index);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001028}
1029
1030/**
1031 * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
1032 * @file: file ptr
1033 * @priv: file handle
1034 * @index: input index
1035 */
1036static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
1037 struct v4l2_fmtdesc *fmt)
1038{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001039 struct video_device *vdev = video_devdata(file);
1040 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001041
1042 if (fmt->index != 0) {
1043 vpif_dbg(1, debug, "Invalid format index\n");
1044 return -EINVAL;
1045 }
1046
1047 /* Fill in the information about format */
1048 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
1049 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1050 strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
1051 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
1052 } else {
1053 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1054 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
1055 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
1056 }
1057 return 0;
1058}
1059
1060/**
1061 * vpif_try_fmt_vid_cap() - TRY_FMT handler
1062 * @file: file ptr
1063 * @priv: file handle
1064 * @fmt: ptr to v4l2 format structure
1065 */
1066static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
1067 struct v4l2_format *fmt)
1068{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001069 struct video_device *vdev = video_devdata(file);
1070 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001071 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
1072
1073 return vpif_check_format(ch, pixfmt, 1);
1074}
1075
1076
1077/**
1078 * vpif_g_fmt_vid_cap() - Set INPUT handler
1079 * @file: file ptr
1080 * @priv: file handle
1081 * @fmt: ptr to v4l2 format structure
1082 */
1083static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
1084 struct v4l2_format *fmt)
1085{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001086 struct video_device *vdev = video_devdata(file);
1087 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001088 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1089
1090 /* Check the validity of the buffer type */
1091 if (common->fmt.type != fmt->type)
1092 return -EINVAL;
1093
1094 /* Fill in the information about format */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001095 *fmt = common->fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001096 return 0;
1097}
1098
1099/**
1100 * vpif_s_fmt_vid_cap() - Set FMT handler
1101 * @file: file ptr
1102 * @priv: file handle
1103 * @fmt: ptr to v4l2 format structure
1104 */
1105static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
1106 struct v4l2_format *fmt)
1107{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001108 struct video_device *vdev = video_devdata(file);
1109 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001110 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1111 struct v4l2_pix_format *pixfmt;
1112 int ret = 0;
1113
Mats Randgaard2c0ddd12010-12-16 12:17:45 -03001114 vpif_dbg(2, debug, "%s\n", __func__);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001115
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001116 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001117 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001118
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001119 pixfmt = &fmt->fmt.pix;
1120 /* Check for valid field format */
1121 ret = vpif_check_format(ch, pixfmt, 0);
1122
1123 if (ret)
1124 return ret;
1125 /* store the format in the channel object */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001126 common->fmt = *fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001127 return 0;
1128}
1129
1130/**
1131 * vpif_querycap() - QUERYCAP handler
1132 * @file: file ptr
1133 * @priv: file handle
1134 * @cap: ptr to v4l2_capability structure
1135 */
1136static int vpif_querycap(struct file *file, void *priv,
1137 struct v4l2_capability *cap)
1138{
1139 struct vpif_capture_config *config = vpif_dev->platform_data;
1140
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001141 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1142 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001143 strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001144 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1145 dev_name(vpif_dev));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001146 strlcpy(cap->card, config->card_name, sizeof(cap->card));
1147
1148 return 0;
1149}
1150
1151/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001152 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001153 * @file: file ptr
1154 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001155 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001156 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001157static int
1158vpif_enum_dv_timings(struct file *file, void *priv,
1159 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001160{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001161 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001162 struct video_device *vdev = video_devdata(file);
1163 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001164 struct vpif_capture_chan_config *chan_cfg;
1165 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001166 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001167
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001168 if (config->chan_config[ch->channel_id].inputs == NULL)
1169 return -ENODATA;
1170
1171 chan_cfg = &config->chan_config[ch->channel_id];
1172 input = chan_cfg->inputs[ch->input_idx].input;
1173 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1174 return -ENODATA;
1175
Laurent Pinchart10d21462014-01-31 09:04:19 -03001176 timings->pad = 0;
1177
1178 ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001179 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001180 return -EINVAL;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001181
Hans Verkuil178cce12012-09-20 09:06:30 -03001182 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001183}
1184
1185/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001186 * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001187 * @file: file ptr
1188 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001189 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001190 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001191static int
1192vpif_query_dv_timings(struct file *file, void *priv,
1193 struct v4l2_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001194{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001195 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001196 struct video_device *vdev = video_devdata(file);
1197 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001198 struct vpif_capture_chan_config *chan_cfg;
1199 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001200 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001201
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001202 if (config->chan_config[ch->channel_id].inputs == NULL)
1203 return -ENODATA;
1204
1205 chan_cfg = &config->chan_config[ch->channel_id];
1206 input = chan_cfg->inputs[ch->input_idx].input;
1207 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1208 return -ENODATA;
1209
Hans Verkuil178cce12012-09-20 09:06:30 -03001210 ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001211 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001212 return -ENODATA;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001213
Hans Verkuil178cce12012-09-20 09:06:30 -03001214 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001215}
1216
Mats Randgaardc027e162010-12-16 12:17:44 -03001217/**
1218 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1219 * @file: file ptr
1220 * @priv: file handle
1221 * @timings: digital video timings
1222 */
1223static int vpif_s_dv_timings(struct file *file, void *priv,
1224 struct v4l2_dv_timings *timings)
1225{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001226 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001227 struct video_device *vdev = video_devdata(file);
1228 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001229 struct vpif_params *vpifparams = &ch->vpifparams;
1230 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001231 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Mats Randgaardc027e162010-12-16 12:17:44 -03001232 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001233 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001234 struct vpif_capture_chan_config *chan_cfg;
1235 struct v4l2_input input;
Mats Randgaardc027e162010-12-16 12:17:44 -03001236 int ret;
1237
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001238 if (config->chan_config[ch->channel_id].inputs == NULL)
1239 return -ENODATA;
1240
1241 chan_cfg = &config->chan_config[ch->channel_id];
1242 input = chan_cfg->inputs[ch->input_idx].input;
1243 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1244 return -ENODATA;
1245
Mats Randgaardc027e162010-12-16 12:17:44 -03001246 if (timings->type != V4L2_DV_BT_656_1120) {
1247 vpif_dbg(2, debug, "Timing type not defined\n");
1248 return -EINVAL;
1249 }
1250
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001251 if (vb2_is_busy(&common->buffer_queue))
1252 return -EBUSY;
1253
Mats Randgaardc027e162010-12-16 12:17:44 -03001254 /* Configure subdevice timings, if any */
Hans Verkuil178cce12012-09-20 09:06:30 -03001255 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
1256 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1257 ret = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001258 if (ret < 0) {
1259 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1260 return ret;
1261 }
1262
1263 if (!(timings->bt.width && timings->bt.height &&
1264 (timings->bt.hbackporch ||
1265 timings->bt.hfrontporch ||
1266 timings->bt.hsync) &&
1267 timings->bt.vfrontporch &&
1268 (timings->bt.vbackporch ||
1269 timings->bt.vsync))) {
1270 vpif_dbg(2, debug, "Timings for width, height, "
1271 "horizontal back porch, horizontal sync, "
1272 "horizontal front porch, vertical back porch, "
1273 "vertical sync and vertical back porch "
1274 "must be defined\n");
1275 return -EINVAL;
1276 }
1277
Hans Verkuil0598c172012-09-18 07:18:47 -03001278 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001279
1280 /* Configure video port timings */
1281
Hans Verkuile3655262013-07-29 08:41:00 -03001282 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001283 std_info->sav2eav = bt->width;
1284
1285 std_info->l1 = 1;
1286 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1287
Hans Verkuile3655262013-07-29 08:41:00 -03001288 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001289 if (bt->interlaced) {
1290 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001291 std_info->l5 = std_info->vsize/2 -
1292 (bt->vfrontporch - 1);
1293 std_info->l7 = std_info->vsize/2 + 1;
1294 std_info->l9 = std_info->l7 + bt->il_vsync +
1295 bt->il_vbackporch + 1;
1296 std_info->l11 = std_info->vsize -
1297 (bt->il_vfrontporch - 1);
1298 } else {
1299 vpif_dbg(2, debug, "Required timing values for "
1300 "interlaced BT format missing\n");
1301 return -EINVAL;
1302 }
1303 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001304 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1305 }
1306 strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1307 std_info->width = bt->width;
1308 std_info->height = bt->height;
1309 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1310 std_info->ycmux_mode = 0;
1311 std_info->capture_format = 0;
1312 std_info->vbi_supported = 0;
1313 std_info->hd_sd = 1;
1314 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001315
1316 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001317 return 0;
1318}
1319
1320/**
1321 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1322 * @file: file ptr
1323 * @priv: file handle
1324 * @timings: digital video timings
1325 */
1326static int vpif_g_dv_timings(struct file *file, void *priv,
1327 struct v4l2_dv_timings *timings)
1328{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001329 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001330 struct video_device *vdev = video_devdata(file);
1331 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001332 struct video_obj *vid_ch = &ch->video;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001333 struct vpif_capture_chan_config *chan_cfg;
1334 struct v4l2_input input;
1335
1336 if (config->chan_config[ch->channel_id].inputs == NULL)
1337 return -ENODATA;
1338
1339 chan_cfg = &config->chan_config[ch->channel_id];
1340 input = chan_cfg->inputs[ch->input_idx].input;
1341 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1342 return -ENODATA;
Mats Randgaardc027e162010-12-16 12:17:44 -03001343
Hans Verkuil0598c172012-09-18 07:18:47 -03001344 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001345
1346 return 0;
1347}
1348
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001349/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001350 * vpif_log_status() - Status information
1351 * @file: file ptr
1352 * @priv: file handle
1353 *
1354 * Returns zero.
1355 */
1356static int vpif_log_status(struct file *filep, void *priv)
1357{
1358 /* status for sub devices */
1359 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1360
1361 return 0;
1362}
1363
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001364/* vpif capture ioctl operations */
1365static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001366 .vidioc_querycap = vpif_querycap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001367 .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001368 .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001369 .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
1370 .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001371
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001372 .vidioc_enum_input = vpif_enum_input,
1373 .vidioc_s_input = vpif_s_input,
1374 .vidioc_g_input = vpif_g_input,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001375
1376 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1377 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1378 .vidioc_querybuf = vb2_ioctl_querybuf,
1379 .vidioc_qbuf = vb2_ioctl_qbuf,
1380 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1381 .vidioc_expbuf = vb2_ioctl_expbuf,
1382 .vidioc_streamon = vb2_ioctl_streamon,
1383 .vidioc_streamoff = vb2_ioctl_streamoff,
1384
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001385 .vidioc_querystd = vpif_querystd,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001386 .vidioc_s_std = vpif_s_std,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001387 .vidioc_g_std = vpif_g_std,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001388
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001389 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1390 .vidioc_query_dv_timings = vpif_query_dv_timings,
1391 .vidioc_s_dv_timings = vpif_s_dv_timings,
1392 .vidioc_g_dv_timings = vpif_g_dv_timings,
1393
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001394 .vidioc_log_status = vpif_log_status,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001395};
1396
1397/* vpif file operations */
1398static struct v4l2_file_operations vpif_fops = {
1399 .owner = THIS_MODULE,
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001400 .open = v4l2_fh_open,
1401 .release = vb2_fop_release,
Hans Verkuil46656af2011-01-04 06:51:35 -03001402 .unlocked_ioctl = video_ioctl2,
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001403 .mmap = vb2_fop_mmap,
1404 .poll = vb2_fop_poll
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001405};
1406
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001407/**
1408 * initialize_vpif() - Initialize vpif data structures
1409 *
1410 * Allocate memory for data structures and initialize them
1411 */
1412static int initialize_vpif(void)
1413{
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001414 int err = 0, i, j;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001415 int free_channel_objects_index;
1416
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001417 /* Default number of buffers should be 3 */
1418 if ((ch0_numbuffers > 0) &&
1419 (ch0_numbuffers < config_params.min_numbuffers))
1420 ch0_numbuffers = config_params.min_numbuffers;
1421 if ((ch1_numbuffers > 0) &&
1422 (ch1_numbuffers < config_params.min_numbuffers))
1423 ch1_numbuffers = config_params.min_numbuffers;
1424
1425 /* Set buffer size to min buffers size if it is invalid */
1426 if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
1427 ch0_bufsize =
1428 config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
1429 if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
1430 ch1_bufsize =
1431 config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
1432
1433 config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
1434 config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
1435 if (ch0_numbuffers) {
1436 config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
1437 = ch0_bufsize;
1438 }
1439 if (ch1_numbuffers) {
1440 config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
1441 = ch1_bufsize;
1442 }
1443
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001444 /* Allocate memory for six channel objects */
1445 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1446 vpif_obj.dev[i] =
1447 kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
1448 /* If memory allocation fails, return error */
1449 if (!vpif_obj.dev[i]) {
1450 free_channel_objects_index = i;
1451 err = -ENOMEM;
1452 goto vpif_init_free_channel_objects;
1453 }
1454 }
1455 return 0;
1456
1457vpif_init_free_channel_objects:
1458 for (j = 0; j < free_channel_objects_index; j++)
1459 kfree(vpif_obj.dev[j]);
1460 return err;
1461}
1462
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001463static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1464 struct v4l2_subdev *subdev,
1465 struct v4l2_async_subdev *asd)
1466{
1467 int i;
1468
1469 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1470 if (!strcmp(vpif_obj.config->subdev_info[i].name,
1471 subdev->name)) {
1472 vpif_obj.sd[i] = subdev;
1473 return 0;
1474 }
1475
1476 return -EINVAL;
1477}
1478
1479static int vpif_probe_complete(void)
1480{
1481 struct common_obj *common;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001482 struct video_device *vdev;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001483 struct channel_obj *ch;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001484 struct vb2_queue *q;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001485 int i, j, err, k;
1486
1487 for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
1488 ch = vpif_obj.dev[j];
1489 ch->channel_id = j;
1490 common = &(ch->common[VPIF_VIDEO_INDEX]);
1491 spin_lock_init(&common->irqlock);
1492 mutex_init(&common->lock);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001493
1494 /* select input 0 */
1495 err = vpif_set_input(vpif_obj.config, ch, 0);
1496 if (err)
1497 goto probe_out;
1498
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001499 /* Initialize vb2 queue */
1500 q = &common->buffer_queue;
1501 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1502 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1503 q->drv_priv = ch;
1504 q->ops = &video_qops;
1505 q->mem_ops = &vb2_dma_contig_memops;
1506 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1507 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1508 q->min_buffers_needed = 1;
Lad, Prabhakar999ba692014-05-16 10:33:33 -03001509 q->lock = &common->lock;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001510
1511 err = vb2_queue_init(q);
1512 if (err) {
1513 vpif_err("vpif_capture: vb2_queue_init() failed\n");
1514 goto probe_out;
1515 }
1516
1517 common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
1518 if (IS_ERR(common->alloc_ctx)) {
1519 vpif_err("Failed to get the context\n");
1520 err = PTR_ERR(common->alloc_ctx);
1521 goto probe_out;
1522 }
1523
1524 INIT_LIST_HEAD(&common->dma_queue);
1525
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001526 /* Initialize the video_device structure */
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001527 vdev = ch->video_dev;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001528 strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
1529 vdev->release = video_device_release;
1530 vdev->fops = &vpif_fops;
1531 vdev->ioctl_ops = &vpif_ioctl_ops;
1532 vdev->v4l2_dev = &vpif_obj.v4l2_dev;
1533 vdev->vfl_dir = VFL_DIR_RX;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001534 vdev->queue = q;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001535 vdev->lock = &common->lock;
1536 set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1537 video_set_drvdata(ch->video_dev, ch);
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001538 err = video_register_device(vdev,
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001539 VFL_TYPE_GRABBER, (j ? 1 : 0));
1540 if (err)
1541 goto probe_out;
1542 }
1543
1544 v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
1545 return 0;
1546
1547probe_out:
1548 for (k = 0; k < j; k++) {
1549 /* Get the pointer to the channel object */
1550 ch = vpif_obj.dev[k];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001551 common = &ch->common[k];
1552 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001553 /* Unregister video device */
1554 video_unregister_device(ch->video_dev);
1555 }
1556 kfree(vpif_obj.sd);
1557 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1558 ch = vpif_obj.dev[i];
1559 /* Note: does nothing if ch->video_dev == NULL */
1560 video_device_release(ch->video_dev);
1561 }
1562 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1563
1564 return err;
1565}
1566
1567static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1568{
1569 return vpif_probe_complete();
1570}
1571
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001572/**
1573 * vpif_probe : This function probes the vpif capture driver
1574 * @pdev: platform device pointer
1575 *
1576 * This creates device entries by register itself to the V4L2 driver and
1577 * initializes fields of each channel objects
1578 */
1579static __init int vpif_probe(struct platform_device *pdev)
1580{
1581 struct vpif_subdev_info *subdevdata;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001582 int i, j, err;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001583 int res_idx = 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001584 struct i2c_adapter *i2c_adap;
1585 struct channel_obj *ch;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001586 struct video_device *vfd;
1587 struct resource *res;
1588 int subdev_count;
1589
1590 vpif_dev = &pdev->dev;
1591
1592 err = initialize_vpif();
1593 if (err) {
1594 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1595 return err;
1596 }
1597
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001598 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1599 if (err) {
1600 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1601 return err;
1602 }
1603
Hans Verkuil5be452c2012-09-20 09:06:29 -03001604 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001605 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001606 IRQF_SHARED, VPIF_DRIVER_NAME,
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001607 (void *)(&vpif_obj.dev[res_idx]->
1608 channel_id));
1609 if (err) {
1610 err = -EINVAL;
1611 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001612 }
Hans Verkuil5be452c2012-09-20 09:06:29 -03001613 res_idx++;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001614 }
1615
1616 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1617 /* Get the pointer to the channel object */
1618 ch = vpif_obj.dev[i];
1619 /* Allocate memory for video device */
1620 vfd = video_device_alloc();
1621 if (NULL == vfd) {
1622 for (j = 0; j < i; j++) {
1623 ch = vpif_obj.dev[j];
1624 video_device_release(ch->video_dev);
1625 }
1626 err = -ENOMEM;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001627 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001628 }
1629
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001630 /* Set video_dev to the video device */
1631 ch->video_dev = vfd;
1632 }
1633
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001634 vpif_obj.config = pdev->dev.platform_data;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001635
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001636 subdev_count = vpif_obj.config->subdev_count;
Mats Randgaard1f8766b2010-08-30 10:30:37 -03001637 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001638 GFP_KERNEL);
1639 if (vpif_obj.sd == NULL) {
1640 vpif_err("unable to allocate memory for subdevice pointers\n");
1641 err = -ENOMEM;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001642 goto vpif_sd_error;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001643 }
1644
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001645 if (!vpif_obj.config->asd_sizes) {
1646 i2c_adap = i2c_get_adapter(1);
1647 for (i = 0; i < subdev_count; i++) {
1648 subdevdata = &vpif_obj.config->subdev_info[i];
1649 vpif_obj.sd[i] =
1650 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1651 i2c_adap,
1652 &subdevdata->
1653 board_info,
1654 NULL);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001655
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001656 if (!vpif_obj.sd[i]) {
1657 vpif_err("Error registering v4l2 subdevice\n");
Wei Yongjun2fcd9dc2013-09-02 05:06:10 -03001658 err = -ENODEV;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001659 goto probe_subdev_out;
1660 }
1661 v4l2_info(&vpif_obj.v4l2_dev,
1662 "registered sub device %s\n",
1663 subdevdata->name);
1664 }
1665 vpif_probe_complete();
1666 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001667 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001668 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1669 vpif_obj.notifier.bound = vpif_async_bound;
1670 vpif_obj.notifier.complete = vpif_async_complete;
1671 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1672 &vpif_obj.notifier);
1673 if (err) {
1674 vpif_err("Error registering async notifier\n");
1675 err = -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001676 goto probe_subdev_out;
1677 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001678 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001679
1680 return 0;
1681
Hans Verkuilb65814e2012-09-20 09:06:26 -03001682probe_subdev_out:
1683 /* free sub devices memory */
1684 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001685
Hans Verkuil5be452c2012-09-20 09:06:29 -03001686vpif_sd_error:
1687 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1688 ch = vpif_obj.dev[i];
1689 /* Note: does nothing if ch->video_dev == NULL */
1690 video_device_release(ch->video_dev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001691 }
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001692vpif_unregister:
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001693 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001694
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001695 return err;
1696}
1697
1698/**
1699 * vpif_remove() - driver remove handler
1700 * @device: ptr to platform device structure
1701 *
1702 * The vidoe device is unregistered
1703 */
1704static int vpif_remove(struct platform_device *device)
1705{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001706 struct common_obj *common;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001707 struct channel_obj *ch;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001708 int i;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001709
1710 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1711
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001712 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001713 /* un-register device */
1714 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1715 /* Get the pointer to the channel object */
1716 ch = vpif_obj.dev[i];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001717 common = &ch->common[i];
1718 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001719 /* Unregister video device */
1720 video_unregister_device(ch->video_dev);
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001721 kfree(vpif_obj.dev[i]);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001722 }
1723 return 0;
1724}
1725
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001726#ifdef CONFIG_PM_SLEEP
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001727/**
1728 * vpif_suspend: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001729 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001730static int vpif_suspend(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001731{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001732
1733 struct common_obj *common;
1734 struct channel_obj *ch;
1735 int i;
1736
1737 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1738 /* Get the pointer to the channel object */
1739 ch = vpif_obj.dev[i];
1740 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001741
1742 if (!vb2_is_streaming(&common->buffer_queue))
1743 continue;
1744
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001745 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001746 /* Disable channel */
1747 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1748 enable_channel0(0);
1749 channel0_intr_enable(0);
1750 }
1751 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1752 ycmux_mode == 2) {
1753 enable_channel1(0);
1754 channel1_intr_enable(0);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001755 }
1756 mutex_unlock(&common->lock);
1757 }
1758
1759 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001760}
1761
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001762/*
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001763 * vpif_resume: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001764 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001765static int vpif_resume(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001766{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001767 struct common_obj *common;
1768 struct channel_obj *ch;
1769 int i;
1770
1771 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1772 /* Get the pointer to the channel object */
1773 ch = vpif_obj.dev[i];
1774 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001775
1776 if (!vb2_is_streaming(&common->buffer_queue))
1777 continue;
1778
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001779 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001780 /* Enable channel */
1781 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1782 enable_channel0(1);
1783 channel0_intr_enable(1);
1784 }
1785 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1786 ycmux_mode == 2) {
1787 enable_channel1(1);
1788 channel1_intr_enable(1);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001789 }
1790 mutex_unlock(&common->lock);
1791 }
1792
1793 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001794}
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001795#endif
1796
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001797static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
1798
Mats Randgaardffa1b392010-08-30 10:30:36 -03001799static __refdata struct platform_driver vpif_driver = {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001800 .driver = {
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001801 .name = VPIF_DRIVER_NAME,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001802 .owner = THIS_MODULE,
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001803 .pm = &vpif_pm_ops,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001804 },
1805 .probe = vpif_probe,
1806 .remove = vpif_remove,
1807};
1808
Lad, Prabhakarfe424b22013-06-17 11:20:45 -03001809module_platform_driver(vpif_driver);