blob: f2b4ae1a6a7b86b868df4e5417aec3a993753a85 [file] [log] [blame]
Chaithrika U Se7332e32009-06-09 05:55:37 -03001/*
2 * vpif-display - VPIF display driver
3 * Display driver for TI DaVinci VPIF
4 *
5 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation version 2.
10 *
11 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
12 * kind, whether express or implied; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
Chaithrika U Se7332e32009-06-09 05:55:37 -030017#include <linux/interrupt.h>
Lad, Prabhakar012eef72013-04-19 05:53:29 -030018#include <linux/module.h>
Chaithrika U Se7332e32009-06-09 05:55:37 -030019#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Chaithrika U Se7332e32009-06-09 05:55:37 -030021
Lad, Prabhakar012eef72013-04-19 05:53:29 -030022#include <media/v4l2-ioctl.h>
Chaithrika U Se7332e32009-06-09 05:55:37 -030023
Chaithrika U Se7332e32009-06-09 05:55:37 -030024#include "vpif.h"
Lad, Prabhakar012eef72013-04-19 05:53:29 -030025#include "vpif_display.h"
Chaithrika U Se7332e32009-06-09 05:55:37 -030026
27MODULE_DESCRIPTION("TI DaVinci VPIF Display driver");
28MODULE_LICENSE("GPL");
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -030029MODULE_VERSION(VPIF_DISPLAY_VERSION);
Chaithrika U Se7332e32009-06-09 05:55:37 -030030
Manjunath Hadli0a631722012-04-13 04:44:00 -030031#define VPIF_V4L2_STD (V4L2_STD_525_60 | V4L2_STD_625_50)
Chaithrika U Se7332e32009-06-09 05:55:37 -030032
33#define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
34#define vpif_dbg(level, debug, fmt, arg...) \
35 v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
36
37static int debug = 1;
38static u32 ch2_numbuffers = 3;
39static u32 ch3_numbuffers = 3;
40static u32 ch2_bufsize = 1920 * 1080 * 2;
41static u32 ch3_bufsize = 720 * 576 * 2;
42
43module_param(debug, int, 0644);
44module_param(ch2_numbuffers, uint, S_IRUGO);
45module_param(ch3_numbuffers, uint, S_IRUGO);
46module_param(ch2_bufsize, uint, S_IRUGO);
47module_param(ch3_bufsize, uint, S_IRUGO);
48
49MODULE_PARM_DESC(debug, "Debug level 0-1");
50MODULE_PARM_DESC(ch2_numbuffers, "Channel2 buffer count (default:3)");
51MODULE_PARM_DESC(ch3_numbuffers, "Channel3 buffer count (default:3)");
52MODULE_PARM_DESC(ch2_bufsize, "Channel2 buffer size (default:1920 x 1080 x 2)");
53MODULE_PARM_DESC(ch3_bufsize, "Channel3 buffer size (default:720 x 576 x 2)");
54
55static struct vpif_config_params config_params = {
56 .min_numbuffers = 3,
57 .numbuffers[0] = 3,
58 .numbuffers[1] = 3,
59 .min_bufsize[0] = 720 * 480 * 2,
60 .min_bufsize[1] = 720 * 480 * 2,
61 .channel_bufsize[0] = 1920 * 1080 * 2,
62 .channel_bufsize[1] = 720 * 576 * 2,
63};
64
65static struct vpif_device vpif_obj = { {NULL} };
66static struct device *vpif_dev;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -030067static void vpif_calculate_offsets(struct channel_obj *ch);
68static void vpif_config_addr(struct channel_obj *ch, int muxmode);
Chaithrika U Se7332e32009-06-09 05:55:37 -030069
Chaithrika U Se7332e32009-06-09 05:55:37 -030070/*
Lad, Prabhakar2401dd22012-06-28 09:28:36 -030071 * buffer_prepare: This is the callback function called from vb2_qbuf()
Chaithrika U Se7332e32009-06-09 05:55:37 -030072 * function the buffer is prepared and user space virtual address is converted
73 * into physical address
74 */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -030075static int vpif_buffer_prepare(struct vb2_buffer *vb)
Chaithrika U Se7332e32009-06-09 05:55:37 -030076{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -030077 struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
78 struct vb2_queue *q = vb->vb2_queue;
Chaithrika U Se7332e32009-06-09 05:55:37 -030079 struct common_obj *common;
80 unsigned long addr;
81
82 common = &fh->channel->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar2401dd22012-06-28 09:28:36 -030083 if (vb->state != VB2_BUF_STATE_ACTIVE &&
84 vb->state != VB2_BUF_STATE_PREPARED) {
85 vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
86 if (vb2_plane_vaddr(vb, 0) &&
87 vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
88 goto buf_align_exit;
Chaithrika U Se7332e32009-06-09 05:55:37 -030089
Lad, Prabhakar2401dd22012-06-28 09:28:36 -030090 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
91 if (q->streaming &&
92 (V4L2_BUF_TYPE_SLICED_VBI_OUTPUT != q->type)) {
93 if (!ISALIGNED(addr + common->ytop_off) ||
94 !ISALIGNED(addr + common->ybtm_off) ||
95 !ISALIGNED(addr + common->ctop_off) ||
96 !ISALIGNED(addr + common->cbtm_off))
97 goto buf_align_exit;
Chaithrika U Se7332e32009-06-09 05:55:37 -030098 }
Chaithrika U Se7332e32009-06-09 05:55:37 -030099 }
100 return 0;
101
102buf_align_exit:
103 vpif_err("buffer offset not aligned to 8 bytes\n");
104 return -EINVAL;
105}
106
107/*
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300108 * vpif_buffer_queue_setup: This function allocates memory for the buffers
Chaithrika U Se7332e32009-06-09 05:55:37 -0300109 */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300110static int vpif_buffer_queue_setup(struct vb2_queue *vq,
111 const struct v4l2_format *fmt,
112 unsigned int *nbuffers, unsigned int *nplanes,
113 unsigned int sizes[], void *alloc_ctxs[])
Chaithrika U Se7332e32009-06-09 05:55:37 -0300114{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300115 struct vpif_fh *fh = vb2_get_drv_priv(vq);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300116 struct channel_obj *ch = fh->channel;
117 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300118 unsigned long size;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300119
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300120 if (V4L2_MEMORY_MMAP == common->memory) {
121 size = config_params.channel_bufsize[ch->channel_id];
122 /*
123 * Checking if the buffer size exceeds the available buffer
124 * ycmux_mode = 0 means 1 channel mode HD and
125 * ycmux_mode = 1 means 2 channels mode SD
126 */
127 if (ch->vpifparams.std_info.ycmux_mode == 0) {
128 if (config_params.video_limit[ch->channel_id])
129 while (size * *nbuffers >
130 (config_params.video_limit[0]
131 + config_params.video_limit[1]))
132 (*nbuffers)--;
133 } else {
134 if (config_params.video_limit[ch->channel_id])
135 while (size * *nbuffers >
Manjunath Hadlifc613d42012-04-13 04:49:10 -0300136 config_params.video_limit[ch->channel_id])
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300137 (*nbuffers)--;
138 }
139 } else {
140 size = common->fmt.fmt.pix.sizeimage;
Manjunath Hadlifc613d42012-04-13 04:49:10 -0300141 }
142
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300143 if (*nbuffers < config_params.min_numbuffers)
144 *nbuffers = config_params.min_numbuffers;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300145
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300146 *nplanes = 1;
147 sizes[0] = size;
148 alloc_ctxs[0] = common->alloc_ctx;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300149 return 0;
150}
151
152/*
153 * vpif_buffer_queue: This function adds the buffer to DMA queue
154 */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300155static void vpif_buffer_queue(struct vb2_buffer *vb)
Chaithrika U Se7332e32009-06-09 05:55:37 -0300156{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300157 struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
158 struct vpif_disp_buffer *buf = container_of(vb,
159 struct vpif_disp_buffer, vb);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300160 struct channel_obj *ch = fh->channel;
161 struct common_obj *common;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300162 unsigned long flags;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300163
164 common = &ch->common[VPIF_VIDEO_INDEX];
165
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300166 /* add the buffer to the DMA queue */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300167 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300168 list_add_tail(&buf->list, &common->dma_queue);
Hans Verkuilc4697d72012-11-16 12:03:07 -0300169 spin_unlock_irqrestore(&common->irqlock, flags);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300170}
171
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300172/*
173 * vpif_buf_cleanup: This function is called from the videobuf2 layer to
174 * free memory allocated to the buffers
175 */
176static void vpif_buf_cleanup(struct vb2_buffer *vb)
177{
178 struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
179 struct vpif_disp_buffer *buf = container_of(vb,
180 struct vpif_disp_buffer, vb);
181 struct channel_obj *ch = fh->channel;
182 struct common_obj *common;
183 unsigned long flags;
184
185 common = &ch->common[VPIF_VIDEO_INDEX];
186
187 spin_lock_irqsave(&common->irqlock, flags);
188 if (vb->state == VB2_BUF_STATE_ACTIVE)
189 list_del_init(&buf->list);
190 spin_unlock_irqrestore(&common->irqlock, flags);
191}
192
193static void vpif_wait_prepare(struct vb2_queue *vq)
194{
195 struct vpif_fh *fh = vb2_get_drv_priv(vq);
196 struct channel_obj *ch = fh->channel;
197 struct common_obj *common;
198
199 common = &ch->common[VPIF_VIDEO_INDEX];
200 mutex_unlock(&common->lock);
201}
202
203static void vpif_wait_finish(struct vb2_queue *vq)
204{
205 struct vpif_fh *fh = vb2_get_drv_priv(vq);
206 struct channel_obj *ch = fh->channel;
207 struct common_obj *common;
208
209 common = &ch->common[VPIF_VIDEO_INDEX];
210 mutex_lock(&common->lock);
211}
212
213static int vpif_buffer_init(struct vb2_buffer *vb)
214{
215 struct vpif_disp_buffer *buf = container_of(vb,
216 struct vpif_disp_buffer, vb);
217
218 INIT_LIST_HEAD(&buf->list);
219
220 return 0;
221}
222
Chaithrika U Se7332e32009-06-09 05:55:37 -0300223static u8 channel_first_int[VPIF_NUMOBJECTS][2] = { {1, 1} };
224
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300225static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
226{
227 struct vpif_display_config *vpif_config_data =
228 vpif_dev->platform_data;
229 struct vpif_fh *fh = vb2_get_drv_priv(vq);
230 struct channel_obj *ch = fh->channel;
231 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
232 struct vpif_params *vpif = &ch->vpifparams;
233 unsigned long addr = 0;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300234 unsigned long flags;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300235 int ret;
236
237 /* If buffer queue is empty, return error */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300238 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300239 if (list_empty(&common->dma_queue)) {
Hans Verkuilc4697d72012-11-16 12:03:07 -0300240 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300241 vpif_err("buffer queue is empty\n");
242 return -EIO;
243 }
244
245 /* Get the next frame from the buffer queue */
246 common->next_frm = common->cur_frm =
247 list_entry(common->dma_queue.next,
248 struct vpif_disp_buffer, list);
249
250 list_del(&common->cur_frm->list);
Hans Verkuilc4697d72012-11-16 12:03:07 -0300251 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300252 /* Mark state of the current frame to active */
253 common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
254
255 /* Initialize field_id and started member */
256 ch->field_id = 0;
257 common->started = 1;
258 addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
259 /* Calculate the offset for Y and C data in the buffer */
260 vpif_calculate_offsets(ch);
261
262 if ((ch->vpifparams.std_info.frm_fmt &&
263 ((common->fmt.fmt.pix.field != V4L2_FIELD_NONE)
264 && (common->fmt.fmt.pix.field != V4L2_FIELD_ANY)))
265 || (!ch->vpifparams.std_info.frm_fmt
266 && (common->fmt.fmt.pix.field == V4L2_FIELD_NONE))) {
267 vpif_err("conflict in field format and std format\n");
268 return -EINVAL;
269 }
270
271 /* clock settings */
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300272 if (vpif_config_data->set_clock) {
273 ret = vpif_config_data->set_clock(ch->vpifparams.std_info.
274 ycmux_mode, ch->vpifparams.std_info.hd_sd);
275 if (ret < 0) {
276 vpif_err("can't set clock\n");
277 return ret;
278 }
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300279 }
280
281 /* set the parameters and addresses */
282 ret = vpif_set_video_params(vpif, ch->channel_id + 2);
283 if (ret < 0)
284 return ret;
285
286 common->started = ret;
287 vpif_config_addr(ch, ret);
288 common->set_addr((addr + common->ytop_off),
289 (addr + common->ybtm_off),
290 (addr + common->ctop_off),
291 (addr + common->cbtm_off));
292
293 /* Set interrupt for both the fields in VPIF
294 Register enable channel in VPIF register */
Lad, Prabhakar9e184042012-09-14 10:22:24 -0300295 channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300296 if (VPIF_CHANNEL2_VIDEO == ch->channel_id) {
297 channel2_intr_assert();
298 channel2_intr_enable(1);
299 enable_channel2(1);
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300300 if (vpif_config_data->chan_config[VPIF_CHANNEL2_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -0300301 channel2_clipping_enable(1);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300302 }
303
304 if ((VPIF_CHANNEL3_VIDEO == ch->channel_id)
305 || (common->started == 2)) {
306 channel3_intr_assert();
307 channel3_intr_enable(1);
308 enable_channel3(1);
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300309 if (vpif_config_data->chan_config[VPIF_CHANNEL3_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -0300310 channel3_clipping_enable(1);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300311 }
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300312
313 return 0;
314}
315
316/* abort streaming and wait for last buffer */
317static int vpif_stop_streaming(struct vb2_queue *vq)
318{
319 struct vpif_fh *fh = vb2_get_drv_priv(vq);
320 struct channel_obj *ch = fh->channel;
321 struct common_obj *common;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300322 unsigned long flags;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300323
324 if (!vb2_is_streaming(vq))
325 return 0;
326
327 common = &ch->common[VPIF_VIDEO_INDEX];
328
329 /* release all active buffers */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300330 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300331 while (!list_empty(&common->dma_queue)) {
332 common->next_frm = list_entry(common->dma_queue.next,
333 struct vpif_disp_buffer, list);
334 list_del(&common->next_frm->list);
335 vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
336 }
Hans Verkuilc4697d72012-11-16 12:03:07 -0300337 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300338
339 return 0;
340}
341
342static struct vb2_ops video_qops = {
343 .queue_setup = vpif_buffer_queue_setup,
344 .wait_prepare = vpif_wait_prepare,
345 .wait_finish = vpif_wait_finish,
346 .buf_init = vpif_buffer_init,
347 .buf_prepare = vpif_buffer_prepare,
348 .start_streaming = vpif_start_streaming,
349 .stop_streaming = vpif_stop_streaming,
350 .buf_cleanup = vpif_buf_cleanup,
351 .buf_queue = vpif_buffer_queue,
352};
353
Chaithrika U Se7332e32009-06-09 05:55:37 -0300354static void process_progressive_mode(struct common_obj *common)
355{
356 unsigned long addr = 0;
357
Hans Verkuilc4697d72012-11-16 12:03:07 -0300358 spin_lock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300359 /* Get the next buffer from buffer queue */
360 common->next_frm = list_entry(common->dma_queue.next,
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300361 struct vpif_disp_buffer, list);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300362 /* Remove that buffer from the buffer queue */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300363 list_del(&common->next_frm->list);
Hans Verkuilc4697d72012-11-16 12:03:07 -0300364 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300365 /* Mark status of the buffer as active */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300366 common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300367
368 /* Set top and bottom field addrs in VPIF registers */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300369 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300370 common->set_addr(addr + common->ytop_off,
371 addr + common->ybtm_off,
372 addr + common->ctop_off,
373 addr + common->cbtm_off);
374}
375
376static void process_interlaced_mode(int fid, struct common_obj *common)
377{
378 /* device field id and local field id are in sync */
379 /* If this is even field */
380 if (0 == fid) {
381 if (common->cur_frm == common->next_frm)
382 return;
383
384 /* one frame is displayed If next frame is
385 * available, release cur_frm and move on */
386 /* Copy frame display time */
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300387 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300388 /* Change status of the cur_frm */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300389 vb2_buffer_done(&common->cur_frm->vb,
390 VB2_BUF_STATE_DONE);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300391 /* Make cur_frm pointing to next_frm */
392 common->cur_frm = common->next_frm;
393
394 } else if (1 == fid) { /* odd field */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300395 spin_lock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300396 if (list_empty(&common->dma_queue)
397 || (common->cur_frm != common->next_frm)) {
Hans Verkuilc4697d72012-11-16 12:03:07 -0300398 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300399 return;
400 }
Hans Verkuilc4697d72012-11-16 12:03:07 -0300401 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300402 /* one field is displayed configure the next
403 * frame if it is available else hold on current
404 * frame */
405 /* Get next from the buffer queue */
406 process_progressive_mode(common);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300407 }
408}
409
410/*
411 * vpif_channel_isr: It changes status of the displayed buffer, takes next
412 * buffer from the queue and sets its address in VPIF registers
413 */
414static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
415{
416 struct vpif_device *dev = &vpif_obj;
417 struct channel_obj *ch;
418 struct common_obj *common;
419 enum v4l2_field field;
420 int fid = -1, i;
421 int channel_id = 0;
422
423 channel_id = *(int *)(dev_id);
Manjunath Hadlib1fc4232012-04-13 04:43:10 -0300424 if (!vpif_intr_status(channel_id + 2))
425 return IRQ_NONE;
426
Chaithrika U Se7332e32009-06-09 05:55:37 -0300427 ch = dev->dev[channel_id];
428 field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
429 for (i = 0; i < VPIF_NUMOBJECTS; i++) {
430 common = &ch->common[i];
431 /* If streaming is started in this channel */
432 if (0 == common->started)
433 continue;
434
435 if (1 == ch->vpifparams.std_info.frm_fmt) {
Hans Verkuilc4697d72012-11-16 12:03:07 -0300436 spin_lock(&common->irqlock);
437 if (list_empty(&common->dma_queue)) {
438 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300439 continue;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300440 }
441 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300442
443 /* Progressive mode */
444 if (!channel_first_int[i][channel_id]) {
445 /* Mark status of the cur_frm to
446 * done and unlock semaphore on it */
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300447 v4l2_get_timestamp(&common->cur_frm->vb.
448 v4l2_buf.timestamp);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300449 vb2_buffer_done(&common->cur_frm->vb,
450 VB2_BUF_STATE_DONE);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300451 /* Make cur_frm pointing to next_frm */
452 common->cur_frm = common->next_frm;
453 }
454
455 channel_first_int[i][channel_id] = 0;
456 process_progressive_mode(common);
457 } else {
458 /* Interlaced mode */
459 /* If it is first interrupt, ignore it */
460
461 if (channel_first_int[i][channel_id]) {
462 channel_first_int[i][channel_id] = 0;
463 continue;
464 }
465
466 if (0 == i) {
467 ch->field_id ^= 1;
468 /* Get field id from VPIF registers */
469 fid = vpif_channel_getfid(ch->channel_id + 2);
470 /* If fid does not match with stored field id */
471 if (fid != ch->field_id) {
472 /* Make them in sync */
473 if (0 == fid)
474 ch->field_id = fid;
475
476 return IRQ_HANDLED;
477 }
478 }
479 process_interlaced_mode(fid, common);
480 }
481 }
482
483 return IRQ_HANDLED;
484}
485
Mats Randgaardc027e162010-12-16 12:17:44 -0300486static int vpif_update_std_info(struct channel_obj *ch)
Chaithrika U Se7332e32009-06-09 05:55:37 -0300487{
Chaithrika U Se7332e32009-06-09 05:55:37 -0300488 struct video_obj *vid_ch = &ch->video;
489 struct vpif_params *vpifparams = &ch->vpifparams;
490 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
491 const struct vpif_channel_config_params *config;
492
Mats Randgaardc027e162010-12-16 12:17:44 -0300493 int i;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300494
Mats Randgaardc027e162010-12-16 12:17:44 -0300495 for (i = 0; i < vpif_ch_params_count; i++) {
Lad, Prabhakarced9b212013-03-20 01:28:27 -0300496 config = &vpif_ch_params[i];
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300497 if (config->hd_sd == 0) {
498 vpif_dbg(2, debug, "SD format\n");
499 if (config->stdid & vid_ch->stdid) {
500 memcpy(std_info, config, sizeof(*config));
501 break;
502 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300503 }
504 }
505
Mats Randgaardc027e162010-12-16 12:17:44 -0300506 if (i == vpif_ch_params_count) {
507 vpif_dbg(1, debug, "Format not found\n");
Mats Randgaardaa444402010-12-16 12:17:42 -0300508 return -EINVAL;
Mats Randgaardc027e162010-12-16 12:17:44 -0300509 }
510
511 return 0;
512}
513
514static int vpif_update_resolution(struct channel_obj *ch)
515{
516 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
517 struct video_obj *vid_ch = &ch->video;
518 struct vpif_params *vpifparams = &ch->vpifparams;
519 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
520
Hans Verkuil0598c172012-09-18 07:18:47 -0300521 if (!vid_ch->stdid && !vid_ch->dv_timings.bt.height)
Mats Randgaardc027e162010-12-16 12:17:44 -0300522 return -EINVAL;
523
Hans Verkuil0598c172012-09-18 07:18:47 -0300524 if (vid_ch->stdid) {
Mats Randgaardc027e162010-12-16 12:17:44 -0300525 if (vpif_update_std_info(ch))
526 return -EINVAL;
527 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300528
529 common->fmt.fmt.pix.width = std_info->width;
530 common->fmt.fmt.pix.height = std_info->height;
531 vpif_dbg(1, debug, "Pixel details: Width = %d,Height = %d\n",
532 common->fmt.fmt.pix.width, common->fmt.fmt.pix.height);
533
534 /* Set height and width paramateres */
Mats Randgaardc027e162010-12-16 12:17:44 -0300535 common->height = std_info->height;
536 common->width = std_info->width;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300537
538 return 0;
539}
540
541/*
542 * vpif_calculate_offsets: This function calculates buffers offset for Y and C
543 * in the top and bottom field
544 */
545static void vpif_calculate_offsets(struct channel_obj *ch)
546{
547 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
548 struct vpif_params *vpifparams = &ch->vpifparams;
549 enum v4l2_field field = common->fmt.fmt.pix.field;
550 struct video_obj *vid_ch = &ch->video;
551 unsigned int hpitch, vpitch, sizeimage;
552
553 if (V4L2_FIELD_ANY == common->fmt.fmt.pix.field) {
554 if (ch->vpifparams.std_info.frm_fmt)
555 vid_ch->buf_field = V4L2_FIELD_NONE;
556 else
557 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
558 } else {
559 vid_ch->buf_field = common->fmt.fmt.pix.field;
560 }
561
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300562 sizeimage = common->fmt.fmt.pix.sizeimage;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300563
564 hpitch = common->fmt.fmt.pix.bytesperline;
565 vpitch = sizeimage / (hpitch * 2);
566 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
567 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
568 common->ytop_off = 0;
569 common->ybtm_off = hpitch;
570 common->ctop_off = sizeimage / 2;
571 common->cbtm_off = sizeimage / 2 + hpitch;
572 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
573 common->ytop_off = 0;
574 common->ybtm_off = sizeimage / 4;
575 common->ctop_off = sizeimage / 2;
576 common->cbtm_off = common->ctop_off + sizeimage / 4;
577 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
578 common->ybtm_off = 0;
579 common->ytop_off = sizeimage / 4;
580 common->cbtm_off = sizeimage / 2;
581 common->ctop_off = common->cbtm_off + sizeimage / 4;
582 }
583
584 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
585 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
586 vpifparams->video_params.storage_mode = 1;
587 } else {
588 vpifparams->video_params.storage_mode = 0;
589 }
590
591 if (ch->vpifparams.std_info.frm_fmt == 1) {
592 vpifparams->video_params.hpitch =
593 common->fmt.fmt.pix.bytesperline;
594 } else {
595 if ((field == V4L2_FIELD_ANY) ||
596 (field == V4L2_FIELD_INTERLACED))
597 vpifparams->video_params.hpitch =
598 common->fmt.fmt.pix.bytesperline * 2;
599 else
600 vpifparams->video_params.hpitch =
601 common->fmt.fmt.pix.bytesperline;
602 }
603
604 ch->vpifparams.video_params.stdid = ch->vpifparams.std_info.stdid;
605}
606
607static void vpif_config_format(struct channel_obj *ch)
608{
609 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
610
611 common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
612 if (config_params.numbuffers[ch->channel_id] == 0)
613 common->memory = V4L2_MEMORY_USERPTR;
614 else
615 common->memory = V4L2_MEMORY_MMAP;
616
617 common->fmt.fmt.pix.sizeimage =
618 config_params.channel_bufsize[ch->channel_id];
619 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
620 common->fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
621}
622
623static int vpif_check_format(struct channel_obj *ch,
624 struct v4l2_pix_format *pixfmt)
625{
626 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
627 enum v4l2_field field = pixfmt->field;
628 u32 sizeimage, hpitch, vpitch;
629
630 if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P)
631 goto invalid_fmt_exit;
632
633 if (!(VPIF_VALID_FIELD(field)))
634 goto invalid_fmt_exit;
635
636 if (pixfmt->bytesperline <= 0)
637 goto invalid_pitch_exit;
638
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300639 sizeimage = pixfmt->sizeimage;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300640
Mats Randgaardc027e162010-12-16 12:17:44 -0300641 if (vpif_update_resolution(ch))
Chaithrika U Se7332e32009-06-09 05:55:37 -0300642 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300643
644 hpitch = pixfmt->bytesperline;
645 vpitch = sizeimage / (hpitch * 2);
646
647 /* Check for valid value of pitch */
648 if ((hpitch < ch->vpifparams.std_info.width) ||
649 (vpitch < ch->vpifparams.std_info.height))
650 goto invalid_pitch_exit;
651
652 /* Check for 8 byte alignment */
653 if (!ISALIGNED(hpitch)) {
654 vpif_err("invalid pitch alignment\n");
655 return -EINVAL;
656 }
657 pixfmt->width = common->fmt.fmt.pix.width;
658 pixfmt->height = common->fmt.fmt.pix.height;
659
660 return 0;
661
662invalid_fmt_exit:
663 vpif_err("invalid field format\n");
664 return -EINVAL;
665
666invalid_pitch_exit:
667 vpif_err("invalid pitch\n");
668 return -EINVAL;
669}
670
671static void vpif_config_addr(struct channel_obj *ch, int muxmode)
672{
673 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
674
675 if (VPIF_CHANNEL3_VIDEO == ch->channel_id) {
676 common->set_addr = ch3_set_videobuf_addr;
677 } else {
678 if (2 == muxmode)
679 common->set_addr = ch2_set_videobuf_addr_yc_nmux;
680 else
681 common->set_addr = ch2_set_videobuf_addr;
682 }
683}
684
685/*
686 * vpif_mmap: It is used to map kernel space buffers into user spaces
687 */
688static int vpif_mmap(struct file *filep, struct vm_area_struct *vma)
689{
690 struct vpif_fh *fh = filep->private_data;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300691 struct channel_obj *ch = fh->channel;
692 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300693 int ret;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300694
695 vpif_dbg(2, debug, "vpif_mmap\n");
Chaithrika U Se7332e32009-06-09 05:55:37 -0300696
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300697 if (mutex_lock_interruptible(&common->lock))
698 return -ERESTARTSYS;
699 ret = vb2_mmap(&common->buffer_queue, vma);
700 mutex_unlock(&common->lock);
701 return ret;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300702}
703
704/*
705 * vpif_poll: It is used for select/poll system call
706 */
707static unsigned int vpif_poll(struct file *filep, poll_table *wait)
708{
709 struct vpif_fh *fh = filep->private_data;
710 struct channel_obj *ch = fh->channel;
711 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300712 unsigned int res = 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300713
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300714 if (common->started) {
715 mutex_lock(&common->lock);
716 res = vb2_poll(&common->buffer_queue, filep, wait);
717 mutex_unlock(&common->lock);
718 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300719
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300720 return res;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300721}
722
723/*
724 * vpif_open: It creates object of file handle structure and stores it in
725 * private_data member of filepointer
726 */
727static int vpif_open(struct file *filep)
728{
729 struct video_device *vdev = video_devdata(filep);
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300730 struct channel_obj *ch = video_get_drvdata(vdev);
731 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
732 struct vpif_fh *fh;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300733
Chaithrika U Se7332e32009-06-09 05:55:37 -0300734 /* Allocate memory for the file handle object */
Mats Randgaard1f8766b2010-08-30 10:30:37 -0300735 fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300736 if (fh == NULL) {
737 vpif_err("unable to allocate memory for file handle object\n");
738 return -ENOMEM;
739 }
740
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300741 if (mutex_lock_interruptible(&common->lock)) {
742 kfree(fh);
743 return -ERESTARTSYS;
744 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300745 /* store pointer to fh in private_data member of filep */
746 filep->private_data = fh;
747 fh->channel = ch;
748 fh->initialized = 0;
749 if (!ch->initialized) {
750 fh->initialized = 1;
751 ch->initialized = 1;
752 memset(&ch->vpifparams, 0, sizeof(ch->vpifparams));
753 }
754
755 /* Increment channel usrs counter */
756 atomic_inc(&ch->usrs);
757 /* Set io_allowed[VPIF_VIDEO_INDEX] member to false */
758 fh->io_allowed[VPIF_VIDEO_INDEX] = 0;
759 /* Initialize priority of this instance to default priority */
760 fh->prio = V4L2_PRIORITY_UNSET;
761 v4l2_prio_open(&ch->prio, &fh->prio);
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300762 mutex_unlock(&common->lock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300763
764 return 0;
765}
766
767/*
768 * vpif_release: This function deletes buffer queue, frees the buffers and
769 * the vpif file handle
770 */
771static int vpif_release(struct file *filep)
772{
773 struct vpif_fh *fh = filep->private_data;
774 struct channel_obj *ch = fh->channel;
775 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
776
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300777 mutex_lock(&common->lock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300778 /* if this instance is doing IO */
779 if (fh->io_allowed[VPIF_VIDEO_INDEX]) {
780 /* Reset io_usrs member of channel object */
781 common->io_usrs = 0;
782 /* Disable channel */
783 if (VPIF_CHANNEL2_VIDEO == ch->channel_id) {
784 enable_channel2(0);
785 channel2_intr_enable(0);
786 }
787 if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) ||
788 (2 == common->started)) {
789 enable_channel3(0);
790 channel3_intr_enable(0);
791 }
792 common->started = 0;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300793
Chaithrika U Se7332e32009-06-09 05:55:37 -0300794 /* Free buffers allocated */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300795 vb2_queue_release(&common->buffer_queue);
796 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
797
Chaithrika U Se7332e32009-06-09 05:55:37 -0300798 common->numbuffers =
799 config_params.numbuffers[ch->channel_id];
800 }
801
Chaithrika U Se7332e32009-06-09 05:55:37 -0300802 /* Decrement channel usrs counter */
803 atomic_dec(&ch->usrs);
804 /* If this file handle has initialize encoder device, reset it */
805 if (fh->initialized)
806 ch->initialized = 0;
807
808 /* Close the priority */
Hans Verkuilffb48772010-05-01 08:03:24 -0300809 v4l2_prio_close(&ch->prio, fh->prio);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300810 filep->private_data = NULL;
811 fh->initialized = 0;
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300812 mutex_unlock(&common->lock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300813 kfree(fh);
814
815 return 0;
816}
817
818/* functions implementing ioctls */
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300819/**
820 * vpif_querycap() - QUERYCAP handler
821 * @file: file ptr
822 * @priv: file handle
823 * @cap: ptr to v4l2_capability structure
824 */
Chaithrika U Se7332e32009-06-09 05:55:37 -0300825static int vpif_querycap(struct file *file, void *priv,
826 struct v4l2_capability *cap)
827{
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -0300828 struct vpif_display_config *config = vpif_dev->platform_data;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300829
Lad, Prabhakar626d533f2012-09-25 11:21:55 -0300830 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
831 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
832 snprintf(cap->driver, sizeof(cap->driver), "%s", dev_name(vpif_dev));
833 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
834 dev_name(vpif_dev));
Chaithrika U Se7332e32009-06-09 05:55:37 -0300835 strlcpy(cap->card, config->card_name, sizeof(cap->card));
836
837 return 0;
838}
839
840static int vpif_enum_fmt_vid_out(struct file *file, void *priv,
841 struct v4l2_fmtdesc *fmt)
842{
843 if (fmt->index != 0) {
844 vpif_err("Invalid format index\n");
845 return -EINVAL;
846 }
847
848 /* Fill in the information about format */
849 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
850 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
851 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
852
853 return 0;
854}
855
856static int vpif_g_fmt_vid_out(struct file *file, void *priv,
857 struct v4l2_format *fmt)
858{
859 struct vpif_fh *fh = priv;
860 struct channel_obj *ch = fh->channel;
861 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
862
863 /* Check the validity of the buffer type */
864 if (common->fmt.type != fmt->type)
865 return -EINVAL;
866
Mats Randgaardc027e162010-12-16 12:17:44 -0300867 if (vpif_update_resolution(ch))
Hans Verkuil9bfaae22011-01-05 13:35:45 -0300868 return -EINVAL;
869 *fmt = common->fmt;
870 return 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300871}
872
873static int vpif_s_fmt_vid_out(struct file *file, void *priv,
874 struct v4l2_format *fmt)
875{
876 struct vpif_fh *fh = priv;
877 struct v4l2_pix_format *pixfmt;
878 struct channel_obj *ch = fh->channel;
879 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
880 int ret = 0;
881
882 if ((VPIF_CHANNEL2_VIDEO == ch->channel_id)
883 || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) {
884 if (!fh->initialized) {
885 vpif_dbg(1, debug, "Channel Busy\n");
886 return -EBUSY;
887 }
888
889 /* Check for the priority */
Hans Verkuilffb48772010-05-01 08:03:24 -0300890 ret = v4l2_prio_check(&ch->prio, fh->prio);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300891 if (0 != ret)
892 return ret;
893 fh->initialized = 1;
894 }
895
896 if (common->started) {
897 vpif_dbg(1, debug, "Streaming in progress\n");
898 return -EBUSY;
899 }
900
901 pixfmt = &fmt->fmt.pix;
902 /* Check for valid field format */
903 ret = vpif_check_format(ch, pixfmt);
904 if (ret)
905 return ret;
906
907 /* store the pix format in the channel object */
908 common->fmt.fmt.pix = *pixfmt;
909 /* store the format in the channel object */
Chaithrika U Se7332e32009-06-09 05:55:37 -0300910 common->fmt = *fmt;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300911 return 0;
912}
913
914static int vpif_try_fmt_vid_out(struct file *file, void *priv,
915 struct v4l2_format *fmt)
916{
917 struct vpif_fh *fh = priv;
918 struct channel_obj *ch = fh->channel;
919 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
920 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
921 int ret = 0;
922
923 ret = vpif_check_format(ch, pixfmt);
924 if (ret) {
925 *pixfmt = common->fmt.fmt.pix;
926 pixfmt->sizeimage = pixfmt->width * pixfmt->height * 2;
927 }
928
929 return ret;
930}
931
932static int vpif_reqbufs(struct file *file, void *priv,
933 struct v4l2_requestbuffers *reqbuf)
934{
935 struct vpif_fh *fh = priv;
936 struct channel_obj *ch = fh->channel;
937 struct common_obj *common;
938 enum v4l2_field field;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300939 struct vb2_queue *q;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300940 u8 index = 0;
Lad, Prabhakarb4a711e72012-10-03 10:01:07 -0300941 int ret;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300942
943 /* This file handle has not initialized the channel,
944 It is not allowed to do settings */
945 if ((VPIF_CHANNEL2_VIDEO == ch->channel_id)
946 || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) {
947 if (!fh->initialized) {
948 vpif_err("Channel Busy\n");
949 return -EBUSY;
950 }
951 }
952
953 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != reqbuf->type)
954 return -EINVAL;
955
956 index = VPIF_VIDEO_INDEX;
957
958 common = &ch->common[index];
Chaithrika U S13df4f62009-06-22 09:02:55 -0300959
Manjunath Hadlifc613d42012-04-13 04:49:10 -0300960 if (common->fmt.type != reqbuf->type || !vpif_dev)
Hans Verkuil9bfaae22011-01-05 13:35:45 -0300961 return -EINVAL;
Hans Verkuil9bfaae22011-01-05 13:35:45 -0300962 if (0 != common->io_usrs)
963 return -EBUSY;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300964
965 if (reqbuf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
966 if (common->fmt.fmt.pix.field == V4L2_FIELD_ANY)
967 field = V4L2_FIELD_INTERLACED;
968 else
969 field = common->fmt.fmt.pix.field;
970 } else {
971 field = V4L2_VBI_INTERLACED;
972 }
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300973 /* Initialize videobuf2 queue as per the buffer type */
974 common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
Wei Yongjun94b76a82012-11-15 09:18:17 -0300975 if (IS_ERR(common->alloc_ctx)) {
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300976 vpif_err("Failed to get the context\n");
Wei Yongjun94b76a82012-11-15 09:18:17 -0300977 return PTR_ERR(common->alloc_ctx);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300978 }
979 q = &common->buffer_queue;
980 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
981 q->io_modes = VB2_MMAP | VB2_USERPTR;
982 q->drv_priv = fh;
983 q->ops = &video_qops;
984 q->mem_ops = &vb2_dma_contig_memops;
985 q->buf_struct_size = sizeof(struct vpif_disp_buffer);
Kamil Debski6aa69f92013-01-25 06:29:57 -0300986 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300987
Lad, Prabhakarb4a711e72012-10-03 10:01:07 -0300988 ret = vb2_queue_init(q);
989 if (ret) {
990 vpif_err("vpif_display: vb2_queue_init() failed\n");
991 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
992 return ret;
993 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300994 /* Set io allowed member of file handle to TRUE */
995 fh->io_allowed[index] = 1;
996 /* Increment io usrs member of channel object to 1 */
997 common->io_usrs = 1;
998 /* Store type of memory requested in channel object */
999 common->memory = reqbuf->memory;
1000 INIT_LIST_HEAD(&common->dma_queue);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001001 /* Allocate buffers */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001002 return vb2_reqbufs(&common->buffer_queue, reqbuf);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001003}
1004
1005static int vpif_querybuf(struct file *file, void *priv,
1006 struct v4l2_buffer *tbuf)
1007{
1008 struct vpif_fh *fh = priv;
1009 struct channel_obj *ch = fh->channel;
1010 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1011
1012 if (common->fmt.type != tbuf->type)
1013 return -EINVAL;
1014
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001015 return vb2_querybuf(&common->buffer_queue, tbuf);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001016}
1017
1018static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1019{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001020 struct vpif_fh *fh = NULL;
1021 struct channel_obj *ch = NULL;
1022 struct common_obj *common = NULL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001023
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001024 if (!buf || !priv)
1025 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001026
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001027 fh = priv;
1028 ch = fh->channel;
1029 if (!ch)
1030 return -EINVAL;
1031
1032 common = &(ch->common[VPIF_VIDEO_INDEX]);
1033 if (common->fmt.type != buf->type)
Chaithrika U Se7332e32009-06-09 05:55:37 -03001034 return -EINVAL;
1035
1036 if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
1037 vpif_err("fh->io_allowed\n");
1038 return -EACCES;
1039 }
1040
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001041 return vb2_qbuf(&common->buffer_queue, buf);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001042}
1043
Hans Verkuil314527a2013-03-15 06:10:40 -03001044static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Chaithrika U Se7332e32009-06-09 05:55:37 -03001045{
1046 struct vpif_fh *fh = priv;
1047 struct channel_obj *ch = fh->channel;
1048 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1049 int ret = 0;
1050
Hans Verkuil314527a2013-03-15 06:10:40 -03001051 if (!(std_id & VPIF_V4L2_STD))
Chaithrika U Se7332e32009-06-09 05:55:37 -03001052 return -EINVAL;
1053
1054 if (common->started) {
1055 vpif_err("streaming in progress\n");
1056 return -EBUSY;
1057 }
1058
1059 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -03001060 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -03001061 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Chaithrika U Se7332e32009-06-09 05:55:37 -03001062 /* Get the information about the standard */
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001063 if (vpif_update_resolution(ch))
1064 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001065
1066 if ((ch->vpifparams.std_info.width *
1067 ch->vpifparams.std_info.height * 2) >
1068 config_params.channel_bufsize[ch->channel_id]) {
1069 vpif_err("invalid std for this size\n");
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001070 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001071 }
1072
1073 common->fmt.fmt.pix.bytesperline = common->fmt.fmt.pix.width;
1074 /* Configure the default format information */
1075 vpif_config_format(ch);
1076
1077 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video,
Hans Verkuil314527a2013-03-15 06:10:40 -03001078 s_std_output, std_id);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001079 if (ret < 0) {
1080 vpif_err("Failed to set output standard\n");
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001081 return ret;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001082 }
1083
1084 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, core,
Hans Verkuil314527a2013-03-15 06:10:40 -03001085 s_std, std_id);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001086 if (ret < 0)
1087 vpif_err("Failed to set standard for sub devices\n");
Chaithrika U Se7332e32009-06-09 05:55:37 -03001088 return ret;
1089}
1090
1091static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
1092{
1093 struct vpif_fh *fh = priv;
1094 struct channel_obj *ch = fh->channel;
1095
1096 *std = ch->video.stdid;
1097 return 0;
1098}
1099
1100static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1101{
1102 struct vpif_fh *fh = priv;
1103 struct channel_obj *ch = fh->channel;
1104 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1105
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001106 return vb2_dqbuf(&common->buffer_queue, p,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001107 (file->f_flags & O_NONBLOCK));
1108}
1109
1110static int vpif_streamon(struct file *file, void *priv,
1111 enum v4l2_buf_type buftype)
1112{
1113 struct vpif_fh *fh = priv;
1114 struct channel_obj *ch = fh->channel;
1115 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1116 struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id];
Chaithrika U Se7332e32009-06-09 05:55:37 -03001117 int ret = 0;
1118
1119 if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1120 vpif_err("buffer type not supported\n");
1121 return -EINVAL;
1122 }
1123
1124 if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
1125 vpif_err("fh->io_allowed\n");
1126 return -EACCES;
1127 }
1128
1129 /* If Streaming is already started, return error */
1130 if (common->started) {
1131 vpif_err("channel->started\n");
1132 return -EBUSY;
1133 }
1134
1135 if ((ch->channel_id == VPIF_CHANNEL2_VIDEO
1136 && oth_ch->common[VPIF_VIDEO_INDEX].started &&
1137 ch->vpifparams.std_info.ycmux_mode == 0)
1138 || ((ch->channel_id == VPIF_CHANNEL3_VIDEO)
1139 && (2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) {
1140 vpif_err("other channel is using\n");
1141 return -EBUSY;
1142 }
1143
1144 ret = vpif_check_format(ch, &common->fmt.fmt.pix);
1145 if (ret < 0)
1146 return ret;
1147
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001148 /* Call vb2_streamon to start streaming in videobuf2 */
1149 ret = vb2_streamon(&common->buffer_queue, buftype);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001150 if (ret < 0) {
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001151 vpif_err("vb2_streamon\n");
Chaithrika U Se7332e32009-06-09 05:55:37 -03001152 return ret;
1153 }
1154
Chaithrika U Se7332e32009-06-09 05:55:37 -03001155 return ret;
1156}
1157
1158static int vpif_streamoff(struct file *file, void *priv,
1159 enum v4l2_buf_type buftype)
1160{
1161 struct vpif_fh *fh = priv;
1162 struct channel_obj *ch = fh->channel;
1163 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Manjunath Hadli6964b102012-06-29 03:20:12 -03001164 struct vpif_display_config *vpif_config_data =
1165 vpif_dev->platform_data;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001166
1167 if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1168 vpif_err("buffer type not supported\n");
1169 return -EINVAL;
1170 }
1171
1172 if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
1173 vpif_err("fh->io_allowed\n");
1174 return -EACCES;
1175 }
1176
1177 if (!common->started) {
1178 vpif_err("channel->started\n");
1179 return -EINVAL;
1180 }
1181
Chaithrika U Se7332e32009-06-09 05:55:37 -03001182 if (buftype == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1183 /* disable channel */
1184 if (VPIF_CHANNEL2_VIDEO == ch->channel_id) {
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001185 if (vpif_config_data->
1186 chan_config[VPIF_CHANNEL2_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -03001187 channel2_clipping_enable(0);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001188 enable_channel2(0);
1189 channel2_intr_enable(0);
1190 }
1191 if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) ||
1192 (2 == common->started)) {
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001193 if (vpif_config_data->
1194 chan_config[VPIF_CHANNEL3_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -03001195 channel3_clipping_enable(0);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001196 enable_channel3(0);
1197 channel3_intr_enable(0);
1198 }
1199 }
1200
1201 common->started = 0;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001202 return vb2_streamoff(&common->buffer_queue, buftype);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001203}
1204
1205static int vpif_cropcap(struct file *file, void *priv,
1206 struct v4l2_cropcap *crop)
1207{
1208 struct vpif_fh *fh = priv;
1209 struct channel_obj *ch = fh->channel;
1210 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1211 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != crop->type)
1212 return -EINVAL;
1213
1214 crop->bounds.left = crop->bounds.top = 0;
1215 crop->defrect.left = crop->defrect.top = 0;
1216 crop->defrect.height = crop->bounds.height = common->height;
1217 crop->defrect.width = crop->bounds.width = common->width;
1218
1219 return 0;
1220}
1221
1222static int vpif_enum_output(struct file *file, void *fh,
1223 struct v4l2_output *output)
1224{
1225
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -03001226 struct vpif_display_config *config = vpif_dev->platform_data;
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001227 struct vpif_display_chan_config *chan_cfg;
1228 struct vpif_fh *vpif_handler = fh;
1229 struct channel_obj *ch = vpif_handler->channel;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001230
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001231 chan_cfg = &config->chan_config[ch->channel_id];
1232 if (output->index >= chan_cfg->output_count) {
Chaithrika U Se7332e32009-06-09 05:55:37 -03001233 vpif_dbg(1, debug, "Invalid output index\n");
1234 return -EINVAL;
1235 }
1236
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001237 *output = chan_cfg->outputs[output->index].output;
1238 return 0;
1239}
Chaithrika U Se7332e32009-06-09 05:55:37 -03001240
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001241/**
1242 * vpif_output_to_subdev() - Maps output to sub device
1243 * @vpif_cfg - global config ptr
1244 * @chan_cfg - channel config ptr
1245 * @index - Given output index from application
1246 *
1247 * lookup the sub device information for a given output index.
1248 * we report all the output to application. output table also
1249 * has sub device name for the each output
1250 */
1251static int
1252vpif_output_to_subdev(struct vpif_display_config *vpif_cfg,
1253 struct vpif_display_chan_config *chan_cfg, int index)
1254{
1255 struct vpif_subdev_info *subdev_info;
1256 const char *subdev_name;
1257 int i;
1258
1259 vpif_dbg(2, debug, "vpif_output_to_subdev\n");
1260
1261 if (chan_cfg->outputs == NULL)
1262 return -1;
1263
1264 subdev_name = chan_cfg->outputs[index].subdev_name;
1265 if (subdev_name == NULL)
1266 return -1;
1267
1268 /* loop through the sub device list to get the sub device info */
1269 for (i = 0; i < vpif_cfg->subdev_count; i++) {
1270 subdev_info = &vpif_cfg->subdevinfo[i];
1271 if (!strcmp(subdev_info->name, subdev_name))
1272 return i;
1273 }
1274 return -1;
1275}
1276
1277/**
1278 * vpif_set_output() - Select an output
1279 * @vpif_cfg - global config ptr
1280 * @ch - channel
1281 * @index - Given output index from application
1282 *
1283 * Select the given output.
1284 */
1285static int vpif_set_output(struct vpif_display_config *vpif_cfg,
1286 struct channel_obj *ch, int index)
1287{
1288 struct vpif_display_chan_config *chan_cfg =
1289 &vpif_cfg->chan_config[ch->channel_id];
1290 struct vpif_subdev_info *subdev_info = NULL;
1291 struct v4l2_subdev *sd = NULL;
1292 u32 input = 0, output = 0;
1293 int sd_index;
1294 int ret;
1295
1296 sd_index = vpif_output_to_subdev(vpif_cfg, chan_cfg, index);
1297 if (sd_index >= 0) {
1298 sd = vpif_obj.sd[sd_index];
1299 subdev_info = &vpif_cfg->subdevinfo[sd_index];
1300 }
1301
1302 if (sd) {
1303 input = chan_cfg->outputs[index].input_route;
1304 output = chan_cfg->outputs[index].output_route;
1305 ret = v4l2_subdev_call(sd, video, s_routing, input, output, 0);
1306 if (ret < 0 && ret != -ENOIOCTLCMD) {
1307 vpif_err("Failed to set output\n");
1308 return ret;
1309 }
1310
1311 }
1312 ch->output_idx = index;
1313 ch->sd = sd;
1314 if (chan_cfg->outputs != NULL)
1315 /* update tvnorms from the sub device output info */
1316 ch->video_dev->tvnorms = chan_cfg->outputs[index].output.std;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001317 return 0;
1318}
1319
1320static int vpif_s_output(struct file *file, void *priv, unsigned int i)
1321{
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001322 struct vpif_display_config *config = vpif_dev->platform_data;
1323 struct vpif_display_chan_config *chan_cfg;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001324 struct vpif_fh *fh = priv;
1325 struct channel_obj *ch = fh->channel;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001326 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001327
1328 chan_cfg = &config->chan_config[ch->channel_id];
1329
1330 if (i >= chan_cfg->output_count)
1331 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001332
Chaithrika U Se7332e32009-06-09 05:55:37 -03001333 if (common->started) {
1334 vpif_err("Streaming in progress\n");
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001335 return -EBUSY;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001336 }
1337
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001338 return vpif_set_output(config, ch, i);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001339}
1340
1341static int vpif_g_output(struct file *file, void *priv, unsigned int *i)
1342{
1343 struct vpif_fh *fh = priv;
1344 struct channel_obj *ch = fh->channel;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001345
Hans Verkuil311673e2012-09-20 09:06:23 -03001346 *i = ch->output_idx;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001347
1348 return 0;
1349}
1350
1351static int vpif_g_priority(struct file *file, void *priv, enum v4l2_priority *p)
1352{
1353 struct vpif_fh *fh = priv;
1354 struct channel_obj *ch = fh->channel;
1355
1356 *p = v4l2_prio_max(&ch->prio);
1357
1358 return 0;
1359}
1360
1361static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p)
1362{
1363 struct vpif_fh *fh = priv;
1364 struct channel_obj *ch = fh->channel;
1365
1366 return v4l2_prio_change(&ch->prio, &fh->prio, p);
1367}
1368
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001369/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001370 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001371 * @file: file ptr
1372 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001373 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001374 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001375static int
1376vpif_enum_dv_timings(struct file *file, void *priv,
1377 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001378{
1379 struct vpif_fh *fh = priv;
1380 struct channel_obj *ch = fh->channel;
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001381 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001382
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001383 ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
Wei Yongjun63af4af2012-10-30 09:49:38 -03001384 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001385 return -EINVAL;
1386 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001387}
1388
1389/**
Mats Randgaardc027e162010-12-16 12:17:44 -03001390 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1391 * @file: file ptr
1392 * @priv: file handle
1393 * @timings: digital video timings
1394 */
1395static int vpif_s_dv_timings(struct file *file, void *priv,
1396 struct v4l2_dv_timings *timings)
1397{
1398 struct vpif_fh *fh = priv;
1399 struct channel_obj *ch = fh->channel;
1400 struct vpif_params *vpifparams = &ch->vpifparams;
1401 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
1402 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001403 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Mats Randgaardc027e162010-12-16 12:17:44 -03001404 int ret;
1405
1406 if (timings->type != V4L2_DV_BT_656_1120) {
1407 vpif_dbg(2, debug, "Timing type not defined\n");
1408 return -EINVAL;
1409 }
1410
1411 /* Configure subdevice timings, if any */
Hans Verkuil882084a2012-09-20 09:06:31 -03001412 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001413 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1414 ret = 0;
1415 if (ret < 0) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001416 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1417 return ret;
1418 }
1419
1420 if (!(timings->bt.width && timings->bt.height &&
1421 (timings->bt.hbackporch ||
1422 timings->bt.hfrontporch ||
1423 timings->bt.hsync) &&
1424 timings->bt.vfrontporch &&
1425 (timings->bt.vbackporch ||
1426 timings->bt.vsync))) {
1427 vpif_dbg(2, debug, "Timings for width, height, "
1428 "horizontal back porch, horizontal sync, "
1429 "horizontal front porch, vertical back porch, "
1430 "vertical sync and vertical back porch "
1431 "must be defined\n");
1432 return -EINVAL;
1433 }
1434
Hans Verkuil0598c172012-09-18 07:18:47 -03001435 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001436
1437 /* Configure video port timings */
1438
Hans Verkuile3655262013-07-29 08:41:00 -03001439 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001440 std_info->sav2eav = bt->width;
1441
1442 std_info->l1 = 1;
1443 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1444
Hans Verkuile3655262013-07-29 08:41:00 -03001445 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001446 if (bt->interlaced) {
1447 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001448 std_info->l5 = std_info->vsize/2 -
1449 (bt->vfrontporch - 1);
1450 std_info->l7 = std_info->vsize/2 + 1;
1451 std_info->l9 = std_info->l7 + bt->il_vsync +
1452 bt->il_vbackporch + 1;
1453 std_info->l11 = std_info->vsize -
1454 (bt->il_vfrontporch - 1);
1455 } else {
1456 vpif_dbg(2, debug, "Required timing values for "
1457 "interlaced BT format missing\n");
1458 return -EINVAL;
1459 }
1460 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001461 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1462 }
1463 strncpy(std_info->name, "Custom timings BT656/1120",
1464 VPIF_MAX_NAME);
1465 std_info->width = bt->width;
1466 std_info->height = bt->height;
1467 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1468 std_info->ycmux_mode = 0;
1469 std_info->capture_format = 0;
1470 std_info->vbi_supported = 0;
1471 std_info->hd_sd = 1;
1472 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001473 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001474
1475 return 0;
1476}
1477
1478/**
1479 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1480 * @file: file ptr
1481 * @priv: file handle
1482 * @timings: digital video timings
1483 */
1484static int vpif_g_dv_timings(struct file *file, void *priv,
1485 struct v4l2_dv_timings *timings)
1486{
1487 struct vpif_fh *fh = priv;
1488 struct channel_obj *ch = fh->channel;
1489 struct video_obj *vid_ch = &ch->video;
Mats Randgaardc027e162010-12-16 12:17:44 -03001490
Hans Verkuil0598c172012-09-18 07:18:47 -03001491 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001492
1493 return 0;
1494}
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001495
1496/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001497 * vpif_log_status() - Status information
1498 * @file: file ptr
1499 * @priv: file handle
1500 *
1501 * Returns zero.
1502 */
1503static int vpif_log_status(struct file *filep, void *priv)
1504{
1505 /* status for sub devices */
1506 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1507
1508 return 0;
1509}
1510
Chaithrika U Se7332e32009-06-09 05:55:37 -03001511/* vpif display ioctl operations */
1512static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
1513 .vidioc_querycap = vpif_querycap,
1514 .vidioc_g_priority = vpif_g_priority,
1515 .vidioc_s_priority = vpif_s_priority,
1516 .vidioc_enum_fmt_vid_out = vpif_enum_fmt_vid_out,
1517 .vidioc_g_fmt_vid_out = vpif_g_fmt_vid_out,
1518 .vidioc_s_fmt_vid_out = vpif_s_fmt_vid_out,
1519 .vidioc_try_fmt_vid_out = vpif_try_fmt_vid_out,
1520 .vidioc_reqbufs = vpif_reqbufs,
1521 .vidioc_querybuf = vpif_querybuf,
1522 .vidioc_qbuf = vpif_qbuf,
1523 .vidioc_dqbuf = vpif_dqbuf,
1524 .vidioc_streamon = vpif_streamon,
1525 .vidioc_streamoff = vpif_streamoff,
1526 .vidioc_s_std = vpif_s_std,
1527 .vidioc_g_std = vpif_g_std,
1528 .vidioc_enum_output = vpif_enum_output,
1529 .vidioc_s_output = vpif_s_output,
1530 .vidioc_g_output = vpif_g_output,
1531 .vidioc_cropcap = vpif_cropcap,
Hans Verkuil0598c172012-09-18 07:18:47 -03001532 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
Mats Randgaardc027e162010-12-16 12:17:44 -03001533 .vidioc_s_dv_timings = vpif_s_dv_timings,
1534 .vidioc_g_dv_timings = vpif_g_dv_timings,
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001535 .vidioc_log_status = vpif_log_status,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001536};
1537
1538static const struct v4l2_file_operations vpif_fops = {
1539 .owner = THIS_MODULE,
1540 .open = vpif_open,
1541 .release = vpif_release,
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001542 .unlocked_ioctl = video_ioctl2,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001543 .mmap = vpif_mmap,
1544 .poll = vpif_poll
1545};
1546
1547static struct video_device vpif_video_template = {
1548 .name = "vpif",
1549 .fops = &vpif_fops,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001550 .ioctl_ops = &vpif_ioctl_ops,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001551};
1552
1553/*Configure the channels, buffer sizei, request irq */
1554static int initialize_vpif(void)
1555{
1556 int free_channel_objects_index;
1557 int free_buffer_channel_index;
1558 int free_buffer_index;
1559 int err = 0, i, j;
1560
1561 /* Default number of buffers should be 3 */
1562 if ((ch2_numbuffers > 0) &&
1563 (ch2_numbuffers < config_params.min_numbuffers))
1564 ch2_numbuffers = config_params.min_numbuffers;
1565 if ((ch3_numbuffers > 0) &&
1566 (ch3_numbuffers < config_params.min_numbuffers))
1567 ch3_numbuffers = config_params.min_numbuffers;
1568
1569 /* Set buffer size to min buffers size if invalid buffer size is
1570 * given */
1571 if (ch2_bufsize < config_params.min_bufsize[VPIF_CHANNEL2_VIDEO])
1572 ch2_bufsize =
1573 config_params.min_bufsize[VPIF_CHANNEL2_VIDEO];
1574 if (ch3_bufsize < config_params.min_bufsize[VPIF_CHANNEL3_VIDEO])
1575 ch3_bufsize =
1576 config_params.min_bufsize[VPIF_CHANNEL3_VIDEO];
1577
1578 config_params.numbuffers[VPIF_CHANNEL2_VIDEO] = ch2_numbuffers;
1579
1580 if (ch2_numbuffers) {
1581 config_params.channel_bufsize[VPIF_CHANNEL2_VIDEO] =
1582 ch2_bufsize;
1583 }
1584 config_params.numbuffers[VPIF_CHANNEL3_VIDEO] = ch3_numbuffers;
1585
1586 if (ch3_numbuffers) {
1587 config_params.channel_bufsize[VPIF_CHANNEL3_VIDEO] =
1588 ch3_bufsize;
1589 }
1590
1591 /* Allocate memory for six channel objects */
1592 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1593 vpif_obj.dev[i] =
Mats Randgaard1f8766b2010-08-30 10:30:37 -03001594 kzalloc(sizeof(struct channel_obj), GFP_KERNEL);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001595 /* If memory allocation fails, return error */
1596 if (!vpif_obj.dev[i]) {
1597 free_channel_objects_index = i;
1598 err = -ENOMEM;
1599 goto vpif_init_free_channel_objects;
1600 }
1601 }
1602
1603 free_channel_objects_index = VPIF_DISPLAY_MAX_DEVICES;
1604 free_buffer_channel_index = VPIF_DISPLAY_NUM_CHANNELS;
1605 free_buffer_index = config_params.numbuffers[i - 1];
1606
1607 return 0;
1608
1609vpif_init_free_channel_objects:
1610 for (j = 0; j < free_channel_objects_index; j++)
1611 kfree(vpif_obj.dev[j]);
1612 return err;
1613}
1614
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001615static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1616 struct v4l2_subdev *subdev,
1617 struct v4l2_async_subdev *asd)
1618{
1619 int i;
1620
1621 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1622 if (!strcmp(vpif_obj.config->subdevinfo[i].name,
1623 subdev->name)) {
1624 vpif_obj.sd[i] = subdev;
1625 vpif_obj.sd[i]->grp_id = 1 << i;
1626 return 0;
1627 }
1628
1629 return -EINVAL;
1630}
1631
1632static int vpif_probe_complete(void)
1633{
1634 struct common_obj *common;
1635 struct channel_obj *ch;
1636 int j, err, k;
1637
1638 for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
1639 ch = vpif_obj.dev[j];
1640 /* Initialize field of the channel objects */
1641 atomic_set(&ch->usrs, 0);
1642 for (k = 0; k < VPIF_NUMOBJECTS; k++) {
1643 ch->common[k].numbuffers = 0;
1644 common = &ch->common[k];
1645 common->io_usrs = 0;
1646 common->started = 0;
1647 spin_lock_init(&common->irqlock);
1648 mutex_init(&common->lock);
1649 common->numbuffers = 0;
1650 common->set_addr = NULL;
1651 common->ytop_off = 0;
1652 common->ybtm_off = 0;
1653 common->ctop_off = 0;
1654 common->cbtm_off = 0;
1655 common->cur_frm = NULL;
1656 common->next_frm = NULL;
1657 memset(&common->fmt, 0, sizeof(common->fmt));
1658 common->numbuffers = config_params.numbuffers[k];
1659 }
1660 ch->initialized = 0;
1661 if (vpif_obj.config->subdev_count)
1662 ch->sd = vpif_obj.sd[0];
1663 ch->channel_id = j;
1664 if (j < 2)
1665 ch->common[VPIF_VIDEO_INDEX].numbuffers =
1666 config_params.numbuffers[ch->channel_id];
1667 else
1668 ch->common[VPIF_VIDEO_INDEX].numbuffers = 0;
1669
1670 memset(&ch->vpifparams, 0, sizeof(ch->vpifparams));
1671
1672 /* Initialize prio member of channel object */
1673 v4l2_prio_init(&ch->prio);
1674 ch->common[VPIF_VIDEO_INDEX].fmt.type =
1675 V4L2_BUF_TYPE_VIDEO_OUTPUT;
1676 ch->video_dev->lock = &common->lock;
1677 video_set_drvdata(ch->video_dev, ch);
1678
1679 /* select output 0 */
1680 err = vpif_set_output(vpif_obj.config, ch, 0);
1681 if (err)
1682 goto probe_out;
1683
1684 /* register video device */
1685 vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n",
1686 (int)ch, (int)&ch->video_dev);
1687
1688 err = video_register_device(ch->video_dev,
1689 VFL_TYPE_GRABBER, (j ? 3 : 2));
1690 if (err < 0)
1691 goto probe_out;
1692 }
1693
1694 return 0;
1695
1696probe_out:
1697 for (k = 0; k < j; k++) {
1698 ch = vpif_obj.dev[k];
1699 video_unregister_device(ch->video_dev);
1700 video_device_release(ch->video_dev);
1701 ch->video_dev = NULL;
1702 }
1703 return err;
1704}
1705
1706static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1707{
1708 return vpif_probe_complete();
1709}
1710
Chaithrika U Se7332e32009-06-09 05:55:37 -03001711/*
1712 * vpif_probe: This function creates device entries by register itself to the
1713 * V4L2 driver and initializes fields of each channel objects
1714 */
1715static __init int vpif_probe(struct platform_device *pdev)
1716{
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -03001717 struct vpif_subdev_info *subdevdata;
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001718 int i, j = 0, err = 0;
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001719 int res_idx = 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001720 struct i2c_adapter *i2c_adap;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001721 struct channel_obj *ch;
1722 struct video_device *vfd;
1723 struct resource *res;
1724 int subdev_count;
Manjunath Hadlifc613d42012-04-13 04:49:10 -03001725 size_t size;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001726
1727 vpif_dev = &pdev->dev;
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -03001728 err = initialize_vpif();
1729
1730 if (err) {
1731 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1732 return err;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001733 }
1734
Chaithrika U Se7332e32009-06-09 05:55:37 -03001735 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1736 if (err) {
1737 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1738 return err;
1739 }
1740
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001741 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakar379d2cf2013-06-17 11:20:51 -03001742 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
1743 IRQF_SHARED, "VPIF_Display",
1744 (void *)(&vpif_obj.dev[res_idx]->
1745 channel_id));
1746 if (err) {
1747 err = -EINVAL;
1748 vpif_err("VPIF IRQ request failed\n");
1749 goto vpif_unregister;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001750 }
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001751 res_idx++;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001752 }
1753
1754 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
Chaithrika U Se7332e32009-06-09 05:55:37 -03001755 /* Get the pointer to the channel object */
1756 ch = vpif_obj.dev[i];
1757
1758 /* Allocate memory for video device */
1759 vfd = video_device_alloc();
1760 if (vfd == NULL) {
1761 for (j = 0; j < i; j++) {
1762 ch = vpif_obj.dev[j];
1763 video_device_release(ch->video_dev);
1764 }
1765 err = -ENOMEM;
Lad, Prabhakar9c63e012013-06-17 11:20:50 -03001766 goto vpif_unregister;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001767 }
1768
1769 /* Initialize field of video device */
1770 *vfd = vpif_video_template;
1771 vfd->v4l2_dev = &vpif_obj.v4l2_dev;
1772 vfd->release = video_device_release;
Hans Verkuil954f3402012-09-05 06:05:50 -03001773 vfd->vfl_dir = VFL_DIR_TX;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001774 snprintf(vfd->name, sizeof(vfd->name),
Manjunath Hadli0a631722012-04-13 04:44:00 -03001775 "VPIF_Display_DRIVER_V%s",
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -03001776 VPIF_DISPLAY_VERSION);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001777
1778 /* Set video_dev to the video device */
1779 ch->video_dev = vfd;
1780 }
1781
Manjunath Hadlifc613d42012-04-13 04:49:10 -03001782 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1783 if (res) {
1784 size = resource_size(res);
1785 /* The resources are divided into two equal memory and when
1786 * we have HD output we can add them together
1787 */
1788 for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
1789 ch = vpif_obj.dev[j];
1790 ch->channel_id = j;
1791
1792 /* only enabled if second resource exists */
1793 config_params.video_limit[ch->channel_id] = 0;
1794 if (size)
1795 config_params.video_limit[ch->channel_id] =
1796 size/2;
1797 }
1798 }
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001799 vpif_obj.config = pdev->dev.platform_data;
1800 subdev_count = vpif_obj.config->subdev_count;
1801 subdevdata = vpif_obj.config->subdevinfo;
Hans Verkuile6067f82012-09-20 09:06:27 -03001802 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
1803 GFP_KERNEL);
1804 if (vpif_obj.sd == NULL) {
1805 vpif_err("unable to allocate memory for subdevice pointers\n");
1806 err = -ENOMEM;
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001807 goto vpif_sd_error;
Hans Verkuile6067f82012-09-20 09:06:27 -03001808 }
1809
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001810 if (!vpif_obj.config->asd_sizes) {
1811 i2c_adap = i2c_get_adapter(1);
1812 for (i = 0; i < subdev_count; i++) {
1813 vpif_obj.sd[i] =
1814 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1815 i2c_adap,
1816 &subdevdata[i].
1817 board_info,
1818 NULL);
1819 if (!vpif_obj.sd[i]) {
1820 vpif_err("Error registering v4l2 subdevice\n");
1821 goto probe_subdev_out;
1822 }
1823
1824 if (vpif_obj.sd[i])
1825 vpif_obj.sd[i]->grp_id = 1 << i;
1826 }
1827 vpif_probe_complete();
1828 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001829 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001830 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1831 vpif_obj.notifier.bound = vpif_async_bound;
1832 vpif_obj.notifier.complete = vpif_async_complete;
1833 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1834 &vpif_obj.notifier);
1835 if (err) {
1836 vpif_err("Error registering async notifier\n");
1837 err = -EINVAL;
Hans Verkuile6067f82012-09-20 09:06:27 -03001838 goto probe_subdev_out;
1839 }
Hans Verkuile6067f82012-09-20 09:06:27 -03001840 }
1841
Chaithrika U Se7332e32009-06-09 05:55:37 -03001842 return 0;
1843
Hans Verkuile6067f82012-09-20 09:06:27 -03001844probe_subdev_out:
1845 kfree(vpif_obj.sd);
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001846vpif_sd_error:
1847 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1848 ch = vpif_obj.dev[i];
1849 /* Note: does nothing if ch->video_dev == NULL */
1850 video_device_release(ch->video_dev);
1851 }
Lad, Prabhakar9c63e012013-06-17 11:20:50 -03001852vpif_unregister:
Chaithrika U Se7332e32009-06-09 05:55:37 -03001853 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001854
1855 return err;
1856}
1857
1858/*
1859 * vpif_remove: It un-register channels from V4L2 driver
1860 */
1861static int vpif_remove(struct platform_device *device)
1862{
1863 struct channel_obj *ch;
Lad, Prabhakar9c63e012013-06-17 11:20:50 -03001864 int i;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001865
1866 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1867
Lad, Prabhakar0b361582013-06-17 11:20:48 -03001868 kfree(vpif_obj.sd);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001869 /* un-register device */
1870 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1871 /* Get the pointer to the channel object */
1872 ch = vpif_obj.dev[i];
1873 /* Unregister video device */
1874 video_unregister_device(ch->video_dev);
1875
1876 ch->video_dev = NULL;
Lad, Prabhakar0b361582013-06-17 11:20:48 -03001877 kfree(vpif_obj.dev[i]);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001878 }
1879
1880 return 0;
1881}
1882
Manjunath Hadlie9530da2012-04-13 04:50:35 -03001883#ifdef CONFIG_PM
1884static int vpif_suspend(struct device *dev)
1885{
1886 struct common_obj *common;
1887 struct channel_obj *ch;
1888 int i;
1889
1890 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1891 /* Get the pointer to the channel object */
1892 ch = vpif_obj.dev[i];
1893 common = &ch->common[VPIF_VIDEO_INDEX];
1894 mutex_lock(&common->lock);
1895 if (atomic_read(&ch->usrs) && common->io_usrs) {
1896 /* Disable channel */
1897 if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
1898 enable_channel2(0);
1899 channel2_intr_enable(0);
1900 }
1901 if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
1902 common->started == 2) {
1903 enable_channel3(0);
1904 channel3_intr_enable(0);
1905 }
1906 }
1907 mutex_unlock(&common->lock);
1908 }
1909
1910 return 0;
1911}
1912
1913static int vpif_resume(struct device *dev)
1914{
1915
1916 struct common_obj *common;
1917 struct channel_obj *ch;
1918 int i;
1919
1920 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1921 /* Get the pointer to the channel object */
1922 ch = vpif_obj.dev[i];
1923 common = &ch->common[VPIF_VIDEO_INDEX];
1924 mutex_lock(&common->lock);
1925 if (atomic_read(&ch->usrs) && common->io_usrs) {
1926 /* Enable channel */
1927 if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
1928 enable_channel2(1);
1929 channel2_intr_enable(1);
1930 }
1931 if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
1932 common->started == 2) {
1933 enable_channel3(1);
1934 channel3_intr_enable(1);
1935 }
1936 }
1937 mutex_unlock(&common->lock);
1938 }
1939
1940 return 0;
1941}
1942
1943static const struct dev_pm_ops vpif_pm = {
1944 .suspend = vpif_suspend,
1945 .resume = vpif_resume,
1946};
1947
1948#define vpif_pm_ops (&vpif_pm)
1949#else
1950#define vpif_pm_ops NULL
1951#endif
1952
Mats Randgaardffa1b392010-08-30 10:30:36 -03001953static __refdata struct platform_driver vpif_driver = {
Chaithrika U Se7332e32009-06-09 05:55:37 -03001954 .driver = {
1955 .name = "vpif_display",
1956 .owner = THIS_MODULE,
Manjunath Hadlie9530da2012-04-13 04:50:35 -03001957 .pm = vpif_pm_ops,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001958 },
1959 .probe = vpif_probe,
1960 .remove = vpif_remove,
1961};
1962
Lad, Prabhakarb8d067b2013-06-17 11:20:49 -03001963module_platform_driver(vpif_driver);