blob: 128e92d1dd5a751c0d3bda0e4a0c16eccd41941a [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 *
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030015 * TODO : add support for VBI & HBI data service
16 * add static buffer allocation
17 */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030018
Lad, Prabhakar012eef72013-04-19 05:53:29 -030019#include <linux/module.h>
20#include <linux/interrupt.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23
Lad, Prabhakar012eef72013-04-19 05:53:29 -030024#include <media/v4l2-ioctl.h>
25
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030026#include "vpif.h"
Lad, Prabhakar012eef72013-04-19 05:53:29 -030027#include "vpif_capture.h"
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030028
29MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
30MODULE_LICENSE("GPL");
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030031MODULE_VERSION(VPIF_CAPTURE_VERSION);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030032
33#define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
34#define vpif_dbg(level, debug, fmt, arg...) \
35 v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
36
37static int debug = 1;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030038
39module_param(debug, int, 0644);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030040
41MODULE_PARM_DESC(debug, "Debug level 0-1");
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030042
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -030043#define VPIF_DRIVER_NAME "vpif_capture"
Kevin Hilmanbff782d2016-12-16 22:47:54 -020044MODULE_ALIAS("platform:" VPIF_DRIVER_NAME);
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -030045
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030046/* global variables */
47static struct vpif_device vpif_obj = { {NULL} };
48static struct device *vpif_dev;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030049static void vpif_calculate_offsets(struct channel_obj *ch);
50static void vpif_config_addr(struct channel_obj *ch, int muxmode);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030051
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030052static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
53
Lad, Prabhakarc66238f2014-05-16 10:33:45 -030054/* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */
55static int ycmux_mode;
56
Junghak Sung2d700712015-09-22 10:30:30 -030057static inline
58struct vpif_cap_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb)
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030059{
60 return container_of(vb, struct vpif_cap_buffer, vb);
61}
62
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030063/**
Lad, Prabhakar23e76a22014-05-16 10:33:37 -030064 * vpif_buffer_prepare : callback function for buffer prepare
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030065 * @vb: ptr to vb2_buffer
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030066 *
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030067 * This is the callback function for buffer prepare when vb2_qbuf()
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030068 * function is called. The buffer is prepared and user space virtual address
69 * or user address is converted into physical address
70 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030071static int vpif_buffer_prepare(struct vb2_buffer *vb)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030072{
Junghak Sung2d700712015-09-22 10:30:30 -030073 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030074 struct vb2_queue *q = vb->vb2_queue;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030075 struct channel_obj *ch = vb2_get_drv_priv(q);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030076 struct common_obj *common;
77 unsigned long addr;
78
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030079 vpif_dbg(2, debug, "vpif_buffer_prepare\n");
80
81 common = &ch->common[VPIF_VIDEO_INDEX];
82
Lad, Prabhakar23e76a22014-05-16 10:33:37 -030083 vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
84 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
85 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030086
Junghak Sung2d700712015-09-22 10:30:30 -030087 vbuf->field = common->fmt.fmt.pix.field;
Lad, Prabhakar23e76a22014-05-16 10:33:37 -030088
89 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
90 if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
91 !IS_ALIGNED((addr + common->ybtm_off), 8) ||
92 !IS_ALIGNED((addr + common->ctop_off), 8) ||
93 !IS_ALIGNED((addr + common->cbtm_off), 8)) {
94 vpif_dbg(1, debug, "offset is not aligned\n");
95 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030096 }
Lad, Prabhakar23e76a22014-05-16 10:33:37 -030097
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030098 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030099}
100
101/**
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300102 * vpif_buffer_queue_setup : Callback function for buffer setup.
103 * @vq: vb2_queue ptr
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300104 * @nbuffers: ptr to number of buffers requested by application
105 * @nplanes:: contains number of distinct video planes needed to hold a frame
106 * @sizes[]: contains the size (in bytes) of each plane.
Hans Verkuil36c0f8b2016-04-15 09:15:05 -0300107 * @alloc_devs: ptr to allocation context
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300108 *
109 * This callback function is called when reqbuf() is called to adjust
110 * the buffer count and buffer size
111 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300112static int vpif_buffer_queue_setup(struct vb2_queue *vq,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300113 unsigned int *nbuffers, unsigned int *nplanes,
Hans Verkuil36c0f8b2016-04-15 09:15:05 -0300114 unsigned int sizes[], struct device *alloc_devs[])
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300115{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300116 struct channel_obj *ch = vb2_get_drv_priv(vq);
Hans Verkuildf9ecb02015-10-28 00:50:37 -0200117 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
118 unsigned size = common->fmt.fmt.pix.sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300119
120 vpif_dbg(2, debug, "vpif_buffer_setup\n");
121
Hans Verkuildf9ecb02015-10-28 00:50:37 -0200122 if (*nplanes) {
123 if (sizes[0] < size)
124 return -EINVAL;
125 size = sizes[0];
126 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300127
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300128 if (vq->num_buffers + *nbuffers < 3)
129 *nbuffers = 3 - vq->num_buffers;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300130
131 *nplanes = 1;
Hans Verkuildf9ecb02015-10-28 00:50:37 -0200132 sizes[0] = size;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300133
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300134 /* Calculate the offset for Y and C data in the buffer */
135 vpif_calculate_offsets(ch);
136
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300137 return 0;
138}
139
140/**
141 * vpif_buffer_queue : Callback function to add buffer to DMA queue
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300142 * @vb: ptr to vb2_buffer
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300143 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300144static void vpif_buffer_queue(struct vb2_buffer *vb)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300145{
Junghak Sung2d700712015-09-22 10:30:30 -0300146 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300147 struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
Junghak Sung2d700712015-09-22 10:30:30 -0300148 struct vpif_cap_buffer *buf = to_vpif_buffer(vbuf);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300149 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300150 unsigned long flags;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300151
152 common = &ch->common[VPIF_VIDEO_INDEX];
153
154 vpif_dbg(2, debug, "vpif_buffer_queue\n");
155
Hans Verkuilaec96832012-11-16 12:03:06 -0300156 spin_lock_irqsave(&common->irqlock, flags);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300157 /* add the buffer to the DMA queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300158 list_add_tail(&buf->list, &common->dma_queue);
Hans Verkuilaec96832012-11-16 12:03:06 -0300159 spin_unlock_irqrestore(&common->irqlock, flags);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300160}
161
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300162/**
163 * vpif_start_streaming : Starts the DMA engine for streaming
164 * @vb: ptr to vb2_buffer
165 * @count: number of buffers
166 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300167static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
168{
169 struct vpif_capture_config *vpif_config_data =
170 vpif_dev->platform_data;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300171 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300172 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
173 struct vpif_params *vpif = &ch->vpifparams;
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300174 struct vpif_cap_buffer *buf, *tmp;
175 unsigned long addr, flags;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300176 int ret;
177
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300178 /* Initialize field_id */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300179 ch->field_id = 0;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300180
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300181 /* configure 1 or 2 channel mode */
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300182 if (vpif_config_data->setup_input_channel_mode) {
183 ret = vpif_config_data->
184 setup_input_channel_mode(vpif->std_info.ycmux_mode);
185 if (ret < 0) {
186 vpif_dbg(1, debug, "can't set vpif channel mode\n");
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300187 goto err;
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300188 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300189 }
190
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300191 ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
192 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
193 vpif_dbg(1, debug, "stream on failed in subdev\n");
194 goto err;
195 }
196
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300197 /* Call vpif_set_params function to set the parameters and addresses */
198 ret = vpif_set_video_params(vpif, ch->channel_id);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300199 if (ret < 0) {
200 vpif_dbg(1, debug, "can't set video params\n");
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300201 goto err;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300202 }
203
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300204 ycmux_mode = ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300205 vpif_config_addr(ch, ret);
206
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300207 /* Get the next frame from the buffer queue */
Kevin Hilman62dd4ac2016-12-07 16:30:23 -0200208 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300209 common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
210 struct vpif_cap_buffer, list);
211 /* Remove buffer from the buffer queue */
212 list_del(&common->cur_frm->list);
213 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300214
Junghak Sung2d700712015-09-22 10:30:30 -0300215 addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb.vb2_buf, 0);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300216
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300217 common->set_addr(addr + common->ytop_off,
218 addr + common->ybtm_off,
219 addr + common->ctop_off,
220 addr + common->cbtm_off);
221
222 /**
223 * Set interrupt for both the fields in VPIF Register enable channel in
224 * VPIF register
225 */
Lad, Prabhakar9e184042012-09-14 10:22:24 -0300226 channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300227 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300228 channel0_intr_assert();
229 channel0_intr_enable(1);
230 enable_channel0(1);
231 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300232 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300233 ycmux_mode == 2) {
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300234 channel1_intr_assert();
235 channel1_intr_enable(1);
236 enable_channel1(1);
237 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300238
239 return 0;
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300240
241err:
Kevin Hilman62dd4ac2016-12-07 16:30:23 -0200242 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300243 list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
244 list_del(&buf->list);
Junghak Sung2d700712015-09-22 10:30:30 -0300245 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300246 }
Dan Carpenter92491962014-06-12 04:01:45 -0300247 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300248
249 return ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300250}
251
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300252/**
253 * vpif_stop_streaming : Stop the DMA engine
254 * @vq: ptr to vb2_queue
255 *
256 * This callback stops the DMA engine and any remaining buffers
257 * in the DMA queue are released.
258 */
Hans Verkuile37559b2014-04-17 02:47:21 -0300259static void vpif_stop_streaming(struct vb2_queue *vq)
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300260{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300261 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300262 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300263 unsigned long flags;
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300264 int ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300265
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300266 common = &ch->common[VPIF_VIDEO_INDEX];
267
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300268 /* Disable channel as per its device type and channel id */
269 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
270 enable_channel0(0);
271 channel0_intr_enable(0);
272 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300273 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300274 ycmux_mode == 2) {
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300275 enable_channel1(0);
276 channel1_intr_enable(0);
277 }
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300278
279 ycmux_mode = 0;
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300280
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300281 ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
282 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
283 vpif_dbg(1, debug, "stream off failed in subdev\n");
284
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300285 /* release all active buffers */
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300286 if (common->cur_frm == common->next_frm) {
Junghak Sung2d700712015-09-22 10:30:30 -0300287 vb2_buffer_done(&common->cur_frm->vb.vb2_buf,
288 VB2_BUF_STATE_ERROR);
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300289 } else {
Markus Elfring03161cd2016-10-12 10:20:34 -0300290 if (common->cur_frm)
Junghak Sung2d700712015-09-22 10:30:30 -0300291 vb2_buffer_done(&common->cur_frm->vb.vb2_buf,
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300292 VB2_BUF_STATE_ERROR);
Markus Elfring03161cd2016-10-12 10:20:34 -0300293 if (common->next_frm)
Junghak Sung2d700712015-09-22 10:30:30 -0300294 vb2_buffer_done(&common->next_frm->vb.vb2_buf,
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300295 VB2_BUF_STATE_ERROR);
296 }
297
Kevin Hilman62dd4ac2016-12-07 16:30:23 -0200298 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300299 while (!list_empty(&common->dma_queue)) {
300 common->next_frm = list_entry(common->dma_queue.next,
301 struct vpif_cap_buffer, list);
302 list_del(&common->next_frm->list);
Junghak Sung2d700712015-09-22 10:30:30 -0300303 vb2_buffer_done(&common->next_frm->vb.vb2_buf,
304 VB2_BUF_STATE_ERROR);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300305 }
Hans Verkuilaec96832012-11-16 12:03:06 -0300306 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300307}
308
309static struct vb2_ops video_qops = {
310 .queue_setup = vpif_buffer_queue_setup,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300311 .buf_prepare = vpif_buffer_prepare,
312 .start_streaming = vpif_start_streaming,
313 .stop_streaming = vpif_stop_streaming,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300314 .buf_queue = vpif_buffer_queue,
Prabhakar Ladb41a97a2014-11-26 19:42:33 -0300315 .wait_prepare = vb2_ops_wait_prepare,
316 .wait_finish = vb2_ops_wait_finish,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300317};
318
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300319/**
320 * vpif_process_buffer_complete: process a completed buffer
321 * @common: ptr to common channel object
322 *
323 * This function time stamp the buffer and mark it as DONE. It also
324 * wake up any process waiting on the QUEUE and set the next buffer
325 * as current
326 */
327static void vpif_process_buffer_complete(struct common_obj *common)
328{
Junghak Sungd6dd6452015-11-03 08:16:37 -0200329 common->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns();
Junghak Sung2d700712015-09-22 10:30:30 -0300330 vb2_buffer_done(&common->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300331 /* Make curFrm pointing to nextFrm */
332 common->cur_frm = common->next_frm;
333}
334
335/**
336 * vpif_schedule_next_buffer: set next buffer address for capture
337 * @common : ptr to common channel object
338 *
339 * This function will get next buffer from the dma queue and
340 * set the buffer address in the vpif register for capture.
341 * the buffer is marked active
342 */
343static void vpif_schedule_next_buffer(struct common_obj *common)
344{
345 unsigned long addr = 0;
346
Hans Verkuilaec96832012-11-16 12:03:06 -0300347 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300348 common->next_frm = list_entry(common->dma_queue.next,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300349 struct vpif_cap_buffer, list);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300350 /* Remove that buffer from the buffer queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300351 list_del(&common->next_frm->list);
Hans Verkuilaec96832012-11-16 12:03:06 -0300352 spin_unlock(&common->irqlock);
Junghak Sung2d700712015-09-22 10:30:30 -0300353 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb.vb2_buf, 0);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300354
355 /* Set top and bottom field addresses in VPIF registers */
356 common->set_addr(addr + common->ytop_off,
357 addr + common->ybtm_off,
358 addr + common->ctop_off,
359 addr + common->cbtm_off);
360}
361
362/**
363 * vpif_channel_isr : ISR handler for vpif capture
364 * @irq: irq number
365 * @dev_id: dev_id ptr
366 *
367 * It changes status of the captured buffer, takes next buffer from the queue
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300368 * and sets its address in VPIF registers
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300369 */
370static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
371{
372 struct vpif_device *dev = &vpif_obj;
373 struct common_obj *common;
374 struct channel_obj *ch;
Markus Elfringc64d61d2016-10-12 10:25:08 -0300375 int channel_id;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300376 int fid = -1, i;
377
378 channel_id = *(int *)(dev_id);
Manjunath Hadlib1fc4232012-04-13 04:43:10 -0300379 if (!vpif_intr_status(channel_id))
380 return IRQ_NONE;
381
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300382 ch = dev->dev[channel_id];
383
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300384 for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
385 common = &ch->common[i];
386 /* skip If streaming is not started in this channel */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300387 /* Check the field format */
388 if (1 == ch->vpifparams.std_info.frm_fmt) {
389 /* Progressive mode */
Hans Verkuilaec96832012-11-16 12:03:06 -0300390 spin_lock(&common->irqlock);
391 if (list_empty(&common->dma_queue)) {
392 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300393 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300394 }
395 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300396
397 if (!channel_first_int[i][channel_id])
398 vpif_process_buffer_complete(common);
399
400 channel_first_int[i][channel_id] = 0;
401
402 vpif_schedule_next_buffer(common);
403
404
405 channel_first_int[i][channel_id] = 0;
406 } else {
407 /**
408 * Interlaced mode. If it is first interrupt, ignore
409 * it
410 */
411 if (channel_first_int[i][channel_id]) {
412 channel_first_int[i][channel_id] = 0;
413 continue;
414 }
415 if (0 == i) {
416 ch->field_id ^= 1;
417 /* Get field id from VPIF registers */
418 fid = vpif_channel_getfid(ch->channel_id);
419 if (fid != ch->field_id) {
420 /**
421 * If field id does not match stored
422 * field id, make them in sync
423 */
424 if (0 == fid)
425 ch->field_id = fid;
426 return IRQ_HANDLED;
427 }
428 }
429 /* device field id and local field id are in sync */
430 if (0 == fid) {
431 /* this is even field */
432 if (common->cur_frm == common->next_frm)
433 continue;
434
435 /* mark the current buffer as done */
436 vpif_process_buffer_complete(common);
437 } else if (1 == fid) {
438 /* odd field */
Hans Verkuilaec96832012-11-16 12:03:06 -0300439 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300440 if (list_empty(&common->dma_queue) ||
Hans Verkuilaec96832012-11-16 12:03:06 -0300441 (common->cur_frm != common->next_frm)) {
442 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300443 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300444 }
445 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300446
447 vpif_schedule_next_buffer(common);
448 }
449 }
450 }
451 return IRQ_HANDLED;
452}
453
454/**
455 * vpif_update_std_info() - update standard related info
456 * @ch: ptr to channel object
457 *
458 * For a given standard selected by application, update values
459 * in the device data structures
460 */
461static int vpif_update_std_info(struct channel_obj *ch)
462{
463 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
464 struct vpif_params *vpifparams = &ch->vpifparams;
465 const struct vpif_channel_config_params *config;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300466 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300467 struct video_obj *vid_ch = &ch->video;
468 int index;
469
470 vpif_dbg(2, debug, "vpif_update_std_info\n");
471
Mats Randgaardaa444402010-12-16 12:17:42 -0300472 for (index = 0; index < vpif_ch_params_count; index++) {
Lad, Prabhakarced9b212013-03-20 01:28:27 -0300473 config = &vpif_ch_params[index];
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300474 if (config->hd_sd == 0) {
475 vpif_dbg(2, debug, "SD format\n");
476 if (config->stdid & vid_ch->stdid) {
477 memcpy(std_info, config, sizeof(*config));
478 break;
479 }
480 } else {
481 vpif_dbg(2, debug, "HD format\n");
Hans Verkuil0598c172012-09-18 07:18:47 -0300482 if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
483 sizeof(vid_ch->dv_timings))) {
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300484 memcpy(std_info, config, sizeof(*config));
485 break;
486 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300487 }
488 }
489
490 /* standard not found */
Mats Randgaardaa444402010-12-16 12:17:42 -0300491 if (index == vpif_ch_params_count)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300492 return -EINVAL;
493
494 common->fmt.fmt.pix.width = std_info->width;
495 common->width = std_info->width;
496 common->fmt.fmt.pix.height = std_info->height;
497 common->height = std_info->height;
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300498 common->fmt.fmt.pix.sizeimage = common->height * common->width * 2;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300499 common->fmt.fmt.pix.bytesperline = std_info->width;
500 vpifparams->video_params.hpitch = std_info->width;
501 vpifparams->video_params.storage_mode = std_info->frm_fmt;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300502
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300503 if (vid_ch->stdid)
504 common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
505 else
506 common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
507
508 if (ch->vpifparams.std_info.frm_fmt)
509 common->fmt.fmt.pix.field = V4L2_FIELD_NONE;
510 else
511 common->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
512
513 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
514 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
515 else
Nori, Sekhar8946ab32017-05-26 07:55:27 -0300516 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV16;
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300517
518 common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
519
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300520 return 0;
521}
522
523/**
524 * vpif_calculate_offsets : This function calculates buffers offsets
525 * @ch : ptr to channel object
526 *
527 * This function calculates buffer offsets for Y and C in the top and
528 * bottom field
529 */
530static void vpif_calculate_offsets(struct channel_obj *ch)
531{
Mauro Carvalho Chehab24ab6332014-08-21 15:49:06 -0500532 unsigned int hpitch, sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300533 struct video_obj *vid_ch = &(ch->video);
534 struct vpif_params *vpifparams = &ch->vpifparams;
535 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
536 enum v4l2_field field = common->fmt.fmt.pix.field;
537
538 vpif_dbg(2, debug, "vpif_calculate_offsets\n");
539
540 if (V4L2_FIELD_ANY == field) {
541 if (vpifparams->std_info.frm_fmt)
542 vid_ch->buf_field = V4L2_FIELD_NONE;
543 else
544 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
545 } else
546 vid_ch->buf_field = common->fmt.fmt.pix.field;
547
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300548 sizeimage = common->fmt.fmt.pix.sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300549
550 hpitch = common->fmt.fmt.pix.bytesperline;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300551
552 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
553 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
554 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
555 common->ytop_off = 0;
556 common->ybtm_off = hpitch;
557 common->ctop_off = sizeimage / 2;
558 common->cbtm_off = sizeimage / 2 + hpitch;
559 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
560 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
561 common->ytop_off = 0;
562 common->ybtm_off = sizeimage / 4;
563 common->ctop_off = sizeimage / 2;
564 common->cbtm_off = common->ctop_off + sizeimage / 4;
565 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
566 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
567 common->ybtm_off = 0;
568 common->ytop_off = sizeimage / 4;
569 common->cbtm_off = sizeimage / 2;
570 common->ctop_off = common->cbtm_off + sizeimage / 4;
571 }
572 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
573 (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
574 vpifparams->video_params.storage_mode = 1;
575 else
576 vpifparams->video_params.storage_mode = 0;
577
578 if (1 == vpifparams->std_info.frm_fmt)
579 vpifparams->video_params.hpitch =
580 common->fmt.fmt.pix.bytesperline;
581 else {
582 if ((field == V4L2_FIELD_ANY)
583 || (field == V4L2_FIELD_INTERLACED))
584 vpifparams->video_params.hpitch =
585 common->fmt.fmt.pix.bytesperline * 2;
586 else
587 vpifparams->video_params.hpitch =
588 common->fmt.fmt.pix.bytesperline;
589 }
590
591 ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
592}
593
594/**
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300595 * vpif_get_default_field() - Get default field type based on interface
596 * @vpif_params - ptr to vpif params
597 */
598static inline enum v4l2_field vpif_get_default_field(
599 struct vpif_interface *iface)
600{
601 return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
602 V4L2_FIELD_INTERLACED;
603}
604
605/**
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300606 * vpif_config_addr() - function to configure buffer address in vpif
607 * @ch - channel ptr
608 * @muxmode - channel mux mode
609 */
610static void vpif_config_addr(struct channel_obj *ch, int muxmode)
611{
612 struct common_obj *common;
613
614 vpif_dbg(2, debug, "vpif_config_addr\n");
615
616 common = &(ch->common[VPIF_VIDEO_INDEX]);
617
618 if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
619 common->set_addr = ch1_set_videobuf_addr;
620 else if (2 == muxmode)
621 common->set_addr = ch0_set_videobuf_addr_yc_nmux;
622 else
623 common->set_addr = ch0_set_videobuf_addr;
624}
625
626/**
Hans Verkuil178cce12012-09-20 09:06:30 -0300627 * vpif_input_to_subdev() - Maps input to sub device
628 * @vpif_cfg - global config ptr
629 * @chan_cfg - channel config ptr
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300630 * @input_index - Given input index from application
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300631 *
632 * lookup the sub device information for a given input index.
633 * we report all the inputs to application. inputs table also
634 * has sub device name for the each input
635 */
Hans Verkuil178cce12012-09-20 09:06:30 -0300636static int vpif_input_to_subdev(
637 struct vpif_capture_config *vpif_cfg,
638 struct vpif_capture_chan_config *chan_cfg,
639 int input_index)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300640{
Hans Verkuil178cce12012-09-20 09:06:30 -0300641 struct vpif_subdev_info *subdev_info;
642 const char *subdev_name;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300643 int i;
644
Hans Verkuil178cce12012-09-20 09:06:30 -0300645 vpif_dbg(2, debug, "vpif_input_to_subdev\n");
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300646
Kevin Hilmanbff782d2016-12-16 22:47:54 -0200647 if (!chan_cfg)
648 return -1;
649 if (input_index >= chan_cfg->input_count)
650 return -1;
Hans Verkuil178cce12012-09-20 09:06:30 -0300651 subdev_name = chan_cfg->inputs[input_index].subdev_name;
Markus Elfring03161cd2016-10-12 10:20:34 -0300652 if (!subdev_name)
Hans Verkuil178cce12012-09-20 09:06:30 -0300653 return -1;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300654
655 /* loop through the sub device list to get the sub device info */
656 for (i = 0; i < vpif_cfg->subdev_count; i++) {
657 subdev_info = &vpif_cfg->subdev_info[i];
658 if (!strcmp(subdev_info->name, subdev_name))
Hans Verkuil178cce12012-09-20 09:06:30 -0300659 return i;
660 }
661 return -1;
662}
663
664/**
665 * vpif_set_input() - Select an input
666 * @vpif_cfg - global config ptr
667 * @ch - channel
668 * @_index - Given input index from application
669 *
670 * Select the given input.
671 */
672static int vpif_set_input(
673 struct vpif_capture_config *vpif_cfg,
674 struct channel_obj *ch,
675 int index)
676{
677 struct vpif_capture_chan_config *chan_cfg =
678 &vpif_cfg->chan_config[ch->channel_id];
679 struct vpif_subdev_info *subdev_info = NULL;
680 struct v4l2_subdev *sd = NULL;
681 u32 input = 0, output = 0;
682 int sd_index;
683 int ret;
684
685 sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
686 if (sd_index >= 0) {
687 sd = vpif_obj.sd[sd_index];
688 subdev_info = &vpif_cfg->subdev_info[sd_index];
Kevin Hilmanbff782d2016-12-16 22:47:54 -0200689 } else {
690 /* no subdevice, no input to setup */
691 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300692 }
693
Hans Verkuil178cce12012-09-20 09:06:30 -0300694 /* first setup input path from sub device to vpif */
695 if (sd && vpif_cfg->setup_input_path) {
696 ret = vpif_cfg->setup_input_path(ch->channel_id,
697 subdev_info->name);
698 if (ret < 0) {
699 vpif_dbg(1, debug, "couldn't setup input path for the" \
700 " sub device %s, for input index %d\n",
701 subdev_info->name, index);
702 return ret;
703 }
704 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300705
Hans Verkuil178cce12012-09-20 09:06:30 -0300706 if (sd) {
707 input = chan_cfg->inputs[index].input_route;
708 output = chan_cfg->inputs[index].output_route;
709 ret = v4l2_subdev_call(sd, video, s_routing,
710 input, output, 0);
711 if (ret < 0 && ret != -ENOIOCTLCMD) {
712 vpif_dbg(1, debug, "Failed to set input\n");
713 return ret;
714 }
715 }
716 ch->input_idx = index;
717 ch->sd = sd;
718 /* copy interface parameters to vpif */
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300719 ch->vpifparams.iface = chan_cfg->vpif_if;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300720
Hans Verkuil178cce12012-09-20 09:06:30 -0300721 /* update tvnorms from the sub device input info */
Lad, Prabhakar8eef6662015-03-08 18:57:23 -0300722 ch->video_dev.tvnorms = chan_cfg->inputs[index].input.std;
Hans Verkuil178cce12012-09-20 09:06:30 -0300723 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300724}
725
726/**
727 * vpif_querystd() - querystd handler
728 * @file: file ptr
729 * @priv: file handle
730 * @std_id: ptr to std id
731 *
732 * This function is called to detect standard at the selected input
733 */
734static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
735{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300736 struct video_device *vdev = video_devdata(file);
737 struct channel_obj *ch = video_get_drvdata(vdev);
Markus Elfring6a842cc2016-10-12 10:22:45 -0300738 int ret;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300739
740 vpif_dbg(2, debug, "vpif_querystd\n");
741
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300742 /* Call querystd function of decoder device */
Hans Verkuil178cce12012-09-20 09:06:30 -0300743 ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300744
Hans Verkuil178cce12012-09-20 09:06:30 -0300745 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
746 return -ENODATA;
747 if (ret) {
748 vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
749 return ret;
750 }
751
752 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300753}
754
755/**
756 * vpif_g_std() - get STD handler
757 * @file: file ptr
758 * @priv: file handle
759 * @std_id: ptr to std id
760 */
761static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
762{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300763 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300764 struct video_device *vdev = video_devdata(file);
765 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300766 struct vpif_capture_chan_config *chan_cfg;
767 struct v4l2_input input;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300768
769 vpif_dbg(2, debug, "vpif_g_std\n");
770
Markus Elfring03161cd2016-10-12 10:20:34 -0300771 if (!config->chan_config[ch->channel_id].inputs)
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300772 return -ENODATA;
773
774 chan_cfg = &config->chan_config[ch->channel_id];
775 input = chan_cfg->inputs[ch->input_idx].input;
776 if (input.capabilities != V4L2_IN_CAP_STD)
777 return -ENODATA;
778
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300779 *std = ch->video.stdid;
780 return 0;
781}
782
783/**
784 * vpif_s_std() - set STD handler
785 * @file: file ptr
786 * @priv: file handle
787 * @std_id: ptr to std id
788 */
Hans Verkuil314527a2013-03-15 06:10:40 -0300789static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300790{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300791 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300792 struct video_device *vdev = video_devdata(file);
793 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300794 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300795 struct vpif_capture_chan_config *chan_cfg;
796 struct v4l2_input input;
797 int ret;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300798
799 vpif_dbg(2, debug, "vpif_s_std\n");
800
Markus Elfring03161cd2016-10-12 10:20:34 -0300801 if (!config->chan_config[ch->channel_id].inputs)
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300802 return -ENODATA;
803
804 chan_cfg = &config->chan_config[ch->channel_id];
805 input = chan_cfg->inputs[ch->input_idx].input;
806 if (input.capabilities != V4L2_IN_CAP_STD)
807 return -ENODATA;
808
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300809 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300810 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300811
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300812 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -0300813 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -0300814 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300815
816 /* Get the information about the standard */
817 if (vpif_update_std_info(ch)) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300818 vpif_err("Error getting the standard info\n");
Hans Verkuil46656af2011-01-04 06:51:35 -0300819 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300820 }
821
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300822 /* set standard in the sub device */
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300823 ret = v4l2_subdev_call(ch->sd, video, s_std, std_id);
Hans Verkuil178cce12012-09-20 09:06:30 -0300824 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300825 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
Hans Verkuil178cce12012-09-20 09:06:30 -0300826 return ret;
827 }
828 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300829}
830
831/**
832 * vpif_enum_input() - ENUMINPUT handler
833 * @file: file ptr
834 * @priv: file handle
835 * @input: ptr to input structure
836 */
837static int vpif_enum_input(struct file *file, void *priv,
838 struct v4l2_input *input)
839{
840
841 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300842 struct video_device *vdev = video_devdata(file);
843 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300844 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300845
846 chan_cfg = &config->chan_config[ch->channel_id];
847
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300848 if (input->index >= chan_cfg->input_count)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300849 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300850
851 memcpy(input, &chan_cfg->inputs[input->index].input,
852 sizeof(*input));
853 return 0;
854}
855
856/**
857 * vpif_g_input() - Get INPUT handler
858 * @file: file ptr
859 * @priv: file handle
860 * @index: ptr to input index
861 */
862static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
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
Hans Verkuil6f47c6c2012-09-20 09:06:22 -0300867 *index = ch->input_idx;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300868 return 0;
869}
870
871/**
872 * vpif_s_input() - Set INPUT handler
873 * @file: file ptr
874 * @priv: file handle
875 * @index: input index
876 */
877static int vpif_s_input(struct file *file, void *priv, unsigned int index)
878{
879 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300880 struct video_device *vdev = video_devdata(file);
881 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300882 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300883 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300884
885 chan_cfg = &config->chan_config[ch->channel_id];
886
Hans Verkuil7aaad132012-09-20 09:06:25 -0300887 if (index >= chan_cfg->input_count)
888 return -EINVAL;
889
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300890 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300891 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300892
Hans Verkuil178cce12012-09-20 09:06:30 -0300893 return vpif_set_input(config, ch, index);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300894}
895
896/**
897 * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
898 * @file: file ptr
899 * @priv: file handle
900 * @index: input index
901 */
902static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
903 struct v4l2_fmtdesc *fmt)
904{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300905 struct video_device *vdev = video_devdata(file);
906 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300907
908 if (fmt->index != 0) {
909 vpif_dbg(1, debug, "Invalid format index\n");
910 return -EINVAL;
911 }
912
913 /* Fill in the information about format */
914 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
915 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
916 strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
917 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
918 } else {
919 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
Nori, Sekhar8946ab32017-05-26 07:55:27 -0300920 strcpy(fmt->description, "YCbCr4:2:2 Semi-Planar");
921 fmt->pixelformat = V4L2_PIX_FMT_NV16;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300922 }
923 return 0;
924}
925
926/**
927 * vpif_try_fmt_vid_cap() - TRY_FMT handler
928 * @file: file ptr
929 * @priv: file handle
930 * @fmt: ptr to v4l2 format structure
931 */
932static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
933 struct v4l2_format *fmt)
934{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300935 struct video_device *vdev = video_devdata(file);
936 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300937 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300938 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
939 struct vpif_params *vpif_params = &ch->vpifparams;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300940
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300941 /*
942 * to supress v4l-compliance warnings silently correct
943 * the pixelformat
944 */
945 if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
946 if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8)
947 pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
948 } else {
Nori, Sekhar8946ab32017-05-26 07:55:27 -0300949 if (pixfmt->pixelformat != V4L2_PIX_FMT_NV16)
950 pixfmt->pixelformat = V4L2_PIX_FMT_NV16;
Lad, Prabhakara4965c52014-05-16 10:33:54 -0300951 }
952
953 common->fmt.fmt.pix.pixelformat = pixfmt->pixelformat;
954
955 vpif_update_std_info(ch);
956
957 pixfmt->field = common->fmt.fmt.pix.field;
958 pixfmt->colorspace = common->fmt.fmt.pix.colorspace;
959 pixfmt->bytesperline = common->fmt.fmt.pix.width;
960 pixfmt->width = common->fmt.fmt.pix.width;
961 pixfmt->height = common->fmt.fmt.pix.height;
962 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height * 2;
963 pixfmt->priv = 0;
964
965 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300966}
967
968
969/**
970 * vpif_g_fmt_vid_cap() - Set INPUT handler
971 * @file: file ptr
972 * @priv: file handle
973 * @fmt: ptr to v4l2 format structure
974 */
975static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
976 struct v4l2_format *fmt)
977{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300978 struct video_device *vdev = video_devdata(file);
979 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300980 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
981
982 /* Check the validity of the buffer type */
983 if (common->fmt.type != fmt->type)
984 return -EINVAL;
985
986 /* Fill in the information about format */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300987 *fmt = common->fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300988 return 0;
989}
990
991/**
992 * vpif_s_fmt_vid_cap() - Set FMT handler
993 * @file: file ptr
994 * @priv: file handle
995 * @fmt: ptr to v4l2 format structure
996 */
997static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
998 struct v4l2_format *fmt)
999{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001000 struct video_device *vdev = video_devdata(file);
1001 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001002 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakara4965c52014-05-16 10:33:54 -03001003 int ret;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001004
Mats Randgaard2c0ddd12010-12-16 12:17:45 -03001005 vpif_dbg(2, debug, "%s\n", __func__);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001006
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001007 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001008 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001009
Lad, Prabhakara4965c52014-05-16 10:33:54 -03001010 ret = vpif_try_fmt_vid_cap(file, priv, fmt);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001011 if (ret)
1012 return ret;
Lad, Prabhakara4965c52014-05-16 10:33:54 -03001013
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001014 /* store the format in the channel object */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001015 common->fmt = *fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001016 return 0;
1017}
1018
1019/**
1020 * vpif_querycap() - QUERYCAP handler
1021 * @file: file ptr
1022 * @priv: file handle
1023 * @cap: ptr to v4l2_capability structure
1024 */
1025static int vpif_querycap(struct file *file, void *priv,
1026 struct v4l2_capability *cap)
1027{
1028 struct vpif_capture_config *config = vpif_dev->platform_data;
1029
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001030 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1031 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001032 strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001033 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1034 dev_name(vpif_dev));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001035 strlcpy(cap->card, config->card_name, sizeof(cap->card));
1036
1037 return 0;
1038}
1039
1040/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001041 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001042 * @file: file ptr
1043 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001044 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001045 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001046static int
1047vpif_enum_dv_timings(struct file *file, void *priv,
1048 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001049{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001050 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001051 struct video_device *vdev = video_devdata(file);
1052 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001053 struct vpif_capture_chan_config *chan_cfg;
1054 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001055 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001056
Markus Elfring03161cd2016-10-12 10:20:34 -03001057 if (!config->chan_config[ch->channel_id].inputs)
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001058 return -ENODATA;
1059
1060 chan_cfg = &config->chan_config[ch->channel_id];
1061 input = chan_cfg->inputs[ch->input_idx].input;
1062 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1063 return -ENODATA;
1064
Laurent Pinchart10d21462014-01-31 09:04:19 -03001065 timings->pad = 0;
1066
1067 ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001068 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001069 return -EINVAL;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001070
Hans Verkuil178cce12012-09-20 09:06:30 -03001071 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001072}
1073
1074/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001075 * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001076 * @file: file ptr
1077 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001078 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001079 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001080static int
1081vpif_query_dv_timings(struct file *file, void *priv,
1082 struct v4l2_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001083{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001084 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001085 struct video_device *vdev = video_devdata(file);
1086 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001087 struct vpif_capture_chan_config *chan_cfg;
1088 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001089 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001090
Markus Elfring03161cd2016-10-12 10:20:34 -03001091 if (!config->chan_config[ch->channel_id].inputs)
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001092 return -ENODATA;
1093
1094 chan_cfg = &config->chan_config[ch->channel_id];
1095 input = chan_cfg->inputs[ch->input_idx].input;
1096 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1097 return -ENODATA;
1098
Hans Verkuil178cce12012-09-20 09:06:30 -03001099 ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001100 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001101 return -ENODATA;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001102
Hans Verkuil178cce12012-09-20 09:06:30 -03001103 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001104}
1105
Mats Randgaardc027e162010-12-16 12:17:44 -03001106/**
1107 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1108 * @file: file ptr
1109 * @priv: file handle
1110 * @timings: digital video timings
1111 */
1112static int vpif_s_dv_timings(struct file *file, void *priv,
1113 struct v4l2_dv_timings *timings)
1114{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001115 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001116 struct video_device *vdev = video_devdata(file);
1117 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001118 struct vpif_params *vpifparams = &ch->vpifparams;
1119 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001120 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Mats Randgaardc027e162010-12-16 12:17:44 -03001121 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001122 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001123 struct vpif_capture_chan_config *chan_cfg;
1124 struct v4l2_input input;
Mats Randgaardc027e162010-12-16 12:17:44 -03001125 int ret;
1126
Markus Elfring03161cd2016-10-12 10:20:34 -03001127 if (!config->chan_config[ch->channel_id].inputs)
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001128 return -ENODATA;
1129
1130 chan_cfg = &config->chan_config[ch->channel_id];
1131 input = chan_cfg->inputs[ch->input_idx].input;
1132 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1133 return -ENODATA;
1134
Mats Randgaardc027e162010-12-16 12:17:44 -03001135 if (timings->type != V4L2_DV_BT_656_1120) {
1136 vpif_dbg(2, debug, "Timing type not defined\n");
1137 return -EINVAL;
1138 }
1139
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001140 if (vb2_is_busy(&common->buffer_queue))
1141 return -EBUSY;
1142
Mats Randgaardc027e162010-12-16 12:17:44 -03001143 /* Configure subdevice timings, if any */
Hans Verkuil178cce12012-09-20 09:06:30 -03001144 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
1145 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1146 ret = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001147 if (ret < 0) {
1148 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1149 return ret;
1150 }
1151
1152 if (!(timings->bt.width && timings->bt.height &&
1153 (timings->bt.hbackporch ||
1154 timings->bt.hfrontporch ||
1155 timings->bt.hsync) &&
1156 timings->bt.vfrontporch &&
1157 (timings->bt.vbackporch ||
1158 timings->bt.vsync))) {
Mauro Carvalho Chehabded026e2016-10-18 17:44:08 -02001159 vpif_dbg(2, debug, "Timings for width, height, horizontal back porch, horizontal sync, horizontal front porch, vertical back porch, vertical sync and vertical back porch must be defined\n");
Mats Randgaardc027e162010-12-16 12:17:44 -03001160 return -EINVAL;
1161 }
1162
Hans Verkuil0598c172012-09-18 07:18:47 -03001163 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001164
1165 /* Configure video port timings */
1166
Hans Verkuile3655262013-07-29 08:41:00 -03001167 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001168 std_info->sav2eav = bt->width;
1169
1170 std_info->l1 = 1;
1171 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1172
Hans Verkuile3655262013-07-29 08:41:00 -03001173 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001174 if (bt->interlaced) {
1175 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001176 std_info->l5 = std_info->vsize/2 -
1177 (bt->vfrontporch - 1);
1178 std_info->l7 = std_info->vsize/2 + 1;
1179 std_info->l9 = std_info->l7 + bt->il_vsync +
1180 bt->il_vbackporch + 1;
1181 std_info->l11 = std_info->vsize -
1182 (bt->il_vfrontporch - 1);
1183 } else {
Mauro Carvalho Chehabded026e2016-10-18 17:44:08 -02001184 vpif_dbg(2, debug, "Required timing values for interlaced BT format missing\n");
Mats Randgaardc027e162010-12-16 12:17:44 -03001185 return -EINVAL;
1186 }
1187 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001188 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1189 }
1190 strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1191 std_info->width = bt->width;
1192 std_info->height = bt->height;
1193 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1194 std_info->ycmux_mode = 0;
1195 std_info->capture_format = 0;
1196 std_info->vbi_supported = 0;
1197 std_info->hd_sd = 1;
1198 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001199
1200 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001201 return 0;
1202}
1203
1204/**
1205 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1206 * @file: file ptr
1207 * @priv: file handle
1208 * @timings: digital video timings
1209 */
1210static int vpif_g_dv_timings(struct file *file, void *priv,
1211 struct v4l2_dv_timings *timings)
1212{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001213 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001214 struct video_device *vdev = video_devdata(file);
1215 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001216 struct video_obj *vid_ch = &ch->video;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001217 struct vpif_capture_chan_config *chan_cfg;
1218 struct v4l2_input input;
1219
Markus Elfring03161cd2016-10-12 10:20:34 -03001220 if (!config->chan_config[ch->channel_id].inputs)
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001221 return -ENODATA;
1222
1223 chan_cfg = &config->chan_config[ch->channel_id];
1224 input = chan_cfg->inputs[ch->input_idx].input;
1225 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1226 return -ENODATA;
Mats Randgaardc027e162010-12-16 12:17:44 -03001227
Hans Verkuil0598c172012-09-18 07:18:47 -03001228 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001229
1230 return 0;
1231}
1232
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001233/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001234 * vpif_log_status() - Status information
1235 * @file: file ptr
1236 * @priv: file handle
1237 *
1238 * Returns zero.
1239 */
1240static int vpif_log_status(struct file *filep, void *priv)
1241{
1242 /* status for sub devices */
1243 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1244
1245 return 0;
1246}
1247
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001248/* vpif capture ioctl operations */
1249static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001250 .vidioc_querycap = vpif_querycap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001251 .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001252 .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001253 .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
1254 .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001255
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001256 .vidioc_enum_input = vpif_enum_input,
1257 .vidioc_s_input = vpif_s_input,
1258 .vidioc_g_input = vpif_g_input,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001259
1260 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1261 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1262 .vidioc_querybuf = vb2_ioctl_querybuf,
1263 .vidioc_qbuf = vb2_ioctl_qbuf,
1264 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1265 .vidioc_expbuf = vb2_ioctl_expbuf,
1266 .vidioc_streamon = vb2_ioctl_streamon,
1267 .vidioc_streamoff = vb2_ioctl_streamoff,
1268
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001269 .vidioc_querystd = vpif_querystd,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001270 .vidioc_s_std = vpif_s_std,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001271 .vidioc_g_std = vpif_g_std,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001272
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001273 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1274 .vidioc_query_dv_timings = vpif_query_dv_timings,
1275 .vidioc_s_dv_timings = vpif_s_dv_timings,
1276 .vidioc_g_dv_timings = vpif_g_dv_timings,
1277
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001278 .vidioc_log_status = vpif_log_status,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001279};
1280
1281/* vpif file operations */
1282static struct v4l2_file_operations vpif_fops = {
1283 .owner = THIS_MODULE,
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001284 .open = v4l2_fh_open,
1285 .release = vb2_fop_release,
Hans Verkuil46656af2011-01-04 06:51:35 -03001286 .unlocked_ioctl = video_ioctl2,
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001287 .mmap = vb2_fop_mmap,
1288 .poll = vb2_fop_poll
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001289};
1290
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001291/**
1292 * initialize_vpif() - Initialize vpif data structures
1293 *
1294 * Allocate memory for data structures and initialize them
1295 */
1296static int initialize_vpif(void)
1297{
Lad, Prabhakar4015bef2014-05-16 10:33:47 -03001298 int err, i, j;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001299 int free_channel_objects_index;
1300
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001301 /* Allocate memory for six channel objects */
1302 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1303 vpif_obj.dev[i] =
1304 kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
1305 /* If memory allocation fails, return error */
1306 if (!vpif_obj.dev[i]) {
1307 free_channel_objects_index = i;
1308 err = -ENOMEM;
1309 goto vpif_init_free_channel_objects;
1310 }
1311 }
1312 return 0;
1313
1314vpif_init_free_channel_objects:
1315 for (j = 0; j < free_channel_objects_index; j++)
1316 kfree(vpif_obj.dev[j]);
1317 return err;
1318}
1319
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001320static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1321 struct v4l2_subdev *subdev,
1322 struct v4l2_async_subdev *asd)
1323{
1324 int i;
1325
1326 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1327 if (!strcmp(vpif_obj.config->subdev_info[i].name,
1328 subdev->name)) {
1329 vpif_obj.sd[i] = subdev;
1330 return 0;
1331 }
1332
1333 return -EINVAL;
1334}
1335
1336static int vpif_probe_complete(void)
1337{
1338 struct common_obj *common;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001339 struct video_device *vdev;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001340 struct channel_obj *ch;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001341 struct vb2_queue *q;
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001342 int j, err, k;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001343
1344 for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
1345 ch = vpif_obj.dev[j];
1346 ch->channel_id = j;
1347 common = &(ch->common[VPIF_VIDEO_INDEX]);
1348 spin_lock_init(&common->irqlock);
1349 mutex_init(&common->lock);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001350
1351 /* select input 0 */
1352 err = vpif_set_input(vpif_obj.config, ch, 0);
1353 if (err)
1354 goto probe_out;
1355
Lad, Prabhakara4965c52014-05-16 10:33:54 -03001356 /* set initial format */
1357 ch->video.stdid = V4L2_STD_525_60;
1358 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
1359 vpif_update_std_info(ch);
1360
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001361 /* Initialize vb2 queue */
1362 q = &common->buffer_queue;
1363 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1364 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1365 q->drv_priv = ch;
1366 q->ops = &video_qops;
1367 q->mem_ops = &vb2_dma_contig_memops;
1368 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1369 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1370 q->min_buffers_needed = 1;
Lad, Prabhakar999ba692014-05-16 10:33:33 -03001371 q->lock = &common->lock;
Hans Verkuil53ddcc62016-02-15 13:09:10 -02001372 q->dev = vpif_dev;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001373
1374 err = vb2_queue_init(q);
1375 if (err) {
1376 vpif_err("vpif_capture: vb2_queue_init() failed\n");
1377 goto probe_out;
1378 }
1379
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001380 INIT_LIST_HEAD(&common->dma_queue);
1381
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001382 /* Initialize the video_device structure */
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001383 vdev = &ch->video_dev;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001384 strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001385 vdev->release = video_device_release_empty;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001386 vdev->fops = &vpif_fops;
1387 vdev->ioctl_ops = &vpif_ioctl_ops;
1388 vdev->v4l2_dev = &vpif_obj.v4l2_dev;
1389 vdev->vfl_dir = VFL_DIR_RX;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001390 vdev->queue = q;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001391 vdev->lock = &common->lock;
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001392 video_set_drvdata(&ch->video_dev, ch);
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001393 err = video_register_device(vdev,
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001394 VFL_TYPE_GRABBER, (j ? 1 : 0));
1395 if (err)
1396 goto probe_out;
1397 }
1398
1399 v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
1400 return 0;
1401
1402probe_out:
1403 for (k = 0; k < j; k++) {
1404 /* Get the pointer to the channel object */
1405 ch = vpif_obj.dev[k];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001406 common = &ch->common[k];
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001407 /* Unregister video device */
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001408 video_unregister_device(&ch->video_dev);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001409 }
1410 kfree(vpif_obj.sd);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001411 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1412
1413 return err;
1414}
1415
1416static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1417{
1418 return vpif_probe_complete();
1419}
1420
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001421/**
1422 * vpif_probe : This function probes the vpif capture driver
1423 * @pdev: platform device pointer
1424 *
1425 * This creates device entries by register itself to the V4L2 driver and
1426 * initializes fields of each channel objects
1427 */
1428static __init int vpif_probe(struct platform_device *pdev)
1429{
1430 struct vpif_subdev_info *subdevdata;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001431 struct i2c_adapter *i2c_adap;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001432 struct resource *res;
1433 int subdev_count;
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001434 int res_idx = 0;
1435 int i, err;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001436
Kevin Hilmanbff782d2016-12-16 22:47:54 -02001437 if (!pdev->dev.platform_data) {
1438 dev_warn(&pdev->dev, "Missing platform data. Giving up.\n");
1439 return -EINVAL;
1440 }
1441
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001442 vpif_dev = &pdev->dev;
1443
1444 err = initialize_vpif();
1445 if (err) {
1446 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1447 return err;
1448 }
1449
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001450 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1451 if (err) {
1452 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1453 return err;
1454 }
1455
Hans Verkuil5be452c2012-09-20 09:06:29 -03001456 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001457 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001458 IRQF_SHARED, VPIF_DRIVER_NAME,
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001459 (void *)(&vpif_obj.dev[res_idx]->
1460 channel_id));
1461 if (err) {
1462 err = -EINVAL;
1463 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001464 }
Hans Verkuil5be452c2012-09-20 09:06:29 -03001465 res_idx++;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001466 }
1467
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001468 vpif_obj.config = pdev->dev.platform_data;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001469
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001470 subdev_count = vpif_obj.config->subdev_count;
Markus Elfringb442c462016-10-12 10:15:34 -03001471 vpif_obj.sd = kcalloc(subdev_count, sizeof(*vpif_obj.sd), GFP_KERNEL);
Markus Elfring03161cd2016-10-12 10:20:34 -03001472 if (!vpif_obj.sd) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001473 err = -ENOMEM;
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001474 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001475 }
1476
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001477 if (!vpif_obj.config->asd_sizes) {
Kevin Hilman2d40cb32016-12-07 16:30:22 -02001478 int i2c_id = vpif_obj.config->i2c_adapter_id;
1479
1480 i2c_adap = i2c_get_adapter(i2c_id);
1481 WARN_ON(!i2c_adap);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001482 for (i = 0; i < subdev_count; i++) {
1483 subdevdata = &vpif_obj.config->subdev_info[i];
1484 vpif_obj.sd[i] =
1485 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1486 i2c_adap,
1487 &subdevdata->
1488 board_info,
1489 NULL);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001490
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001491 if (!vpif_obj.sd[i]) {
1492 vpif_err("Error registering v4l2 subdevice\n");
Wei Yongjun2fcd9dc2013-09-02 05:06:10 -03001493 err = -ENODEV;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001494 goto probe_subdev_out;
1495 }
1496 v4l2_info(&vpif_obj.v4l2_dev,
1497 "registered sub device %s\n",
1498 subdevdata->name);
1499 }
1500 vpif_probe_complete();
1501 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001502 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001503 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1504 vpif_obj.notifier.bound = vpif_async_bound;
1505 vpif_obj.notifier.complete = vpif_async_complete;
1506 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1507 &vpif_obj.notifier);
1508 if (err) {
1509 vpif_err("Error registering async notifier\n");
1510 err = -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001511 goto probe_subdev_out;
1512 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001513 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001514
1515 return 0;
1516
Hans Verkuilb65814e2012-09-20 09:06:26 -03001517probe_subdev_out:
1518 /* free sub devices memory */
1519 kfree(vpif_obj.sd);
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001520vpif_unregister:
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001521 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001522
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001523 return err;
1524}
1525
1526/**
1527 * vpif_remove() - driver remove handler
1528 * @device: ptr to platform device structure
1529 *
1530 * The vidoe device is unregistered
1531 */
1532static int vpif_remove(struct platform_device *device)
1533{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001534 struct common_obj *common;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001535 struct channel_obj *ch;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001536 int i;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001537
1538 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1539
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001540 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001541 /* un-register device */
1542 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1543 /* Get the pointer to the channel object */
1544 ch = vpif_obj.dev[i];
Prabhakar Lade9b58722014-07-18 13:31:51 -03001545 common = &ch->common[VPIF_VIDEO_INDEX];
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001546 /* Unregister video device */
Lad, Prabhakar8eef6662015-03-08 18:57:23 -03001547 video_unregister_device(&ch->video_dev);
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001548 kfree(vpif_obj.dev[i]);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001549 }
1550 return 0;
1551}
1552
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001553#ifdef CONFIG_PM_SLEEP
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001554/**
1555 * vpif_suspend: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001556 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001557static int vpif_suspend(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001558{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001559
1560 struct common_obj *common;
1561 struct channel_obj *ch;
1562 int i;
1563
1564 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1565 /* Get the pointer to the channel object */
1566 ch = vpif_obj.dev[i];
1567 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001568
Prabhakar Ladc54d4a02014-09-06 12:26:51 -03001569 if (!vb2_start_streaming_called(&common->buffer_queue))
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001570 continue;
1571
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001572 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001573 /* Disable channel */
1574 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1575 enable_channel0(0);
1576 channel0_intr_enable(0);
1577 }
1578 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1579 ycmux_mode == 2) {
1580 enable_channel1(0);
1581 channel1_intr_enable(0);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001582 }
1583 mutex_unlock(&common->lock);
1584 }
1585
1586 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001587}
1588
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001589/*
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001590 * vpif_resume: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001591 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001592static int vpif_resume(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001593{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001594 struct common_obj *common;
1595 struct channel_obj *ch;
1596 int i;
1597
1598 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1599 /* Get the pointer to the channel object */
1600 ch = vpif_obj.dev[i];
1601 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001602
Prabhakar Ladc54d4a02014-09-06 12:26:51 -03001603 if (!vb2_start_streaming_called(&common->buffer_queue))
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001604 continue;
1605
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001606 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001607 /* Enable channel */
1608 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1609 enable_channel0(1);
1610 channel0_intr_enable(1);
1611 }
1612 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1613 ycmux_mode == 2) {
1614 enable_channel1(1);
1615 channel1_intr_enable(1);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001616 }
1617 mutex_unlock(&common->lock);
1618 }
1619
1620 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001621}
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001622#endif
1623
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001624static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
1625
Mats Randgaardffa1b392010-08-30 10:30:36 -03001626static __refdata struct platform_driver vpif_driver = {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001627 .driver = {
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001628 .name = VPIF_DRIVER_NAME,
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001629 .pm = &vpif_pm_ops,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001630 },
1631 .probe = vpif_probe,
1632 .remove = vpif_remove,
1633};
1634
Lad, Prabhakarfe424b22013-06-17 11:20:45 -03001635module_platform_driver(vpif_driver);