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