diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-08-21 00:24:42 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-10-09 21:07:34 -0400 |
commit | db8a695658cda21eacfa2a5e3b15e8964bfb93ef (patch) | |
tree | ac69f32af5b52f78ad65ad1125d330aa19c7bdda | |
parent | 293197cd0f34eb6bfb5492a63a878575b69e9df4 (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>
-rw-r--r-- | drivers/media/video/mt20xx.c | 138 | ||||
-rw-r--r-- | drivers/media/video/tda8290.c | 247 | ||||
-rw-r--r-- | drivers/media/video/tda9887.c | 39 | ||||
-rw-r--r-- | drivers/media/video/tea5761.c | 55 | ||||
-rw-r--r-- | drivers/media/video/tea5767.c | 61 | ||||
-rw-r--r-- | drivers/media/video/tuner-core.c | 55 | ||||
-rw-r--r-- | drivers/media/video/tuner-driver.h | 37 | ||||
-rw-r--r-- | drivers/media/video/tuner-i2c.h | 70 | ||||
-rw-r--r-- | drivers/media/video/tuner-simple.c | 57 |
9 files changed, 430 insertions, 329 deletions
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c index bd495c12d29f..41bc91817a16 100644 --- a/drivers/media/video/mt20xx.c +++ b/drivers/media/video/mt20xx.c | |||
@@ -37,23 +37,22 @@ static char *microtune_part[] = { | |||
37 | }; | 37 | }; |
38 | 38 | ||
39 | struct microtune_priv { | 39 | struct microtune_priv { |
40 | struct tuner_i2c_props i2c_props; | ||
41 | |||
40 | unsigned int xogc; | 42 | unsigned int xogc; |
41 | unsigned int radio_if2; | 43 | unsigned int radio_if2; |
42 | }; | 44 | }; |
43 | 45 | ||
44 | static void microtune_release(struct i2c_client *c) | 46 | static void microtune_release(struct tuner *t) |
45 | { | 47 | { |
46 | struct tuner *t = i2c_get_clientdata(c); | ||
47 | |||
48 | kfree(t->priv); | 48 | kfree(t->priv); |
49 | t->priv = NULL; | 49 | t->priv = NULL; |
50 | } | 50 | } |
51 | 51 | ||
52 | // IsSpurInBand()? | 52 | // IsSpurInBand()? |
53 | static int mt2032_spurcheck(struct i2c_client *c, | 53 | static int mt2032_spurcheck(struct tuner *t, |
54 | int f1, int f2, int spectrum_from,int spectrum_to) | 54 | int f1, int f2, int spectrum_from,int spectrum_to) |
55 | { | 55 | { |
56 | struct tuner *t = i2c_get_clientdata(c); | ||
57 | int n1=1,n2,f; | 56 | int n1=1,n2,f; |
58 | 57 | ||
59 | f1=f1/1000; //scale to kHz to avoid 32bit overflows | 58 | f1=f1/1000; //scale to kHz to avoid 32bit overflows |
@@ -81,7 +80,7 @@ static int mt2032_spurcheck(struct i2c_client *c, | |||
81 | return 1; | 80 | return 1; |
82 | } | 81 | } |
83 | 82 | ||
84 | static int mt2032_compute_freq(struct i2c_client *c, | 83 | static int mt2032_compute_freq(struct tuner *t, |
85 | unsigned int rfin, | 84 | unsigned int rfin, |
86 | unsigned int if1, unsigned int if2, | 85 | unsigned int if1, unsigned int if2, |
87 | unsigned int spectrum_from, | 86 | unsigned int spectrum_from, |
@@ -90,7 +89,6 @@ static int mt2032_compute_freq(struct i2c_client *c, | |||
90 | int *ret_sel, | 89 | int *ret_sel, |
91 | unsigned int xogc) //all in Hz | 90 | unsigned int xogc) //all in Hz |
92 | { | 91 | { |
93 | struct tuner *t = i2c_get_clientdata(c); | ||
94 | unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1, | 92 | unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1, |
95 | desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq; | 93 | desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq; |
96 | 94 | ||
@@ -140,7 +138,7 @@ static int mt2032_compute_freq(struct i2c_client *c, | |||
140 | return(-1); | 138 | return(-1); |
141 | } | 139 | } |
142 | 140 | ||
143 | mt2032_spurcheck(c, lo1freq, desired_lo2, spectrum_from, spectrum_to); | 141 | mt2032_spurcheck(t, lo1freq, desired_lo2, spectrum_from, spectrum_to); |
144 | // should recalculate lo1 (one step up/down) | 142 | // should recalculate lo1 (one step up/down) |
145 | 143 | ||
146 | // set up MT2032 register map for transfer over i2c | 144 | // set up MT2032 register map for transfer over i2c |
@@ -164,16 +162,16 @@ static int mt2032_compute_freq(struct i2c_client *c, | |||
164 | return 0; | 162 | return 0; |
165 | } | 163 | } |
166 | 164 | ||
167 | static int mt2032_check_lo_lock(struct i2c_client *c) | 165 | static int mt2032_check_lo_lock(struct tuner *t) |
168 | { | 166 | { |
169 | struct tuner *t = i2c_get_clientdata(c); | 167 | struct microtune_priv *priv = t->priv; |
170 | int try,lock=0; | 168 | int try,lock=0; |
171 | unsigned char buf[2]; | 169 | unsigned char buf[2]; |
172 | 170 | ||
173 | for(try=0;try<10;try++) { | 171 | for(try=0;try<10;try++) { |
174 | buf[0]=0x0e; | 172 | buf[0]=0x0e; |
175 | i2c_master_send(c,buf,1); | 173 | tuner_i2c_xfer_send(&priv->i2c_props,buf,1); |
176 | i2c_master_recv(c,buf,1); | 174 | tuner_i2c_xfer_recv(&priv->i2c_props,buf,1); |
177 | tuner_dbg("mt2032 Reg.E=0x%02x\n",buf[0]); | 175 | tuner_dbg("mt2032 Reg.E=0x%02x\n",buf[0]); |
178 | lock=buf[0] &0x06; | 176 | lock=buf[0] &0x06; |
179 | 177 | ||
@@ -186,15 +184,15 @@ static int mt2032_check_lo_lock(struct i2c_client *c) | |||
186 | return lock; | 184 | return lock; |
187 | } | 185 | } |
188 | 186 | ||
189 | static int mt2032_optimize_vco(struct i2c_client *c,int sel,int lock) | 187 | static int mt2032_optimize_vco(struct tuner *t,int sel,int lock) |
190 | { | 188 | { |
191 | struct tuner *t = i2c_get_clientdata(c); | 189 | struct microtune_priv *priv = t->priv; |
192 | unsigned char buf[2]; | 190 | unsigned char buf[2]; |
193 | int tad1; | 191 | int tad1; |
194 | 192 | ||
195 | buf[0]=0x0f; | 193 | buf[0]=0x0f; |
196 | i2c_master_send(c,buf,1); | 194 | tuner_i2c_xfer_send(&priv->i2c_props,buf,1); |
197 | i2c_master_recv(c,buf,1); | 195 | tuner_i2c_xfer_recv(&priv->i2c_props,buf,1); |
198 | tuner_dbg("mt2032 Reg.F=0x%02x\n",buf[0]); | 196 | tuner_dbg("mt2032 Reg.F=0x%02x\n",buf[0]); |
199 | tad1=buf[0]&0x07; | 197 | tad1=buf[0]&0x07; |
200 | 198 | ||
@@ -217,58 +215,57 @@ static int mt2032_optimize_vco(struct i2c_client *c,int sel,int lock) | |||
217 | 215 | ||
218 | buf[0]=0x0f; | 216 | buf[0]=0x0f; |
219 | buf[1]=sel; | 217 | buf[1]=sel; |
220 | i2c_master_send(c,buf,2); | 218 | tuner_i2c_xfer_send(&priv->i2c_props,buf,2); |
221 | lock=mt2032_check_lo_lock(c); | 219 | lock=mt2032_check_lo_lock(t); |
222 | return lock; | 220 | return lock; |
223 | } | 221 | } |
224 | 222 | ||
225 | 223 | ||
226 | static void mt2032_set_if_freq(struct i2c_client *c, unsigned int rfin, | 224 | static void mt2032_set_if_freq(struct tuner *t, unsigned int rfin, |
227 | unsigned int if1, unsigned int if2, | 225 | unsigned int if1, unsigned int if2, |
228 | unsigned int from, unsigned int to) | 226 | unsigned int from, unsigned int to) |
229 | { | 227 | { |
230 | unsigned char buf[21]; | 228 | unsigned char buf[21]; |
231 | int lint_try,ret,sel,lock=0; | 229 | int lint_try,ret,sel,lock=0; |
232 | struct tuner *t = i2c_get_clientdata(c); | ||
233 | struct microtune_priv *priv = t->priv; | 230 | struct microtune_priv *priv = t->priv; |
234 | 231 | ||
235 | tuner_dbg("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n", | 232 | tuner_dbg("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n", |
236 | rfin,if1,if2,from,to); | 233 | rfin,if1,if2,from,to); |
237 | 234 | ||
238 | buf[0]=0; | 235 | buf[0]=0; |
239 | ret=i2c_master_send(c,buf,1); | 236 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,1); |
240 | i2c_master_recv(c,buf,21); | 237 | tuner_i2c_xfer_recv(&priv->i2c_props,buf,21); |
241 | 238 | ||
242 | buf[0]=0; | 239 | buf[0]=0; |
243 | ret=mt2032_compute_freq(c,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc); | 240 | ret=mt2032_compute_freq(t,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc); |
244 | if (ret<0) | 241 | if (ret<0) |
245 | return; | 242 | return; |
246 | 243 | ||
247 | // send only the relevant registers per Rev. 1.2 | 244 | // send only the relevant registers per Rev. 1.2 |
248 | buf[0]=0; | 245 | buf[0]=0; |
249 | ret=i2c_master_send(c,buf,4); | 246 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,4); |
250 | buf[5]=5; | 247 | buf[5]=5; |
251 | ret=i2c_master_send(c,buf+5,4); | 248 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+5,4); |
252 | buf[11]=11; | 249 | buf[11]=11; |
253 | ret=i2c_master_send(c,buf+11,3); | 250 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+11,3); |
254 | if(ret!=3) | 251 | if(ret!=3) |
255 | tuner_warn("i2c i/o error: rc == %d (should be 3)\n",ret); | 252 | tuner_warn("i2c i/o error: rc == %d (should be 3)\n",ret); |
256 | 253 | ||
257 | // wait for PLLs to lock (per manual), retry LINT if not. | 254 | // wait for PLLs to lock (per manual), retry LINT if not. |
258 | for(lint_try=0; lint_try<2; lint_try++) { | 255 | for(lint_try=0; lint_try<2; lint_try++) { |
259 | lock=mt2032_check_lo_lock(c); | 256 | lock=mt2032_check_lo_lock(t); |
260 | 257 | ||
261 | if(optimize_vco) | 258 | if(optimize_vco) |
262 | lock=mt2032_optimize_vco(c,sel,lock); | 259 | lock=mt2032_optimize_vco(t,sel,lock); |
263 | if(lock==6) break; | 260 | if(lock==6) break; |
264 | 261 | ||
265 | tuner_dbg("mt2032: re-init PLLs by LINT\n"); | 262 | tuner_dbg("mt2032: re-init PLLs by LINT\n"); |
266 | buf[0]=7; | 263 | buf[0]=7; |
267 | buf[1]=0x80 +8+priv->xogc; // set LINT to re-init PLLs | 264 | buf[1]=0x80 +8+priv->xogc; // set LINT to re-init PLLs |
268 | i2c_master_send(c,buf,2); | 265 | tuner_i2c_xfer_send(&priv->i2c_props,buf,2); |
269 | mdelay(10); | 266 | mdelay(10); |
270 | buf[1]=8+priv->xogc; | 267 | buf[1]=8+priv->xogc; |
271 | i2c_master_send(c,buf,2); | 268 | tuner_i2c_xfer_send(&priv->i2c_props,buf,2); |
272 | } | 269 | } |
273 | 270 | ||
274 | if (lock!=6) | 271 | if (lock!=6) |
@@ -276,15 +273,14 @@ static void mt2032_set_if_freq(struct i2c_client *c, unsigned int rfin, | |||
276 | 273 | ||
277 | buf[0]=2; | 274 | buf[0]=2; |
278 | buf[1]=0x20; // LOGC for optimal phase noise | 275 | buf[1]=0x20; // LOGC for optimal phase noise |
279 | ret=i2c_master_send(c,buf,2); | 276 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); |
280 | if (ret!=2) | 277 | if (ret!=2) |
281 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret); | 278 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret); |
282 | } | 279 | } |
283 | 280 | ||
284 | 281 | ||
285 | static void mt2032_set_tv_freq(struct i2c_client *c, unsigned int freq) | 282 | static void mt2032_set_tv_freq(struct tuner *t, unsigned int freq) |
286 | { | 283 | { |
287 | struct tuner *t = i2c_get_clientdata(c); | ||
288 | int if2,from,to; | 284 | int if2,from,to; |
289 | 285 | ||
290 | // signal bandwidth and picture carrier | 286 | // signal bandwidth and picture carrier |
@@ -300,18 +296,17 @@ static void mt2032_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
300 | if2 = 38900*1000; | 296 | if2 = 38900*1000; |
301 | } | 297 | } |
302 | 298 | ||
303 | mt2032_set_if_freq(c, freq*62500 /* freq*1000*1000/16 */, | 299 | mt2032_set_if_freq(t, freq*62500 /* freq*1000*1000/16 */, |
304 | 1090*1000*1000, if2, from, to); | 300 | 1090*1000*1000, if2, from, to); |
305 | } | 301 | } |
306 | 302 | ||
307 | static void mt2032_set_radio_freq(struct i2c_client *c, unsigned int freq) | 303 | static void mt2032_set_radio_freq(struct tuner *t, unsigned int freq) |
308 | { | 304 | { |
309 | struct tuner *t = i2c_get_clientdata(c); | ||
310 | struct microtune_priv *priv = t->priv; | 305 | struct microtune_priv *priv = t->priv; |
311 | int if2 = priv->radio_if2; | 306 | int if2 = priv->radio_if2; |
312 | 307 | ||
313 | // per Manual for FM tuning: first if center freq. 1085 MHz | 308 | // per Manual for FM tuning: first if center freq. 1085 MHz |
314 | mt2032_set_if_freq(c, freq * 1000 / 16, | 309 | mt2032_set_if_freq(t, freq * 1000 / 16, |
315 | 1085*1000*1000,if2,if2,if2); | 310 | 1085*1000*1000,if2,if2,if2); |
316 | } | 311 | } |
317 | 312 | ||
@@ -322,9 +317,8 @@ static struct tuner_operations mt2032_tuner_ops = { | |||
322 | }; | 317 | }; |
323 | 318 | ||
324 | // Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001 | 319 | // Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001 |
325 | static int mt2032_init(struct i2c_client *c) | 320 | static int mt2032_init(struct tuner *t) |
326 | { | 321 | { |
327 | struct tuner *t = i2c_get_clientdata(c); | ||
328 | struct microtune_priv *priv = t->priv; | 322 | struct microtune_priv *priv = t->priv; |
329 | unsigned char buf[21]; | 323 | unsigned char buf[21]; |
330 | int ret,xogc,xok=0; | 324 | int ret,xogc,xok=0; |
@@ -334,7 +328,7 @@ static int mt2032_init(struct i2c_client *c) | |||
334 | buf[2]=0xff; | 328 | buf[2]=0xff; |
335 | buf[3]=0x0f; | 329 | buf[3]=0x0f; |
336 | buf[4]=0x1f; | 330 | buf[4]=0x1f; |
337 | ret=i2c_master_send(c,buf+1,4); | 331 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+1,4); |
338 | 332 | ||
339 | buf[5]=6; // Index register 6 | 333 | buf[5]=6; // Index register 6 |
340 | buf[6]=0xe4; | 334 | buf[6]=0xe4; |
@@ -342,11 +336,11 @@ static int mt2032_init(struct i2c_client *c) | |||
342 | buf[8]=0xc3; | 336 | buf[8]=0xc3; |
343 | buf[9]=0x4e; | 337 | buf[9]=0x4e; |
344 | buf[10]=0xec; | 338 | buf[10]=0xec; |
345 | ret=i2c_master_send(c,buf+5,6); | 339 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+5,6); |
346 | 340 | ||
347 | buf[12]=13; // Index register 13 | 341 | buf[12]=13; // Index register 13 |
348 | buf[13]=0x32; | 342 | buf[13]=0x32; |
349 | ret=i2c_master_send(c,buf+12,2); | 343 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+12,2); |
350 | 344 | ||
351 | // Adjust XOGC (register 7), wait for XOK | 345 | // Adjust XOGC (register 7), wait for XOK |
352 | xogc=7; | 346 | xogc=7; |
@@ -354,8 +348,8 @@ static int mt2032_init(struct i2c_client *c) | |||
354 | tuner_dbg("mt2032: xogc = 0x%02x\n",xogc&0x07); | 348 | tuner_dbg("mt2032: xogc = 0x%02x\n",xogc&0x07); |
355 | mdelay(10); | 349 | mdelay(10); |
356 | buf[0]=0x0e; | 350 | buf[0]=0x0e; |
357 | i2c_master_send(c,buf,1); | 351 | tuner_i2c_xfer_send(&priv->i2c_props,buf,1); |
358 | i2c_master_recv(c,buf,1); | 352 | tuner_i2c_xfer_recv(&priv->i2c_props,buf,1); |
359 | xok=buf[0]&0x01; | 353 | xok=buf[0]&0x01; |
360 | tuner_dbg("mt2032: xok = 0x%02x\n",xok); | 354 | tuner_dbg("mt2032: xok = 0x%02x\n",xok); |
361 | if (xok == 1) break; | 355 | if (xok == 1) break; |
@@ -368,7 +362,7 @@ static int mt2032_init(struct i2c_client *c) | |||
368 | } | 362 | } |
369 | buf[0]=0x07; | 363 | buf[0]=0x07; |
370 | buf[1]=0x88 + xogc; | 364 | buf[1]=0x88 + xogc; |
371 | ret=i2c_master_send(c,buf,2); | 365 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); |
372 | if (ret!=2) | 366 | if (ret!=2) |
373 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret); | 367 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret); |
374 | } while (xok != 1 ); | 368 | } while (xok != 1 ); |
@@ -379,21 +373,21 @@ static int mt2032_init(struct i2c_client *c) | |||
379 | return(1); | 373 | return(1); |
380 | } | 374 | } |
381 | 375 | ||
382 | static void mt2050_set_antenna(struct i2c_client *c, unsigned char antenna) | 376 | static void mt2050_set_antenna(struct tuner *t, unsigned char antenna) |
383 | { | 377 | { |
384 | struct tuner *t = i2c_get_clientdata(c); | 378 | struct microtune_priv *priv = t->priv; |
385 | unsigned char buf[2]; | 379 | unsigned char buf[2]; |
386 | int ret; | 380 | int ret; |
387 | 381 | ||
388 | buf[0] = 6; | 382 | buf[0] = 6; |
389 | buf[1] = antenna ? 0x11 : 0x10; | 383 | buf[1] = antenna ? 0x11 : 0x10; |
390 | ret=i2c_master_send(c,buf,2); | 384 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); |
391 | tuner_dbg("mt2050: enabled antenna connector %d\n", antenna); | 385 | tuner_dbg("mt2050: enabled antenna connector %d\n", antenna); |
392 | } | 386 | } |
393 | 387 | ||
394 | static void mt2050_set_if_freq(struct i2c_client *c,unsigned int freq, unsigned int if2) | 388 | static void mt2050_set_if_freq(struct tuner *t,unsigned int freq, unsigned int if2) |
395 | { | 389 | { |
396 | struct tuner *t = i2c_get_clientdata(c); | 390 | struct microtune_priv *priv = t->priv; |
397 | unsigned int if1=1218*1000*1000; | 391 | unsigned int if1=1218*1000*1000; |
398 | unsigned int f_lo1,f_lo2,lo1,lo2,f_lo1_modulo,f_lo2_modulo,num1,num2,div1a,div1b,div2a,div2b; | 392 | unsigned int f_lo1,f_lo2,lo1,lo2,f_lo1_modulo,f_lo2_modulo,num1,num2,div1a,div1b,div2a,div2b; |
399 | int ret; | 393 | int ret; |
@@ -449,14 +443,13 @@ static void mt2050_set_if_freq(struct i2c_client *c,unsigned int freq, unsigned | |||
449 | printk("\n"); | 443 | printk("\n"); |
450 | } | 444 | } |
451 | 445 | ||
452 | ret=i2c_master_send(c,buf,6); | 446 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,6); |
453 | if (ret!=6) | 447 | if (ret!=6) |
454 | tuner_warn("i2c i/o error: rc == %d (should be 6)\n",ret); | 448 | tuner_warn("i2c i/o error: rc == %d (should be 6)\n",ret); |
455 | } | 449 | } |
456 | 450 | ||
457 | static void mt2050_set_tv_freq(struct i2c_client *c, unsigned int freq) | 451 | static void mt2050_set_tv_freq(struct tuner *t, unsigned int freq) |
458 | { | 452 | { |
459 | struct tuner *t = i2c_get_clientdata(c); | ||
460 | unsigned int if2; | 453 | unsigned int if2; |
461 | 454 | ||
462 | if (t->std & V4L2_STD_525_60) { | 455 | if (t->std & V4L2_STD_525_60) { |
@@ -470,18 +463,17 @@ static void mt2050_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
470 | // DVB (pinnacle 300i) | 463 | // DVB (pinnacle 300i) |
471 | if2 = 36150*1000; | 464 | if2 = 36150*1000; |
472 | } | 465 | } |
473 | mt2050_set_if_freq(c, freq*62500, if2); | 466 | mt2050_set_if_freq(t, freq*62500, if2); |
474 | mt2050_set_antenna(c, tv_antenna); | 467 | mt2050_set_antenna(t, tv_antenna); |
475 | } | 468 | } |
476 | 469 | ||
477 | static void mt2050_set_radio_freq(struct i2c_client *c, unsigned int freq) | 470 | static void mt2050_set_radio_freq(struct tuner *t, unsigned int freq) |
478 | { | 471 | { |
479 | struct tuner *t = i2c_get_clientdata(c); | ||
480 | struct microtune_priv *priv = t->priv; | 472 | struct microtune_priv *priv = t->priv; |
481 | int if2 = priv->radio_if2; | 473 | int if2 = priv->radio_if2; |
482 | 474 | ||
483 | mt2050_set_if_freq(c, freq * 1000 / 16, if2); | 475 | mt2050_set_if_freq(t, freq * 1000 / 16, if2); |
484 | mt2050_set_antenna(c, radio_antenna); | 476 | mt2050_set_antenna(t, radio_antenna); |
485 | } | 477 | } |
486 | 478 | ||
487 | static struct tuner_operations mt2050_tuner_ops = { | 479 | static struct tuner_operations mt2050_tuner_ops = { |
@@ -490,23 +482,23 @@ static struct tuner_operations mt2050_tuner_ops = { | |||
490 | .release = microtune_release, | 482 | .release = microtune_release, |
491 | }; | 483 | }; |
492 | 484 | ||
493 | static int mt2050_init(struct i2c_client *c) | 485 | static int mt2050_init(struct tuner *t) |
494 | { | 486 | { |
495 | struct tuner *t = i2c_get_clientdata(c); | 487 | struct microtune_priv *priv = t->priv; |
496 | unsigned char buf[2]; | 488 | unsigned char buf[2]; |
497 | int ret; | 489 | int ret; |
498 | 490 | ||
499 | buf[0]=6; | 491 | buf[0]=6; |
500 | buf[1]=0x10; | 492 | buf[1]=0x10; |
501 | ret=i2c_master_send(c,buf,2); // power | 493 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); // power |
502 | 494 | ||
503 | buf[0]=0x0f; | 495 | buf[0]=0x0f; |
504 | buf[1]=0x0f; | 496 | buf[1]=0x0f; |
505 | ret=i2c_master_send(c,buf,2); // m1lo | 497 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); // m1lo |
506 | 498 | ||
507 | buf[0]=0x0d; | 499 | buf[0]=0x0d; |
508 | ret=i2c_master_send(c,buf,1); | 500 | ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,1); |
509 | i2c_master_recv(c,buf,1); | 501 | tuner_i2c_xfer_recv(&priv->i2c_props,buf,1); |
510 | 502 | ||
511 | tuner_dbg("mt2050: sro is %x\n",buf[0]); | 503 | tuner_dbg("mt2050: sro is %x\n",buf[0]); |
512 | 504 | ||
@@ -515,10 +507,9 @@ static int mt2050_init(struct i2c_client *c) | |||
515 | return 0; | 507 | return 0; |
516 | } | 508 | } |
517 | 509 | ||
518 | int microtune_init(struct i2c_client *c) | 510 | int microtune_init(struct tuner *t) |
519 | { | 511 | { |
520 | struct microtune_priv *priv = NULL; | 512 | struct microtune_priv *priv = NULL; |
521 | struct tuner *t = i2c_get_clientdata(c); | ||
522 | char *name; | 513 | char *name; |
523 | unsigned char buf[21]; | 514 | unsigned char buf[21]; |
524 | int company_code; | 515 | int company_code; |
@@ -528,6 +519,9 @@ int microtune_init(struct i2c_client *c) | |||
528 | return -ENOMEM; | 519 | return -ENOMEM; |
529 | t->priv = priv; | 520 | t->priv = priv; |
530 | 521 | ||
522 | priv->i2c_props.addr = t->i2c.addr; | ||
523 | priv->i2c_props.adap = t->i2c.adapter; | ||
524 | |||
531 | priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ | 525 | priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ |
532 | 526 | ||
533 | memset(buf,0,sizeof(buf)); | 527 | memset(buf,0,sizeof(buf)); |
@@ -541,8 +535,8 @@ int microtune_init(struct i2c_client *c) | |||
541 | } | 535 | } |
542 | name = "unknown"; | 536 | name = "unknown"; |
543 | 537 | ||
544 | i2c_master_send(c,buf,1); | 538 | tuner_i2c_xfer_send(&priv->i2c_props,buf,1); |
545 | i2c_master_recv(c,buf,21); | 539 | tuner_i2c_xfer_recv(&priv->i2c_props,buf,21); |
546 | if (tuner_debug) { | 540 | if (tuner_debug) { |
547 | int i; | 541 | int i; |
548 | tuner_dbg("MT20xx hexdump:"); | 542 | tuner_dbg("MT20xx hexdump:"); |
@@ -562,10 +556,10 @@ int microtune_init(struct i2c_client *c) | |||
562 | name = microtune_part[buf[0x13]]; | 556 | name = microtune_part[buf[0x13]]; |
563 | switch (buf[0x13]) { | 557 | switch (buf[0x13]) { |
564 | case MT2032: | 558 | case MT2032: |
565 | mt2032_init(c); | 559 | mt2032_init(t); |
566 | break; | 560 | break; |
567 | case MT2050: | 561 | case MT2050: |
568 | mt2050_init(c); | 562 | mt2050_init(t); |
569 | break; | 563 | break; |
570 | default: | 564 | default: |
571 | tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n", | 565 | tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n", |
@@ -573,7 +567,7 @@ int microtune_init(struct i2c_client *c) | |||
573 | return 0; | 567 | return 0; |
574 | } | 568 | } |
575 | 569 | ||
576 | strlcpy(c->name, name, sizeof(c->name)); | 570 | strlcpy(t->i2c.name, name, sizeof(t->i2c.name)); |
577 | tuner_info("microtune %s found, OK\n",name); | 571 | tuner_info("microtune %s found, OK\n",name); |
578 | return 0; | 572 | return 0; |
579 | } | 573 | } |
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 | ||
28 | struct tda8290_priv { | 28 | struct 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 | ||
82 | static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | 84 | static 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 | ||
157 | static void tda827x_agcf(struct i2c_client *c) | 158 | static 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 | ||
207 | static void tda827xa_lna_gain(struct i2c_client *c, int high) | 207 | static 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 | ||
243 | static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | 243 | static 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 | ||
331 | static void tda827xa_agcf(struct i2c_client *c) | 330 | static 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 | ||
343 | static void tda8290_i2c_bridge(struct i2c_client *c, int close) | 341 | static 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 | ||
361 | static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | 361 | static 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 | ||
518 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) | 517 | static 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 | ||
527 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) | 525 | static 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 | ||
533 | static int has_signal(struct i2c_client *c) | 531 | static 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 | ||
545 | static void standby(struct i2c_client *c) | 545 | static 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 | ||
564 | static void tda8290_init_if(struct i2c_client *c) | 563 | static 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 | ||
578 | static void tda8290_init_tuner(struct i2c_client *c) | 578 | static 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 | ||
598 | static void tda8290_release(struct i2c_client *c) | 597 | static 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 | ||
614 | int tda8290_init(struct i2c_client *c) | 611 | int 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 | ||
688 | int tda8290_probe(struct i2c_client *c) | 687 | int 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 }; |
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c index d162bc67d445..be5387f11afb 100644 --- a/drivers/media/video/tda9887.c +++ b/drivers/media/video/tda9887.c | |||
@@ -29,6 +29,8 @@ | |||
29 | i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0) | 29 | i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0) |
30 | 30 | ||
31 | struct tda9887_priv { | 31 | struct tda9887_priv { |
32 | struct tuner_i2c_props i2c_props; | ||
33 | |||
32 | unsigned char data[4]; | 34 | unsigned char data[4]; |
33 | }; | 35 | }; |
34 | 36 | ||
@@ -510,19 +512,19 @@ static int tda9887_set_config(struct tuner *t, char *buf) | |||
510 | 512 | ||
511 | static int tda9887_status(struct tuner *t) | 513 | static int tda9887_status(struct tuner *t) |
512 | { | 514 | { |
515 | struct tda9887_priv *priv = t->priv; | ||
513 | unsigned char buf[1]; | 516 | unsigned char buf[1]; |
514 | int rc; | 517 | int rc; |
515 | 518 | ||
516 | memset(buf,0,sizeof(buf)); | 519 | memset(buf,0,sizeof(buf)); |
517 | if (1 != (rc = i2c_master_recv(&t->i2c,buf,1))) | 520 | if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1))) |
518 | tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc); | 521 | tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc); |
519 | dump_read_message(t, buf); | 522 | dump_read_message(t, buf); |
520 | return 0; | 523 | return 0; |
521 | } | 524 | } |
522 | 525 | ||
523 | static void tda9887_configure(struct i2c_client *client) | 526 | static void tda9887_configure(struct tuner *t) |
524 | { | 527 | { |
525 | struct tuner *t = i2c_get_clientdata(client); | ||
526 | struct tda9887_priv *priv = t->priv; | 528 | struct tda9887_priv *priv = t->priv; |
527 | int rc; | 529 | int rc; |
528 | 530 | ||
@@ -557,7 +559,7 @@ static void tda9887_configure(struct i2c_client *client) | |||
557 | if (tuner_debug > 1) | 559 | if (tuner_debug > 1) |
558 | dump_write_message(t, priv->data); | 560 | dump_write_message(t, priv->data); |
559 | 561 | ||
560 | if (4 != (rc = i2c_master_send(&t->i2c,priv->data,4))) | 562 | if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4))) |
561 | tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc); | 563 | tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc); |
562 | 564 | ||
563 | if (tuner_debug > 2) { | 565 | if (tuner_debug > 2) { |
@@ -568,16 +570,15 @@ static void tda9887_configure(struct i2c_client *client) | |||
568 | 570 | ||
569 | /* ---------------------------------------------------------------------- */ | 571 | /* ---------------------------------------------------------------------- */ |
570 | 572 | ||
571 | static void tda9887_tuner_status(struct i2c_client *client) | 573 | static void tda9887_tuner_status(struct tuner *t) |
572 | { | 574 | { |
573 | struct tuner *t = i2c_get_clientdata(client); | ||
574 | struct tda9887_priv *priv = t->priv; | 575 | struct tda9887_priv *priv = t->priv; |
575 | tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]); | 576 | tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]); |
576 | } | 577 | } |
577 | 578 | ||
578 | static int tda9887_get_afc(struct i2c_client *client) | 579 | static int tda9887_get_afc(struct tuner *t) |
579 | { | 580 | { |
580 | struct tuner *t = i2c_get_clientdata(client); | 581 | struct tda9887_priv *priv = t->priv; |
581 | static int AFC_BITS_2_kHz[] = { | 582 | static int AFC_BITS_2_kHz[] = { |
582 | -12500, -37500, -62500, -97500, | 583 | -12500, -37500, -62500, -97500, |
583 | -112500, -137500, -162500, -187500, | 584 | -112500, -137500, -162500, -187500, |
@@ -587,26 +588,24 @@ static int tda9887_get_afc(struct i2c_client *client) | |||
587 | int afc=0; | 588 | int afc=0; |
588 | __u8 reg = 0; | 589 | __u8 reg = 0; |
589 | 590 | ||
590 | if (1 == i2c_master_recv(&t->i2c,®,1)) | 591 | if (1 == tuner_i2c_xfer_recv(&priv->i2c_props,®,1)) |
591 | afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; | 592 | afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; |
592 | 593 | ||
593 | return afc; | 594 | return afc; |
594 | } | 595 | } |
595 | 596 | ||
596 | static void tda9887_standby(struct i2c_client *client) | 597 | static void tda9887_standby(struct tuner *t) |
597 | { | 598 | { |
598 | tda9887_configure(client); | 599 | tda9887_configure(t); |
599 | } | 600 | } |
600 | 601 | ||
601 | static void tda9887_set_freq(struct i2c_client *client, unsigned int freq) | 602 | static void tda9887_set_freq(struct tuner *t, unsigned int freq) |
602 | { | 603 | { |
603 | tda9887_configure(client); | 604 | tda9887_configure(t); |
604 | } | 605 | } |
605 | 606 | ||
606 | static void tda9887_release(struct i2c_client *c) | 607 | static void tda9887_release(struct tuner *t) |
607 | { | 608 | { |
608 | struct tuner *t = i2c_get_clientdata(c); | ||
609 | |||
610 | kfree(t->priv); | 609 | kfree(t->priv); |
611 | t->priv = NULL; | 610 | t->priv = NULL; |
612 | } | 611 | } |
@@ -620,17 +619,19 @@ static struct tuner_operations tda9887_tuner_ops = { | |||
620 | .release = tda9887_release, | 619 | .release = tda9887_release, |
621 | }; | 620 | }; |
622 | 621 | ||
623 | int tda9887_tuner_init(struct i2c_client *c) | 622 | int tda9887_tuner_init(struct tuner *t) |
624 | { | 623 | { |
625 | struct tda9887_priv *priv = NULL; | 624 | struct tda9887_priv *priv = NULL; |
626 | struct tuner *t = i2c_get_clientdata(c); | ||
627 | 625 | ||
628 | priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL); | 626 | priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL); |
629 | if (priv == NULL) | 627 | if (priv == NULL) |
630 | return -ENOMEM; | 628 | return -ENOMEM; |
631 | t->priv = priv; | 629 | t->priv = priv; |
632 | 630 | ||
633 | strlcpy(c->name, "tda9887", sizeof(c->name)); | 631 | priv->i2c_props.addr = t->i2c.addr; |
632 | priv->i2c_props.adap = t->i2c.adapter; | ||
633 | |||
634 | strlcpy(t->i2c.name, "tda9887", sizeof(t->i2c.name)); | ||
634 | 635 | ||
635 | tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c.addr, | 636 | tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c.addr, |
636 | t->i2c.driver->driver.name); | 637 | t->i2c.driver->driver.name); |
diff --git a/drivers/media/video/tea5761.c b/drivers/media/video/tea5761.c index 43bdc374927e..9965ba48cffa 100644 --- a/drivers/media/video/tea5761.c +++ b/drivers/media/video/tea5761.c | |||
@@ -18,6 +18,10 @@ | |||
18 | /* from tuner-core.c */ | 18 | /* from tuner-core.c */ |
19 | extern int tuner_debug; | 19 | extern int tuner_debug; |
20 | 20 | ||
21 | struct tea5761_priv { | ||
22 | struct tuner_i2c_props i2c_props; | ||
23 | }; | ||
24 | |||
21 | /*****************************************************************************/ | 25 | /*****************************************************************************/ |
22 | 26 | ||
23 | /*************************** | 27 | /*************************** |
@@ -114,10 +118,8 @@ extern int tuner_debug; | |||
114 | 118 | ||
115 | /*****************************************************************************/ | 119 | /*****************************************************************************/ |
116 | 120 | ||
117 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) | 121 | static void set_tv_freq(struct tuner *t, unsigned int freq) |
118 | { | 122 | { |
119 | struct tuner *t = i2c_get_clientdata(c); | ||
120 | |||
121 | tuner_warn("This tuner doesn't support TV freq.\n"); | 123 | tuner_warn("This tuner doesn't support TV freq.\n"); |
122 | } | 124 | } |
123 | 125 | ||
@@ -135,9 +137,9 @@ static void tea5761_status_dump(unsigned char *buffer) | |||
135 | } | 137 | } |
136 | 138 | ||
137 | /* Freq should be specifyed at 62.5 Hz */ | 139 | /* Freq should be specifyed at 62.5 Hz */ |
138 | static void set_radio_freq(struct i2c_client *c, unsigned int frq) | 140 | static void set_radio_freq(struct tuner *t, unsigned int frq) |
139 | { | 141 | { |
140 | struct tuner *t = i2c_get_clientdata(c); | 142 | struct tea5761_priv *priv = t->priv; |
141 | unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 }; | 143 | unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 }; |
142 | unsigned div; | 144 | unsigned div; |
143 | int rc; | 145 | int rc; |
@@ -167,31 +169,31 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq) | |||
167 | if (tuner_debug) | 169 | if (tuner_debug) |
168 | tea5761_status_dump(buffer); | 170 | tea5761_status_dump(buffer); |
169 | 171 | ||
170 | if (7 != (rc = i2c_master_send(c, buffer, 7))) | 172 | if (7 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 7))) |
171 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 173 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
172 | } | 174 | } |
173 | 175 | ||
174 | static int tea5761_signal(struct i2c_client *c) | 176 | static int tea5761_signal(struct tuner *t) |
175 | { | 177 | { |
176 | unsigned char buffer[16]; | 178 | unsigned char buffer[16]; |
177 | int rc; | 179 | int rc; |
178 | struct tuner *t = i2c_get_clientdata(c); | 180 | struct tea5761_priv *priv = t->priv; |
179 | 181 | ||
180 | memset(buffer, 0, sizeof(buffer)); | 182 | memset(buffer, 0, sizeof(buffer)); |
181 | if (16 != (rc = i2c_master_recv(c, buffer, 16))) | 183 | if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) |
182 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 184 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
183 | 185 | ||
184 | return ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); | 186 | return ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); |
185 | } | 187 | } |
186 | 188 | ||
187 | static int tea5761_stereo(struct i2c_client *c) | 189 | static int tea5761_stereo(struct tuner *t) |
188 | { | 190 | { |
189 | unsigned char buffer[16]; | 191 | unsigned char buffer[16]; |
190 | int rc; | 192 | int rc; |
191 | struct tuner *t = i2c_get_clientdata(c); | 193 | struct tea5761_priv *priv = t->priv; |
192 | 194 | ||
193 | memset(buffer, 0, sizeof(buffer)); | 195 | memset(buffer, 0, sizeof(buffer)); |
194 | if (16 != (rc = i2c_master_recv(c, buffer, 16))) | 196 | if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) |
195 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 197 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
196 | 198 | ||
197 | rc = buffer[9] & TEA5761_TUNCHECK_STEREO; | 199 | rc = buffer[9] & TEA5761_TUNCHECK_STEREO; |
@@ -201,13 +203,13 @@ static int tea5761_stereo(struct i2c_client *c) | |||
201 | return (rc ? V4L2_TUNER_SUB_STEREO : 0); | 203 | return (rc ? V4L2_TUNER_SUB_STEREO : 0); |
202 | } | 204 | } |
203 | 205 | ||
204 | int tea5761_autodetection(struct i2c_client *c) | 206 | int tea5761_autodetection(struct tuner *t) |
205 | { | 207 | { |
206 | unsigned char buffer[16]; | 208 | unsigned char buffer[16]; |
207 | int rc; | 209 | int rc; |
208 | struct tuner *t = i2c_get_clientdata(c); | 210 | struct tuner_i2c_props i2c = { .adap = t->i2c.adapter, .addr = t->i2c.addr }; |
209 | 211 | ||
210 | if (16 != (rc = i2c_master_recv(c, buffer, 16))) { | 212 | if (16 != (rc = tuner_i2c_xfer_recv(&i2c, buffer, 16))) { |
211 | tuner_warn("it is not a TEA5761. Received %i chars.\n", rc); | 213 | tuner_warn("it is not a TEA5761. Received %i chars.\n", rc); |
212 | return EINVAL; | 214 | return EINVAL; |
213 | } | 215 | } |
@@ -220,22 +222,37 @@ int tea5761_autodetection(struct i2c_client *c) | |||
220 | return 0; | 222 | return 0; |
221 | } | 223 | } |
222 | 224 | ||
225 | static void tea5761_release(struct tuner *t) | ||
226 | { | ||
227 | kfree(t->priv); | ||
228 | t->priv = NULL; | ||
229 | } | ||
230 | |||
223 | static struct tuner_operations tea5761_tuner_ops = { | 231 | static struct tuner_operations tea5761_tuner_ops = { |
224 | .set_tv_freq = set_tv_freq, | 232 | .set_tv_freq = set_tv_freq, |
225 | .set_radio_freq = set_radio_freq, | 233 | .set_radio_freq = set_radio_freq, |
226 | .has_signal = tea5761_signal, | 234 | .has_signal = tea5761_signal, |
227 | .is_stereo = tea5761_stereo, | 235 | .is_stereo = tea5761_stereo, |
236 | .release = tea5761_release, | ||
228 | }; | 237 | }; |
229 | 238 | ||
230 | int tea5761_tuner_init(struct i2c_client *c) | 239 | int tea5761_tuner_init(struct tuner *t) |
231 | { | 240 | { |
232 | struct tuner *t = i2c_get_clientdata(c); | 241 | struct tea5761_priv *priv = NULL; |
233 | 242 | ||
234 | if (tea5761_autodetection(c) == EINVAL) | 243 | if (tea5761_autodetection(t) == EINVAL) |
235 | return EINVAL; | 244 | return EINVAL; |
236 | 245 | ||
246 | priv = kzalloc(sizeof(struct tea5761_priv), GFP_KERNEL); | ||
247 | if (priv == NULL) | ||
248 | return -ENOMEM; | ||
249 | t->priv = priv; | ||
250 | |||
251 | priv->i2c_props.addr = t->i2c.addr; | ||
252 | priv->i2c_props.adap = t->i2c.adapter; | ||
253 | |||
237 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5761HN FM Radio"); | 254 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5761HN FM Radio"); |
238 | strlcpy(c->name, "tea5761", sizeof(c->name)); | 255 | strlcpy(t->i2c.name, "tea5761", sizeof(t->i2c.name)); |
239 | 256 | ||
240 | memcpy(&t->ops, &tea5761_tuner_ops, sizeof(struct tuner_operations)); | 257 | memcpy(&t->ops, &tea5761_tuner_ops, sizeof(struct tuner_operations)); |
241 | 258 | ||
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c index 4c9c4e01331a..5a08ec2f99fb 100644 --- a/drivers/media/video/tea5767.c +++ b/drivers/media/video/tea5767.c | |||
@@ -20,6 +20,10 @@ | |||
20 | /* from tuner-core.c */ | 20 | /* from tuner-core.c */ |
21 | extern int tuner_debug; | 21 | extern int tuner_debug; |
22 | 22 | ||
23 | struct tea5767_priv { | ||
24 | struct tuner_i2c_props i2c_props; | ||
25 | }; | ||
26 | |||
23 | /*****************************************************************************/ | 27 | /*****************************************************************************/ |
24 | 28 | ||
25 | /****************************** | 29 | /****************************** |
@@ -129,10 +133,8 @@ enum tea5767_xtal_freq { | |||
129 | 133 | ||
130 | /*****************************************************************************/ | 134 | /*****************************************************************************/ |
131 | 135 | ||
132 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) | 136 | static void set_tv_freq(struct tuner *t, unsigned int freq) |
133 | { | 137 | { |
134 | struct tuner *t = i2c_get_clientdata(c); | ||
135 | |||
136 | tuner_warn("This tuner doesn't support TV freq.\n"); | 138 | tuner_warn("This tuner doesn't support TV freq.\n"); |
137 | } | 139 | } |
138 | 140 | ||
@@ -190,9 +192,9 @@ static void tea5767_status_dump(unsigned char *buffer) | |||
190 | } | 192 | } |
191 | 193 | ||
192 | /* Freq should be specifyed at 62.5 Hz */ | 194 | /* Freq should be specifyed at 62.5 Hz */ |
193 | static void set_radio_freq(struct i2c_client *c, unsigned int frq) | 195 | static void set_radio_freq(struct tuner *t, unsigned int frq) |
194 | { | 196 | { |
195 | struct tuner *t = i2c_get_clientdata(c); | 197 | struct tea5767_priv *priv = t->priv; |
196 | unsigned char buffer[5]; | 198 | unsigned char buffer[5]; |
197 | unsigned div; | 199 | unsigned div; |
198 | int rc; | 200 | int rc; |
@@ -246,38 +248,38 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq) | |||
246 | buffer[0] = (div >> 8) & 0x3f; | 248 | buffer[0] = (div >> 8) & 0x3f; |
247 | buffer[1] = div & 0xff; | 249 | buffer[1] = div & 0xff; |
248 | 250 | ||
249 | if (5 != (rc = i2c_master_send(c, buffer, 5))) | 251 | if (5 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 5))) |
250 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 252 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
251 | 253 | ||
252 | if (tuner_debug) { | 254 | if (tuner_debug) { |
253 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) | 255 | if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) |
254 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 256 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
255 | else | 257 | else |
256 | tea5767_status_dump(buffer); | 258 | tea5767_status_dump(buffer); |
257 | } | 259 | } |
258 | } | 260 | } |
259 | 261 | ||
260 | static int tea5767_signal(struct i2c_client *c) | 262 | static int tea5767_signal(struct tuner *t) |
261 | { | 263 | { |
262 | unsigned char buffer[5]; | 264 | unsigned char buffer[5]; |
263 | int rc; | 265 | int rc; |
264 | struct tuner *t = i2c_get_clientdata(c); | 266 | struct tea5767_priv *priv = t->priv; |
265 | 267 | ||
266 | memset(buffer, 0, sizeof(buffer)); | 268 | memset(buffer, 0, sizeof(buffer)); |
267 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) | 269 | if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) |
268 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 270 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
269 | 271 | ||
270 | return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); | 272 | return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); |
271 | } | 273 | } |
272 | 274 | ||
273 | static int tea5767_stereo(struct i2c_client *c) | 275 | static int tea5767_stereo(struct tuner *t) |
274 | { | 276 | { |
275 | unsigned char buffer[5]; | 277 | unsigned char buffer[5]; |
276 | int rc; | 278 | int rc; |
277 | struct tuner *t = i2c_get_clientdata(c); | 279 | struct tea5767_priv *priv = t->priv; |
278 | 280 | ||
279 | memset(buffer, 0, sizeof(buffer)); | 281 | memset(buffer, 0, sizeof(buffer)); |
280 | if (5 != (rc = i2c_master_recv(c, buffer, 5))) | 282 | if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) |
281 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 283 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
282 | 284 | ||
283 | rc = buffer[2] & TEA5767_STEREO_MASK; | 285 | rc = buffer[2] & TEA5767_STEREO_MASK; |
@@ -287,10 +289,10 @@ static int tea5767_stereo(struct i2c_client *c) | |||
287 | return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); | 289 | return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); |
288 | } | 290 | } |
289 | 291 | ||
290 | static void tea5767_standby(struct i2c_client *c) | 292 | static void tea5767_standby(struct tuner *t) |
291 | { | 293 | { |
292 | unsigned char buffer[5]; | 294 | unsigned char buffer[5]; |
293 | struct tuner *t = i2c_get_clientdata(c); | 295 | struct tea5767_priv *priv = t->priv; |
294 | unsigned div, rc; | 296 | unsigned div, rc; |
295 | 297 | ||
296 | div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */ | 298 | div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */ |
@@ -301,17 +303,17 @@ static void tea5767_standby(struct i2c_client *c) | |||
301 | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY; | 303 | TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY; |
302 | buffer[4] = 0; | 304 | buffer[4] = 0; |
303 | 305 | ||
304 | if (5 != (rc = i2c_master_send(c, buffer, 5))) | 306 | if (5 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 5))) |
305 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); | 307 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
306 | } | 308 | } |
307 | 309 | ||
308 | int tea5767_autodetection(struct i2c_client *c) | 310 | int tea5767_autodetection(struct tuner *t) |
309 | { | 311 | { |
312 | struct tuner_i2c_props i2c = { .adap = t->i2c.adapter, .addr = t->i2c.addr }; | ||
310 | unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 313 | unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
311 | int rc; | 314 | int rc; |
312 | struct tuner *t = i2c_get_clientdata(c); | ||
313 | 315 | ||
314 | if ((rc = i2c_master_recv(c, buffer, 7))< 5) { | 316 | if ((rc = tuner_i2c_xfer_send(&i2c, buffer, 7))< 5) { |
315 | tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); | 317 | tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); |
316 | return EINVAL; | 318 | return EINVAL; |
317 | } | 319 | } |
@@ -343,20 +345,35 @@ int tea5767_autodetection(struct i2c_client *c) | |||
343 | return 0; | 345 | return 0; |
344 | } | 346 | } |
345 | 347 | ||
348 | static void tea5767_release(struct tuner *t) | ||
349 | { | ||
350 | kfree(t->priv); | ||
351 | t->priv = NULL; | ||
352 | } | ||
353 | |||
346 | static struct tuner_operations tea5767_tuner_ops = { | 354 | static struct tuner_operations tea5767_tuner_ops = { |
347 | .set_tv_freq = set_tv_freq, | 355 | .set_tv_freq = set_tv_freq, |
348 | .set_radio_freq = set_radio_freq, | 356 | .set_radio_freq = set_radio_freq, |
349 | .has_signal = tea5767_signal, | 357 | .has_signal = tea5767_signal, |
350 | .is_stereo = tea5767_stereo, | 358 | .is_stereo = tea5767_stereo, |
351 | .standby = tea5767_standby, | 359 | .standby = tea5767_standby, |
360 | .release = tea5767_release, | ||
352 | }; | 361 | }; |
353 | 362 | ||
354 | int tea5767_tuner_init(struct i2c_client *c) | 363 | int tea5767_tuner_init(struct tuner *t) |
355 | { | 364 | { |
356 | struct tuner *t = i2c_get_clientdata(c); | 365 | struct tea5767_priv *priv = NULL; |
366 | |||
367 | priv = kzalloc(sizeof(struct tea5767_priv), GFP_KERNEL); | ||
368 | if (priv == NULL) | ||
369 | return -ENOMEM; | ||
370 | t->priv = priv; | ||
371 | |||
372 | priv->i2c_props.addr = t->i2c.addr; | ||
373 | priv->i2c_props.adap = t->i2c.adapter; | ||
357 | 374 | ||
358 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio"); | 375 | tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio"); |
359 | strlcpy(c->name, "tea5767", sizeof(c->name)); | 376 | strlcpy(t->i2c.name, "tea5767", sizeof(t->i2c.name)); |
360 | 377 | ||
361 | memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations)); | 378 | memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations)); |
362 | 379 | ||
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c index f505f43bb126..0363eae800e7 100644 --- a/drivers/media/video/tuner-core.c +++ b/drivers/media/video/tuner-core.c | |||
@@ -94,7 +94,7 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
94 | else | 94 | else |
95 | freq = tv_range[1] * 16; | 95 | freq = tv_range[1] * 16; |
96 | } | 96 | } |
97 | t->ops.set_tv_freq(c, freq); | 97 | t->ops.set_tv_freq(t, freq); |
98 | } | 98 | } |
99 | 99 | ||
100 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) | 100 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) |
@@ -121,7 +121,7 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq) | |||
121 | freq = radio_range[1] * 16000; | 121 | freq = radio_range[1] * 16000; |
122 | } | 122 | } |
123 | 123 | ||
124 | t->ops.set_radio_freq(c, freq); | 124 | t->ops.set_radio_freq(t, freq); |
125 | } | 125 | } |
126 | 126 | ||
127 | static void set_freq(struct i2c_client *c, unsigned long freq) | 127 | static void set_freq(struct i2c_client *c, unsigned long freq) |
@@ -199,7 +199,7 @@ static void set_type(struct i2c_client *c, unsigned int type, | |||
199 | 199 | ||
200 | /* discard private data, in case set_type() was previously called */ | 200 | /* discard private data, in case set_type() was previously called */ |
201 | if (t->ops.release) | 201 | if (t->ops.release) |
202 | t->ops.release(c); | 202 | t->ops.release(t); |
203 | else { | 203 | else { |
204 | kfree(t->priv); | 204 | kfree(t->priv); |
205 | t->priv = NULL; | 205 | t->priv = NULL; |
@@ -207,13 +207,13 @@ static void set_type(struct i2c_client *c, unsigned int type, | |||
207 | 207 | ||
208 | switch (t->type) { | 208 | switch (t->type) { |
209 | case TUNER_MT2032: | 209 | case TUNER_MT2032: |
210 | microtune_init(c); | 210 | microtune_init(t); |
211 | break; | 211 | break; |
212 | case TUNER_PHILIPS_TDA8290: | 212 | case TUNER_PHILIPS_TDA8290: |
213 | tda8290_init(c); | 213 | tda8290_init(t); |
214 | break; | 214 | break; |
215 | case TUNER_TEA5767: | 215 | case TUNER_TEA5767: |
216 | if (tea5767_tuner_init(c) == EINVAL) { | 216 | if (tea5767_tuner_init(t) == EINVAL) { |
217 | t->type = TUNER_ABSENT; | 217 | t->type = TUNER_ABSENT; |
218 | t->mode_mask = T_UNINITIALIZED; | 218 | t->mode_mask = T_UNINITIALIZED; |
219 | return; | 219 | return; |
@@ -222,7 +222,7 @@ static void set_type(struct i2c_client *c, unsigned int type, | |||
222 | break; | 222 | break; |
223 | #ifdef CONFIG_TUNER_TEA5761 | 223 | #ifdef CONFIG_TUNER_TEA5761 |
224 | case TUNER_TEA5761: | 224 | case TUNER_TEA5761: |
225 | if (tea5761_tuner_init(c) == EINVAL) { | 225 | if (tea5761_tuner_init(t) == EINVAL) { |
226 | t->type = TUNER_ABSENT; | 226 | t->type = TUNER_ABSENT; |
227 | t->mode_mask = T_UNINITIALIZED; | 227 | t->mode_mask = T_UNINITIALIZED; |
228 | return; | 228 | return; |
@@ -240,7 +240,7 @@ static void set_type(struct i2c_client *c, unsigned int type, | |||
240 | buffer[2] = 0x86; | 240 | buffer[2] = 0x86; |
241 | buffer[3] = 0x54; | 241 | buffer[3] = 0x54; |
242 | i2c_master_send(c, buffer, 4); | 242 | i2c_master_send(c, buffer, 4); |
243 | default_tuner_init(c); | 243 | default_tuner_init(t); |
244 | break; | 244 | break; |
245 | case TUNER_PHILIPS_TD1316: | 245 | case TUNER_PHILIPS_TD1316: |
246 | buffer[0] = 0x0b; | 246 | buffer[0] = 0x0b; |
@@ -248,13 +248,13 @@ static void set_type(struct i2c_client *c, unsigned int type, | |||
248 | buffer[2] = 0x86; | 248 | buffer[2] = 0x86; |
249 | buffer[3] = 0xa4; | 249 | buffer[3] = 0xa4; |
250 | i2c_master_send(c,buffer,4); | 250 | i2c_master_send(c,buffer,4); |
251 | default_tuner_init(c); | 251 | default_tuner_init(t); |
252 | break; | 252 | break; |
253 | case TUNER_TDA9887: | 253 | case TUNER_TDA9887: |
254 | tda9887_tuner_init(c); | 254 | tda9887_tuner_init(t); |
255 | break; | 255 | break; |
256 | default: | 256 | default: |
257 | default_tuner_init(c); | 257 | default_tuner_init(t); |
258 | break; | 258 | break; |
259 | } | 259 | } |
260 | 260 | ||
@@ -426,9 +426,8 @@ static int tuner_fixup_std(struct tuner *t) | |||
426 | return 0; | 426 | return 0; |
427 | } | 427 | } |
428 | 428 | ||
429 | static void tuner_status(struct i2c_client *client) | 429 | static void tuner_status(struct tuner *t) |
430 | { | 430 | { |
431 | struct tuner *t = i2c_get_clientdata(client); | ||
432 | unsigned long freq, freq_fraction; | 431 | unsigned long freq, freq_fraction; |
433 | const char *p; | 432 | const char *p; |
434 | 433 | ||
@@ -451,10 +450,10 @@ static void tuner_status(struct i2c_client *client) | |||
451 | if (t->mode != V4L2_TUNER_RADIO) | 450 | if (t->mode != V4L2_TUNER_RADIO) |
452 | return; | 451 | return; |
453 | if (t->ops.has_signal) { | 452 | if (t->ops.has_signal) { |
454 | tuner_info("Signal strength: %d\n", t->ops.has_signal(client)); | 453 | tuner_info("Signal strength: %d\n", t->ops.has_signal(t)); |
455 | } | 454 | } |
456 | if (t->ops.is_stereo) { | 455 | if (t->ops.is_stereo) { |
457 | tuner_info("Stereo: %s\n", t->ops.is_stereo(client) ? "yes" : "no"); | 456 | tuner_info("Stereo: %s\n", t->ops.is_stereo(t) ? "yes" : "no"); |
458 | } | 457 | } |
459 | } | 458 | } |
460 | 459 | ||
@@ -503,7 +502,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) | |||
503 | switch (addr) { | 502 | switch (addr) { |
504 | #ifdef CONFIG_TUNER_TEA5761 | 503 | #ifdef CONFIG_TUNER_TEA5761 |
505 | case 0x10: | 504 | case 0x10: |
506 | if (tea5761_autodetection(&t->i2c) != EINVAL) { | 505 | if (tea5761_autodetection(t) != EINVAL) { |
507 | t->type = TUNER_TEA5761; | 506 | t->type = TUNER_TEA5761; |
508 | t->mode_mask = T_RADIO; | 507 | t->mode_mask = T_RADIO; |
509 | t->mode = T_STANDBY; | 508 | t->mode = T_STANDBY; |
@@ -520,7 +519,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) | |||
520 | case 0x4b: | 519 | case 0x4b: |
521 | /* If chip is not tda8290, don't register. | 520 | /* If chip is not tda8290, don't register. |
522 | since it can be tda9887*/ | 521 | since it can be tda9887*/ |
523 | if (tda8290_probe(&t->i2c) == 0) { | 522 | if (tda8290_probe(t) == 0) { |
524 | tuner_dbg("chip at addr %x is a tda8290\n", addr); | 523 | tuner_dbg("chip at addr %x is a tda8290\n", addr); |
525 | } else { | 524 | } else { |
526 | /* Default is being tda9887 */ | 525 | /* Default is being tda9887 */ |
@@ -531,7 +530,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) | |||
531 | } | 530 | } |
532 | break; | 531 | break; |
533 | case 0x60: | 532 | case 0x60: |
534 | if (tea5767_autodetection(&t->i2c) != EINVAL) { | 533 | if (tea5767_autodetection(t) != EINVAL) { |
535 | t->type = TUNER_TEA5767; | 534 | t->type = TUNER_TEA5767; |
536 | t->mode_mask = T_RADIO; | 535 | t->mode_mask = T_RADIO; |
537 | t->mode = T_STANDBY; | 536 | t->mode = T_STANDBY; |
@@ -588,7 +587,7 @@ static int tuner_detach(struct i2c_client *client) | |||
588 | } | 587 | } |
589 | 588 | ||
590 | if (t->ops.release) | 589 | if (t->ops.release) |
591 | t->ops.release(client); | 590 | t->ops.release(t); |
592 | else { | 591 | else { |
593 | kfree(t->priv); | 592 | kfree(t->priv); |
594 | } | 593 | } |
@@ -613,7 +612,7 @@ static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, | |||
613 | if (check_mode(t, cmd) == EINVAL) { | 612 | if (check_mode(t, cmd) == EINVAL) { |
614 | t->mode = T_STANDBY; | 613 | t->mode = T_STANDBY; |
615 | if (t->ops.standby) | 614 | if (t->ops.standby) |
616 | t->ops.standby (client); | 615 | t->ops.standby(t); |
617 | return EINVAL; | 616 | return EINVAL; |
618 | } | 617 | } |
619 | return 0; | 618 | return 0; |
@@ -662,7 +661,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) | |||
662 | return 0; | 661 | return 0; |
663 | t->mode = T_STANDBY; | 662 | t->mode = T_STANDBY; |
664 | if (t->ops.standby) | 663 | if (t->ops.standby) |
665 | t->ops.standby (client); | 664 | t->ops.standby(t); |
666 | break; | 665 | break; |
667 | #ifdef CONFIG_VIDEO_V4L1 | 666 | #ifdef CONFIG_VIDEO_V4L1 |
668 | case VIDIOCSAUDIO: | 667 | case VIDIOCSAUDIO: |
@@ -722,9 +721,9 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) | |||
722 | 721 | ||
723 | if (V4L2_TUNER_RADIO == t->mode) { | 722 | if (V4L2_TUNER_RADIO == t->mode) { |
724 | if (t->ops.has_signal) | 723 | if (t->ops.has_signal) |
725 | vt->signal = t->ops.has_signal(client); | 724 | vt->signal = t->ops.has_signal(t); |
726 | if (t->ops.is_stereo) { | 725 | if (t->ops.is_stereo) { |
727 | if (t->ops.is_stereo(client)) | 726 | if (t->ops.is_stereo(t)) |
728 | vt->flags |= | 727 | vt->flags |= |
729 | VIDEO_TUNER_STEREO_ON; | 728 | VIDEO_TUNER_STEREO_ON; |
730 | else | 729 | else |
@@ -753,7 +752,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) | |||
753 | return 0; | 752 | return 0; |
754 | 753 | ||
755 | if (V4L2_TUNER_RADIO == t->mode && t->ops.is_stereo) | 754 | if (V4L2_TUNER_RADIO == t->mode && t->ops.is_stereo) |
756 | va->mode = t->ops.is_stereo(client) | 755 | va->mode = t->ops.is_stereo(t) |
757 | ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; | 756 | ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; |
758 | return 0; | 757 | return 0; |
759 | } | 758 | } |
@@ -819,7 +818,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) | |||
819 | 818 | ||
820 | tuner->type = t->mode; | 819 | tuner->type = t->mode; |
821 | if (t->ops.get_afc) | 820 | if (t->ops.get_afc) |
822 | tuner->afc=t->ops.get_afc(client); | 821 | tuner->afc=t->ops.get_afc(t); |
823 | if (t->mode == V4L2_TUNER_ANALOG_TV) | 822 | if (t->mode == V4L2_TUNER_ANALOG_TV) |
824 | tuner->capability |= V4L2_TUNER_CAP_NORM; | 823 | tuner->capability |= V4L2_TUNER_CAP_NORM; |
825 | if (t->mode != V4L2_TUNER_RADIO) { | 824 | if (t->mode != V4L2_TUNER_RADIO) { |
@@ -830,12 +829,12 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) | |||
830 | 829 | ||
831 | /* radio mode */ | 830 | /* radio mode */ |
832 | if (t->ops.has_signal) | 831 | if (t->ops.has_signal) |
833 | tuner->signal = t->ops.has_signal(client); | 832 | tuner->signal = t->ops.has_signal(t); |
834 | 833 | ||
835 | tuner->rxsubchans = | 834 | tuner->rxsubchans = |
836 | V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; | 835 | V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
837 | if (t->ops.is_stereo) { | 836 | if (t->ops.is_stereo) { |
838 | tuner->rxsubchans = t->ops.is_stereo(client) ? | 837 | tuner->rxsubchans = t->ops.is_stereo(t) ? |
839 | V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; | 838 | V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; |
840 | } | 839 | } |
841 | 840 | ||
@@ -864,7 +863,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) | |||
864 | } | 863 | } |
865 | case VIDIOC_LOG_STATUS: | 864 | case VIDIOC_LOG_STATUS: |
866 | if (t->ops.tuner_status) | 865 | if (t->ops.tuner_status) |
867 | t->ops.tuner_status(client); | 866 | t->ops.tuner_status(t); |
868 | break; | 867 | break; |
869 | } | 868 | } |
870 | 869 | ||
diff --git a/drivers/media/video/tuner-driver.h b/drivers/media/video/tuner-driver.h index 145045561a51..3cd1d446f2f3 100644 --- a/drivers/media/video/tuner-driver.h +++ b/drivers/media/video/tuner-driver.h | |||
@@ -24,18 +24,21 @@ | |||
24 | 24 | ||
25 | #include <linux/videodev2.h> | 25 | #include <linux/videodev2.h> |
26 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include "tuner-i2c.h" | ||
27 | 28 | ||
28 | extern unsigned const int tuner_count; | 29 | extern unsigned const int tuner_count; |
29 | 30 | ||
31 | struct tuner; | ||
32 | |||
30 | struct tuner_operations { | 33 | struct tuner_operations { |
31 | void (*set_tv_freq)(struct i2c_client *c, unsigned int freq); | 34 | void (*set_tv_freq)(struct tuner *t, unsigned int freq); |
32 | void (*set_radio_freq)(struct i2c_client *c, unsigned int freq); | 35 | void (*set_radio_freq)(struct tuner *t, unsigned int freq); |
33 | int (*has_signal)(struct i2c_client *c); | 36 | int (*has_signal)(struct tuner *t); |
34 | int (*is_stereo)(struct i2c_client *c); | 37 | int (*is_stereo)(struct tuner *t); |
35 | int (*get_afc)(struct i2c_client *c); | 38 | int (*get_afc)(struct tuner *t); |
36 | void (*tuner_status)(struct i2c_client *c); | 39 | void (*tuner_status)(struct tuner *t); |
37 | void (*standby)(struct i2c_client *c); | 40 | void (*standby)(struct tuner *t); |
38 | void (*release)(struct i2c_client *c); | 41 | void (*release)(struct tuner *t); |
39 | }; | 42 | }; |
40 | 43 | ||
41 | struct tuner { | 44 | struct tuner { |
@@ -66,20 +69,20 @@ struct tuner { | |||
66 | 69 | ||
67 | /* ------------------------------------------------------------------------ */ | 70 | /* ------------------------------------------------------------------------ */ |
68 | 71 | ||
69 | extern int default_tuner_init(struct i2c_client *c); | 72 | extern int default_tuner_init(struct tuner *t); |
70 | 73 | ||
71 | extern int tda9887_tuner_init(struct i2c_client *c); | 74 | extern int tda9887_tuner_init(struct tuner *t); |
72 | 75 | ||
73 | extern int microtune_init(struct i2c_client *c); | 76 | extern int microtune_init(struct tuner *t); |
74 | 77 | ||
75 | extern int tda8290_init(struct i2c_client *c); | 78 | extern int tda8290_init(struct tuner *t); |
76 | extern int tda8290_probe(struct i2c_client *c); | 79 | extern int tda8290_probe(struct tuner *t); |
77 | 80 | ||
78 | extern int tea5761_tuner_init(struct i2c_client *c); | 81 | extern int tea5761_tuner_init(struct tuner *t); |
79 | extern int tea5761_autodetection(struct i2c_client *c); | 82 | extern int tea5761_autodetection(struct tuner *t); |
80 | 83 | ||
81 | extern int tea5767_autodetection(struct i2c_client *c); | 84 | extern int tea5767_autodetection(struct tuner *t); |
82 | extern int tea5767_tuner_init(struct i2c_client *c); | 85 | extern int tea5767_tuner_init(struct tuner *t); |
83 | 86 | ||
84 | /* ------------------------------------------------------------------------ */ | 87 | /* ------------------------------------------------------------------------ */ |
85 | 88 | ||
diff --git a/drivers/media/video/tuner-i2c.h b/drivers/media/video/tuner-i2c.h new file mode 100644 index 000000000000..159019ec3373 --- /dev/null +++ b/drivers/media/video/tuner-i2c.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | tuner-i2c.h - i2c interface for different tuners | ||
3 | |||
4 | Copyright (C) 2007 Michael Krufky (mkrufky@linuxtv.org) | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2 of the License, or | ||
9 | (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef __TUNER_I2C_H__ | ||
22 | #define __TUNER_I2C_H__ | ||
23 | |||
24 | #include <linux/i2c.h> | ||
25 | |||
26 | struct tuner_i2c_props { | ||
27 | u8 addr; | ||
28 | struct i2c_adapter *adap; | ||
29 | }; | ||
30 | |||
31 | static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len) | ||
32 | { | ||
33 | struct i2c_msg msg = { .addr = props->addr, .flags = 0, | ||
34 | .buf = buf, .len = len }; | ||
35 | int ret = i2c_transfer(props->adap, &msg, 1); | ||
36 | |||
37 | return (ret == 1) ? len : ret; | ||
38 | } | ||
39 | |||
40 | static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len) | ||
41 | { | ||
42 | struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD, | ||
43 | .buf = buf, .len = len }; | ||
44 | int ret = i2c_transfer(props->adap, &msg, 1); | ||
45 | |||
46 | return (ret == 1) ? len : ret; | ||
47 | } | ||
48 | |||
49 | #ifndef __TUNER_DRIVER_H__ | ||
50 | #define tuner_warn(fmt, arg...) do {\ | ||
51 | printk(KERN_WARNING PREFIX "%d-%04x: " fmt, \ | ||
52 | i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0) | ||
53 | #define tuner_info(fmt, arg...) do {\ | ||
54 | printk(KERN_INFO PREFIX "%d-%04x: " fmt, \ | ||
55 | i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0) | ||
56 | #define tuner_dbg(fmt, arg...) do {\ | ||
57 | if ((debug)) \ | ||
58 | printk(KERN_DEBUG PREFIX "%d-%04x: " fmt, \ | ||
59 | i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0) | ||
60 | #endif /* __TUNER_DRIVER_H__ */ | ||
61 | |||
62 | #endif /* __TUNER_I2C_H__ */ | ||
63 | |||
64 | /* | ||
65 | * Overrides for Emacs so that we follow Linus's tabbing style. | ||
66 | * --------------------------------------------------------------------------- | ||
67 | * Local variables: | ||
68 | * c-basic-offset: 8 | ||
69 | * End: | ||
70 | */ | ||
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c index 572f22423b98..eca2ff249a36 100644 --- a/drivers/media/video/tuner-simple.c +++ b/drivers/media/video/tuner-simple.c | |||
@@ -84,31 +84,32 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner"); | |||
84 | 84 | ||
85 | struct tuner_simple_priv { | 85 | struct tuner_simple_priv { |
86 | u16 last_div; | 86 | u16 last_div; |
87 | struct tuner_i2c_props i2c_props; | ||
87 | }; | 88 | }; |
88 | 89 | ||
89 | /* ---------------------------------------------------------------------- */ | 90 | /* ---------------------------------------------------------------------- */ |
90 | 91 | ||
91 | static int tuner_getstatus(struct i2c_client *c) | 92 | static int tuner_getstatus(struct tuner *t) |
92 | { | 93 | { |
94 | struct tuner_simple_priv *priv = t->priv; | ||
93 | unsigned char byte; | 95 | unsigned char byte; |
94 | 96 | ||
95 | if (1 != i2c_master_recv(c,&byte,1)) | 97 | if (1 != tuner_i2c_xfer_recv(&priv->i2c_props,&byte,1)) |
96 | return 0; | 98 | return 0; |
97 | 99 | ||
98 | return byte; | 100 | return byte; |
99 | } | 101 | } |
100 | 102 | ||
101 | static int tuner_signal(struct i2c_client *c) | 103 | static int tuner_signal(struct tuner *t) |
102 | { | 104 | { |
103 | return (tuner_getstatus(c) & TUNER_SIGNAL) << 13; | 105 | return (tuner_getstatus(t) & TUNER_SIGNAL) << 13; |
104 | } | 106 | } |
105 | 107 | ||
106 | static int tuner_stereo(struct i2c_client *c) | 108 | static int tuner_stereo(struct tuner *t) |
107 | { | 109 | { |
108 | int stereo, status; | 110 | int stereo, status; |
109 | struct tuner *t = i2c_get_clientdata(c); | ||
110 | 111 | ||
111 | status = tuner_getstatus (c); | 112 | status = tuner_getstatus(t); |
112 | 113 | ||
113 | switch (t->type) { | 114 | switch (t->type) { |
114 | case TUNER_PHILIPS_FM1216ME_MK3: | 115 | case TUNER_PHILIPS_FM1216ME_MK3: |
@@ -127,9 +128,8 @@ static int tuner_stereo(struct i2c_client *c) | |||
127 | 128 | ||
128 | /* ---------------------------------------------------------------------- */ | 129 | /* ---------------------------------------------------------------------- */ |
129 | 130 | ||
130 | static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) | 131 | static void default_set_tv_freq(struct tuner *t, unsigned int freq) |
131 | { | 132 | { |
132 | struct tuner *t = i2c_get_clientdata(c); | ||
133 | struct tuner_simple_priv *priv = t->priv; | 133 | struct tuner_simple_priv *priv = t->priv; |
134 | u8 config, cb, tuneraddr; | 134 | u8 config, cb, tuneraddr; |
135 | u16 div; | 135 | u16 div; |
@@ -285,13 +285,13 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
285 | buffer[1] = 0x04; | 285 | buffer[1] = 0x04; |
286 | } | 286 | } |
287 | /* set to the correct mode (analog or digital) */ | 287 | /* set to the correct mode (analog or digital) */ |
288 | tuneraddr = c->addr; | 288 | tuneraddr = priv->i2c_props.addr; |
289 | c->addr = 0x0a; | 289 | priv->i2c_props.addr = 0x0a; |
290 | if (2 != (rc = i2c_master_send(c,&buffer[0],2))) | 290 | if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[0],2))) |
291 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); | 291 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); |
292 | if (2 != (rc = i2c_master_send(c,&buffer[2],2))) | 292 | if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[2],2))) |
293 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); | 293 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); |
294 | c->addr = tuneraddr; | 294 | priv->i2c_props.addr = tuneraddr; |
295 | /* FIXME: input */ | 295 | /* FIXME: input */ |
296 | break; | 296 | break; |
297 | } | 297 | } |
@@ -345,12 +345,12 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
345 | } | 345 | } |
346 | if (params->default_pll_gating_18) | 346 | if (params->default_pll_gating_18) |
347 | config |= TDA9887_GATING_18; | 347 | config |= TDA9887_GATING_18; |
348 | i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); | 348 | i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config); |
349 | } | 349 | } |
350 | tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", | 350 | tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", |
351 | buffer[0],buffer[1],buffer[2],buffer[3]); | 351 | buffer[0],buffer[1],buffer[2],buffer[3]); |
352 | 352 | ||
353 | if (4 != (rc = i2c_master_send(c,buffer,4))) | 353 | if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4))) |
354 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); | 354 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); |
355 | 355 | ||
356 | switch (t->type) { | 356 | switch (t->type) { |
@@ -362,7 +362,7 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
362 | buffer[1] = 0x20; | 362 | buffer[1] = 0x20; |
363 | tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]); | 363 | tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]); |
364 | 364 | ||
365 | if (2 != (rc = i2c_master_send(c,buffer,2))) | 365 | if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,2))) |
366 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); | 366 | tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); |
367 | break; | 367 | break; |
368 | case TUNER_MICROTUNE_4042FI5: | 368 | case TUNER_MICROTUNE_4042FI5: |
@@ -375,7 +375,7 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
375 | for (;;) { | 375 | for (;;) { |
376 | if (time_after(jiffies,timeout)) | 376 | if (time_after(jiffies,timeout)) |
377 | return; | 377 | return; |
378 | if (1 != (rc = i2c_master_recv(c,&status_byte,1))) { | 378 | if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,&status_byte,1))) { |
379 | tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc); | 379 | tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc); |
380 | break; | 380 | break; |
381 | } | 381 | } |
@@ -393,17 +393,16 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) | |||
393 | tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", | 393 | tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", |
394 | buffer[0],buffer[1],buffer[2],buffer[3]); | 394 | buffer[0],buffer[1],buffer[2],buffer[3]); |
395 | 395 | ||
396 | if (4 != (rc = i2c_master_send(c,buffer,4))) | 396 | if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4))) |
397 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); | 397 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); |
398 | break; | 398 | break; |
399 | } | 399 | } |
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | static void default_set_radio_freq(struct i2c_client *c, unsigned int freq) | 403 | static void default_set_radio_freq(struct tuner *t, unsigned int freq) |
404 | { | 404 | { |
405 | struct tunertype *tun; | 405 | struct tunertype *tun; |
406 | struct tuner *t = i2c_get_clientdata(c); | ||
407 | struct tuner_simple_priv *priv = t->priv; | 406 | struct tuner_simple_priv *priv = t->priv; |
408 | u8 buffer[4]; | 407 | u8 buffer[4]; |
409 | u16 div; | 408 | u16 div; |
@@ -498,16 +497,14 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq) | |||
498 | config |= TDA9887_GAIN_NORMAL; | 497 | config |= TDA9887_GAIN_NORMAL; |
499 | if (params->radio_if == 2) | 498 | if (params->radio_if == 2) |
500 | config |= TDA9887_RIF_41_3; | 499 | config |= TDA9887_RIF_41_3; |
501 | i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); | 500 | i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config); |
502 | } | 501 | } |
503 | if (4 != (rc = i2c_master_send(c,buffer,4))) | 502 | if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4))) |
504 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); | 503 | tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); |
505 | } | 504 | } |
506 | 505 | ||
507 | static void tuner_release(struct i2c_client *c) | 506 | static void tuner_release(struct tuner *t) |
508 | { | 507 | { |
509 | struct tuner *t = i2c_get_clientdata(c); | ||
510 | |||
511 | kfree(t->priv); | 508 | kfree(t->priv); |
512 | t->priv = NULL; | 509 | t->priv = NULL; |
513 | } | 510 | } |
@@ -520,9 +517,8 @@ static struct tuner_operations simple_tuner_ops = { | |||
520 | .release = tuner_release, | 517 | .release = tuner_release, |
521 | }; | 518 | }; |
522 | 519 | ||
523 | int default_tuner_init(struct i2c_client *c) | 520 | int default_tuner_init(struct tuner *t) |
524 | { | 521 | { |
525 | struct tuner *t = i2c_get_clientdata(c); | ||
526 | struct tuner_simple_priv *priv = NULL; | 522 | struct tuner_simple_priv *priv = NULL; |
527 | 523 | ||
528 | priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL); | 524 | priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL); |
@@ -530,9 +526,12 @@ int default_tuner_init(struct i2c_client *c) | |||
530 | return -ENOMEM; | 526 | return -ENOMEM; |
531 | t->priv = priv; | 527 | t->priv = priv; |
532 | 528 | ||
529 | priv->i2c_props.addr = t->i2c.addr; | ||
530 | priv->i2c_props.adap = t->i2c.adapter; | ||
531 | |||
533 | tuner_info("type set to %d (%s)\n", | 532 | tuner_info("type set to %d (%s)\n", |
534 | t->type, tuners[t->type].name); | 533 | t->type, tuners[t->type].name); |
535 | strlcpy(c->name, tuners[t->type].name, sizeof(c->name)); | 534 | strlcpy(t->i2c.name, tuners[t->type].name, sizeof(t->i2c.name)); |
536 | 535 | ||
537 | memcpy(&t->ops, &simple_tuner_ops, sizeof(struct tuner_operations)); | 536 | memcpy(&t->ops, &simple_tuner_ops, sizeof(struct tuner_operations)); |
538 | 537 | ||