1 /*****************************************************************************
7 *****************************************************************************/
10 * Copyright (C) 2010 R.M. Thomas <rmthomas@sciolus.org>
13 * This is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * The software is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this software; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 /*****************************************************************************/
30 * ACKNOWLEGEMENTS AND REFERENCES
31 * ------------------------------
32 * This driver makes use of register information contained in the Syntek
33 * Semicon DC-1125 driver hosted at
34 * http://sourceforge.net/projects/syntekdriver/.
35 * Particularly useful has been a patch to the latter driver provided by
36 * Ivor Hewitt in January 2009. The NTSC implementation is taken from the
39 /****************************************************************************/
41 #include "easycap_debug.h"
44 /*--------------------------------------------------------------------------*/
45 const struct stk1160config { int reg; int set; } stk1160config[256] = {
65 #if defined(PREFER_NTSC)
68 #if defined(OLDMARGIN)
78 #if defined(OLDMARGIN)
88 #else /* ! PREFER_NTSC*/
90 #if defined(OLDMARGIN)
100 #if defined(OLDMARGIN)
110 #endif /* ! PREFER_NTSC*/
115 /*---------------------------------------------------------------------------*/
118 /*--------------------------------------------------------------------------*/
119 const struct saa7113config { int reg; int set; } saa7113config[256] = {
127 #if defined(PREFER_NTSC)
131 #endif /* ! PREFER_NTSC*/
133 {0x0A, SAA_0A_DEFAULT},
134 {0x0B, SAA_0B_DEFAULT},
135 {0x0C, SAA_0C_DEFAULT},
136 {0x0D, SAA_0D_DEFAULT},
145 #if defined(PREFER_NTSC)
149 #endif /* ! PREFER_NTSC*/
175 #if defined(PREFER_NTSC)
179 #endif /* ! PREFER_NTSC*/
183 /*--------------------------------------------------------------------------*/
185 /****************************************************************************/
187 confirm_resolution(struct usb_device *p)
189 __u8 get0, get1, get2, get3, get4, get5, get6, get7;
190 GET(p, 0x0110, &get0);
191 GET(p, 0x0111, &get1);
192 GET(p, 0x0112, &get2);
193 GET(p, 0x0113, &get3);
194 GET(p, 0x0114, &get4);
195 GET(p, 0x0115, &get5);
196 GET(p, 0x0116, &get6);
197 GET(p, 0x0117, &get7);
198 JOT(8, "0x%03X, 0x%03X, " \
201 "0x%03X, 0x%03X\n", \
202 get0, get1, get2, get3, get4, get5, get6, get7);
203 JOT(8, "....cf PAL_720x526: " \
207 "0x%03X, 0x%03X\n", \
208 0x000, 0x000, 0x001, 0x000, 0x5A0, 0x005, 0x121, 0x001);
209 JOT(8, "....cf PAL_704x526: " \
213 "0x%03X, 0x%03X\n", \
214 0x004, 0x000, 0x001, 0x000, 0x584, 0x005, 0x121, 0x001);
215 JOT(8, "....cf VGA_640x480: " \
219 "0x%03X, 0x%03X\n", \
220 0x008, 0x000, 0x020, 0x000, 0x508, 0x005, 0x110, 0x001);
223 /****************************************************************************/
225 confirm_stream(struct usb_device *p)
230 GET(p, 0x0100, &igot); get2 = 0x80 & igot;
232 JOT(8, "confirm_stream: OK\n");
234 JOT(8, "confirm_stream: STUCK\n");
237 /****************************************************************************/
239 setup_stk(struct usb_device *p)
244 while (0xFFF != stk1160config[i0].reg) {
245 SET(p, stk1160config[i0].reg, stk1160config[i0].set);
253 /****************************************************************************/
255 setup_saa(struct usb_device *p)
264 while (0xFF != saa7113config[i0].reg) {
265 ir = write_saa(p, saa7113config[i0].reg, saa7113config[i0].set);
270 /****************************************************************************/
272 write_000(struct usb_device *p, __u16 set2, __u16 set0)
276 GET(p, 0x0002, &igot2);
277 GET(p, 0x0000, &igot0);
278 SET(p, 0x0002, set2);
279 SET(p, 0x0000, set0);
282 /****************************************************************************/
284 write_saa(struct usb_device *p, __u16 reg0, __u16 set0)
292 /****************************************************************************/
293 /*--------------------------------------------------------------------------*/
295 * REGISTER 500: SETTING VALUE TO 0x008B READS FROM VT1612A (?)
296 * REGISTER 500: SETTING VALUE TO 0x008C WRITES TO VT1612A
297 * REGISTER 502: LEAST SIGNIFICANT BYTE OF VALUE TO SET
298 * REGISTER 503: MOST SIGNIFICANT BYTE OF VALUE TO SET
299 * REGISTER 504: TARGET ADDRESS ON VT1612A
301 /*--------------------------------------------------------------------------*/
303 write_vt(struct usb_device *p, __u16 reg0, __u16 set0)
306 __u16 got502, got503;
307 __u16 set502, set503;
309 SET(p, 0x0504, reg0);
310 SET(p, 0x0500, 0x008B);
312 GET(p, 0x0502, &igot); got502 = (0xFF & igot);
313 GET(p, 0x0503, &igot); got503 = (0xFF & igot);
315 JOT(16, "write_vt(., 0x%04X, 0x%04X): was 0x%04X\n", \
316 reg0, set0, ((got503 << 8) | got502));
318 set502 = (0x00FF & set0);
319 set503 = ((0xFF00 & set0) >> 8);
321 SET(p, 0x0504, reg0);
322 SET(p, 0x0502, set502);
323 SET(p, 0x0503, set503);
324 SET(p, 0x0500, 0x008C);
328 /****************************************************************************/
329 /*--------------------------------------------------------------------------*/
331 * REGISTER 500: SETTING VALUE TO 0x008B READS FROM VT1612A (?)
332 * REGISTER 500: SETTING VALUE TO 0x008C WRITES TO VT1612A
333 * REGISTER 502: LEAST SIGNIFICANT BYTE OF VALUE TO GET
334 * REGISTER 503: MOST SIGNIFICANT BYTE OF VALUE TO GET
335 * REGISTER 504: TARGET ADDRESS ON VT1612A
337 /*--------------------------------------------------------------------------*/
339 read_vt(struct usb_device *p, __u16 reg0)
342 __u16 got502, got503;
344 SET(p, 0x0504, reg0);
345 SET(p, 0x0500, 0x008B);
347 GET(p, 0x0502, &igot); got502 = (0xFF & igot);
348 GET(p, 0x0503, &igot); got503 = (0xFF & igot);
350 JOT(16, "read_vt(., 0x%04X): has 0x%04X\n", reg0, ((got503 << 8) | got502));
352 return (got503 << 8) | got502;
354 /****************************************************************************/
355 /*--------------------------------------------------------------------------*/
357 * THESE APPEAR TO HAVE NO EFFECT ON EITHER VIDEO OR AUDIO.
359 /*--------------------------------------------------------------------------*/
361 write_300(struct usb_device *p)
363 SET(p, 0x300, 0x0012);
364 SET(p, 0x350, 0x002D);
365 SET(p, 0x351, 0x0001);
366 SET(p, 0x352, 0x0000);
367 SET(p, 0x353, 0x0000);
368 SET(p, 0x300, 0x0080);
371 /****************************************************************************/
372 /*--------------------------------------------------------------------------*/
374 * NOTE: THE FOLLOWING IS NOT CHECKED:
375 * REGISTER 0x0F, WHICH IS INVOLVED IN CHROMINANCE AUTOMATIC GAIN CONTROL.
377 /*--------------------------------------------------------------------------*/
379 check_saa(struct usb_device *p)
385 while (0xFF != saa7113config[i0].reg) {
386 if (0x0F == saa7113config[i0].reg) {
390 ir = read_saa(p, saa7113config[i0].reg);
391 if (ir != saa7113config[i0].set) {
392 SAY("SAA register 0x%02X has 0x%02X, expected 0x%02X\n", \
393 saa7113config[i0].reg, ir, saa7113config[i0].set);
403 /****************************************************************************/
405 merit_saa(struct usb_device *p)
409 rc = read_saa(p, 0x1F);
410 if ((0 > rc) || (0x02 & rc))
415 /****************************************************************************/
417 ready_saa(struct usb_device *p)
424 rc = read_saa(p, 0x1F);
426 if ((1 == (0x01 & rc))&&(0 == (0x40 & rc)))
435 JOT(8, "hardware detects 60 Hz\n");
437 JOT(8, "hardware detects 50 Hz\n");
439 JOT(8, "hardware detects interlacing\n");
441 JOT(8, "hardware detects no interlacing\n");
445 /****************************************************************************/
446 /*--------------------------------------------------------------------------*/
448 * NOTE: THE FOLLOWING ARE NOT CHECKED:
449 * REGISTERS 0x000, 0x002: FUNCTIONALITY IS NOT KNOWN
450 * REGISTER 0x100: ACCEPT ALSO (0x80 | stk1160config[.].set)
452 /*--------------------------------------------------------------------------*/
454 check_stk(struct usb_device *p)
458 while (0xFFF != stk1160config[i0].reg) {
459 if (0x000 == stk1160config[i0].reg) {
462 if (0x002 == stk1160config[i0].reg) {
466 ir = read_stk(p, stk1160config[i0].reg);
468 if (0x100 == stk1160config[i0].reg) {
469 if ((ir != (0xFF & stk1160config[i0].set)) && \
470 (ir != (0x80 | (0xFF & stk1160config[i0].set))) && \
471 (0xFFFF != stk1160config[i0].set)) {
472 SAY("STK register 0x%03X has 0x%02X, " \
473 "expected 0x%02X\n", \
474 stk1160config[i0].reg, ir, \
475 stk1160config[i0].set);
480 if ((ir != (0xFF & stk1160config[i0].set)) && \
481 (0xFFFF != stk1160config[i0].set)) {
482 SAY("STK register 0x%03X has 0x%02X, " \
483 "expected 0x%02X\n", \
484 stk1160config[i0].reg, ir, \
485 stk1160config[i0].set);
491 /****************************************************************************/
493 read_saa(struct usb_device *p, __u16 reg0)
499 if (0 != wait_i2c(p))
502 GET(p, 0x0209, &igot);
505 /****************************************************************************/
507 read_stk(struct usb_device *p, __u32 reg0)
515 /*****************************************************************************/
516 /*---------------------------------------------------------------------------*/
518 * HARDWARE USERSPACE INPUT NUMBER PHYSICAL INPUT DRIVER input VALUE
520 * CVBS+S-VIDEO 0 or 1 CVBS 1
521 * FOUR-CVBS 0 or 1 CVBS1 1
522 * FOUR-CVBS 2 CVBS2 2
523 * FOUR-CVBS 3 CVBS3 3
524 * FOUR-CVBS 4 CVBS4 4
525 * CVBS+S-VIDEO 5 S-VIDEO 5
527 * WHEN 5==input THE ARGUMENT mode MUST ALSO BE SUPPLIED:
529 * mode 7 => GAIN TO BE SET EXPLICITLY USING REGISTER 0x05 (UNTESTED)
530 * mode 9 => USE AUTOMATIC GAIN CONTROL (DEFAULT)
533 /*---------------------------------------------------------------------------*/
535 select_input(struct usb_device *p, int input, int mode)
544 SET(p, 0x0000, 0x0098); break;
547 SET(p, 0x0000, 0x0090); break;
550 SET(p, 0x0000, 0x0088); break;
553 SET(p, 0x0000, 0x0080); break;
561 if (0 != write_saa(p, 0x02, 0x87)) {
562 SAY("ERROR: failed to set SAA " \
563 "register 0x02 for input " \
566 if (0 != write_saa(p, 0x05, 0xFF)) {
567 SAY("ERROR: failed to set SAA " \
568 "register 0x05 for input " \
575 if (0 != write_saa(p, 0x02, 0x89)) {
576 SAY("ERROR: failed to set SAA " \
577 "register 0x02 for input " \
580 if (0 != write_saa(p, 0x05, 0x00)) {
581 SAY("ERROR: failed to set SAA " \
582 "register 0x05 for input " \
589 SAY("MISTAKE: bad mode: %i\n", mode);
593 if (0 != write_saa(p, 0x04, 0x00)) {
594 SAY("ERROR: failed to set SAA register 0x04 " \
595 "for input %i\n", input);
597 if (0 != write_saa(p, 0x09, 0x80)) {
598 SAY("ERROR: failed to set SAA register 0x09 " \
599 "for input %i\n", input);
605 SAY("ERROR: bad input: %i\n", input);
610 SET(p, 0x0002, 0x0093);
617 /****************************************************************************/
619 set_resolution(struct usb_device *p, \
620 __u16 set0, __u16 set1, __u16 set2, __u16 set3)
622 __u16 u0x0111, u0x0113, u0x0115, u0x0117;
624 u0x0111 = ((0xFF00 & set0) >> 8);
625 u0x0113 = ((0xFF00 & set1) >> 8);
626 u0x0115 = ((0xFF00 & set2) >> 8);
627 u0x0117 = ((0xFF00 & set3) >> 8);
629 SET(p, 0x0110, (0x00FF & set0));
630 SET(p, 0x0111, u0x0111);
631 SET(p, 0x0112, (0x00FF & set1));
632 SET(p, 0x0113, u0x0113);
633 SET(p, 0x0114, (0x00FF & set2));
634 SET(p, 0x0115, u0x0115);
635 SET(p, 0x0116, (0x00FF & set3));
636 SET(p, 0x0117, u0x0117);
640 /****************************************************************************/
642 start_100(struct usb_device *p)
647 GET(p, 0x0100, &igot); get0 = igot;
649 SET(p, 0x0100, (0x80 | get0));
653 /****************************************************************************/
655 stop_100(struct usb_device *p)
660 GET(p, 0x0100, &igot); get0 = igot;
662 SET(p, 0x0100, (0x7F & get0));
666 /****************************************************************************/
667 /*--------------------------------------------------------------------------*/
669 * FUNCTION wait_i2c() RETURNS 0 ON SUCCESS
671 /*--------------------------------------------------------------------------*/
673 wait_i2c(struct usb_device *p)
680 for (k = 0; k < max; k++) {
681 GET(p, 0x0201, &igot); get0 = igot;
698 /****************************************************************************/
700 regset(struct usb_device *pusb_device, __u16 index, __u16 value)
709 rc0 = usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
711 (__u8)(USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE), \
718 #if defined(NOREADBACK)
721 rc1 = usb_control_msg(pusb_device, usb_rcvctrlpipe(pusb_device, 0), \
723 (__u8)(USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE), \
727 (__u16)sizeof(__u16), \
745 JOT(8, "unexpected 0x%02X for STK register 0x%03X\n", \
752 if ((0xFF & value) != igot) {
753 JOT(8, "unexpected 0x%02X != 0x%02X " \
754 "for STK register 0x%03X\n", \
765 JOT(8, "unexpected 0x%02X != 0x%02X " \
766 "for STK register 0x%03X\n", \
772 #endif /* ! NOREADBACK*/
774 return (0 > rc0) ? rc0 : rc1;
776 /*****************************************************************************/
778 regget(struct usb_device *pusb_device, __u16 index, void *pvoid)
785 ir = usb_control_msg(pusb_device, usb_rcvctrlpipe(pusb_device, 0), \
787 (__u8)(USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE), \
795 /*****************************************************************************/
797 wakeup_device(struct usb_device *pusb_device)
799 return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
800 (__u8)USB_REQ_SET_FEATURE, \
801 (__u8)(USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE), \
802 USB_DEVICE_REMOTE_WAKEUP, \
808 /*****************************************************************************/
809 /*---------------------------------------------------------------------------*/
812 * THE MESSAGE OF TYPE (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE)
813 * CAUSES MUTING IF THE VALUE 0x0100 IS SENT.
814 * TO ENABLE AUDIO THE VALUE 0x0200 MUST BE SENT.
816 /*---------------------------------------------------------------------------*/
818 audio_setup(struct easycap *peasycap)
820 struct usb_device *pusb_device;
821 static __u8 request = 0x01;
822 static __u8 requesttype = \
823 (__u8)(USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE);
825 static __u16 value_unmute = 0x0200;
826 static __u16 index = 0x0301;
828 static unsigned char buffer[1];
829 static __u16 length = 1;
832 if (NULL == peasycap)
835 pusb_device = peasycap->pusb_device;
836 if (NULL == pusb_device)
839 JOT(8, "%02X %02X %02X %02X %02X %02X %02X %02X\n", \
840 requesttype, request, \
841 (0x00FF & value_unmute), \
842 (0xFF00 & value_unmute) >> 8, \
844 (0xFF00 & index) >> 8, \
846 (0xFF00 & length) >> 8);
850 rc = usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
853 (__u16)value_unmute, \
855 (void *)&buffer[0], \
859 JOT(8, "0x%02X=buffer\n", *((__u8 *) &buffer[0]));
860 if (rc != (int)length)
861 SAY("ERROR: usb_control_msg returned %i\n", rc);
863 /*--------------------------------------------------------------------------*/
865 * REGISTER 500: SETTING VALUE TO 0x0094 RESETS AUDIO CONFIGURATION ???
866 * REGISTER 506: ANALOGUE AUDIO ATTENTUATOR ???
867 * FOR THE CVBS+S-VIDEO HARDWARE:
868 * SETTING VALUE TO 0x0000 GIVES QUIET SOUND.
869 * THE UPPER BYTE SEEMS TO HAVE NO EFFECT.
870 * FOR THE FOUR-CVBS HARDWARE:
871 * SETTING VALUE TO 0x0000 SEEMS TO HAVE NO EFFECT.
872 * REGISTER 507: ANALOGUE AUDIO PREAMPLIFIER ON/OFF ???
873 * FOR THE CVBS-S-VIDEO HARDWARE:
874 * SETTING VALUE TO 0x0001 GIVES VERY LOUD, DISTORTED SOUND.
875 * THE UPPER BYTE SEEMS TO HAVE NO EFFECT.
877 /*--------------------------------------------------------------------------*/
879 SET(pusb_device, 0x0500, 0x0094);
881 SET(pusb_device, 0x0500, 0x008C);
883 SET(pusb_device, 0x0506, 0x0001);
884 SET(pusb_device, 0x0507, 0x0000);
886 id1 = read_vt(pusb_device, 0x007C);
887 id2 = read_vt(pusb_device, 0x007E);
888 SAY("0x%04X:0x%04X is audio vendor id\n", id1, id2);
890 /*---------------------------------------------------------------------------*/
892 * SELECT AUDIO SOURCE "LINE IN" AND SET DEFAULT GAIN TO 0 dB.
894 * THESE COMMANDS SEEM TO BE ACCEPTED (THOUGH POSSIBLY IGNORED) EVEN WHEN
895 * THERE IS NO SEPARATE AUDIO CHIP PRESENT.
897 /*---------------------------------------------------------------------------*/
899 write_vt(pusb_device, 0x0002, 0x8000);
900 write_vt(pusb_device, 0x001C, 0x8000);
902 write_vt(pusb_device, 0x000E, 0x0000);
903 write_vt(pusb_device, 0x0010, 0x0000);
904 write_vt(pusb_device, 0x0012, 0x8000);
905 write_vt(pusb_device, 0x0016, 0x0000);
907 write_vt(pusb_device, 0x001A, 0x0404);
908 write_vt(pusb_device, 0x0002, 0x0000);
909 write_vt(pusb_device, 0x001C, 0x0000);
911 check_vt(pusb_device);
915 /*****************************************************************************/
917 check_vt(struct usb_device *pusb_device)
921 igot = read_vt(pusb_device, 0x0002);
923 SAY("ERROR: failed to read VT1612A register 0x02\n");
925 SAY("register 0x%02X muted\n", 0x02);
927 igot = read_vt(pusb_device, 0x000E);
929 SAY("ERROR: failed to read VT1612A register 0x0E\n");
931 SAY("register 0x%02X muted\n", 0x0E);
933 igot = read_vt(pusb_device, 0x0010);
935 SAY("ERROR: failed to read VT1612A register 0x10\n");
937 SAY("register 0x%02X muted\n", 0x10);
939 igot = read_vt(pusb_device, 0x0012);
941 SAY("ERROR: failed to read VT1612A register 0x12\n");
943 SAY("register 0x%02X muted\n", 0x12);
945 igot = read_vt(pusb_device, 0x0016);
947 SAY("ERROR: failed to read VT1612A register 0x16\n");
949 SAY("register 0x%02X muted\n", 0x16);
951 igot = read_vt(pusb_device, 0x001A);
953 SAY("ERROR: failed to read VT1612A register 0x1A\n");
955 SAY("register 0x%02X muted\n", 0x1A);
957 igot = read_vt(pusb_device, 0x001C);
959 SAY("ERROR: failed to read VT1612A register 0x1C\n");
961 SAY("register 0x%02X muted\n", 0x1C);
965 /*****************************************************************************/
966 /*---------------------------------------------------------------------------*/
968 * NOTE: THIS DOES INCREASE THE VOLUME DRAMATICALLY:
969 * audio_gainset(pusb_device, 0x000F);
971 * IF 16<loud<31 VT1621A REGISTER 0x1C IS SET FOR POSITIVE GAIN.
972 * IF loud<=16 VT1621A REGISTER 0x1C IS SET FOR ZERO GAIN.
973 * THERE IS NEVER ANY (ADDITIONAL) ATTENUATION.
975 /*---------------------------------------------------------------------------*/
977 audio_gainset(struct usb_device *pusb_device, __s8 loud)
985 u8 = 0x000F & (__u8)(loud - 16);
987 write_vt(pusb_device, 0x0002, 0x8000);
989 igot = read_vt(pusb_device, 0x001C);
991 SAY("ERROR: failed to read VT1612A register 0x1C\n");
994 mute = 0x8000 & ((unsigned int)igot);
996 JOT(8, "0x%04X=(mute|u8|(u8<<8))\n", mute | u8 | (u8 << 8));
998 write_vt(pusb_device, 0x001C, 0x8000);
999 write_vt(pusb_device, 0x001C, (mute | u8 | (u8 << 8)));
1000 write_vt(pusb_device, 0x0002, 0x0000);
1004 /*****************************************************************************/
1006 audio_gainget(struct usb_device *pusb_device)
1010 igot = read_vt(pusb_device, 0x001C);
1012 SAY("ERROR: failed to read VT1612A register 0x1C\n");
1015 /*****************************************************************************/
1017 set2to78(struct usb_device *p)
1022 ir = regset(p, 0x0002, 0x0078);
1024 SAY("ERROR: failed to set register 0x0002 to 0x0078\n");
1028 /*****************************************************************************/
1030 set2to93(struct usb_device *p)
1035 ir = regset(p, 0x0002, 0x0093);
1037 SAY("ERROR: failed to set register 0x0002 to 0x0078\n");
1041 /*****************************************************************************/