blob: dbd4f0f609195ac757c9f3df64dd06ad93e59dce [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 vb2_queue *q = vb->vb2_queue;
Lad, Prabhakara2b235c2014-05-16 10:33:06 -030078 struct channel_obj *ch = vb2_get_drv_priv(q);
Chaithrika U Se7332e32009-06-09 05:55:37 -030079 struct common_obj *common;
80 unsigned long addr;
81
Lad, Prabhakara2b235c2014-05-16 10:33:06 -030082 common = &ch->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, Prabhakara2b235c2014-05-16 10:33:06 -0300115 struct channel_obj *ch = vb2_get_drv_priv(vq);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300116 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300117 unsigned long size;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300118
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300119 if (V4L2_MEMORY_MMAP == common->memory) {
120 size = config_params.channel_bufsize[ch->channel_id];
121 /*
122 * Checking if the buffer size exceeds the available buffer
123 * ycmux_mode = 0 means 1 channel mode HD and
124 * ycmux_mode = 1 means 2 channels mode SD
125 */
126 if (ch->vpifparams.std_info.ycmux_mode == 0) {
127 if (config_params.video_limit[ch->channel_id])
128 while (size * *nbuffers >
129 (config_params.video_limit[0]
130 + config_params.video_limit[1]))
131 (*nbuffers)--;
132 } else {
133 if (config_params.video_limit[ch->channel_id])
134 while (size * *nbuffers >
Manjunath Hadlifc613d42012-04-13 04:49:10 -0300135 config_params.video_limit[ch->channel_id])
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300136 (*nbuffers)--;
137 }
138 } else {
139 size = common->fmt.fmt.pix.sizeimage;
Manjunath Hadlifc613d42012-04-13 04:49:10 -0300140 }
141
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300142 if (*nbuffers < config_params.min_numbuffers)
143 *nbuffers = config_params.min_numbuffers;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300144
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300145 *nplanes = 1;
146 sizes[0] = size;
147 alloc_ctxs[0] = common->alloc_ctx;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300148 return 0;
149}
150
151/*
152 * vpif_buffer_queue: This function adds the buffer to DMA queue
153 */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300154static void vpif_buffer_queue(struct vb2_buffer *vb)
Chaithrika U Se7332e32009-06-09 05:55:37 -0300155{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300156 struct vpif_disp_buffer *buf = container_of(vb,
157 struct vpif_disp_buffer, vb);
Lad, Prabhakara2b235c2014-05-16 10:33:06 -0300158 struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300159 struct common_obj *common;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300160 unsigned long flags;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300161
162 common = &ch->common[VPIF_VIDEO_INDEX];
163
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300164 /* add the buffer to the DMA queue */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300165 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300166 list_add_tail(&buf->list, &common->dma_queue);
Hans Verkuilc4697d72012-11-16 12:03:07 -0300167 spin_unlock_irqrestore(&common->irqlock, flags);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300168}
169
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300170/*
171 * vpif_buf_cleanup: This function is called from the videobuf2 layer to
172 * free memory allocated to the buffers
173 */
174static void vpif_buf_cleanup(struct vb2_buffer *vb)
175{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300176 struct vpif_disp_buffer *buf = container_of(vb,
177 struct vpif_disp_buffer, vb);
Lad, Prabhakara2b235c2014-05-16 10:33:06 -0300178 struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300179 struct common_obj *common;
180 unsigned long flags;
181
182 common = &ch->common[VPIF_VIDEO_INDEX];
183
184 spin_lock_irqsave(&common->irqlock, flags);
185 if (vb->state == VB2_BUF_STATE_ACTIVE)
186 list_del_init(&buf->list);
187 spin_unlock_irqrestore(&common->irqlock, flags);
188}
189
190static void vpif_wait_prepare(struct vb2_queue *vq)
191{
Lad, Prabhakara2b235c2014-05-16 10:33:06 -0300192 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300193 struct common_obj *common;
194
195 common = &ch->common[VPIF_VIDEO_INDEX];
196 mutex_unlock(&common->lock);
197}
198
199static void vpif_wait_finish(struct vb2_queue *vq)
200{
Lad, Prabhakara2b235c2014-05-16 10:33:06 -0300201 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300202 struct common_obj *common;
203
204 common = &ch->common[VPIF_VIDEO_INDEX];
205 mutex_lock(&common->lock);
206}
207
208static int vpif_buffer_init(struct vb2_buffer *vb)
209{
210 struct vpif_disp_buffer *buf = container_of(vb,
211 struct vpif_disp_buffer, vb);
212
213 INIT_LIST_HEAD(&buf->list);
214
215 return 0;
216}
217
Chaithrika U Se7332e32009-06-09 05:55:37 -0300218static u8 channel_first_int[VPIF_NUMOBJECTS][2] = { {1, 1} };
219
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300220static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
221{
222 struct vpif_display_config *vpif_config_data =
223 vpif_dev->platform_data;
Lad, Prabhakara2b235c2014-05-16 10:33:06 -0300224 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300225 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
226 struct vpif_params *vpif = &ch->vpifparams;
227 unsigned long addr = 0;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300228 unsigned long flags;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300229 int ret;
230
Hans Verkuilc4697d72012-11-16 12:03:07 -0300231 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300232
233 /* Get the next frame from the buffer queue */
234 common->next_frm = common->cur_frm =
235 list_entry(common->dma_queue.next,
236 struct vpif_disp_buffer, list);
237
238 list_del(&common->cur_frm->list);
Hans Verkuilc4697d72012-11-16 12:03:07 -0300239 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300240 /* Mark state of the current frame to active */
241 common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
242
243 /* Initialize field_id and started member */
244 ch->field_id = 0;
245 common->started = 1;
246 addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
247 /* Calculate the offset for Y and C data in the buffer */
248 vpif_calculate_offsets(ch);
249
250 if ((ch->vpifparams.std_info.frm_fmt &&
251 ((common->fmt.fmt.pix.field != V4L2_FIELD_NONE)
252 && (common->fmt.fmt.pix.field != V4L2_FIELD_ANY)))
253 || (!ch->vpifparams.std_info.frm_fmt
254 && (common->fmt.fmt.pix.field == V4L2_FIELD_NONE))) {
255 vpif_err("conflict in field format and std format\n");
256 return -EINVAL;
257 }
258
259 /* clock settings */
Lad, Prabhakarf4ad8d72012-09-27 02:33:12 -0300260 if (vpif_config_data->set_clock) {
261 ret = vpif_config_data->set_clock(ch->vpifparams.std_info.
262 ycmux_mode, ch->vpifparams.std_info.hd_sd);
263 if (ret < 0) {
264 vpif_err("can't set clock\n");
265 return ret;
266 }
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300267 }
268
269 /* set the parameters and addresses */
270 ret = vpif_set_video_params(vpif, ch->channel_id + 2);
271 if (ret < 0)
272 return ret;
273
274 common->started = ret;
275 vpif_config_addr(ch, ret);
276 common->set_addr((addr + common->ytop_off),
277 (addr + common->ybtm_off),
278 (addr + common->ctop_off),
279 (addr + common->cbtm_off));
280
281 /* Set interrupt for both the fields in VPIF
282 Register enable channel in VPIF register */
Lad, Prabhakar9e184042012-09-14 10:22:24 -0300283 channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300284 if (VPIF_CHANNEL2_VIDEO == ch->channel_id) {
285 channel2_intr_assert();
286 channel2_intr_enable(1);
287 enable_channel2(1);
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300288 if (vpif_config_data->chan_config[VPIF_CHANNEL2_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -0300289 channel2_clipping_enable(1);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300290 }
291
292 if ((VPIF_CHANNEL3_VIDEO == ch->channel_id)
293 || (common->started == 2)) {
294 channel3_intr_assert();
295 channel3_intr_enable(1);
296 enable_channel3(1);
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -0300297 if (vpif_config_data->chan_config[VPIF_CHANNEL3_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -0300298 channel3_clipping_enable(1);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300299 }
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300300
301 return 0;
302}
303
304/* abort streaming and wait for last buffer */
Hans Verkuile37559b2014-04-17 02:47:21 -0300305static void vpif_stop_streaming(struct vb2_queue *vq)
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300306{
Lad, Prabhakara2b235c2014-05-16 10:33:06 -0300307 struct channel_obj *ch = vb2_get_drv_priv(vq);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300308 struct common_obj *common;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300309 unsigned long flags;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300310
311 if (!vb2_is_streaming(vq))
Hans Verkuile37559b2014-04-17 02:47:21 -0300312 return;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300313
314 common = &ch->common[VPIF_VIDEO_INDEX];
315
Lad, Prabhakar18c7adc2014-03-22 08:03:08 -0300316 /* Disable channel */
317 if (VPIF_CHANNEL2_VIDEO == ch->channel_id) {
318 enable_channel2(0);
319 channel2_intr_enable(0);
320 }
321 if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) ||
322 (2 == common->started)) {
323 enable_channel3(0);
324 channel3_intr_enable(0);
325 }
326 common->started = 0;
327
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300328 /* release all active buffers */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300329 spin_lock_irqsave(&common->irqlock, flags);
Lad, Prabhakar18c7adc2014-03-22 08:03:08 -0300330 if (common->cur_frm == common->next_frm) {
331 vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
332 } else {
333 if (common->cur_frm != NULL)
334 vb2_buffer_done(&common->cur_frm->vb,
335 VB2_BUF_STATE_ERROR);
336 if (common->next_frm != NULL)
337 vb2_buffer_done(&common->next_frm->vb,
338 VB2_BUF_STATE_ERROR);
339 }
340
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300341 while (!list_empty(&common->dma_queue)) {
342 common->next_frm = list_entry(common->dma_queue.next,
343 struct vpif_disp_buffer, list);
344 list_del(&common->next_frm->list);
345 vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
346 }
Hans Verkuilc4697d72012-11-16 12:03:07 -0300347 spin_unlock_irqrestore(&common->irqlock, flags);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300348}
349
350static struct vb2_ops video_qops = {
351 .queue_setup = vpif_buffer_queue_setup,
352 .wait_prepare = vpif_wait_prepare,
353 .wait_finish = vpif_wait_finish,
354 .buf_init = vpif_buffer_init,
355 .buf_prepare = vpif_buffer_prepare,
356 .start_streaming = vpif_start_streaming,
357 .stop_streaming = vpif_stop_streaming,
358 .buf_cleanup = vpif_buf_cleanup,
359 .buf_queue = vpif_buffer_queue,
360};
361
Chaithrika U Se7332e32009-06-09 05:55:37 -0300362static void process_progressive_mode(struct common_obj *common)
363{
364 unsigned long addr = 0;
365
Hans Verkuilc4697d72012-11-16 12:03:07 -0300366 spin_lock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300367 /* Get the next buffer from buffer queue */
368 common->next_frm = list_entry(common->dma_queue.next,
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300369 struct vpif_disp_buffer, list);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300370 /* Remove that buffer from the buffer queue */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300371 list_del(&common->next_frm->list);
Hans Verkuilc4697d72012-11-16 12:03:07 -0300372 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300373 /* Mark status of the buffer as active */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300374 common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300375
376 /* Set top and bottom field addrs in VPIF registers */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300377 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300378 common->set_addr(addr + common->ytop_off,
379 addr + common->ybtm_off,
380 addr + common->ctop_off,
381 addr + common->cbtm_off);
382}
383
384static void process_interlaced_mode(int fid, struct common_obj *common)
385{
386 /* device field id and local field id are in sync */
387 /* If this is even field */
388 if (0 == fid) {
389 if (common->cur_frm == common->next_frm)
390 return;
391
392 /* one frame is displayed If next frame is
393 * available, release cur_frm and move on */
394 /* Copy frame display time */
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300395 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300396 /* Change status of the cur_frm */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300397 vb2_buffer_done(&common->cur_frm->vb,
398 VB2_BUF_STATE_DONE);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300399 /* Make cur_frm pointing to next_frm */
400 common->cur_frm = common->next_frm;
401
402 } else if (1 == fid) { /* odd field */
Hans Verkuilc4697d72012-11-16 12:03:07 -0300403 spin_lock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300404 if (list_empty(&common->dma_queue)
405 || (common->cur_frm != common->next_frm)) {
Hans Verkuilc4697d72012-11-16 12:03:07 -0300406 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300407 return;
408 }
Hans Verkuilc4697d72012-11-16 12:03:07 -0300409 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300410 /* one field is displayed configure the next
411 * frame if it is available else hold on current
412 * frame */
413 /* Get next from the buffer queue */
414 process_progressive_mode(common);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300415 }
416}
417
418/*
419 * vpif_channel_isr: It changes status of the displayed buffer, takes next
420 * buffer from the queue and sets its address in VPIF registers
421 */
422static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
423{
424 struct vpif_device *dev = &vpif_obj;
425 struct channel_obj *ch;
426 struct common_obj *common;
427 enum v4l2_field field;
428 int fid = -1, i;
429 int channel_id = 0;
430
431 channel_id = *(int *)(dev_id);
Manjunath Hadlib1fc4232012-04-13 04:43:10 -0300432 if (!vpif_intr_status(channel_id + 2))
433 return IRQ_NONE;
434
Chaithrika U Se7332e32009-06-09 05:55:37 -0300435 ch = dev->dev[channel_id];
436 field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field;
437 for (i = 0; i < VPIF_NUMOBJECTS; i++) {
438 common = &ch->common[i];
439 /* If streaming is started in this channel */
440 if (0 == common->started)
441 continue;
442
443 if (1 == ch->vpifparams.std_info.frm_fmt) {
Hans Verkuilc4697d72012-11-16 12:03:07 -0300444 spin_lock(&common->irqlock);
445 if (list_empty(&common->dma_queue)) {
446 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300447 continue;
Hans Verkuilc4697d72012-11-16 12:03:07 -0300448 }
449 spin_unlock(&common->irqlock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300450
451 /* Progressive mode */
452 if (!channel_first_int[i][channel_id]) {
453 /* Mark status of the cur_frm to
454 * done and unlock semaphore on it */
Sakari Ailus8e6057b2012-09-15 15:14:42 -0300455 v4l2_get_timestamp(&common->cur_frm->vb.
456 v4l2_buf.timestamp);
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300457 vb2_buffer_done(&common->cur_frm->vb,
458 VB2_BUF_STATE_DONE);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300459 /* Make cur_frm pointing to next_frm */
460 common->cur_frm = common->next_frm;
461 }
462
463 channel_first_int[i][channel_id] = 0;
464 process_progressive_mode(common);
465 } else {
466 /* Interlaced mode */
467 /* If it is first interrupt, ignore it */
468
469 if (channel_first_int[i][channel_id]) {
470 channel_first_int[i][channel_id] = 0;
471 continue;
472 }
473
474 if (0 == i) {
475 ch->field_id ^= 1;
476 /* Get field id from VPIF registers */
477 fid = vpif_channel_getfid(ch->channel_id + 2);
478 /* If fid does not match with stored field id */
479 if (fid != ch->field_id) {
480 /* Make them in sync */
481 if (0 == fid)
482 ch->field_id = fid;
483
484 return IRQ_HANDLED;
485 }
486 }
487 process_interlaced_mode(fid, common);
488 }
489 }
490
491 return IRQ_HANDLED;
492}
493
Mats Randgaardc027e162010-12-16 12:17:44 -0300494static int vpif_update_std_info(struct channel_obj *ch)
Chaithrika U Se7332e32009-06-09 05:55:37 -0300495{
Chaithrika U Se7332e32009-06-09 05:55:37 -0300496 struct video_obj *vid_ch = &ch->video;
497 struct vpif_params *vpifparams = &ch->vpifparams;
498 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
499 const struct vpif_channel_config_params *config;
500
Mats Randgaardc027e162010-12-16 12:17:44 -0300501 int i;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300502
Mats Randgaardc027e162010-12-16 12:17:44 -0300503 for (i = 0; i < vpif_ch_params_count; i++) {
Lad, Prabhakarced9b212013-03-20 01:28:27 -0300504 config = &vpif_ch_params[i];
Mats Randgaard40c8bce2010-12-16 12:17:43 -0300505 if (config->hd_sd == 0) {
506 vpif_dbg(2, debug, "SD format\n");
507 if (config->stdid & vid_ch->stdid) {
508 memcpy(std_info, config, sizeof(*config));
509 break;
510 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300511 }
512 }
513
Mats Randgaardc027e162010-12-16 12:17:44 -0300514 if (i == vpif_ch_params_count) {
515 vpif_dbg(1, debug, "Format not found\n");
Mats Randgaardaa444402010-12-16 12:17:42 -0300516 return -EINVAL;
Mats Randgaardc027e162010-12-16 12:17:44 -0300517 }
518
519 return 0;
520}
521
522static int vpif_update_resolution(struct channel_obj *ch)
523{
524 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
525 struct video_obj *vid_ch = &ch->video;
526 struct vpif_params *vpifparams = &ch->vpifparams;
527 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
528
Hans Verkuil0598c172012-09-18 07:18:47 -0300529 if (!vid_ch->stdid && !vid_ch->dv_timings.bt.height)
Mats Randgaardc027e162010-12-16 12:17:44 -0300530 return -EINVAL;
531
Hans Verkuil0598c172012-09-18 07:18:47 -0300532 if (vid_ch->stdid) {
Mats Randgaardc027e162010-12-16 12:17:44 -0300533 if (vpif_update_std_info(ch))
534 return -EINVAL;
535 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300536
537 common->fmt.fmt.pix.width = std_info->width;
538 common->fmt.fmt.pix.height = std_info->height;
539 vpif_dbg(1, debug, "Pixel details: Width = %d,Height = %d\n",
540 common->fmt.fmt.pix.width, common->fmt.fmt.pix.height);
541
542 /* Set height and width paramateres */
Mats Randgaardc027e162010-12-16 12:17:44 -0300543 common->height = std_info->height;
544 common->width = std_info->width;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300545
546 return 0;
547}
548
549/*
550 * vpif_calculate_offsets: This function calculates buffers offset for Y and C
551 * in the top and bottom field
552 */
553static void vpif_calculate_offsets(struct channel_obj *ch)
554{
555 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
556 struct vpif_params *vpifparams = &ch->vpifparams;
557 enum v4l2_field field = common->fmt.fmt.pix.field;
558 struct video_obj *vid_ch = &ch->video;
559 unsigned int hpitch, vpitch, sizeimage;
560
561 if (V4L2_FIELD_ANY == common->fmt.fmt.pix.field) {
562 if (ch->vpifparams.std_info.frm_fmt)
563 vid_ch->buf_field = V4L2_FIELD_NONE;
564 else
565 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
566 } else {
567 vid_ch->buf_field = common->fmt.fmt.pix.field;
568 }
569
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300570 sizeimage = common->fmt.fmt.pix.sizeimage;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300571
572 hpitch = common->fmt.fmt.pix.bytesperline;
573 vpitch = sizeimage / (hpitch * 2);
574 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
575 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
576 common->ytop_off = 0;
577 common->ybtm_off = hpitch;
578 common->ctop_off = sizeimage / 2;
579 common->cbtm_off = sizeimage / 2 + hpitch;
580 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
581 common->ytop_off = 0;
582 common->ybtm_off = sizeimage / 4;
583 common->ctop_off = sizeimage / 2;
584 common->cbtm_off = common->ctop_off + sizeimage / 4;
585 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
586 common->ybtm_off = 0;
587 common->ytop_off = sizeimage / 4;
588 common->cbtm_off = sizeimage / 2;
589 common->ctop_off = common->cbtm_off + sizeimage / 4;
590 }
591
592 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
593 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
594 vpifparams->video_params.storage_mode = 1;
595 } else {
596 vpifparams->video_params.storage_mode = 0;
597 }
598
599 if (ch->vpifparams.std_info.frm_fmt == 1) {
600 vpifparams->video_params.hpitch =
601 common->fmt.fmt.pix.bytesperline;
602 } else {
603 if ((field == V4L2_FIELD_ANY) ||
604 (field == V4L2_FIELD_INTERLACED))
605 vpifparams->video_params.hpitch =
606 common->fmt.fmt.pix.bytesperline * 2;
607 else
608 vpifparams->video_params.hpitch =
609 common->fmt.fmt.pix.bytesperline;
610 }
611
612 ch->vpifparams.video_params.stdid = ch->vpifparams.std_info.stdid;
613}
614
615static void vpif_config_format(struct channel_obj *ch)
616{
617 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
618
619 common->fmt.fmt.pix.field = V4L2_FIELD_ANY;
620 if (config_params.numbuffers[ch->channel_id] == 0)
621 common->memory = V4L2_MEMORY_USERPTR;
622 else
623 common->memory = V4L2_MEMORY_MMAP;
624
625 common->fmt.fmt.pix.sizeimage =
626 config_params.channel_bufsize[ch->channel_id];
627 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
628 common->fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
629}
630
631static int vpif_check_format(struct channel_obj *ch,
632 struct v4l2_pix_format *pixfmt)
633{
634 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
635 enum v4l2_field field = pixfmt->field;
636 u32 sizeimage, hpitch, vpitch;
637
638 if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P)
639 goto invalid_fmt_exit;
640
641 if (!(VPIF_VALID_FIELD(field)))
642 goto invalid_fmt_exit;
643
644 if (pixfmt->bytesperline <= 0)
645 goto invalid_pitch_exit;
646
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300647 sizeimage = pixfmt->sizeimage;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300648
Mats Randgaardc027e162010-12-16 12:17:44 -0300649 if (vpif_update_resolution(ch))
Chaithrika U Se7332e32009-06-09 05:55:37 -0300650 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300651
652 hpitch = pixfmt->bytesperline;
653 vpitch = sizeimage / (hpitch * 2);
654
655 /* Check for valid value of pitch */
656 if ((hpitch < ch->vpifparams.std_info.width) ||
657 (vpitch < ch->vpifparams.std_info.height))
658 goto invalid_pitch_exit;
659
660 /* Check for 8 byte alignment */
661 if (!ISALIGNED(hpitch)) {
662 vpif_err("invalid pitch alignment\n");
663 return -EINVAL;
664 }
665 pixfmt->width = common->fmt.fmt.pix.width;
666 pixfmt->height = common->fmt.fmt.pix.height;
667
668 return 0;
669
670invalid_fmt_exit:
671 vpif_err("invalid field format\n");
672 return -EINVAL;
673
674invalid_pitch_exit:
675 vpif_err("invalid pitch\n");
676 return -EINVAL;
677}
678
679static void vpif_config_addr(struct channel_obj *ch, int muxmode)
680{
681 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
682
683 if (VPIF_CHANNEL3_VIDEO == ch->channel_id) {
684 common->set_addr = ch3_set_videobuf_addr;
685 } else {
686 if (2 == muxmode)
687 common->set_addr = ch2_set_videobuf_addr_yc_nmux;
688 else
689 common->set_addr = ch2_set_videobuf_addr;
690 }
691}
692
693/*
694 * vpif_mmap: It is used to map kernel space buffers into user spaces
695 */
696static int vpif_mmap(struct file *filep, struct vm_area_struct *vma)
697{
698 struct vpif_fh *fh = filep->private_data;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300699 struct channel_obj *ch = fh->channel;
700 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300701 int ret;
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300702
703 vpif_dbg(2, debug, "vpif_mmap\n");
Chaithrika U Se7332e32009-06-09 05:55:37 -0300704
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300705 if (mutex_lock_interruptible(&common->lock))
706 return -ERESTARTSYS;
707 ret = vb2_mmap(&common->buffer_queue, vma);
708 mutex_unlock(&common->lock);
709 return ret;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300710}
711
712/*
713 * vpif_poll: It is used for select/poll system call
714 */
715static unsigned int vpif_poll(struct file *filep, poll_table *wait)
716{
717 struct vpif_fh *fh = filep->private_data;
718 struct channel_obj *ch = fh->channel;
719 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300720 unsigned int res = 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300721
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300722 if (common->started) {
723 mutex_lock(&common->lock);
724 res = vb2_poll(&common->buffer_queue, filep, wait);
725 mutex_unlock(&common->lock);
726 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300727
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300728 return res;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300729}
730
731/*
732 * vpif_open: It creates object of file handle structure and stores it in
733 * private_data member of filepointer
734 */
735static int vpif_open(struct file *filep)
736{
737 struct video_device *vdev = video_devdata(filep);
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300738 struct channel_obj *ch = video_get_drvdata(vdev);
739 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
740 struct vpif_fh *fh;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300741
Chaithrika U Se7332e32009-06-09 05:55:37 -0300742 /* Allocate memory for the file handle object */
Mats Randgaard1f8766b2010-08-30 10:30:37 -0300743 fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300744 if (fh == NULL) {
745 vpif_err("unable to allocate memory for file handle object\n");
746 return -ENOMEM;
747 }
748
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300749 if (mutex_lock_interruptible(&common->lock)) {
750 kfree(fh);
751 return -ERESTARTSYS;
752 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300753 /* store pointer to fh in private_data member of filep */
754 filep->private_data = fh;
755 fh->channel = ch;
756 fh->initialized = 0;
757 if (!ch->initialized) {
758 fh->initialized = 1;
759 ch->initialized = 1;
760 memset(&ch->vpifparams, 0, sizeof(ch->vpifparams));
761 }
762
763 /* Increment channel usrs counter */
764 atomic_inc(&ch->usrs);
765 /* Set io_allowed[VPIF_VIDEO_INDEX] member to false */
766 fh->io_allowed[VPIF_VIDEO_INDEX] = 0;
767 /* Initialize priority of this instance to default priority */
768 fh->prio = V4L2_PRIORITY_UNSET;
769 v4l2_prio_open(&ch->prio, &fh->prio);
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300770 mutex_unlock(&common->lock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300771
772 return 0;
773}
774
775/*
776 * vpif_release: This function deletes buffer queue, frees the buffers and
777 * the vpif file handle
778 */
779static int vpif_release(struct file *filep)
780{
781 struct vpif_fh *fh = filep->private_data;
782 struct channel_obj *ch = fh->channel;
783 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
784
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300785 mutex_lock(&common->lock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300786 /* if this instance is doing IO */
787 if (fh->io_allowed[VPIF_VIDEO_INDEX]) {
788 /* Reset io_usrs member of channel object */
789 common->io_usrs = 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300790 common->numbuffers =
791 config_params.numbuffers[ch->channel_id];
792 }
793
Chaithrika U Se7332e32009-06-09 05:55:37 -0300794 /* Decrement channel usrs counter */
795 atomic_dec(&ch->usrs);
796 /* If this file handle has initialize encoder device, reset it */
797 if (fh->initialized)
798 ch->initialized = 0;
799
800 /* Close the priority */
Hans Verkuilffb48772010-05-01 08:03:24 -0300801 v4l2_prio_close(&ch->prio, fh->prio);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300802 filep->private_data = NULL;
803 fh->initialized = 0;
Hans Verkuil0b7286d2012-07-31 03:47:07 -0300804 mutex_unlock(&common->lock);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300805 kfree(fh);
806
807 return 0;
808}
809
810/* functions implementing ioctls */
Mats Randgaard2c0ddd12010-12-16 12:17:45 -0300811/**
812 * vpif_querycap() - QUERYCAP handler
813 * @file: file ptr
814 * @priv: file handle
815 * @cap: ptr to v4l2_capability structure
816 */
Chaithrika U Se7332e32009-06-09 05:55:37 -0300817static int vpif_querycap(struct file *file, void *priv,
818 struct v4l2_capability *cap)
819{
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -0300820 struct vpif_display_config *config = vpif_dev->platform_data;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300821
Lad, Prabhakar626d533f2012-09-25 11:21:55 -0300822 cap->device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
823 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
824 snprintf(cap->driver, sizeof(cap->driver), "%s", dev_name(vpif_dev));
825 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
826 dev_name(vpif_dev));
Chaithrika U Se7332e32009-06-09 05:55:37 -0300827 strlcpy(cap->card, config->card_name, sizeof(cap->card));
828
829 return 0;
830}
831
832static int vpif_enum_fmt_vid_out(struct file *file, void *priv,
833 struct v4l2_fmtdesc *fmt)
834{
835 if (fmt->index != 0) {
836 vpif_err("Invalid format index\n");
837 return -EINVAL;
838 }
839
840 /* Fill in the information about format */
841 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
842 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
843 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
844
845 return 0;
846}
847
848static int vpif_g_fmt_vid_out(struct file *file, void *priv,
849 struct v4l2_format *fmt)
850{
851 struct vpif_fh *fh = priv;
852 struct channel_obj *ch = fh->channel;
853 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
854
855 /* Check the validity of the buffer type */
856 if (common->fmt.type != fmt->type)
857 return -EINVAL;
858
Mats Randgaardc027e162010-12-16 12:17:44 -0300859 if (vpif_update_resolution(ch))
Hans Verkuil9bfaae22011-01-05 13:35:45 -0300860 return -EINVAL;
861 *fmt = common->fmt;
862 return 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300863}
864
865static int vpif_s_fmt_vid_out(struct file *file, void *priv,
866 struct v4l2_format *fmt)
867{
868 struct vpif_fh *fh = priv;
869 struct v4l2_pix_format *pixfmt;
870 struct channel_obj *ch = fh->channel;
871 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
872 int ret = 0;
873
874 if ((VPIF_CHANNEL2_VIDEO == ch->channel_id)
875 || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) {
876 if (!fh->initialized) {
877 vpif_dbg(1, debug, "Channel Busy\n");
878 return -EBUSY;
879 }
880
881 /* Check for the priority */
Hans Verkuilffb48772010-05-01 08:03:24 -0300882 ret = v4l2_prio_check(&ch->prio, fh->prio);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300883 if (0 != ret)
884 return ret;
885 fh->initialized = 1;
886 }
887
888 if (common->started) {
889 vpif_dbg(1, debug, "Streaming in progress\n");
890 return -EBUSY;
891 }
892
893 pixfmt = &fmt->fmt.pix;
894 /* Check for valid field format */
895 ret = vpif_check_format(ch, pixfmt);
896 if (ret)
897 return ret;
898
899 /* store the pix format in the channel object */
900 common->fmt.fmt.pix = *pixfmt;
901 /* store the format in the channel object */
Chaithrika U Se7332e32009-06-09 05:55:37 -0300902 common->fmt = *fmt;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300903 return 0;
904}
905
906static int vpif_try_fmt_vid_out(struct file *file, void *priv,
907 struct v4l2_format *fmt)
908{
909 struct vpif_fh *fh = priv;
910 struct channel_obj *ch = fh->channel;
911 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
912 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
913 int ret = 0;
914
915 ret = vpif_check_format(ch, pixfmt);
916 if (ret) {
917 *pixfmt = common->fmt.fmt.pix;
918 pixfmt->sizeimage = pixfmt->width * pixfmt->height * 2;
919 }
920
921 return ret;
922}
923
924static int vpif_reqbufs(struct file *file, void *priv,
925 struct v4l2_requestbuffers *reqbuf)
926{
927 struct vpif_fh *fh = priv;
928 struct channel_obj *ch = fh->channel;
929 struct common_obj *common;
930 enum v4l2_field field;
931 u8 index = 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300932
933 /* This file handle has not initialized the channel,
934 It is not allowed to do settings */
935 if ((VPIF_CHANNEL2_VIDEO == ch->channel_id)
936 || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) {
937 if (!fh->initialized) {
938 vpif_err("Channel Busy\n");
939 return -EBUSY;
940 }
941 }
942
943 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != reqbuf->type)
944 return -EINVAL;
945
946 index = VPIF_VIDEO_INDEX;
947
948 common = &ch->common[index];
Chaithrika U S13df4f62009-06-22 09:02:55 -0300949
Manjunath Hadlifc613d42012-04-13 04:49:10 -0300950 if (common->fmt.type != reqbuf->type || !vpif_dev)
Hans Verkuil9bfaae22011-01-05 13:35:45 -0300951 return -EINVAL;
Hans Verkuil9bfaae22011-01-05 13:35:45 -0300952 if (0 != common->io_usrs)
953 return -EBUSY;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300954
955 if (reqbuf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
956 if (common->fmt.fmt.pix.field == V4L2_FIELD_ANY)
957 field = V4L2_FIELD_INTERLACED;
958 else
959 field = common->fmt.fmt.pix.field;
960 } else {
961 field = V4L2_VBI_INTERLACED;
962 }
Chaithrika U Se7332e32009-06-09 05:55:37 -0300963 /* Set io allowed member of file handle to TRUE */
964 fh->io_allowed[index] = 1;
965 /* Increment io usrs member of channel object to 1 */
966 common->io_usrs = 1;
967 /* Store type of memory requested in channel object */
968 common->memory = reqbuf->memory;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300969 /* Allocate buffers */
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300970 return vb2_reqbufs(&common->buffer_queue, reqbuf);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300971}
972
973static int vpif_querybuf(struct file *file, void *priv,
974 struct v4l2_buffer *tbuf)
975{
976 struct vpif_fh *fh = priv;
977 struct channel_obj *ch = fh->channel;
978 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
979
980 if (common->fmt.type != tbuf->type)
981 return -EINVAL;
982
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300983 return vb2_querybuf(&common->buffer_queue, tbuf);
Chaithrika U Se7332e32009-06-09 05:55:37 -0300984}
985
986static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
987{
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300988 struct vpif_fh *fh = NULL;
989 struct channel_obj *ch = NULL;
990 struct common_obj *common = NULL;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300991
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300992 if (!buf || !priv)
993 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -0300994
Lad, Prabhakar2401dd22012-06-28 09:28:36 -0300995 fh = priv;
996 ch = fh->channel;
997 if (!ch)
998 return -EINVAL;
999
1000 common = &(ch->common[VPIF_VIDEO_INDEX]);
1001 if (common->fmt.type != buf->type)
Chaithrika U Se7332e32009-06-09 05:55:37 -03001002 return -EINVAL;
1003
1004 if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
1005 vpif_err("fh->io_allowed\n");
1006 return -EACCES;
1007 }
1008
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001009 return vb2_qbuf(&common->buffer_queue, buf);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001010}
1011
Hans Verkuil314527a2013-03-15 06:10:40 -03001012static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
Chaithrika U Se7332e32009-06-09 05:55:37 -03001013{
1014 struct vpif_fh *fh = priv;
1015 struct channel_obj *ch = fh->channel;
1016 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1017 int ret = 0;
1018
Hans Verkuil314527a2013-03-15 06:10:40 -03001019 if (!(std_id & VPIF_V4L2_STD))
Chaithrika U Se7332e32009-06-09 05:55:37 -03001020 return -EINVAL;
1021
1022 if (common->started) {
1023 vpif_err("streaming in progress\n");
1024 return -EBUSY;
1025 }
1026
1027 /* Call encoder subdevice function to set the standard */
Hans Verkuil314527a2013-03-15 06:10:40 -03001028 ch->video.stdid = std_id;
Hans Verkuil0598c172012-09-18 07:18:47 -03001029 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
Chaithrika U Se7332e32009-06-09 05:55:37 -03001030 /* Get the information about the standard */
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001031 if (vpif_update_resolution(ch))
1032 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001033
1034 if ((ch->vpifparams.std_info.width *
1035 ch->vpifparams.std_info.height * 2) >
1036 config_params.channel_bufsize[ch->channel_id]) {
1037 vpif_err("invalid std for this size\n");
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001038 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001039 }
1040
1041 common->fmt.fmt.pix.bytesperline = common->fmt.fmt.pix.width;
1042 /* Configure the default format information */
1043 vpif_config_format(ch);
1044
1045 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video,
Hans Verkuil314527a2013-03-15 06:10:40 -03001046 s_std_output, std_id);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001047 if (ret < 0) {
1048 vpif_err("Failed to set output standard\n");
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001049 return ret;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001050 }
1051
1052 ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, core,
Hans Verkuil314527a2013-03-15 06:10:40 -03001053 s_std, std_id);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001054 if (ret < 0)
1055 vpif_err("Failed to set standard for sub devices\n");
Chaithrika U Se7332e32009-06-09 05:55:37 -03001056 return ret;
1057}
1058
1059static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
1060{
1061 struct vpif_fh *fh = priv;
1062 struct channel_obj *ch = fh->channel;
1063
1064 *std = ch->video.stdid;
1065 return 0;
1066}
1067
1068static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1069{
1070 struct vpif_fh *fh = priv;
1071 struct channel_obj *ch = fh->channel;
1072 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1073
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001074 return vb2_dqbuf(&common->buffer_queue, p,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001075 (file->f_flags & O_NONBLOCK));
1076}
1077
1078static int vpif_streamon(struct file *file, void *priv,
1079 enum v4l2_buf_type buftype)
1080{
1081 struct vpif_fh *fh = priv;
1082 struct channel_obj *ch = fh->channel;
1083 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1084 struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id];
Chaithrika U Se7332e32009-06-09 05:55:37 -03001085 int ret = 0;
1086
1087 if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1088 vpif_err("buffer type not supported\n");
1089 return -EINVAL;
1090 }
1091
1092 if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
1093 vpif_err("fh->io_allowed\n");
1094 return -EACCES;
1095 }
1096
1097 /* If Streaming is already started, return error */
1098 if (common->started) {
1099 vpif_err("channel->started\n");
1100 return -EBUSY;
1101 }
1102
1103 if ((ch->channel_id == VPIF_CHANNEL2_VIDEO
1104 && oth_ch->common[VPIF_VIDEO_INDEX].started &&
1105 ch->vpifparams.std_info.ycmux_mode == 0)
1106 || ((ch->channel_id == VPIF_CHANNEL3_VIDEO)
1107 && (2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) {
1108 vpif_err("other channel is using\n");
1109 return -EBUSY;
1110 }
1111
1112 ret = vpif_check_format(ch, &common->fmt.fmt.pix);
1113 if (ret < 0)
1114 return ret;
1115
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001116 /* Call vb2_streamon to start streaming in videobuf2 */
1117 ret = vb2_streamon(&common->buffer_queue, buftype);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001118 if (ret < 0) {
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001119 vpif_err("vb2_streamon\n");
Chaithrika U Se7332e32009-06-09 05:55:37 -03001120 return ret;
1121 }
1122
Chaithrika U Se7332e32009-06-09 05:55:37 -03001123 return ret;
1124}
1125
1126static int vpif_streamoff(struct file *file, void *priv,
1127 enum v4l2_buf_type buftype)
1128{
1129 struct vpif_fh *fh = priv;
1130 struct channel_obj *ch = fh->channel;
1131 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Manjunath Hadli6964b102012-06-29 03:20:12 -03001132 struct vpif_display_config *vpif_config_data =
1133 vpif_dev->platform_data;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001134
1135 if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1136 vpif_err("buffer type not supported\n");
1137 return -EINVAL;
1138 }
1139
1140 if (!fh->io_allowed[VPIF_VIDEO_INDEX]) {
1141 vpif_err("fh->io_allowed\n");
1142 return -EACCES;
1143 }
1144
1145 if (!common->started) {
1146 vpif_err("channel->started\n");
1147 return -EINVAL;
1148 }
1149
Chaithrika U Se7332e32009-06-09 05:55:37 -03001150 if (buftype == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1151 /* disable channel */
1152 if (VPIF_CHANNEL2_VIDEO == ch->channel_id) {
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001153 if (vpif_config_data->
1154 chan_config[VPIF_CHANNEL2_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -03001155 channel2_clipping_enable(0);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001156 enable_channel2(0);
1157 channel2_intr_enable(0);
1158 }
1159 if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) ||
1160 (2 == common->started)) {
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001161 if (vpif_config_data->
1162 chan_config[VPIF_CHANNEL3_VIDEO].clip_en)
Manjunath Hadli6964b102012-06-29 03:20:12 -03001163 channel3_clipping_enable(0);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001164 enable_channel3(0);
1165 channel3_intr_enable(0);
1166 }
1167 }
1168
1169 common->started = 0;
Lad, Prabhakar2401dd22012-06-28 09:28:36 -03001170 return vb2_streamoff(&common->buffer_queue, buftype);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001171}
1172
1173static int vpif_cropcap(struct file *file, void *priv,
1174 struct v4l2_cropcap *crop)
1175{
1176 struct vpif_fh *fh = priv;
1177 struct channel_obj *ch = fh->channel;
1178 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1179 if (V4L2_BUF_TYPE_VIDEO_OUTPUT != crop->type)
1180 return -EINVAL;
1181
1182 crop->bounds.left = crop->bounds.top = 0;
1183 crop->defrect.left = crop->defrect.top = 0;
1184 crop->defrect.height = crop->bounds.height = common->height;
1185 crop->defrect.width = crop->bounds.width = common->width;
1186
1187 return 0;
1188}
1189
1190static int vpif_enum_output(struct file *file, void *fh,
1191 struct v4l2_output *output)
1192{
1193
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -03001194 struct vpif_display_config *config = vpif_dev->platform_data;
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001195 struct vpif_display_chan_config *chan_cfg;
1196 struct vpif_fh *vpif_handler = fh;
1197 struct channel_obj *ch = vpif_handler->channel;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001198
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001199 chan_cfg = &config->chan_config[ch->channel_id];
1200 if (output->index >= chan_cfg->output_count) {
Chaithrika U Se7332e32009-06-09 05:55:37 -03001201 vpif_dbg(1, debug, "Invalid output index\n");
1202 return -EINVAL;
1203 }
1204
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001205 *output = chan_cfg->outputs[output->index].output;
1206 return 0;
1207}
Chaithrika U Se7332e32009-06-09 05:55:37 -03001208
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001209/**
1210 * vpif_output_to_subdev() - Maps output to sub device
1211 * @vpif_cfg - global config ptr
1212 * @chan_cfg - channel config ptr
1213 * @index - Given output index from application
1214 *
1215 * lookup the sub device information for a given output index.
1216 * we report all the output to application. output table also
1217 * has sub device name for the each output
1218 */
1219static int
1220vpif_output_to_subdev(struct vpif_display_config *vpif_cfg,
1221 struct vpif_display_chan_config *chan_cfg, int index)
1222{
1223 struct vpif_subdev_info *subdev_info;
1224 const char *subdev_name;
1225 int i;
1226
1227 vpif_dbg(2, debug, "vpif_output_to_subdev\n");
1228
1229 if (chan_cfg->outputs == NULL)
1230 return -1;
1231
1232 subdev_name = chan_cfg->outputs[index].subdev_name;
1233 if (subdev_name == NULL)
1234 return -1;
1235
1236 /* loop through the sub device list to get the sub device info */
1237 for (i = 0; i < vpif_cfg->subdev_count; i++) {
1238 subdev_info = &vpif_cfg->subdevinfo[i];
1239 if (!strcmp(subdev_info->name, subdev_name))
1240 return i;
1241 }
1242 return -1;
1243}
1244
1245/**
1246 * vpif_set_output() - Select an output
1247 * @vpif_cfg - global config ptr
1248 * @ch - channel
1249 * @index - Given output index from application
1250 *
1251 * Select the given output.
1252 */
1253static int vpif_set_output(struct vpif_display_config *vpif_cfg,
1254 struct channel_obj *ch, int index)
1255{
1256 struct vpif_display_chan_config *chan_cfg =
1257 &vpif_cfg->chan_config[ch->channel_id];
1258 struct vpif_subdev_info *subdev_info = NULL;
1259 struct v4l2_subdev *sd = NULL;
1260 u32 input = 0, output = 0;
1261 int sd_index;
1262 int ret;
1263
1264 sd_index = vpif_output_to_subdev(vpif_cfg, chan_cfg, index);
1265 if (sd_index >= 0) {
1266 sd = vpif_obj.sd[sd_index];
1267 subdev_info = &vpif_cfg->subdevinfo[sd_index];
1268 }
1269
1270 if (sd) {
1271 input = chan_cfg->outputs[index].input_route;
1272 output = chan_cfg->outputs[index].output_route;
1273 ret = v4l2_subdev_call(sd, video, s_routing, input, output, 0);
1274 if (ret < 0 && ret != -ENOIOCTLCMD) {
1275 vpif_err("Failed to set output\n");
1276 return ret;
1277 }
1278
1279 }
1280 ch->output_idx = index;
1281 ch->sd = sd;
1282 if (chan_cfg->outputs != NULL)
1283 /* update tvnorms from the sub device output info */
1284 ch->video_dev->tvnorms = chan_cfg->outputs[index].output.std;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001285 return 0;
1286}
1287
1288static int vpif_s_output(struct file *file, void *priv, unsigned int i)
1289{
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001290 struct vpif_display_config *config = vpif_dev->platform_data;
1291 struct vpif_display_chan_config *chan_cfg;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001292 struct vpif_fh *fh = priv;
1293 struct channel_obj *ch = fh->channel;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001294 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001295
1296 chan_cfg = &config->chan_config[ch->channel_id];
1297
1298 if (i >= chan_cfg->output_count)
1299 return -EINVAL;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001300
Chaithrika U Se7332e32009-06-09 05:55:37 -03001301 if (common->started) {
1302 vpif_err("Streaming in progress\n");
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001303 return -EBUSY;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001304 }
1305
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001306 return vpif_set_output(config, ch, i);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001307}
1308
1309static int vpif_g_output(struct file *file, void *priv, unsigned int *i)
1310{
1311 struct vpif_fh *fh = priv;
1312 struct channel_obj *ch = fh->channel;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001313
Hans Verkuil311673e2012-09-20 09:06:23 -03001314 *i = ch->output_idx;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001315
1316 return 0;
1317}
1318
1319static int vpif_g_priority(struct file *file, void *priv, enum v4l2_priority *p)
1320{
1321 struct vpif_fh *fh = priv;
1322 struct channel_obj *ch = fh->channel;
1323
1324 *p = v4l2_prio_max(&ch->prio);
1325
1326 return 0;
1327}
1328
1329static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p)
1330{
1331 struct vpif_fh *fh = priv;
1332 struct channel_obj *ch = fh->channel;
1333
1334 return v4l2_prio_change(&ch->prio, &fh->prio, p);
1335}
1336
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001337/**
Hans Verkuil0598c172012-09-18 07:18:47 -03001338 * vpif_enum_dv_timings() - ENUM_DV_TIMINGS handler
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001339 * @file: file ptr
1340 * @priv: file handle
Hans Verkuil0598c172012-09-18 07:18:47 -03001341 * @timings: input timings
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001342 */
Hans Verkuil0598c172012-09-18 07:18:47 -03001343static int
1344vpif_enum_dv_timings(struct file *file, void *priv,
1345 struct v4l2_enum_dv_timings *timings)
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001346{
1347 struct vpif_fh *fh = priv;
1348 struct channel_obj *ch = fh->channel;
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001349 int ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001350
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001351 ret = v4l2_subdev_call(ch->sd, video, enum_dv_timings, timings);
Wei Yongjun63af4af2012-10-30 09:49:38 -03001352 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001353 return -EINVAL;
1354 return ret;
Mats Randgaard40c8bce2010-12-16 12:17:43 -03001355}
1356
1357/**
Mats Randgaardc027e162010-12-16 12:17:44 -03001358 * vpif_s_dv_timings() - S_DV_TIMINGS handler
1359 * @file: file ptr
1360 * @priv: file handle
1361 * @timings: digital video timings
1362 */
1363static int vpif_s_dv_timings(struct file *file, void *priv,
1364 struct v4l2_dv_timings *timings)
1365{
1366 struct vpif_fh *fh = priv;
1367 struct channel_obj *ch = fh->channel;
1368 struct vpif_params *vpifparams = &ch->vpifparams;
1369 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
1370 struct video_obj *vid_ch = &ch->video;
Hans Verkuil0598c172012-09-18 07:18:47 -03001371 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
Mats Randgaardc027e162010-12-16 12:17:44 -03001372 int ret;
1373
1374 if (timings->type != V4L2_DV_BT_656_1120) {
1375 vpif_dbg(2, debug, "Timing type not defined\n");
1376 return -EINVAL;
1377 }
1378
1379 /* Configure subdevice timings, if any */
Hans Verkuil882084a2012-09-20 09:06:31 -03001380 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
Lad, Prabhakar2bd4e582012-09-25 08:11:49 -03001381 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1382 ret = 0;
1383 if (ret < 0) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001384 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1385 return ret;
1386 }
1387
1388 if (!(timings->bt.width && timings->bt.height &&
1389 (timings->bt.hbackporch ||
1390 timings->bt.hfrontporch ||
1391 timings->bt.hsync) &&
1392 timings->bt.vfrontporch &&
1393 (timings->bt.vbackporch ||
1394 timings->bt.vsync))) {
1395 vpif_dbg(2, debug, "Timings for width, height, "
1396 "horizontal back porch, horizontal sync, "
1397 "horizontal front porch, vertical back porch, "
1398 "vertical sync and vertical back porch "
1399 "must be defined\n");
1400 return -EINVAL;
1401 }
1402
Hans Verkuil0598c172012-09-18 07:18:47 -03001403 vid_ch->dv_timings = *timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001404
1405 /* Configure video port timings */
1406
Hans Verkuile3655262013-07-29 08:41:00 -03001407 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
Mats Randgaardc027e162010-12-16 12:17:44 -03001408 std_info->sav2eav = bt->width;
1409
1410 std_info->l1 = 1;
1411 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1412
Hans Verkuile3655262013-07-29 08:41:00 -03001413 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
Mats Randgaardc027e162010-12-16 12:17:44 -03001414 if (bt->interlaced) {
1415 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
Mats Randgaardc027e162010-12-16 12:17:44 -03001416 std_info->l5 = std_info->vsize/2 -
1417 (bt->vfrontporch - 1);
1418 std_info->l7 = std_info->vsize/2 + 1;
1419 std_info->l9 = std_info->l7 + bt->il_vsync +
1420 bt->il_vbackporch + 1;
1421 std_info->l11 = std_info->vsize -
1422 (bt->il_vfrontporch - 1);
1423 } else {
1424 vpif_dbg(2, debug, "Required timing values for "
1425 "interlaced BT format missing\n");
1426 return -EINVAL;
1427 }
1428 } else {
Mats Randgaardc027e162010-12-16 12:17:44 -03001429 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1430 }
1431 strncpy(std_info->name, "Custom timings BT656/1120",
1432 VPIF_MAX_NAME);
1433 std_info->width = bt->width;
1434 std_info->height = bt->height;
1435 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1436 std_info->ycmux_mode = 0;
1437 std_info->capture_format = 0;
1438 std_info->vbi_supported = 0;
1439 std_info->hd_sd = 1;
1440 std_info->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001441 vid_ch->stdid = 0;
Mats Randgaardc027e162010-12-16 12:17:44 -03001442
1443 return 0;
1444}
1445
1446/**
1447 * vpif_g_dv_timings() - G_DV_TIMINGS handler
1448 * @file: file ptr
1449 * @priv: file handle
1450 * @timings: digital video timings
1451 */
1452static int vpif_g_dv_timings(struct file *file, void *priv,
1453 struct v4l2_dv_timings *timings)
1454{
1455 struct vpif_fh *fh = priv;
1456 struct channel_obj *ch = fh->channel;
1457 struct video_obj *vid_ch = &ch->video;
Mats Randgaardc027e162010-12-16 12:17:44 -03001458
Hans Verkuil0598c172012-09-18 07:18:47 -03001459 *timings = vid_ch->dv_timings;
Mats Randgaardc027e162010-12-16 12:17:44 -03001460
1461 return 0;
1462}
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001463
1464/*
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001465 * vpif_log_status() - Status information
1466 * @file: file ptr
1467 * @priv: file handle
1468 *
1469 * Returns zero.
1470 */
1471static int vpif_log_status(struct file *filep, void *priv)
1472{
1473 /* status for sub devices */
1474 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1475
1476 return 0;
1477}
1478
Chaithrika U Se7332e32009-06-09 05:55:37 -03001479/* vpif display ioctl operations */
1480static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
1481 .vidioc_querycap = vpif_querycap,
1482 .vidioc_g_priority = vpif_g_priority,
1483 .vidioc_s_priority = vpif_s_priority,
1484 .vidioc_enum_fmt_vid_out = vpif_enum_fmt_vid_out,
1485 .vidioc_g_fmt_vid_out = vpif_g_fmt_vid_out,
1486 .vidioc_s_fmt_vid_out = vpif_s_fmt_vid_out,
1487 .vidioc_try_fmt_vid_out = vpif_try_fmt_vid_out,
1488 .vidioc_reqbufs = vpif_reqbufs,
1489 .vidioc_querybuf = vpif_querybuf,
1490 .vidioc_qbuf = vpif_qbuf,
1491 .vidioc_dqbuf = vpif_dqbuf,
1492 .vidioc_streamon = vpif_streamon,
1493 .vidioc_streamoff = vpif_streamoff,
1494 .vidioc_s_std = vpif_s_std,
1495 .vidioc_g_std = vpif_g_std,
1496 .vidioc_enum_output = vpif_enum_output,
1497 .vidioc_s_output = vpif_s_output,
1498 .vidioc_g_output = vpif_g_output,
1499 .vidioc_cropcap = vpif_cropcap,
Hans Verkuil0598c172012-09-18 07:18:47 -03001500 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
Mats Randgaardc027e162010-12-16 12:17:44 -03001501 .vidioc_s_dv_timings = vpif_s_dv_timings,
1502 .vidioc_g_dv_timings = vpif_g_dv_timings,
Mats Randgaard7036d6a2010-12-16 12:17:41 -03001503 .vidioc_log_status = vpif_log_status,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001504};
1505
1506static const struct v4l2_file_operations vpif_fops = {
1507 .owner = THIS_MODULE,
1508 .open = vpif_open,
1509 .release = vpif_release,
Hans Verkuil9bfaae22011-01-05 13:35:45 -03001510 .unlocked_ioctl = video_ioctl2,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001511 .mmap = vpif_mmap,
1512 .poll = vpif_poll
1513};
1514
1515static struct video_device vpif_video_template = {
1516 .name = "vpif",
1517 .fops = &vpif_fops,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001518 .ioctl_ops = &vpif_ioctl_ops,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001519};
1520
1521/*Configure the channels, buffer sizei, request irq */
1522static int initialize_vpif(void)
1523{
1524 int free_channel_objects_index;
1525 int free_buffer_channel_index;
1526 int free_buffer_index;
1527 int err = 0, i, j;
1528
1529 /* Default number of buffers should be 3 */
1530 if ((ch2_numbuffers > 0) &&
1531 (ch2_numbuffers < config_params.min_numbuffers))
1532 ch2_numbuffers = config_params.min_numbuffers;
1533 if ((ch3_numbuffers > 0) &&
1534 (ch3_numbuffers < config_params.min_numbuffers))
1535 ch3_numbuffers = config_params.min_numbuffers;
1536
1537 /* Set buffer size to min buffers size if invalid buffer size is
1538 * given */
1539 if (ch2_bufsize < config_params.min_bufsize[VPIF_CHANNEL2_VIDEO])
1540 ch2_bufsize =
1541 config_params.min_bufsize[VPIF_CHANNEL2_VIDEO];
1542 if (ch3_bufsize < config_params.min_bufsize[VPIF_CHANNEL3_VIDEO])
1543 ch3_bufsize =
1544 config_params.min_bufsize[VPIF_CHANNEL3_VIDEO];
1545
1546 config_params.numbuffers[VPIF_CHANNEL2_VIDEO] = ch2_numbuffers;
1547
1548 if (ch2_numbuffers) {
1549 config_params.channel_bufsize[VPIF_CHANNEL2_VIDEO] =
1550 ch2_bufsize;
1551 }
1552 config_params.numbuffers[VPIF_CHANNEL3_VIDEO] = ch3_numbuffers;
1553
1554 if (ch3_numbuffers) {
1555 config_params.channel_bufsize[VPIF_CHANNEL3_VIDEO] =
1556 ch3_bufsize;
1557 }
1558
1559 /* Allocate memory for six channel objects */
1560 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1561 vpif_obj.dev[i] =
Mats Randgaard1f8766b2010-08-30 10:30:37 -03001562 kzalloc(sizeof(struct channel_obj), GFP_KERNEL);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001563 /* If memory allocation fails, return error */
1564 if (!vpif_obj.dev[i]) {
1565 free_channel_objects_index = i;
1566 err = -ENOMEM;
1567 goto vpif_init_free_channel_objects;
1568 }
1569 }
1570
1571 free_channel_objects_index = VPIF_DISPLAY_MAX_DEVICES;
1572 free_buffer_channel_index = VPIF_DISPLAY_NUM_CHANNELS;
1573 free_buffer_index = config_params.numbuffers[i - 1];
1574
1575 return 0;
1576
1577vpif_init_free_channel_objects:
1578 for (j = 0; j < free_channel_objects_index; j++)
1579 kfree(vpif_obj.dev[j]);
1580 return err;
1581}
1582
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001583static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1584 struct v4l2_subdev *subdev,
1585 struct v4l2_async_subdev *asd)
1586{
1587 int i;
1588
1589 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1590 if (!strcmp(vpif_obj.config->subdevinfo[i].name,
1591 subdev->name)) {
1592 vpif_obj.sd[i] = subdev;
1593 vpif_obj.sd[i]->grp_id = 1 << i;
1594 return 0;
1595 }
1596
1597 return -EINVAL;
1598}
1599
1600static int vpif_probe_complete(void)
1601{
1602 struct common_obj *common;
1603 struct channel_obj *ch;
Lad, Prabhakara2b235c2014-05-16 10:33:06 -03001604 struct vb2_queue *q;
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001605 int j, err, k;
1606
1607 for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
1608 ch = vpif_obj.dev[j];
1609 /* Initialize field of the channel objects */
1610 atomic_set(&ch->usrs, 0);
1611 for (k = 0; k < VPIF_NUMOBJECTS; k++) {
1612 ch->common[k].numbuffers = 0;
1613 common = &ch->common[k];
1614 common->io_usrs = 0;
1615 common->started = 0;
1616 spin_lock_init(&common->irqlock);
1617 mutex_init(&common->lock);
1618 common->numbuffers = 0;
1619 common->set_addr = NULL;
1620 common->ytop_off = 0;
1621 common->ybtm_off = 0;
1622 common->ctop_off = 0;
1623 common->cbtm_off = 0;
1624 common->cur_frm = NULL;
1625 common->next_frm = NULL;
1626 memset(&common->fmt, 0, sizeof(common->fmt));
1627 common->numbuffers = config_params.numbuffers[k];
1628 }
1629 ch->initialized = 0;
1630 if (vpif_obj.config->subdev_count)
1631 ch->sd = vpif_obj.sd[0];
1632 ch->channel_id = j;
1633 if (j < 2)
1634 ch->common[VPIF_VIDEO_INDEX].numbuffers =
1635 config_params.numbuffers[ch->channel_id];
1636 else
1637 ch->common[VPIF_VIDEO_INDEX].numbuffers = 0;
1638
1639 memset(&ch->vpifparams, 0, sizeof(ch->vpifparams));
1640
1641 /* Initialize prio member of channel object */
1642 v4l2_prio_init(&ch->prio);
1643 ch->common[VPIF_VIDEO_INDEX].fmt.type =
1644 V4L2_BUF_TYPE_VIDEO_OUTPUT;
1645 ch->video_dev->lock = &common->lock;
1646 video_set_drvdata(ch->video_dev, ch);
1647
1648 /* select output 0 */
1649 err = vpif_set_output(vpif_obj.config, ch, 0);
1650 if (err)
1651 goto probe_out;
1652
Lad, Prabhakara2b235c2014-05-16 10:33:06 -03001653 /* Initialize vb2 queue */
1654 q = &common->buffer_queue;
1655 q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1656 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1657 q->drv_priv = ch;
1658 q->ops = &video_qops;
1659 q->mem_ops = &vb2_dma_contig_memops;
1660 q->buf_struct_size = sizeof(struct vpif_disp_buffer);
1661 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1662 q->min_buffers_needed = 1;
1663
1664 err = vb2_queue_init(q);
1665 if (err) {
1666 vpif_err("vpif_display: vb2_queue_init() failed\n");
1667 goto probe_out;
1668 }
1669
1670 common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
1671 if (IS_ERR(common->alloc_ctx)) {
1672 vpif_err("Failed to get the context\n");
1673 err = PTR_ERR(common->alloc_ctx);
1674 goto probe_out;
1675 }
1676
1677 INIT_LIST_HEAD(&common->dma_queue);
1678
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001679 /* register video device */
1680 vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n",
1681 (int)ch, (int)&ch->video_dev);
1682
1683 err = video_register_device(ch->video_dev,
1684 VFL_TYPE_GRABBER, (j ? 3 : 2));
1685 if (err < 0)
1686 goto probe_out;
1687 }
1688
1689 return 0;
1690
1691probe_out:
1692 for (k = 0; k < j; k++) {
1693 ch = vpif_obj.dev[k];
Lad, Prabhakara2b235c2014-05-16 10:33:06 -03001694 common = &ch->common[k];
1695 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001696 video_unregister_device(ch->video_dev);
1697 video_device_release(ch->video_dev);
1698 ch->video_dev = NULL;
1699 }
1700 return err;
1701}
1702
1703static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1704{
1705 return vpif_probe_complete();
1706}
1707
Chaithrika U Se7332e32009-06-09 05:55:37 -03001708/*
1709 * vpif_probe: This function creates device entries by register itself to the
1710 * V4L2 driver and initializes fields of each channel objects
1711 */
1712static __init int vpif_probe(struct platform_device *pdev)
1713{
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -03001714 struct vpif_subdev_info *subdevdata;
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001715 int i, j = 0, err = 0;
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001716 int res_idx = 0;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001717 struct i2c_adapter *i2c_adap;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001718 struct channel_obj *ch;
1719 struct video_device *vfd;
1720 struct resource *res;
1721 int subdev_count;
Manjunath Hadlifc613d42012-04-13 04:49:10 -03001722 size_t size;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001723
1724 vpif_dev = &pdev->dev;
Muralidharan Karicheri317b2e22009-09-16 14:30:53 -03001725 err = initialize_vpif();
1726
1727 if (err) {
1728 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1729 return err;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001730 }
1731
Chaithrika U Se7332e32009-06-09 05:55:37 -03001732 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1733 if (err) {
1734 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1735 return err;
1736 }
1737
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001738 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
Lad, Prabhakar379d2cf2013-06-17 11:20:51 -03001739 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
1740 IRQF_SHARED, "VPIF_Display",
1741 (void *)(&vpif_obj.dev[res_idx]->
1742 channel_id));
1743 if (err) {
1744 err = -EINVAL;
1745 vpif_err("VPIF IRQ request failed\n");
1746 goto vpif_unregister;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001747 }
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001748 res_idx++;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001749 }
1750
1751 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
Chaithrika U Se7332e32009-06-09 05:55:37 -03001752 /* Get the pointer to the channel object */
1753 ch = vpif_obj.dev[i];
1754
1755 /* Allocate memory for video device */
1756 vfd = video_device_alloc();
1757 if (vfd == NULL) {
1758 for (j = 0; j < i; j++) {
1759 ch = vpif_obj.dev[j];
1760 video_device_release(ch->video_dev);
1761 }
1762 err = -ENOMEM;
Lad, Prabhakar9c63e012013-06-17 11:20:50 -03001763 goto vpif_unregister;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001764 }
1765
1766 /* Initialize field of video device */
1767 *vfd = vpif_video_template;
1768 vfd->v4l2_dev = &vpif_obj.v4l2_dev;
1769 vfd->release = video_device_release;
Hans Verkuil954f3402012-09-05 06:05:50 -03001770 vfd->vfl_dir = VFL_DIR_TX;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001771 snprintf(vfd->name, sizeof(vfd->name),
Manjunath Hadli0a631722012-04-13 04:44:00 -03001772 "VPIF_Display_DRIVER_V%s",
Mauro Carvalho Chehab64dc3c12011-06-25 11:28:37 -03001773 VPIF_DISPLAY_VERSION);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001774
1775 /* Set video_dev to the video device */
1776 ch->video_dev = vfd;
1777 }
1778
Manjunath Hadlifc613d42012-04-13 04:49:10 -03001779 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1780 if (res) {
1781 size = resource_size(res);
1782 /* The resources are divided into two equal memory and when
1783 * we have HD output we can add them together
1784 */
1785 for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) {
1786 ch = vpif_obj.dev[j];
1787 ch->channel_id = j;
1788
1789 /* only enabled if second resource exists */
1790 config_params.video_limit[ch->channel_id] = 0;
1791 if (size)
1792 config_params.video_limit[ch->channel_id] =
1793 size/2;
1794 }
1795 }
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001796 vpif_obj.config = pdev->dev.platform_data;
1797 subdev_count = vpif_obj.config->subdev_count;
1798 subdevdata = vpif_obj.config->subdevinfo;
Hans Verkuile6067f82012-09-20 09:06:27 -03001799 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
1800 GFP_KERNEL);
1801 if (vpif_obj.sd == NULL) {
1802 vpif_err("unable to allocate memory for subdevice pointers\n");
1803 err = -ENOMEM;
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001804 goto vpif_sd_error;
Hans Verkuile6067f82012-09-20 09:06:27 -03001805 }
1806
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001807 if (!vpif_obj.config->asd_sizes) {
1808 i2c_adap = i2c_get_adapter(1);
1809 for (i = 0; i < subdev_count; i++) {
1810 vpif_obj.sd[i] =
1811 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1812 i2c_adap,
1813 &subdevdata[i].
1814 board_info,
1815 NULL);
1816 if (!vpif_obj.sd[i]) {
1817 vpif_err("Error registering v4l2 subdevice\n");
Wei Yongjun9d3e9762013-08-22 22:59:44 -03001818 err = -ENODEV;
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001819 goto probe_subdev_out;
1820 }
1821
1822 if (vpif_obj.sd[i])
1823 vpif_obj.sd[i]->grp_id = 1 << i;
1824 }
1825 vpif_probe_complete();
1826 } else {
Sylwester Nawrockie8419d02013-07-19 12:31:10 -03001827 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
Lad, Prabhakar4b8a5312013-06-25 11:17:35 -03001828 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1829 vpif_obj.notifier.bound = vpif_async_bound;
1830 vpif_obj.notifier.complete = vpif_async_complete;
1831 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1832 &vpif_obj.notifier);
1833 if (err) {
1834 vpif_err("Error registering async notifier\n");
1835 err = -EINVAL;
Hans Verkuile6067f82012-09-20 09:06:27 -03001836 goto probe_subdev_out;
1837 }
Hans Verkuile6067f82012-09-20 09:06:27 -03001838 }
1839
Chaithrika U Se7332e32009-06-09 05:55:37 -03001840 return 0;
1841
Hans Verkuile6067f82012-09-20 09:06:27 -03001842probe_subdev_out:
1843 kfree(vpif_obj.sd);
Hans Verkuil01b1d9752012-09-20 09:06:28 -03001844vpif_sd_error:
1845 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1846 ch = vpif_obj.dev[i];
1847 /* Note: does nothing if ch->video_dev == NULL */
1848 video_device_release(ch->video_dev);
1849 }
Lad, Prabhakar9c63e012013-06-17 11:20:50 -03001850vpif_unregister:
Chaithrika U Se7332e32009-06-09 05:55:37 -03001851 v4l2_device_unregister(&vpif_obj.v4l2_dev);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001852
1853 return err;
1854}
1855
1856/*
1857 * vpif_remove: It un-register channels from V4L2 driver
1858 */
1859static int vpif_remove(struct platform_device *device)
1860{
Lad, Prabhakara2b235c2014-05-16 10:33:06 -03001861 struct common_obj *common;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001862 struct channel_obj *ch;
Lad, Prabhakar9c63e012013-06-17 11:20:50 -03001863 int i;
Chaithrika U Se7332e32009-06-09 05:55:37 -03001864
1865 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1866
Lad, Prabhakar0b361582013-06-17 11:20:48 -03001867 kfree(vpif_obj.sd);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001868 /* un-register device */
1869 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1870 /* Get the pointer to the channel object */
1871 ch = vpif_obj.dev[i];
Lad, Prabhakara2b235c2014-05-16 10:33:06 -03001872 common = &ch->common[i];
1873 vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001874 /* Unregister video device */
1875 video_unregister_device(ch->video_dev);
1876
1877 ch->video_dev = NULL;
Lad, Prabhakar0b361582013-06-17 11:20:48 -03001878 kfree(vpif_obj.dev[i]);
Chaithrika U Se7332e32009-06-09 05:55:37 -03001879 }
1880
1881 return 0;
1882}
1883
Manjunath Hadlie9530da2012-04-13 04:50:35 -03001884#ifdef CONFIG_PM
1885static int vpif_suspend(struct device *dev)
1886{
1887 struct common_obj *common;
1888 struct channel_obj *ch;
1889 int i;
1890
1891 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1892 /* Get the pointer to the channel object */
1893 ch = vpif_obj.dev[i];
1894 common = &ch->common[VPIF_VIDEO_INDEX];
1895 mutex_lock(&common->lock);
1896 if (atomic_read(&ch->usrs) && common->io_usrs) {
1897 /* Disable channel */
1898 if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
1899 enable_channel2(0);
1900 channel2_intr_enable(0);
1901 }
1902 if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
1903 common->started == 2) {
1904 enable_channel3(0);
1905 channel3_intr_enable(0);
1906 }
1907 }
1908 mutex_unlock(&common->lock);
1909 }
1910
1911 return 0;
1912}
1913
1914static int vpif_resume(struct device *dev)
1915{
1916
1917 struct common_obj *common;
1918 struct channel_obj *ch;
1919 int i;
1920
1921 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1922 /* Get the pointer to the channel object */
1923 ch = vpif_obj.dev[i];
1924 common = &ch->common[VPIF_VIDEO_INDEX];
1925 mutex_lock(&common->lock);
1926 if (atomic_read(&ch->usrs) && common->io_usrs) {
1927 /* Enable channel */
1928 if (ch->channel_id == VPIF_CHANNEL2_VIDEO) {
1929 enable_channel2(1);
1930 channel2_intr_enable(1);
1931 }
1932 if (ch->channel_id == VPIF_CHANNEL3_VIDEO ||
1933 common->started == 2) {
1934 enable_channel3(1);
1935 channel3_intr_enable(1);
1936 }
1937 }
1938 mutex_unlock(&common->lock);
1939 }
1940
1941 return 0;
1942}
1943
1944static const struct dev_pm_ops vpif_pm = {
1945 .suspend = vpif_suspend,
1946 .resume = vpif_resume,
1947};
1948
1949#define vpif_pm_ops (&vpif_pm)
1950#else
1951#define vpif_pm_ops NULL
1952#endif
1953
Mats Randgaardffa1b392010-08-30 10:30:36 -03001954static __refdata struct platform_driver vpif_driver = {
Chaithrika U Se7332e32009-06-09 05:55:37 -03001955 .driver = {
1956 .name = "vpif_display",
1957 .owner = THIS_MODULE,
Manjunath Hadlie9530da2012-04-13 04:50:35 -03001958 .pm = vpif_pm_ops,
Chaithrika U Se7332e32009-06-09 05:55:37 -03001959 },
1960 .probe = vpif_probe,
1961 .remove = vpif_remove,
1962};
1963
Lad, Prabhakarb8d067b2013-06-17 11:20:49 -03001964module_platform_driver(vpif_driver);