Deleted Added
full compact
bktr_tuner.c (139919) bktr_tuner.c (140655)
1/*-
2 * 1. Redistributions of source code must retain the
3 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 18 unchanged lines hidden (view full) ---

27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * 1. Redistributions of source code must retain the
3 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 18 unchanged lines hidden (view full) ---

27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/bktr/bktr_tuner.c 139919 2005-01-08 22:52:00Z imp $");
35__FBSDID("$FreeBSD: head/sys/dev/bktr/bktr_tuner.c 140655 2005-01-23 07:13:09Z julian $");
36
37/*
38 * This is part of the Driver for Video Capture Cards (Frame grabbers)
39 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
40 * chipset.
41 * Copyright Roger Hardiman and Amancio Hasty.
42 *
43 * bktr_tuner : This deals with controlling the tuner fitted to TV cards.

--- 88 unchanged lines hidden (view full) ---

132#define TSCH5_FCONTROL 0x82
133#define TSCH5_RADIO 0x86
134
135/* The control value for the ALPS TSBH1 Tuner */
136#define TSBH1_FCONTROL 0xce
137
138
139static void mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq);
36
37/*
38 * This is part of the Driver for Video Capture Cards (Frame grabbers)
39 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
40 * chipset.
41 * Copyright Roger Hardiman and Amancio Hasty.
42 *
43 * bktr_tuner : This deals with controlling the tuner fitted to TV cards.

--- 88 unchanged lines hidden (view full) ---

132#define TSCH5_FCONTROL 0x82
133#define TSCH5_RADIO 0x86
134
135/* The control value for the ALPS TSBH1 Tuner */
136#define TSBH1_FCONTROL 0xce
137
138
139static void mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq);
140static int mt2032_init(bktr_ptr_t bktr);
141
142
143static const struct TUNER tuners[] = {
144/* XXX FIXME: fill in the band-switch crosspoints */
145 /* NO_TUNER */
146 { "<no>", /* the 'name' */
147 TTYPE_XXX, /* input type */
148 { 0x00, /* control byte for Tuner PLL */

--- 572 unchanged lines hidden (view full) ---

721/* This is needed as the tuner details are no longer globally declared */
722
723void select_tuner( bktr_ptr_t bktr, int tuner_type ) {
724 if (tuner_type < Bt848_MAX_TUNER) {
725 bktr->card.tuner = &tuners[ tuner_type ];
726 } else {
727 bktr->card.tuner = NULL;
728 }
140
141
142static const struct TUNER tuners[] = {
143/* XXX FIXME: fill in the band-switch crosspoints */
144 /* NO_TUNER */
145 { "<no>", /* the 'name' */
146 TTYPE_XXX, /* input type */
147 { 0x00, /* control byte for Tuner PLL */

--- 572 unchanged lines hidden (view full) ---

720/* This is needed as the tuner details are no longer globally declared */
721
722void select_tuner( bktr_ptr_t bktr, int tuner_type ) {
723 if (tuner_type < Bt848_MAX_TUNER) {
724 bktr->card.tuner = &tuners[ tuner_type ];
725 } else {
726 bktr->card.tuner = NULL;
727 }
729 if (tuner_type == TUNER_MT2032) {
730 mt2032_init(bktr);
731 }
732}
733
734/*
735 * Tuner Notes:
736 * Programming the tuner properly is quite complicated.
737 * Here are some notes, based on a FM1246 data sheet for a PAL-I tuner.
738 * The tuner (front end) covers 45.75 Mhz - 855.25 Mhz and an FM band of
739 * 87.5 Mhz to 108.0 Mhz.

--- 299 unchanged lines hidden (view full) ---

1039 return( 0 );
1040}
1041
1042
1043
1044
1045#define TDA9887_ADDR 0x86
1046
728}
729
730/*
731 * Tuner Notes:
732 * Programming the tuner properly is quite complicated.
733 * Here are some notes, based on a FM1246 data sheet for a PAL-I tuner.
734 * The tuner (front end) covers 45.75 Mhz - 855.25 Mhz and an FM band of
735 * 87.5 Mhz to 108.0 Mhz.

--- 299 unchanged lines hidden (view full) ---

1035 return( 0 );
1036}
1037
1038
1039
1040
1041#define TDA9887_ADDR 0x86
1042
1047int
1043static int
1048TDA9887_init(bktr_ptr_t bktr, int output2_enable)
1049{
1050 u_char addr = TDA9887_ADDR;
1044TDA9887_init(bktr_ptr_t bktr, int output2_enable)
1045{
1046 u_char addr = TDA9887_ADDR;
1051#if 0
1052 char buf[8];
1053
1047
1054 /* NOTE: these are PAL values */
1055 buf[0] = 0; /* sub address */
1056 buf[1] = 0x50; /* output port1 inactive */
1057 buf[2] = 0x6e; /* tuner takeover point / de-emphasis */
1058 buf[3] = 0x09; /* fVIF = 38.9 MHz, fFM = 5.5 MHz */
1048 i2cWrite(bktr, addr, 0, output2_enable ? 0x50 : 0xd0);
1049 i2cWrite(bktr, addr, 1, 0x6e); /* takeover point / de-emphasis */
1059
1050
1060 if (!output2_enable)
1061 buf[1] |= 0x80;
1062
1063 if (i2cWriteBuf(bktr, addr, 4, buf) == -1) {
1064 printf("%s: TDA9887 write failed\n", bktr_name(bktr));
1065 return -1;
1066 }
1051 /* PAL BG: 0x09 PAL I: 0x0a NTSC: 0x04 */
1052#ifdef MT2032_NTSC
1053 i2cWrite(bktr, addr, 2, 0x04);
1067#else
1054#else
1068 i2cWrite(bktr, addr, 0, output2_enable ? 0x50 : 0xd0);
1069 i2cWrite(bktr, addr, 1, 0x6e);
1070 i2cWrite(bktr, addr, 2, 0x09);
1071#endif
1072 return 0;
1073}
1074
1075
1076
1077#define MT2032_OPTIMIZE_VCO 1
1078
1079/* holds the value of XOGC register after init */
1080static int MT2032_XOGC = 4;
1081
1082/* card.tuner_pllAddr not set during init */
1083#define MT2032_ADDR 0xc0
1084
1085#ifndef MT2032_ADDR
1086#define MT2032_ADDR (bktr->card.tuner_pllAddr)
1087#endif
1088
1055 i2cWrite(bktr, addr, 2, 0x09);
1056#endif
1057 return 0;
1058}
1059
1060
1061
1062#define MT2032_OPTIMIZE_VCO 1
1063
1064/* holds the value of XOGC register after init */
1065static int MT2032_XOGC = 4;
1066
1067/* card.tuner_pllAddr not set during init */
1068#define MT2032_ADDR 0xc0
1069
1070#ifndef MT2032_ADDR
1071#define MT2032_ADDR (bktr->card.tuner_pllAddr)
1072#endif
1073
1089static u_char
1074static int
1090_MT2032_GetRegister(bktr_ptr_t bktr, u_char regNum)
1091{
1092 int ch;
1093
1094 if (i2cWrite(bktr, MT2032_ADDR, regNum, -1) == -1) {
1075_MT2032_GetRegister(bktr_ptr_t bktr, u_char regNum)
1076{
1077 int ch;
1078
1079 if (i2cWrite(bktr, MT2032_ADDR, regNum, -1) == -1) {
1095 printf("%s: MT2032 write failed (i2c addr %#x)\n",
1096 bktr_name(bktr), MT2032_ADDR);
1080 if (bootverbose)
1081 printf("%s: MT2032 write failed (i2c addr %#x)\n",
1082 bktr_name(bktr), MT2032_ADDR);
1083 return -1;
1097 }
1098 if ((ch = i2cRead(bktr, MT2032_ADDR + 1)) == -1) {
1084 }
1085 if ((ch = i2cRead(bktr, MT2032_ADDR + 1)) == -1) {
1099 printf("%s: MT2032 get register %d failed\n",
1100 bktr_name(bktr), regNum);
1101 return 0;
1086 if (bootverbose)
1087 printf("%s: MT2032 get register %d failed\n",
1088 bktr_name(bktr), regNum);
1089 return -1;
1102 }
1103 return ch;
1104}
1105
1106static void
1107_MT2032_SetRegister(bktr_ptr_t bktr, u_char regNum, u_char data)
1108{
1109 i2cWrite(bktr, MT2032_ADDR, regNum, data);
1110}
1111
1112#define MT2032_GetRegister(r) _MT2032_GetRegister(bktr,r)
1113#define MT2032_SetRegister(r,d) _MT2032_SetRegister(bktr,r,d)
1114
1115
1090 }
1091 return ch;
1092}
1093
1094static void
1095_MT2032_SetRegister(bktr_ptr_t bktr, u_char regNum, u_char data)
1096{
1097 i2cWrite(bktr, MT2032_ADDR, regNum, data);
1098}
1099
1100#define MT2032_GetRegister(r) _MT2032_GetRegister(bktr,r)
1101#define MT2032_SetRegister(r,d) _MT2032_SetRegister(bktr,r,d)
1102
1103
1116static int
1104int
1117mt2032_init(bktr_ptr_t bktr)
1118{
1119 u_char rdbuf[22];
1120 int xogc, xok = 0;
1121 int i;
1105mt2032_init(bktr_ptr_t bktr)
1106{
1107 u_char rdbuf[22];
1108 int xogc, xok = 0;
1109 int i;
1110 int x;
1122
1123 TDA9887_init(bktr, 0);
1124
1111
1112 TDA9887_init(bktr, 0);
1113
1125 for (i = 0; i < 21; i++)
1126 rdbuf[i] = MT2032_GetRegister(i);
1114 for (i = 0; i < 21; i++) {
1115 if ((x = MT2032_GetRegister(i)) == -1)
1116 break;
1117 rdbuf[i] = x;
1118 }
1119 if (i < 21)
1120 return -1;
1127
1128 printf("%s: MT2032: Companycode=%02x%02x Part=%02x Revision=%02x\n",
1129 bktr_name(bktr),
1130 rdbuf[0x11], rdbuf[0x12], rdbuf[0x13], rdbuf[0x14]);
1121
1122 printf("%s: MT2032: Companycode=%02x%02x Part=%02x Revision=%02x\n",
1123 bktr_name(bktr),
1124 rdbuf[0x11], rdbuf[0x12], rdbuf[0x13], rdbuf[0x14]);
1125 if (rdbuf[0x13] != 4) {
1126 printf("%s: MT2032 not found or unknown type\n", bktr_name(bktr));
1127 return -1;
1128 }
1131
1132 /* Initialize Registers per spec. */
1133 MT2032_SetRegister(2, 0xff);
1134 MT2032_SetRegister(3, 0x0f);
1135 MT2032_SetRegister(4, 0x1f);
1136 MT2032_SetRegister(6, 0xe4);
1137 MT2032_SetRegister(7, 0x8f);
1138 MT2032_SetRegister(8, 0xc3);

--- 211 unchanged lines hidden (view full) ---

1350 u_char buf[21];
1351 int lint_try, sel, lock = 0;
1352
1353 if (MT2032_ComputeFreq(rfin, if1, if2, from, to, &buf[0], &sel, MT2032_XOGC) == -1)
1354 return -1;
1355
1356 TDA9887_init(bktr, 0);
1357
1129
1130 /* Initialize Registers per spec. */
1131 MT2032_SetRegister(2, 0xff);
1132 MT2032_SetRegister(3, 0x0f);
1133 MT2032_SetRegister(4, 0x1f);
1134 MT2032_SetRegister(6, 0xe4);
1135 MT2032_SetRegister(7, 0x8f);
1136 MT2032_SetRegister(8, 0xc3);

--- 211 unchanged lines hidden (view full) ---

1348 u_char buf[21];
1349 int lint_try, sel, lock = 0;
1350
1351 if (MT2032_ComputeFreq(rfin, if1, if2, from, to, &buf[0], &sel, MT2032_XOGC) == -1)
1352 return -1;
1353
1354 TDA9887_init(bktr, 0);
1355
1358 printf("%s: MT2032-SetIFFreq: 0x%02X%02X%02X%02X...\n",
1359 bktr_name(bktr),
1360 buf[0x00], buf[0x01], buf[0x02], buf[0x03]);
1361
1362 /* send only the relevant registers per Rev. 1.2 */
1363 MT2032_SetRegister(0, buf[0x00]);
1364 MT2032_SetRegister(1, buf[0x01]);
1365 MT2032_SetRegister(2, buf[0x02]);
1366
1367 MT2032_SetRegister(5, buf[0x05]);
1368 MT2032_SetRegister(6, buf[0x06]);
1369 MT2032_SetRegister(7, buf[0x07]);

--- 24 unchanged lines hidden (view full) ---

1394 TDA9887_init(bktr, 1);
1395 return 0;
1396}
1397
1398static void
1399mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq)
1400{
1401 int if2,from,to;
1356 /* send only the relevant registers per Rev. 1.2 */
1357 MT2032_SetRegister(0, buf[0x00]);
1358 MT2032_SetRegister(1, buf[0x01]);
1359 MT2032_SetRegister(2, buf[0x02]);
1360
1361 MT2032_SetRegister(5, buf[0x05]);
1362 MT2032_SetRegister(6, buf[0x06]);
1363 MT2032_SetRegister(7, buf[0x07]);

--- 24 unchanged lines hidden (view full) ---

1388 TDA9887_init(bktr, 1);
1389 return 0;
1390}
1391
1392static void
1393mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq)
1394{
1395 int if2,from,to;
1396 int stat, tad;
1402
1397
1398#ifdef MT2032_NTSC
1399 from=40750*1000;
1400 to=46750*1000;
1401 if2=45750*1000;
1402#else
1403 from=32900*1000;
1404 to=39900*1000;
1405 if2=38900*1000;
1403 from=32900*1000;
1404 to=39900*1000;
1405 if2=38900*1000;
1406#endif
1406
1407
1407 printf("%s: setting frequency to %d\n", bktr_name(bktr), freq*62500);
1408 MT2032_SetIFFreq(bktr, freq*62500 /* freq*1000*1000/16 */,
1409 1090*1000*1000, if2, from, to);
1408 if (MT2032_SetIFFreq(bktr, freq*62500 /* freq*1000*1000/16 */,
1409 1090*1000*1000, if2, from, to) == 0) {
1410 bktr->tuner.frequency = freq;
1411 stat = MT2032_GetRegister(0x0e);
1412 tad = MT2032_GetRegister(0x0f);
1413 if (bootverbose)
1414 printf("%s: frequency set to %d, st = %#x, tad = %#x\n",
1415 bktr_name(bktr), freq*62500, stat, tad);
1416 }
1410}
1417}