diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-14 16:31:16 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-08-15 15:43:09 -0400 |
commit | 2c3fb08b3f74b8792004095a1f6881a3296ff643 (patch) | |
tree | 19be9d09c4aa66d4363ee9d38a43721f5d6b144f /drivers/media/video/davinci/vpif_display.c | |
parent | 2a2d1cf46500ab7599d0b45ee837f3936763ccac (diff) |
[media] rename drivers/media/video as .../platform
The remaining drivers are mostly platform drivers. Name the
dir to reflect it.
It makes sense to latter break it into a few other dirs.
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/davinci/vpif_display.c')
-rw-r--r-- | drivers/media/video/davinci/vpif_display.c | 2010 |
1 files changed, 0 insertions, 2010 deletions
diff --git a/drivers/media/video/davinci/vpif_display.c b/drivers/media/video/davinci/vpif_display.c deleted file mode 100644 index 4a24848c1a66..000000000000 --- a/drivers/media/video/davinci/vpif_display.c +++ /dev/null | |||
@@ -1,2010 +0,0 @@ | |||
1 | /* | ||
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 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/fs.h> | ||
22 | #include <linux/mm.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/workqueue.h> | ||
25 | #include <linux/string.h> | ||
26 | #include <linux/videodev2.h> | ||
27 | #include <linux/wait.h> | ||
28 | #include <linux/time.h> | ||
29 | #include <linux/i2c.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/io.h> | ||
32 | #include <linux/slab.h> | ||
33 | |||
34 | #include <asm/irq.h> | ||
35 | #include <asm/page.h> | ||
36 | |||
37 | #include <media/adv7343.h> | ||
38 | #include <media/v4l2-device.h> | ||
39 | #include <media/v4l2-ioctl.h> | ||
40 | #include <media/v4l2-chip-ident.h> | ||
41 | |||
42 | #include "vpif_display.h" | ||
43 | #include "vpif.h" | ||
44 | |||
45 | MODULE_DESCRIPTION("TI DaVinci VPIF Display driver"); | ||
46 | MODULE_LICENSE("GPL"); | ||
47 | MODULE_VERSION(VPIF_DISPLAY_VERSION); | ||
48 | |||
49 | #define VPIF_V4L2_STD (V4L2_STD_525_60 | V4L2_STD_625_50) | ||
50 | |||
51 | #define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg) | ||
52 | #define vpif_dbg(level, debug, fmt, arg...) \ | ||
53 | v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg) | ||
54 | |||
55 | static int debug = 1; | ||
56 | static u32 ch2_numbuffers = 3; | ||
57 | static u32 ch3_numbuffers = 3; | ||
58 | static u32 ch2_bufsize = 1920 * 1080 * 2; | ||
59 | static u32 ch3_bufsize = 720 * 576 * 2; | ||
60 | |||
61 | module_param(debug, int, 0644); | ||
62 | module_param(ch2_numbuffers, uint, S_IRUGO); | ||
63 | module_param(ch3_numbuffers, uint, S_IRUGO); | ||
64 | module_param(ch2_bufsize, uint, S_IRUGO); | ||
65 | module_param(ch3_bufsize, uint, S_IRUGO); | ||
66 | |||
67 | MODULE_PARM_DESC(debug, "Debug level 0-1"); | ||
68 | MODULE_PARM_DESC(ch2_numbuffers, "Channel2 buffer count (default:3)"); | ||
69 | MODULE_PARM_DESC(ch3_numbuffers, "Channel3 buffer count (default:3)"); | ||
70 | MODULE_PARM_DESC(ch2_bufsize, "Channel2 buffer size (default:1920 x 1080 x 2)"); | ||
71 | MODULE_PARM_DESC(ch3_bufsize, "Channel3 buffer size (default:720 x 576 x 2)"); | ||
72 | |||
73 | static struct vpif_config_params config_params = { | ||
74 | .min_numbuffers = 3, | ||
75 | .numbuffers[0] = 3, | ||
76 | .numbuffers[1] = 3, | ||
77 | .min_bufsize[0] = 720 * 480 * 2, | ||
78 | .min_bufsize[1] = 720 * 480 * 2, | ||
79 | .channel_bufsize[0] = 1920 * 1080 * 2, | ||
80 | .channel_bufsize[1] = 720 * 576 * 2, | ||
81 | }; | ||
82 | |||
83 | static struct vpif_device vpif_obj = { {NULL} }; | ||
84 | static struct device *vpif_dev; | ||
85 | static void vpif_calculate_offsets(struct channel_obj *ch); | ||
86 | static void vpif_config_addr(struct channel_obj *ch, int muxmode); | ||
87 | |||
88 | /* | ||
89 | * buffer_prepare: This is the callback function called from vb2_qbuf() | ||
90 | * function the buffer is prepared and user space virtual address is converted | ||
91 | * into physical address | ||
92 | */ | ||
93 | static int vpif_buffer_prepare(struct vb2_buffer *vb) | ||
94 | { | ||
95 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); | ||
96 | struct vb2_queue *q = vb->vb2_queue; | ||
97 | struct common_obj *common; | ||
98 | unsigned long addr; | ||
99 | |||
100 | common = &fh->channel->common[VPIF_VIDEO_INDEX]; | ||
101 | if (vb->state != VB2_BUF_STATE_ACTIVE && | ||
102 | vb->state != VB2_BUF_STATE_PREPARED) { | ||
103 | vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage); | ||
104 | if (vb2_plane_vaddr(vb, 0) && | ||
105 | vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) | ||
106 | goto buf_align_exit; | ||
107 | |||
108 | addr = vb2_dma_contig_plane_dma_addr(vb, 0); | ||
109 | if (q->streaming && | ||
110 | (V4L2_BUF_TYPE_SLICED_VBI_OUTPUT != q->type)) { | ||
111 | if (!ISALIGNED(addr + common->ytop_off) || | ||
112 | !ISALIGNED(addr + common->ybtm_off) || | ||
113 | !ISALIGNED(addr + common->ctop_off) || | ||
114 | !ISALIGNED(addr + common->cbtm_off)) | ||
115 | goto buf_align_exit; | ||
116 | } | ||
117 | } | ||
118 | return 0; | ||
119 | |||
120 | buf_align_exit: | ||
121 | vpif_err("buffer offset not aligned to 8 bytes\n"); | ||
122 | return -EINVAL; | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * vpif_buffer_queue_setup: This function allocates memory for the buffers | ||
127 | */ | ||
128 | static int vpif_buffer_queue_setup(struct vb2_queue *vq, | ||
129 | const struct v4l2_format *fmt, | ||
130 | unsigned int *nbuffers, unsigned int *nplanes, | ||
131 | unsigned int sizes[], void *alloc_ctxs[]) | ||
132 | { | ||
133 | struct vpif_fh *fh = vb2_get_drv_priv(vq); | ||
134 | struct channel_obj *ch = fh->channel; | ||
135 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
136 | unsigned long size; | ||
137 | |||
138 | if (V4L2_MEMORY_MMAP == common->memory) { | ||
139 | size = config_params.channel_bufsize[ch->channel_id]; | ||
140 | /* | ||
141 | * Checking if the buffer size exceeds the available buffer | ||
142 | * ycmux_mode = 0 means 1 channel mode HD and | ||
143 | * ycmux_mode = 1 means 2 channels mode SD | ||
144 | */ | ||
145 | if (ch->vpifparams.std_info.ycmux_mode == 0) { | ||
146 | if (config_params.video_limit[ch->channel_id]) | ||
147 | while (size * *nbuffers > | ||
148 | (config_params.video_limit[0] | ||
149 | + config_params.video_limit[1])) | ||
150 | (*nbuffers)--; | ||
151 | } else { | ||
152 | if (config_params.video_limit[ch->channel_id]) | ||
153 | while (size * *nbuffers > | ||
154 | config_params.video_limit[ch->channel_id]) | ||
155 | (*nbuffers)--; | ||
156 | } | ||
157 | } else { | ||
158 | size = common->fmt.fmt.pix.sizeimage; | ||
159 | } | ||
160 | |||
161 | if (*nbuffers < config_params.min_numbuffers) | ||
162 | *nbuffers = config_params.min_numbuffers; | ||
163 | |||
164 | *nplanes = 1; | ||
165 | sizes[0] = size; | ||
166 | alloc_ctxs[0] = common->alloc_ctx; | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* | ||
171 | * vpif_buffer_queue: This function adds the buffer to DMA queue | ||
172 | */ | ||
173 | static void vpif_buffer_queue(struct vb2_buffer *vb) | ||
174 | { | ||
175 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); | ||
176 | struct vpif_disp_buffer *buf = container_of(vb, | ||
177 | struct vpif_disp_buffer, vb); | ||
178 | struct channel_obj *ch = fh->channel; | ||
179 | struct common_obj *common; | ||
180 | |||
181 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
182 | |||
183 | /* add the buffer to the DMA queue */ | ||
184 | list_add_tail(&buf->list, &common->dma_queue); | ||
185 | } | ||
186 | |||
187 | /* | ||
188 | * vpif_buf_cleanup: This function is called from the videobuf2 layer to | ||
189 | * free memory allocated to the buffers | ||
190 | */ | ||
191 | static void vpif_buf_cleanup(struct vb2_buffer *vb) | ||
192 | { | ||
193 | struct vpif_fh *fh = vb2_get_drv_priv(vb->vb2_queue); | ||
194 | struct vpif_disp_buffer *buf = container_of(vb, | ||
195 | struct vpif_disp_buffer, vb); | ||
196 | struct channel_obj *ch = fh->channel; | ||
197 | struct common_obj *common; | ||
198 | unsigned long flags; | ||
199 | |||
200 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
201 | |||
202 | spin_lock_irqsave(&common->irqlock, flags); | ||
203 | if (vb->state == VB2_BUF_STATE_ACTIVE) | ||
204 | list_del_init(&buf->list); | ||
205 | spin_unlock_irqrestore(&common->irqlock, flags); | ||
206 | } | ||
207 | |||
208 | static void vpif_wait_prepare(struct vb2_queue *vq) | ||
209 | { | ||
210 | struct vpif_fh *fh = vb2_get_drv_priv(vq); | ||
211 | struct channel_obj *ch = fh->channel; | ||
212 | struct common_obj *common; | ||
213 | |||
214 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
215 | mutex_unlock(&common->lock); | ||
216 | } | ||
217 | |||
218 | static void vpif_wait_finish(struct vb2_queue *vq) | ||
219 | { | ||
220 | struct vpif_fh *fh = vb2_get_drv_priv(vq); | ||
221 | struct channel_obj *ch = fh->channel; | ||
222 | struct common_obj *common; | ||
223 | |||
224 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
225 | mutex_lock(&common->lock); | ||
226 | } | ||
227 | |||
228 | static int vpif_buffer_init(struct vb2_buffer *vb) | ||
229 | { | ||
230 | struct vpif_disp_buffer *buf = container_of(vb, | ||
231 | struct vpif_disp_buffer, vb); | ||
232 | |||
233 | INIT_LIST_HEAD(&buf->list); | ||
234 | |||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | static u8 channel_first_int[VPIF_NUMOBJECTS][2] = { {1, 1} }; | ||
239 | |||
240 | static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count) | ||
241 | { | ||
242 | struct vpif_display_config *vpif_config_data = | ||
243 | vpif_dev->platform_data; | ||
244 | struct vpif_fh *fh = vb2_get_drv_priv(vq); | ||
245 | struct channel_obj *ch = fh->channel; | ||
246 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
247 | struct vpif_params *vpif = &ch->vpifparams; | ||
248 | unsigned long addr = 0; | ||
249 | int ret; | ||
250 | |||
251 | /* If buffer queue is empty, return error */ | ||
252 | if (list_empty(&common->dma_queue)) { | ||
253 | vpif_err("buffer queue is empty\n"); | ||
254 | return -EIO; | ||
255 | } | ||
256 | |||
257 | /* Get the next frame from the buffer queue */ | ||
258 | common->next_frm = common->cur_frm = | ||
259 | list_entry(common->dma_queue.next, | ||
260 | struct vpif_disp_buffer, list); | ||
261 | |||
262 | list_del(&common->cur_frm->list); | ||
263 | /* Mark state of the current frame to active */ | ||
264 | common->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE; | ||
265 | |||
266 | /* Initialize field_id and started member */ | ||
267 | ch->field_id = 0; | ||
268 | common->started = 1; | ||
269 | addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0); | ||
270 | /* Calculate the offset for Y and C data in the buffer */ | ||
271 | vpif_calculate_offsets(ch); | ||
272 | |||
273 | if ((ch->vpifparams.std_info.frm_fmt && | ||
274 | ((common->fmt.fmt.pix.field != V4L2_FIELD_NONE) | ||
275 | && (common->fmt.fmt.pix.field != V4L2_FIELD_ANY))) | ||
276 | || (!ch->vpifparams.std_info.frm_fmt | ||
277 | && (common->fmt.fmt.pix.field == V4L2_FIELD_NONE))) { | ||
278 | vpif_err("conflict in field format and std format\n"); | ||
279 | return -EINVAL; | ||
280 | } | ||
281 | |||
282 | /* clock settings */ | ||
283 | ret = | ||
284 | vpif_config_data->set_clock(ch->vpifparams.std_info.ycmux_mode, | ||
285 | ch->vpifparams.std_info.hd_sd); | ||
286 | if (ret < 0) { | ||
287 | vpif_err("can't set clock\n"); | ||
288 | return ret; | ||
289 | } | ||
290 | |||
291 | /* set the parameters and addresses */ | ||
292 | ret = vpif_set_video_params(vpif, ch->channel_id + 2); | ||
293 | if (ret < 0) | ||
294 | return ret; | ||
295 | |||
296 | common->started = ret; | ||
297 | vpif_config_addr(ch, ret); | ||
298 | common->set_addr((addr + common->ytop_off), | ||
299 | (addr + common->ybtm_off), | ||
300 | (addr + common->ctop_off), | ||
301 | (addr + common->cbtm_off)); | ||
302 | |||
303 | /* Set interrupt for both the fields in VPIF | ||
304 | Register enable channel in VPIF register */ | ||
305 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { | ||
306 | channel2_intr_assert(); | ||
307 | channel2_intr_enable(1); | ||
308 | enable_channel2(1); | ||
309 | if (vpif_config_data->ch2_clip_en) | ||
310 | channel2_clipping_enable(1); | ||
311 | } | ||
312 | |||
313 | if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) | ||
314 | || (common->started == 2)) { | ||
315 | channel3_intr_assert(); | ||
316 | channel3_intr_enable(1); | ||
317 | enable_channel3(1); | ||
318 | if (vpif_config_data->ch3_clip_en) | ||
319 | channel3_clipping_enable(1); | ||
320 | } | ||
321 | channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1; | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | /* abort streaming and wait for last buffer */ | ||
327 | static int vpif_stop_streaming(struct vb2_queue *vq) | ||
328 | { | ||
329 | struct vpif_fh *fh = vb2_get_drv_priv(vq); | ||
330 | struct channel_obj *ch = fh->channel; | ||
331 | struct common_obj *common; | ||
332 | |||
333 | if (!vb2_is_streaming(vq)) | ||
334 | return 0; | ||
335 | |||
336 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
337 | |||
338 | /* release all active buffers */ | ||
339 | while (!list_empty(&common->dma_queue)) { | ||
340 | common->next_frm = list_entry(common->dma_queue.next, | ||
341 | struct vpif_disp_buffer, list); | ||
342 | list_del(&common->next_frm->list); | ||
343 | vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR); | ||
344 | } | ||
345 | |||
346 | return 0; | ||
347 | } | ||
348 | |||
349 | static struct vb2_ops video_qops = { | ||
350 | .queue_setup = vpif_buffer_queue_setup, | ||
351 | .wait_prepare = vpif_wait_prepare, | ||
352 | .wait_finish = vpif_wait_finish, | ||
353 | .buf_init = vpif_buffer_init, | ||
354 | .buf_prepare = vpif_buffer_prepare, | ||
355 | .start_streaming = vpif_start_streaming, | ||
356 | .stop_streaming = vpif_stop_streaming, | ||
357 | .buf_cleanup = vpif_buf_cleanup, | ||
358 | .buf_queue = vpif_buffer_queue, | ||
359 | }; | ||
360 | |||
361 | static void process_progressive_mode(struct common_obj *common) | ||
362 | { | ||
363 | unsigned long addr = 0; | ||
364 | |||
365 | /* Get the next buffer from buffer queue */ | ||
366 | common->next_frm = list_entry(common->dma_queue.next, | ||
367 | struct vpif_disp_buffer, list); | ||
368 | /* Remove that buffer from the buffer queue */ | ||
369 | list_del(&common->next_frm->list); | ||
370 | /* Mark status of the buffer as active */ | ||
371 | common->next_frm->vb.state = VB2_BUF_STATE_ACTIVE; | ||
372 | |||
373 | /* Set top and bottom field addrs in VPIF registers */ | ||
374 | addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0); | ||
375 | common->set_addr(addr + common->ytop_off, | ||
376 | addr + common->ybtm_off, | ||
377 | addr + common->ctop_off, | ||
378 | addr + common->cbtm_off); | ||
379 | } | ||
380 | |||
381 | static void process_interlaced_mode(int fid, struct common_obj *common) | ||
382 | { | ||
383 | /* device field id and local field id are in sync */ | ||
384 | /* If this is even field */ | ||
385 | if (0 == fid) { | ||
386 | if (common->cur_frm == common->next_frm) | ||
387 | return; | ||
388 | |||
389 | /* one frame is displayed If next frame is | ||
390 | * available, release cur_frm and move on */ | ||
391 | /* Copy frame display time */ | ||
392 | do_gettimeofday(&common->cur_frm->vb.v4l2_buf.timestamp); | ||
393 | /* Change status of the cur_frm */ | ||
394 | vb2_buffer_done(&common->cur_frm->vb, | ||
395 | VB2_BUF_STATE_DONE); | ||
396 | /* Make cur_frm pointing to next_frm */ | ||
397 | common->cur_frm = common->next_frm; | ||
398 | |||
399 | } else if (1 == fid) { /* odd field */ | ||
400 | if (list_empty(&common->dma_queue) | ||
401 | || (common->cur_frm != common->next_frm)) { | ||
402 | return; | ||
403 | } | ||
404 | /* one field is displayed configure the next | ||
405 | * frame if it is available else hold on current | ||
406 | * frame */ | ||
407 | /* Get next from the buffer queue */ | ||
408 | process_progressive_mode(common); | ||
409 | |||
410 | } | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * vpif_channel_isr: It changes status of the displayed buffer, takes next | ||
415 | * buffer from the queue and sets its address in VPIF registers | ||
416 | */ | ||
417 | static irqreturn_t vpif_channel_isr(int irq, void *dev_id) | ||
418 | { | ||
419 | struct vpif_device *dev = &vpif_obj; | ||
420 | struct channel_obj *ch; | ||
421 | struct common_obj *common; | ||
422 | enum v4l2_field field; | ||
423 | int fid = -1, i; | ||
424 | int channel_id = 0; | ||
425 | |||
426 | channel_id = *(int *)(dev_id); | ||
427 | if (!vpif_intr_status(channel_id + 2)) | ||
428 | return IRQ_NONE; | ||
429 | |||
430 | ch = dev->dev[channel_id]; | ||
431 | field = ch->common[VPIF_VIDEO_INDEX].fmt.fmt.pix.field; | ||
432 | for (i = 0; i < VPIF_NUMOBJECTS; i++) { | ||
433 | common = &ch->common[i]; | ||
434 | /* If streaming is started in this channel */ | ||
435 | if (0 == common->started) | ||
436 | continue; | ||
437 | |||
438 | if (1 == ch->vpifparams.std_info.frm_fmt) { | ||
439 | if (list_empty(&common->dma_queue)) | ||
440 | continue; | ||
441 | |||
442 | /* Progressive mode */ | ||
443 | if (!channel_first_int[i][channel_id]) { | ||
444 | /* Mark status of the cur_frm to | ||
445 | * done and unlock semaphore on it */ | ||
446 | do_gettimeofday(&common->cur_frm->vb. | ||
447 | v4l2_buf.timestamp); | ||
448 | vb2_buffer_done(&common->cur_frm->vb, | ||
449 | VB2_BUF_STATE_DONE); | ||
450 | /* Make cur_frm pointing to next_frm */ | ||
451 | common->cur_frm = common->next_frm; | ||
452 | } | ||
453 | |||
454 | channel_first_int[i][channel_id] = 0; | ||
455 | process_progressive_mode(common); | ||
456 | } else { | ||
457 | /* Interlaced mode */ | ||
458 | /* If it is first interrupt, ignore it */ | ||
459 | |||
460 | if (channel_first_int[i][channel_id]) { | ||
461 | channel_first_int[i][channel_id] = 0; | ||
462 | continue; | ||
463 | } | ||
464 | |||
465 | if (0 == i) { | ||
466 | ch->field_id ^= 1; | ||
467 | /* Get field id from VPIF registers */ | ||
468 | fid = vpif_channel_getfid(ch->channel_id + 2); | ||
469 | /* If fid does not match with stored field id */ | ||
470 | if (fid != ch->field_id) { | ||
471 | /* Make them in sync */ | ||
472 | if (0 == fid) | ||
473 | ch->field_id = fid; | ||
474 | |||
475 | return IRQ_HANDLED; | ||
476 | } | ||
477 | } | ||
478 | process_interlaced_mode(fid, common); | ||
479 | } | ||
480 | } | ||
481 | |||
482 | return IRQ_HANDLED; | ||
483 | } | ||
484 | |||
485 | static int vpif_update_std_info(struct channel_obj *ch) | ||
486 | { | ||
487 | struct video_obj *vid_ch = &ch->video; | ||
488 | struct vpif_params *vpifparams = &ch->vpifparams; | ||
489 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; | ||
490 | const struct vpif_channel_config_params *config; | ||
491 | |||
492 | int i; | ||
493 | |||
494 | for (i = 0; i < vpif_ch_params_count; i++) { | ||
495 | config = &ch_params[i]; | ||
496 | if (config->hd_sd == 0) { | ||
497 | vpif_dbg(2, debug, "SD format\n"); | ||
498 | if (config->stdid & vid_ch->stdid) { | ||
499 | memcpy(std_info, config, sizeof(*config)); | ||
500 | break; | ||
501 | } | ||
502 | } else { | ||
503 | vpif_dbg(2, debug, "HD format\n"); | ||
504 | if (config->dv_preset == vid_ch->dv_preset) { | ||
505 | memcpy(std_info, config, sizeof(*config)); | ||
506 | break; | ||
507 | } | ||
508 | } | ||
509 | } | ||
510 | |||
511 | if (i == vpif_ch_params_count) { | ||
512 | vpif_dbg(1, debug, "Format not found\n"); | ||
513 | return -EINVAL; | ||
514 | } | ||
515 | |||
516 | return 0; | ||
517 | } | ||
518 | |||
519 | static int vpif_update_resolution(struct channel_obj *ch) | ||
520 | { | ||
521 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
522 | struct video_obj *vid_ch = &ch->video; | ||
523 | struct vpif_params *vpifparams = &ch->vpifparams; | ||
524 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; | ||
525 | |||
526 | if (!vid_ch->stdid && !vid_ch->dv_preset && !vid_ch->bt_timings.height) | ||
527 | return -EINVAL; | ||
528 | |||
529 | if (vid_ch->stdid || vid_ch->dv_preset) { | ||
530 | if (vpif_update_std_info(ch)) | ||
531 | return -EINVAL; | ||
532 | } | ||
533 | |||
534 | common->fmt.fmt.pix.width = std_info->width; | ||
535 | common->fmt.fmt.pix.height = std_info->height; | ||
536 | vpif_dbg(1, debug, "Pixel details: Width = %d,Height = %d\n", | ||
537 | common->fmt.fmt.pix.width, common->fmt.fmt.pix.height); | ||
538 | |||
539 | /* Set height and width paramateres */ | ||
540 | common->height = std_info->height; | ||
541 | common->width = std_info->width; | ||
542 | |||
543 | return 0; | ||
544 | } | ||
545 | |||
546 | /* | ||
547 | * vpif_calculate_offsets: This function calculates buffers offset for Y and C | ||
548 | * in the top and bottom field | ||
549 | */ | ||
550 | static void vpif_calculate_offsets(struct channel_obj *ch) | ||
551 | { | ||
552 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
553 | struct vpif_params *vpifparams = &ch->vpifparams; | ||
554 | enum v4l2_field field = common->fmt.fmt.pix.field; | ||
555 | struct video_obj *vid_ch = &ch->video; | ||
556 | unsigned int hpitch, vpitch, sizeimage; | ||
557 | |||
558 | if (V4L2_FIELD_ANY == common->fmt.fmt.pix.field) { | ||
559 | if (ch->vpifparams.std_info.frm_fmt) | ||
560 | vid_ch->buf_field = V4L2_FIELD_NONE; | ||
561 | else | ||
562 | vid_ch->buf_field = V4L2_FIELD_INTERLACED; | ||
563 | } else { | ||
564 | vid_ch->buf_field = common->fmt.fmt.pix.field; | ||
565 | } | ||
566 | |||
567 | sizeimage = common->fmt.fmt.pix.sizeimage; | ||
568 | |||
569 | hpitch = common->fmt.fmt.pix.bytesperline; | ||
570 | vpitch = sizeimage / (hpitch * 2); | ||
571 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || | ||
572 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { | ||
573 | common->ytop_off = 0; | ||
574 | common->ybtm_off = hpitch; | ||
575 | common->ctop_off = sizeimage / 2; | ||
576 | common->cbtm_off = sizeimage / 2 + hpitch; | ||
577 | } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) { | ||
578 | common->ytop_off = 0; | ||
579 | common->ybtm_off = sizeimage / 4; | ||
580 | common->ctop_off = sizeimage / 2; | ||
581 | common->cbtm_off = common->ctop_off + sizeimage / 4; | ||
582 | } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) { | ||
583 | common->ybtm_off = 0; | ||
584 | common->ytop_off = sizeimage / 4; | ||
585 | common->cbtm_off = sizeimage / 2; | ||
586 | common->ctop_off = common->cbtm_off + sizeimage / 4; | ||
587 | } | ||
588 | |||
589 | if ((V4L2_FIELD_NONE == vid_ch->buf_field) || | ||
590 | (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) { | ||
591 | vpifparams->video_params.storage_mode = 1; | ||
592 | } else { | ||
593 | vpifparams->video_params.storage_mode = 0; | ||
594 | } | ||
595 | |||
596 | if (ch->vpifparams.std_info.frm_fmt == 1) { | ||
597 | vpifparams->video_params.hpitch = | ||
598 | common->fmt.fmt.pix.bytesperline; | ||
599 | } else { | ||
600 | if ((field == V4L2_FIELD_ANY) || | ||
601 | (field == V4L2_FIELD_INTERLACED)) | ||
602 | vpifparams->video_params.hpitch = | ||
603 | common->fmt.fmt.pix.bytesperline * 2; | ||
604 | else | ||
605 | vpifparams->video_params.hpitch = | ||
606 | common->fmt.fmt.pix.bytesperline; | ||
607 | } | ||
608 | |||
609 | ch->vpifparams.video_params.stdid = ch->vpifparams.std_info.stdid; | ||
610 | } | ||
611 | |||
612 | static void vpif_config_format(struct channel_obj *ch) | ||
613 | { | ||
614 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
615 | |||
616 | common->fmt.fmt.pix.field = V4L2_FIELD_ANY; | ||
617 | if (config_params.numbuffers[ch->channel_id] == 0) | ||
618 | common->memory = V4L2_MEMORY_USERPTR; | ||
619 | else | ||
620 | common->memory = V4L2_MEMORY_MMAP; | ||
621 | |||
622 | common->fmt.fmt.pix.sizeimage = | ||
623 | config_params.channel_bufsize[ch->channel_id]; | ||
624 | common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P; | ||
625 | common->fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | ||
626 | } | ||
627 | |||
628 | static int vpif_check_format(struct channel_obj *ch, | ||
629 | struct v4l2_pix_format *pixfmt) | ||
630 | { | ||
631 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
632 | enum v4l2_field field = pixfmt->field; | ||
633 | u32 sizeimage, hpitch, vpitch; | ||
634 | |||
635 | if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P) | ||
636 | goto invalid_fmt_exit; | ||
637 | |||
638 | if (!(VPIF_VALID_FIELD(field))) | ||
639 | goto invalid_fmt_exit; | ||
640 | |||
641 | if (pixfmt->bytesperline <= 0) | ||
642 | goto invalid_pitch_exit; | ||
643 | |||
644 | sizeimage = pixfmt->sizeimage; | ||
645 | |||
646 | if (vpif_update_resolution(ch)) | ||
647 | return -EINVAL; | ||
648 | |||
649 | hpitch = pixfmt->bytesperline; | ||
650 | vpitch = sizeimage / (hpitch * 2); | ||
651 | |||
652 | /* Check for valid value of pitch */ | ||
653 | if ((hpitch < ch->vpifparams.std_info.width) || | ||
654 | (vpitch < ch->vpifparams.std_info.height)) | ||
655 | goto invalid_pitch_exit; | ||
656 | |||
657 | /* Check for 8 byte alignment */ | ||
658 | if (!ISALIGNED(hpitch)) { | ||
659 | vpif_err("invalid pitch alignment\n"); | ||
660 | return -EINVAL; | ||
661 | } | ||
662 | pixfmt->width = common->fmt.fmt.pix.width; | ||
663 | pixfmt->height = common->fmt.fmt.pix.height; | ||
664 | |||
665 | return 0; | ||
666 | |||
667 | invalid_fmt_exit: | ||
668 | vpif_err("invalid field format\n"); | ||
669 | return -EINVAL; | ||
670 | |||
671 | invalid_pitch_exit: | ||
672 | vpif_err("invalid pitch\n"); | ||
673 | return -EINVAL; | ||
674 | } | ||
675 | |||
676 | static void vpif_config_addr(struct channel_obj *ch, int muxmode) | ||
677 | { | ||
678 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
679 | |||
680 | if (VPIF_CHANNEL3_VIDEO == ch->channel_id) { | ||
681 | common->set_addr = ch3_set_videobuf_addr; | ||
682 | } else { | ||
683 | if (2 == muxmode) | ||
684 | common->set_addr = ch2_set_videobuf_addr_yc_nmux; | ||
685 | else | ||
686 | common->set_addr = ch2_set_videobuf_addr; | ||
687 | } | ||
688 | } | ||
689 | |||
690 | /* | ||
691 | * vpif_mmap: It is used to map kernel space buffers into user spaces | ||
692 | */ | ||
693 | static int vpif_mmap(struct file *filep, struct vm_area_struct *vma) | ||
694 | { | ||
695 | struct vpif_fh *fh = filep->private_data; | ||
696 | struct channel_obj *ch = fh->channel; | ||
697 | struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]); | ||
698 | int ret; | ||
699 | |||
700 | vpif_dbg(2, debug, "vpif_mmap\n"); | ||
701 | |||
702 | if (mutex_lock_interruptible(&common->lock)) | ||
703 | return -ERESTARTSYS; | ||
704 | ret = vb2_mmap(&common->buffer_queue, vma); | ||
705 | mutex_unlock(&common->lock); | ||
706 | return ret; | ||
707 | } | ||
708 | |||
709 | /* | ||
710 | * vpif_poll: It is used for select/poll system call | ||
711 | */ | ||
712 | static unsigned int vpif_poll(struct file *filep, poll_table *wait) | ||
713 | { | ||
714 | struct vpif_fh *fh = filep->private_data; | ||
715 | struct channel_obj *ch = fh->channel; | ||
716 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
717 | unsigned int res = 0; | ||
718 | |||
719 | if (common->started) { | ||
720 | mutex_lock(&common->lock); | ||
721 | res = vb2_poll(&common->buffer_queue, filep, wait); | ||
722 | mutex_unlock(&common->lock); | ||
723 | } | ||
724 | |||
725 | return res; | ||
726 | } | ||
727 | |||
728 | /* | ||
729 | * vpif_open: It creates object of file handle structure and stores it in | ||
730 | * private_data member of filepointer | ||
731 | */ | ||
732 | static int vpif_open(struct file *filep) | ||
733 | { | ||
734 | struct video_device *vdev = video_devdata(filep); | ||
735 | struct channel_obj *ch = video_get_drvdata(vdev); | ||
736 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
737 | struct vpif_fh *fh; | ||
738 | |||
739 | /* Allocate memory for the file handle object */ | ||
740 | fh = kzalloc(sizeof(struct vpif_fh), GFP_KERNEL); | ||
741 | if (fh == NULL) { | ||
742 | vpif_err("unable to allocate memory for file handle object\n"); | ||
743 | return -ENOMEM; | ||
744 | } | ||
745 | |||
746 | if (mutex_lock_interruptible(&common->lock)) { | ||
747 | kfree(fh); | ||
748 | return -ERESTARTSYS; | ||
749 | } | ||
750 | /* store pointer to fh in private_data member of filep */ | ||
751 | filep->private_data = fh; | ||
752 | fh->channel = ch; | ||
753 | fh->initialized = 0; | ||
754 | if (!ch->initialized) { | ||
755 | fh->initialized = 1; | ||
756 | ch->initialized = 1; | ||
757 | memset(&ch->vpifparams, 0, sizeof(ch->vpifparams)); | ||
758 | } | ||
759 | |||
760 | /* Increment channel usrs counter */ | ||
761 | atomic_inc(&ch->usrs); | ||
762 | /* Set io_allowed[VPIF_VIDEO_INDEX] member to false */ | ||
763 | fh->io_allowed[VPIF_VIDEO_INDEX] = 0; | ||
764 | /* Initialize priority of this instance to default priority */ | ||
765 | fh->prio = V4L2_PRIORITY_UNSET; | ||
766 | v4l2_prio_open(&ch->prio, &fh->prio); | ||
767 | mutex_unlock(&common->lock); | ||
768 | |||
769 | return 0; | ||
770 | } | ||
771 | |||
772 | /* | ||
773 | * vpif_release: This function deletes buffer queue, frees the buffers and | ||
774 | * the vpif file handle | ||
775 | */ | ||
776 | static int vpif_release(struct file *filep) | ||
777 | { | ||
778 | struct vpif_fh *fh = filep->private_data; | ||
779 | struct channel_obj *ch = fh->channel; | ||
780 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
781 | |||
782 | mutex_lock(&common->lock); | ||
783 | /* if this instance is doing IO */ | ||
784 | if (fh->io_allowed[VPIF_VIDEO_INDEX]) { | ||
785 | /* Reset io_usrs member of channel object */ | ||
786 | common->io_usrs = 0; | ||
787 | /* Disable channel */ | ||
788 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { | ||
789 | enable_channel2(0); | ||
790 | channel2_intr_enable(0); | ||
791 | } | ||
792 | if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) || | ||
793 | (2 == common->started)) { | ||
794 | enable_channel3(0); | ||
795 | channel3_intr_enable(0); | ||
796 | } | ||
797 | common->started = 0; | ||
798 | |||
799 | /* Free buffers allocated */ | ||
800 | vb2_queue_release(&common->buffer_queue); | ||
801 | vb2_dma_contig_cleanup_ctx(common->alloc_ctx); | ||
802 | |||
803 | common->numbuffers = | ||
804 | config_params.numbuffers[ch->channel_id]; | ||
805 | } | ||
806 | |||
807 | /* Decrement channel usrs counter */ | ||
808 | atomic_dec(&ch->usrs); | ||
809 | /* If this file handle has initialize encoder device, reset it */ | ||
810 | if (fh->initialized) | ||
811 | ch->initialized = 0; | ||
812 | |||
813 | /* Close the priority */ | ||
814 | v4l2_prio_close(&ch->prio, fh->prio); | ||
815 | filep->private_data = NULL; | ||
816 | fh->initialized = 0; | ||
817 | mutex_unlock(&common->lock); | ||
818 | kfree(fh); | ||
819 | |||
820 | return 0; | ||
821 | } | ||
822 | |||
823 | /* functions implementing ioctls */ | ||
824 | /** | ||
825 | * vpif_querycap() - QUERYCAP handler | ||
826 | * @file: file ptr | ||
827 | * @priv: file handle | ||
828 | * @cap: ptr to v4l2_capability structure | ||
829 | */ | ||
830 | static int vpif_querycap(struct file *file, void *priv, | ||
831 | struct v4l2_capability *cap) | ||
832 | { | ||
833 | struct vpif_display_config *config = vpif_dev->platform_data; | ||
834 | |||
835 | cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; | ||
836 | strlcpy(cap->driver, "vpif display", sizeof(cap->driver)); | ||
837 | strlcpy(cap->bus_info, "Platform", sizeof(cap->bus_info)); | ||
838 | strlcpy(cap->card, config->card_name, sizeof(cap->card)); | ||
839 | |||
840 | return 0; | ||
841 | } | ||
842 | |||
843 | static int vpif_enum_fmt_vid_out(struct file *file, void *priv, | ||
844 | struct v4l2_fmtdesc *fmt) | ||
845 | { | ||
846 | if (fmt->index != 0) { | ||
847 | vpif_err("Invalid format index\n"); | ||
848 | return -EINVAL; | ||
849 | } | ||
850 | |||
851 | /* Fill in the information about format */ | ||
852 | fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | ||
853 | strcpy(fmt->description, "YCbCr4:2:2 YC Planar"); | ||
854 | fmt->pixelformat = V4L2_PIX_FMT_YUV422P; | ||
855 | |||
856 | return 0; | ||
857 | } | ||
858 | |||
859 | static int vpif_g_fmt_vid_out(struct file *file, void *priv, | ||
860 | struct v4l2_format *fmt) | ||
861 | { | ||
862 | struct vpif_fh *fh = priv; | ||
863 | struct channel_obj *ch = fh->channel; | ||
864 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
865 | |||
866 | /* Check the validity of the buffer type */ | ||
867 | if (common->fmt.type != fmt->type) | ||
868 | return -EINVAL; | ||
869 | |||
870 | if (vpif_update_resolution(ch)) | ||
871 | return -EINVAL; | ||
872 | *fmt = common->fmt; | ||
873 | return 0; | ||
874 | } | ||
875 | |||
876 | static int vpif_s_fmt_vid_out(struct file *file, void *priv, | ||
877 | struct v4l2_format *fmt) | ||
878 | { | ||
879 | struct vpif_fh *fh = priv; | ||
880 | struct v4l2_pix_format *pixfmt; | ||
881 | struct channel_obj *ch = fh->channel; | ||
882 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
883 | int ret = 0; | ||
884 | |||
885 | if ((VPIF_CHANNEL2_VIDEO == ch->channel_id) | ||
886 | || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) { | ||
887 | if (!fh->initialized) { | ||
888 | vpif_dbg(1, debug, "Channel Busy\n"); | ||
889 | return -EBUSY; | ||
890 | } | ||
891 | |||
892 | /* Check for the priority */ | ||
893 | ret = v4l2_prio_check(&ch->prio, fh->prio); | ||
894 | if (0 != ret) | ||
895 | return ret; | ||
896 | fh->initialized = 1; | ||
897 | } | ||
898 | |||
899 | if (common->started) { | ||
900 | vpif_dbg(1, debug, "Streaming in progress\n"); | ||
901 | return -EBUSY; | ||
902 | } | ||
903 | |||
904 | pixfmt = &fmt->fmt.pix; | ||
905 | /* Check for valid field format */ | ||
906 | ret = vpif_check_format(ch, pixfmt); | ||
907 | if (ret) | ||
908 | return ret; | ||
909 | |||
910 | /* store the pix format in the channel object */ | ||
911 | common->fmt.fmt.pix = *pixfmt; | ||
912 | /* store the format in the channel object */ | ||
913 | common->fmt = *fmt; | ||
914 | return 0; | ||
915 | } | ||
916 | |||
917 | static int vpif_try_fmt_vid_out(struct file *file, void *priv, | ||
918 | struct v4l2_format *fmt) | ||
919 | { | ||
920 | struct vpif_fh *fh = priv; | ||
921 | struct channel_obj *ch = fh->channel; | ||
922 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
923 | struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; | ||
924 | int ret = 0; | ||
925 | |||
926 | ret = vpif_check_format(ch, pixfmt); | ||
927 | if (ret) { | ||
928 | *pixfmt = common->fmt.fmt.pix; | ||
929 | pixfmt->sizeimage = pixfmt->width * pixfmt->height * 2; | ||
930 | } | ||
931 | |||
932 | return ret; | ||
933 | } | ||
934 | |||
935 | static int vpif_reqbufs(struct file *file, void *priv, | ||
936 | struct v4l2_requestbuffers *reqbuf) | ||
937 | { | ||
938 | struct vpif_fh *fh = priv; | ||
939 | struct channel_obj *ch = fh->channel; | ||
940 | struct common_obj *common; | ||
941 | enum v4l2_field field; | ||
942 | struct vb2_queue *q; | ||
943 | u8 index = 0; | ||
944 | |||
945 | /* This file handle has not initialized the channel, | ||
946 | It is not allowed to do settings */ | ||
947 | if ((VPIF_CHANNEL2_VIDEO == ch->channel_id) | ||
948 | || (VPIF_CHANNEL3_VIDEO == ch->channel_id)) { | ||
949 | if (!fh->initialized) { | ||
950 | vpif_err("Channel Busy\n"); | ||
951 | return -EBUSY; | ||
952 | } | ||
953 | } | ||
954 | |||
955 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT != reqbuf->type) | ||
956 | return -EINVAL; | ||
957 | |||
958 | index = VPIF_VIDEO_INDEX; | ||
959 | |||
960 | common = &ch->common[index]; | ||
961 | |||
962 | if (common->fmt.type != reqbuf->type || !vpif_dev) | ||
963 | return -EINVAL; | ||
964 | if (0 != common->io_usrs) | ||
965 | return -EBUSY; | ||
966 | |||
967 | if (reqbuf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { | ||
968 | if (common->fmt.fmt.pix.field == V4L2_FIELD_ANY) | ||
969 | field = V4L2_FIELD_INTERLACED; | ||
970 | else | ||
971 | field = common->fmt.fmt.pix.field; | ||
972 | } else { | ||
973 | field = V4L2_VBI_INTERLACED; | ||
974 | } | ||
975 | /* Initialize videobuf2 queue as per the buffer type */ | ||
976 | common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev); | ||
977 | if (!common->alloc_ctx) { | ||
978 | vpif_err("Failed to get the context\n"); | ||
979 | return -EINVAL; | ||
980 | } | ||
981 | q = &common->buffer_queue; | ||
982 | q->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; | ||
983 | q->io_modes = VB2_MMAP | VB2_USERPTR; | ||
984 | q->drv_priv = fh; | ||
985 | q->ops = &video_qops; | ||
986 | q->mem_ops = &vb2_dma_contig_memops; | ||
987 | q->buf_struct_size = sizeof(struct vpif_disp_buffer); | ||
988 | |||
989 | vb2_queue_init(q); | ||
990 | |||
991 | /* Set io allowed member of file handle to TRUE */ | ||
992 | fh->io_allowed[index] = 1; | ||
993 | /* Increment io usrs member of channel object to 1 */ | ||
994 | common->io_usrs = 1; | ||
995 | /* Store type of memory requested in channel object */ | ||
996 | common->memory = reqbuf->memory; | ||
997 | INIT_LIST_HEAD(&common->dma_queue); | ||
998 | /* Allocate buffers */ | ||
999 | return vb2_reqbufs(&common->buffer_queue, reqbuf); | ||
1000 | } | ||
1001 | |||
1002 | static int vpif_querybuf(struct file *file, void *priv, | ||
1003 | struct v4l2_buffer *tbuf) | ||
1004 | { | ||
1005 | struct vpif_fh *fh = priv; | ||
1006 | struct channel_obj *ch = fh->channel; | ||
1007 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1008 | |||
1009 | if (common->fmt.type != tbuf->type) | ||
1010 | return -EINVAL; | ||
1011 | |||
1012 | return vb2_querybuf(&common->buffer_queue, tbuf); | ||
1013 | } | ||
1014 | |||
1015 | static int vpif_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) | ||
1016 | { | ||
1017 | struct vpif_fh *fh = NULL; | ||
1018 | struct channel_obj *ch = NULL; | ||
1019 | struct common_obj *common = NULL; | ||
1020 | |||
1021 | if (!buf || !priv) | ||
1022 | return -EINVAL; | ||
1023 | |||
1024 | fh = priv; | ||
1025 | ch = fh->channel; | ||
1026 | if (!ch) | ||
1027 | return -EINVAL; | ||
1028 | |||
1029 | common = &(ch->common[VPIF_VIDEO_INDEX]); | ||
1030 | if (common->fmt.type != buf->type) | ||
1031 | return -EINVAL; | ||
1032 | |||
1033 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { | ||
1034 | vpif_err("fh->io_allowed\n"); | ||
1035 | return -EACCES; | ||
1036 | } | ||
1037 | |||
1038 | return vb2_qbuf(&common->buffer_queue, buf); | ||
1039 | } | ||
1040 | |||
1041 | static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id) | ||
1042 | { | ||
1043 | struct vpif_fh *fh = priv; | ||
1044 | struct channel_obj *ch = fh->channel; | ||
1045 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1046 | int ret = 0; | ||
1047 | |||
1048 | if (!(*std_id & VPIF_V4L2_STD)) | ||
1049 | return -EINVAL; | ||
1050 | |||
1051 | if (common->started) { | ||
1052 | vpif_err("streaming in progress\n"); | ||
1053 | return -EBUSY; | ||
1054 | } | ||
1055 | |||
1056 | /* Call encoder subdevice function to set the standard */ | ||
1057 | ch->video.stdid = *std_id; | ||
1058 | ch->video.dv_preset = V4L2_DV_INVALID; | ||
1059 | memset(&ch->video.bt_timings, 0, sizeof(ch->video.bt_timings)); | ||
1060 | |||
1061 | /* Get the information about the standard */ | ||
1062 | if (vpif_update_resolution(ch)) | ||
1063 | return -EINVAL; | ||
1064 | |||
1065 | if ((ch->vpifparams.std_info.width * | ||
1066 | ch->vpifparams.std_info.height * 2) > | ||
1067 | config_params.channel_bufsize[ch->channel_id]) { | ||
1068 | vpif_err("invalid std for this size\n"); | ||
1069 | return -EINVAL; | ||
1070 | } | ||
1071 | |||
1072 | common->fmt.fmt.pix.bytesperline = common->fmt.fmt.pix.width; | ||
1073 | /* Configure the default format information */ | ||
1074 | vpif_config_format(ch); | ||
1075 | |||
1076 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video, | ||
1077 | s_std_output, *std_id); | ||
1078 | if (ret < 0) { | ||
1079 | vpif_err("Failed to set output standard\n"); | ||
1080 | return ret; | ||
1081 | } | ||
1082 | |||
1083 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, core, | ||
1084 | s_std, *std_id); | ||
1085 | if (ret < 0) | ||
1086 | vpif_err("Failed to set standard for sub devices\n"); | ||
1087 | return ret; | ||
1088 | } | ||
1089 | |||
1090 | static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std) | ||
1091 | { | ||
1092 | struct vpif_fh *fh = priv; | ||
1093 | struct channel_obj *ch = fh->channel; | ||
1094 | |||
1095 | *std = ch->video.stdid; | ||
1096 | return 0; | ||
1097 | } | ||
1098 | |||
1099 | static int vpif_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) | ||
1100 | { | ||
1101 | struct vpif_fh *fh = priv; | ||
1102 | struct channel_obj *ch = fh->channel; | ||
1103 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1104 | |||
1105 | return vb2_dqbuf(&common->buffer_queue, p, | ||
1106 | (file->f_flags & O_NONBLOCK)); | ||
1107 | } | ||
1108 | |||
1109 | static int vpif_streamon(struct file *file, void *priv, | ||
1110 | enum v4l2_buf_type buftype) | ||
1111 | { | ||
1112 | struct vpif_fh *fh = priv; | ||
1113 | struct channel_obj *ch = fh->channel; | ||
1114 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1115 | struct channel_obj *oth_ch = vpif_obj.dev[!ch->channel_id]; | ||
1116 | int ret = 0; | ||
1117 | |||
1118 | if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) { | ||
1119 | vpif_err("buffer type not supported\n"); | ||
1120 | return -EINVAL; | ||
1121 | } | ||
1122 | |||
1123 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { | ||
1124 | vpif_err("fh->io_allowed\n"); | ||
1125 | return -EACCES; | ||
1126 | } | ||
1127 | |||
1128 | /* If Streaming is already started, return error */ | ||
1129 | if (common->started) { | ||
1130 | vpif_err("channel->started\n"); | ||
1131 | return -EBUSY; | ||
1132 | } | ||
1133 | |||
1134 | if ((ch->channel_id == VPIF_CHANNEL2_VIDEO | ||
1135 | && oth_ch->common[VPIF_VIDEO_INDEX].started && | ||
1136 | ch->vpifparams.std_info.ycmux_mode == 0) | ||
1137 | || ((ch->channel_id == VPIF_CHANNEL3_VIDEO) | ||
1138 | && (2 == oth_ch->common[VPIF_VIDEO_INDEX].started))) { | ||
1139 | vpif_err("other channel is using\n"); | ||
1140 | return -EBUSY; | ||
1141 | } | ||
1142 | |||
1143 | ret = vpif_check_format(ch, &common->fmt.fmt.pix); | ||
1144 | if (ret < 0) | ||
1145 | return ret; | ||
1146 | |||
1147 | /* Call vb2_streamon to start streaming in videobuf2 */ | ||
1148 | ret = vb2_streamon(&common->buffer_queue, buftype); | ||
1149 | if (ret < 0) { | ||
1150 | vpif_err("vb2_streamon\n"); | ||
1151 | return ret; | ||
1152 | } | ||
1153 | |||
1154 | return ret; | ||
1155 | } | ||
1156 | |||
1157 | static int vpif_streamoff(struct file *file, void *priv, | ||
1158 | enum v4l2_buf_type buftype) | ||
1159 | { | ||
1160 | struct vpif_fh *fh = priv; | ||
1161 | struct channel_obj *ch = fh->channel; | ||
1162 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1163 | struct vpif_display_config *vpif_config_data = | ||
1164 | vpif_dev->platform_data; | ||
1165 | |||
1166 | if (buftype != V4L2_BUF_TYPE_VIDEO_OUTPUT) { | ||
1167 | vpif_err("buffer type not supported\n"); | ||
1168 | return -EINVAL; | ||
1169 | } | ||
1170 | |||
1171 | if (!fh->io_allowed[VPIF_VIDEO_INDEX]) { | ||
1172 | vpif_err("fh->io_allowed\n"); | ||
1173 | return -EACCES; | ||
1174 | } | ||
1175 | |||
1176 | if (!common->started) { | ||
1177 | vpif_err("channel->started\n"); | ||
1178 | return -EINVAL; | ||
1179 | } | ||
1180 | |||
1181 | if (buftype == V4L2_BUF_TYPE_VIDEO_OUTPUT) { | ||
1182 | /* disable channel */ | ||
1183 | if (VPIF_CHANNEL2_VIDEO == ch->channel_id) { | ||
1184 | if (vpif_config_data->ch2_clip_en) | ||
1185 | channel2_clipping_enable(0); | ||
1186 | enable_channel2(0); | ||
1187 | channel2_intr_enable(0); | ||
1188 | } | ||
1189 | if ((VPIF_CHANNEL3_VIDEO == ch->channel_id) || | ||
1190 | (2 == common->started)) { | ||
1191 | if (vpif_config_data->ch3_clip_en) | ||
1192 | channel3_clipping_enable(0); | ||
1193 | enable_channel3(0); | ||
1194 | channel3_intr_enable(0); | ||
1195 | } | ||
1196 | } | ||
1197 | |||
1198 | common->started = 0; | ||
1199 | return vb2_streamoff(&common->buffer_queue, buftype); | ||
1200 | } | ||
1201 | |||
1202 | static int vpif_cropcap(struct file *file, void *priv, | ||
1203 | struct v4l2_cropcap *crop) | ||
1204 | { | ||
1205 | struct vpif_fh *fh = priv; | ||
1206 | struct channel_obj *ch = fh->channel; | ||
1207 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1208 | if (V4L2_BUF_TYPE_VIDEO_OUTPUT != crop->type) | ||
1209 | return -EINVAL; | ||
1210 | |||
1211 | crop->bounds.left = crop->bounds.top = 0; | ||
1212 | crop->defrect.left = crop->defrect.top = 0; | ||
1213 | crop->defrect.height = crop->bounds.height = common->height; | ||
1214 | crop->defrect.width = crop->bounds.width = common->width; | ||
1215 | |||
1216 | return 0; | ||
1217 | } | ||
1218 | |||
1219 | static int vpif_enum_output(struct file *file, void *fh, | ||
1220 | struct v4l2_output *output) | ||
1221 | { | ||
1222 | |||
1223 | struct vpif_display_config *config = vpif_dev->platform_data; | ||
1224 | |||
1225 | if (output->index >= config->output_count) { | ||
1226 | vpif_dbg(1, debug, "Invalid output index\n"); | ||
1227 | return -EINVAL; | ||
1228 | } | ||
1229 | |||
1230 | strcpy(output->name, config->output[output->index]); | ||
1231 | output->type = V4L2_OUTPUT_TYPE_ANALOG; | ||
1232 | output->std = VPIF_V4L2_STD; | ||
1233 | |||
1234 | return 0; | ||
1235 | } | ||
1236 | |||
1237 | static int vpif_s_output(struct file *file, void *priv, unsigned int i) | ||
1238 | { | ||
1239 | struct vpif_fh *fh = priv; | ||
1240 | struct channel_obj *ch = fh->channel; | ||
1241 | struct video_obj *vid_ch = &ch->video; | ||
1242 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1243 | int ret = 0; | ||
1244 | |||
1245 | if (common->started) { | ||
1246 | vpif_err("Streaming in progress\n"); | ||
1247 | return -EBUSY; | ||
1248 | } | ||
1249 | |||
1250 | ret = v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 1, video, | ||
1251 | s_routing, 0, i, 0); | ||
1252 | |||
1253 | if (ret < 0) | ||
1254 | vpif_err("Failed to set output standard\n"); | ||
1255 | |||
1256 | vid_ch->output_id = i; | ||
1257 | return ret; | ||
1258 | } | ||
1259 | |||
1260 | static int vpif_g_output(struct file *file, void *priv, unsigned int *i) | ||
1261 | { | ||
1262 | struct vpif_fh *fh = priv; | ||
1263 | struct channel_obj *ch = fh->channel; | ||
1264 | struct video_obj *vid_ch = &ch->video; | ||
1265 | |||
1266 | *i = vid_ch->output_id; | ||
1267 | |||
1268 | return 0; | ||
1269 | } | ||
1270 | |||
1271 | static int vpif_g_priority(struct file *file, void *priv, enum v4l2_priority *p) | ||
1272 | { | ||
1273 | struct vpif_fh *fh = priv; | ||
1274 | struct channel_obj *ch = fh->channel; | ||
1275 | |||
1276 | *p = v4l2_prio_max(&ch->prio); | ||
1277 | |||
1278 | return 0; | ||
1279 | } | ||
1280 | |||
1281 | static int vpif_s_priority(struct file *file, void *priv, enum v4l2_priority p) | ||
1282 | { | ||
1283 | struct vpif_fh *fh = priv; | ||
1284 | struct channel_obj *ch = fh->channel; | ||
1285 | |||
1286 | return v4l2_prio_change(&ch->prio, &fh->prio, p); | ||
1287 | } | ||
1288 | |||
1289 | /** | ||
1290 | * vpif_enum_dv_presets() - ENUM_DV_PRESETS handler | ||
1291 | * @file: file ptr | ||
1292 | * @priv: file handle | ||
1293 | * @preset: input preset | ||
1294 | */ | ||
1295 | static int vpif_enum_dv_presets(struct file *file, void *priv, | ||
1296 | struct v4l2_dv_enum_preset *preset) | ||
1297 | { | ||
1298 | struct vpif_fh *fh = priv; | ||
1299 | struct channel_obj *ch = fh->channel; | ||
1300 | struct video_obj *vid_ch = &ch->video; | ||
1301 | |||
1302 | return v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], | ||
1303 | video, enum_dv_presets, preset); | ||
1304 | } | ||
1305 | |||
1306 | /** | ||
1307 | * vpif_s_dv_presets() - S_DV_PRESETS handler | ||
1308 | * @file: file ptr | ||
1309 | * @priv: file handle | ||
1310 | * @preset: input preset | ||
1311 | */ | ||
1312 | static int vpif_s_dv_preset(struct file *file, void *priv, | ||
1313 | struct v4l2_dv_preset *preset) | ||
1314 | { | ||
1315 | struct vpif_fh *fh = priv; | ||
1316 | struct channel_obj *ch = fh->channel; | ||
1317 | struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1318 | struct video_obj *vid_ch = &ch->video; | ||
1319 | int ret = 0; | ||
1320 | |||
1321 | if (common->started) { | ||
1322 | vpif_dbg(1, debug, "streaming in progress\n"); | ||
1323 | return -EBUSY; | ||
1324 | } | ||
1325 | |||
1326 | ret = v4l2_prio_check(&ch->prio, fh->prio); | ||
1327 | if (ret != 0) | ||
1328 | return ret; | ||
1329 | |||
1330 | fh->initialized = 1; | ||
1331 | |||
1332 | /* Call encoder subdevice function to set the standard */ | ||
1333 | if (mutex_lock_interruptible(&common->lock)) | ||
1334 | return -ERESTARTSYS; | ||
1335 | |||
1336 | ch->video.dv_preset = preset->preset; | ||
1337 | ch->video.stdid = V4L2_STD_UNKNOWN; | ||
1338 | memset(&ch->video.bt_timings, 0, sizeof(ch->video.bt_timings)); | ||
1339 | |||
1340 | /* Get the information about the standard */ | ||
1341 | if (vpif_update_resolution(ch)) { | ||
1342 | ret = -EINVAL; | ||
1343 | } else { | ||
1344 | /* Configure the default format information */ | ||
1345 | vpif_config_format(ch); | ||
1346 | |||
1347 | ret = v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], | ||
1348 | video, s_dv_preset, preset); | ||
1349 | } | ||
1350 | |||
1351 | mutex_unlock(&common->lock); | ||
1352 | |||
1353 | return ret; | ||
1354 | } | ||
1355 | /** | ||
1356 | * vpif_g_dv_presets() - G_DV_PRESETS handler | ||
1357 | * @file: file ptr | ||
1358 | * @priv: file handle | ||
1359 | * @preset: input preset | ||
1360 | */ | ||
1361 | static int vpif_g_dv_preset(struct file *file, void *priv, | ||
1362 | struct v4l2_dv_preset *preset) | ||
1363 | { | ||
1364 | struct vpif_fh *fh = priv; | ||
1365 | struct channel_obj *ch = fh->channel; | ||
1366 | |||
1367 | preset->preset = ch->video.dv_preset; | ||
1368 | |||
1369 | return 0; | ||
1370 | } | ||
1371 | /** | ||
1372 | * vpif_s_dv_timings() - S_DV_TIMINGS handler | ||
1373 | * @file: file ptr | ||
1374 | * @priv: file handle | ||
1375 | * @timings: digital video timings | ||
1376 | */ | ||
1377 | static int vpif_s_dv_timings(struct file *file, void *priv, | ||
1378 | struct v4l2_dv_timings *timings) | ||
1379 | { | ||
1380 | struct vpif_fh *fh = priv; | ||
1381 | struct channel_obj *ch = fh->channel; | ||
1382 | struct vpif_params *vpifparams = &ch->vpifparams; | ||
1383 | struct vpif_channel_config_params *std_info = &vpifparams->std_info; | ||
1384 | struct video_obj *vid_ch = &ch->video; | ||
1385 | struct v4l2_bt_timings *bt = &vid_ch->bt_timings; | ||
1386 | int ret; | ||
1387 | |||
1388 | if (timings->type != V4L2_DV_BT_656_1120) { | ||
1389 | vpif_dbg(2, debug, "Timing type not defined\n"); | ||
1390 | return -EINVAL; | ||
1391 | } | ||
1392 | |||
1393 | /* Configure subdevice timings, if any */ | ||
1394 | ret = v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], | ||
1395 | video, s_dv_timings, timings); | ||
1396 | if (ret == -ENOIOCTLCMD) { | ||
1397 | vpif_dbg(2, debug, "Custom DV timings not supported by " | ||
1398 | "subdevice\n"); | ||
1399 | return -EINVAL; | ||
1400 | } | ||
1401 | if (ret < 0) { | ||
1402 | vpif_dbg(2, debug, "Error setting custom DV timings\n"); | ||
1403 | return ret; | ||
1404 | } | ||
1405 | |||
1406 | if (!(timings->bt.width && timings->bt.height && | ||
1407 | (timings->bt.hbackporch || | ||
1408 | timings->bt.hfrontporch || | ||
1409 | timings->bt.hsync) && | ||
1410 | timings->bt.vfrontporch && | ||
1411 | (timings->bt.vbackporch || | ||
1412 | timings->bt.vsync))) { | ||
1413 | vpif_dbg(2, debug, "Timings for width, height, " | ||
1414 | "horizontal back porch, horizontal sync, " | ||
1415 | "horizontal front porch, vertical back porch, " | ||
1416 | "vertical sync and vertical back porch " | ||
1417 | "must be defined\n"); | ||
1418 | return -EINVAL; | ||
1419 | } | ||
1420 | |||
1421 | *bt = timings->bt; | ||
1422 | |||
1423 | /* Configure video port timings */ | ||
1424 | |||
1425 | std_info->eav2sav = bt->hbackporch + bt->hfrontporch + | ||
1426 | bt->hsync - 8; | ||
1427 | std_info->sav2eav = bt->width; | ||
1428 | |||
1429 | std_info->l1 = 1; | ||
1430 | std_info->l3 = bt->vsync + bt->vbackporch + 1; | ||
1431 | |||
1432 | if (bt->interlaced) { | ||
1433 | if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) { | ||
1434 | std_info->vsize = bt->height * 2 + | ||
1435 | bt->vfrontporch + bt->vsync + bt->vbackporch + | ||
1436 | bt->il_vfrontporch + bt->il_vsync + | ||
1437 | bt->il_vbackporch; | ||
1438 | std_info->l5 = std_info->vsize/2 - | ||
1439 | (bt->vfrontporch - 1); | ||
1440 | std_info->l7 = std_info->vsize/2 + 1; | ||
1441 | std_info->l9 = std_info->l7 + bt->il_vsync + | ||
1442 | bt->il_vbackporch + 1; | ||
1443 | std_info->l11 = std_info->vsize - | ||
1444 | (bt->il_vfrontporch - 1); | ||
1445 | } else { | ||
1446 | vpif_dbg(2, debug, "Required timing values for " | ||
1447 | "interlaced BT format missing\n"); | ||
1448 | return -EINVAL; | ||
1449 | } | ||
1450 | } else { | ||
1451 | std_info->vsize = bt->height + bt->vfrontporch + | ||
1452 | bt->vsync + bt->vbackporch; | ||
1453 | std_info->l5 = std_info->vsize - (bt->vfrontporch - 1); | ||
1454 | } | ||
1455 | strncpy(std_info->name, "Custom timings BT656/1120", | ||
1456 | VPIF_MAX_NAME); | ||
1457 | std_info->width = bt->width; | ||
1458 | std_info->height = bt->height; | ||
1459 | std_info->frm_fmt = bt->interlaced ? 0 : 1; | ||
1460 | std_info->ycmux_mode = 0; | ||
1461 | std_info->capture_format = 0; | ||
1462 | std_info->vbi_supported = 0; | ||
1463 | std_info->hd_sd = 1; | ||
1464 | std_info->stdid = 0; | ||
1465 | std_info->dv_preset = V4L2_DV_INVALID; | ||
1466 | |||
1467 | vid_ch->stdid = 0; | ||
1468 | vid_ch->dv_preset = V4L2_DV_INVALID; | ||
1469 | |||
1470 | return 0; | ||
1471 | } | ||
1472 | |||
1473 | /** | ||
1474 | * vpif_g_dv_timings() - G_DV_TIMINGS handler | ||
1475 | * @file: file ptr | ||
1476 | * @priv: file handle | ||
1477 | * @timings: digital video timings | ||
1478 | */ | ||
1479 | static int vpif_g_dv_timings(struct file *file, void *priv, | ||
1480 | struct v4l2_dv_timings *timings) | ||
1481 | { | ||
1482 | struct vpif_fh *fh = priv; | ||
1483 | struct channel_obj *ch = fh->channel; | ||
1484 | struct video_obj *vid_ch = &ch->video; | ||
1485 | struct v4l2_bt_timings *bt = &vid_ch->bt_timings; | ||
1486 | |||
1487 | timings->bt = *bt; | ||
1488 | |||
1489 | return 0; | ||
1490 | } | ||
1491 | |||
1492 | /* | ||
1493 | * vpif_g_chip_ident() - Identify the chip | ||
1494 | * @file: file ptr | ||
1495 | * @priv: file handle | ||
1496 | * @chip: chip identity | ||
1497 | * | ||
1498 | * Returns zero or -EINVAL if read operations fails. | ||
1499 | */ | ||
1500 | static int vpif_g_chip_ident(struct file *file, void *priv, | ||
1501 | struct v4l2_dbg_chip_ident *chip) | ||
1502 | { | ||
1503 | chip->ident = V4L2_IDENT_NONE; | ||
1504 | chip->revision = 0; | ||
1505 | if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER && | ||
1506 | chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR) { | ||
1507 | vpif_dbg(2, debug, "match_type is invalid.\n"); | ||
1508 | return -EINVAL; | ||
1509 | } | ||
1510 | |||
1511 | return v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 0, core, | ||
1512 | g_chip_ident, chip); | ||
1513 | } | ||
1514 | |||
1515 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
1516 | /* | ||
1517 | * vpif_dbg_g_register() - Read register | ||
1518 | * @file: file ptr | ||
1519 | * @priv: file handle | ||
1520 | * @reg: register to be read | ||
1521 | * | ||
1522 | * Debugging only | ||
1523 | * Returns zero or -EINVAL if read operations fails. | ||
1524 | */ | ||
1525 | static int vpif_dbg_g_register(struct file *file, void *priv, | ||
1526 | struct v4l2_dbg_register *reg){ | ||
1527 | struct vpif_fh *fh = priv; | ||
1528 | struct channel_obj *ch = fh->channel; | ||
1529 | struct video_obj *vid_ch = &ch->video; | ||
1530 | |||
1531 | return v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], core, | ||
1532 | g_register, reg); | ||
1533 | } | ||
1534 | |||
1535 | /* | ||
1536 | * vpif_dbg_s_register() - Write to register | ||
1537 | * @file: file ptr | ||
1538 | * @priv: file handle | ||
1539 | * @reg: register to be modified | ||
1540 | * | ||
1541 | * Debugging only | ||
1542 | * Returns zero or -EINVAL if write operations fails. | ||
1543 | */ | ||
1544 | static int vpif_dbg_s_register(struct file *file, void *priv, | ||
1545 | struct v4l2_dbg_register *reg){ | ||
1546 | struct vpif_fh *fh = priv; | ||
1547 | struct channel_obj *ch = fh->channel; | ||
1548 | struct video_obj *vid_ch = &ch->video; | ||
1549 | |||
1550 | return v4l2_subdev_call(vpif_obj.sd[vid_ch->output_id], core, | ||
1551 | s_register, reg); | ||
1552 | } | ||
1553 | #endif | ||
1554 | |||
1555 | /* | ||
1556 | * vpif_log_status() - Status information | ||
1557 | * @file: file ptr | ||
1558 | * @priv: file handle | ||
1559 | * | ||
1560 | * Returns zero. | ||
1561 | */ | ||
1562 | static int vpif_log_status(struct file *filep, void *priv) | ||
1563 | { | ||
1564 | /* status for sub devices */ | ||
1565 | v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status); | ||
1566 | |||
1567 | return 0; | ||
1568 | } | ||
1569 | |||
1570 | /* vpif display ioctl operations */ | ||
1571 | static const struct v4l2_ioctl_ops vpif_ioctl_ops = { | ||
1572 | .vidioc_querycap = vpif_querycap, | ||
1573 | .vidioc_g_priority = vpif_g_priority, | ||
1574 | .vidioc_s_priority = vpif_s_priority, | ||
1575 | .vidioc_enum_fmt_vid_out = vpif_enum_fmt_vid_out, | ||
1576 | .vidioc_g_fmt_vid_out = vpif_g_fmt_vid_out, | ||
1577 | .vidioc_s_fmt_vid_out = vpif_s_fmt_vid_out, | ||
1578 | .vidioc_try_fmt_vid_out = vpif_try_fmt_vid_out, | ||
1579 | .vidioc_reqbufs = vpif_reqbufs, | ||
1580 | .vidioc_querybuf = vpif_querybuf, | ||
1581 | .vidioc_qbuf = vpif_qbuf, | ||
1582 | .vidioc_dqbuf = vpif_dqbuf, | ||
1583 | .vidioc_streamon = vpif_streamon, | ||
1584 | .vidioc_streamoff = vpif_streamoff, | ||
1585 | .vidioc_s_std = vpif_s_std, | ||
1586 | .vidioc_g_std = vpif_g_std, | ||
1587 | .vidioc_enum_output = vpif_enum_output, | ||
1588 | .vidioc_s_output = vpif_s_output, | ||
1589 | .vidioc_g_output = vpif_g_output, | ||
1590 | .vidioc_cropcap = vpif_cropcap, | ||
1591 | .vidioc_enum_dv_presets = vpif_enum_dv_presets, | ||
1592 | .vidioc_s_dv_preset = vpif_s_dv_preset, | ||
1593 | .vidioc_g_dv_preset = vpif_g_dv_preset, | ||
1594 | .vidioc_s_dv_timings = vpif_s_dv_timings, | ||
1595 | .vidioc_g_dv_timings = vpif_g_dv_timings, | ||
1596 | .vidioc_g_chip_ident = vpif_g_chip_ident, | ||
1597 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
1598 | .vidioc_g_register = vpif_dbg_g_register, | ||
1599 | .vidioc_s_register = vpif_dbg_s_register, | ||
1600 | #endif | ||
1601 | .vidioc_log_status = vpif_log_status, | ||
1602 | }; | ||
1603 | |||
1604 | static const struct v4l2_file_operations vpif_fops = { | ||
1605 | .owner = THIS_MODULE, | ||
1606 | .open = vpif_open, | ||
1607 | .release = vpif_release, | ||
1608 | .unlocked_ioctl = video_ioctl2, | ||
1609 | .mmap = vpif_mmap, | ||
1610 | .poll = vpif_poll | ||
1611 | }; | ||
1612 | |||
1613 | static struct video_device vpif_video_template = { | ||
1614 | .name = "vpif", | ||
1615 | .fops = &vpif_fops, | ||
1616 | .ioctl_ops = &vpif_ioctl_ops, | ||
1617 | .tvnorms = VPIF_V4L2_STD, | ||
1618 | .current_norm = V4L2_STD_625_50, | ||
1619 | |||
1620 | }; | ||
1621 | |||
1622 | /*Configure the channels, buffer sizei, request irq */ | ||
1623 | static int initialize_vpif(void) | ||
1624 | { | ||
1625 | int free_channel_objects_index; | ||
1626 | int free_buffer_channel_index; | ||
1627 | int free_buffer_index; | ||
1628 | int err = 0, i, j; | ||
1629 | |||
1630 | /* Default number of buffers should be 3 */ | ||
1631 | if ((ch2_numbuffers > 0) && | ||
1632 | (ch2_numbuffers < config_params.min_numbuffers)) | ||
1633 | ch2_numbuffers = config_params.min_numbuffers; | ||
1634 | if ((ch3_numbuffers > 0) && | ||
1635 | (ch3_numbuffers < config_params.min_numbuffers)) | ||
1636 | ch3_numbuffers = config_params.min_numbuffers; | ||
1637 | |||
1638 | /* Set buffer size to min buffers size if invalid buffer size is | ||
1639 | * given */ | ||
1640 | if (ch2_bufsize < config_params.min_bufsize[VPIF_CHANNEL2_VIDEO]) | ||
1641 | ch2_bufsize = | ||
1642 | config_params.min_bufsize[VPIF_CHANNEL2_VIDEO]; | ||
1643 | if (ch3_bufsize < config_params.min_bufsize[VPIF_CHANNEL3_VIDEO]) | ||
1644 | ch3_bufsize = | ||
1645 | config_params.min_bufsize[VPIF_CHANNEL3_VIDEO]; | ||
1646 | |||
1647 | config_params.numbuffers[VPIF_CHANNEL2_VIDEO] = ch2_numbuffers; | ||
1648 | |||
1649 | if (ch2_numbuffers) { | ||
1650 | config_params.channel_bufsize[VPIF_CHANNEL2_VIDEO] = | ||
1651 | ch2_bufsize; | ||
1652 | } | ||
1653 | config_params.numbuffers[VPIF_CHANNEL3_VIDEO] = ch3_numbuffers; | ||
1654 | |||
1655 | if (ch3_numbuffers) { | ||
1656 | config_params.channel_bufsize[VPIF_CHANNEL3_VIDEO] = | ||
1657 | ch3_bufsize; | ||
1658 | } | ||
1659 | |||
1660 | /* Allocate memory for six channel objects */ | ||
1661 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { | ||
1662 | vpif_obj.dev[i] = | ||
1663 | kzalloc(sizeof(struct channel_obj), GFP_KERNEL); | ||
1664 | /* If memory allocation fails, return error */ | ||
1665 | if (!vpif_obj.dev[i]) { | ||
1666 | free_channel_objects_index = i; | ||
1667 | err = -ENOMEM; | ||
1668 | goto vpif_init_free_channel_objects; | ||
1669 | } | ||
1670 | } | ||
1671 | |||
1672 | free_channel_objects_index = VPIF_DISPLAY_MAX_DEVICES; | ||
1673 | free_buffer_channel_index = VPIF_DISPLAY_NUM_CHANNELS; | ||
1674 | free_buffer_index = config_params.numbuffers[i - 1]; | ||
1675 | |||
1676 | return 0; | ||
1677 | |||
1678 | vpif_init_free_channel_objects: | ||
1679 | for (j = 0; j < free_channel_objects_index; j++) | ||
1680 | kfree(vpif_obj.dev[j]); | ||
1681 | return err; | ||
1682 | } | ||
1683 | |||
1684 | /* | ||
1685 | * vpif_probe: This function creates device entries by register itself to the | ||
1686 | * V4L2 driver and initializes fields of each channel objects | ||
1687 | */ | ||
1688 | static __init int vpif_probe(struct platform_device *pdev) | ||
1689 | { | ||
1690 | struct vpif_subdev_info *subdevdata; | ||
1691 | struct vpif_display_config *config; | ||
1692 | int i, j = 0, k, q, m, err = 0; | ||
1693 | struct i2c_adapter *i2c_adap; | ||
1694 | struct common_obj *common; | ||
1695 | struct channel_obj *ch; | ||
1696 | struct video_device *vfd; | ||
1697 | struct resource *res; | ||
1698 | int subdev_count; | ||
1699 | size_t size; | ||
1700 | |||
1701 | vpif_dev = &pdev->dev; | ||
1702 | err = initialize_vpif(); | ||
1703 | |||
1704 | if (err) { | ||
1705 | v4l2_err(vpif_dev->driver, "Error initializing vpif\n"); | ||
1706 | return err; | ||
1707 | } | ||
1708 | |||
1709 | err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev); | ||
1710 | if (err) { | ||
1711 | v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n"); | ||
1712 | return err; | ||
1713 | } | ||
1714 | |||
1715 | k = 0; | ||
1716 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, k))) { | ||
1717 | for (i = res->start; i <= res->end; i++) { | ||
1718 | if (request_irq(i, vpif_channel_isr, IRQF_SHARED, | ||
1719 | "VPIF_Display", | ||
1720 | (void *)(&vpif_obj.dev[k]->channel_id))) { | ||
1721 | err = -EBUSY; | ||
1722 | goto vpif_int_err; | ||
1723 | } | ||
1724 | } | ||
1725 | k++; | ||
1726 | } | ||
1727 | |||
1728 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { | ||
1729 | |||
1730 | /* Get the pointer to the channel object */ | ||
1731 | ch = vpif_obj.dev[i]; | ||
1732 | |||
1733 | /* Allocate memory for video device */ | ||
1734 | vfd = video_device_alloc(); | ||
1735 | if (vfd == NULL) { | ||
1736 | for (j = 0; j < i; j++) { | ||
1737 | ch = vpif_obj.dev[j]; | ||
1738 | video_device_release(ch->video_dev); | ||
1739 | } | ||
1740 | err = -ENOMEM; | ||
1741 | goto vpif_int_err; | ||
1742 | } | ||
1743 | |||
1744 | /* Initialize field of video device */ | ||
1745 | *vfd = vpif_video_template; | ||
1746 | vfd->v4l2_dev = &vpif_obj.v4l2_dev; | ||
1747 | vfd->release = video_device_release; | ||
1748 | snprintf(vfd->name, sizeof(vfd->name), | ||
1749 | "VPIF_Display_DRIVER_V%s", | ||
1750 | VPIF_DISPLAY_VERSION); | ||
1751 | |||
1752 | /* Set video_dev to the video device */ | ||
1753 | ch->video_dev = vfd; | ||
1754 | } | ||
1755 | |||
1756 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1757 | if (res) { | ||
1758 | size = resource_size(res); | ||
1759 | /* The resources are divided into two equal memory and when | ||
1760 | * we have HD output we can add them together | ||
1761 | */ | ||
1762 | for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) { | ||
1763 | ch = vpif_obj.dev[j]; | ||
1764 | ch->channel_id = j; | ||
1765 | |||
1766 | /* only enabled if second resource exists */ | ||
1767 | config_params.video_limit[ch->channel_id] = 0; | ||
1768 | if (size) | ||
1769 | config_params.video_limit[ch->channel_id] = | ||
1770 | size/2; | ||
1771 | } | ||
1772 | } | ||
1773 | |||
1774 | for (j = 0; j < VPIF_DISPLAY_MAX_DEVICES; j++) { | ||
1775 | ch = vpif_obj.dev[j]; | ||
1776 | /* Initialize field of the channel objects */ | ||
1777 | atomic_set(&ch->usrs, 0); | ||
1778 | for (k = 0; k < VPIF_NUMOBJECTS; k++) { | ||
1779 | ch->common[k].numbuffers = 0; | ||
1780 | common = &ch->common[k]; | ||
1781 | common->io_usrs = 0; | ||
1782 | common->started = 0; | ||
1783 | spin_lock_init(&common->irqlock); | ||
1784 | mutex_init(&common->lock); | ||
1785 | common->numbuffers = 0; | ||
1786 | common->set_addr = NULL; | ||
1787 | common->ytop_off = common->ybtm_off = 0; | ||
1788 | common->ctop_off = common->cbtm_off = 0; | ||
1789 | common->cur_frm = common->next_frm = NULL; | ||
1790 | memset(&common->fmt, 0, sizeof(common->fmt)); | ||
1791 | common->numbuffers = config_params.numbuffers[k]; | ||
1792 | |||
1793 | } | ||
1794 | ch->initialized = 0; | ||
1795 | ch->channel_id = j; | ||
1796 | if (j < 2) | ||
1797 | ch->common[VPIF_VIDEO_INDEX].numbuffers = | ||
1798 | config_params.numbuffers[ch->channel_id]; | ||
1799 | else | ||
1800 | ch->common[VPIF_VIDEO_INDEX].numbuffers = 0; | ||
1801 | |||
1802 | memset(&ch->vpifparams, 0, sizeof(ch->vpifparams)); | ||
1803 | |||
1804 | /* Initialize prio member of channel object */ | ||
1805 | v4l2_prio_init(&ch->prio); | ||
1806 | ch->common[VPIF_VIDEO_INDEX].fmt.type = | ||
1807 | V4L2_BUF_TYPE_VIDEO_OUTPUT; | ||
1808 | ch->video_dev->lock = &common->lock; | ||
1809 | |||
1810 | /* register video device */ | ||
1811 | vpif_dbg(1, debug, "channel=%x,channel->video_dev=%x\n", | ||
1812 | (int)ch, (int)&ch->video_dev); | ||
1813 | |||
1814 | err = video_register_device(ch->video_dev, | ||
1815 | VFL_TYPE_GRABBER, (j ? 3 : 2)); | ||
1816 | if (err < 0) | ||
1817 | goto probe_out; | ||
1818 | |||
1819 | video_set_drvdata(ch->video_dev, ch); | ||
1820 | } | ||
1821 | |||
1822 | i2c_adap = i2c_get_adapter(1); | ||
1823 | config = pdev->dev.platform_data; | ||
1824 | subdev_count = config->subdev_count; | ||
1825 | subdevdata = config->subdevinfo; | ||
1826 | vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count, | ||
1827 | GFP_KERNEL); | ||
1828 | if (vpif_obj.sd == NULL) { | ||
1829 | vpif_err("unable to allocate memory for subdevice pointers\n"); | ||
1830 | err = -ENOMEM; | ||
1831 | goto probe_out; | ||
1832 | } | ||
1833 | |||
1834 | for (i = 0; i < subdev_count; i++) { | ||
1835 | vpif_obj.sd[i] = v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev, | ||
1836 | i2c_adap, | ||
1837 | &subdevdata[i].board_info, | ||
1838 | NULL); | ||
1839 | if (!vpif_obj.sd[i]) { | ||
1840 | vpif_err("Error registering v4l2 subdevice\n"); | ||
1841 | goto probe_subdev_out; | ||
1842 | } | ||
1843 | |||
1844 | if (vpif_obj.sd[i]) | ||
1845 | vpif_obj.sd[i]->grp_id = 1 << i; | ||
1846 | } | ||
1847 | |||
1848 | v4l2_info(&vpif_obj.v4l2_dev, | ||
1849 | " VPIF display driver initialized\n"); | ||
1850 | return 0; | ||
1851 | |||
1852 | probe_subdev_out: | ||
1853 | kfree(vpif_obj.sd); | ||
1854 | probe_out: | ||
1855 | for (k = 0; k < j; k++) { | ||
1856 | ch = vpif_obj.dev[k]; | ||
1857 | video_unregister_device(ch->video_dev); | ||
1858 | video_device_release(ch->video_dev); | ||
1859 | ch->video_dev = NULL; | ||
1860 | } | ||
1861 | vpif_int_err: | ||
1862 | v4l2_device_unregister(&vpif_obj.v4l2_dev); | ||
1863 | vpif_err("VPIF IRQ request failed\n"); | ||
1864 | for (q = k; k >= 0; k--) { | ||
1865 | for (m = i; m >= res->start; m--) | ||
1866 | free_irq(m, (void *)(&vpif_obj.dev[k]->channel_id)); | ||
1867 | res = platform_get_resource(pdev, IORESOURCE_IRQ, k-1); | ||
1868 | m = res->end; | ||
1869 | } | ||
1870 | |||
1871 | return err; | ||
1872 | } | ||
1873 | |||
1874 | /* | ||
1875 | * vpif_remove: It un-register channels from V4L2 driver | ||
1876 | */ | ||
1877 | static int vpif_remove(struct platform_device *device) | ||
1878 | { | ||
1879 | struct channel_obj *ch; | ||
1880 | int i; | ||
1881 | |||
1882 | v4l2_device_unregister(&vpif_obj.v4l2_dev); | ||
1883 | |||
1884 | /* un-register device */ | ||
1885 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { | ||
1886 | /* Get the pointer to the channel object */ | ||
1887 | ch = vpif_obj.dev[i]; | ||
1888 | /* Unregister video device */ | ||
1889 | video_unregister_device(ch->video_dev); | ||
1890 | |||
1891 | ch->video_dev = NULL; | ||
1892 | } | ||
1893 | |||
1894 | return 0; | ||
1895 | } | ||
1896 | |||
1897 | #ifdef CONFIG_PM | ||
1898 | static int vpif_suspend(struct device *dev) | ||
1899 | { | ||
1900 | struct common_obj *common; | ||
1901 | struct channel_obj *ch; | ||
1902 | int i; | ||
1903 | |||
1904 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { | ||
1905 | /* Get the pointer to the channel object */ | ||
1906 | ch = vpif_obj.dev[i]; | ||
1907 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1908 | mutex_lock(&common->lock); | ||
1909 | if (atomic_read(&ch->usrs) && common->io_usrs) { | ||
1910 | /* Disable channel */ | ||
1911 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { | ||
1912 | enable_channel2(0); | ||
1913 | channel2_intr_enable(0); | ||
1914 | } | ||
1915 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || | ||
1916 | common->started == 2) { | ||
1917 | enable_channel3(0); | ||
1918 | channel3_intr_enable(0); | ||
1919 | } | ||
1920 | } | ||
1921 | mutex_unlock(&common->lock); | ||
1922 | } | ||
1923 | |||
1924 | return 0; | ||
1925 | } | ||
1926 | |||
1927 | static int vpif_resume(struct device *dev) | ||
1928 | { | ||
1929 | |||
1930 | struct common_obj *common; | ||
1931 | struct channel_obj *ch; | ||
1932 | int i; | ||
1933 | |||
1934 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { | ||
1935 | /* Get the pointer to the channel object */ | ||
1936 | ch = vpif_obj.dev[i]; | ||
1937 | common = &ch->common[VPIF_VIDEO_INDEX]; | ||
1938 | mutex_lock(&common->lock); | ||
1939 | if (atomic_read(&ch->usrs) && common->io_usrs) { | ||
1940 | /* Enable channel */ | ||
1941 | if (ch->channel_id == VPIF_CHANNEL2_VIDEO) { | ||
1942 | enable_channel2(1); | ||
1943 | channel2_intr_enable(1); | ||
1944 | } | ||
1945 | if (ch->channel_id == VPIF_CHANNEL3_VIDEO || | ||
1946 | common->started == 2) { | ||
1947 | enable_channel3(1); | ||
1948 | channel3_intr_enable(1); | ||
1949 | } | ||
1950 | } | ||
1951 | mutex_unlock(&common->lock); | ||
1952 | } | ||
1953 | |||
1954 | return 0; | ||
1955 | } | ||
1956 | |||
1957 | static const struct dev_pm_ops vpif_pm = { | ||
1958 | .suspend = vpif_suspend, | ||
1959 | .resume = vpif_resume, | ||
1960 | }; | ||
1961 | |||
1962 | #define vpif_pm_ops (&vpif_pm) | ||
1963 | #else | ||
1964 | #define vpif_pm_ops NULL | ||
1965 | #endif | ||
1966 | |||
1967 | static __refdata struct platform_driver vpif_driver = { | ||
1968 | .driver = { | ||
1969 | .name = "vpif_display", | ||
1970 | .owner = THIS_MODULE, | ||
1971 | .pm = vpif_pm_ops, | ||
1972 | }, | ||
1973 | .probe = vpif_probe, | ||
1974 | .remove = vpif_remove, | ||
1975 | }; | ||
1976 | |||
1977 | static __init int vpif_init(void) | ||
1978 | { | ||
1979 | return platform_driver_register(&vpif_driver); | ||
1980 | } | ||
1981 | |||
1982 | /* | ||
1983 | * vpif_cleanup: This function un-registers device and driver to the kernel, | ||
1984 | * frees requested irq handler and de-allocates memory allocated for channel | ||
1985 | * objects. | ||
1986 | */ | ||
1987 | static void vpif_cleanup(void) | ||
1988 | { | ||
1989 | struct platform_device *pdev; | ||
1990 | struct resource *res; | ||
1991 | int irq_num; | ||
1992 | int i = 0; | ||
1993 | |||
1994 | pdev = container_of(vpif_dev, struct platform_device, dev); | ||
1995 | |||
1996 | while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) { | ||
1997 | for (irq_num = res->start; irq_num <= res->end; irq_num++) | ||
1998 | free_irq(irq_num, | ||
1999 | (void *)(&vpif_obj.dev[i]->channel_id)); | ||
2000 | i++; | ||
2001 | } | ||
2002 | |||
2003 | platform_driver_unregister(&vpif_driver); | ||
2004 | kfree(vpif_obj.sd); | ||
2005 | for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) | ||
2006 | kfree(vpif_obj.dev[i]); | ||
2007 | } | ||
2008 | |||
2009 | module_init(vpif_init); | ||
2010 | module_exit(vpif_cleanup); | ||