3 * i2c tv tuner chip device driver
4 * controls the philips tda8290+75 tuner chip combo.
7 #include <linux/videodev.h>
8 #include <linux/delay.h>
9 #include <media/tuner.h>
11 #define I2C_ADDR_TDA8290 0x4b
12 #define I2C_ADDR_TDA8275 0x61
14 /* ---------------------------------------------------------------------- */
21 static struct freq_entry band_table[] = {
40 { 0x05A4, 0xD8 }, // FM radio
43 { 0x0394, 0xF8 }, // 57250000 Hz
44 { 0x0000, 0xF0 }, // 0
47 static struct freq_entry div_table[] = {
54 static struct freq_entry agc_table[] = {
62 static __u8 get_freq_entry( struct freq_entry* table, __u16 freq)
64 while(table->freq && table->freq > freq)
69 /* ---------------------------------------------------------------------- */
71 static unsigned char i2c_enable_bridge[2] = { 0x21, 0xC0 };
72 static unsigned char i2c_disable_bridge[2] = { 0x21, 0x80 };
73 static unsigned char i2c_init_tda8275[14] = { 0x00, 0x00, 0x00, 0x00,
74 0xfC, 0x04, 0xA3, 0x3F,
75 0x2A, 0x04, 0xFF, 0x00,
77 static unsigned char i2c_set_VS[2] = { 0x30, 0x6F };
78 static unsigned char i2c_set_GP01_CF[2] = { 0x20, 0x0B };
79 static unsigned char i2c_tda8290_reset[2] = { 0x00, 0x00 };
80 static unsigned char i2c_tda8290_standby[2] = { 0x00, 0x02 };
81 static unsigned char i2c_gainset_off[2] = { 0x28, 0x14 };
82 static unsigned char i2c_gainset_on[2] = { 0x28, 0x54 };
83 static unsigned char i2c_agc3_00[2] = { 0x80, 0x00 };
84 static unsigned char i2c_agc2_BF[2] = { 0x60, 0xBF };
85 static unsigned char i2c_cb1_D0[2] = { 0x30, 0xD0 };
86 static unsigned char i2c_cb1_D2[2] = { 0x30, 0xD2 };
87 static unsigned char i2c_cb1_56[2] = { 0x30, 0x56 };
88 static unsigned char i2c_cb1_52[2] = { 0x30, 0x52 };
89 static unsigned char i2c_cb1_50[2] = { 0x30, 0x50 };
90 static unsigned char i2c_agc2_7F[2] = { 0x60, 0x7F };
91 static unsigned char i2c_agc3_08[2] = { 0x80, 0x08 };
93 static struct i2c_msg i2c_msg_init[] = {
94 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_init_tda8275), i2c_init_tda8275 },
95 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
96 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_VS), i2c_set_VS },
97 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_set_GP01_CF), i2c_set_GP01_CF },
100 static struct i2c_msg i2c_msg_prolog[] = {
101 // { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_easy_mode), i2c_easy_mode },
102 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_off), i2c_gainset_off },
103 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_reset), i2c_tda8290_reset },
104 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge },
107 static struct i2c_msg i2c_msg_config[] = {
108 // { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_set_freq), i2c_set_freq },
109 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_00), i2c_agc3_00 },
110 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_BF), i2c_agc2_BF },
111 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D2), i2c_cb1_D2 },
112 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_56), i2c_cb1_56 },
113 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_52), i2c_cb1_52 },
116 static struct i2c_msg i2c_msg_epilog[] = {
117 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_50), i2c_cb1_50 },
118 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc2_7F), i2c_agc2_7F },
119 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_agc3_08), i2c_agc3_08 },
120 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
121 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_gainset_on), i2c_gainset_on },
124 static struct i2c_msg i2c_msg_standby[] = {
125 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_enable_bridge), i2c_enable_bridge },
126 { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_cb1_D0), i2c_cb1_D0 },
127 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_disable_bridge), i2c_disable_bridge },
128 { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_tda8290_standby), i2c_tda8290_standby },
131 static int tda8290_tune(struct i2c_client *c)
133 struct tuner *t = i2c_get_clientdata(c);
134 struct i2c_msg easy_mode =
135 { I2C_ADDR_TDA8290, 0, 2, t->i2c_easy_mode };
136 struct i2c_msg set_freq =
137 { I2C_ADDR_TDA8275, 0, 8, t->i2c_set_freq };
139 i2c_transfer(c->adapter, &easy_mode, 1);
140 i2c_transfer(c->adapter, i2c_msg_prolog, ARRAY_SIZE(i2c_msg_prolog));
142 i2c_transfer(c->adapter, &set_freq, 1);
143 i2c_transfer(c->adapter, i2c_msg_config, ARRAY_SIZE(i2c_msg_config));
146 i2c_transfer(c->adapter, i2c_msg_epilog, ARRAY_SIZE(i2c_msg_epilog));
150 static void set_frequency(struct tuner *t, u16 ifc, unsigned int freq)
154 if (t->mode == V4L2_TUNER_RADIO)
157 N = (((freq<<3)+ifc)&0x3fffc);
159 N = N >> get_freq_entry(div_table, freq);
160 t->i2c_set_freq[0] = 0;
161 t->i2c_set_freq[1] = (unsigned char)(N>>8);
162 t->i2c_set_freq[2] = (unsigned char) N;
163 t->i2c_set_freq[3] = 0x40;
164 t->i2c_set_freq[4] = 0x52;
165 t->i2c_set_freq[5] = get_freq_entry(band_table, freq);
166 t->i2c_set_freq[6] = get_freq_entry(agc_table, freq);
167 t->i2c_set_freq[7] = 0x8f;
170 #define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
171 #define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
172 #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
173 #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
175 static void set_audio(struct tuner *t)
177 t->i2c_easy_mode[0] = 0x01;
179 if (t->std & V4L2_STD_MN)
180 t->i2c_easy_mode[1] = 0x01;
181 else if (t->std & V4L2_STD_B)
182 t->i2c_easy_mode[1] = 0x02;
183 else if (t->std & V4L2_STD_GH)
184 t->i2c_easy_mode[1] = 0x04;
185 else if (t->std & V4L2_STD_PAL_I)
186 t->i2c_easy_mode[1] = 0x08;
187 else if (t->std & V4L2_STD_DK)
188 t->i2c_easy_mode[1] = 0x10;
189 else if (t->std & V4L2_STD_SECAM_L)
190 t->i2c_easy_mode[1] = 0x20;
193 static void set_tv_freq(struct i2c_client *c, unsigned int freq)
195 struct tuner *t = i2c_get_clientdata(c);
198 set_frequency(t, 864, freq);
202 static void set_radio_freq(struct i2c_client *c, unsigned int freq)
204 struct tuner *t = i2c_get_clientdata(c);
205 set_frequency(t, 704, freq);
209 static int has_signal(struct i2c_client *c)
211 unsigned char i2c_get_afc[1] = { 0x1B };
212 unsigned char afc = 0;
214 i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
215 i2c_master_recv(c, &afc, 1);
216 return (afc & 0x80)? 65535:0;
219 static void standby(struct i2c_client *c)
221 i2c_transfer(c->adapter, i2c_msg_standby, ARRAY_SIZE(i2c_msg_standby));
224 int tda8290_init(struct i2c_client *c)
226 struct tuner *t = i2c_get_clientdata(c);
228 strlcpy(c->name, "tda8290+75", sizeof(c->name));
229 tuner_info("tuner: type set to %s\n", c->name);
230 t->tv_freq = set_tv_freq;
231 t->radio_freq = set_radio_freq;
232 t->has_signal = has_signal;
233 t->standby = standby;
235 i2c_master_send(c, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge));
236 i2c_transfer(c->adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init));
241 * Overrides for Emacs so that we follow Linus's tabbing style.
242 * ---------------------------------------------------------------------------