aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHartmut Hackmann <hartmut.hackmann@t.online.de>2005-11-09 00:37:48 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 10:56:21 -0500
commitde48eebce8b63dbae7272ee80f4fe0eaddb61278 (patch)
treeaa6a750b39c44732801e31ec0cc235f34b2c2b22 /drivers
parent4c0772a9e1fdd5972751993c58d0ac2a427ceb24 (diff)
[PATCH] v4l: 806: add support for tda8275a
- Add support for tda8275a Signed-off-by: Hartmut Hackmann <hartmut.hackmann@t.online.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/tda8290.c638
-rw-r--r--drivers/media/video/tuner-core.c2
2 files changed, 479 insertions, 161 deletions
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index e2027dada5d1..47d3d2ce9770 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -1,177 +1,402 @@
1/* 1/*
2 * 2
3 * i2c tv tuner chip device driver 3 i2c tv tuner chip device driver
4 * controls the philips tda8290+75 tuner chip combo. 4 controls the philips tda8290+75 tuner chip combo.
5 */ 5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
6#include <linux/i2c.h> 21#include <linux/i2c.h>
7#include <linux/videodev.h> 22#include <linux/videodev.h>
8#include <linux/delay.h> 23#include <linux/delay.h>
9#include <media/tuner.h> 24#include <media/tuner.h>
10 25
11#define I2C_ADDR_TDA8290 0x4b
12#define I2C_ADDR_TDA8275 0x61
13
14/* ---------------------------------------------------------------------- */ 26/* ---------------------------------------------------------------------- */
15 27
16struct freq_entry { 28struct tda827x_data {
17 u16 freq; 29 u32 lomax;
18 u8 value; 30 u8 spd;
31 u8 bs;
32 u8 bp;
33 u8 cp;
34 u8 gc3;
35 u8 div1p5;
19}; 36};
20 37
21static struct freq_entry band_table[] = { 38 /* Note lomax entry is lo / 62500 */
22 { 0x2DF4, 0x1C }, 39
23 { 0x2574, 0x14 }, 40static struct tda827x_data tda827x_analog[] = {
24 { 0x22B4, 0x0C }, 41 { .lomax = 992, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 62 MHz */
25 { 0x20D4, 0x0B }, 42 { .lomax = 1056, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 66 MHz */
26 { 0x1E74, 0x3B }, 43 { .lomax = 1216, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 76 MHz */
27 { 0x1C34, 0x33 }, 44 { .lomax = 1344, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 84 MHz */
28 { 0x16F4, 0x5B }, 45 { .lomax = 1488, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 93 MHz */
29 { 0x1454, 0x53 }, 46 { .lomax = 1568, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 98 MHz */
30 { 0x12D4, 0x52 }, 47 { .lomax = 1744, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 109 MHz */
31 { 0x1034, 0x4A }, 48 { .lomax = 1968, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 123 MHz */
32 { 0x0EE4, 0x7A }, 49 { .lomax = 2128, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 133 MHz */
33 { 0x0D34, 0x72 }, 50 { .lomax = 2416, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 151 MHz */
34 { 0x0B54, 0x9A }, 51 { .lomax = 2464, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 154 MHz */
35 { 0x0914, 0x91 }, 52 { .lomax = 2896, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 181 MHz */
36 { 0x07F4, 0x89 }, 53 { .lomax = 2960, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 185 MHz */
37 { 0x0774, 0xB9 }, 54 { .lomax = 3472, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 217 MHz */
38 { 0x067B, 0xB1 }, 55 { .lomax = 3904, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 244 MHz */
39 { 0x0634, 0xD9 }, 56 { .lomax = 4240, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 265 MHz */
40 { 0x05A4, 0xD8 }, // FM radio 57 { .lomax = 4832, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 302 MHz */
41 { 0x0494, 0xD0 }, 58 { .lomax = 5184, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 324 MHz */
42 { 0x03BC, 0xC8 }, 59 { .lomax = 5920, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 370 MHz */
43 { 0x0394, 0xF8 }, // 57250000 Hz 60 { .lomax = 7264, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 454 MHz */
44 { 0x0000, 0xF0 }, // 0 61 { .lomax = 7888, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 493 MHz */
62 { .lomax = 8480, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 530 MHz */
63 { .lomax = 8864, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 554 MHz */
64 { .lomax = 9664, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 604 MHz */
65 { .lomax = 11088, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 696 MHz */
66 { .lomax = 11840, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 740 MHz */
67 { .lomax = 13120, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 820 MHz */
68 { .lomax = 13840, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 865 MHz */
69 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */
45}; 70};
46 71
47static struct freq_entry div_table[] = { 72static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
48 { 0x1C34, 3 }, 73{
49 { 0x0D34, 2 }, 74 unsigned char tuner_reg[8];
50 { 0x067B, 1 }, 75 unsigned char reg2[2];
51 { 0x0000, 0 }, 76 u32 N;
52}; 77 int i;
78 struct tuner *t = i2c_get_clientdata(c);
79 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0};
53 80
54static struct freq_entry agc_table[] = { 81 if (t->mode == V4L2_TUNER_RADIO)
55 { 0x22B4, 0x8F }, 82 freq = freq / 1000;
56 { 0x0B54, 0x9F }, 83
57 { 0x09A4, 0x8F }, 84 N = freq + ifc;
58 { 0x0554, 0x9F }, 85 i = 0;
59 { 0x0000, 0xBF }, 86 while (tda827x_analog[i].lomax < N) {
60}; 87 if(tda827x_analog[i + 1].lomax == 0)
88 break;
89 i++;
90 }
91
92 N = N << tda827x_analog[i].spd;
93
94 tuner_reg[0] = 0;
95 tuner_reg[1] = (unsigned char)(N>>8);
96 tuner_reg[2] = (unsigned char) N;
97 tuner_reg[3] = 0x40;
98 tuner_reg[4] = 0x52 + (t->tda827x_lpsel << 5);
99 tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) +
100 (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp;
101 tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4);
102 tuner_reg[7] = 0x8f;
103
104 msg.buf = tuner_reg;
105 msg.len = 8;
106 i2c_transfer(c->adapter, &msg, 1);
107
108 msg.buf= reg2;
109 msg.len = 2;
110 reg2[0] = 0x80;
111 reg2[1] = 0;
112 i2c_transfer(c->adapter, &msg, 1);
113
114 reg2[0] = 0x60;
115 reg2[1] = 0xbf;
116 i2c_transfer(c->adapter, &msg, 1);
117
118 reg2[0] = 0x30;
119 reg2[1] = tuner_reg[4] + 0x80;
120 i2c_transfer(c->adapter, &msg, 1);
121
122 msleep(1);
123 reg2[0] = 0x30;
124 reg2[1] = tuner_reg[4] + 4;
125 i2c_transfer(c->adapter, &msg, 1);
126
127 msleep(1);
128 reg2[0] = 0x30;
129 reg2[1] = tuner_reg[4];
130 i2c_transfer(c->adapter, &msg, 1);
131
132 msleep(550);
133 reg2[0] = 0x30;
134 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ;
135 i2c_transfer(c->adapter, &msg, 1);
61 136
62static __u8 get_freq_entry( struct freq_entry* table, __u16 freq) 137 reg2[0] = 0x60;
138 reg2[1] = 0x7f;
139 i2c_transfer(c->adapter, &msg, 1);
140
141 reg2[0] = 0x80;
142 reg2[1] = 0x08; // Vsync en
143 i2c_transfer(c->adapter, &msg, 1);
144}
145
146static void tda827x_agcf(struct i2c_client *c)
63{ 147{
64 while(table->freq && table->freq > freq) 148 struct tuner *t = i2c_get_clientdata(c);
65 table++; 149 unsigned char data[] = {0x80, 0x0c};
66 return table->value; 150 struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data,
151 .flags = 0, .len = 2};
152 i2c_transfer(c->adapter, &msg, 1);
67} 153}
68 154
69/* ---------------------------------------------------------------------- */ 155/* ---------------------------------------------------------------------- */
70 156
71static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 }; 157struct tda827xa_data {
72static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 }; 158 u32 lomax;
73static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00, 159 u8 svco;
74 0xfC, 0x04, 0xA3, 0x3F, 160 u8 spd;
75 0x2A, 0x04, 0xFF, 0x00, 161 u8 scr;
76 0x00, 0x40 }; 162 u8 sbs;
77static unsigned char i2c_set_VS[2] = { 0x30, 0x6F }; 163 u8 gc3;
78static unsigned char i2c_set_GP01_CF[2] = { 0x20, 0x0B };
79static unsigned char i2c_tda8290_reset[2] = { 0x00, 0x00 };
80static unsigned char i2c_tda8290_standby[2] = { 0x00, 0x02 };
81static unsigned char i2c_gainset_off[2] = { 0x28, 0x14 };
82static unsigned char i2c_gainset_on[2] = { 0x28, 0x54 };
83static unsigned char i2c_agc3_00[2] = { 0x80, 0x00 };
84static unsigned char i2c_agc2_BF[2] = { 0x60, 0xBF };
85static unsigned char i2c_cb1_D0[2] = { 0x30, 0xD0 };
86static unsigned char i2c_cb1_D2[2] = { 0x30, 0xD2 };
87static unsigned char i2c_cb1_56[2] = { 0x30, 0x56 };
88static unsigned char i2c_cb1_52[2] = { 0x30, 0x52 };
89static unsigned char i2c_cb1_50[2] = { 0x30, 0x50 };
90static unsigned char i2c_agc2_7F[2] = { 0x60, 0x7F };
91static unsigned char i2c_agc3_08[2] = { 0x80, 0x08 };
92
93/* FIXME: European PAL/SECAM should select 9MHz Lowpass Filter, while
94 NTSC/M and PAL/M should be using 7MHz filter, by selecting CB3 */
95static unsigned char i2c_cb3_9MHz[2] = { 0xc0, 0x39 };
96static unsigned char i2c_cb3_7MHz[2] = { 0xc0, 0x3B };
97
98static struct i2c_msg i2c_msg_init[] = {
99 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_init_tda8275), i2c_init_tda8275 },
100 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
101 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_VS), i2c_set_VS },
102 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_GP01_CF), i2c_set_GP01_CF },
103}; 164};
104 165
105static struct i2c_msg i2c_msg_prolog[] = { 166static struct tda827xa_data tda827xa_analog[] = {
106// { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_easy_mode), i2c_easy_mode }, 167 { .lomax = 910, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, /* 56.875 MHz */
107 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_off), i2c_gainset_off }, 168 { .lomax = 1076, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 67.25 MHz */
108 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_reset), i2c_tda8290_reset }, 169 { .lomax = 1300, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 81.25 MHz */
109 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge }, 170 { .lomax = 1560, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 97.5 MHz */
171 { .lomax = 1820, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1}, /* 113.75 MHz */
172 { .lomax = 2152, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 134.5 MHz */
173 { .lomax = 2464, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 154 MHz */
174 { .lomax = 2600, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 162.5 MHz */
175 { .lomax = 2928, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 183 MHz */
176 { .lomax = 3120, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1}, /* 195 MHz */
177 { .lomax = 3640, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3}, /* 227.5 MHz */
178 { .lomax = 4304, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3}, /* 269 MHz */
179 { .lomax = 5200, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1}, /* 325 MHz */
180 { .lomax = 6240, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 390 MHz */
181 { .lomax = 7280, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 455 MHz */
182 { .lomax = 8320, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 520 MHz */
183 { .lomax = 8608, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1}, /* 538 MHz */
184 { .lomax = 8864, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 554 MHz */
185 { .lomax = 9920, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 620 MHz */
186 { .lomax = 10400, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 650 MHz */
187 { .lomax = 11200, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 700 MHz */
188 { .lomax = 12480, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 780 MHz */
189 { .lomax = 13120, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 820 MHz */
190 { .lomax = 13920, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 870 MHz */
191 { .lomax = 14576, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0}, /* 911 MHz */
192 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */
110}; 193};
111 194
112static struct i2c_msg i2c_msg_config[] = { 195static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
113// { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_set_freq), i2c_set_freq }, 196{
114 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_00), i2c_agc3_00 }, 197 unsigned char tuner_reg[14];
115 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_BF), i2c_agc2_BF }, 198 unsigned char reg2[2];
116 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D2), i2c_cb1_D2 }, 199 u32 N;
117 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_56), i2c_cb1_56 }, 200 int i;
118 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_52), i2c_cb1_52 }, 201 struct tuner *t = i2c_get_clientdata(c);
119}; 202 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0};
120 203
121static struct i2c_msg i2c_msg_epilog[] = { 204 if (t->mode == V4L2_TUNER_RADIO)
122 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_50), i2c_cb1_50 }, 205 freq = freq / 1000;
123 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_7F), i2c_agc2_7F },
124 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_08), i2c_agc3_08 },
125 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
126 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_on), i2c_gainset_on },
127};
128 206
129static struct i2c_msg i2c_msg_standby[] = { 207 N = freq + ifc;
130 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge }, 208 i = 0;
131 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D0), i2c_cb1_D0 }, 209 while (tda827xa_analog[i].lomax < N) {
132 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge }, 210 if(tda827xa_analog[i + 1].lomax == 0)
133 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_standby), i2c_tda8290_standby }, 211 break;
134}; 212 i++;
213 }
214
215 N = N << tda827xa_analog[i].spd;
216
217 tuner_reg[0] = 0;
218 tuner_reg[1] = (unsigned char)(N>>8);
219 tuner_reg[2] = (unsigned char) N;
220 tuner_reg[3] = 0;
221 tuner_reg[4] = 0x16;
222 tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) +
223 tda827xa_analog[i].sbs;
224 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
225 tuner_reg[7] = 0x0c;
226 tuner_reg[8] = 4;
227 tuner_reg[9] = 0x20;
228 tuner_reg[10] = 0xff;
229 tuner_reg[11] = 0xe0;
230 tuner_reg[12] = 0;
231 tuner_reg[13] = 0x39 + (t->tda827x_lpsel << 1);
232
233 msg.buf = tuner_reg;
234 msg.len = 14;
235 i2c_transfer(c->adapter, &msg, 1);
236
237 msg.buf= reg2;
238 msg.len = 2;
239 reg2[0] = 0x60;
240 reg2[1] = 0x3c;
241 i2c_transfer(c->adapter, &msg, 1);
242
243 reg2[0] = 0xa0;
244 reg2[1] = 0xc0;
245 i2c_transfer(c->adapter, &msg, 1);
246
247 msleep(2);
248 reg2[0] = 0x30;
249 reg2[1] = 0x10 + tda827xa_analog[i].scr;
250 i2c_transfer(c->adapter, &msg, 1);
251
252 msleep(550);
253 reg2[0] = 0x50;
254 reg2[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
255 i2c_transfer(c->adapter, &msg, 1);
256
257 reg2[0] = 0x80;
258 reg2[1] = 0x28;
259 i2c_transfer(c->adapter, &msg, 1);
260
261 reg2[0] = 0xb0;
262 reg2[1] = 0x01;
263 i2c_transfer(c->adapter, &msg, 1);
135 264
136static int tda8290_tune(struct i2c_client *c) 265 reg2[0] = 0xc0;
266 reg2[1] = 0x19 + (t->tda827x_lpsel << 1);
267 i2c_transfer(c->adapter, &msg, 1);
268}
269
270static void tda827xa_agcf(struct i2c_client *c)
137{ 271{
138 struct tuner *t = i2c_get_clientdata(c); 272 struct tuner *t = i2c_get_clientdata(c);
139 struct i2c_msg easy_mode = 273 unsigned char data[] = {0x80, 0x2c};
140 { I2C_ADDR_TDA8290, 0, 2, t->i2c_easy_mode }; 274 struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data,
141 struct i2c_msg set_freq = 275 .flags = 0, .len = 2};
142 { I2C_ADDR_TDA8275, 0, 8, t->i2c_set_freq }; 276 i2c_transfer(c->adapter, &msg, 1);
143 277}
144 i2c_transfer(c->adapter, &easy_mode, 1);
145 i2c_transfer(c->adapter, i2c_msg_prolog, ARRAY_SIZE(i2c_msg_prolog));
146 278
147 i2c_transfer(c->adapter, &set_freq, 1); 279/*---------------------------------------------------------------------*/
148 i2c_transfer(c->adapter, i2c_msg_config, ARRAY_SIZE(i2c_msg_config));
149 280
150 msleep(550); 281static void tda8290_i2c_bridge(struct i2c_client *c, int close)
151 i2c_transfer(c->adapter, i2c_msg_epilog, ARRAY_SIZE(i2c_msg_epilog)); 282{
152 return 0; 283 unsigned char enable[2] = { 0x21, 0xC0 };
284 unsigned char disable[2] = { 0x21, 0x80 };
285 unsigned char *msg;
286 if(close) {
287 msg = enable;
288 i2c_master_send(c, msg, 2);
289 /* let the bridge stabilize */
290 msleep(20);
291 } else {
292 msg = disable;
293 i2c_master_send(c, msg, 2);
294 }
153} 295}
154 296
155static void set_frequency(struct tuner *t, u16 ifc, unsigned int freq) 297/*---------------------------------------------------------------------*/
298
299static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
156{ 300{
157 u32 N; 301 struct tuner *t = i2c_get_clientdata(c);
302 unsigned char soft_reset[] = { 0x00, 0x00 };
303 unsigned char easy_mode[] = { 0x01, t->tda8290_easy_mode };
304 unsigned char expert_mode[] = { 0x01, 0x80 };
305 unsigned char gainset_off[] = { 0x28, 0x14 };
306 unsigned char if_agc_spd[] = { 0x0f, 0x88 };
307 unsigned char adc_head_6[] = { 0x05, 0x04 };
308 unsigned char adc_head_9[] = { 0x05, 0x02 };
309 unsigned char adc_head_12[] = { 0x05, 0x01 };
310 unsigned char pll_bw_nom[] = { 0x0d, 0x47 };
311 unsigned char pll_bw_low[] = { 0x0d, 0x27 };
312 unsigned char gainset_2[] = { 0x28, 0x64 };
313 unsigned char agc_rst_on[] = { 0x0e, 0x0b };
314 unsigned char agc_rst_off[] = { 0x0e, 0x09 };
315 unsigned char if_agc_set[] = { 0x0f, 0x81 };
316 unsigned char addr_adc_sat = 0x1a;
317 unsigned char addr_agc_stat = 0x1d;
318 unsigned char addr_pll_stat = 0x1b;
319 unsigned char adc_sat, agc_stat,
320 pll_stat;
321
322 i2c_master_send(c, easy_mode, 2);
323 i2c_master_send(c, soft_reset, 2);
324 msleep(1);
325
326 i2c_master_send(c, expert_mode, 2);
327 i2c_master_send(c, gainset_off, 2);
328 i2c_master_send(c, if_agc_spd, 2);
329 if (t->tda8290_easy_mode & 0x60)
330 i2c_master_send(c, adc_head_9, 2);
331 else
332 i2c_master_send(c, adc_head_6, 2);
333 i2c_master_send(c, pll_bw_nom, 2);
334
335 tda8290_i2c_bridge(c, 1);
336 if (t->tda827x_ver != 0)
337 tda827xa_tune(c, ifc, freq);
338 else
339 tda827x_tune(c, ifc, freq);
340 /* adjust headroom resp. gain */
341 i2c_master_send(c, &addr_adc_sat, 1);
342 i2c_master_recv(c, &adc_sat, 1);
343 i2c_master_send(c, &addr_agc_stat, 1);
344 i2c_master_recv(c, &agc_stat, 1);
345 i2c_master_send(c, &addr_pll_stat, 1);
346 i2c_master_recv(c, &pll_stat, 1);
347 if (pll_stat & 0x80)
348 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
349 else
350 tuner_dbg("tda8290 not locked, no signal?\n");
351 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat <20))) {
352 tuner_dbg("adjust gain, step 1. Agc: %d\n", agc_stat);
353 i2c_master_send(c, gainset_2, 2);
354 msleep(100);
355 i2c_master_send(c, &addr_agc_stat, 1);
356 i2c_master_recv(c, &agc_stat, 1);
357 i2c_master_send(c, &addr_pll_stat, 1);
358 i2c_master_recv(c, &pll_stat, 1);
359 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
360 tuner_dbg("adjust gain, step 2. Agc: %d\n", agc_stat);
361 if (t->tda827x_ver != 0)
362 tda827xa_agcf(c);
363 else
364 tda827x_agcf(c);
365 msleep(100);
366 i2c_master_send(c, &addr_agc_stat, 1);
367 i2c_master_recv(c, &agc_stat, 1);
368 i2c_master_send(c, &addr_pll_stat, 1);
369 i2c_master_recv(c, &pll_stat, 1);
370 if((agc_stat > 115) || !(pll_stat & 0x80)) {
371 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
372 i2c_master_send(c, adc_head_12, 2);
373 i2c_master_send(c, pll_bw_low, 2);
374 msleep(100);
375 }
376 }
377 }
158 378
159 if (t->mode == V4L2_TUNER_RADIO) 379 /* l/ l' deadlock? */
160 freq = freq / 1000; 380 if(t->tda8290_easy_mode & 0x60) {
381 i2c_master_send(c, &addr_adc_sat, 1);
382 i2c_master_recv(c, &adc_sat, 1);
383 i2c_master_send(c, &addr_pll_stat, 1);
384 i2c_master_recv(c, &pll_stat, 1);
385 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
386 i2c_master_send(c, agc_rst_on, 2);
387 msleep(40);
388 i2c_master_send(c, agc_rst_off, 2);
389 }
390 }
161 391
162 N = (((freq<<3)+ifc)&0x3fffc); 392 tda8290_i2c_bridge(c, 0);
163 393 i2c_master_send(c, if_agc_set, 2);
164 N = N >> get_freq_entry(div_table, freq); 394 return 0;
165 t->i2c_set_freq[0] = 0;
166 t->i2c_set_freq[1] = (unsigned char)(N>>8);
167 t->i2c_set_freq[2] = (unsigned char) N;
168 t->i2c_set_freq[3] = 0x40;
169 t->i2c_set_freq[4] = 0x52;
170 t->i2c_set_freq[5] = get_freq_entry(band_table, freq);
171 t->i2c_set_freq[6] = get_freq_entry(agc_table, freq);
172 t->i2c_set_freq[7] = 0x8f;
173} 395}
174 396
397
398/*---------------------------------------------------------------------*/
399
175#define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC) 400#define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
176#define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B) 401#define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
177#define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H) 402#define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
@@ -179,26 +404,27 @@ static void set_frequency(struct tuner *t, u16 ifc, unsigned int freq)
179 404
180static void set_audio(struct tuner *t) 405static void set_audio(struct tuner *t)
181{ 406{
182 t->i2c_easy_mode[0] = 0x01; 407 t->tda827x_lpsel = 0;
183 408
184 if (t->std & V4L2_STD_MN) { 409 if (t->std & V4L2_STD_MN) {
185 t->sgIF = 736; 410 t->sgIF = 92;
186 t->i2c_easy_mode[1] = 0x01; 411 t->tda8290_easy_mode = 0x01;
412 t->tda827x_lpsel = 1;
187 } else if (t->std & V4L2_STD_B) { 413 } else if (t->std & V4L2_STD_B) {
188 t->sgIF = 864; 414 t->sgIF = 108;
189 t->i2c_easy_mode[1] = 0x02; 415 t->tda8290_easy_mode = 0x02;
190 } else if (t->std & V4L2_STD_GH) { 416 } else if (t->std & V4L2_STD_GH) {
191 t->sgIF = 992; 417 t->sgIF = 124;
192 t->i2c_easy_mode[1] = 0x04; 418 t->tda8290_easy_mode = 0x04;
193 } else if (t->std & V4L2_STD_PAL_I) { 419 } else if (t->std & V4L2_STD_PAL_I) {
194 t->sgIF = 992; 420 t->sgIF = 124;
195 t->i2c_easy_mode[1] = 0x08; 421 t->tda8290_easy_mode = 0x08;
196 } else if (t->std & V4L2_STD_DK) { 422 } else if (t->std & V4L2_STD_DK) {
197 t->sgIF = 992; 423 t->sgIF = 124;
198 t->i2c_easy_mode[1] = 0x10; 424 t->tda8290_easy_mode = 0x10;
199 } else if (t->std & V4L2_STD_SECAM_L) { 425 } else if (t->std & V4L2_STD_SECAM_L) {
200 t->sgIF = 992; 426 t->sgIF = 124;
201 t->i2c_easy_mode[1] = 0x20; 427 t->tda8290_easy_mode = 0x20;
202 } 428 }
203} 429}
204 430
@@ -207,15 +433,13 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
207 struct tuner *t = i2c_get_clientdata(c); 433 struct tuner *t = i2c_get_clientdata(c);
208 434
209 set_audio(t); 435 set_audio(t);
210 set_frequency(t, t->sgIF, freq); 436 tda8290_tune(c, t->sgIF, freq);
211 tda8290_tune(c);
212} 437}
213 438
214static void set_radio_freq(struct i2c_client *c, unsigned int freq) 439static void set_radio_freq(struct i2c_client *c, unsigned int freq)
215{ 440{
216 struct tuner *t = i2c_get_clientdata(c); 441 /* if frequency is 5.5 MHz */
217 set_frequency(t, 704, freq); 442 tda8290_tune(c, 88, freq);
218 tda8290_tune(c);
219} 443}
220 444
221static int has_signal(struct i2c_client *c) 445static int has_signal(struct i2c_client *c)
@@ -228,24 +452,118 @@ static int has_signal(struct i2c_client *c)
228 return (afc & 0x80)? 65535:0; 452 return (afc & 0x80)? 65535:0;
229} 453}
230 454
455/*---------------------------------------------------------------------*/
456
231static void standby(struct i2c_client *c) 457static void standby(struct i2c_client *c)
232{ 458{
233 i2c_transfer(c->adapter, i2c_msg_standby, ARRAY_SIZE(i2c_msg_standby)); 459 struct tuner *t = i2c_get_clientdata(c);
460 unsigned char cb1[] = { 0x30, 0xD0 };
461 unsigned char tda8290_standby[] = { 0x00, 0x02 };
462 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
463
464 tda8290_i2c_bridge(c, 1);
465 if (t->tda827x_ver != 0)
466 cb1[1] = 0x90;
467 i2c_transfer(c->adapter, &msg, 1);
468 tda8290_i2c_bridge(c, 0);
469 i2c_master_send(c, tda8290_standby, 2);
234} 470}
235 471
236int tda8290_init(struct i2c_client *c) 472
473static void tda8290_init_if(struct i2c_client *c)
474{
475 unsigned char set_VS[] = { 0x30, 0x6F };
476 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
477
478 i2c_master_send(c, set_VS, 2);
479 i2c_master_send(c, set_GP01_CF, 2);
480}
481
482static void tda8290_init_tuner(struct i2c_client *c)
237{ 483{
238 struct tuner *t = i2c_get_clientdata(c); 484 struct tuner *t = i2c_get_clientdata(c);
485 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
486 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
487 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
488 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
489 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0,
490 .buf=tda8275_init, .len = 14};
491 if (t->tda827x_ver != 0)
492 msg.buf = tda8275a_init;
493
494 tda8290_i2c_bridge(c, 1);
495 i2c_transfer(c->adapter, &msg, 1);
496 tda8290_i2c_bridge(c, 0);
497}
498
499/*---------------------------------------------------------------------*/
239 500
240 strlcpy(c->name, "tda8290+75", sizeof(c->name)); 501int tda8290_init(struct i2c_client *c)
502{
503 struct tuner *t = i2c_get_clientdata(c);
504 u8 data;
505 int i, ret, tuners_found;
506 u32 tuner_addrs;
507 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1};
508
509 tda8290_i2c_bridge(c, 1);
510 /* probe for tuner chip */
511 tuners_found = 0;
512 tuner_addrs = 0;
513 for (i=0x60; i<= 0x63; i++) {
514 msg.addr = i;
515 ret = i2c_transfer(c->adapter, &msg, 1);
516 if (ret == 1) {
517 tuners_found++;
518 tuner_addrs = (tuner_addrs << 8) + i;
519 }
520 }
521 /* if there is more than one tuner, we expect the right one is
522 behind the bridge and we choose the highest address that doesn't
523 give a response now
524 */
525 tda8290_i2c_bridge(c, 0);
526 if(tuners_found > 1)
527 for (i = 0; i < tuners_found; i++) {
528 msg.addr = tuner_addrs & 0xff;
529 ret = i2c_transfer(c->adapter, &msg, 1);
530 if(ret == 1)
531 tuner_addrs = tuner_addrs >> 8;
532 else
533 break;
534 }
535 if (tuner_addrs == 0) {
536 tuner_addrs = 0x61;
537 tuner_info ("could not clearly identify tuner address, defaulting to %x\n",
538 tuner_addrs);
539 } else {
540 tuner_addrs = tuner_addrs & 0xff;
541 tuner_info ("setting tuner address to %x\n", tuner_addrs);
542 }
543 t->tda827x_addr = tuner_addrs;
544 msg.addr = tuner_addrs;
545
546 tda8290_i2c_bridge(c, 1);
547 ret = i2c_transfer(c->adapter, &msg, 1);
548 if( ret != 1)
549 tuner_warn ("TDA827x access failed!\n");
550 if ((data & 0x3c) == 0) {
551 strlcpy(c->name, "tda8290+75", sizeof(c->name));
552 t->tda827x_ver = 0;
553 } else {
554 strlcpy(c->name, "tda8290+75a", sizeof(c->name));
555 t->tda827x_ver = 2;
556 }
241 tuner_info("tuner: type set to %s\n", c->name); 557 tuner_info("tuner: type set to %s\n", c->name);
558
242 t->tv_freq = set_tv_freq; 559 t->tv_freq = set_tv_freq;
243 t->radio_freq = set_radio_freq; 560 t->radio_freq = set_radio_freq;
244 t->has_signal = has_signal; 561 t->has_signal = has_signal;
245 t->standby = standby; 562 t->standby = standby;
563 t->tda827x_lpsel = 0;
246 564
247 i2c_master_send(c, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge)); 565 tda8290_init_tuner(c);
248 i2c_transfer(c->adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init)); 566 tda8290_init_if(c);
249 return 0; 567 return 0;
250} 568}
251 569
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index e677869afcf3..b9f1acf30caf 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -28,7 +28,7 @@
28 28
29/* standard i2c insmod options */ 29/* standard i2c insmod options */
30static unsigned short normal_i2c[] = { 30static unsigned short normal_i2c[] = {
31 0x4b, /* tda8290 */ 31 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
32 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 32 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
33 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 33 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
34 I2C_CLIENT_END 34 I2C_CLIENT_END