blob: 54343a3c7b739fb6e92f35c5c46a5e43aaee8076 [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, Prabhakar7ff51192014-05-16 10:33:41 -0300890 struct video_device *vdev = video_devdata(file);
891 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300892
893 vpif_dbg(2, debug, "vpif_g_std\n");
894
895 *std = ch->video.stdid;
896 return 0;
897}
898
899/**
900 * vpif_s_std() - set STD handler
901 * @file: file ptr
902 * @priv: file handle
903 * @std_id: ptr to std id
904 */
Hans Verkuil314527a2013-03-15 06:10:40 -0300905static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300906{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300907 struct video_device *vdev = video_devdata(file);
908 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300909 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
910 int ret = 0;
911
912 vpif_dbg(2, debug, "vpif_s_std\n");
913
Lad, Prabhakarc66238f2014-05-16 10:33:45 -0300914 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300915 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300916
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300917 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -0300918 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -0300919 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300920
921 /* Get the information about the standard */
922 if (vpif_update_std_info(ch)) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300923 vpif_err("Error getting the standard info\n");
Hans Verkuil46656af2011-01-04 06:51:35 -0300924 return -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300925 }
926
927 /* Configure the default format information */
928 vpif_config_format(ch);
929
930 /* set standard in the sub device */
Hans Verkuil314527a2013-03-15 06:10:40 -0300931 ret = v4l2_subdev_call(ch->sd, core, s_std, std_id);
Hans Verkuil178cce12012-09-20 09:06:30 -0300932 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300933 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
Hans Verkuil178cce12012-09-20 09:06:30 -0300934 return ret;
935 }
936 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300937}
938
939/**
940 * vpif_enum_input() - ENUMINPUT handler
941 * @file: file ptr
942 * @priv: file handle
943 * @input: ptr to input structure
944 */
945static int vpif_enum_input(struct file *file, void *priv,
946 struct v4l2_input *input)
947{
948
949 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300950 struct video_device *vdev = video_devdata(file);
951 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300952 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300953
954 chan_cfg = &config->chan_config[ch->channel_id];
955
956 if (input->index >= chan_cfg->input_count) {
957 vpif_dbg(1, debug, "Invalid input index\n");
958 return -EINVAL;
959 }
960
961 memcpy(input, &chan_cfg->inputs[input->index].input,
962 sizeof(*input));
963 return 0;
964}
965
966/**
967 * vpif_g_input() - Get INPUT handler
968 * @file: file ptr
969 * @priv: file handle
970 * @index: ptr to input index
971 */
972static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
973{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300974 struct video_device *vdev = video_devdata(file);
975 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300976
Hans Verkuil6f47c6c2012-09-20 09:06:22 -0300977 *index = ch->input_idx;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300978 return 0;
979}
980
981/**
982 * vpif_s_input() - Set INPUT handler
983 * @file: file ptr
984 * @priv: file handle
985 * @index: input index
986 */
987static int vpif_s_input(struct file *file, void *priv, unsigned int index)
988{
989 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300990 struct video_device *vdev = video_devdata(file);
991 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300992 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar7ff51192014-05-16 10:33:41 -0300993 struct vpif_capture_chan_config *chan_cfg;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -0300994
995 chan_cfg = &config->chan_config[ch->channel_id];
996
Hans Verkuil7aaad132012-09-20 09:06:25 -0300997 if (index >= chan_cfg->input_count)
998 return -EINVAL;
999
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001000 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001001 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001002
Hans Verkuil178cce12012-09-20 09:06:30 -03001003 return vpif_set_input(config, ch, index);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001004}
1005
1006/**
1007 * vpif_enum_fmt_vid_cap() - ENUM_FMT handler
1008 * @file: file ptr
1009 * @priv: file handle
1010 * @index: input index
1011 */
1012static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
1013 struct v4l2_fmtdesc *fmt)
1014{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001015 struct video_device *vdev = video_devdata(file);
1016 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001017
1018 if (fmt->index != 0) {
1019 vpif_dbg(1, debug, "Invalid format index\n");
1020 return -EINVAL;
1021 }
1022
1023 /* Fill in the information about format */
1024 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
1025 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1026 strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
1027 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
1028 } else {
1029 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1030 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
1031 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
1032 }
1033 return 0;
1034}
1035
1036/**
1037 * vpif_try_fmt_vid_cap() - TRY_FMT handler
1038 * @file: file ptr
1039 * @priv: file handle
1040 * @fmt: ptr to v4l2 format structure
1041 */
1042static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
1043 struct v4l2_format *fmt)
1044{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001045 struct video_device *vdev = video_devdata(file);
1046 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001047 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
1048
1049 return vpif_check_format(ch, pixfmt, 1);
1050}
1051
1052
1053/**
1054 * vpif_g_fmt_vid_cap() - Set INPUT handler
1055 * @file: file ptr
1056 * @priv: file handle
1057 * @fmt: ptr to v4l2 format structure
1058 */
1059static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
1060 struct v4l2_format *fmt)
1061{
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001062 struct video_device *vdev = video_devdata(file);
1063 struct channel_obj *ch = video_get_drvdata(vdev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001064 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1065
1066 /* Check the validity of the buffer type */
1067 if (common->fmt.type != fmt->type)
1068 return -EINVAL;
1069
1070 /* Fill in the information about format */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001071 *fmt = common->fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001072 return 0;
1073}
1074
1075/**
1076 * vpif_s_fmt_vid_cap() - Set FMT handler
1077 * @file: file ptr
1078 * @priv: file handle
1079 * @fmt: ptr to v4l2 format structure
1080 */
1081static int vpif_s_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 struct v4l2_pix_format *pixfmt;
1088 int ret = 0;
1089
Mats Randgaard2c0ddd12010-12-16 12:17:45 -03001090 vpif_dbg(2, debug, "%s\n", __func__);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001091
Lad, Prabhakarc66238f2014-05-16 10:33:45 -03001092 if (vb2_is_busy(&common->buffer_queue))
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001093 return -EBUSY;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001094
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001095 pixfmt = &fmt->fmt.pix;
1096 /* Check for valid field format */
1097 ret = vpif_check_format(ch, pixfmt, 0);
1098
1099 if (ret)
1100 return ret;
1101 /* store the format in the channel object */
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001102 common->fmt = *fmt;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001103 return 0;
1104}
1105
1106/**
1107 * vpif_querycap() - QUERYCAP handler
1108 * @file: file ptr
1109 * @priv: file handle
1110 * @cap: ptr to v4l2_capability structure
1111 */
1112static int vpif_querycap(struct file *file, void *priv,
1113 struct v4l2_capability *cap)
1114{
1115 struct vpif_capture_config *config = vpif_dev->platform_data;
1116
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001117 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1118 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001119 strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
Lad, Prabhakar626d533f2012-09-25 11:21:55 -03001120 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1121 dev_name(vpif_dev));
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001122 strlcpy(cap->card, config->card_name, sizeof(cap->card));
1123
1124 return 0;
1125}
1126
1127/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001128 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001129 * @file: file ptr
1130 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001131 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001132 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001133static int
1134vpif_enum_dv_timings(struct file *file, void *priv,
1135 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001136{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001137 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001138 struct video_device *vdev = video_devdata(file);
1139 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001140 struct vpif_capture_chan_config *chan_cfg;
1141 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001142 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001143
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001144 if (config->chan_config[ch->channel_id].inputs == NULL)
1145 return -ENODATA;
1146
1147 chan_cfg = &config->chan_config[ch->channel_id];
1148 input = chan_cfg->inputs[ch->input_idx].input;
1149 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1150 return -ENODATA;
1151
Hans Verkuil178cce12012-09-20 09:06:30 -03001152 ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001153 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001154 return -EINVAL;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001155
Hans Verkuil178cce12012-09-20 09:06:30 -03001156 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001157}
1158
1159/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001160 * vpif_query_dv_timings() - QUERY_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001161 * @file: file ptr
1162 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001163 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001164 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001165static int
1166vpif_query_dv_timings(struct file *file, void *priv,
1167 struct v4l2_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001168{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001169 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001170 struct video_device *vdev = video_devdata(file);
1171 struct channel_obj *ch = video_get_drvdata(vdev);
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001172 struct vpif_capture_chan_config *chan_cfg;
1173 struct v4l2_input input;
Hans Verkuil178cce12012-09-20 09:06:30 -03001174 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001175
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001176 if (config->chan_config[ch->channel_id].inputs == NULL)
1177 return -ENODATA;
1178
1179 chan_cfg = &config->chan_config[ch->channel_id];
1180 input = chan_cfg->inputs[ch->input_idx].input;
1181 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1182 return -ENODATA;
1183
Hans Verkuil178cce12012-09-20 09:06:30 -03001184 ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
Wei Yongjune070f1b2012-10-30 09:45:00 -03001185 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Hans Verkuil178cce12012-09-20 09:06:30 -03001186 return -ENODATA;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001187
Hans Verkuil178cce12012-09-20 09:06:30 -03001188 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001189}
1190
Mats Randgaardc027e162010-12-16 12:17:44 -03001191/**
1192 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1193 * @file: file ptr
1194 * @priv: file handle
1195 * @timings: digital video timings
1196 */
1197static int vpif_s_dv_timings(struct file *file, void *priv,
1198 struct v4l2_dv_timings *timings)
1199{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001200 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001201 struct video_device *vdev = video_devdata(file);
1202 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001203 struct vpif_params *vpifparams = &ch->vpifparams;
1204 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001205 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Mats Randgaardc027e162010-12-16 12:17:44 -03001206 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001207 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001208 struct vpif_capture_chan_config *chan_cfg;
1209 struct v4l2_input input;
Mats Randgaardc027e162010-12-16 12:17:44 -03001210 int ret;
1211
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001212 if (config->chan_config[ch->channel_id].inputs == NULL)
1213 return -ENODATA;
1214
1215 chan_cfg = &config->chan_config[ch->channel_id];
1216 input = chan_cfg->inputs[ch->input_idx].input;
1217 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1218 return -ENODATA;
1219
Mats Randgaardc027e162010-12-16 12:17:44 -03001220 if (timings->type != V4L2_DV_BT_656_1120) {
1221 vpif_dbg(2, debug, "Timing type not defined\n");
1222 return -EINVAL;
1223 }
1224
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001225 if (vb2_is_busy(&common->buffer_queue))
1226 return -EBUSY;
1227
Mats Randgaardc027e162010-12-16 12:17:44 -03001228 /* Configure subdevice timings, if any */
Hans Verkuil178cce12012-09-20 09:06:30 -03001229 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
1230 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1231 ret = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001232 if (ret < 0) {
1233 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1234 return ret;
1235 }
1236
1237 if (!(timings->bt.width && timings->bt.height &&
1238 (timings->bt.hbackporch ||
1239 timings->bt.hfrontporch ||
1240 timings->bt.hsync) &&
1241 timings->bt.vfrontporch &&
1242 (timings->bt.vbackporch ||
1243 timings->bt.vsync))) {
1244 vpif_dbg(2, debug, "Timings for width, height, "
1245 "horizontal back porch, horizontal sync, "
1246 "horizontal front porch, vertical back porch, "
1247 "vertical sync and vertical back porch "
1248 "must be defined\n");
1249 return -EINVAL;
1250 }
1251
Hans Verkuil0598c172012-09-18 07:18:47 -03001252 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001253
1254 /* Configure video port timings */
1255
Hans Verkuile3655262013-07-29 08:41:00 -03001256 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001257 std_info->sav2eav = bt->width;
1258
1259 std_info->l1 = 1;
1260 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1261
Hans Verkuile3655262013-07-29 08:41:00 -03001262 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001263 if (bt->interlaced) {
1264 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001265 std_info->l5 = std_info->vsize/2 -
1266 (bt->vfrontporch - 1);
1267 std_info->l7 = std_info->vsize/2 + 1;
1268 std_info->l9 = std_info->l7 + bt->il_vsync +
1269 bt->il_vbackporch + 1;
1270 std_info->l11 = std_info->vsize -
1271 (bt->il_vfrontporch - 1);
1272 } else {
1273 vpif_dbg(2, debug, "Required timing values for "
1274 "interlaced BT format missing\n");
1275 return -EINVAL;
1276 }
1277 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001278 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1279 }
1280 strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1281 std_info->width = bt->width;
1282 std_info->height = bt->height;
1283 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1284 std_info->ycmux_mode = 0;
1285 std_info->capture_format = 0;
1286 std_info->vbi_supported = 0;
1287 std_info->hd_sd = 1;
1288 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001289
1290 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001291 return 0;
1292}
1293
1294/**
1295 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1296 * @file: file ptr
1297 * @priv: file handle
1298 * @timings: digital video timings
1299 */
1300static int vpif_g_dv_timings(struct file *file, void *priv,
1301 struct v4l2_dv_timings *timings)
1302{
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001303 struct vpif_capture_config *config = vpif_dev->platform_data;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001304 struct video_device *vdev = video_devdata(file);
1305 struct channel_obj *ch = video_get_drvdata(vdev);
Mats Randgaardc027e162010-12-16 12:17:44 -03001306 struct video_obj *vid_ch = &ch->video;
Lad, Prabhakar1e8852af2014-05-16 10:33:51 -03001307 struct vpif_capture_chan_config *chan_cfg;
1308 struct v4l2_input input;
1309
1310 if (config->chan_config[ch->channel_id].inputs == NULL)
1311 return -ENODATA;
1312
1313 chan_cfg = &config->chan_config[ch->channel_id];
1314 input = chan_cfg->inputs[ch->input_idx].input;
1315 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1316 return -ENODATA;
Mats Randgaardc027e162010-12-16 12:17:44 -03001317
Hans Verkuil0598c172012-09-18 07:18:47 -03001318 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001319
1320 return 0;
1321}
1322
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001323/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001324 * vpif_log_status() - Status information
1325 * @file: file ptr
1326 * @priv: file handle
1327 *
1328 * Returns zero.
1329 */
1330static int vpif_log_status(struct file *filep, void *priv)
1331{
1332 /* status for sub devices */
1333 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1334
1335 return 0;
1336}
1337
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001338/* vpif capture ioctl operations */
1339static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001340 .vidioc_querycap = vpif_querycap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001341 .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001342 .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001343 .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
1344 .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001345
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001346 .vidioc_enum_input = vpif_enum_input,
1347 .vidioc_s_input = vpif_s_input,
1348 .vidioc_g_input = vpif_g_input,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001349
1350 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1351 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1352 .vidioc_querybuf = vb2_ioctl_querybuf,
1353 .vidioc_qbuf = vb2_ioctl_qbuf,
1354 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1355 .vidioc_expbuf = vb2_ioctl_expbuf,
1356 .vidioc_streamon = vb2_ioctl_streamon,
1357 .vidioc_streamoff = vb2_ioctl_streamoff,
1358
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001359 .vidioc_querystd = vpif_querystd,
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001360 .vidioc_s_std = vpif_s_std,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001361 .vidioc_g_std = vpif_g_std,
Lad, Prabhakard9a3b132014-05-16 10:33:42 -03001362
Lad, Prabhakar7b4657f2014-05-16 10:33:49 -03001363 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1364 .vidioc_query_dv_timings = vpif_query_dv_timings,
1365 .vidioc_s_dv_timings = vpif_s_dv_timings,
1366 .vidioc_g_dv_timings = vpif_g_dv_timings,
1367
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001368 .vidioc_log_status = vpif_log_status,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001369};
1370
1371/* vpif file operations */
1372static struct v4l2_file_operations vpif_fops = {
1373 .owner = THIS_MODULE,
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001374 .open = v4l2_fh_open,
1375 .release = vb2_fop_release,
Hans Verkuil46656af2011-01-04 06:51:35 -03001376 .unlocked_ioctl = video_ioctl2,
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001377 .mmap = vb2_fop_mmap,
1378 .poll = vb2_fop_poll
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001379};
1380
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001381/**
1382 * initialize_vpif() - Initialize vpif data structures
1383 *
1384 * Allocate memory for data structures and initialize them
1385 */
1386static int initialize_vpif(void)
1387{
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001388 int err = 0, i, j;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001389 int free_channel_objects_index;
1390
Mauro Carvalho Chehabea06cc52014-05-24 16:32:44 -03001391 /* Default number of buffers should be 3 */
1392 if ((ch0_numbuffers > 0) &&
1393 (ch0_numbuffers < config_params.min_numbuffers))
1394 ch0_numbuffers = config_params.min_numbuffers;
1395 if ((ch1_numbuffers > 0) &&
1396 (ch1_numbuffers < config_params.min_numbuffers))
1397 ch1_numbuffers = config_params.min_numbuffers;
1398
1399 /* Set buffer size to min buffers size if it is invalid */
1400 if (ch0_bufsize < config_params.min_bufsize[VPIF_CHANNEL0_VIDEO])
1401 ch0_bufsize =
1402 config_params.min_bufsize[VPIF_CHANNEL0_VIDEO];
1403 if (ch1_bufsize < config_params.min_bufsize[VPIF_CHANNEL1_VIDEO])
1404 ch1_bufsize =
1405 config_params.min_bufsize[VPIF_CHANNEL1_VIDEO];
1406
1407 config_params.numbuffers[VPIF_CHANNEL0_VIDEO] = ch0_numbuffers;
1408 config_params.numbuffers[VPIF_CHANNEL1_VIDEO] = ch1_numbuffers;
1409 if (ch0_numbuffers) {
1410 config_params.channel_bufsize[VPIF_CHANNEL0_VIDEO]
1411 = ch0_bufsize;
1412 }
1413 if (ch1_numbuffers) {
1414 config_params.channel_bufsize[VPIF_CHANNEL1_VIDEO]
1415 = ch1_bufsize;
1416 }
1417
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001418 /* Allocate memory for six channel objects */
1419 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1420 vpif_obj.dev[i] =
1421 kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
1422 /* If memory allocation fails, return error */
1423 if (!vpif_obj.dev[i]) {
1424 free_channel_objects_index = i;
1425 err = -ENOMEM;
1426 goto vpif_init_free_channel_objects;
1427 }
1428 }
1429 return 0;
1430
1431vpif_init_free_channel_objects:
1432 for (j = 0; j < free_channel_objects_index; j++)
1433 kfree(vpif_obj.dev[j]);
1434 return err;
1435}
1436
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001437static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1438 struct v4l2_subdev *subdev,
1439 struct v4l2_async_subdev *asd)
1440{
1441 int i;
1442
1443 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1444 if (!strcmp(vpif_obj.config->subdev_info[i].name,
1445 subdev->name)) {
1446 vpif_obj.sd[i] = subdev;
1447 return 0;
1448 }
1449
1450 return -EINVAL;
1451}
1452
1453static int vpif_probe_complete(void)
1454{
1455 struct common_obj *common;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001456 struct video_device *vdev;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001457 struct channel_obj *ch;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001458 struct vb2_queue *q;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001459 int i, j, err, k;
1460
1461 for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
1462 ch = vpif_obj.dev[j];
1463 ch->channel_id = j;
1464 common = &(ch->common[VPIF_VIDEO_INDEX]);
1465 spin_lock_init(&common->irqlock);
1466 mutex_init(&common->lock);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001467
1468 /* select input 0 */
1469 err = vpif_set_input(vpif_obj.config, ch, 0);
1470 if (err)
1471 goto probe_out;
1472
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001473 /* Initialize vb2 queue */
1474 q = &common->buffer_queue;
1475 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1476 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1477 q->drv_priv = ch;
1478 q->ops = &video_qops;
1479 q->mem_ops = &vb2_dma_contig_memops;
1480 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1481 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1482 q->min_buffers_needed = 1;
Lad, Prabhakar999ba692014-05-16 10:33:33 -03001483 q->lock = &common->lock;
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001484
1485 err = vb2_queue_init(q);
1486 if (err) {
1487 vpif_err("vpif_capture: vb2_queue_init() failed\n");
1488 goto probe_out;
1489 }
1490
1491 common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
1492 if (IS_ERR(common->alloc_ctx)) {
1493 vpif_err("Failed to get the context\n");
1494 err = PTR_ERR(common->alloc_ctx);
1495 goto probe_out;
1496 }
1497
1498 INIT_LIST_HEAD(&common->dma_queue);
1499
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001500 /* Initialize the video_device structure */
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001501 vdev = ch->video_dev;
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001502 strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
1503 vdev->release = video_device_release;
1504 vdev->fops = &vpif_fops;
1505 vdev->ioctl_ops = &vpif_ioctl_ops;
1506 vdev->v4l2_dev = &vpif_obj.v4l2_dev;
1507 vdev->vfl_dir = VFL_DIR_RX;
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001508 vdev->queue = q;
Lad, Prabhakar7ff51192014-05-16 10:33:41 -03001509 vdev->lock = &common->lock;
1510 set_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags);
1511 video_set_drvdata(ch->video_dev, ch);
Lad, Prabhakard26d26b2014-05-16 10:33:40 -03001512 err = video_register_device(vdev,
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001513 VFL_TYPE_GRABBER, (j ? 1 : 0));
1514 if (err)
1515 goto probe_out;
1516 }
1517
1518 v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
1519 return 0;
1520
1521probe_out:
1522 for (k = 0; k < j; k++) {
1523 /* Get the pointer to the channel object */
1524 ch = vpif_obj.dev[k];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001525 common = &ch->common[k];
1526 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001527 /* Unregister video device */
1528 video_unregister_device(ch->video_dev);
1529 }
1530 kfree(vpif_obj.sd);
1531 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1532 ch = vpif_obj.dev[i];
1533 /* Note: does nothing if ch->video_dev == NULL */
1534 video_device_release(ch->video_dev);
1535 }
1536 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1537
1538 return err;
1539}
1540
1541static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1542{
1543 return vpif_probe_complete();
1544}
1545
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001546/**
1547 * vpif_probe : This function probes the vpif capture driver
1548 * @pdev: platform device pointer
1549 *
1550 * This creates device entries by register itself to the V4L2 driver and
1551 * initializes fields of each channel objects
1552 */
1553static __init int vpif_probe(struct platform_device *pdev)
1554{
1555 struct vpif_subdev_info *subdevdata;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001556 int i, j, err;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001557 int res_idx = 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001558 struct i2c_adapter *i2c_adap;
1559 struct channel_obj *ch;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001560 struct video_device *vfd;
1561 struct resource *res;
1562 int subdev_count;
1563
1564 vpif_dev = &pdev->dev;
1565
1566 err = initialize_vpif();
1567 if (err) {
1568 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1569 return err;
1570 }
1571
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001572 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1573 if (err) {
1574 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1575 return err;
1576 }
1577
Hans Verkuil5be452c2012-09-20 09:06:29 -03001578 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001579 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001580 IRQF_SHARED, VPIF_DRIVER_NAME,
Lad, Prabhakara76a0b32013-06-17 11:20:47 -03001581 (void *)(&vpif_obj.dev[res_idx]->
1582 channel_id));
1583 if (err) {
1584 err = -EINVAL;
1585 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001586 }
Hans Verkuil5be452c2012-09-20 09:06:29 -03001587 res_idx++;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001588 }
1589
1590 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1591 /* Get the pointer to the channel object */
1592 ch = vpif_obj.dev[i];
1593 /* Allocate memory for video device */
1594 vfd = video_device_alloc();
1595 if (NULL == vfd) {
1596 for (j = 0; j < i; j++) {
1597 ch = vpif_obj.dev[j];
1598 video_device_release(ch->video_dev);
1599 }
1600 err = -ENOMEM;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001601 goto vpif_unregister;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001602 }
1603
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001604 /* Set video_dev to the video device */
1605 ch->video_dev = vfd;
1606 }
1607
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001608 vpif_obj.config = pdev->dev.platform_data;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001609
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001610 subdev_count = vpif_obj.config->subdev_count;
Mats Randgaard1f8766b2010-08-30 10:30:37 -03001611 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001612 GFP_KERNEL);
1613 if (vpif_obj.sd == NULL) {
1614 vpif_err("unable to allocate memory for subdevice pointers\n");
1615 err = -ENOMEM;
Hans Verkuil5be452c2012-09-20 09:06:29 -03001616 goto vpif_sd_error;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001617 }
1618
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001619 if (!vpif_obj.config->asd_sizes) {
1620 i2c_adap = i2c_get_adapter(1);
1621 for (i = 0; i < subdev_count; i++) {
1622 subdevdata = &vpif_obj.config->subdev_info[i];
1623 vpif_obj.sd[i] =
1624 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1625 i2c_adap,
1626 &subdevdata->
1627 board_info,
1628 NULL);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001629
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001630 if (!vpif_obj.sd[i]) {
1631 vpif_err("Error registering v4l2 subdevice\n");
Wei Yongjun2fcd9dc2013-09-02 05:06:10 -03001632 err = -ENODEV;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001633 goto probe_subdev_out;
1634 }
1635 v4l2_info(&vpif_obj.v4l2_dev,
1636 "registered sub device %s\n",
1637 subdevdata->name);
1638 }
1639 vpif_probe_complete();
1640 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001641 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar873229e2013-06-25 11:17:34 -03001642 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1643 vpif_obj.notifier.bound = vpif_async_bound;
1644 vpif_obj.notifier.complete = vpif_async_complete;
1645 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1646 &vpif_obj.notifier);
1647 if (err) {
1648 vpif_err("Error registering async notifier\n");
1649 err = -EINVAL;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001650 goto probe_subdev_out;
1651 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001652 }
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001653
1654 return 0;
1655
Hans Verkuilb65814e2012-09-20 09:06:26 -03001656probe_subdev_out:
1657 /* free sub devices memory */
1658 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001659
Hans Verkuil5be452c2012-09-20 09:06:29 -03001660vpif_sd_error:
1661 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1662 ch = vpif_obj.dev[i];
1663 /* Note: does nothing if ch->video_dev == NULL */
1664 video_device_release(ch->video_dev);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001665 }
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001666vpif_unregister:
Hans Verkuild2f7a1a2011-12-13 05:44:42 -03001667 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001668
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001669 return err;
1670}
1671
1672/**
1673 * vpif_remove() - driver remove handler
1674 * @device: ptr to platform device structure
1675 *
1676 * The vidoe device is unregistered
1677 */
1678static int vpif_remove(struct platform_device *device)
1679{
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001680 struct common_obj *common;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001681 struct channel_obj *ch;
Lad, Prabhakarb2de4f22013-06-17 11:20:46 -03001682 int i;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001683
1684 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1685
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001686 kfree(vpif_obj.sd);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001687 /* un-register device */
1688 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1689 /* Get the pointer to the channel object */
1690 ch = vpif_obj.dev[i];
Lad, Prabhakarfa09acc2014-05-16 10:33:31 -03001691 common = &ch->common[i];
1692 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001693 /* Unregister video device */
1694 video_unregister_device(ch->video_dev);
Lad, Prabhakar410ca602013-06-17 11:20:44 -03001695 kfree(vpif_obj.dev[i]);
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001696 }
1697 return 0;
1698}
1699
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001700#ifdef CONFIG_PM_SLEEP
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001701/**
1702 * vpif_suspend: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001703 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001704static int vpif_suspend(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001705{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001706
1707 struct common_obj *common;
1708 struct channel_obj *ch;
1709 int i;
1710
1711 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1712 /* Get the pointer to the channel object */
1713 ch = vpif_obj.dev[i];
1714 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001715
1716 if (!vb2_is_streaming(&common->buffer_queue))
1717 continue;
1718
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001719 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001720 /* Disable channel */
1721 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1722 enable_channel0(0);
1723 channel0_intr_enable(0);
1724 }
1725 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1726 ycmux_mode == 2) {
1727 enable_channel1(0);
1728 channel1_intr_enable(0);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001729 }
1730 mutex_unlock(&common->lock);
1731 }
1732
1733 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001734}
1735
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001736/*
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001737 * vpif_resume: vpif device suspend
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001738 */
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001739static int vpif_resume(struct device *dev)
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001740{
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001741 struct common_obj *common;
1742 struct channel_obj *ch;
1743 int i;
1744
1745 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1746 /* Get the pointer to the channel object */
1747 ch = vpif_obj.dev[i];
1748 common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001749
1750 if (!vb2_is_streaming(&common->buffer_queue))
1751 continue;
1752
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001753 mutex_lock(&common->lock);
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001754 /* Enable channel */
1755 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1756 enable_channel0(1);
1757 channel0_intr_enable(1);
1758 }
1759 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1760 ycmux_mode == 2) {
1761 enable_channel1(1);
1762 channel1_intr_enable(1);
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001763 }
1764 mutex_unlock(&common->lock);
1765 }
1766
1767 return 0;
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001768}
Manjunath Hadli3d5946d2012-04-13 04:50:55 -03001769#endif
1770
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001771static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
1772
Mats Randgaardffa1b392010-08-30 10:30:36 -03001773static __refdata struct platform_driver vpif_driver = {
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001774 .driver = {
Lad, Prabhakare75ea0c2014-05-16 10:33:46 -03001775 .name = VPIF_DRIVER_NAME,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001776 .owner = THIS_MODULE,
Lad, Prabhakarb7047712014-05-16 10:33:50 -03001777 .pm = &vpif_pm_ops,
Muralidharan Karicheri6ffefff2009-09-16 14:31:10 -03001778 },
1779 .probe = vpif_probe,
1780 .remove = vpif_remove,
1781};
1782
Lad, Prabhakarfe424b22013-06-17 11:20:45 -03001783module_platform_driver(vpif_driver);