blob: 7b53182eb0695a627ebc948f5157e31bca80b382 [file] [log] [blame]
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001/*
2 * Copyright (C) 2009 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * TODO : add support for VBI & HBI data service
19 * add static buffer allocation
20 */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030021
Lad, Prabhakar012eef72013-04-19 05:53:29 -030022#include <linux/module.h>
23#include <linux/interrupt.h>
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26
Lad, Prabhakar012eef72013-04-19 05:53:29 -030027#include <media/v4l2-ioctl.h>
28
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030029#include "vpif.h"
Lad, Prabhakar012eef72013-04-19 05:53:29 -030030#include "vpif_capture.h"
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030031
32MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
33MODULE_LICENSE("GPL");
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030034MODULE_VERSION(VPIF_CAPTURE_VERSION);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030035
36#define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
37#define vpif_dbg(level, debug, fmt, arg...) \
38 v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
39
40static int debug = 1;
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -030041static u32 ch0_numbuffers = 3;
42static u32 ch1_numbuffers = 3;
43static u32 ch0_bufsize = 1920 * 1080 * 2;
44static u32 ch1_bufsize = 720 * 576 * 2;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030045
46module_param(debug, int, 0644);
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -030047module_param(ch0_numbuffers, uint, S_IRUGO);
48module_param(ch1_numbuffers, uint, S_IRUGO);
49module_param(ch0_bufsize, uint, S_IRUGO);
50module_param(ch1_bufsize, uint, S_IRUGO);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030051
52MODULE_PARM_DESC(debug, "Debug level 0-1");
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -030053MODULE_PARM_DESC(ch2_numbuffers, "Channel0 buffer count (default:3)");
54MODULE_PARM_DESC(ch3_numbuffers, "Channel1 buffer count (default:3)");
55MODULE_PARM_DESC(ch2_bufsize, "Channel0 buffer size (default:1920 x 1080 x 2)");
56MODULE_PARM_DESC(ch3_bufsize, "Channel1 buffer size (default:720 x 576 x 2)");
57
58static struct vpif_config_params config_params = {
59 .min_numbuffers = 3,
60 .numbuffers[0] = 3,
61 .numbuffers[1] = 3,
62 .min_bufsize[0] = 720 * 480 * 2,
63 .min_bufsize[1] = 720 * 480 * 2,
64 .channel_bufsize[0] = 1920 * 1080 * 2,
65 .channel_bufsize[1] = 720 * 576 * 2,
66};
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030067
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -030068#define VPIF_DRIVER_NAME "vpif_capture"
69
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030070/* global variables */
71static struct vpif_device vpif_obj = { {NULL} };
72static struct device *vpif_dev;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030073static void vpif_calculate_offsets(struct channel_obj *ch);
74static void vpif_config_addr(struct channel_obj *ch, int muxmode);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030075
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030076static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
77
Lad, Prabhakarc66238f2014-05-16 10:33:45 -030078/* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */
79static int ycmux_mode;
80
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030081static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb)
82{
83 return container_of(vb, struct vpif_cap_buffer, vb);
84}
85
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030086/**
Lad, Prabhakar23e76a22014-05-16 10:33:37 -030087 * vpif_buffer_prepare : callback function for buffer prepare
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030088 * @vb: ptr to vb2_buffer
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030089 *
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030090 * This is the callback function for buffer prepare when vb2_qbuf()
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030091 * function is called. The buffer is prepared and user space virtual address
92 * or user address is converted into physical address
93 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030094static int vpif_buffer_prepare(struct vb2_buffer *vb)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030095{
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -030096 struct vb2_queue *q = vb->vb2_queue;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -030097 struct channel_obj *ch = vb2_get_drv_priv(q);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -030098 struct common_obj *common;
99 unsigned long addr;
100
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300101 vpif_dbg(2, debug, "vpif_buffer_prepare\n");
102
103 common = &ch->common[VPIF_VIDEO_INDEX];
104
Lad, Prabhakar23e76a22014-05-16 10:33:37 -0300105 vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
106 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
107 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300108
Lad, Prabhakar23e76a22014-05-16 10:33:37 -0300109 vb->v4l2_buf.field = common->fmt.fmt.pix.field;
110
111 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
112 if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
113 !IS_ALIGNED((addr + common->ybtm_off), 8) ||
114 !IS_ALIGNED((addr + common->ctop_off), 8) ||
115 !IS_ALIGNED((addr + common->cbtm_off), 8)) {
116 vpif_dbg(1, debug, "offset is not aligned\n");
117 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300118 }
Lad, Prabhakar23e76a22014-05-16 10:33:37 -0300119
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300120 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300121}
122
123/**
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300124 * vpif_buffer_queue_setup : Callback function for buffer setup.
125 * @vq: vb2_queue ptr
126 * @fmt: v4l2 format
127 * @nbuffers: ptr to number of buffers requested by application
128 * @nplanes:: contains number of distinct video planes needed to hold a frame
129 * @sizes[]: contains the size (in bytes) of each plane.
130 * @alloc_ctxs: ptr to allocation context
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300131 *
132 * This callback function is called when reqbuf() is called to adjust
133 * the buffer count and buffer size
134 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300135static int vpif_buffer_queue_setup(struct vb2_queue *vq,
136 const struct v4l2_format *fmt,
137 unsigned int *nbuffers, unsigned int *nplanes,
138 unsigned int sizes[], void *alloc_ctxs[])
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300139{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300140 struct channel_obj *ch = vb2_get_drv_priv(vq);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300141 struct common_obj *common;
142
143 common = &ch->common[VPIF_VIDEO_INDEX];
144
145 vpif_dbg(2, debug, "vpif_buffer_setup\n");
146
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300147 if (fmt && fmt->fmt.pix.sizeimage < common->fmt.fmt.pix.sizeimage)
148 return -EINVAL;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300149
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300150 if (vq->num_buffers + *nbuffers < 3)
151 *nbuffers = 3 - vq->num_buffers;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300152
153 *nplanes = 1;
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300154 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : common->fmt.fmt.pix.sizeimage;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300155 alloc_ctxs[0] = common->alloc_ctx;
156
Lad, Prabhakar837939d2014-05-16 10:33:38 -0300157 /* Calculate the offset for Y and C data in the buffer */
158 vpif_calculate_offsets(ch);
159
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300160 return 0;
161}
162
163/**
164 * vpif_buffer_queue : Callback function to add buffer to DMA queue
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300165 * @vb: ptr to vb2_buffer
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300166 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300167static void vpif_buffer_queue(struct vb2_buffer *vb)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300168{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300169 struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
170 struct vpif_cap_buffer *buf = to_vpif_buffer(vb);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300171 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300172 unsigned long flags;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300173
174 common = &ch->common[VPIF_VIDEO_INDEX];
175
176 vpif_dbg(2, debug, "vpif_buffer_queue\n");
177
Hans Verkuilaec96832012-11-16 12:03:06 -0300178 spin_lock_irqsave(&common->irqlock, flags);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300179 /* add the buffer to the DMA queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300180 list_add_tail(&buf->list, &common->dma_queue);
Hans Verkuilaec96832012-11-16 12:03:06 -0300181 spin_unlock_irqrestore(&common->irqlock, flags);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300182}
183
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300184/**
185 * vpif_start_streaming : Starts the DMA engine for streaming
186 * @vb: ptr to vb2_buffer
187 * @count: number of buffers
188 */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300189static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
190{
191 struct vpif_capture_config *vpif_config_data =
192 vpif_dev->platform_data;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300193 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300194 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
195 struct vpif_params *vpif = &ch->vpifparams;
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300196 struct vpif_cap_buffer *buf, *tmp;
197 unsigned long addr, flags;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300198 int ret;
199
Hans Verkuilaec96832012-11-16 12:03:06 -0300200 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300201
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300202 /* Initialize field_id */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300203 ch->field_id = 0;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300204
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300205 /* configure 1 or 2 channel mode */
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300206 if (vpif_config_data->setup_input_channel_mode) {
207 ret = vpif_config_data->
208 setup_input_channel_mode(vpif->std_info.ycmux_mode);
209 if (ret < 0) {
210 vpif_dbg(1, debug, "can't set vpif channel mode\n");
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300211 goto err;
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300212 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300213 }
214
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300215 ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
216 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
217 vpif_dbg(1, debug, "stream on failed in subdev\n");
218 goto err;
219 }
220
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300221 /* Call vpif_set_params function to set the parameters and addresses */
222 ret = vpif_set_video_params(vpif, ch->channel_id);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300223 if (ret < 0) {
224 vpif_dbg(1, debug, "can't set video params\n");
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300225 goto err;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300226 }
227
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300228 ycmux_mode = ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300229 vpif_config_addr(ch, ret);
230
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300231 /* Get the next frame from the buffer queue */
232 common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
233 struct vpif_cap_buffer, list);
234 /* Remove buffer from the buffer queue */
235 list_del(&common->cur_frm->list);
236 spin_unlock_irqrestore(&common->irqlock, flags);
237 /* Mark state of the current frame to active */
238 common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
239
240 addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
241
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300242 common->set_addr(addr + common->ytop_off,
243 addr + common->ybtm_off,
244 addr + common->ctop_off,
245 addr + common->cbtm_off);
246
247 /**
248 * Set interrupt for both the fields in VPIF Register enable channel in
249 * VPIF register
250 */
Lad, Prabhakar9e184042012-09-14 10:22:24 -0300251 channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300252 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300253 channel0_intr_assert();
254 channel0_intr_enable(1);
255 enable_channel0(1);
256 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300257 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300258 ycmux_mode == 2) {
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300259 channel1_intr_assert();
260 channel1_intr_enable(1);
261 enable_channel1(1);
262 }
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300263
264 return 0;
Lad, Prabhakarbebd8d12014-05-16 10:33:35 -0300265
266err:
267 list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
268 list_del(&buf->list);
269 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
270 }
271
272 return ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300273}
274
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300275/**
276 * vpif_stop_streaming : Stop the DMA engine
277 * @vq: ptr to vb2_queue
278 *
279 * This callback stops the DMA engine and any remaining buffers
280 * in the DMA queue are released.
281 */
Hans Verkuile37559b2014-04-17 02:47:21 -0300282static void vpif_stop_streaming(struct vb2_queue *vq)
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300283{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -0300284 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300285 struct common_obj *common;
Hans Verkuilaec96832012-11-16 12:03:06 -0300286 unsigned long flags;
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300287 int ret;
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300288
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300289 common = &ch->common[VPIF_VIDEO_INDEX];
290
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300291 /* Disable channel as per its device type and channel id */
292 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
293 enable_channel0(0);
294 channel0_intr_enable(0);
295 }
Lad, Prabhakar41b9f242014-05-16 10:33:39 -0300296 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300297 ycmux_mode == 2) {
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300298 enable_channel1(0);
299 channel1_intr_enable(0);
300 }
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300301
302 ycmux_mode = 0;
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300303
Lad, Prabhakard9a3b132014-05-16 10:33:42 -0300304 ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
305 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
306 vpif_dbg(1, debug, "stream off failed in subdev\n");
307
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300308 /* release all active buffers */
Hans Verkuilaec96832012-11-16 12:03:06 -0300309 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakare6ba3db2014-03-22 08:03:07 -0300310 if (common->cur_frm == common->next_frm) {
311 vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
312 } else {
313 if (common->cur_frm != NULL)
314 vb2_buffer_done(&common->cur_frm->vb,
315 VB2_BUF_STATE_ERROR);
316 if (common->next_frm != NULL)
317 vb2_buffer_done(&common->next_frm->vb,
318 VB2_BUF_STATE_ERROR);
319 }
320
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300321 while (!list_empty(&common->dma_queue)) {
322 common->next_frm = list_entry(common->dma_queue.next,
323 struct vpif_cap_buffer, list);
324 list_del(&common->next_frm->list);
325 vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
326 }
Hans Verkuilaec96832012-11-16 12:03:06 -0300327 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300328}
329
330static struct vb2_ops video_qops = {
331 .queue_setup = vpif_buffer_queue_setup,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300332 .buf_prepare = vpif_buffer_prepare,
333 .start_streaming = vpif_start_streaming,
334 .stop_streaming = vpif_stop_streaming,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300335 .buf_queue = vpif_buffer_queue,
336};
337
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300338/**
339 * vpif_process_buffer_complete: process a completed buffer
340 * @common: ptr to common channel object
341 *
342 * This function time stamp the buffer and mark it as DONE. It also
343 * wake up any process waiting on the QUEUE and set the next buffer
344 * as current
345 */
346static void vpif_process_buffer_complete(struct common_obj *common)
347{
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300348 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300349 vb2_buffer_done(&common->cur_frm->vb,
350 VB2_BUF_STATE_DONE);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300351 /* Make curFrm pointing to nextFrm */
352 common->cur_frm = common->next_frm;
353}
354
355/**
356 * vpif_schedule_next_buffer: set next buffer address for capture
357 * @common : ptr to common channel object
358 *
359 * This function will get next buffer from the dma queue and
360 * set the buffer address in the vpif register for capture.
361 * the buffer is marked active
362 */
363static void vpif_schedule_next_buffer(struct common_obj *common)
364{
365 unsigned long addr = 0;
366
Hans Verkuilaec96832012-11-16 12:03:06 -0300367 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300368 common->next_frm = list_entry(common->dma_queue.next,
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300369 struct vpif_cap_buffer, list);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300370 /* Remove that buffer from the buffer queue */
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300371 list_del(&common->next_frm->list);
Hans Verkuilaec96832012-11-16 12:03:06 -0300372 spin_unlock(&common->irqlock);
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300373 common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
374 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300375
376 /* Set top and bottom field addresses in VPIF registers */
377 common->set_addr(addr + common->ytop_off,
378 addr + common->ybtm_off,
379 addr + common->ctop_off,
380 addr + common->cbtm_off);
381}
382
383/**
384 * vpif_channel_isr : ISR handler for vpif capture
385 * @irq: irq number
386 * @dev_id: dev_id ptr
387 *
388 * It changes status of the captured buffer, takes next buffer from the queue
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300389 * and sets its address in VPIF registers
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300390 */
391static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
392{
393 struct vpif_device *dev = &vpif_obj;
394 struct common_obj *common;
395 struct channel_obj *ch;
396 enum v4l2_field field;
397 int channel_id = 0;
398 int fid = -1, i;
399
400 channel_id = *(int *)(dev_id);
Manjunath Hadlib1fc4232012-04-13 04:43:10 -0300401 if (!vpif_intr_status(channel_id))
402 return IRQ_NONE;
403
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300404 ch = dev->dev[channel_id];
405
406 field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
407
408 for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
409 common = &ch->common[i];
410 /* skip If streaming is not started in this channel */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300411 /* Check the field format */
412 if (1 == ch->vpifparams.std_info.frm_fmt) {
413 /* Progressive mode */
Hans Verkuilaec96832012-11-16 12:03:06 -0300414 spin_lock(&common->irqlock);
415 if (list_empty(&common->dma_queue)) {
416 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300417 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300418 }
419 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300420
421 if (!channel_first_int[i][channel_id])
422 vpif_process_buffer_complete(common);
423
424 channel_first_int[i][channel_id] = 0;
425
426 vpif_schedule_next_buffer(common);
427
428
429 channel_first_int[i][channel_id] = 0;
430 } else {
431 /**
432 * Interlaced mode. If it is first interrupt, ignore
433 * it
434 */
435 if (channel_first_int[i][channel_id]) {
436 channel_first_int[i][channel_id] = 0;
437 continue;
438 }
439 if (0 == i) {
440 ch->field_id ^= 1;
441 /* Get field id from VPIF registers */
442 fid = vpif_channel_getfid(ch->channel_id);
443 if (fid != ch->field_id) {
444 /**
445 * If field id does not match stored
446 * field id, make them in sync
447 */
448 if (0 == fid)
449 ch->field_id = fid;
450 return IRQ_HANDLED;
451 }
452 }
453 /* device field id and local field id are in sync */
454 if (0 == fid) {
455 /* this is even field */
456 if (common->cur_frm == common->next_frm)
457 continue;
458
459 /* mark the current buffer as done */
460 vpif_process_buffer_complete(common);
461 } else if (1 == fid) {
462 /* odd field */
Hans Verkuilaec96832012-11-16 12:03:06 -0300463 spin_lock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300464 if (list_empty(&common->dma_queue) ||
Hans Verkuilaec96832012-11-16 12:03:06 -0300465 (common->cur_frm != common->next_frm)) {
466 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300467 continue;
Hans Verkuilaec96832012-11-16 12:03:06 -0300468 }
469 spin_unlock(&common->irqlock);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300470
471 vpif_schedule_next_buffer(common);
472 }
473 }
474 }
475 return IRQ_HANDLED;
476}
477
478/**
479 * vpif_update_std_info() - update standard related info
480 * @ch: ptr to channel object
481 *
482 * For a given standard selected by application, update values
483 * in the device data structures
484 */
485static int vpif_update_std_info(struct channel_obj *ch)
486{
487 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
488 struct vpif_params *vpifparams = &ch->vpifparams;
489 const struct vpif_channel_config_params *config;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300490 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300491 struct video_obj *vid_ch = &ch->video;
492 int index;
493
494 vpif_dbg(2, debug, "vpif_update_std_info\n");
495
Mats Randgaardaa444402010-12-16 12:17:42 -0300496 for (index = 0; index < vpif_ch_params_count; index++) {
Lad, Prabhakarced9b212013-03-20 01:28:27 -0300497 config = &vpif_ch_params[index];
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300498 if (config->hd_sd == 0) {
499 vpif_dbg(2, debug, "SD format\n");
500 if (config->stdid & vid_ch->stdid) {
501 memcpy(std_info, config, sizeof(*config));
502 break;
503 }
504 } else {
505 vpif_dbg(2, debug, "HD format\n");
Hans Verkuil0598c172012-09-18 07:18:47 -0300506 if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
507 sizeof(vid_ch->dv_timings))) {
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300508 memcpy(std_info, config, sizeof(*config));
509 break;
510 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300511 }
512 }
513
514 /* standard not found */
Mats Randgaardaa444402010-12-16 12:17:42 -0300515 if (index == vpif_ch_params_count)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300516 return -EINVAL;
517
518 common->fmt.fmt.pix.width = std_info->width;
519 common->width = std_info->width;
520 common->fmt.fmt.pix.height = std_info->height;
521 common->height = std_info->height;
522 common->fmt.fmt.pix.bytesperline = std_info->width;
523 vpifparams->video_params.hpitch = std_info->width;
524 vpifparams->video_params.storage_mode = std_info->frm_fmt;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300525
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300526 return 0;
527}
528
529/**
530 * vpif_calculate_offsets : This function calculates buffers offsets
531 * @ch : ptr to channel object
532 *
533 * This function calculates buffer offsets for Y and C in the top and
534 * bottom field
535 */
536static void vpif_calculate_offsets(struct channel_obj *ch)
537{
538 unsigned int hpitch, vpitch, sizeimage;
539 struct video_obj *vid_ch = &(ch->video);
540 struct vpif_params *vpifparams = &ch->vpifparams;
541 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
542 enum v4l2_field field = common->fmt.fmt.pix.field;
543
544 vpif_dbg(2, debug, "vpif_calculate_offsets\n");
545
546 if (V4L2_FIELD_ANY == field) {
547 if (vpifparams->std_info.frm_fmt)
548 vid_ch->buf_field = V4L2_FIELD_NONE;
549 else
550 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
551 } else
552 vid_ch->buf_field = common->fmt.fmt.pix.field;
553
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300554 sizeimage = common->fmt.fmt.pix.sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300555
556 hpitch = common->fmt.fmt.pix.bytesperline;
557 vpitch = sizeimage / (hpitch * 2);
558
559 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
560 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
561 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
562 common->ytop_off = 0;
563 common->ybtm_off = hpitch;
564 common->ctop_off = sizeimage / 2;
565 common->cbtm_off = sizeimage / 2 + hpitch;
566 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
567 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
568 common->ytop_off = 0;
569 common->ybtm_off = sizeimage / 4;
570 common->ctop_off = sizeimage / 2;
571 common->cbtm_off = common->ctop_off + sizeimage / 4;
572 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
573 /* Calculate offsets for Y top, Y Bottom, C top and C Bottom */
574 common->ybtm_off = 0;
575 common->ytop_off = sizeimage / 4;
576 common->cbtm_off = sizeimage / 2;
577 common->ctop_off = common->cbtm_off + sizeimage / 4;
578 }
579 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
580 (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
581 vpifparams->video_params.storage_mode = 1;
582 else
583 vpifparams->video_params.storage_mode = 0;
584
585 if (1 == vpifparams->std_info.frm_fmt)
586 vpifparams->video_params.hpitch =
587 common->fmt.fmt.pix.bytesperline;
588 else {
589 if ((field == V4L2_FIELD_ANY)
590 || (field == V4L2_FIELD_INTERLACED))
591 vpifparams->video_params.hpitch =
592 common->fmt.fmt.pix.bytesperline * 2;
593 else
594 vpifparams->video_params.hpitch =
595 common->fmt.fmt.pix.bytesperline;
596 }
597
598 ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
599}
600
601/**
602 * vpif_config_format: configure default frame format in the device
603 * ch : ptr to channel object
604 */
605static void vpif_config_format(struct channel_obj *ch)
606{
607 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
608
609 vpif_dbg(2, debug, "vpif_config_format\n");
610
611 common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -0300612 common->fmt.fmt.pix.sizeimage
613 = config_params.channel_bufsize[ch->channel_id];
614
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300615 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
616 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
617 else
618 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
619 common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
620}
621
622/**
623 * vpif_get_default_field() - Get default field type based on interface
624 * @vpif_params - ptr to vpif params
625 */
626static inline enum v4l2_field vpif_get_default_field(
627 struct vpif_interface *iface)
628{
629 return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
630 V4L2_FIELD_INTERLACED;
631}
632
633/**
634 * vpif_check_format() - check given pixel format for compatibility
635 * @ch - channel ptr
636 * @pixfmt - Given pixel format
637 * @update - update the values as per hardware requirement
638 *
639 * Check the application pixel format for S_FMT and update the input
640 * values as per hardware limits for TRY_FMT. The default pixel and
641 * field format is selected based on interface type.
642 */
643static int vpif_check_format(struct channel_obj *ch,
644 struct v4l2_pix_format *pixfmt,
645 int update)
646{
647 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
648 struct vpif_params *vpif_params = &ch->vpifparams;
649 enum v4l2_field field = pixfmt->field;
650 u32 sizeimage, hpitch, vpitch;
651 int ret = -EINVAL;
652
653 vpif_dbg(2, debug, "vpif_check_format\n");
654 /**
655 * first check for the pixel format. If if_type is Raw bayer,
656 * only V4L2_PIX_FMT_SBGGR8 format is supported. Otherwise only
657 * V4L2_PIX_FMT_YUV422P is supported
658 */
659 if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
660 if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8) {
661 if (!update) {
662 vpif_dbg(2, debug, "invalid pix format\n");
663 goto exit;
664 }
665 pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
666 }
667 } else {
668 if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) {
669 if (!update) {
670 vpif_dbg(2, debug, "invalid pixel format\n");
671 goto exit;
672 }
673 pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
674 }
675 }
676
677 if (!(VPIF_VALID_FIELD(field))) {
678 if (!update) {
679 vpif_dbg(2, debug, "invalid field format\n");
680 goto exit;
681 }
682 /**
683 * By default use FIELD_NONE for RAW Bayer capture
684 * and FIELD_INTERLACED for other interfaces
685 */
686 field = vpif_get_default_field(&vpif_params->iface);
687 } else if (field == V4L2_FIELD_ANY)
688 /* unsupported field. Use default */
689 field = vpif_get_default_field(&vpif_params->iface);
690
691 /* validate the hpitch */
692 hpitch = pixfmt->bytesperline;
693 if (hpitch < vpif_params->std_info.width) {
694 if (!update) {
695 vpif_dbg(2, debug, "invalid hpitch\n");
696 goto exit;
697 }
698 hpitch = vpif_params->std_info.width;
699 }
700
Lad, Prabhakar60aa38d2012-06-28 09:28:05 -0300701 sizeimage = pixfmt->sizeimage;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300702
703 vpitch = sizeimage / (hpitch * 2);
704
705 /* validate the vpitch */
706 if (vpitch < vpif_params->std_info.height) {
707 if (!update) {
708 vpif_dbg(2, debug, "Invalid vpitch\n");
709 goto exit;
710 }
711 vpitch = vpif_params->std_info.height;
712 }
713
714 /* Check for 8 byte alignment */
715 if (!ALIGN(hpitch, 8)) {
716 if (!update) {
717 vpif_dbg(2, debug, "invalid pitch alignment\n");
718 goto exit;
719 }
720 /* adjust to next 8 byte boundary */
721 hpitch = (((hpitch + 7) / 8) * 8);
722 }
723 /* if update is set, modify the bytesperline and sizeimage */
724 if (update) {
725 pixfmt->bytesperline = hpitch;
726 pixfmt->sizeimage = hpitch * vpitch * 2;
727 }
728 /**
729 * Image width and height is always based on current standard width and
730 * height
731 */
732 pixfmt->width = common->fmt.fmt.pix.width;
733 pixfmt->height = common->fmt.fmt.pix.height;
734 return 0;
735exit:
736 return ret;
737}
738
739/**
740 * vpif_config_addr() - function to configure buffer address in vpif
741 * @ch - channel ptr
742 * @muxmode - channel mux mode
743 */
744static void vpif_config_addr(struct channel_obj *ch, int muxmode)
745{
746 struct common_obj *common;
747
748 vpif_dbg(2, debug, "vpif_config_addr\n");
749
750 common = &(ch->common[VPIF_VIDEO_INDEX]);
751
752 if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
753 common->set_addr = ch1_set_videobuf_addr;
754 else if (2 == muxmode)
755 common->set_addr = ch0_set_videobuf_addr_yc_nmux;
756 else
757 common->set_addr = ch0_set_videobuf_addr;
758}
759
760/**
Hans Verkuil178cce12012-09-20 09:06:30 -0300761 * vpif_input_to_subdev() - Maps input to sub device
762 * @vpif_cfg - global config ptr
763 * @chan_cfg - channel config ptr
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300764 * @input_index - Given input index from application
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300765 *
766 * lookup the sub device information for a given input index.
767 * we report all the inputs to application. inputs table also
768 * has sub device name for the each input
769 */
Hans Verkuil178cce12012-09-20 09:06:30 -0300770static int vpif_input_to_subdev(
771 struct vpif_capture_config *vpif_cfg,
772 struct vpif_capture_chan_config *chan_cfg,
773 int input_index)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300774{
Hans Verkuil178cce12012-09-20 09:06:30 -0300775 struct vpif_subdev_info *subdev_info;
776 const char *subdev_name;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300777 int i;
778
Hans Verkuil178cce12012-09-20 09:06:30 -0300779 vpif_dbg(2, debug, "vpif_input_to_subdev\n");
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300780
Hans Verkuil178cce12012-09-20 09:06:30 -0300781 subdev_name = chan_cfg->inputs[input_index].subdev_name;
782 if (subdev_name == NULL)
783 return -1;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300784
785 /* loop through the sub device list to get the sub device info */
786 for (i = 0; i < vpif_cfg->subdev_count; i++) {
787 subdev_info = &vpif_cfg->subdev_info[i];
788 if (!strcmp(subdev_info->name, subdev_name))
Hans Verkuil178cce12012-09-20 09:06:30 -0300789 return i;
790 }
791 return -1;
792}
793
794/**
795 * vpif_set_input() - Select an input
796 * @vpif_cfg - global config ptr
797 * @ch - channel
798 * @_index - Given input index from application
799 *
800 * Select the given input.
801 */
802static int vpif_set_input(
803 struct vpif_capture_config *vpif_cfg,
804 struct channel_obj *ch,
805 int index)
806{
807 struct vpif_capture_chan_config *chan_cfg =
808 &vpif_cfg->chan_config[ch->channel_id];
809 struct vpif_subdev_info *subdev_info = NULL;
810 struct v4l2_subdev *sd = NULL;
811 u32 input = 0, output = 0;
812 int sd_index;
813 int ret;
814
815 sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
816 if (sd_index >= 0) {
817 sd = vpif_obj.sd[sd_index];
818 subdev_info = &vpif_cfg->subdev_info[sd_index];
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300819 }
820
Hans Verkuil178cce12012-09-20 09:06:30 -0300821 /* first setup input path from sub device to vpif */
822 if (sd && vpif_cfg->setup_input_path) {
823 ret = vpif_cfg->setup_input_path(ch->channel_id,
824 subdev_info->name);
825 if (ret < 0) {
826 vpif_dbg(1, debug, "couldn't setup input path for the" \
827 " sub device %s, for input index %d\n",
828 subdev_info->name, index);
829 return ret;
830 }
831 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300832
Hans Verkuil178cce12012-09-20 09:06:30 -0300833 if (sd) {
834 input = chan_cfg->inputs[index].input_route;
835 output = chan_cfg->inputs[index].output_route;
836 ret = v4l2_subdev_call(sd, video, s_routing,
837 input, output, 0);
838 if (ret < 0 && ret != -ENOIOCTLCMD) {
839 vpif_dbg(1, debug, "Failed to set input\n");
840 return ret;
841 }
842 }
843 ch->input_idx = index;
844 ch->sd = sd;
845 /* copy interface parameters to vpif */
Hans Verkuil0d4f35f2012-09-20 09:06:32 -0300846 ch->vpifparams.iface = chan_cfg->vpif_if;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300847
Hans Verkuil178cce12012-09-20 09:06:30 -0300848 /* update tvnorms from the sub device input info */
849 ch->video_dev->tvnorms = chan_cfg->inputs[index].input.std;
850 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300851}
852
853/**
854 * vpif_querystd() - querystd handler
855 * @file: file ptr
856 * @priv: file handle
857 * @std_id: ptr to std id
858 *
859 * This function is called to detect standard at the selected input
860 */
861static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
862{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300863 struct video_device *vdev = video_devdata(file);
864 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300865 int ret = 0;
866
867 vpif_dbg(2, debug, "vpif_querystd\n");
868
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300869 /* Call querystd function of decoder device */
Hans Verkuil178cce12012-09-20 09:06:30 -0300870 ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300871
Hans Verkuil178cce12012-09-20 09:06:30 -0300872 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
873 return -ENODATA;
874 if (ret) {
875 vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
876 return ret;
877 }
878
879 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300880}
881
882/**
883 * vpif_g_std() - get STD handler
884 * @file: file ptr
885 * @priv: file handle
886 * @std_id: ptr to std id
887 */
888static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
889{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300890 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300891 struct video_device *vdev = video_devdata(file);
892 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300893 struct vpif_capture_chan_config *chan_cfg;
894 struct v4l2_input input;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300895
896 vpif_dbg(2, debug, "vpif_g_std\n");
897
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300898 if (config->chan_config[ch->channel_id].inputs == NULL)
899 return -ENODATA;
900
901 chan_cfg = &config->chan_config[ch->channel_id];
902 input = chan_cfg->inputs[ch->input_idx].input;
903 if (input.capabilities != V4L2_IN_CAP_STD)
904 return -ENODATA;
905
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300906 *std = ch->video.stdid;
907 return 0;
908}
909
910/**
911 * vpif_s_std() - set STD handler
912 * @file: file ptr
913 * @priv: file handle
914 * @std_id: ptr to std id
915 */
Hans Verkuil314527a2013-03-15 06:10:40 -0300916static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300917{
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300918 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300919 struct video_device *vdev = video_devdata(file);
920 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300921 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300922 struct vpif_capture_chan_config *chan_cfg;
923 struct v4l2_input input;
924 int ret;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300925
926 vpif_dbg(2, debug, "vpif_s_std\n");
927
Lad, Prabhakard557b7d2014-05-16 10:33:52 -0300928 if (config->chan_config[ch->channel_id].inputs == NULL)
929 return -ENODATA;
930
931 chan_cfg = &config->chan_config[ch->channel_id];
932 input = chan_cfg->inputs[ch->input_idx].input;
933 if (input.capabilities != V4L2_IN_CAP_STD)
934 return -ENODATA;
935
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300936 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300937 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300938
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300939 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -0300940 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -0300941 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300942
943 /* Get the information about the standard */
944 if (vpif_update_std_info(ch)) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300945 vpif_err("Error getting the standard info\n");
Hans Verkuil46656af2011-01-04 06:51:35 -0300946 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300947 }
948
949 /* Configure the default format information */
950 vpif_config_format(ch);
951
952 /* set standard in the sub device */
Hans Verkuil314527a2013-03-15 06:10:40 -0300953 ret = v4l2_subdev_call(ch->sd, core, s_std, std_id);
Hans Verkuil178cce12012-09-20 09:06:30 -0300954 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300955 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
Hans Verkuil178cce12012-09-20 09:06:30 -0300956 return ret;
957 }
958 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300959}
960
961/**
962 * vpif_enum_input() - ENUMINPUT handler
963 * @file: file ptr
964 * @priv: file handle
965 * @input: ptr to input structure
966 */
967static int vpif_enum_input(struct file *file, void *priv,
968 struct v4l2_input *input)
969{
970
971 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300972 struct video_device *vdev = video_devdata(file);
973 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300974 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300975
976 chan_cfg = &config->chan_config[ch->channel_id];
977
978 if (input->index >= chan_cfg->input_count) {
979 vpif_dbg(1, debug, "Invalid input index\n");
980 return -EINVAL;
981 }
982
983 memcpy(input, &chan_cfg->inputs[input->index].input,
984 sizeof(*input));
985 return 0;
986}
987
988/**
989 * vpif_g_input() - Get INPUT handler
990 * @file: file ptr
991 * @priv: file handle
992 * @index: ptr to input index
993 */
994static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
995{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300996 struct video_device *vdev = video_devdata(file);
997 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300998
Hans Verkuil6f47c6c2012-09-20 09:06:22 -0300999 *index = ch->input_idx;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001000 return 0;
1001}
1002
1003/**
1004 * vpif_s_input() - Set INPUT handler
1005 * @file: file ptr
1006 * @priv: file handle
1007 * @index: input index
1008 */
1009static int vpif_s_input(struct file *file, void *priv, unsigned int index)
1010{
1011 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001012 struct video_device *vdev = video_devdata(file);
1013 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001014 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001015 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001016
1017 chan_cfg = &config->chan_config[ch->channel_id];
1018
Hans Verkuil7aaad132012-09-20 09:06:25 -03001019 if (index >= chan_cfg->input_count)
1020 return -EINVAL;
1021
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001022 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001023 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001024
Hans Verkuil178cce12012-09-20 09:06:30 -03001025 return vpif_set_input(config, ch, index);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001026}
1027
1028/**
1029 * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
1030 * @file: file ptr
1031 * @priv: file handle
1032 * @index: input index
1033 */
1034static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
1035 struct v4l2_fmtdesc *fmt)
1036{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001037 struct video_device *vdev = video_devdata(file);
1038 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001039
1040 if (fmt->index != 0) {
1041 vpif_dbg(1, debug, "Invalid format index\n");
1042 return -EINVAL;
1043 }
1044
1045 /* Fill in the information about format */
1046 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
1047 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1048 strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
1049 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
1050 } else {
1051 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1052 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
1053 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
1054 }
1055 return 0;
1056}
1057
1058/**
1059 * vpif_try_fmt_vid_cap() - TRY_FMT handler
1060 * @file: file ptr
1061 * @priv: file handle
1062 * @fmt: ptr to v4l2 format structure
1063 */
1064static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
1065 struct v4l2_format *fmt)
1066{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001067 struct video_device *vdev = video_devdata(file);
1068 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001069 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
1070
1071 return vpif_check_format(ch, pixfmt, 1);
1072}
1073
1074
1075/**
1076 * vpif_g_fmt_vid_cap() - Set INPUT handler
1077 * @file: file ptr
1078 * @priv: file handle
1079 * @fmt: ptr to v4l2 format structure
1080 */
1081static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
1082 struct v4l2_format *fmt)
1083{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001084 struct video_device *vdev = video_devdata(file);
1085 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001086 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1087
1088 /* Check the validity of the buffer type */
1089 if (common->fmt.type != fmt->type)
1090 return -EINVAL;
1091
1092 /* Fill in the information about format */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001093 *fmt = common->fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001094 return 0;
1095}
1096
1097/**
1098 * vpif_s_fmt_vid_cap() - Set FMT handler
1099 * @file: file ptr
1100 * @priv: file handle
1101 * @fmt: ptr to v4l2 format structure
1102 */
1103static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
1104 struct v4l2_format *fmt)
1105{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001106 struct video_device *vdev = video_devdata(file);
1107 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001108 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1109 struct v4l2_pix_format *pixfmt;
1110 int ret = 0;
1111
Mats Randgaard2c0ddd12010-12-16 12:17:45 -03001112 vpif_dbg(2, debug, "%s\n", __func__);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001113
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001114 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001115 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001116
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001117 pixfmt = &fmt->fmt.pix;
1118 /* Check for valid field format */
1119 ret = vpif_check_format(ch, pixfmt, 0);
1120
1121 if (ret)
1122 return ret;
1123 /* store the format in the channel object */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001124 common->fmt = *fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001125 return 0;
1126}
1127
1128/**
1129 * vpif_querycap() - QUERYCAP handler
1130 * @file: file ptr
1131 * @priv: file handle
1132 * @cap: ptr to v4l2_capability structure
1133 */
1134static int vpif_querycap(struct file *file, void *priv,
1135 struct v4l2_capability *cap)
1136{
1137 struct vpif_capture_config *config = vpif_dev->platform_data;
1138
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001139 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1140 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001141 strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001142 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1143 dev_name(vpif_dev));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001144 strlcpy(cap->card, config->card_name, sizeof(cap->card));
1145
1146 return 0;
1147}
1148
1149/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001150 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001151 * @file: file ptr
1152 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001153 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001154 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001155static int
1156vpif_enum_dv_timings(struct file *file, void *priv,
1157 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001158{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001159 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001160 struct video_device *vdev = video_devdata(file);
1161 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001162 struct vpif_capture_chan_config *chan_cfg;
1163 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001164 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001165
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001166 if (config->chan_config[ch->channel_id].inputs == NULL)
1167 return -ENODATA;
1168
1169 chan_cfg = &config->chan_config[ch->channel_id];
1170 input = chan_cfg->inputs[ch->input_idx].input;
1171 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1172 return -ENODATA;
1173
Hans Verkuil178cce12012-09-20 09:06:30 -03001174 ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001175 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001176 return -EINVAL;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001177
Hans Verkuil178cce12012-09-20 09:06:30 -03001178 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001179}
1180
1181/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001182 * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001183 * @file: file ptr
1184 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001185 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001186 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001187static int
1188vpif_query_dv_timings(struct file *file, void *priv,
1189 struct v4l2_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001190{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001191 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001192 struct video_device *vdev = video_devdata(file);
1193 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001194 struct vpif_capture_chan_config *chan_cfg;
1195 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001196 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001197
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001198 if (config->chan_config[ch->channel_id].inputs == NULL)
1199 return -ENODATA;
1200
1201 chan_cfg = &config->chan_config[ch->channel_id];
1202 input = chan_cfg->inputs[ch->input_idx].input;
1203 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1204 return -ENODATA;
1205
Hans Verkuil178cce12012-09-20 09:06:30 -03001206 ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001207 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001208 return -ENODATA;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001209
Hans Verkuil178cce12012-09-20 09:06:30 -03001210 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001211}
1212
Mats Randgaardc027e162010-12-16 12:17:44 -03001213/**
1214 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1215 * @file: file ptr
1216 * @priv: file handle
1217 * @timings: digital video timings
1218 */
1219static int vpif_s_dv_timings(struct file *file, void *priv,
1220 struct v4l2_dv_timings *timings)
1221{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001222 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001223 struct video_device *vdev = video_devdata(file);
1224 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001225 struct vpif_params *vpifparams = &ch->vpifparams;
1226 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001227 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Mats Randgaardc027e162010-12-16 12:17:44 -03001228 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001229 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001230 struct vpif_capture_chan_config *chan_cfg;
1231 struct v4l2_input input;
Mats Randgaardc027e162010-12-16 12:17:44 -03001232 int ret;
1233
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001234 if (config->chan_config[ch->channel_id].inputs == NULL)
1235 return -ENODATA;
1236
1237 chan_cfg = &config->chan_config[ch->channel_id];
1238 input = chan_cfg->inputs[ch->input_idx].input;
1239 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1240 return -ENODATA;
1241
Mats Randgaardc027e162010-12-16 12:17:44 -03001242 if (timings->type != V4L2_DV_BT_656_1120) {
1243 vpif_dbg(2, debug, "Timing type not defined\n");
1244 return -EINVAL;
1245 }
1246
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001247 if (vb2_is_busy(&common->buffer_queue))
1248 return -EBUSY;
1249
Mats Randgaardc027e162010-12-16 12:17:44 -03001250 /* Configure subdevice timings, if any */
Hans Verkuil178cce12012-09-20 09:06:30 -03001251 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
1252 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1253 ret = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001254 if (ret < 0) {
1255 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1256 return ret;
1257 }
1258
1259 if (!(timings->bt.width && timings->bt.height &&
1260 (timings->bt.hbackporch ||
1261 timings->bt.hfrontporch ||
1262 timings->bt.hsync) &&
1263 timings->bt.vfrontporch &&
1264 (timings->bt.vbackporch ||
1265 timings->bt.vsync))) {
1266 vpif_dbg(2, debug, "Timings for width, height, "
1267 "horizontal back porch, horizontal sync, "
1268 "horizontal front porch, vertical back porch, "
1269 "vertical sync and vertical back porch "
1270 "must be defined\n");
1271 return -EINVAL;
1272 }
1273
Hans Verkuil0598c172012-09-18 07:18:47 -03001274 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001275
1276 /* Configure video port timings */
1277
Hans Verkuile3655262013-07-29 08:41:00 -03001278 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001279 std_info->sav2eav = bt->width;
1280
1281 std_info->l1 = 1;
1282 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1283
Hans Verkuile3655262013-07-29 08:41:00 -03001284 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001285 if (bt->interlaced) {
1286 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001287 std_info->l5 = std_info->vsize/2 -
1288 (bt->vfrontporch - 1);
1289 std_info->l7 = std_info->vsize/2 + 1;
1290 std_info->l9 = std_info->l7 + bt->il_vsync +
1291 bt->il_vbackporch + 1;
1292 std_info->l11 = std_info->vsize -
1293 (bt->il_vfrontporch - 1);
1294 } else {
1295 vpif_dbg(2, debug, "Required timing values for "
1296 "interlaced BT format missing\n");
1297 return -EINVAL;
1298 }
1299 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001300 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1301 }
1302 strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1303 std_info->width = bt->width;
1304 std_info->height = bt->height;
1305 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1306 std_info->ycmux_mode = 0;
1307 std_info->capture_format = 0;
1308 std_info->vbi_supported = 0;
1309 std_info->hd_sd = 1;
1310 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001311
1312 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001313 return 0;
1314}
1315
1316/**
1317 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1318 * @file: file ptr
1319 * @priv: file handle
1320 * @timings: digital video timings
1321 */
1322static int vpif_g_dv_timings(struct file *file, void *priv,
1323 struct v4l2_dv_timings *timings)
1324{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001325 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001326 struct video_device *vdev = video_devdata(file);
1327 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001328 struct video_obj *vid_ch = &ch->video;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001329 struct vpif_capture_chan_config *chan_cfg;
1330 struct v4l2_input input;
1331
1332 if (config->chan_config[ch->channel_id].inputs == NULL)
1333 return -ENODATA;
1334
1335 chan_cfg = &config->chan_config[ch->channel_id];
1336 input = chan_cfg->inputs[ch->input_idx].input;
1337 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1338 return -ENODATA;
Mats Randgaardc027e162010-12-16 12:17:44 -03001339
Hans Verkuil0598c172012-09-18 07:18:47 -03001340 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001341
1342 return 0;
1343}
1344
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001345/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001346 * vpif_log_status() - Status information
1347 * @file: file ptr
1348 * @priv: file handle
1349 *
1350 * Returns zero.
1351 */
1352static int vpif_log_status(struct file *filep, void *priv)
1353{
1354 /* status for sub devices */
1355 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1356
1357 return 0;
1358}
1359
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001360/* vpif capture ioctl operations */
1361static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001362 .vidioc_querycap = vpif_querycap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001363 .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001364 .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001365 .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
1366 .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001367
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001368 .vidioc_enum_input = vpif_enum_input,
1369 .vidioc_s_input = vpif_s_input,
1370 .vidioc_g_input = vpif_g_input,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001371
1372 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1373 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1374 .vidioc_querybuf = vb2_ioctl_querybuf,
1375 .vidioc_qbuf = vb2_ioctl_qbuf,
1376 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1377 .vidioc_expbuf = vb2_ioctl_expbuf,
1378 .vidioc_streamon = vb2_ioctl_streamon,
1379 .vidioc_streamoff = vb2_ioctl_streamoff,
1380
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001381 .vidioc_querystd = vpif_querystd,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001382 .vidioc_s_std = vpif_s_std,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001383 .vidioc_g_std = vpif_g_std,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001384
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001385 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1386 .vidioc_query_dv_timings = vpif_query_dv_timings,
1387 .vidioc_s_dv_timings = vpif_s_dv_timings,
1388 .vidioc_g_dv_timings = vpif_g_dv_timings,
1389
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001390 .vidioc_log_status = vpif_log_status,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001391};
1392
1393/* vpif file operations */
1394static struct v4l2_file_operations vpif_fops = {
1395 .owner = THIS_MODULE,
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001396 .open = v4l2_fh_open,
1397 .release = vb2_fop_release,
Hans Verkuil46656af2011-01-04 06:51:35 -03001398 .unlocked_ioctl = video_ioctl2,
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001399 .mmap = vb2_fop_mmap,
1400 .poll = vb2_fop_poll
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001401};
1402
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001403/**
1404 * initialize_vpif() - Initialize vpif data structures
1405 *
1406 * Allocate memory for data structures and initialize them
1407 */
1408static int initialize_vpif(void)
1409{
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001410 int err = 0, i, j;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001411 int free_channel_objects_index;
1412
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001413 /* Default number of buffers should be 3 */
1414 if ((ch0_numbuffers > 0) &&
1415 (ch0_numbuffers < config_params.min_numbuffers))
1416 ch0_numbuffers = config_params.min_numbuffers;
1417 if ((ch1_numbuffers > 0) &&
1418 (ch1_numbuffers < config_params.min_numbuffers))
1419 ch1_numbuffers = config_params.min_numbuffers;
1420
1421 /* Set buffer size to min buffers size if it is invalid */
1422 if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
1423 ch0_bufsize =
1424 config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
1425 if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
1426 ch1_bufsize =
1427 config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
1428
1429 config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
1430 config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
1431 if (ch0_numbuffers) {
1432 config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
1433 = ch0_bufsize;
1434 }
1435 if (ch1_numbuffers) {
1436 config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
1437 = ch1_bufsize;
1438 }
1439
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001440 /* Allocate memory for six channel objects */
1441 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1442 vpif_obj.dev[i] =
1443 kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
1444 /* If memory allocation fails, return error */
1445 if (!vpif_obj.dev[i]) {
1446 free_channel_objects_index = i;
1447 err = -ENOMEM;
1448 goto vpif_init_free_channel_objects;
1449 }
1450 }
1451 return 0;
1452
1453vpif_init_free_channel_objects:
1454 for (j = 0; j < free_channel_objects_index; j++)
1455 kfree(vpif_obj.dev[j]);
1456 return err;
1457}
1458
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001459static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1460 struct v4l2_subdev *subdev,
1461 struct v4l2_async_subdev *asd)
1462{
1463 int i;
1464
1465 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1466 if (!strcmp(vpif_obj.config->subdev_info[i].name,
1467 subdev->name)) {
1468 vpif_obj.sd[i] = subdev;
1469 return 0;
1470 }
1471
1472 return -EINVAL;
1473}
1474
1475static int vpif_probe_complete(void)
1476{
1477 struct common_obj *common;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001478 struct video_device *vdev;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001479 struct channel_obj *ch;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001480 struct vb2_queue *q;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001481 int i, j, err, k;
1482
1483 for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
1484 ch = vpif_obj.dev[j];
1485 ch->channel_id = j;
1486 common = &(ch->common[VPIF_VIDEO_INDEX]);
1487 spin_lock_init(&common->irqlock);
1488 mutex_init(&common->lock);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001489
1490 /* select input 0 */
1491 err = vpif_set_input(vpif_obj.config, ch, 0);
1492 if (err)
1493 goto probe_out;
1494
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001495 /* Initialize vb2 queue */
1496 q = &common->buffer_queue;
1497 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1498 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1499 q->drv_priv = ch;
1500 q->ops = &video_qops;
1501 q->mem_ops = &vb2_dma_contig_memops;
1502 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1503 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1504 q->min_buffers_needed = 1;
Lad, Prabhakar999ba692014-05-16 10:33:33 -03001505 q->lock = &common->lock;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001506
1507 err = vb2_queue_init(q);
1508 if (err) {
1509 vpif_err("vpif_capture: vb2_queue_init() failed\n");
1510 goto probe_out;
1511 }
1512
1513 common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
1514 if (IS_ERR(common->alloc_ctx)) {
1515 vpif_err("Failed to get the context\n");
1516 err = PTR_ERR(common->alloc_ctx);
1517 goto probe_out;
1518 }
1519
1520 INIT_LIST_HEAD(&common->dma_queue);
1521
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001522 /* Initialize the video_device structure */
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001523 vdev = ch->video_dev;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001524 strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
1525 vdev->release = video_device_release;
1526 vdev->fops = &vpif_fops;
1527 vdev->ioctl_ops = &vpif_ioctl_ops;
1528 vdev->v4l2_dev = &vpif_obj.v4l2_dev;
1529 vdev->vfl_dir = VFL_DIR_RX;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001530 vdev->queue = q;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001531 vdev->lock = &common->lock;
1532 set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1533 video_set_drvdata(ch->video_dev, ch);
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001534 err = video_register_device(vdev,
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001535 VFL_TYPE_GRABBER, (j ? 1 : 0));
1536 if (err)
1537 goto probe_out;
1538 }
1539
1540 v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
1541 return 0;
1542
1543probe_out:
1544 for (k = 0; k < j; k++) {
1545 /* Get the pointer to the channel object */
1546 ch = vpif_obj.dev[k];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001547 common = &ch->common[k];
1548 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001549 /* Unregister video device */
1550 video_unregister_device(ch->video_dev);
1551 }
1552 kfree(vpif_obj.sd);
1553 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1554 ch = vpif_obj.dev[i];
1555 /* Note: does nothing if ch->video_dev == NULL */
1556 video_device_release(ch->video_dev);
1557 }
1558 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1559
1560 return err;
1561}
1562
1563static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1564{
1565 return vpif_probe_complete();
1566}
1567
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001568/**
1569 * vpif_probe : This function probes the vpif capture driver
1570 * @pdev: platform device pointer
1571 *
1572 * This creates device entries by register itself to the V4L2 driver and
1573 * initializes fields of each channel objects
1574 */
1575static __init int vpif_probe(struct platform_device *pdev)
1576{
1577 struct vpif_subdev_info *subdevdata;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001578 int i, j, err;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001579 int res_idx = 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001580 struct i2c_adapter *i2c_adap;
1581 struct channel_obj *ch;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001582 struct video_device *vfd;
1583 struct resource *res;
1584 int subdev_count;
1585
1586 vpif_dev = &pdev->dev;
1587
1588 err = initialize_vpif();
1589 if (err) {
1590 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1591 return err;
1592 }
1593
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001594 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1595 if (err) {
1596 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1597 return err;
1598 }
1599
Hans Verkuil5be452c2012-09-20 09:06:29 -03001600 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001601 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001602 IRQF_SHARED, VPIF_DRIVER_NAME,
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001603 (void *)(&vpif_obj.dev[res_idx]->
1604 channel_id));
1605 if (err) {
1606 err = -EINVAL;
1607 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001608 }
Hans Verkuil5be452c2012-09-20 09:06:29 -03001609 res_idx++;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001610 }
1611
1612 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1613 /* Get the pointer to the channel object */
1614 ch = vpif_obj.dev[i];
1615 /* Allocate memory for video device */
1616 vfd = video_device_alloc();
1617 if (NULL == vfd) {
1618 for (j = 0; j < i; j++) {
1619 ch = vpif_obj.dev[j];
1620 video_device_release(ch->video_dev);
1621 }
1622 err = -ENOMEM;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001623 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001624 }
1625
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001626 /* Set video_dev to the video device */
1627 ch->video_dev = vfd;
1628 }
1629
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001630 vpif_obj.config = pdev->dev.platform_data;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001631
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001632 subdev_count = vpif_obj.config->subdev_count;
Mats Randgaard1f8766b2010-08-30 10:30:37 -03001633 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001634 GFP_KERNEL);
1635 if (vpif_obj.sd == NULL) {
1636 vpif_err("unable to allocate memory for subdevice pointers\n");
1637 err = -ENOMEM;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001638 goto vpif_sd_error;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001639 }
1640
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001641 if (!vpif_obj.config->asd_sizes) {
1642 i2c_adap = i2c_get_adapter(1);
1643 for (i = 0; i < subdev_count; i++) {
1644 subdevdata = &vpif_obj.config->subdev_info[i];
1645 vpif_obj.sd[i] =
1646 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1647 i2c_adap,
1648 &subdevdata->
1649 board_info,
1650 NULL);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001651
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001652 if (!vpif_obj.sd[i]) {
1653 vpif_err("Error registering v4l2 subdevice\n");
Wei Yongjun2fcd9dc2013-09-02 05:06:10 -03001654 err = -ENODEV;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001655 goto probe_subdev_out;
1656 }
1657 v4l2_info(&vpif_obj.v4l2_dev,
1658 "registered sub device %s\n",
1659 subdevdata->name);
1660 }
1661 vpif_probe_complete();
1662 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001663 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001664 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1665 vpif_obj.notifier.bound = vpif_async_bound;
1666 vpif_obj.notifier.complete = vpif_async_complete;
1667 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1668 &vpif_obj.notifier);
1669 if (err) {
1670 vpif_err("Error registering async notifier\n");
1671 err = -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001672 goto probe_subdev_out;
1673 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001674 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001675
1676 return 0;
1677
Hans Verkuilb65814e2012-09-20 09:06:26 -03001678probe_subdev_out:
1679 /* free sub devices memory */
1680 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001681
Hans Verkuil5be452c2012-09-20 09:06:29 -03001682vpif_sd_error:
1683 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1684 ch = vpif_obj.dev[i];
1685 /* Note: does nothing if ch->video_dev == NULL */
1686 video_device_release(ch->video_dev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001687 }
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001688vpif_unregister:
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001689 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001690
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001691 return err;
1692}
1693
1694/**
1695 * vpif_remove() - driver remove handler
1696 * @device: ptr to platform device structure
1697 *
1698 * The vidoe device is unregistered
1699 */
1700static int vpif_remove(struct platform_device *device)
1701{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001702 struct common_obj *common;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001703 struct channel_obj *ch;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001704 int i;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001705
1706 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1707
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001708 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001709 /* un-register device */
1710 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1711 /* Get the pointer to the channel object */
1712 ch = vpif_obj.dev[i];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001713 common = &ch->common[i];
1714 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001715 /* Unregister video device */
1716 video_unregister_device(ch->video_dev);
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001717 kfree(vpif_obj.dev[i]);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001718 }
1719 return 0;
1720}
1721
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001722#ifdef CONFIG_PM_SLEEP
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001723/**
1724 * vpif_suspend: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001725 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001726static int vpif_suspend(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001727{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001728
1729 struct common_obj *common;
1730 struct channel_obj *ch;
1731 int i;
1732
1733 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1734 /* Get the pointer to the channel object */
1735 ch = vpif_obj.dev[i];
1736 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001737
1738 if (!vb2_is_streaming(&common->buffer_queue))
1739 continue;
1740
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001741 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001742 /* Disable channel */
1743 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1744 enable_channel0(0);
1745 channel0_intr_enable(0);
1746 }
1747 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1748 ycmux_mode == 2) {
1749 enable_channel1(0);
1750 channel1_intr_enable(0);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001751 }
1752 mutex_unlock(&common->lock);
1753 }
1754
1755 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001756}
1757
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001758/*
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001759 * vpif_resume: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001760 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001761static int vpif_resume(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001762{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001763 struct common_obj *common;
1764 struct channel_obj *ch;
1765 int i;
1766
1767 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1768 /* Get the pointer to the channel object */
1769 ch = vpif_obj.dev[i];
1770 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001771
1772 if (!vb2_is_streaming(&common->buffer_queue))
1773 continue;
1774
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001775 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001776 /* Enable channel */
1777 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1778 enable_channel0(1);
1779 channel0_intr_enable(1);
1780 }
1781 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1782 ycmux_mode == 2) {
1783 enable_channel1(1);
1784 channel1_intr_enable(1);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001785 }
1786 mutex_unlock(&common->lock);
1787 }
1788
1789 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001790}
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001791#endif
1792
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001793static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
1794
Mats Randgaardffa1b392010-08-30 10:30:36 -03001795static __refdata struct platform_driver vpif_driver = {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001796 .driver = {
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001797 .name = VPIF_DRIVER_NAME,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001798 .owner = THIS_MODULE,
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001799 .pm = &vpif_pm_ops,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001800 },
1801 .probe = vpif_probe,
1802 .remove = vpif_remove,
1803};
1804
Lad, Prabhakarfe424b22013-06-17 11:20:45 -03001805module_platform_driver(vpif_driver);