2 * $Id: tda8290.c,v 1.7 2005/03/07 12:01:51 kraxel Exp $
4 * i2c tv tuner chip device driver
5 * controls the philips tda8290+75 tuner chip combo.
8 #include <linux/videodev.h>
9 #include <linux/delay.h>
10 #include <media/tuner.h>
12 /* ---------------------------------------------------------------------- */
19 static struct freq_entry band_table
[] = {
38 { 0x05A4, 0xD8 }, // FM radio
41 { 0x0394, 0xF8 }, // 57250000 Hz
42 { 0x0000, 0xF0 }, // 0
45 static struct freq_entry div_table
[] = {
52 static struct freq_entry agc_table
[] = {
60 static __u8
get_freq_entry( struct freq_entry
* table
, __u16 freq
)
62 while(table
->freq
&& table
->freq
> freq
)
67 /* ---------------------------------------------------------------------- */
69 static unsigned char i2c_enable_bridge
[2] = { 0x21, 0xC0 };
70 static unsigned char i2c_disable_bridge
[2] = { 0x21, 0x80 };
71 static unsigned char i2c_init_tda8275
[14] = { 0x00, 0x00, 0x00, 0x00,
72 0x7C, 0x04, 0xA3, 0x3F,
73 0x2A, 0x04, 0xFF, 0x00,
75 static unsigned char i2c_set_VS
[2] = { 0x30, 0x6F };
76 static unsigned char i2c_set_GP01_CF
[2] = { 0x20, 0x0B };
77 static unsigned char i2c_tda8290_reset
[2] = { 0x00, 0x00 };
78 static unsigned char i2c_gainset_off
[2] = { 0x28, 0x14 };
79 static unsigned char i2c_gainset_on
[2] = { 0x28, 0x54 };
80 static unsigned char i2c_agc3_00
[2] = { 0x80, 0x00 };
81 static unsigned char i2c_agc2_BF
[2] = { 0x60, 0xBF };
82 static unsigned char i2c_cb1_D2
[2] = { 0x30, 0xD2 };
83 static unsigned char i2c_cb1_56
[2] = { 0x30, 0x56 };
84 static unsigned char i2c_cb1_52
[2] = { 0x30, 0x52 };
85 static unsigned char i2c_cb1_50
[2] = { 0x30, 0x50 };
86 static unsigned char i2c_agc2_7F
[2] = { 0x60, 0x7F };
87 static unsigned char i2c_agc3_08
[2] = { 0x80, 0x08 };
89 static struct i2c_msg i2c_msg_init
[] = {
90 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_init_tda8275
), i2c_init_tda8275
},
91 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_disable_bridge
), i2c_disable_bridge
},
92 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_set_VS
), i2c_set_VS
},
93 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_set_GP01_CF
), i2c_set_GP01_CF
},
96 static struct i2c_msg i2c_msg_prolog
[] = {
97 // { I2C_ADDR_TDA8290, 0, ARRAY_SIZE(i2c_easy_mode), i2c_easy_mode },
98 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_gainset_off
), i2c_gainset_off
},
99 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_tda8290_reset
), i2c_tda8290_reset
},
100 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_enable_bridge
), i2c_enable_bridge
},
103 static struct i2c_msg i2c_msg_config
[] = {
104 // { I2C_ADDR_TDA8275, 0, ARRAY_SIZE(i2c_set_freq), i2c_set_freq },
105 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_agc3_00
), i2c_agc3_00
},
106 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_agc2_BF
), i2c_agc2_BF
},
107 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_D2
), i2c_cb1_D2
},
108 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_56
), i2c_cb1_56
},
109 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_52
), i2c_cb1_52
},
112 static struct i2c_msg i2c_msg_epilog
[] = {
113 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_cb1_50
), i2c_cb1_50
},
114 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_agc2_7F
), i2c_agc2_7F
},
115 { I2C_ADDR_TDA8275
, 0, ARRAY_SIZE(i2c_agc3_08
), i2c_agc3_08
},
116 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_disable_bridge
), i2c_disable_bridge
},
117 { I2C_ADDR_TDA8290
, 0, ARRAY_SIZE(i2c_gainset_on
), i2c_gainset_on
},
120 static int tda8290_tune(struct i2c_client
*c
)
122 struct tuner
*t
= i2c_get_clientdata(c
);
123 struct i2c_msg easy_mode
=
124 { I2C_ADDR_TDA8290
, 0, 2, t
->i2c_easy_mode
};
125 struct i2c_msg set_freq
=
126 { I2C_ADDR_TDA8275
, 0, 8, t
->i2c_set_freq
};
128 i2c_transfer(c
->adapter
, &easy_mode
, 1);
129 i2c_transfer(c
->adapter
, i2c_msg_prolog
, ARRAY_SIZE(i2c_msg_prolog
));
131 i2c_transfer(c
->adapter
, &set_freq
, 1);
132 i2c_transfer(c
->adapter
, i2c_msg_config
, ARRAY_SIZE(i2c_msg_config
));
135 i2c_transfer(c
->adapter
, i2c_msg_epilog
, ARRAY_SIZE(i2c_msg_epilog
));
139 static void set_frequency(struct tuner
*t
, u16 ifc
)
141 u32 N
= (((t
->freq
<<3)+ifc
)&0x3fffc);
143 N
= N
>> get_freq_entry(div_table
, t
->freq
);
144 t
->i2c_set_freq
[0] = 0;
145 t
->i2c_set_freq
[1] = (unsigned char)(N
>>8);
146 t
->i2c_set_freq
[2] = (unsigned char) N
;
147 t
->i2c_set_freq
[3] = 0x40;
148 t
->i2c_set_freq
[4] = 0x52;
149 t
->i2c_set_freq
[5] = get_freq_entry(band_table
, t
->freq
);
150 t
->i2c_set_freq
[6] = get_freq_entry(agc_table
, t
->freq
);
151 t
->i2c_set_freq
[7] = 0x8f;
154 #define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
155 #define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
156 #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
157 #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
159 static void set_audio(struct tuner
*t
)
161 t
->i2c_easy_mode
[0] = 0x01;
163 if (t
->std
& V4L2_STD_MN
)
164 t
->i2c_easy_mode
[1] = 0x01;
165 else if (t
->std
& V4L2_STD_B
)
166 t
->i2c_easy_mode
[1] = 0x02;
167 else if (t
->std
& V4L2_STD_GH
)
168 t
->i2c_easy_mode
[1] = 0x04;
169 else if (t
->std
& V4L2_STD_PAL_I
)
170 t
->i2c_easy_mode
[1] = 0x08;
171 else if (t
->std
& V4L2_STD_DK
)
172 t
->i2c_easy_mode
[1] = 0x10;
173 else if (t
->std
& V4L2_STD_SECAM_L
)
174 t
->i2c_easy_mode
[1] = 0x20;
177 static void set_tv_freq(struct i2c_client
*c
, unsigned int freq
)
179 struct tuner
*t
= i2c_get_clientdata(c
);
182 set_frequency(t
, 864);
186 static void set_radio_freq(struct i2c_client
*c
, unsigned int freq
)
188 struct tuner
*t
= i2c_get_clientdata(c
);
189 set_frequency(t
, 704);
193 static int has_signal(struct i2c_client
*c
)
195 unsigned char i2c_get_afc
[1] = { 0x1B };
196 unsigned char afc
= 0;
198 i2c_master_send(c
, i2c_get_afc
, ARRAY_SIZE(i2c_get_afc
));
199 i2c_master_recv(c
, &afc
, 1);
200 return (afc
& 0x80)? 65535:0;
203 int tda8290_init(struct i2c_client
*c
)
205 struct tuner
*t
= i2c_get_clientdata(c
);
207 strlcpy(c
->name
, "tda8290+75", sizeof(c
->name
));
208 tuner_info("tuner: type set to %s\n", c
->name
);
209 t
->tv_freq
= set_tv_freq
;
210 t
->radio_freq
= set_radio_freq
;
211 t
->has_signal
= has_signal
;
213 i2c_master_send(c
, i2c_enable_bridge
, ARRAY_SIZE(i2c_enable_bridge
));
214 i2c_transfer(c
->adapter
, i2c_msg_init
, ARRAY_SIZE(i2c_msg_init
));
219 * Overrides for Emacs so that we follow Linus's tabbing style.
220 * ---------------------------------------------------------------------------