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 /****************************************************************************/
44 #define GET(X, Y, Z) do { \
47 __rc = regget(X, Y, Z, sizeof(u8)); \
49 JOT(8, ":-(%i\n", __LINE__); return __rc; \
53 #define SET(X, Y, Z) do { \
55 __rc = regset(X, Y, Z); \
57 JOT(8, ":-(%i\n", __LINE__); return __rc; \
61 /*--------------------------------------------------------------------------*/
62 static const struct stk1160config
{
65 } stk1160configPAL
[] = {
85 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
89 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
98 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
106 /*--------------------------------------------------------------------------*/
107 static const struct stk1160config stk1160configNTSC
[] = {
127 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
131 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
140 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
148 /*--------------------------------------------------------------------------*/
149 static const struct saa7113config
{
152 } saa7113configPAL
[] = {
162 {0x0A, SAA_0A_DEFAULT
},
163 {0x0B, SAA_0B_DEFAULT
},
164 {0x0C, SAA_0C_DEFAULT
},
165 {0x0D, SAA_0D_DEFAULT
},
205 /*--------------------------------------------------------------------------*/
206 static const struct saa7113config saa7113configNTSC
[] = {
216 {0x0A, SAA_0A_DEFAULT
},
217 {0x0B, SAA_0B_DEFAULT
},
218 {0x0C, SAA_0C_DEFAULT
},
219 {0x0D, SAA_0D_DEFAULT
},
260 static int regget(struct usb_device
*pusb_device
,
261 u16 index
, void *reg
, int reg_size
)
268 rc
= usb_control_msg(pusb_device
, usb_rcvctrlpipe(pusb_device
, 0),
270 (USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
),
272 index
, reg
, reg_size
, 50000);
277 static int regset(struct usb_device
*pusb_device
, u16 index
, u16 value
)
284 rc
= usb_control_msg(pusb_device
, usb_sndctrlpipe(pusb_device
, 0),
286 (USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
),
287 value
, index
, NULL
, 0, 500);
292 if (easycap_readback
) {
294 rc
= regget(pusb_device
, index
, &igot
, sizeof(igot
));
311 JOT(8, "unexpected 0x%02X "
312 "for STK register 0x%03X\n",
317 if ((0xFF & value
) != igot
)
318 JOT(8, "unexpected 0x%02X != 0x%02X "
319 "for STK register 0x%03X\n",
327 /*--------------------------------------------------------------------------*/
329 * FUNCTION wait_i2c() RETURNS 0 ON SUCCESS
331 /*--------------------------------------------------------------------------*/
332 static int wait_i2c(struct usb_device
*p
)
342 for (k
= 0; k
< max
; k
++) {
343 GET(p
, 0x0201, &igot
); get0
= igot
;
358 /****************************************************************************/
359 int write_saa(struct usb_device
*p
, u16 reg0
, u16 set0
)
369 /****************************************************************************/
370 /*--------------------------------------------------------------------------*/
372 * REGISTER 500: SETTING VALUE TO 0x008B READS FROM VT1612A (?)
373 * REGISTER 500: SETTING VALUE TO 0x008C WRITES TO VT1612A
374 * REGISTER 502: LEAST SIGNIFICANT BYTE OF VALUE TO SET
375 * REGISTER 503: MOST SIGNIFICANT BYTE OF VALUE TO SET
376 * REGISTER 504: TARGET ADDRESS ON VT1612A
378 /*--------------------------------------------------------------------------*/
379 static int write_vt(struct usb_device
*p
, u16 reg0
, u16 set0
)
387 SET(p
, 0x0504, reg0
);
388 SET(p
, 0x0500, 0x008B);
390 GET(p
, 0x0502, &igot
); got502
= (0xFF & igot
);
391 GET(p
, 0x0503, &igot
); got503
= (0xFF & igot
);
393 JOT(16, "write_vt(., 0x%04X, 0x%04X): was 0x%04X\n",
394 reg0
, set0
, ((got503
<< 8) | got502
));
396 set502
= (0x00FF & set0
);
397 set503
= ((0xFF00 & set0
) >> 8);
399 SET(p
, 0x0504, reg0
);
400 SET(p
, 0x0502, set502
);
401 SET(p
, 0x0503, set503
);
402 SET(p
, 0x0500, 0x008C);
406 /****************************************************************************/
407 /*--------------------------------------------------------------------------*/
409 * REGISTER 500: SETTING VALUE TO 0x008B READS FROM VT1612A (?)
410 * REGISTER 500: SETTING VALUE TO 0x008C WRITES TO VT1612A
411 * REGISTER 502: LEAST SIGNIFICANT BYTE OF VALUE TO GET
412 * REGISTER 503: MOST SIGNIFICANT BYTE OF VALUE TO GET
413 * REGISTER 504: TARGET ADDRESS ON VT1612A
415 /*--------------------------------------------------------------------------*/
416 static int read_vt(struct usb_device
*p
, u16 reg0
)
423 SET(p
, 0x0504, reg0
);
424 SET(p
, 0x0500, 0x008B);
426 GET(p
, 0x0502, &igot
); got502
= (0xFF & igot
);
427 GET(p
, 0x0503, &igot
); got503
= (0xFF & igot
);
429 JOT(16, "read_vt(., 0x%04X): has 0x%04X\n",
430 reg0
, ((got503
<< 8) | got502
));
432 return (got503
<< 8) | got502
;
434 /****************************************************************************/
435 /*--------------------------------------------------------------------------*/
437 * THESE APPEAR TO HAVE NO EFFECT ON EITHER VIDEO OR AUDIO.
439 /*--------------------------------------------------------------------------*/
440 static int write_300(struct usb_device
*p
)
444 SET(p
, 0x300, 0x0012);
445 SET(p
, 0x350, 0x002D);
446 SET(p
, 0x351, 0x0001);
447 SET(p
, 0x352, 0x0000);
448 SET(p
, 0x353, 0x0000);
449 SET(p
, 0x300, 0x0080);
452 /****************************************************************************/
453 /****************************************************************************/
454 int setup_stk(struct usb_device
*p
, bool ntsc
)
457 const struct stk1160config
*cfg
;
460 cfg
= (ntsc
) ? stk1160configNTSC
: stk1160configPAL
;
461 for (i
= 0; cfg
[i
].reg
!= 0xFFF; i
++)
462 SET(p
, cfg
[i
].reg
, cfg
[i
].set
);
468 /****************************************************************************/
469 int setup_saa(struct usb_device
*p
, bool ntsc
)
472 const struct saa7113config
*cfg
;
475 cfg
= (ntsc
) ? saa7113configNTSC
: saa7113configPAL
;
476 for (i
= 0; cfg
[i
].reg
!= 0xFF; i
++) {
477 rc
= write_saa(p
, cfg
[i
].reg
, cfg
[i
].set
);
480 "Failed to set SAA register %d", cfg
[i
].reg
);
484 /****************************************************************************/
485 int merit_saa(struct usb_device
*p
)
491 rc
= read_saa(p
, 0x1F);
492 return ((0 > rc
) || (0x02 & rc
)) ? 1 : 0;
494 /****************************************************************************/
495 int ready_saa(struct usb_device
*p
)
498 const int max
= 5, marktime
= PATIENCE
/5;
499 /*--------------------------------------------------------------------------*/
501 * RETURNS 0 FOR INTERLACED 50 Hz
502 * 1 FOR NON-INTERLACED 50 Hz
503 * 2 FOR INTERLACED 60 Hz
504 * 3 FOR NON-INTERLACED 60 Hz
506 /*--------------------------------------------------------------------------*/
511 rc
= read_saa(p
, 0x1F);
513 if (0 == (0x40 & rc
))
515 if (1 == (0x01 & rc
))
527 JOT(8, "hardware detects 60 Hz\n");
530 JOT(8, "hardware detects 50 Hz\n");
533 JOT(8, "hardware detects interlacing\n");
536 JOT(8, "hardware detects no interlacing\n");
540 /****************************************************************************/
541 int read_saa(struct usb_device
*p
, u16 reg0
)
549 if (0 != wait_i2c(p
))
552 GET(p
, 0x0209, &igot
);
555 /****************************************************************************/
556 static int read_stk(struct usb_device
*p
, u32 reg0
)
566 int select_input(struct usb_device
*p
, int input
, int mode
)
576 if (0 != write_saa(p
, 0x02, 0x80))
577 SAY("ERROR: failed to set SAA register 0x02 "
578 "for input %i\n", input
);
580 SET(p
, 0x0000, 0x0098);
581 SET(p
, 0x0002, 0x0078);
585 if (0 != write_saa(p
, 0x02, 0x80))
586 SAY("ERROR: failed to set SAA register 0x02 "
587 "for input %i\n", input
);
589 SET(p
, 0x0000, 0x0090);
590 SET(p
, 0x0002, 0x0078);
594 if (0 != write_saa(p
, 0x02, 0x80))
595 SAY("ERROR: failed to set SAA register 0x02 "
596 " for input %i\n", input
);
598 SET(p
, 0x0000, 0x0088);
599 SET(p
, 0x0002, 0x0078);
603 if (0 != write_saa(p
, 0x02, 0x80)) {
604 SAY("ERROR: failed to set SAA register 0x02 "
605 "for input %i\n", input
);
607 SET(p
, 0x0000, 0x0080);
608 SET(p
, 0x0002, 0x0078);
616 if (0 != write_saa(p
, 0x02, 0x87))
617 SAY("ERROR: failed to set SAA register 0x02 "
618 "for input %i\n", input
);
620 if (0 != write_saa(p
, 0x05, 0xFF))
621 SAY("ERROR: failed to set SAA register 0x05 "
622 "for input %i\n", input
);
627 if (0 != write_saa(p
, 0x02, 0x89))
628 SAY("ERROR: failed to set SAA register 0x02 "
629 "for input %i\n", input
);
631 if (0 != write_saa(p
, 0x05, 0x00))
632 SAY("ERROR: failed to set SAA register 0x05 "
633 "for input %i\n", input
);
638 SAY("MISTAKE: bad mode: %i\n", mode
);
642 if (0 != write_saa(p
, 0x04, 0x00))
643 SAY("ERROR: failed to set SAA register 0x04 "
644 "for input %i\n", input
);
646 if (0 != write_saa(p
, 0x09, 0x80))
647 SAY("ERROR: failed to set SAA register 0x09 "
648 "for input %i\n", input
);
650 SET(p
, 0x0002, 0x0093);
654 SAY("ERROR: bad input: %i\n", input
);
658 ir
= read_stk(p
, 0x00);
659 JOT(8, "STK register 0x00 has 0x%02X\n", ir
);
660 ir
= read_saa(p
, 0x02);
661 JOT(8, "SAA register 0x02 has 0x%02X\n", ir
);
667 /****************************************************************************/
668 int set_resolution(struct usb_device
*p
,
669 u16 set0
, u16 set1
, u16 set2
, u16 set3
)
671 u16 u0x0111
, u0x0113
, u0x0115
, u0x0117
;
675 u0x0111
= ((0xFF00 & set0
) >> 8);
676 u0x0113
= ((0xFF00 & set1
) >> 8);
677 u0x0115
= ((0xFF00 & set2
) >> 8);
678 u0x0117
= ((0xFF00 & set3
) >> 8);
680 SET(p
, 0x0110, (0x00FF & set0
));
681 SET(p
, 0x0111, u0x0111
);
682 SET(p
, 0x0112, (0x00FF & set1
));
683 SET(p
, 0x0113, u0x0113
);
684 SET(p
, 0x0114, (0x00FF & set2
));
685 SET(p
, 0x0115, u0x0115
);
686 SET(p
, 0x0116, (0x00FF & set3
));
687 SET(p
, 0x0117, u0x0117
);
691 /****************************************************************************/
692 int start_100(struct usb_device
*p
)
694 u16 get116
, get117
, get0
;
695 u8 igot116
, igot117
, igot
;
699 GET(p
, 0x0116, &igot116
);
701 GET(p
, 0x0117, &igot117
);
703 SET(p
, 0x0116, 0x0000);
704 SET(p
, 0x0117, 0x0000);
706 GET(p
, 0x0100, &igot
);
708 SET(p
, 0x0100, (0x80 | get0
));
710 SET(p
, 0x0116, get116
);
711 SET(p
, 0x0117, get117
);
715 /****************************************************************************/
716 int stop_100(struct usb_device
*p
)
723 GET(p
, 0x0100, &igot
);
725 SET(p
, 0x0100, (0x7F & get0
));
728 /****************************************************************************/
729 /****************************************************************************/
730 /*****************************************************************************/
731 int easycap_wakeup_device(struct usb_device
*pusb_device
)
736 return usb_control_msg(pusb_device
, usb_sndctrlpipe(pusb_device
, 0),
738 USB_DIR_OUT
| USB_TYPE_STANDARD
| USB_RECIP_DEVICE
,
739 USB_DEVICE_REMOTE_WAKEUP
,
742 /*****************************************************************************/
743 int easycap_audio_setup(struct easycap
*peasycap
)
745 struct usb_device
*pusb_device
;
748 /*---------------------------------------------------------------------------*/
751 * THE MESSAGE OF TYPE (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE)
752 * CAUSES MUTING IF THE VALUE 0x0100 IS SENT.
753 * TO ENABLE AUDIO THE VALUE 0x0200 MUST BE SENT.
755 /*---------------------------------------------------------------------------*/
756 const u8 request
= 0x01;
757 const u8 requesttype
= USB_DIR_OUT
|
760 const u16 value_unmute
= 0x0200;
761 const u16 index
= 0x0301;
762 const u16 length
= 1;
767 pusb_device
= peasycap
->pusb_device
;
771 JOM(8, "%02X %02X %02X %02X %02X %02X %02X %02X\n",
772 requesttype
, request
,
773 (0x00FF & value_unmute
),
774 (0xFF00 & value_unmute
) >> 8,
776 (0xFF00 & index
) >> 8,
778 (0xFF00 & length
) >> 8);
782 rc
= usb_control_msg(pusb_device
, usb_sndctrlpipe(pusb_device
, 0),
783 request
, requesttype
, value_unmute
,
784 index
, &buffer
[0], length
, 50000);
786 JOT(8, "0x%02X=buffer\n", buffer
[0]);
787 if (rc
!= (int)length
) {
790 SAY("usb_control_msg returned -EPIPE\n");
793 SAY("ERROR: usb_control_msg returned %i\n", rc
);
797 /*--------------------------------------------------------------------------*/
799 * REGISTER 500: SETTING VALUE TO 0x0094 RESETS AUDIO CONFIGURATION ???
800 * REGISTER 506: ANALOGUE AUDIO ATTENTUATOR ???
801 * FOR THE CVBS+S-VIDEO HARDWARE:
802 * SETTING VALUE TO 0x0000 GIVES QUIET SOUND.
803 * THE UPPER BYTE SEEMS TO HAVE NO EFFECT.
804 * FOR THE FOUR-CVBS HARDWARE:
805 * SETTING VALUE TO 0x0000 SEEMS TO HAVE NO EFFECT.
806 * REGISTER 507: ANALOGUE AUDIO PREAMPLIFIER ON/OFF ???
807 * FOR THE CVBS-S-VIDEO HARDWARE:
808 * SETTING VALUE TO 0x0001 GIVES VERY LOUD, DISTORTED SOUND.
809 * THE UPPER BYTE SEEMS TO HAVE NO EFFECT.
811 /*--------------------------------------------------------------------------*/
812 SET(pusb_device
, 0x0500, 0x0094);
813 SET(pusb_device
, 0x0500, 0x008C);
814 SET(pusb_device
, 0x0506, 0x0001);
815 SET(pusb_device
, 0x0507, 0x0000);
816 id1
= read_vt(pusb_device
, 0x007C);
817 id2
= read_vt(pusb_device
, 0x007E);
818 SAM("0x%04X:0x%04X is audio vendor id\n", id1
, id2
);
819 /*---------------------------------------------------------------------------*/
821 * SELECT AUDIO SOURCE "LINE IN" AND SET THE AUDIO GAIN.
823 /*---------------------------------------------------------------------------*/
824 if (easycap_audio_gainset(pusb_device
, peasycap
->gain
))
825 SAY("ERROR: audio_gainset() failed\n");
826 check_vt(pusb_device
);
829 /*****************************************************************************/
830 int check_vt(struct usb_device
*pusb_device
)
836 igot
= read_vt(pusb_device
, 0x0002);
838 SAY("ERROR: failed to read VT1612A register 0x02\n");
840 SAY("register 0x%02X muted\n", 0x02);
842 igot
= read_vt(pusb_device
, 0x000E);
844 SAY("ERROR: failed to read VT1612A register 0x0E\n");
846 SAY("register 0x%02X muted\n", 0x0E);
848 igot
= read_vt(pusb_device
, 0x0010);
850 SAY("ERROR: failed to read VT1612A register 0x10\n");
852 SAY("register 0x%02X muted\n", 0x10);
854 igot
= read_vt(pusb_device
, 0x0012);
856 SAY("ERROR: failed to read VT1612A register 0x12\n");
858 SAY("register 0x%02X muted\n", 0x12);
860 igot
= read_vt(pusb_device
, 0x0014);
862 SAY("ERROR: failed to read VT1612A register 0x14\n");
864 SAY("register 0x%02X muted\n", 0x14);
866 igot
= read_vt(pusb_device
, 0x0016);
868 SAY("ERROR: failed to read VT1612A register 0x16\n");
870 SAY("register 0x%02X muted\n", 0x16);
872 igot
= read_vt(pusb_device
, 0x0018);
874 SAY("ERROR: failed to read VT1612A register 0x18\n");
876 SAY("register 0x%02X muted\n", 0x18);
878 igot
= read_vt(pusb_device
, 0x001C);
880 SAY("ERROR: failed to read VT1612A register 0x1C\n");
882 SAY("register 0x%02X muted\n", 0x1C);
886 /*****************************************************************************/
887 /*---------------------------------------------------------------------------*/
888 /* NOTE: THIS DOES INCREASE THE VOLUME DRAMATICALLY:
889 * audio_gainset(pusb_device, 0x000F);
891 * loud dB register 0x10 dB register 0x1C dB total
900 /*---------------------------------------------------------------------------*/
901 int easycap_audio_gainset(struct usb_device
*pusb_device
, s8 loud
)
914 write_vt(pusb_device
, 0x0002, 0x8000);
915 /*---------------------------------------------------------------------------*/
916 igot
= read_vt(pusb_device
, 0x000E);
918 SAY("ERROR: failed to read VT1612A register 0x0E\n");
921 mute
= 0x8000 & ((unsigned int)igot
);
925 tmp
= 0x01 | (0x001F & (((u8
)(15 - loud
)) << 1));
929 JOT(8, "0x%04X=(mute|tmp) for VT1612A register 0x0E\n", mute
| tmp
);
930 write_vt(pusb_device
, 0x000E, (mute
| tmp
));
931 /*---------------------------------------------------------------------------*/
932 igot
= read_vt(pusb_device
, 0x0010);
934 SAY("ERROR: failed to read VT1612A register 0x10\n");
937 mute
= 0x8000 & ((unsigned int)igot
);
940 JOT(8, "0x%04X=(mute|tmp|(tmp<<8)) for VT1612A register 0x10,...0x18\n",
941 mute
| tmp
| (tmp
<< 8));
942 write_vt(pusb_device
, 0x0010, (mute
| tmp
| (tmp
<< 8)));
943 write_vt(pusb_device
, 0x0012, (mute
| tmp
| (tmp
<< 8)));
944 write_vt(pusb_device
, 0x0014, (mute
| tmp
| (tmp
<< 8)));
945 write_vt(pusb_device
, 0x0016, (mute
| tmp
| (tmp
<< 8)));
946 write_vt(pusb_device
, 0x0018, (mute
| tmp
| (tmp
<< 8)));
947 /*---------------------------------------------------------------------------*/
948 igot
= read_vt(pusb_device
, 0x001C);
950 SAY("ERROR: failed to read VT1612A register 0x1C\n");
953 mute
= 0x8000 & ((unsigned int)igot
);
957 tmp
= 0x000F & (u8
)(loud
- 16);
961 JOT(8, "0x%04X=(mute|tmp|(tmp<<8)) for VT1612A register 0x1C\n",
962 mute
| tmp
| (tmp
<< 8));
963 write_vt(pusb_device
, 0x001C, (mute
| tmp
| (tmp
<< 8)));
964 write_vt(pusb_device
, 0x001A, 0x0404);
965 write_vt(pusb_device
, 0x0002, 0x0000);
968 /*****************************************************************************/