1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/module.h>
24#include <linux/interrupt.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27
28#include <media/v4l2-ioctl.h>
29
30#include "vpif.h"
31#include "vpif_capture.h"
32
33MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
34MODULE_LICENSE("GPL");
35MODULE_VERSION(VPIF_CAPTURE_VERSION);
36
37#define vpif_err(fmt, arg...) v4l2_err(&vpif_obj.v4l2_dev, fmt, ## arg)
38#define vpif_dbg(level, debug, fmt, arg...) \
39 v4l2_dbg(level, debug, &vpif_obj.v4l2_dev, fmt, ## arg)
40
41static int debug = 1;
42
43module_param(debug, int, 0644);
44
45MODULE_PARM_DESC(debug, "Debug level 0-1");
46
47#define VPIF_DRIVER_NAME "vpif_capture"
48
49
50static struct vpif_device vpif_obj = { {NULL} };
51static struct device *vpif_dev;
52static void vpif_calculate_offsets(struct channel_obj *ch);
53static void vpif_config_addr(struct channel_obj *ch, int muxmode);
54
55static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
56
57
58static int ycmux_mode;
59
60static inline
61struct vpif_cap_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb)
62{
63 return container_of(vb, struct vpif_cap_buffer, vb);
64}
65
66
67
68
69
70
71
72
73
74static int vpif_buffer_prepare(struct vb2_buffer *vb)
75{
76 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
77 struct vb2_queue *q = vb->vb2_queue;
78 struct channel_obj *ch = vb2_get_drv_priv(q);
79 struct common_obj *common;
80 unsigned long addr;
81
82 vpif_dbg(2, debug, "vpif_buffer_prepare\n");
83
84 common = &ch->common[VPIF_VIDEO_INDEX];
85
86 vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
87 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
88 return -EINVAL;
89
90 vbuf->field = common->fmt.fmt.pix.field;
91
92 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
93 if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
94 !IS_ALIGNED((addr + common->ybtm_off), 8) ||
95 !IS_ALIGNED((addr + common->ctop_off), 8) ||
96 !IS_ALIGNED((addr + common->cbtm_off), 8)) {
97 vpif_dbg(1, debug, "offset is not aligned\n");
98 return -EINVAL;
99 }
100
101 return 0;
102}
103
104
105
106
107
108
109
110
111
112
113
114
115static int vpif_buffer_queue_setup(struct vb2_queue *vq,
116 unsigned int *nbuffers, unsigned int *nplanes,
117 unsigned int sizes[], struct device *alloc_devs[])
118{
119 struct channel_obj *ch = vb2_get_drv_priv(vq);
120 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
121 unsigned size = common->fmt.fmt.pix.sizeimage;
122
123 vpif_dbg(2, debug, "vpif_buffer_setup\n");
124
125 if (*nplanes) {
126 if (sizes[0] < size)
127 return -EINVAL;
128 size = sizes[0];
129 }
130
131 if (vq->num_buffers + *nbuffers < 3)
132 *nbuffers = 3 - vq->num_buffers;
133
134 *nplanes = 1;
135 sizes[0] = size;
136
137
138 vpif_calculate_offsets(ch);
139
140 return 0;
141}
142
143
144
145
146
147static void vpif_buffer_queue(struct vb2_buffer *vb)
148{
149 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
150 struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
151 struct vpif_cap_buffer *buf = to_vpif_buffer(vbuf);
152 struct common_obj *common;
153 unsigned long flags;
154
155 common = &ch->common[VPIF_VIDEO_INDEX];
156
157 vpif_dbg(2, debug, "vpif_buffer_queue\n");
158
159 spin_lock_irqsave(&common->irqlock, flags);
160
161 list_add_tail(&buf->list, &common->dma_queue);
162 spin_unlock_irqrestore(&common->irqlock, flags);
163}
164
165
166
167
168
169
170static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
171{
172 struct vpif_capture_config *vpif_config_data =
173 vpif_dev->platform_data;
174 struct channel_obj *ch = vb2_get_drv_priv(vq);
175 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
176 struct vpif_params *vpif = &ch->vpifparams;
177 struct vpif_cap_buffer *buf, *tmp;
178 unsigned long addr, flags;
179 int ret;
180
181 spin_lock_irqsave(&common->irqlock, flags);
182
183
184 ch->field_id = 0;
185
186
187 if (vpif_config_data->setup_input_channel_mode) {
188 ret = vpif_config_data->
189 setup_input_channel_mode(vpif->std_info.ycmux_mode);
190 if (ret < 0) {
191 vpif_dbg(1, debug, "can't set vpif channel mode\n");
192 goto err;
193 }
194 }
195
196 ret = v4l2_subdev_call(ch->sd, video, s_stream, 1);
197 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
198 vpif_dbg(1, debug, "stream on failed in subdev\n");
199 goto err;
200 }
201
202
203 ret = vpif_set_video_params(vpif, ch->channel_id);
204 if (ret < 0) {
205 vpif_dbg(1, debug, "can't set video params\n");
206 goto err;
207 }
208
209 ycmux_mode = ret;
210 vpif_config_addr(ch, ret);
211
212
213 common->cur_frm = common->next_frm = list_entry(common->dma_queue.next,
214 struct vpif_cap_buffer, list);
215
216 list_del(&common->cur_frm->list);
217 spin_unlock_irqrestore(&common->irqlock, flags);
218
219 addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb.vb2_buf, 0);
220
221 common->set_addr(addr + common->ytop_off,
222 addr + common->ybtm_off,
223 addr + common->ctop_off,
224 addr + common->cbtm_off);
225
226
227
228
229
230 channel_first_int[VPIF_VIDEO_INDEX][ch->channel_id] = 1;
231 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
232 channel0_intr_assert();
233 channel0_intr_enable(1);
234 enable_channel0(1);
235 }
236 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
237 ycmux_mode == 2) {
238 channel1_intr_assert();
239 channel1_intr_enable(1);
240 enable_channel1(1);
241 }
242
243 return 0;
244
245err:
246 list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
247 list_del(&buf->list);
248 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
249 }
250 spin_unlock_irqrestore(&common->irqlock, flags);
251
252 return ret;
253}
254
255
256
257
258
259
260
261
262static void vpif_stop_streaming(struct vb2_queue *vq)
263{
264 struct channel_obj *ch = vb2_get_drv_priv(vq);
265 struct common_obj *common;
266 unsigned long flags;
267 int ret;
268
269 common = &ch->common[VPIF_VIDEO_INDEX];
270
271
272 if (VPIF_CHANNEL0_VIDEO == ch->channel_id) {
273 enable_channel0(0);
274 channel0_intr_enable(0);
275 }
276 if (VPIF_CHANNEL1_VIDEO == ch->channel_id ||
277 ycmux_mode == 2) {
278 enable_channel1(0);
279 channel1_intr_enable(0);
280 }
281
282 ycmux_mode = 0;
283
284 ret = v4l2_subdev_call(ch->sd, video, s_stream, 0);
285 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
286 vpif_dbg(1, debug, "stream off failed in subdev\n");
287
288
289 spin_lock_irqsave(&common->irqlock, flags);
290 if (common->cur_frm == common->next_frm) {
291 vb2_buffer_done(&common->cur_frm->vb.vb2_buf,
292 VB2_BUF_STATE_ERROR);
293 } else {
294 if (common->cur_frm != NULL)
295 vb2_buffer_done(&common->cur_frm->vb.vb2_buf,
296 VB2_BUF_STATE_ERROR);
297 if (common->next_frm != NULL)
298 vb2_buffer_done(&common->next_frm->vb.vb2_buf,
299 VB2_BUF_STATE_ERROR);
300 }
301
302 while (!list_empty(&common->dma_queue)) {
303 common->next_frm = list_entry(common->dma_queue.next,
304 struct vpif_cap_buffer, list);
305 list_del(&common->next_frm->list);
306 vb2_buffer_done(&common->next_frm->vb.vb2_buf,
307 VB2_BUF_STATE_ERROR);
308 }
309 spin_unlock_irqrestore(&common->irqlock, flags);
310}
311
312static struct vb2_ops video_qops = {
313 .queue_setup = vpif_buffer_queue_setup,
314 .buf_prepare = vpif_buffer_prepare,
315 .start_streaming = vpif_start_streaming,
316 .stop_streaming = vpif_stop_streaming,
317 .buf_queue = vpif_buffer_queue,
318 .wait_prepare = vb2_ops_wait_prepare,
319 .wait_finish = vb2_ops_wait_finish,
320};
321
322
323
324
325
326
327
328
329
330static void vpif_process_buffer_complete(struct common_obj *common)
331{
332 common->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns();
333 vb2_buffer_done(&common->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
334
335 common->cur_frm = common->next_frm;
336}
337
338
339
340
341
342
343
344
345
346static void vpif_schedule_next_buffer(struct common_obj *common)
347{
348 unsigned long addr = 0;
349
350 spin_lock(&common->irqlock);
351 common->next_frm = list_entry(common->dma_queue.next,
352 struct vpif_cap_buffer, list);
353
354 list_del(&common->next_frm->list);
355 spin_unlock(&common->irqlock);
356 addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb.vb2_buf, 0);
357
358
359 common->set_addr(addr + common->ytop_off,
360 addr + common->ybtm_off,
361 addr + common->ctop_off,
362 addr + common->cbtm_off);
363}
364
365
366
367
368
369
370
371
372
373static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
374{
375 struct vpif_device *dev = &vpif_obj;
376 struct common_obj *common;
377 struct channel_obj *ch;
378 int channel_id = 0;
379 int fid = -1, i;
380
381 channel_id = *(int *)(dev_id);
382 if (!vpif_intr_status(channel_id))
383 return IRQ_NONE;
384
385 ch = dev->dev[channel_id];
386
387 for (i = 0; i < VPIF_NUMBER_OF_OBJECTS; i++) {
388 common = &ch->common[i];
389
390
391 if (1 == ch->vpifparams.std_info.frm_fmt) {
392
393 spin_lock(&common->irqlock);
394 if (list_empty(&common->dma_queue)) {
395 spin_unlock(&common->irqlock);
396 continue;
397 }
398 spin_unlock(&common->irqlock);
399
400 if (!channel_first_int[i][channel_id])
401 vpif_process_buffer_complete(common);
402
403 channel_first_int[i][channel_id] = 0;
404
405 vpif_schedule_next_buffer(common);
406
407
408 channel_first_int[i][channel_id] = 0;
409 } else {
410
411
412
413
414 if (channel_first_int[i][channel_id]) {
415 channel_first_int[i][channel_id] = 0;
416 continue;
417 }
418 if (0 == i) {
419 ch->field_id ^= 1;
420
421 fid = vpif_channel_getfid(ch->channel_id);
422 if (fid != ch->field_id) {
423
424
425
426
427 if (0 == fid)
428 ch->field_id = fid;
429 return IRQ_HANDLED;
430 }
431 }
432
433 if (0 == fid) {
434
435 if (common->cur_frm == common->next_frm)
436 continue;
437
438
439 vpif_process_buffer_complete(common);
440 } else if (1 == fid) {
441
442 spin_lock(&common->irqlock);
443 if (list_empty(&common->dma_queue) ||
444 (common->cur_frm != common->next_frm)) {
445 spin_unlock(&common->irqlock);
446 continue;
447 }
448 spin_unlock(&common->irqlock);
449
450 vpif_schedule_next_buffer(common);
451 }
452 }
453 }
454 return IRQ_HANDLED;
455}
456
457
458
459
460
461
462
463
464static int vpif_update_std_info(struct channel_obj *ch)
465{
466 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
467 struct vpif_params *vpifparams = &ch->vpifparams;
468 const struct vpif_channel_config_params *config;
469 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
470 struct video_obj *vid_ch = &ch->video;
471 int index;
472
473 vpif_dbg(2, debug, "vpif_update_std_info\n");
474
475 for (index = 0; index < vpif_ch_params_count; index++) {
476 config = &vpif_ch_params[index];
477 if (config->hd_sd == 0) {
478 vpif_dbg(2, debug, "SD format\n");
479 if (config->stdid & vid_ch->stdid) {
480 memcpy(std_info, config, sizeof(*config));
481 break;
482 }
483 } else {
484 vpif_dbg(2, debug, "HD format\n");
485 if (!memcmp(&config->dv_timings, &vid_ch->dv_timings,
486 sizeof(vid_ch->dv_timings))) {
487 memcpy(std_info, config, sizeof(*config));
488 break;
489 }
490 }
491 }
492
493
494 if (index == vpif_ch_params_count)
495 return -EINVAL;
496
497 common->fmt.fmt.pix.width = std_info->width;
498 common->width = std_info->width;
499 common->fmt.fmt.pix.height = std_info->height;
500 common->height = std_info->height;
501 common->fmt.fmt.pix.sizeimage = common->height * common->width * 2;
502 common->fmt.fmt.pix.bytesperline = std_info->width;
503 vpifparams->video_params.hpitch = std_info->width;
504 vpifparams->video_params.storage_mode = std_info->frm_fmt;
505
506 if (vid_ch->stdid)
507 common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
508 else
509 common->fmt.fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
510
511 if (ch->vpifparams.std_info.frm_fmt)
512 common->fmt.fmt.pix.field = V4L2_FIELD_NONE;
513 else
514 common->fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
515
516 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
517 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
518 else
519 common->fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
520
521 common->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
522
523 return 0;
524}
525
526
527
528
529
530
531
532
533static void vpif_calculate_offsets(struct channel_obj *ch)
534{
535 unsigned int hpitch, sizeimage;
536 struct video_obj *vid_ch = &(ch->video);
537 struct vpif_params *vpifparams = &ch->vpifparams;
538 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
539 enum v4l2_field field = common->fmt.fmt.pix.field;
540
541 vpif_dbg(2, debug, "vpif_calculate_offsets\n");
542
543 if (V4L2_FIELD_ANY == field) {
544 if (vpifparams->std_info.frm_fmt)
545 vid_ch->buf_field = V4L2_FIELD_NONE;
546 else
547 vid_ch->buf_field = V4L2_FIELD_INTERLACED;
548 } else
549 vid_ch->buf_field = common->fmt.fmt.pix.field;
550
551 sizeimage = common->fmt.fmt.pix.sizeimage;
552
553 hpitch = common->fmt.fmt.pix.bytesperline;
554
555 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
556 (V4L2_FIELD_INTERLACED == vid_ch->buf_field)) {
557
558 common->ytop_off = 0;
559 common->ybtm_off = hpitch;
560 common->ctop_off = sizeimage / 2;
561 common->cbtm_off = sizeimage / 2 + hpitch;
562 } else if (V4L2_FIELD_SEQ_TB == vid_ch->buf_field) {
563
564 common->ytop_off = 0;
565 common->ybtm_off = sizeimage / 4;
566 common->ctop_off = sizeimage / 2;
567 common->cbtm_off = common->ctop_off + sizeimage / 4;
568 } else if (V4L2_FIELD_SEQ_BT == vid_ch->buf_field) {
569
570 common->ybtm_off = 0;
571 common->ytop_off = sizeimage / 4;
572 common->cbtm_off = sizeimage / 2;
573 common->ctop_off = common->cbtm_off + sizeimage / 4;
574 }
575 if ((V4L2_FIELD_NONE == vid_ch->buf_field) ||
576 (V4L2_FIELD_INTERLACED == vid_ch->buf_field))
577 vpifparams->video_params.storage_mode = 1;
578 else
579 vpifparams->video_params.storage_mode = 0;
580
581 if (1 == vpifparams->std_info.frm_fmt)
582 vpifparams->video_params.hpitch =
583 common->fmt.fmt.pix.bytesperline;
584 else {
585 if ((field == V4L2_FIELD_ANY)
586 || (field == V4L2_FIELD_INTERLACED))
587 vpifparams->video_params.hpitch =
588 common->fmt.fmt.pix.bytesperline * 2;
589 else
590 vpifparams->video_params.hpitch =
591 common->fmt.fmt.pix.bytesperline;
592 }
593
594 ch->vpifparams.video_params.stdid = vpifparams->std_info.stdid;
595}
596
597
598
599
600
601static inline enum v4l2_field vpif_get_default_field(
602 struct vpif_interface *iface)
603{
604 return (iface->if_type == VPIF_IF_RAW_BAYER) ? V4L2_FIELD_NONE :
605 V4L2_FIELD_INTERLACED;
606}
607
608
609
610
611
612
613static void vpif_config_addr(struct channel_obj *ch, int muxmode)
614{
615 struct common_obj *common;
616
617 vpif_dbg(2, debug, "vpif_config_addr\n");
618
619 common = &(ch->common[VPIF_VIDEO_INDEX]);
620
621 if (VPIF_CHANNEL1_VIDEO == ch->channel_id)
622 common->set_addr = ch1_set_videobuf_addr;
623 else if (2 == muxmode)
624 common->set_addr = ch0_set_videobuf_addr_yc_nmux;
625 else
626 common->set_addr = ch0_set_videobuf_addr;
627}
628
629
630
631
632
633
634
635
636
637
638
639static int vpif_input_to_subdev(
640 struct vpif_capture_config *vpif_cfg,
641 struct vpif_capture_chan_config *chan_cfg,
642 int input_index)
643{
644 struct vpif_subdev_info *subdev_info;
645 const char *subdev_name;
646 int i;
647
648 vpif_dbg(2, debug, "vpif_input_to_subdev\n");
649
650 subdev_name = chan_cfg->inputs[input_index].subdev_name;
651 if (subdev_name == NULL)
652 return -1;
653
654
655 for (i = 0; i < vpif_cfg->subdev_count; i++) {
656 subdev_info = &vpif_cfg->subdev_info[i];
657 if (!strcmp(subdev_info->name, subdev_name))
658 return i;
659 }
660 return -1;
661}
662
663
664
665
666
667
668
669
670
671static int vpif_set_input(
672 struct vpif_capture_config *vpif_cfg,
673 struct channel_obj *ch,
674 int index)
675{
676 struct vpif_capture_chan_config *chan_cfg =
677 &vpif_cfg->chan_config[ch->channel_id];
678 struct vpif_subdev_info *subdev_info = NULL;
679 struct v4l2_subdev *sd = NULL;
680 u32 input = 0, output = 0;
681 int sd_index;
682 int ret;
683
684 sd_index = vpif_input_to_subdev(vpif_cfg, chan_cfg, index);
685 if (sd_index >= 0) {
686 sd = vpif_obj.sd[sd_index];
687 subdev_info = &vpif_cfg->subdev_info[sd_index];
688 }
689
690
691 if (sd && vpif_cfg->setup_input_path) {
692 ret = vpif_cfg->setup_input_path(ch->channel_id,
693 subdev_info->name);
694 if (ret < 0) {
695 vpif_dbg(1, debug, "couldn't setup input path for the" \
696 " sub device %s, for input index %d\n",
697 subdev_info->name, index);
698 return ret;
699 }
700 }
701
702 if (sd) {
703 input = chan_cfg->inputs[index].input_route;
704 output = chan_cfg->inputs[index].output_route;
705 ret = v4l2_subdev_call(sd, video, s_routing,
706 input, output, 0);
707 if (ret < 0 && ret != -ENOIOCTLCMD) {
708 vpif_dbg(1, debug, "Failed to set input\n");
709 return ret;
710 }
711 }
712 ch->input_idx = index;
713 ch->sd = sd;
714
715 ch->vpifparams.iface = chan_cfg->vpif_if;
716
717
718 ch->video_dev.tvnorms = chan_cfg->inputs[index].input.std;
719 return 0;
720}
721
722
723
724
725
726
727
728
729
730static int vpif_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
731{
732 struct video_device *vdev = video_devdata(file);
733 struct channel_obj *ch = video_get_drvdata(vdev);
734 int ret = 0;
735
736 vpif_dbg(2, debug, "vpif_querystd\n");
737
738
739 ret = v4l2_subdev_call(ch->sd, video, querystd, std_id);
740
741 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
742 return -ENODATA;
743 if (ret) {
744 vpif_dbg(1, debug, "Failed to query standard for sub devices\n");
745 return ret;
746 }
747
748 return 0;
749}
750
751
752
753
754
755
756
757static int vpif_g_std(struct file *file, void *priv, v4l2_std_id *std)
758{
759 struct vpif_capture_config *config = vpif_dev->platform_data;
760 struct video_device *vdev = video_devdata(file);
761 struct channel_obj *ch = video_get_drvdata(vdev);
762 struct vpif_capture_chan_config *chan_cfg;
763 struct v4l2_input input;
764
765 vpif_dbg(2, debug, "vpif_g_std\n");
766
767 if (config->chan_config[ch->channel_id].inputs == NULL)
768 return -ENODATA;
769
770 chan_cfg = &config->chan_config[ch->channel_id];
771 input = chan_cfg->inputs[ch->input_idx].input;
772 if (input.capabilities != V4L2_IN_CAP_STD)
773 return -ENODATA;
774
775 *std = ch->video.stdid;
776 return 0;
777}
778
779
780
781
782
783
784
785static int vpif_s_std(struct file *file, void *priv, v4l2_std_id std_id)
786{
787 struct vpif_capture_config *config = vpif_dev->platform_data;
788 struct video_device *vdev = video_devdata(file);
789 struct channel_obj *ch = video_get_drvdata(vdev);
790 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
791 struct vpif_capture_chan_config *chan_cfg;
792 struct v4l2_input input;
793 int ret;
794
795 vpif_dbg(2, debug, "vpif_s_std\n");
796
797 if (config->chan_config[ch->channel_id].inputs == NULL)
798 return -ENODATA;
799
800 chan_cfg = &config->chan_config[ch->channel_id];
801 input = chan_cfg->inputs[ch->input_idx].input;
802 if (input.capabilities != V4L2_IN_CAP_STD)
803 return -ENODATA;
804
805 if (vb2_is_busy(&common->buffer_queue))
806 return -EBUSY;
807
808
809 ch->video.stdid = std_id;
810 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
811
812
813 if (vpif_update_std_info(ch)) {
814 vpif_err("Error getting the standard info\n");
815 return -EINVAL;
816 }
817
818
819 ret = v4l2_subdev_call(ch->sd, video, s_std, std_id);
820 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV) {
821 vpif_dbg(1, debug, "Failed to set standard for sub devices\n");
822 return ret;
823 }
824 return 0;
825}
826
827
828
829
830
831
832
833static int vpif_enum_input(struct file *file, void *priv,
834 struct v4l2_input *input)
835{
836
837 struct vpif_capture_config *config = vpif_dev->platform_data;
838 struct video_device *vdev = video_devdata(file);
839 struct channel_obj *ch = video_get_drvdata(vdev);
840 struct vpif_capture_chan_config *chan_cfg;
841
842 chan_cfg = &config->chan_config[ch->channel_id];
843
844 if (input->index >= chan_cfg->input_count)
845 return -EINVAL;
846
847 memcpy(input, &chan_cfg->inputs[input->index].input,
848 sizeof(*input));
849 return 0;
850}
851
852
853
854
855
856
857
858static int vpif_g_input(struct file *file, void *priv, unsigned int *index)
859{
860 struct video_device *vdev = video_devdata(file);
861 struct channel_obj *ch = video_get_drvdata(vdev);
862
863 *index = ch->input_idx;
864 return 0;
865}
866
867
868
869
870
871
872
873static int vpif_s_input(struct file *file, void *priv, unsigned int index)
874{
875 struct vpif_capture_config *config = vpif_dev->platform_data;
876 struct video_device *vdev = video_devdata(file);
877 struct channel_obj *ch = video_get_drvdata(vdev);
878 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
879 struct vpif_capture_chan_config *chan_cfg;
880
881 chan_cfg = &config->chan_config[ch->channel_id];
882
883 if (index >= chan_cfg->input_count)
884 return -EINVAL;
885
886 if (vb2_is_busy(&common->buffer_queue))
887 return -EBUSY;
888
889 return vpif_set_input(config, ch, index);
890}
891
892
893
894
895
896
897
898static int vpif_enum_fmt_vid_cap(struct file *file, void *priv,
899 struct v4l2_fmtdesc *fmt)
900{
901 struct video_device *vdev = video_devdata(file);
902 struct channel_obj *ch = video_get_drvdata(vdev);
903
904 if (fmt->index != 0) {
905 vpif_dbg(1, debug, "Invalid format index\n");
906 return -EINVAL;
907 }
908
909
910 if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
911 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
912 strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
913 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
914 } else {
915 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
916 strcpy(fmt->description, "YCbCr4:2:2 YC Planar");
917 fmt->pixelformat = V4L2_PIX_FMT_YUV422P;
918 }
919 return 0;
920}
921
922
923
924
925
926
927
928static int vpif_try_fmt_vid_cap(struct file *file, void *priv,
929 struct v4l2_format *fmt)
930{
931 struct video_device *vdev = video_devdata(file);
932 struct channel_obj *ch = video_get_drvdata(vdev);
933 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
934 struct common_obj *common = &(ch->common[VPIF_VIDEO_INDEX]);
935 struct vpif_params *vpif_params = &ch->vpifparams;
936
937
938
939
940
941 if (vpif_params->iface.if_type == VPIF_IF_RAW_BAYER) {
942 if (pixfmt->pixelformat != V4L2_PIX_FMT_SBGGR8)
943 pixfmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
944 } else {
945 if (pixfmt->pixelformat != V4L2_PIX_FMT_YUV422P)
946 pixfmt->pixelformat = V4L2_PIX_FMT_YUV422P;
947 }
948
949 common->fmt.fmt.pix.pixelformat = pixfmt->pixelformat;
950
951 vpif_update_std_info(ch);
952
953 pixfmt->field = common->fmt.fmt.pix.field;
954 pixfmt->colorspace = common->fmt.fmt.pix.colorspace;
955 pixfmt->bytesperline = common->fmt.fmt.pix.width;
956 pixfmt->width = common->fmt.fmt.pix.width;
957 pixfmt->height = common->fmt.fmt.pix.height;
958 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height * 2;
959 pixfmt->priv = 0;
960
961 return 0;
962}
963
964
965
966
967
968
969
970
971static int vpif_g_fmt_vid_cap(struct file *file, void *priv,
972 struct v4l2_format *fmt)
973{
974 struct video_device *vdev = video_devdata(file);
975 struct channel_obj *ch = video_get_drvdata(vdev);
976 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
977
978
979 if (common->fmt.type != fmt->type)
980 return -EINVAL;
981
982
983 *fmt = common->fmt;
984 return 0;
985}
986
987
988
989
990
991
992
993static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
994 struct v4l2_format *fmt)
995{
996 struct video_device *vdev = video_devdata(file);
997 struct channel_obj *ch = video_get_drvdata(vdev);
998 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
999 int ret;
1000
1001 vpif_dbg(2, debug, "%s\n", __func__);
1002
1003 if (vb2_is_busy(&common->buffer_queue))
1004 return -EBUSY;
1005
1006 ret = vpif_try_fmt_vid_cap(file, priv, fmt);
1007 if (ret)
1008 return ret;
1009
1010
1011 common->fmt = *fmt;
1012 return 0;
1013}
1014
1015
1016
1017
1018
1019
1020
1021static int vpif_querycap(struct file *file, void *priv,
1022 struct v4l2_capability *cap)
1023{
1024 struct vpif_capture_config *config = vpif_dev->platform_data;
1025
1026 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1027 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1028 strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
1029 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1030 dev_name(vpif_dev));
1031 strlcpy(cap->card, config->card_name, sizeof(cap->card));
1032
1033 return 0;
1034}
1035
1036
1037
1038
1039
1040
1041
1042static int
1043vpif_enum_dv_timings(struct file *file, void *priv,
1044 struct v4l2_enum_dv_timings *timings)
1045{
1046 struct vpif_capture_config *config = vpif_dev->platform_data;
1047 struct video_device *vdev = video_devdata(file);
1048 struct channel_obj *ch = video_get_drvdata(vdev);
1049 struct vpif_capture_chan_config *chan_cfg;
1050 struct v4l2_input input;
1051 int ret;
1052
1053 if (config->chan_config[ch->channel_id].inputs == NULL)
1054 return -ENODATA;
1055
1056 chan_cfg = &config->chan_config[ch->channel_id];
1057 input = chan_cfg->inputs[ch->input_idx].input;
1058 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1059 return -ENODATA;
1060
1061 timings->pad = 0;
1062
1063 ret = v4l2_subdev_call(ch->sd, pad, enum_dv_timings, timings);
1064 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1065 return -EINVAL;
1066
1067 return ret;
1068}
1069
1070
1071
1072
1073
1074
1075
1076static int
1077vpif_query_dv_timings(struct file *file, void *priv,
1078 struct v4l2_dv_timings *timings)
1079{
1080 struct vpif_capture_config *config = vpif_dev->platform_data;
1081 struct video_device *vdev = video_devdata(file);
1082 struct channel_obj *ch = video_get_drvdata(vdev);
1083 struct vpif_capture_chan_config *chan_cfg;
1084 struct v4l2_input input;
1085 int ret;
1086
1087 if (config->chan_config[ch->channel_id].inputs == NULL)
1088 return -ENODATA;
1089
1090 chan_cfg = &config->chan_config[ch->channel_id];
1091 input = chan_cfg->inputs[ch->input_idx].input;
1092 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1093 return -ENODATA;
1094
1095 ret = v4l2_subdev_call(ch->sd, video, query_dv_timings, timings);
1096 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1097 return -ENODATA;
1098
1099 return ret;
1100}
1101
1102
1103
1104
1105
1106
1107
1108static int vpif_s_dv_timings(struct file *file, void *priv,
1109 struct v4l2_dv_timings *timings)
1110{
1111 struct vpif_capture_config *config = vpif_dev->platform_data;
1112 struct video_device *vdev = video_devdata(file);
1113 struct channel_obj *ch = video_get_drvdata(vdev);
1114 struct vpif_params *vpifparams = &ch->vpifparams;
1115 struct vpif_channel_config_params *std_info = &vpifparams->std_info;
1116 struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
1117 struct video_obj *vid_ch = &ch->video;
1118 struct v4l2_bt_timings *bt = &vid_ch->dv_timings.bt;
1119 struct vpif_capture_chan_config *chan_cfg;
1120 struct v4l2_input input;
1121 int ret;
1122
1123 if (config->chan_config[ch->channel_id].inputs == NULL)
1124 return -ENODATA;
1125
1126 chan_cfg = &config->chan_config[ch->channel_id];
1127 input = chan_cfg->inputs[ch->input_idx].input;
1128 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1129 return -ENODATA;
1130
1131 if (timings->type != V4L2_DV_BT_656_1120) {
1132 vpif_dbg(2, debug, "Timing type not defined\n");
1133 return -EINVAL;
1134 }
1135
1136 if (vb2_is_busy(&common->buffer_queue))
1137 return -EBUSY;
1138
1139
1140 ret = v4l2_subdev_call(ch->sd, video, s_dv_timings, timings);
1141 if (ret == -ENOIOCTLCMD || ret == -ENODEV)
1142 ret = 0;
1143 if (ret < 0) {
1144 vpif_dbg(2, debug, "Error setting custom DV timings\n");
1145 return ret;
1146 }
1147
1148 if (!(timings->bt.width && timings->bt.height &&
1149 (timings->bt.hbackporch ||
1150 timings->bt.hfrontporch ||
1151 timings->bt.hsync) &&
1152 timings->bt.vfrontporch &&
1153 (timings->bt.vbackporch ||
1154 timings->bt.vsync))) {
1155 vpif_dbg(2, debug, "Timings for width, height, "
1156 "horizontal back porch, horizontal sync, "
1157 "horizontal front porch, vertical back porch, "
1158 "vertical sync and vertical back porch "
1159 "must be defined\n");
1160 return -EINVAL;
1161 }
1162
1163 vid_ch->dv_timings = *timings;
1164
1165
1166
1167 std_info->eav2sav = V4L2_DV_BT_BLANKING_WIDTH(bt) - 8;
1168 std_info->sav2eav = bt->width;
1169
1170 std_info->l1 = 1;
1171 std_info->l3 = bt->vsync + bt->vbackporch + 1;
1172
1173 std_info->vsize = V4L2_DV_BT_FRAME_HEIGHT(bt);
1174 if (bt->interlaced) {
1175 if (bt->il_vbackporch || bt->il_vfrontporch || bt->il_vsync) {
1176 std_info->l5 = std_info->vsize/2 -
1177 (bt->vfrontporch - 1);
1178 std_info->l7 = std_info->vsize/2 + 1;
1179 std_info->l9 = std_info->l7 + bt->il_vsync +
1180 bt->il_vbackporch + 1;
1181 std_info->l11 = std_info->vsize -
1182 (bt->il_vfrontporch - 1);
1183 } else {
1184 vpif_dbg(2, debug, "Required timing values for "
1185 "interlaced BT format missing\n");
1186 return -EINVAL;
1187 }
1188 } else {
1189 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
1190 }
1191 strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1192 std_info->width = bt->width;
1193 std_info->height = bt->height;
1194 std_info->frm_fmt = bt->interlaced ? 0 : 1;
1195 std_info->ycmux_mode = 0;
1196 std_info->capture_format = 0;
1197 std_info->vbi_supported = 0;
1198 std_info->hd_sd = 1;
1199 std_info->stdid = 0;
1200
1201 vid_ch->stdid = 0;
1202 return 0;
1203}
1204
1205
1206
1207
1208
1209
1210
1211static int vpif_g_dv_timings(struct file *file, void *priv,
1212 struct v4l2_dv_timings *timings)
1213{
1214 struct vpif_capture_config *config = vpif_dev->platform_data;
1215 struct video_device *vdev = video_devdata(file);
1216 struct channel_obj *ch = video_get_drvdata(vdev);
1217 struct video_obj *vid_ch = &ch->video;
1218 struct vpif_capture_chan_config *chan_cfg;
1219 struct v4l2_input input;
1220
1221 if (config->chan_config[ch->channel_id].inputs == NULL)
1222 return -ENODATA;
1223
1224 chan_cfg = &config->chan_config[ch->channel_id];
1225 input = chan_cfg->inputs[ch->input_idx].input;
1226 if (input.capabilities != V4L2_IN_CAP_DV_TIMINGS)
1227 return -ENODATA;
1228
1229 *timings = vid_ch->dv_timings;
1230
1231 return 0;
1232}
1233
1234
1235
1236
1237
1238
1239
1240
1241static int vpif_log_status(struct file *filep, void *priv)
1242{
1243
1244 v4l2_device_call_all(&vpif_obj.v4l2_dev, 0, core, log_status);
1245
1246 return 0;
1247}
1248
1249
1250static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
1251 .vidioc_querycap = vpif_querycap,
1252 .vidioc_enum_fmt_vid_cap = vpif_enum_fmt_vid_cap,
1253 .vidioc_g_fmt_vid_cap = vpif_g_fmt_vid_cap,
1254 .vidioc_s_fmt_vid_cap = vpif_s_fmt_vid_cap,
1255 .vidioc_try_fmt_vid_cap = vpif_try_fmt_vid_cap,
1256
1257 .vidioc_enum_input = vpif_enum_input,
1258 .vidioc_s_input = vpif_s_input,
1259 .vidioc_g_input = vpif_g_input,
1260
1261 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1262 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1263 .vidioc_querybuf = vb2_ioctl_querybuf,
1264 .vidioc_qbuf = vb2_ioctl_qbuf,
1265 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1266 .vidioc_expbuf = vb2_ioctl_expbuf,
1267 .vidioc_streamon = vb2_ioctl_streamon,
1268 .vidioc_streamoff = vb2_ioctl_streamoff,
1269
1270 .vidioc_querystd = vpif_querystd,
1271 .vidioc_s_std = vpif_s_std,
1272 .vidioc_g_std = vpif_g_std,
1273
1274 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1275 .vidioc_query_dv_timings = vpif_query_dv_timings,
1276 .vidioc_s_dv_timings = vpif_s_dv_timings,
1277 .vidioc_g_dv_timings = vpif_g_dv_timings,
1278
1279 .vidioc_log_status = vpif_log_status,
1280};
1281
1282
1283static struct v4l2_file_operations vpif_fops = {
1284 .owner = THIS_MODULE,
1285 .open = v4l2_fh_open,
1286 .release = vb2_fop_release,
1287 .unlocked_ioctl = video_ioctl2,
1288 .mmap = vb2_fop_mmap,
1289 .poll = vb2_fop_poll
1290};
1291
1292
1293
1294
1295
1296
1297static int initialize_vpif(void)
1298{
1299 int err, i, j;
1300 int free_channel_objects_index;
1301
1302
1303 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1304 vpif_obj.dev[i] =
1305 kzalloc(sizeof(*vpif_obj.dev[i]), GFP_KERNEL);
1306
1307 if (!vpif_obj.dev[i]) {
1308 free_channel_objects_index = i;
1309 err = -ENOMEM;
1310 goto vpif_init_free_channel_objects;
1311 }
1312 }
1313 return 0;
1314
1315vpif_init_free_channel_objects:
1316 for (j = 0; j < free_channel_objects_index; j++)
1317 kfree(vpif_obj.dev[j]);
1318 return err;
1319}
1320
1321static int vpif_async_bound(struct v4l2_async_notifier *notifier,
1322 struct v4l2_subdev *subdev,
1323 struct v4l2_async_subdev *asd)
1324{
1325 int i;
1326
1327 for (i = 0; i < vpif_obj.config->subdev_count; i++)
1328 if (!strcmp(vpif_obj.config->subdev_info[i].name,
1329 subdev->name)) {
1330 vpif_obj.sd[i] = subdev;
1331 return 0;
1332 }
1333
1334 return -EINVAL;
1335}
1336
1337static int vpif_probe_complete(void)
1338{
1339 struct common_obj *common;
1340 struct video_device *vdev;
1341 struct channel_obj *ch;
1342 struct vb2_queue *q;
1343 int j, err, k;
1344
1345 for (j = 0; j < VPIF_CAPTURE_MAX_DEVICES; j++) {
1346 ch = vpif_obj.dev[j];
1347 ch->channel_id = j;
1348 common = &(ch->common[VPIF_VIDEO_INDEX]);
1349 spin_lock_init(&common->irqlock);
1350 mutex_init(&common->lock);
1351
1352
1353 err = vpif_set_input(vpif_obj.config, ch, 0);
1354 if (err)
1355 goto probe_out;
1356
1357
1358 ch->video.stdid = V4L2_STD_525_60;
1359 memset(&ch->video.dv_timings, 0, sizeof(ch->video.dv_timings));
1360 vpif_update_std_info(ch);
1361
1362
1363 q = &common->buffer_queue;
1364 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1365 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1366 q->drv_priv = ch;
1367 q->ops = &video_qops;
1368 q->mem_ops = &vb2_dma_contig_memops;
1369 q->buf_struct_size = sizeof(struct vpif_cap_buffer);
1370 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1371 q->min_buffers_needed = 1;
1372 q->lock = &common->lock;
1373 q->dev = vpif_dev;
1374
1375 err = vb2_queue_init(q);
1376 if (err) {
1377 vpif_err("vpif_capture: vb2_queue_init() failed\n");
1378 goto probe_out;
1379 }
1380
1381 INIT_LIST_HEAD(&common->dma_queue);
1382
1383
1384 vdev = &ch->video_dev;
1385 strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
1386 vdev->release = video_device_release_empty;
1387 vdev->fops = &vpif_fops;
1388 vdev->ioctl_ops = &vpif_ioctl_ops;
1389 vdev->v4l2_dev = &vpif_obj.v4l2_dev;
1390 vdev->vfl_dir = VFL_DIR_RX;
1391 vdev->queue = q;
1392 vdev->lock = &common->lock;
1393 video_set_drvdata(&ch->video_dev, ch);
1394 err = video_register_device(vdev,
1395 VFL_TYPE_GRABBER, (j ? 1 : 0));
1396 if (err)
1397 goto probe_out;
1398 }
1399
1400 v4l2_info(&vpif_obj.v4l2_dev, "VPIF capture driver initialized\n");
1401 return 0;
1402
1403probe_out:
1404 for (k = 0; k < j; k++) {
1405
1406 ch = vpif_obj.dev[k];
1407 common = &ch->common[k];
1408
1409 video_unregister_device(&ch->video_dev);
1410 }
1411 kfree(vpif_obj.sd);
1412 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1413
1414 return err;
1415}
1416
1417static int vpif_async_complete(struct v4l2_async_notifier *notifier)
1418{
1419 return vpif_probe_complete();
1420}
1421
1422
1423
1424
1425
1426
1427
1428
1429static __init int vpif_probe(struct platform_device *pdev)
1430{
1431 struct vpif_subdev_info *subdevdata;
1432 struct i2c_adapter *i2c_adap;
1433 struct resource *res;
1434 int subdev_count;
1435 int res_idx = 0;
1436 int i, err;
1437
1438 vpif_dev = &pdev->dev;
1439
1440 err = initialize_vpif();
1441 if (err) {
1442 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1443 return err;
1444 }
1445
1446 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
1447 if (err) {
1448 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1449 return err;
1450 }
1451
1452 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
1453 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
1454 IRQF_SHARED, VPIF_DRIVER_NAME,
1455 (void *)(&vpif_obj.dev[res_idx]->
1456 channel_id));
1457 if (err) {
1458 err = -EINVAL;
1459 goto vpif_unregister;
1460 }
1461 res_idx++;
1462 }
1463
1464 vpif_obj.config = pdev->dev.platform_data;
1465
1466 subdev_count = vpif_obj.config->subdev_count;
1467 vpif_obj.sd = kzalloc(sizeof(struct v4l2_subdev *) * subdev_count,
1468 GFP_KERNEL);
1469 if (vpif_obj.sd == NULL) {
1470 vpif_err("unable to allocate memory for subdevice pointers\n");
1471 err = -ENOMEM;
1472 goto vpif_unregister;
1473 }
1474
1475 if (!vpif_obj.config->asd_sizes) {
1476 i2c_adap = i2c_get_adapter(1);
1477 for (i = 0; i < subdev_count; i++) {
1478 subdevdata = &vpif_obj.config->subdev_info[i];
1479 vpif_obj.sd[i] =
1480 v4l2_i2c_new_subdev_board(&vpif_obj.v4l2_dev,
1481 i2c_adap,
1482 &subdevdata->
1483 board_info,
1484 NULL);
1485
1486 if (!vpif_obj.sd[i]) {
1487 vpif_err("Error registering v4l2 subdevice\n");
1488 err = -ENODEV;
1489 goto probe_subdev_out;
1490 }
1491 v4l2_info(&vpif_obj.v4l2_dev,
1492 "registered sub device %s\n",
1493 subdevdata->name);
1494 }
1495 vpif_probe_complete();
1496 } else {
1497 vpif_obj.notifier.subdevs = vpif_obj.config->asd;
1498 vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
1499 vpif_obj.notifier.bound = vpif_async_bound;
1500 vpif_obj.notifier.complete = vpif_async_complete;
1501 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
1502 &vpif_obj.notifier);
1503 if (err) {
1504 vpif_err("Error registering async notifier\n");
1505 err = -EINVAL;
1506 goto probe_subdev_out;
1507 }
1508 }
1509
1510 return 0;
1511
1512probe_subdev_out:
1513
1514 kfree(vpif_obj.sd);
1515vpif_unregister:
1516 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1517
1518 return err;
1519}
1520
1521
1522
1523
1524
1525
1526
1527static int vpif_remove(struct platform_device *device)
1528{
1529 struct common_obj *common;
1530 struct channel_obj *ch;
1531 int i;
1532
1533 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1534
1535 kfree(vpif_obj.sd);
1536
1537 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1538
1539 ch = vpif_obj.dev[i];
1540 common = &ch->common[VPIF_VIDEO_INDEX];
1541
1542 video_unregister_device(&ch->video_dev);
1543 kfree(vpif_obj.dev[i]);
1544 }
1545 return 0;
1546}
1547
1548#ifdef CONFIG_PM_SLEEP
1549
1550
1551
1552static int vpif_suspend(struct device *dev)
1553{
1554
1555 struct common_obj *common;
1556 struct channel_obj *ch;
1557 int i;
1558
1559 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1560
1561 ch = vpif_obj.dev[i];
1562 common = &ch->common[VPIF_VIDEO_INDEX];
1563
1564 if (!vb2_start_streaming_called(&common->buffer_queue))
1565 continue;
1566
1567 mutex_lock(&common->lock);
1568
1569 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1570 enable_channel0(0);
1571 channel0_intr_enable(0);
1572 }
1573 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1574 ycmux_mode == 2) {
1575 enable_channel1(0);
1576 channel1_intr_enable(0);
1577 }
1578 mutex_unlock(&common->lock);
1579 }
1580
1581 return 0;
1582}
1583
1584
1585
1586
1587static int vpif_resume(struct device *dev)
1588{
1589 struct common_obj *common;
1590 struct channel_obj *ch;
1591 int i;
1592
1593 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
1594
1595 ch = vpif_obj.dev[i];
1596 common = &ch->common[VPIF_VIDEO_INDEX];
1597
1598 if (!vb2_start_streaming_called(&common->buffer_queue))
1599 continue;
1600
1601 mutex_lock(&common->lock);
1602
1603 if (ch->channel_id == VPIF_CHANNEL0_VIDEO) {
1604 enable_channel0(1);
1605 channel0_intr_enable(1);
1606 }
1607 if (ch->channel_id == VPIF_CHANNEL1_VIDEO ||
1608 ycmux_mode == 2) {
1609 enable_channel1(1);
1610 channel1_intr_enable(1);
1611 }
1612 mutex_unlock(&common->lock);
1613 }
1614
1615 return 0;
1616}
1617#endif
1618
1619static SIMPLE_DEV_PM_OPS(vpif_pm_ops, vpif_suspend, vpif_resume);
1620
1621static __refdata struct platform_driver vpif_driver = {
1622 .driver = {
1623 .name = VPIF_DRIVER_NAME,
1624 .pm = &vpif_pm_ops,
1625 },
1626 .probe = vpif_probe,
1627 .remove = vpif_remove,
1628};
1629
1630module_platform_driver(vpif_driver);
1631