aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tuner-core.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@brturbo.com.br>2005-06-24 01:05:07 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-24 03:06:39 -0400
commit56fc08ca375491b965cb76fad65bfb98973e80d8 (patch)
treed19bb1d6e1d139dda8989188fae49cf124f3aaac /drivers/media/video/tuner-core.c
parentb45009b0288a96a3458f4f8e93cb776678d41875 (diff)
[PATCH] v4l: update for tuner cards and some V4L chips
Tuner improvements and additions. TEA5767 FM tuner added. Several small fixes. Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> Signed-off-by: Nickolay V Shmyrev <nshmyrev@yandex.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/media/video/tuner-core.c')
-rw-r--r--drivers/media/video/tuner-core.c212
1 files changed, 145 insertions, 67 deletions
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 71423ae3b4d..ba13bfadb52 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: tuner-core.c,v 1.7 2005/05/30 02:02:47 mchehab Exp $ 2 * $Id: tuner-core.c,v 1.15 2005/06/12 01:36:14 mchehab Exp $
3 * 3 *
4 * i2c tv tuner chip device driver 4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on 5 * core core, i.e. kernel interfaces, registering and so on
@@ -26,15 +26,17 @@
26/* 26/*
27 * comment line bellow to return to old behavor, where only one I2C device is supported 27 * comment line bellow to return to old behavor, where only one I2C device is supported
28 */ 28 */
29/* #define CONFIG_TUNER_MULTI_I2C */ 29#define CONFIG_TUNER_MULTI_I2C /**/
30 30
31#define UNSET (-1U) 31#define UNSET (-1U)
32 32
33/* standard i2c insmod options */ 33/* standard i2c insmod options */
34static unsigned short normal_i2c[] = { 34static unsigned short normal_i2c[] = {
35 0x4b, /* tda8290 */ 35 0x4b, /* tda8290 */
36 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 36 I2C_CLIENT_END
37 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 37};
38static unsigned short normal_i2c_range[] = {
39 0x60, 0x6f,
38 I2C_CLIENT_END 40 I2C_CLIENT_END
39}; 41};
40I2C_CLIENT_INSMOD; 42I2C_CLIENT_INSMOD;
@@ -59,7 +61,7 @@ MODULE_LICENSE("GPL");
59 61
60static int this_adap; 62static int this_adap;
61#ifdef CONFIG_TUNER_MULTI_I2C 63#ifdef CONFIG_TUNER_MULTI_I2C
62static unsigned short tv_tuner, radio_tuner; 64static unsigned short first_tuner, tv_tuner, radio_tuner;
63#endif 65#endif
64 66
65static struct i2c_driver driver; 67static struct i2c_driver driver;
@@ -67,7 +69,7 @@ static struct i2c_client client_template;
67 69
68/* ---------------------------------------------------------------------- */ 70/* ---------------------------------------------------------------------- */
69 71
70// Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz 72/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
71static void set_tv_freq(struct i2c_client *c, unsigned int freq) 73static void set_tv_freq(struct i2c_client *c, unsigned int freq)
72{ 74{
73 struct tuner *t = i2c_get_clientdata(c); 75 struct tuner *t = i2c_get_clientdata(c);
@@ -81,14 +83,26 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
81 return; 83 return;
82 } 84 }
83 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) { 85 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) {
84 /* FIXME: better do that chip-specific, but 86
85 right now we don't have that in the config 87 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
86 struct and this way is still better than no 88 /* V4L2_TUNER_CAP_LOW frequency */
87 check at all */ 89
88 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n", 90 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for TV. Tuners yet doesn't support converting it to valid freq.\n");
89 freq/16,freq%16*100/16,tv_range[0],tv_range[1]); 91
90 return; 92 t->tv_freq(c,freq>>10);
93
94 return;
95 } else {
96 /* FIXME: better do that chip-specific, but
97 right now we don't have that in the config
98 struct and this way is still better than no
99 check at all */
100 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n",
101 freq/16,freq%16*100/16,tv_range[0],tv_range[1]);
102 return;
103 }
91 } 104 }
105 tuner_dbg("62.5 Khz freq step selected for TV.\n");
92 t->tv_freq(c,freq); 106 t->tv_freq(c,freq);
93} 107}
94 108
@@ -105,11 +119,29 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
105 return; 119 return;
106 } 120 }
107 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) { 121 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) {
108 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n", 122 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
123 /* V4L2_TUNER_CAP_LOW frequency */
124 if (t->type == TUNER_TEA5767) {
125 tuner_info("radio freq step 62.5Hz (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
126 t->radio_freq(c,freq>>10);
127 return;
128 }
129
130 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for Radio. Tuners yet doesn't support converting it to valid freq.\n");
131
132 tuner_info("radio freq (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
133
134 t->radio_freq(c,freq>>10);
135 return;
136
137 } else {
138 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
109 freq/16,freq%16*100/16, 139 freq/16,freq%16*100/16,
110 radio_range[0],radio_range[1]); 140 radio_range[0],radio_range[1]);
111 return; 141 return;
142 }
112 } 143 }
144 tuner_dbg("62.5 Khz freq step selected for Radio.\n");
113 t->radio_freq(c,freq); 145 t->radio_freq(c,freq);
114} 146}
115 147
@@ -133,34 +165,13 @@ static void set_freq(struct i2c_client *c, unsigned long freq)
133 t->freq = freq; 165 t->freq = freq;
134} 166}
135 167
136#ifdef CONFIG_TUNER_MULTI_I2C
137static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
138{
139 struct tuner *t = i2c_get_clientdata(c);
140
141 switch (tun_addr->type) {
142 case V4L2_TUNER_RADIO:
143 radio_tuner=tun_addr->addr;
144 tuner_dbg("radio tuner set to I2C address 0x%02x\n",radio_tuner<<1);
145
146 break;
147 default:
148 tv_tuner=tun_addr->addr;
149 tuner_dbg("TV tuner set to I2C address 0x%02x\n",tv_tuner<<1);
150 break;
151 }
152}
153#else
154#define set_addr(c,tun_addr) \
155 tuner_warn("It is recommended to enable CONFIG_TUNER_MULTI_I2C for this card.\n");
156#endif
157
158static void set_type(struct i2c_client *c, unsigned int type) 168static void set_type(struct i2c_client *c, unsigned int type)
159{ 169{
160 struct tuner *t = i2c_get_clientdata(c); 170 struct tuner *t = i2c_get_clientdata(c);
161 171
172 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type);
162 /* sanity check */ 173 /* sanity check */
163 if (type == UNSET || type == TUNER_ABSENT) 174 if (type == UNSET || type == TUNER_ABSENT)
164 return; 175 return;
165 if (type >= tuner_count) 176 if (type >= tuner_count)
166 return; 177 return;
@@ -175,6 +186,7 @@ static void set_type(struct i2c_client *c, unsigned int type)
175 return; 186 return;
176 187
177 t->initialized = 1; 188 t->initialized = 1;
189
178 t->type = type; 190 t->type = type;
179 switch (t->type) { 191 switch (t->type) {
180 case TUNER_MT2032: 192 case TUNER_MT2032:
@@ -189,6 +201,53 @@ static void set_type(struct i2c_client *c, unsigned int type)
189 } 201 }
190} 202}
191 203
204#ifdef CONFIG_TUNER_MULTI_I2C
205#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \
206 return 0; } else \
207 tuner_info ("Cmd %s accepted to "tun"\n",cmd);
208#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \
209 CHECK_ADDR(radio_tuner,cmd,"radio") } else \
210 { CHECK_ADDR(tv_tuner,cmd,"TV"); }
211#else
212#define CHECK_ADDR(tp,cmd,tun) tuner_info ("Cmd %s accepted to "tun"\n",cmd);
213#define CHECK_MODE(cmd) tuner_info ("Cmd %s accepted\n",cmd);
214#endif
215
216#ifdef CONFIG_TUNER_MULTI_I2C
217
218static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
219{
220 /* ADDR_UNSET defaults to first available tuner */
221 if ( tun_addr->addr == ADDR_UNSET ) {
222 if (first_tuner != c->addr)
223 return;
224 switch (tun_addr->v4l2_tuner) {
225 case V4L2_TUNER_RADIO:
226 radio_tuner=c->addr;
227 break;
228 default:
229 tv_tuner=c->addr;
230 break;
231 }
232 } else {
233 /* Sets tuner to its configured value */
234 switch (tun_addr->v4l2_tuner) {
235 case V4L2_TUNER_RADIO:
236 radio_tuner=tun_addr->addr;
237 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
238 return;
239 default:
240 tv_tuner=tun_addr->addr;
241 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
242 return;
243 }
244 }
245 set_type(c,tun_addr->type);
246}
247#else
248#define set_addr(c,tun_addr) set_type(c,(tun_addr)->type)
249#endif
250
192static char pal[] = "-"; 251static char pal[] = "-";
193module_param_string(pal, pal, sizeof(pal), 0644); 252module_param_string(pal, pal, sizeof(pal), 0644);
194 253
@@ -233,6 +292,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
233#else 292#else
234 /* by default, first I2C card is both tv and radio tuner */ 293 /* by default, first I2C card is both tv and radio tuner */
235 if (this_adap == 0) { 294 if (this_adap == 0) {
295 first_tuner = addr;
236 tv_tuner = addr; 296 tv_tuner = addr;
237 radio_tuner = addr; 297 radio_tuner = addr;
238 } 298 }
@@ -249,11 +309,12 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
249 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client)); 309 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client));
250 i2c_set_clientdata(&t->i2c, t); 310 i2c_set_clientdata(&t->i2c, t);
251 t->type = UNSET; 311 t->type = UNSET;
252 t->radio_if2 = 10700*1000; // 10.7MHz - FM radio 312 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */
253 313
254 i2c_attach_client(&t->i2c); 314 i2c_attach_client(&t->i2c);
255 tuner_info("chip found @ 0x%x (%s)\n", 315 tuner_info("chip found @ 0x%x (%s)\n",
256 addr << 1, adap->name); 316 addr << 1, adap->name);
317
257 set_type(&t->i2c, t->type); 318 set_type(&t->i2c, t->type);
258 return 0; 319 return 0;
259} 320}
@@ -261,12 +322,14 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
261static int tuner_probe(struct i2c_adapter *adap) 322static int tuner_probe(struct i2c_adapter *adap)
262{ 323{
263 if (0 != addr) { 324 if (0 != addr) {
264 normal_i2c[0] = addr; 325 normal_i2c[0] = addr;
265 normal_i2c[1] = I2C_CLIENT_END; 326 normal_i2c_range[0] = addr;
327 normal_i2c_range[1] = addr;
266 } 328 }
267 this_adap = 0; 329 this_adap = 0;
268 330
269#ifdef CONFIG_TUNER_MULTI_I2C 331#ifdef CONFIG_TUNER_MULTI_I2C
332 first_tuner = 0;
270 tv_tuner = 0; 333 tv_tuner = 0;
271 radio_tuner = 0; 334 radio_tuner = 0;
272#endif 335#endif
@@ -298,17 +361,6 @@ static int tuner_detach(struct i2c_client *client)
298 tuner_info("ignore v4l1 call\n"); \ 361 tuner_info("ignore v4l1 call\n"); \
299 return 0; } 362 return 0; }
300 363
301#ifdef CONFIG_TUNER_MULTI_I2C
302#define CHECK_ADDR(tp,cmd) if (client->addr!=tp) { \
303 tuner_info ("Cmd %s to addr 0x%02x rejected.\n",cmd,client->addr<<1); \
304 return 0; }
305#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \
306 CHECK_ADDR(radio_tuner,cmd) } else { CHECK_ADDR(tv_tuner,cmd); }
307#else
308#define CHECK_ADDR(tp,cmd)
309#define CHECK_MODE(cmd)
310#endif
311
312static int 364static int
313tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) 365tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
314{ 366{
@@ -320,19 +372,19 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
320 case TUNER_SET_TYPE: 372 case TUNER_SET_TYPE:
321 set_type(client,*iarg); 373 set_type(client,*iarg);
322 break; 374 break;
323 case TUNER_SET_ADDR: 375 case TUNER_SET_TYPE_ADDR:
324 set_addr(client,(struct tuner_addr *)arg); 376 set_addr(client,(struct tuner_addr *)arg);
325 break; 377 break;
326 case AUDC_SET_RADIO: 378 case AUDC_SET_RADIO:
327 CHECK_ADDR(radio_tuner,"AUDC_SET_RADIO"); 379 t->mode = V4L2_TUNER_RADIO;
380 CHECK_ADDR(tv_tuner,"AUDC_SET_RADIO","TV");
328 381
329 if (V4L2_TUNER_RADIO != t->mode) { 382 if (V4L2_TUNER_RADIO != t->mode) {
330 set_tv_freq(client,400 * 16); 383 set_tv_freq(client,400 * 16);
331 t->mode = V4L2_TUNER_RADIO;
332 } 384 }
333 break; 385 break;
334 case AUDC_CONFIG_PINNACLE: 386 case AUDC_CONFIG_PINNACLE:
335 CHECK_ADDR(tv_tuner,"AUDC_CONFIG_PINNACLE"); 387 CHECK_ADDR(tv_tuner,"AUDC_CONFIG_PINNACLE","TV");
336 switch (*iarg) { 388 switch (*iarg) {
337 case 2: 389 case 2:
338 tuner_dbg("pinnacle pal\n"); 390 tuner_dbg("pinnacle pal\n");
@@ -360,9 +412,10 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
360 }; 412 };
361 struct video_channel *vc = arg; 413 struct video_channel *vc = arg;
362 414
363 CHECK_ADDR(tv_tuner,"VIDIOCSCHAN");
364 CHECK_V4L2; 415 CHECK_V4L2;
365 t->mode = V4L2_TUNER_ANALOG_TV; 416 t->mode = V4L2_TUNER_ANALOG_TV;
417 CHECK_ADDR(tv_tuner,"VIDIOCSCHAN","TV");
418
366 if (vc->norm < ARRAY_SIZE(map)) 419 if (vc->norm < ARRAY_SIZE(map))
367 t->std = map[vc->norm]; 420 t->std = map[vc->norm];
368 tuner_fixup_std(t); 421 tuner_fixup_std(t);
@@ -383,17 +436,27 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
383 { 436 {
384 struct video_tuner *vt = arg; 437 struct video_tuner *vt = arg;
385 438
386 CHECK_ADDR(radio_tuner,"VIDIOCGTUNER:"); 439 CHECK_ADDR(radio_tuner,"VIDIOCGTUNER","radio");
387 CHECK_V4L2; 440 CHECK_V4L2;
388 if (V4L2_TUNER_RADIO == t->mode && t->has_signal) 441 if (V4L2_TUNER_RADIO == t->mode) {
389 vt->signal = t->has_signal(client); 442 if (t->has_signal)
443 vt->signal = t->has_signal(client);
444 if (t->is_stereo) {
445 if (t->is_stereo(client))
446 vt-> flags |= VIDEO_TUNER_STEREO_ON;
447 else
448 vt-> flags &= 0xffff ^ VIDEO_TUNER_STEREO_ON;
449 }
450 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */
451 }
452
390 return 0; 453 return 0;
391 } 454 }
392 case VIDIOCGAUDIO: 455 case VIDIOCGAUDIO:
393 { 456 {
394 struct video_audio *va = arg; 457 struct video_audio *va = arg;
395 458
396 CHECK_ADDR(radio_tuner,"VIDIOCGAUDIO"); 459 CHECK_ADDR(radio_tuner,"VIDIOCGAUDIO","radio");
397 CHECK_V4L2; 460 CHECK_V4L2;
398 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo) 461 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
399 va->mode = t->is_stereo(client) 462 va->mode = t->is_stereo(client)
@@ -406,9 +469,10 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
406 { 469 {
407 v4l2_std_id *id = arg; 470 v4l2_std_id *id = arg;
408 471
409 CHECK_ADDR(tv_tuner,"VIDIOC_S_STD");
410 SWITCH_V4L2; 472 SWITCH_V4L2;
411 t->mode = V4L2_TUNER_ANALOG_TV; 473 t->mode = V4L2_TUNER_ANALOG_TV;
474 CHECK_ADDR(tv_tuner,"VIDIOC_S_STD","TV");
475
412 t->std = *id; 476 t->std = *id;
413 tuner_fixup_std(t); 477 tuner_fixup_std(t);
414 if (t->freq) 478 if (t->freq)
@@ -444,13 +508,27 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
444 508
445 CHECK_MODE("VIDIOC_G_TUNER"); 509 CHECK_MODE("VIDIOC_G_TUNER");
446 SWITCH_V4L2; 510 SWITCH_V4L2;
447 if (V4L2_TUNER_RADIO == t->mode && t->has_signal) 511 if (V4L2_TUNER_RADIO == t->mode) {
448 tuner->signal = t->has_signal(client); 512 if (t->has_signal)
513 tuner -> signal = t->has_signal(client);
514 if (t->is_stereo) {
515 if (t->is_stereo(client)) {
516 tuner -> capability |= V4L2_TUNER_CAP_STEREO;
517 tuner -> rxsubchans |= V4L2_TUNER_SUB_STEREO;
518 } else {
519 tuner -> rxsubchans &= 0xffff ^ V4L2_TUNER_SUB_STEREO;
520 }
521 }
522 }
523 /* Wow to deal with V4L2_TUNER_CAP_LOW ? For now, it accepts from low at 62.5KHz step to high at 62.5 Hz */
449 tuner->rangelow = tv_range[0] * 16; 524 tuner->rangelow = tv_range[0] * 16;
450 tuner->rangehigh = tv_range[1] * 16; 525// tuner->rangehigh = tv_range[1] * 16;
526// tuner->rangelow = tv_range[0] * 16384;
527 tuner->rangehigh = tv_range[1] * 16384;
451 break; 528 break;
452 } 529 }
453 default: 530 default:
531 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd);
454 /* nothing */ 532 /* nothing */
455 break; 533 break;
456 } 534 }
@@ -458,7 +536,7 @@ tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
458 return 0; 536 return 0;
459} 537}
460 538
461static int tuner_suspend(struct device * dev, pm_message_t state, u32 level) 539static int tuner_suspend(struct device * dev, u32 state, u32 level)
462{ 540{
463 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 541 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
464 struct tuner *t = i2c_get_clientdata(c); 542 struct tuner *t = i2c_get_clientdata(c);