2 * $Id: tda8290.c,v 1.15 2005/07/08 20:21:33 mchehab 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 0xfC, 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, unsigned int freq)
143 if (t->mode == V4L2_TUNER_RADIO)
146 N = (((freq<<3)+ifc)&0x3fffc);
148 N = N >> get_freq_entry(div_table, freq);
149 t->i2c_set_freq[0] = 0;
150 t->i2c_set_freq[1] = (unsigned char)(N>>8);
151 t->i2c_set_freq[2] = (unsigned char) N;
152 t->i2c_set_freq[3] = 0x40;
153 t->i2c_set_freq[4] = 0x52;
154 t->i2c_set_freq[5] = get_freq_entry(band_table, freq);
155 t->i2c_set_freq[6] = get_freq_entry(agc_table, freq);
156 t->i2c_set_freq[7] = 0x8f;
159 #define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC)
160 #define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B)
161 #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H)
162 #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)
164 static void set_audio(struct tuner *t)
166 t->i2c_easy_mode[0] = 0x01;
168 if (t->std & V4L2_STD_MN)
169 t->i2c_easy_mode[1] = 0x01;
170 else if (t->std & V4L2_STD_B)
171 t->i2c_easy_mode[1] = 0x02;
172 else if (t->std & V4L2_STD_GH)
173 t->i2c_easy_mode[1] = 0x04;
174 else if (t->std & V4L2_STD_PAL_I)
175 t->i2c_easy_mode[1] = 0x08;
176 else if (t->std & V4L2_STD_DK)
177 t->i2c_easy_mode[1] = 0x10;
178 else if (t->std & V4L2_STD_SECAM_L)
179 t->i2c_easy_mode[1] = 0x20;
182 static void set_tv_freq(struct i2c_client *c, unsigned int freq)
184 struct tuner *t = i2c_get_clientdata(c);
187 set_frequency(t, 864, freq);
191 static void set_radio_freq(struct i2c_client *c, unsigned int freq)
193 struct tuner *t = i2c_get_clientdata(c);
194 set_frequency(t, 704, freq);
198 static int has_signal(struct i2c_client *c)
200 unsigned char i2c_get_afc[1] = { 0x1B };
201 unsigned char afc = 0;
203 i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
204 i2c_master_recv(c, &afc, 1);
205 return (afc & 0x80)? 65535:0;
208 int tda8290_init(struct i2c_client *c)
210 struct tuner *t = i2c_get_clientdata(c);
212 strlcpy(c->name, "tda8290+75", sizeof(c->name));
213 tuner_info("tuner: type set to %s\n", c->name);
214 t->tv_freq = set_tv_freq;
215 t->radio_freq = set_radio_freq;
216 t->has_signal = has_signal;
218 i2c_master_send(c, i2c_enable_bridge, ARRAY_SIZE(i2c_enable_bridge));
219 i2c_transfer(c->adapter, i2c_msg_init, ARRAY_SIZE(i2c_msg_init));
224 * Overrides for Emacs so that we follow Linus's tabbing style.
225 * ---------------------------------------------------------------------------