aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tda8290.c
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2007-08-21 00:24:42 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-10-09 21:07:34 -0400
commitdb8a695658cda21eacfa2a5e3b15e8964bfb93ef (patch)
treeac69f32af5b52f78ad65ad1125d330aa19c7bdda /drivers/media/video/tda8290.c
parent293197cd0f34eb6bfb5492a63a878575b69e9df4 (diff)
V4L/DVB (6127): tuner: kill i2c_client interface to tuner sub-drivers
To ease the conversion of the analog tuner sub-drivers into dvb_frontend style tuner modules, we must remove the i2c_client interface. dvb_frontend style tuner modules use i2c_transfer directly on the i2c_adapter. This change only alters the interface between tuner.ko and the tuner sub-drivers. The v4l2 / i2c_client interface to tuner.ko remains intact. This patch adds inline functions tuner_i2c_xfer_send, and tuner_i2c_xfer_recv, to replace i2c_master_send and i2c_master_recv inside the tuner sub-drivers. Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Acked-by: Hans Verkuil <hverkuil@xs4all.nl> Acked-by: Mike Isely <isely@pobox.com> Acked-by: Steven Toth <stoth@hauppauge.com> Acked-by: Patrick Boettcher <pb@linuxtv.org> Acked-by: Jarod Wilson <jwilson@redhat.com> Acked-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/tda8290.c')
-rw-r--r--drivers/media/video/tda8290.c247
1 files changed, 124 insertions, 123 deletions
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index 760d22f65da2..beb4a7e1d286 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -26,6 +26,8 @@
26/* ---------------------------------------------------------------------- */ 26/* ---------------------------------------------------------------------- */
27 27
28struct tda8290_priv { 28struct tda8290_priv {
29 struct tuner_i2c_props i2c_props;
30
29 unsigned char tda8290_easy_mode; 31 unsigned char tda8290_easy_mode;
30 unsigned char tda827x_lpsel; 32 unsigned char tda827x_lpsel;
31 unsigned char tda827x_addr; 33 unsigned char tda827x_addr;
@@ -79,13 +81,12 @@ static struct tda827x_data tda827x_analog[] = {
79 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */ 81 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */
80}; 82};
81 83
82static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 84static void tda827x_tune(struct tuner *t, u16 ifc, unsigned int freq)
83{ 85{
84 unsigned char tuner_reg[8]; 86 unsigned char tuner_reg[8];
85 unsigned char reg2[2]; 87 unsigned char reg2[2];
86 u32 N; 88 u32 N;
87 int i; 89 int i;
88 struct tuner *t = i2c_get_clientdata(c);
89 struct tda8290_priv *priv = t->priv; 90 struct tda8290_priv *priv = t->priv;
90 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0}; 91 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0};
91 92
@@ -114,54 +115,53 @@ static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
114 115
115 msg.buf = tuner_reg; 116 msg.buf = tuner_reg;
116 msg.len = 8; 117 msg.len = 8;
117 i2c_transfer(c->adapter, &msg, 1); 118 i2c_transfer(priv->i2c_props.adap, &msg, 1);
118 119
119 msg.buf= reg2; 120 msg.buf= reg2;
120 msg.len = 2; 121 msg.len = 2;
121 reg2[0] = 0x80; 122 reg2[0] = 0x80;
122 reg2[1] = 0; 123 reg2[1] = 0;
123 i2c_transfer(c->adapter, &msg, 1); 124 i2c_transfer(priv->i2c_props.adap, &msg, 1);
124 125
125 reg2[0] = 0x60; 126 reg2[0] = 0x60;
126 reg2[1] = 0xbf; 127 reg2[1] = 0xbf;
127 i2c_transfer(c->adapter, &msg, 1); 128 i2c_transfer(priv->i2c_props.adap, &msg, 1);
128 129
129 reg2[0] = 0x30; 130 reg2[0] = 0x30;
130 reg2[1] = tuner_reg[4] + 0x80; 131 reg2[1] = tuner_reg[4] + 0x80;
131 i2c_transfer(c->adapter, &msg, 1); 132 i2c_transfer(priv->i2c_props.adap, &msg, 1);
132 133
133 msleep(1); 134 msleep(1);
134 reg2[0] = 0x30; 135 reg2[0] = 0x30;
135 reg2[1] = tuner_reg[4] + 4; 136 reg2[1] = tuner_reg[4] + 4;
136 i2c_transfer(c->adapter, &msg, 1); 137 i2c_transfer(priv->i2c_props.adap, &msg, 1);
137 138
138 msleep(1); 139 msleep(1);
139 reg2[0] = 0x30; 140 reg2[0] = 0x30;
140 reg2[1] = tuner_reg[4]; 141 reg2[1] = tuner_reg[4];
141 i2c_transfer(c->adapter, &msg, 1); 142 i2c_transfer(priv->i2c_props.adap, &msg, 1);
142 143
143 msleep(550); 144 msleep(550);
144 reg2[0] = 0x30; 145 reg2[0] = 0x30;
145 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ; 146 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ;
146 i2c_transfer(c->adapter, &msg, 1); 147 i2c_transfer(priv->i2c_props.adap, &msg, 1);
147 148
148 reg2[0] = 0x60; 149 reg2[0] = 0x60;
149 reg2[1] = 0x3f; 150 reg2[1] = 0x3f;
150 i2c_transfer(c->adapter, &msg, 1); 151 i2c_transfer(priv->i2c_props.adap, &msg, 1);
151 152
152 reg2[0] = 0x80; 153 reg2[0] = 0x80;
153 reg2[1] = 0x08; // Vsync en 154 reg2[1] = 0x08; // Vsync en
154 i2c_transfer(c->adapter, &msg, 1); 155 i2c_transfer(priv->i2c_props.adap, &msg, 1);
155} 156}
156 157
157static void tda827x_agcf(struct i2c_client *c) 158static void tda827x_agcf(struct tuner *t)
158{ 159{
159 struct tuner *t = i2c_get_clientdata(c);
160 struct tda8290_priv *priv = t->priv; 160 struct tda8290_priv *priv = t->priv;
161 unsigned char data[] = {0x80, 0x0c}; 161 unsigned char data[] = {0x80, 0x0c};
162 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data, 162 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
163 .flags = 0, .len = 2}; 163 .flags = 0, .len = 2};
164 i2c_transfer(c->adapter, &msg, 1); 164 i2c_transfer(priv->i2c_props.adap, &msg, 1);
165} 165}
166 166
167/* ---------------------------------------------------------------------- */ 167/* ---------------------------------------------------------------------- */
@@ -204,12 +204,12 @@ static struct tda827xa_data tda827xa_analog[] = {
204 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */ 204 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */
205}; 205};
206 206
207static void tda827xa_lna_gain(struct i2c_client *c, int high) 207static void tda827xa_lna_gain(struct tuner *t, int high)
208{ 208{
209 struct tuner *t = i2c_get_clientdata(c); 209 struct tda8290_priv *priv = t->priv;
210 unsigned char buf[] = {0x22, 0x01}; 210 unsigned char buf[] = {0x22, 0x01};
211 int arg; 211 int arg;
212 struct i2c_msg msg = {.addr = c->addr, .flags = 0, .buf = buf, .len = sizeof(buf)}; 212 struct i2c_msg msg = {.addr = priv->i2c_props.addr, .flags = 0, .buf = buf, .len = sizeof(buf)};
213 if (t->config) { 213 if (t->config) {
214 if (high) 214 if (high)
215 tuner_dbg("setting LNA to high gain\n"); 215 tuner_dbg("setting LNA to high gain\n");
@@ -227,29 +227,28 @@ static void tda827xa_lna_gain(struct i2c_client *c, int high)
227 else 227 else
228 arg = 0; 228 arg = 0;
229 if (t->tuner_callback) 229 if (t->tuner_callback)
230 t->tuner_callback(c->adapter->algo_data, 1, arg); 230 t->tuner_callback(priv->i2c_props.adap->algo_data, 1, arg);
231 buf[1] = high ? 0 : 1; 231 buf[1] = high ? 0 : 1;
232 if (t->config == 2) 232 if (t->config == 2)
233 buf[1] = high ? 1 : 0; 233 buf[1] = high ? 1 : 0;
234 i2c_transfer(c->adapter, &msg, 1); 234 i2c_transfer(priv->i2c_props.adap, &msg, 1);
235 break; 235 break;
236 case 3: /* switch with GPIO of saa713x */ 236 case 3: /* switch with GPIO of saa713x */
237 if (t->tuner_callback) 237 if (t->tuner_callback)
238 t->tuner_callback(c->adapter->algo_data, 0, high); 238 t->tuner_callback(priv->i2c_props.adap->algo_data, 0, high);
239 break; 239 break;
240 } 240 }
241} 241}
242 242
243static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 243static void tda827xa_tune(struct tuner *t, u16 ifc, unsigned int freq)
244{ 244{
245 unsigned char tuner_reg[11]; 245 unsigned char tuner_reg[11];
246 u32 N; 246 u32 N;
247 int i; 247 int i;
248 struct tuner *t = i2c_get_clientdata(c);
249 struct tda8290_priv *priv = t->priv; 248 struct tda8290_priv *priv = t->priv;
250 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg}; 249 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg};
251 250
252 tda827xa_lna_gain( c, 1); 251 tda827xa_lna_gain(t, 1);
253 msleep(10); 252 msleep(10);
254 253
255 if (t->mode == V4L2_TUNER_RADIO) 254 if (t->mode == V4L2_TUNER_RADIO)
@@ -278,7 +277,7 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
278 tuner_reg[9] = 0x20; 277 tuner_reg[9] = 0x20;
279 tuner_reg[10] = 0x00; 278 tuner_reg[10] = 0x00;
280 msg.len = 11; 279 msg.len = 11;
281 i2c_transfer(c->adapter, &msg, 1); 280 i2c_transfer(priv->i2c_props.adap, &msg, 1);
282 281
283 tuner_reg[0] = 0x90; 282 tuner_reg[0] = 0x90;
284 tuner_reg[1] = 0xff; 283 tuner_reg[1] = 0xff;
@@ -286,81 +285,81 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
286 tuner_reg[3] = 0; 285 tuner_reg[3] = 0;
287 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1); 286 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1);
288 msg.len = 5; 287 msg.len = 5;
289 i2c_transfer(c->adapter, &msg, 1); 288 i2c_transfer(priv->i2c_props.adap, &msg, 1);
290 289
291 tuner_reg[0] = 0xa0; 290 tuner_reg[0] = 0xa0;
292 tuner_reg[1] = 0xc0; 291 tuner_reg[1] = 0xc0;
293 msg.len = 2; 292 msg.len = 2;
294 i2c_transfer(c->adapter, &msg, 1); 293 i2c_transfer(priv->i2c_props.adap, &msg, 1);
295 294
296 tuner_reg[0] = 0x30; 295 tuner_reg[0] = 0x30;
297 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr; 296 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
298 i2c_transfer(c->adapter, &msg, 1); 297 i2c_transfer(priv->i2c_props.adap, &msg, 1);
299 298
300 msg.flags = I2C_M_RD; 299 msg.flags = I2C_M_RD;
301 i2c_transfer(c->adapter, &msg, 1); 300 i2c_transfer(priv->i2c_props.adap, &msg, 1);
302 msg.flags = 0; 301 msg.flags = 0;
303 tuner_reg[1] >>= 4; 302 tuner_reg[1] >>= 4;
304 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]); 303 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]);
305 if (tuner_reg[1] < 1) 304 if (tuner_reg[1] < 1)
306 tda827xa_lna_gain( c, 0); 305 tda827xa_lna_gain(t, 0);
307 306
308 msleep(100); 307 msleep(100);
309 tuner_reg[0] = 0x60; 308 tuner_reg[0] = 0x60;
310 tuner_reg[1] = 0x3c; 309 tuner_reg[1] = 0x3c;
311 i2c_transfer(c->adapter, &msg, 1); 310 i2c_transfer(priv->i2c_props.adap, &msg, 1);
312 311
313 msleep(163); 312 msleep(163);
314 tuner_reg[0] = 0x50; 313 tuner_reg[0] = 0x50;
315 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); 314 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
316 i2c_transfer(c->adapter, &msg, 1); 315 i2c_transfer(priv->i2c_props.adap, &msg, 1);
317 316
318 tuner_reg[0] = 0x80; 317 tuner_reg[0] = 0x80;
319 tuner_reg[1] = 0x28; 318 tuner_reg[1] = 0x28;
320 i2c_transfer(c->adapter, &msg, 1); 319 i2c_transfer(priv->i2c_props.adap, &msg, 1);
321 320
322 tuner_reg[0] = 0xb0; 321 tuner_reg[0] = 0xb0;
323 tuner_reg[1] = 0x01; 322 tuner_reg[1] = 0x01;
324 i2c_transfer(c->adapter, &msg, 1); 323 i2c_transfer(priv->i2c_props.adap, &msg, 1);
325 324
326 tuner_reg[0] = 0xc0; 325 tuner_reg[0] = 0xc0;
327 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1); 326 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1);
328 i2c_transfer(c->adapter, &msg, 1); 327 i2c_transfer(priv->i2c_props.adap, &msg, 1);
329} 328}
330 329
331static void tda827xa_agcf(struct i2c_client *c) 330static void tda827xa_agcf(struct tuner *t)
332{ 331{
333 struct tuner *t = i2c_get_clientdata(c);
334 struct tda8290_priv *priv = t->priv; 332 struct tda8290_priv *priv = t->priv;
335 unsigned char data[] = {0x80, 0x2c}; 333 unsigned char data[] = {0x80, 0x2c};
336 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data, 334 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
337 .flags = 0, .len = 2}; 335 .flags = 0, .len = 2};
338 i2c_transfer(c->adapter, &msg, 1); 336 i2c_transfer(priv->i2c_props.adap, &msg, 1);
339} 337}
340 338
341/*---------------------------------------------------------------------*/ 339/*---------------------------------------------------------------------*/
342 340
343static void tda8290_i2c_bridge(struct i2c_client *c, int close) 341static void tda8290_i2c_bridge(struct tuner *t, int close)
344{ 342{
343 struct tda8290_priv *priv = t->priv;
344
345 unsigned char enable[2] = { 0x21, 0xC0 }; 345 unsigned char enable[2] = { 0x21, 0xC0 };
346 unsigned char disable[2] = { 0x21, 0x00 }; 346 unsigned char disable[2] = { 0x21, 0x00 };
347 unsigned char *msg; 347 unsigned char *msg;
348 if(close) { 348 if(close) {
349 msg = enable; 349 msg = enable;
350 i2c_master_send(c, msg, 2); 350 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
351 /* let the bridge stabilize */ 351 /* let the bridge stabilize */
352 msleep(20); 352 msleep(20);
353 } else { 353 } else {
354 msg = disable; 354 msg = disable;
355 i2c_master_send(c, msg, 2); 355 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
356 } 356 }
357} 357}
358 358
359/*---------------------------------------------------------------------*/ 359/*---------------------------------------------------------------------*/
360 360
361static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 361static int tda8290_tune(struct tuner *t, u16 ifc, unsigned int freq)
362{ 362{
363 struct tuner *t = i2c_get_clientdata(c);
364 struct tda8290_priv *priv = t->priv; 363 struct tda8290_priv *priv = t->priv;
365 unsigned char soft_reset[] = { 0x00, 0x00 }; 364 unsigned char soft_reset[] = { 0x00, 0x00 };
366 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode }; 365 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
@@ -385,34 +384,34 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
385 int i; 384 int i;
386 385
387 tuner_dbg("tda827xa config is 0x%02x\n", t->config); 386 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
388 i2c_master_send(c, easy_mode, 2); 387 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
389 i2c_master_send(c, agc_out_on, 2); 388 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
390 i2c_master_send(c, soft_reset, 2); 389 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
391 msleep(1); 390 msleep(1);
392 391
393 expert_mode[1] = priv->tda8290_easy_mode + 0x80; 392 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
394 i2c_master_send(c, expert_mode, 2); 393 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
395 i2c_master_send(c, gainset_off, 2); 394 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
396 i2c_master_send(c, if_agc_spd, 2); 395 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
397 if (priv->tda8290_easy_mode & 0x60) 396 if (priv->tda8290_easy_mode & 0x60)
398 i2c_master_send(c, adc_head_9, 2); 397 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
399 else 398 else
400 i2c_master_send(c, adc_head_6, 2); 399 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
401 i2c_master_send(c, pll_bw_nom, 2); 400 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
402 401
403 tda8290_i2c_bridge(c, 1); 402 tda8290_i2c_bridge(t, 1);
404 if (priv->tda827x_ver != 0) 403 if (priv->tda827x_ver != 0)
405 tda827xa_tune(c, ifc, freq); 404 tda827xa_tune(t, ifc, freq);
406 else 405 else
407 tda827x_tune(c, ifc, freq); 406 tda827x_tune(t, ifc, freq);
408 for (i = 0; i < 3; i++) { 407 for (i = 0; i < 3; i++) {
409 i2c_master_send(c, &addr_pll_stat, 1); 408 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
410 i2c_master_recv(c, &pll_stat, 1); 409 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
411 if (pll_stat & 0x80) { 410 if (pll_stat & 0x80) {
412 i2c_master_send(c, &addr_adc_sat, 1); 411 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
413 i2c_master_recv(c, &adc_sat, 1); 412 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
414 i2c_master_send(c, &addr_agc_stat, 1); 413 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
415 i2c_master_recv(c, &agc_stat, 1); 414 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
416 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); 415 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
417 break; 416 break;
418 } else { 417 } else {
@@ -424,28 +423,28 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
424 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { 423 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
425 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", 424 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
426 agc_stat, adc_sat, pll_stat & 0x80); 425 agc_stat, adc_sat, pll_stat & 0x80);
427 i2c_master_send(c, gainset_2, 2); 426 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
428 msleep(100); 427 msleep(100);
429 i2c_master_send(c, &addr_agc_stat, 1); 428 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
430 i2c_master_recv(c, &agc_stat, 1); 429 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
431 i2c_master_send(c, &addr_pll_stat, 1); 430 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
432 i2c_master_recv(c, &pll_stat, 1); 431 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
433 if ((agc_stat > 115) || !(pll_stat & 0x80)) { 432 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
434 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", 433 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
435 agc_stat, pll_stat & 0x80); 434 agc_stat, pll_stat & 0x80);
436 if (priv->tda827x_ver != 0) 435 if (priv->tda827x_ver != 0)
437 tda827xa_agcf(c); 436 tda827xa_agcf(t);
438 else 437 else
439 tda827x_agcf(c); 438 tda827x_agcf(t);
440 msleep(100); 439 msleep(100);
441 i2c_master_send(c, &addr_agc_stat, 1); 440 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
442 i2c_master_recv(c, &agc_stat, 1); 441 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
443 i2c_master_send(c, &addr_pll_stat, 1); 442 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
444 i2c_master_recv(c, &pll_stat, 1); 443 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
445 if((agc_stat > 115) || !(pll_stat & 0x80)) { 444 if((agc_stat > 115) || !(pll_stat & 0x80)) {
446 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); 445 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
447 i2c_master_send(c, adc_head_12, 2); 446 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
448 i2c_master_send(c, pll_bw_low, 2); 447 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
449 msleep(100); 448 msleep(100);
450 } 449 }
451 } 450 }
@@ -453,20 +452,20 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
453 452
454 /* l/ l' deadlock? */ 453 /* l/ l' deadlock? */
455 if(priv->tda8290_easy_mode & 0x60) { 454 if(priv->tda8290_easy_mode & 0x60) {
456 i2c_master_send(c, &addr_adc_sat, 1); 455 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
457 i2c_master_recv(c, &adc_sat, 1); 456 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
458 i2c_master_send(c, &addr_pll_stat, 1); 457 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
459 i2c_master_recv(c, &pll_stat, 1); 458 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
460 if ((adc_sat > 20) || !(pll_stat & 0x80)) { 459 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
461 tuner_dbg("trying to resolve SECAM L deadlock\n"); 460 tuner_dbg("trying to resolve SECAM L deadlock\n");
462 i2c_master_send(c, agc_rst_on, 2); 461 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
463 msleep(40); 462 msleep(40);
464 i2c_master_send(c, agc_rst_off, 2); 463 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
465 } 464 }
466 } 465 }
467 466
468 tda8290_i2c_bridge(c, 0); 467 tda8290_i2c_bridge(t, 0);
469 i2c_master_send(c, if_agc_set, 2); 468 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
470 return 0; 469 return 0;
471} 470}
472 471
@@ -515,69 +514,69 @@ static void set_audio(struct tuner *t)
515 tuner_dbg("setting tda8290 to system %s\n", mode); 514 tuner_dbg("setting tda8290 to system %s\n", mode);
516} 515}
517 516
518static void set_tv_freq(struct i2c_client *c, unsigned int freq) 517static void set_tv_freq(struct tuner *t, unsigned int freq)
519{ 518{
520 struct tuner *t = i2c_get_clientdata(c);
521 struct tda8290_priv *priv = t->priv; 519 struct tda8290_priv *priv = t->priv;
522 520
523 set_audio(t); 521 set_audio(t);
524 tda8290_tune(c, priv->sgIF, freq); 522 tda8290_tune(t, priv->sgIF, freq);
525} 523}
526 524
527static void set_radio_freq(struct i2c_client *c, unsigned int freq) 525static void set_radio_freq(struct tuner *t, unsigned int freq)
528{ 526{
529 /* if frequency is 5.5 MHz */ 527 /* if frequency is 5.5 MHz */
530 tda8290_tune(c, 88, freq); 528 tda8290_tune(t, 88, freq);
531} 529}
532 530
533static int has_signal(struct i2c_client *c) 531static int has_signal(struct tuner *t)
534{ 532{
533 struct tda8290_priv *priv = t->priv;
534
535 unsigned char i2c_get_afc[1] = { 0x1B }; 535 unsigned char i2c_get_afc[1] = { 0x1B };
536 unsigned char afc = 0; 536 unsigned char afc = 0;
537 537
538 i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); 538 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
539 i2c_master_recv(c, &afc, 1); 539 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
540 return (afc & 0x80)? 65535:0; 540 return (afc & 0x80)? 65535:0;
541} 541}
542 542
543/*---------------------------------------------------------------------*/ 543/*---------------------------------------------------------------------*/
544 544
545static void standby(struct i2c_client *c) 545static void standby(struct tuner *t)
546{ 546{
547 struct tuner *t = i2c_get_clientdata(c);
548 struct tda8290_priv *priv = t->priv; 547 struct tda8290_priv *priv = t->priv;
549 unsigned char cb1[] = { 0x30, 0xD0 }; 548 unsigned char cb1[] = { 0x30, 0xD0 };
550 unsigned char tda8290_standby[] = { 0x00, 0x02 }; 549 unsigned char tda8290_standby[] = { 0x00, 0x02 };
551 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; 550 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
552 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 551 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
553 552
554 tda8290_i2c_bridge(c, 1); 553 tda8290_i2c_bridge(t, 1);
555 if (priv->tda827x_ver != 0) 554 if (priv->tda827x_ver != 0)
556 cb1[1] = 0x90; 555 cb1[1] = 0x90;
557 i2c_transfer(c->adapter, &msg, 1); 556 i2c_transfer(priv->i2c_props.adap, &msg, 1);
558 tda8290_i2c_bridge(c, 0); 557 tda8290_i2c_bridge(t, 0);
559 i2c_master_send(c, tda8290_agc_tri, 2); 558 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
560 i2c_master_send(c, tda8290_standby, 2); 559 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
561} 560}
562 561
563 562
564static void tda8290_init_if(struct i2c_client *c) 563static void tda8290_init_if(struct tuner *t)
565{ 564{
566 struct tuner *t = i2c_get_clientdata(c); 565 struct tda8290_priv *priv = t->priv;
566
567 unsigned char set_VS[] = { 0x30, 0x6F }; 567 unsigned char set_VS[] = { 0x30, 0x6F };
568 unsigned char set_GP00_CF[] = { 0x20, 0x01 }; 568 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
569 unsigned char set_GP01_CF[] = { 0x20, 0x0B }; 569 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
570 570
571 if ((t->config == 1) || (t->config == 2)) 571 if ((t->config == 1) || (t->config == 2))
572 i2c_master_send(c, set_GP00_CF, 2); 572 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
573 else 573 else
574 i2c_master_send(c, set_GP01_CF, 2); 574 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
575 i2c_master_send(c, set_VS, 2); 575 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
576} 576}
577 577
578static void tda8290_init_tuner(struct i2c_client *c) 578static void tda8290_init_tuner(struct tuner *t)
579{ 579{
580 struct tuner *t = i2c_get_clientdata(c);
581 struct tda8290_priv *priv = t->priv; 580 struct tda8290_priv *priv = t->priv;
582 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, 581 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
583 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; 582 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
@@ -588,17 +587,15 @@ static void tda8290_init_tuner(struct i2c_client *c)
588 if (priv->tda827x_ver != 0) 587 if (priv->tda827x_ver != 0)
589 msg.buf = tda8275a_init; 588 msg.buf = tda8275a_init;
590 589
591 tda8290_i2c_bridge(c, 1); 590 tda8290_i2c_bridge(t, 1);
592 i2c_transfer(c->adapter, &msg, 1); 591 i2c_transfer(priv->i2c_props.adap, &msg, 1);
593 tda8290_i2c_bridge(c, 0); 592 tda8290_i2c_bridge(t, 0);
594} 593}
595 594
596/*---------------------------------------------------------------------*/ 595/*---------------------------------------------------------------------*/
597 596
598static void tda8290_release(struct i2c_client *c) 597static void tda8290_release(struct tuner *t)
599{ 598{
600 struct tuner *t = i2c_get_clientdata(c);
601
602 kfree(t->priv); 599 kfree(t->priv);
603 t->priv = NULL; 600 t->priv = NULL;
604} 601}
@@ -611,10 +608,9 @@ static struct tuner_operations tda8290_tuner_ops = {
611 .release = tda8290_release, 608 .release = tda8290_release,
612}; 609};
613 610
614int tda8290_init(struct i2c_client *c) 611int tda8290_init(struct tuner *t)
615{ 612{
616 struct tda8290_priv *priv = NULL; 613 struct tda8290_priv *priv = NULL;
617 struct tuner *t = i2c_get_clientdata(c);
618 u8 data; 614 u8 data;
619 int i, ret, tuners_found; 615 int i, ret, tuners_found;
620 u32 tuner_addrs; 616 u32 tuner_addrs;
@@ -625,13 +621,16 @@ int tda8290_init(struct i2c_client *c)
625 return -ENOMEM; 621 return -ENOMEM;
626 t->priv = priv; 622 t->priv = priv;
627 623
628 tda8290_i2c_bridge(c, 1); 624 priv->i2c_props.addr = t->i2c.addr;
625 priv->i2c_props.adap = t->i2c.adapter;
626
627 tda8290_i2c_bridge(t, 1);
629 /* probe for tuner chip */ 628 /* probe for tuner chip */
630 tuners_found = 0; 629 tuners_found = 0;
631 tuner_addrs = 0; 630 tuner_addrs = 0;
632 for (i=0x60; i<= 0x63; i++) { 631 for (i=0x60; i<= 0x63; i++) {
633 msg.addr = i; 632 msg.addr = i;
634 ret = i2c_transfer(c->adapter, &msg, 1); 633 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
635 if (ret == 1) { 634 if (ret == 1) {
636 tuners_found++; 635 tuners_found++;
637 tuner_addrs = (tuner_addrs << 8) + i; 636 tuner_addrs = (tuner_addrs << 8) + i;
@@ -641,11 +640,11 @@ int tda8290_init(struct i2c_client *c)
641 behind the bridge and we choose the highest address that doesn't 640 behind the bridge and we choose the highest address that doesn't
642 give a response now 641 give a response now
643 */ 642 */
644 tda8290_i2c_bridge(c, 0); 643 tda8290_i2c_bridge(t, 0);
645 if(tuners_found > 1) 644 if(tuners_found > 1)
646 for (i = 0; i < tuners_found; i++) { 645 for (i = 0; i < tuners_found; i++) {
647 msg.addr = tuner_addrs & 0xff; 646 msg.addr = tuner_addrs & 0xff;
648 ret = i2c_transfer(c->adapter, &msg, 1); 647 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
649 if(ret == 1) 648 if(ret == 1)
650 tuner_addrs = tuner_addrs >> 8; 649 tuner_addrs = tuner_addrs >> 8;
651 else 650 else
@@ -662,31 +661,33 @@ int tda8290_init(struct i2c_client *c)
662 priv->tda827x_addr = tuner_addrs; 661 priv->tda827x_addr = tuner_addrs;
663 msg.addr = tuner_addrs; 662 msg.addr = tuner_addrs;
664 663
665 tda8290_i2c_bridge(c, 1); 664 tda8290_i2c_bridge(t, 1);
666 ret = i2c_transfer(c->adapter, &msg, 1); 665 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
667 if( ret != 1) 666 if( ret != 1)
668 tuner_warn ("TDA827x access failed!\n"); 667 tuner_warn ("TDA827x access failed!\n");
669 if ((data & 0x3c) == 0) { 668 if ((data & 0x3c) == 0) {
670 strlcpy(c->name, "tda8290+75", sizeof(c->name)); 669 strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name));
671 priv->tda827x_ver = 0; 670 priv->tda827x_ver = 0;
672 } else { 671 } else {
673 strlcpy(c->name, "tda8290+75a", sizeof(c->name)); 672 strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name));
674 priv->tda827x_ver = 2; 673 priv->tda827x_ver = 2;
675 } 674 }
676 tuner_info("type set to %s\n", c->name); 675 tuner_info("type set to %s\n", t->i2c.name);
677 676
678 memcpy(&t->ops, &tda8290_tuner_ops, sizeof(struct tuner_operations)); 677 memcpy(&t->ops, &tda8290_tuner_ops, sizeof(struct tuner_operations));
679 678
680 priv->tda827x_lpsel = 0; 679 priv->tda827x_lpsel = 0;
681 t->mode = V4L2_TUNER_ANALOG_TV; 680 t->mode = V4L2_TUNER_ANALOG_TV;
682 681
683 tda8290_init_tuner(c); 682 tda8290_init_tuner(t);
684 tda8290_init_if(c); 683 tda8290_init_if(t);
685 return 0; 684 return 0;
686} 685}
687 686
688int tda8290_probe(struct i2c_client *c) 687int tda8290_probe(struct tuner *t)
689{ 688{
689 struct i2c_client *c = &t->i2c;
690
690 unsigned char soft_reset[] = { 0x00, 0x00 }; 691 unsigned char soft_reset[] = { 0x00, 0x00 };
691 unsigned char easy_mode_b[] = { 0x01, 0x02 }; 692 unsigned char easy_mode_b[] = { 0x01, 0x02 };
692 unsigned char easy_mode_g[] = { 0x01, 0x04 }; 693 unsigned char easy_mode_g[] = { 0x01, 0x04 };