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 /* FIXME: European PAL/SECAM should select 9MHz Lowpass Filter, while
94 NTSC/M and PAL/M should be using 7MHz filter, by selecting CB3 */
95 static unsigned char i2c_cb3_9MHz
[2] = { 0xc0, 0x39 };
96 static unsigned char i2c_cb3_7MHz
[2] = { 0xc0, 0x3B };
98 static 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
},
105 static struct i2c_msg i2c_msg_prolog
[] = {
106 // { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_easy_mode), i2c_easy_mode },
107 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_gainset_off
), i2c_gainset_off
},
108 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_tda8290_reset
), i2c_tda8290_reset
},
109 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_enable_bridge
), i2c_enable_bridge
},
112 static struct i2c_msg i2c_msg_config
[] = {
113 // { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_set_freq), i2c_set_freq },
114 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_agc3_00
), i2c_agc3_00
},
115 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_agc2_BF
), i2c_agc2_BF
},
116 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_D2
), i2c_cb1_D2
},
117 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_56
), i2c_cb1_56
},
118 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_52
), i2c_cb1_52
},
121 static struct i2c_msg i2c_msg_epilog
[] = {
122 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_50
), i2c_cb1_50
},
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
},
129 static struct i2c_msg i2c_msg_standby
[] = {
130 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_enable_bridge
), i2c_enable_bridge
},
131 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_D0
), i2c_cb1_D0
},
132 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_disable_bridge
), i2c_disable_bridge
},
133 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_tda8290_standby
), i2c_tda8290_standby
},
136 static int tda8290_tune(struct i2c_client
*c
)
138 struct tuner
*t
= i2c_get_clientdata(c
);
139 struct i2c_msg easy_mode
=
140 { I2C_ADDR_TDA8290
, 0, 2, t
->i2c_easy_mode
};
141 struct i2c_msg set_freq
=
142 { I2C_ADDR_TDA8275
, 0, 8, t
->i2c_set_freq
};
144 i2c_transfer(c
->adapter
, &easy_mode
, 1);
145 i2c_transfer(c
->adapter
, i2c_msg_prolog
, ARRAY_SIZE(i2c_msg_prolog
));
147 i2c_transfer(c
->adapter
, &set_freq
, 1);
148 i2c_transfer(c
->adapter
, i2c_msg_config
, ARRAY_SIZE(i2c_msg_config
));
151 i2c_transfer(c
->adapter
, i2c_msg_epilog
, ARRAY_SIZE(i2c_msg_epilog
));
155 static void set_frequency(struct tuner
*t
, u16 ifc
, unsigned int freq
)
159 if (t
->mode
== V4L2_TUNER_RADIO
)
162 N
= (((freq
<<3)+ifc
)&0x3fffc);
164 N
= N
>> get_freq_entry(div_table
, freq
);
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;
175 #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)
177 #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
178 #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
180 static void set_audio(struct tuner
*t
)
182 t
->i2c_easy_mode
[0] = 0x01;
184 if (t
->std
& V4L2_STD_MN
) {
186 t
->i2c_easy_mode
[1] = 0x01;
187 } else if (t
->std
& V4L2_STD_B
) {
189 t
->i2c_easy_mode
[1] = 0x02;
190 } else if (t
->std
& V4L2_STD_GH
) {
192 t
->i2c_easy_mode
[1] = 0x04;
193 } else if (t
->std
& V4L2_STD_PAL_I
) {
195 t
->i2c_easy_mode
[1] = 0x08;
196 } else if (t
->std
& V4L2_STD_DK
) {
198 t
->i2c_easy_mode
[1] = 0x10;
199 } else if (t
->std
& V4L2_STD_SECAM_L
) {
201 t
->i2c_easy_mode
[1] = 0x20;
205 static void set_tv_freq(struct i2c_client
*c
, unsigned int freq
)
207 struct tuner
*t
= i2c_get_clientdata(c
);
210 set_frequency(t
, t
->sgIF
, freq
);
214 static void set_radio_freq(struct i2c_client
*c
, unsigned int freq
)
216 struct tuner
*t
= i2c_get_clientdata(c
);
217 set_frequency(t
, 704, freq
);
221 static int has_signal(struct i2c_client
*c
)
223 unsigned char i2c_get_afc
[1] = { 0x1B };
224 unsigned char afc
= 0;
226 i2c_master_send(c
, i2c_get_afc
, ARRAY_SIZE(i2c_get_afc
));
227 i2c_master_recv(c
, &afc
, 1);
228 return (afc
& 0x80)? 65535:0;
231 static void standby(struct i2c_client
*c
)
233 i2c_transfer(c
->adapter
, i2c_msg_standby
, ARRAY_SIZE(i2c_msg_standby
));
236 int tda8290_init(struct i2c_client
*c
)
238 struct tuner
*t
= i2c_get_clientdata(c
);
240 strlcpy(c
->name
, "tda8290+75", sizeof(c
->name
));
241 tuner_info("tuner: type set to %s\n", c
->name
);
242 t
->tv_freq
= set_tv_freq
;
243 t
->radio_freq
= set_radio_freq
;
244 t
->has_signal
= has_signal
;
245 t
->standby
= standby
;
247 i2c_master_send(c
, i2c_enable_bridge
, ARRAY_SIZE(i2c_enable_bridge
));
248 i2c_transfer(c
->adapter
, i2c_msg_init
, ARRAY_SIZE(i2c_msg_init
));
253 * Overrides for Emacs so that we follow Linus's tabbing style.
254 * ---------------------------------------------------------------------------