aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7164
diff options
context:
space:
mode:
authorSteven Toth <stoth@kernellabs.com>2010-07-31 15:06:06 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-21 05:55:06 -0400
commite8ce2f21665442a29a2b2d1b25197b05405a7216 (patch)
treeda2b06eb5b2047f453ebbc2d87a027c7487266f3 /drivers/media/video/saa7164
parent11bd27b2e7ab8125b0f8d763b8b61d07a5a38acf (diff)
[media] saa7164: add NTSC VBI support
IRQ handlers, firmware messages, deferred queue handlers, V4L api's etc. Signed-off-by: Steven Toth <stoth@kernellabs.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/saa7164')
-rw-r--r--drivers/media/video/saa7164/Makefile2
-rw-r--r--drivers/media/video/saa7164/saa7164-api.c111
-rw-r--r--drivers/media/video/saa7164/saa7164-cards.c14
-rw-r--r--drivers/media/video/saa7164/saa7164-core.c143
-rw-r--r--drivers/media/video/saa7164/saa7164-reg.h2
-rw-r--r--drivers/media/video/saa7164/saa7164-types.h20
-rw-r--r--drivers/media/video/saa7164/saa7164.h51
7 files changed, 326 insertions, 17 deletions
diff --git a/drivers/media/video/saa7164/Makefile b/drivers/media/video/saa7164/Makefile
index e2b748007dbb..6303a8e60eac 100644
--- a/drivers/media/video/saa7164/Makefile
+++ b/drivers/media/video/saa7164/Makefile
@@ -1,6 +1,6 @@
1saa7164-objs := saa7164-cards.o saa7164-core.o saa7164-i2c.o saa7164-dvb.o \ 1saa7164-objs := saa7164-cards.o saa7164-core.o saa7164-i2c.o saa7164-dvb.o \
2 saa7164-fw.o saa7164-bus.o saa7164-cmd.o saa7164-api.o \ 2 saa7164-fw.o saa7164-bus.o saa7164-cmd.o saa7164-api.o \
3 saa7164-buffer.o saa7164-encoder.o 3 saa7164-buffer.o saa7164-encoder.o saa7164-vbi.o
4 4
5obj-$(CONFIG_VIDEO_SAA7164) += saa7164.o 5obj-$(CONFIG_VIDEO_SAA7164) += saa7164.o
6 6
diff --git a/drivers/media/video/saa7164/saa7164-api.c b/drivers/media/video/saa7164/saa7164-api.c
index 9fd39326b85a..814751deb218 100644
--- a/drivers/media/video/saa7164/saa7164-api.c
+++ b/drivers/media/video/saa7164/saa7164-api.c
@@ -24,6 +24,62 @@
24 24
25#include "saa7164.h" 25#include "saa7164.h"
26 26
27int saa7164_api_set_vbi_format(struct saa7164_port *port)
28{
29 struct saa7164_dev *dev = port->dev;
30 tmComResProbeCommit_t fmt, rsp;
31 int ret;
32
33 dprintk(DBGLVL_API, "%s(nr=%d)\n", __func__, port->nr);
34
35 fmt.bmHint = 0;
36 fmt.bFormatIndex = 1;
37 fmt.bFrameIndex = 1;
38
39 /* Probe, see if it can support this format */
40 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
41 SET_CUR, SAA_PROBE_CONTROL, sizeof(fmt), &fmt);
42 if (ret != SAA_OK)
43 printk(KERN_ERR "%s() set error, ret = 0x%x\n", __func__, ret);
44
45 /* See of the format change was successful */
46 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
47 GET_CUR, SAA_PROBE_CONTROL, sizeof(rsp), &rsp);
48 if (ret != SAA_OK) {
49 printk(KERN_ERR "%s() get error, ret = 0x%x\n", __func__, ret);
50 } else {
51 /* Compare requested vs received, should be same */
52 if (memcmp(&fmt, &rsp, sizeof(rsp)) == 0) {
53 /* Ask the device to select the negotiated format */
54 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
55 SET_CUR, SAA_COMMIT_CONTROL, sizeof(fmt), &fmt);
56 if (ret != SAA_OK)
57 printk(KERN_ERR "%s() commit error, ret = 0x%x\n",
58 __func__, ret);
59
60 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
61 GET_CUR, SAA_COMMIT_CONTROL, sizeof(rsp), &rsp);
62 if (ret != SAA_OK)
63 printk(KERN_ERR "%s() GET commit error, ret = 0x%x\n",
64 __func__, ret);
65
66 if (memcmp(&fmt, &rsp, sizeof(rsp)) != 0)
67 printk(KERN_ERR "%s() memcmp error, ret = 0x%x\n",
68 __func__, ret);
69
70 dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint);
71 dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n", rsp.bFormatIndex);
72 dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n", rsp.bFrameIndex);
73 } else
74 printk(KERN_ERR "%s() compare failed\n", __func__);
75 }
76
77 if (ret == SAA_OK)
78 dprintk(DBGLVL_API, "%s(nr=%d) Success\n", __func__, port->nr);
79
80 return ret;
81}
82
27int saa7164_api_set_gop_size(struct saa7164_port *port) 83int saa7164_api_set_gop_size(struct saa7164_port *port)
28{ 84{
29 struct saa7164_dev *dev = port->dev; 85 struct saa7164_dev *dev = port->dev;
@@ -463,7 +519,8 @@ int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
463 int ret; 519 int ret;
464 u8 mas; 520 u8 mas;
465 521
466 dprintk(DBGLVL_API, "%s()\n", __func__); 522 dprintk(DBGLVL_API, "%s(nr=%d type=%d val=%x)\n", __func__,
523 port->nr, port->type, val);
467 524
468 if (port->nr == 0) 525 if (port->nr == 0)
469 mas = 0xd0; 526 mas = 0xd0;
@@ -516,7 +573,7 @@ int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
516 int ret = 0; 573 int ret = 0;
517 u8 agc_disable; 574 u8 agc_disable;
518 575
519 dprintk(DBGLVL_API, "%s(%p, 0x%x)\n", __func__, port, std); 576 dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std);
520 577
521 if (std & V4L2_STD_NTSC) { 578 if (std & V4L2_STD_NTSC) {
522 dprintk(DBGLVL_API, " NTSC\n"); 579 dprintk(DBGLVL_API, " NTSC\n");
@@ -580,6 +637,9 @@ int saa7164_api_initialize_dif(struct saa7164_port *port)
580 int ret = -EINVAL; 637 int ret = -EINVAL;
581 u32 std = 0; 638 u32 std = 0;
582 639
640 dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__,
641 port->nr, port->type);
642
583 if (port->type == SAA7164_MPEG_ENCODER) { 643 if (port->type == SAA7164_MPEG_ENCODER) {
584 /* Pick any analog standard to init the diff. 644 /* Pick any analog standard to init the diff.
585 * we'll come back during encoder_init' 645 * we'll come back during encoder_init'
@@ -593,6 +653,13 @@ int saa7164_api_initialize_dif(struct saa7164_port *port)
593 else 653 else
594 p = &dev->ports[ SAA7164_PORT_ENC2 ]; 654 p = &dev->ports[ SAA7164_PORT_ENC2 ];
595 } else 655 } else
656 if (port->type == SAA7164_MPEG_VBI) {
657 std = V4L2_STD_NTSC;
658 if (port->nr == SAA7164_PORT_VBI1)
659 p = &dev->ports[ SAA7164_PORT_ENC1 ];
660 else
661 p = &dev->ports[ SAA7164_PORT_ENC2 ];
662 } else
596 BUG(); 663 BUG();
597 664
598 if (p) 665 if (p)
@@ -603,12 +670,18 @@ int saa7164_api_initialize_dif(struct saa7164_port *port)
603 670
604int saa7164_api_transition_port(struct saa7164_port *port, u8 mode) 671int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
605{ 672{
673 struct saa7164_dev *dev = port->dev;
674
606 int ret; 675 int ret;
607 676
677 dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n",
678 __func__, port->nr, port->hwcfg.unitid, mode);
679
608 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR, 680 ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR,
609 SAA_STATE_CONTROL, sizeof(mode), &mode); 681 SAA_STATE_CONTROL, sizeof(mode), &mode);
610 if (ret != SAA_OK) 682 if (ret != SAA_OK)
611 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 683 printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
684 __func__, port->nr, port->hwcfg.unitid, ret);
612 685
613 return ret; 686 return ret;
614} 687}
@@ -639,6 +712,23 @@ int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen)
639} 712}
640 713
641 714
715int saa7164_api_configure_port_vbi(struct saa7164_dev *dev,
716 struct saa7164_port *port)
717{
718 tmComResVBIFormatDescrHeader_t *fmt = &port->vbi_fmt_ntsc;
719
720 dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
721 dprintk(DBGLVL_API, " VideoStandard = 0x%x\n", fmt->VideoStandard);
722 dprintk(DBGLVL_API, " StartLine = %d\n", fmt->StartLine);
723 dprintk(DBGLVL_API, " EndLine = %d\n", fmt->EndLine);
724 dprintk(DBGLVL_API, " FieldRate = %d\n", fmt->FieldRate);
725 dprintk(DBGLVL_API, " bNumLines = %d\n", fmt->bNumLines);
726 dprintk(DBGLVL_API, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
727 port->nr);
728
729 return 0;
730}
731
642int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev, 732int saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev,
643 struct saa7164_port *port, 733 struct saa7164_port *port,
644 tmComResTSFormatDescrHeader_t *tsfmt) 734 tmComResTSFormatDescrHeader_t *tsfmt)
@@ -710,6 +800,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
710{ 800{
711 struct saa7164_port *tsport = 0; 801 struct saa7164_port *tsport = 0;
712 struct saa7164_port *encport = 0; 802 struct saa7164_port *encport = 0;
803 struct saa7164_port *vbiport = 0;
713 u32 idx, next_offset; 804 u32 idx, next_offset;
714 int i; 805 int i;
715 tmComResDescrHeader_t *hdr, *t; 806 tmComResDescrHeader_t *hdr, *t;
@@ -724,6 +815,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
724 tmComResProcDescrHeader_t *pdh; 815 tmComResProcDescrHeader_t *pdh;
725 tmComResAFeatureDescrHeader_t *afd; 816 tmComResAFeatureDescrHeader_t *afd;
726 tmComResEncoderDescrHeader_t *edh; 817 tmComResEncoderDescrHeader_t *edh;
818 tmComResVBIFormatDescrHeader_t *vbifmt;
727 u32 currpath = 0; 819 u32 currpath = 0;
728 820
729 dprintk(DBGLVL_API, 821 dprintk(DBGLVL_API,
@@ -881,8 +973,17 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
881 encport, psfmt); 973 encport, psfmt);
882 break; 974 break;
883 case VS_FORMAT_VBI: 975 case VS_FORMAT_VBI:
884 dprintk(DBGLVL_API, 976 vbifmt =
885 " = VS_FORMAT_VBI\n"); 977 (tmComResVBIFormatDescrHeader_t *)t;
978 if (currpath == 1)
979 vbiport = &dev->ports[ SAA7164_PORT_VBI1 ];
980 else
981 vbiport = &dev->ports[ SAA7164_PORT_VBI2 ];
982 memcpy(&vbiport->hwcfg, vcoutputtermhdr,
983 sizeof(*vcoutputtermhdr));
984 memcpy(&vbiport->vbi_fmt_ntsc, vbifmt, sizeof(*vbifmt));
985 saa7164_api_configure_port_vbi(dev,
986 vbiport);
886 break; 987 break;
887 case VS_FORMAT_RDS: 988 case VS_FORMAT_RDS:
888 dprintk(DBGLVL_API, 989 dprintk(DBGLVL_API,
diff --git a/drivers/media/video/saa7164/saa7164-cards.c b/drivers/media/video/saa7164/saa7164-cards.c
index 81baa3662919..dc2889abb337 100644
--- a/drivers/media/video/saa7164/saa7164-cards.c
+++ b/drivers/media/video/saa7164/saa7164-cards.c
@@ -57,6 +57,8 @@ struct saa7164_board saa7164_boards[] = {
57 .portb = SAA7164_MPEG_DVB, 57 .portb = SAA7164_MPEG_DVB,
58 .portc = SAA7164_MPEG_ENCODER, 58 .portc = SAA7164_MPEG_ENCODER,
59 .portd = SAA7164_MPEG_ENCODER, 59 .portd = SAA7164_MPEG_ENCODER,
60 .porte = SAA7164_MPEG_VBI,
61 .portf = SAA7164_MPEG_VBI,
60 .chiprev = SAA7164_CHIP_REV3, 62 .chiprev = SAA7164_CHIP_REV3,
61 .unit = {{ 63 .unit = {{
62 .id = 0x1d, 64 .id = 0x1d,
@@ -101,6 +103,8 @@ struct saa7164_board saa7164_boards[] = {
101 .portb = SAA7164_MPEG_DVB, 103 .portb = SAA7164_MPEG_DVB,
102 .portc = SAA7164_MPEG_ENCODER, 104 .portc = SAA7164_MPEG_ENCODER,
103 .portd = SAA7164_MPEG_ENCODER, 105 .portd = SAA7164_MPEG_ENCODER,
106 .porte = SAA7164_MPEG_VBI,
107 .portf = SAA7164_MPEG_VBI,
104 .chiprev = SAA7164_CHIP_REV2, 108 .chiprev = SAA7164_CHIP_REV2,
105 .unit = {{ 109 .unit = {{
106 .id = 0x06, 110 .id = 0x06,
@@ -145,6 +149,8 @@ struct saa7164_board saa7164_boards[] = {
145 .portb = SAA7164_MPEG_DVB, 149 .portb = SAA7164_MPEG_DVB,
146 .portc = SAA7164_MPEG_ENCODER, 150 .portc = SAA7164_MPEG_ENCODER,
147 .portd = SAA7164_MPEG_ENCODER, 151 .portd = SAA7164_MPEG_ENCODER,
152 .porte = SAA7164_MPEG_VBI,
153 .portf = SAA7164_MPEG_VBI,
148 .chiprev = SAA7164_CHIP_REV2, 154 .chiprev = SAA7164_CHIP_REV2,
149 .unit = {{ 155 .unit = {{
150 .id = 0x1d, 156 .id = 0x1d,
@@ -205,6 +211,8 @@ struct saa7164_board saa7164_boards[] = {
205 .portd = SAA7164_MPEG_ENCODER, 211 .portd = SAA7164_MPEG_ENCODER,
206 .portc = SAA7164_MPEG_ENCODER, 212 .portc = SAA7164_MPEG_ENCODER,
207 .portd = SAA7164_MPEG_ENCODER, 213 .portd = SAA7164_MPEG_ENCODER,
214 .porte = SAA7164_MPEG_VBI,
215 .portf = SAA7164_MPEG_VBI,
208 .chiprev = SAA7164_CHIP_REV3, 216 .chiprev = SAA7164_CHIP_REV3,
209 .unit = {{ 217 .unit = {{
210 .id = 0x22, 218 .id = 0x22,
@@ -263,6 +271,10 @@ struct saa7164_board saa7164_boards[] = {
263 .portb = SAA7164_MPEG_DVB, 271 .portb = SAA7164_MPEG_DVB,
264 .portc = SAA7164_MPEG_ENCODER, 272 .portc = SAA7164_MPEG_ENCODER,
265 .portd = SAA7164_MPEG_ENCODER, 273 .portd = SAA7164_MPEG_ENCODER,
274 .porte = SAA7164_MPEG_VBI,
275 .portf = SAA7164_MPEG_VBI,
276 .porte = SAA7164_MPEG_VBI,
277 .portf = SAA7164_MPEG_VBI,
266 .chiprev = SAA7164_CHIP_REV3, 278 .chiprev = SAA7164_CHIP_REV3,
267 .unit = {{ 279 .unit = {{
268 .id = 0x28, 280 .id = 0x28,
@@ -321,6 +333,8 @@ struct saa7164_board saa7164_boards[] = {
321 .portb = SAA7164_MPEG_DVB, 333 .portb = SAA7164_MPEG_DVB,
322 .portc = SAA7164_MPEG_ENCODER, 334 .portc = SAA7164_MPEG_ENCODER,
323 .portd = SAA7164_MPEG_ENCODER, 335 .portd = SAA7164_MPEG_ENCODER,
336 .porte = SAA7164_MPEG_VBI,
337 .portf = SAA7164_MPEG_VBI,
324 .chiprev = SAA7164_CHIP_REV3, 338 .chiprev = SAA7164_CHIP_REV3,
325 .unit = {{ 339 .unit = {{
326 .id = 0x26, 340 .id = 0x26,
diff --git a/drivers/media/video/saa7164/saa7164-core.c b/drivers/media/video/saa7164/saa7164-core.c
index b1efbeae8598..7901bb1c739e 100644
--- a/drivers/media/video/saa7164/saa7164-core.c
+++ b/drivers/media/video/saa7164/saa7164-core.c
@@ -53,6 +53,10 @@ unsigned int encoder_buffers = SAA7164_MAX_ENCODER_BUFFERS;
53module_param(encoder_buffers, int, 0644); 53module_param(encoder_buffers, int, 0644);
54MODULE_PARM_DESC(encoder_buffers, "Total buffers in read queue 16-512 def:64"); 54MODULE_PARM_DESC(encoder_buffers, "Total buffers in read queue 16-512 def:64");
55 55
56unsigned int vbi_buffers = SAA7164_MAX_VBI_BUFFERS;
57module_param(vbi_buffers, int, 0644);
58MODULE_PARM_DESC(vbi_buffers, "Total buffers in read queue 16-512 def:64");
59
56unsigned int waitsecs = 10; 60unsigned int waitsecs = 10;
57module_param(waitsecs, int, 0644); 61module_param(waitsecs, int, 0644);
58MODULE_PARM_DESC(waitsecs, "timeout on firmware messages"); 62MODULE_PARM_DESC(waitsecs, "timeout on firmware messages");
@@ -440,6 +444,61 @@ static void saa7164_work_enchandler(struct work_struct *w)
440 } 444 }
441} 445}
442 446
447static void saa7164_work_vbihandler(struct work_struct *w)
448{
449 struct saa7164_port *port =
450 container_of(w, struct saa7164_port, workenc);
451 struct saa7164_dev *dev = port->dev;
452
453 u32 wp, mcb, rp, cnt = 0;
454
455 port->last_svc_msecs_diff = port->last_svc_msecs;
456 port->last_svc_msecs = jiffies_to_msecs(jiffies);
457 port->last_svc_msecs_diff = port->last_svc_msecs -
458 port->last_svc_msecs_diff;
459
460 saa7164_histogram_update(&port->svc_interval,
461 port->last_svc_msecs_diff);
462
463 port->last_irq_svc_msecs_diff = port->last_svc_msecs -
464 port->last_irq_msecs;
465
466 saa7164_histogram_update(&port->irq_svc_interval,
467 port->last_irq_svc_msecs_diff);
468
469 dprintk(DBGLVL_IRQ,
470 "%s() %Ldms elapsed irq->deferred %Ldms wp: %d rp: %d\n",
471 __func__,
472 port->last_svc_msecs_diff,
473 port->last_irq_svc_msecs_diff,
474 port->last_svc_wp,
475 port->last_svc_rp
476 );
477
478 /* Current write position */
479 wp = saa7164_readl(port->bufcounter);
480 if (wp > (port->hwcfg.buffercount - 1)) {
481 printk(KERN_ERR "%s() illegal buf count %d\n", __func__, wp);
482 return;
483 }
484
485 /* Most current complete buffer */
486 if (wp == 0)
487 mcb = (port->hwcfg.buffercount - 1);
488 else
489 mcb = wp - 1;
490 /* TODO: Convert this into a /proc/saa7164 style readable file */
491 if (print_histogram == port->nr) {
492 saa7164_histogram_print(port, &port->irq_interval);
493 saa7164_histogram_print(port, &port->svc_interval);
494 saa7164_histogram_print(port, &port->irq_svc_interval);
495 saa7164_histogram_print(port, &port->read_interval);
496 saa7164_histogram_print(port, &port->poll_interval);
497 /* TODO: fix this to preserve any previous state */
498 print_histogram = 64 + port->nr;
499 }
500}
501
443static void saa7164_work_cmdhandler(struct work_struct *w) 502static void saa7164_work_cmdhandler(struct work_struct *w)
444{ 503{
445 struct saa7164_dev *dev = container_of(w, struct saa7164_dev, workcmd); 504 struct saa7164_dev *dev = container_of(w, struct saa7164_dev, workcmd);
@@ -458,6 +517,31 @@ static void saa7164_buffer_deliver(struct saa7164_buffer *buf)
458 517
459} 518}
460 519
520static irqreturn_t saa7164_irq_vbi(struct saa7164_port *port)
521{
522 struct saa7164_dev *dev = port->dev;
523
524 /* Store old time */
525 port->last_irq_msecs_diff = port->last_irq_msecs;
526
527 /* Collect new stats */
528 port->last_irq_msecs = jiffies_to_msecs(jiffies);
529
530 /* Calculate stats */
531 port->last_irq_msecs_diff = port->last_irq_msecs -
532 port->last_irq_msecs_diff;
533
534 saa7164_histogram_update(&port->irq_interval,
535 port->last_irq_msecs_diff);
536
537 dprintk(DBGLVL_IRQ, "%s() %Ldms elapsed\n", __func__,
538 port->last_irq_msecs_diff);
539
540 /* Tis calls the vbi irq handler */
541 schedule_work(&port->workenc);
542 return 0;
543}
544
461static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port) 545static irqreturn_t saa7164_irq_encoder(struct saa7164_port *port)
462{ 546{
463 struct saa7164_dev *dev = port->dev; 547 struct saa7164_dev *dev = port->dev;
@@ -527,6 +611,8 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
527 struct saa7164_port *portb = &dev->ports[ SAA7164_PORT_TS2 ]; 611 struct saa7164_port *portb = &dev->ports[ SAA7164_PORT_TS2 ];
528 struct saa7164_port *portc = &dev->ports[ SAA7164_PORT_ENC1 ]; 612 struct saa7164_port *portc = &dev->ports[ SAA7164_PORT_ENC1 ];
529 struct saa7164_port *portd = &dev->ports[ SAA7164_PORT_ENC2 ]; 613 struct saa7164_port *portd = &dev->ports[ SAA7164_PORT_ENC2 ];
614 struct saa7164_port *porte = &dev->ports[ SAA7164_PORT_VBI1 ];
615 struct saa7164_port *portf = &dev->ports[ SAA7164_PORT_VBI2 ];
530 616
531 u32 intid, intstat[INT_SIZE/4]; 617 u32 intid, intstat[INT_SIZE/4];
532 int i, handled = 0, bit; 618 int i, handled = 0, bit;
@@ -590,9 +676,19 @@ static irqreturn_t saa7164_irq(int irq, void *dev_id)
590 676
591 } else if (intid == portd->hwcfg.interruptid) { 677 } else if (intid == portd->hwcfg.interruptid) {
592 678
593 /* Encoder path 1 */ 679 /* Encoder path 2 */
594 saa7164_irq_encoder(portd); 680 saa7164_irq_encoder(portd);
595 681
682 } else if (intid == porte->hwcfg.interruptid) {
683
684 /* VBI path 1 */
685 saa7164_irq_vbi(porte);
686
687 } else if (intid == portf->hwcfg.interruptid) {
688
689 /* VBI path 2 */
690 saa7164_irq_vbi(portf);
691
596 } else { 692 } else {
597 /* Find the function */ 693 /* Find the function */
598 dprintk(DBGLVL_IRQ, 694 dprintk(DBGLVL_IRQ,
@@ -830,9 +926,19 @@ static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
830 if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2)) 926 if ((portnr == SAA7164_PORT_TS1) || (portnr == SAA7164_PORT_TS2))
831 port->type = SAA7164_MPEG_DVB; 927 port->type = SAA7164_MPEG_DVB;
832 else 928 else
833 if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2)) 929 if ((portnr == SAA7164_PORT_ENC1) || (portnr == SAA7164_PORT_ENC2)) {
834 port->type = SAA7164_MPEG_ENCODER; 930 port->type = SAA7164_MPEG_ENCODER;
931
932 /* We need a deferred interrupt handler for cmd handling */
933 INIT_WORK(&port->workenc, saa7164_work_enchandler);
934 }
835 else 935 else
936 if ((portnr == SAA7164_PORT_VBI1) || (portnr == SAA7164_PORT_VBI2)) {
937 port->type = SAA7164_MPEG_VBI;
938
939 /* We need a deferred interrupt handler for cmd handling */
940 INIT_WORK(&port->workenc, saa7164_work_vbihandler);
941 } else
836 BUG(); 942 BUG();
837 943
838 /* Init all the critical resources */ 944 /* Init all the critical resources */
@@ -844,17 +950,15 @@ static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
844 INIT_LIST_HEAD(&port->list_buf_free.list); 950 INIT_LIST_HEAD(&port->list_buf_free.list);
845 init_waitqueue_head(&port->wait_read); 951 init_waitqueue_head(&port->wait_read);
846 952
847 /* We need a deferred interrupt handler for cmd handling */
848 INIT_WORK(&port->workenc, saa7164_work_enchandler);
849 953
850 saa7164_histogram_reset(&port->irq_interval, "irq intervals"); 954 saa7164_histogram_reset(&port->irq_interval, "irq intervals");
851 saa7164_histogram_reset(&port->svc_interval, "deferred intervals"); 955 saa7164_histogram_reset(&port->svc_interval, "deferred intervals");
852 saa7164_histogram_reset(&port->irq_svc_interval, 956 saa7164_histogram_reset(&port->irq_svc_interval,
853 "irq to deferred intervals"); 957 "irq to deferred intervals");
854 saa7164_histogram_reset(&port->read_interval, 958 saa7164_histogram_reset(&port->read_interval,
855 "encoder read() intervals"); 959 "encoder/vbi read() intervals");
856 saa7164_histogram_reset(&port->poll_interval, 960 saa7164_histogram_reset(&port->poll_interval,
857 "encoder poll() intervals"); 961 "encoder/vbi poll() intervals");
858 962
859 return 0; 963 return 0;
860} 964}
@@ -905,6 +1009,8 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
905 saa7164_port_init(dev, SAA7164_PORT_TS2); 1009 saa7164_port_init(dev, SAA7164_PORT_TS2);
906 saa7164_port_init(dev, SAA7164_PORT_ENC1); 1010 saa7164_port_init(dev, SAA7164_PORT_ENC1);
907 saa7164_port_init(dev, SAA7164_PORT_ENC2); 1011 saa7164_port_init(dev, SAA7164_PORT_ENC2);
1012 saa7164_port_init(dev, SAA7164_PORT_VBI1);
1013 saa7164_port_init(dev, SAA7164_PORT_VBI2);
908 1014
909 if (get_resources(dev) < 0) { 1015 if (get_resources(dev) < 0) {
910 printk(KERN_ERR "CORE %s No more PCIe resources for " 1016 printk(KERN_ERR "CORE %s No more PCIe resources for "
@@ -1107,6 +1213,21 @@ static int __devinit saa7164_initdev(struct pci_dev *pci_dev,
1107 } 1213 }
1108 } 1214 }
1109 1215
1216 if (saa7164_boards[dev->board].porte == SAA7164_MPEG_VBI) {
1217 if (saa7164_vbi_register(&dev->ports[ SAA7164_PORT_VBI1 ]) < 0) {
1218 printk(KERN_ERR"%s() Failed to register "
1219 "vbi device\n", __func__);
1220 }
1221 }
1222
1223 if (saa7164_boards[dev->board].portf == SAA7164_MPEG_VBI) {
1224 if (saa7164_vbi_register(&dev->ports[ SAA7164_PORT_VBI2 ]) < 0) {
1225 printk(KERN_ERR"%s() Failed to register "
1226 "vbi device\n", __func__);
1227 }
1228 }
1229
1230
1110 } /* != BOARD_UNKNOWN */ 1231 } /* != BOARD_UNKNOWN */
1111 else 1232 else
1112 printk(KERN_ERR "%s() Unsupported board detected, " 1233 printk(KERN_ERR "%s() Unsupported board detected, "
@@ -1144,6 +1265,10 @@ static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
1144 &dev->ports[ SAA7164_PORT_ENC1 ].read_interval); 1265 &dev->ports[ SAA7164_PORT_ENC1 ].read_interval);
1145 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ], 1266 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_ENC1 ],
1146 &dev->ports[ SAA7164_PORT_ENC1 ].poll_interval); 1267 &dev->ports[ SAA7164_PORT_ENC1 ].poll_interval);
1268 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_VBI1 ],
1269 &dev->ports[ SAA7164_PORT_VBI1 ].read_interval);
1270 saa7164_histogram_print(&dev->ports[ SAA7164_PORT_VBI2 ],
1271 &dev->ports[ SAA7164_PORT_VBI2 ].poll_interval);
1147 1272
1148 saa7164_shutdown(dev); 1273 saa7164_shutdown(dev);
1149 1274
@@ -1159,6 +1284,12 @@ static void __devexit saa7164_finidev(struct pci_dev *pci_dev)
1159 if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER) 1284 if (saa7164_boards[dev->board].portd == SAA7164_MPEG_ENCODER)
1160 saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC2 ]); 1285 saa7164_encoder_unregister(&dev->ports[ SAA7164_PORT_ENC2 ]);
1161 1286
1287 if (saa7164_boards[dev->board].porte == SAA7164_MPEG_VBI)
1288 saa7164_vbi_unregister(&dev->ports[ SAA7164_PORT_VBI1 ]);
1289
1290 if (saa7164_boards[dev->board].portf == SAA7164_MPEG_VBI)
1291 saa7164_vbi_unregister(&dev->ports[ SAA7164_PORT_VBI2 ]);
1292
1162 saa7164_i2c_unregister(&dev->i2c_bus[0]); 1293 saa7164_i2c_unregister(&dev->i2c_bus[0]);
1163 saa7164_i2c_unregister(&dev->i2c_bus[1]); 1294 saa7164_i2c_unregister(&dev->i2c_bus[1]);
1164 saa7164_i2c_unregister(&dev->i2c_bus[2]); 1295 saa7164_i2c_unregister(&dev->i2c_bus[2]);
diff --git a/drivers/media/video/saa7164/saa7164-reg.h b/drivers/media/video/saa7164/saa7164-reg.h
index 33da55c21c91..b950f41c5c5e 100644
--- a/drivers/media/video/saa7164/saa7164-reg.h
+++ b/drivers/media/video/saa7164/saa7164-reg.h
@@ -156,6 +156,8 @@
156#define EXU_INTERRUPT_CONTROL 0x03 156#define EXU_INTERRUPT_CONTROL 0x03
157 157
158/* State Transition and args */ 158/* State Transition and args */
159#define SAA_PROBE_CONTROL 0x01
160#define SAA_COMMIT_CONTROL 0x02
159#define SAA_STATE_CONTROL 0x03 161#define SAA_STATE_CONTROL 0x03
160#define SAA_DMASTATE_STOP 0x00 162#define SAA_DMASTATE_STOP 0x00
161#define SAA_DMASTATE_ACQUIRE 0x01 163#define SAA_DMASTATE_ACQUIRE 0x01
diff --git a/drivers/media/video/saa7164/saa7164-types.h b/drivers/media/video/saa7164/saa7164-types.h
index dacd9ce1d419..cb051d5d138c 100644
--- a/drivers/media/video/saa7164/saa7164-types.h
+++ b/drivers/media/video/saa7164/saa7164-types.h
@@ -414,3 +414,23 @@ typedef struct
414 u8 bPackDataType; 414 u8 bPackDataType;
415} __attribute__((packed)) tmComResPSFormatDescrHeader_t; 415} __attribute__((packed)) tmComResPSFormatDescrHeader_t;
416 416
417/* VBI control structure */
418typedef struct
419{
420 u8 len;
421 u8 type;
422 u8 subtype; /* VS_FORMAT_VBI */
423 u8 bFormatIndex;
424 u32 VideoStandard; /* See KS_AnalogVideoStandard, NTSC = 1 */
425 u8 StartLine; /* NTSC Start = 10 */
426 u8 EndLine; /* NTSC = 21 */
427 u8 FieldRate; /* 60 for NTSC */
428 u8 bNumLines; /* Unsed - scheduled for removal */
429} __attribute__((packed)) tmComResVBIFormatDescrHeader_t;
430
431typedef struct
432{
433 u16 bmHint;
434 u8 bFormatIndex;
435 u8 bFrameIndex;
436} __attribute__((packed)) tmComResProbeCommit_t;
diff --git a/drivers/media/video/saa7164/saa7164.h b/drivers/media/video/saa7164/saa7164.h
index c1b82bb2a359..82ff561a29f7 100644
--- a/drivers/media/video/saa7164/saa7164.h
+++ b/drivers/media/video/saa7164/saa7164.h
@@ -88,13 +88,16 @@
88#define SAA7164_PS_NUMBER_OF_LINES 256 88#define SAA7164_PS_NUMBER_OF_LINES 256
89#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */ 89#define SAA7164_PT_ENTRIES 16 /* (312 * 188) / 4096 */
90#define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */ 90#define SAA7164_MAX_ENCODER_BUFFERS 64 /* max 5secs of latency at 6Mbps */
91#define SAA7164_MAX_VBI_BUFFERS 64
91 92
92/* Port related defines */ 93/* Port related defines */
93#define SAA7164_PORT_TS1 (0) 94#define SAA7164_PORT_TS1 (0)
94#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1) 95#define SAA7164_PORT_TS2 (SAA7164_PORT_TS1 + 1)
95#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1) 96#define SAA7164_PORT_ENC1 (SAA7164_PORT_TS2 + 1)
96#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1) 97#define SAA7164_PORT_ENC2 (SAA7164_PORT_ENC1 + 1)
97#define SAA7164_MAX_PORTS (SAA7164_PORT_ENC2 + 1) 98#define SAA7164_PORT_VBI1 (SAA7164_PORT_ENC2 + 1)
99#define SAA7164_PORT_VBI2 (SAA7164_PORT_VBI1 + 1)
100#define SAA7164_MAX_PORTS (SAA7164_PORT_VBI2 + 1)
98 101
99#define DBGLVL_FW 4 102#define DBGLVL_FW 4
100#define DBGLVL_DVB 8 103#define DBGLVL_DVB 8
@@ -105,6 +108,7 @@
105#define DBGLVL_IRQ 256 108#define DBGLVL_IRQ 256
106#define DBGLVL_BUF 512 109#define DBGLVL_BUF 512
107#define DBGLVL_ENC 1024 110#define DBGLVL_ENC 1024
111#define DBGLVL_VBI 2048
108 112
109#define SAA7164_NORMS ( V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 ) 113#define SAA7164_NORMS ( V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 )
110 114
@@ -112,6 +116,7 @@ enum port_t {
112 SAA7164_MPEG_UNDEFINED = 0, 116 SAA7164_MPEG_UNDEFINED = 0,
113 SAA7164_MPEG_DVB, 117 SAA7164_MPEG_DVB,
114 SAA7164_MPEG_ENCODER, 118 SAA7164_MPEG_ENCODER,
119 SAA7164_MPEG_VBI,
115}; 120};
116 121
117enum saa7164_i2c_bus_nr { 122enum saa7164_i2c_bus_nr {
@@ -156,7 +161,8 @@ struct saa7164_unit {
156 161
157struct saa7164_board { 162struct saa7164_board {
158 char *name; 163 char *name;
159 enum port_t porta, portb, portc, portd; 164 enum port_t porta, portb, portc,
165 portd, porte, portf;
160 enum { 166 enum {
161 SAA7164_CHIP_UNDEFINED = 0, 167 SAA7164_CHIP_UNDEFINED = 0,
162 SAA7164_CHIP_REV2, 168 SAA7164_CHIP_REV2,
@@ -173,8 +179,15 @@ struct saa7164_subid {
173 179
174struct saa7164_encoder_fh { 180struct saa7164_encoder_fh {
175 struct saa7164_port *port; 181 struct saa7164_port *port;
176 u32 freq; 182// u32 freq;
177 u32 tuner_type; 183// u32 tuner_type;
184 atomic_t v4l_reading;
185};
186
187struct saa7164_vbi_fh {
188 struct saa7164_port *port;
189// u32 freq;
190// u32 tuner_type;
178 atomic_t v4l_reading; 191 atomic_t v4l_reading;
179}; 192};
180 193
@@ -270,6 +283,23 @@ struct saa7164_encoder_params {
270 u32 gop_size; 283 u32 gop_size;
271}; 284};
272 285
286struct saa7164_vbi_params {
287 struct saa7164_tvnorm encodernorm;
288 u32 height;
289 u32 width;
290 u32 is_50hz;
291 u32 bitrate; /* bps */
292 u32 bitrate_peak; /* bps */
293 u32 bitrate_mode;
294 u32 stream_type; /* V4L2_MPEG_STREAM_TYPE_MPEG2_TS */
295
296 u32 audio_sampling_freq;
297 u32 ctl_mute;
298 u32 ctl_aspect;
299 u32 refdist;
300 u32 gop_size;
301};
302
273struct saa7164_port; 303struct saa7164_port;
274 304
275struct saa7164_buffer { 305struct saa7164_buffer {
@@ -374,7 +404,7 @@ struct saa7164_port {
374 404
375 struct work_struct workenc; 405 struct work_struct workenc;
376 406
377 /* V4L */ 407 /* V4L Encoder Video */
378 struct saa7164_encoder_params encoder_params; 408 struct saa7164_encoder_params encoder_params;
379 struct video_device *v4l_device; 409 struct video_device *v4l_device;
380 atomic_t v4l_reader_count; 410 atomic_t v4l_reader_count;
@@ -383,6 +413,10 @@ struct saa7164_port {
383 struct saa7164_buffer list_buf_free; 413 struct saa7164_buffer list_buf_free;
384 wait_queue_head_t wait_read; 414 wait_queue_head_t wait_read;
385 415
416 /* V4L VBI */
417 tmComResVBIFormatDescrHeader_t vbi_fmt_ntsc;
418 struct saa7164_vbi_params vbi_params;
419
386 /* Debug */ 420 /* Debug */
387 u32 sync_errors; 421 u32 sync_errors;
388 u32 v_cc_errors; 422 u32 v_cc_errors;
@@ -442,6 +476,7 @@ struct saa7164_dev {
442extern struct list_head saa7164_devlist; 476extern struct list_head saa7164_devlist;
443extern unsigned int waitsecs; 477extern unsigned int waitsecs;
444extern unsigned int encoder_buffers; 478extern unsigned int encoder_buffers;
479extern unsigned int vbi_buffers;
445 480
446/* ----------------------------------------------------------- */ 481/* ----------------------------------------------------------- */
447/* saa7164-core.c */ 482/* saa7164-core.c */
@@ -505,6 +540,7 @@ int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
505int saa7164_api_set_audio_std(struct saa7164_port *port); 540int saa7164_api_set_audio_std(struct saa7164_port *port);
506int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect); 541int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
507int saa7164_api_get_videomux(struct saa7164_port *port); 542int saa7164_api_get_videomux(struct saa7164_port *port);
543int saa7164_api_set_vbi_format(struct saa7164_port *port);
508 544
509/* ----------------------------------------------------------- */ 545/* ----------------------------------------------------------- */
510/* saa7164-cards.c */ 546/* saa7164-cards.c */
@@ -546,6 +582,11 @@ int saa7164_encoder_register(struct saa7164_port *port);
546void saa7164_encoder_unregister(struct saa7164_port *port); 582void saa7164_encoder_unregister(struct saa7164_port *port);
547 583
548/* ----------------------------------------------------------- */ 584/* ----------------------------------------------------------- */
585/* saa7164-vbi.c */
586int saa7164_vbi_register(struct saa7164_port *port);
587void saa7164_vbi_unregister(struct saa7164_port *port);
588
589/* ----------------------------------------------------------- */
549 590
550extern unsigned int crc_checking; 591extern unsigned int crc_checking;
551 592