]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/video/tuner-core.c
V4L/DVB (12482): firedtv: add PID filtering for SW zigzag retune
[mirror_ubuntu-artful-kernel.git] / drivers / media / video / tuner-core.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 *
3 * i2c tv tuner chip device driver
4 * core core, i.e. kernel interfaces, registering and so on
5 */
6
7#include <linux/module.h>
1da177e4 8#include <linux/kernel.h>
1da177e4
LT
9#include <linux/string.h>
10#include <linux/timer.h>
11#include <linux/delay.h>
12#include <linux/errno.h>
13#include <linux/slab.h>
14#include <linux/poll.h>
15#include <linux/i2c.h>
16#include <linux/types.h>
1da177e4 17#include <linux/init.h>
75b4c260 18#include <linux/videodev2.h>
1da177e4 19#include <media/tuner.h>
4adad287 20#include <media/tuner-types.h>
e8a4a9e7 21#include <media/v4l2-device.h>
35ea11ff 22#include <media/v4l2-ioctl.h>
75b4c260 23#include <media/v4l2-i2c-drv.h>
96c0b7cf 24#include "mt20xx.h"
910bb3e3 25#include "tda8290.h"
7ab10bf7 26#include "tea5761.h"
8d0936ed 27#include "tea5767.h"
215b95ba 28#include "tuner-xc2028.h"
4adad287 29#include "tuner-simple.h"
31c9584c 30#include "tda9887.h"
27c685a4 31#include "xc5000.h"
1da177e4
LT
32
33#define UNSET (-1U)
34
9dd659de 35#define PREFIX t->i2c->driver->driver.name
241020d1 36
a07c8779 37/** This macro allows us to probe dynamically, avoiding static links */
ff138171 38#ifdef CONFIG_MEDIA_ATTACH
a07c8779
MK
39#define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
40 int __r = -EINVAL; \
41 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
42 if (__a) { \
43 __r = (int) __a(ARGS); \
a1355e53 44 symbol_put(FUNCTION); \
a07c8779
MK
45 } else { \
46 printk(KERN_ERR "TUNER: Unable to find " \
47 "symbol "#FUNCTION"()\n"); \
48 } \
a07c8779
MK
49 __r; \
50})
51
52static void tuner_detach(struct dvb_frontend *fe)
53{
54 if (fe->ops.tuner_ops.release) {
55 fe->ops.tuner_ops.release(fe);
56 symbol_put_addr(fe->ops.tuner_ops.release);
57 }
58 if (fe->ops.analog_ops.release) {
59 fe->ops.analog_ops.release(fe);
60 symbol_put_addr(fe->ops.analog_ops.release);
61 }
62}
63#else
64#define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
65 FUNCTION(ARGS); \
66})
67
68static void tuner_detach(struct dvb_frontend *fe)
69{
70 if (fe->ops.tuner_ops.release)
71 fe->ops.tuner_ops.release(fe);
72 if (fe->ops.analog_ops.release)
73 fe->ops.analog_ops.release(fe);
74}
75#endif
76
f7f427e4
MK
77struct tuner {
78 /* device */
79 struct dvb_frontend fe;
80 struct i2c_client *i2c;
e8a4a9e7 81 struct v4l2_subdev sd;
f7f427e4
MK
82 struct list_head list;
83 unsigned int using_v4l2:1;
84
85 /* keep track of the current settings */
86 v4l2_std_id std;
87 unsigned int tv_freq;
88 unsigned int radio_freq;
89 unsigned int audmode;
90
91 unsigned int mode;
92 unsigned int mode_mask; /* Combination of allowable modes */
93
94 unsigned int type; /* chip type id */
95 unsigned int config;
7271e60a 96 const char *name;
f7f427e4
MK
97};
98
e8a4a9e7
HV
99static inline struct tuner *to_tuner(struct v4l2_subdev *sd)
100{
101 return container_of(sd, struct tuner, sd);
102}
103
1da177e4
LT
104
105/* insmod options used at init time => read/only */
ff699e6b
DSL
106static unsigned int addr;
107static unsigned int no_autodetect;
108static unsigned int show_i2c;
fd3113e8 109
1da177e4 110/* insmod options used at runtime => read/write */
ab166050
MK
111static int tuner_debug;
112
113#define tuner_warn(fmt, arg...) do { \
114 printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
115 i2c_adapter_id(t->i2c->adapter), \
116 t->i2c->addr, ##arg); \
117 } while (0)
118
119#define tuner_info(fmt, arg...) do { \
120 printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
121 i2c_adapter_id(t->i2c->adapter), \
122 t->i2c->addr, ##arg); \
123 } while (0)
124
125#define tuner_err(fmt, arg...) do { \
126 printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
127 i2c_adapter_id(t->i2c->adapter), \
128 t->i2c->addr, ##arg); \
129 } while (0)
130
131#define tuner_dbg(fmt, arg...) do { \
132 if (tuner_debug) \
133 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
134 i2c_adapter_id(t->i2c->adapter), \
135 t->i2c->addr, ##arg); \
136 } while (0)
137
138/* ------------------------------------------------------------------------ */
1da177e4 139
f7ce3cc6 140static unsigned int tv_range[2] = { 44, 958 };
1da177e4
LT
141static unsigned int radio_range[2] = { 65, 108 };
142
7e578191
MCC
143static char pal[] = "--";
144static char secam[] = "--";
145static char ntsc[] = "-";
146
f9195ded 147
7e578191
MCC
148module_param(addr, int, 0444);
149module_param(no_autodetect, int, 0444);
150module_param(show_i2c, int, 0444);
f9195ded 151module_param_named(debug,tuner_debug, int, 0644);
7e578191
MCC
152module_param_string(pal, pal, sizeof(pal), 0644);
153module_param_string(secam, secam, sizeof(secam), 0644);
154module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
f7ce3cc6 155module_param_array(tv_range, int, NULL, 0644);
1da177e4
LT
156module_param_array(radio_range, int, NULL, 0644);
157
158MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
159MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
160MODULE_LICENSE("GPL");
161
1da177e4
LT
162/* ---------------------------------------------------------------------- */
163
c7919d52
MK
164static void fe_set_params(struct dvb_frontend *fe,
165 struct analog_parameters *params)
e18f9444 166{
4e9154b8
MK
167 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
168 struct tuner *t = fe->analog_demod_priv;
e18f9444 169
e18f9444
MK
170 if (NULL == fe_tuner_ops->set_analog_params) {
171 tuner_warn("Tuner frontend module has no way to set freq\n");
172 return;
173 }
c7919d52 174 fe_tuner_ops->set_analog_params(fe, params);
e18f9444
MK
175}
176
4e9154b8 177static void fe_standby(struct dvb_frontend *fe)
e18f9444 178{
4e9154b8 179 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
e18f9444
MK
180
181 if (fe_tuner_ops->sleep)
4e9154b8 182 fe_tuner_ops->sleep(fe);
e18f9444
MK
183}
184
4e9154b8 185static int fe_has_signal(struct dvb_frontend *fe)
1f5ef197 186{
1419683d 187 u16 strength = 0;
1f5ef197 188
4e9154b8
MK
189 if (fe->ops.tuner_ops.get_rf_strength)
190 fe->ops.tuner_ops.get_rf_strength(fe, &strength);
1f5ef197
MK
191
192 return strength;
193}
194
f1c9a281
MK
195static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg)
196{
197 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
198 struct tuner *t = fe->analog_demod_priv;
199
200 if (fe_tuner_ops->set_config)
201 return fe_tuner_ops->set_config(fe, priv_cfg);
202
203 tuner_warn("Tuner frontend module has no way to set config\n");
204
205 return 0;
206}
207
4e9154b8 208static void tuner_status(struct dvb_frontend *fe);
1dde7a4f 209
e8a4a9e7 210static struct analog_demod_ops tuner_analog_ops = {
c7919d52 211 .set_params = fe_set_params,
1dde7a4f 212 .standby = fe_standby,
1dde7a4f 213 .has_signal = fe_has_signal,
f1c9a281 214 .set_config = fe_set_config,
1dde7a4f
MK
215 .tuner_status = tuner_status
216};
217
56fc08ca 218/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
1da177e4
LT
219static void set_tv_freq(struct i2c_client *c, unsigned int freq)
220{
e8a4a9e7 221 struct tuner *t = to_tuner(i2c_get_clientdata(c));
bc3e5c7f 222 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1da177e4 223
c7919d52
MK
224 struct analog_parameters params = {
225 .mode = t->mode,
226 .audmode = t->audmode,
227 .std = t->std
228 };
229
1da177e4 230 if (t->type == UNSET) {
f7ce3cc6 231 tuner_warn ("tuner type not set\n");
1da177e4
LT
232 return;
233 }
bc3e5c7f 234 if (NULL == analog_ops->set_params) {
f7ce3cc6 235 tuner_warn ("Tuner has no way to set tv freq\n");
1da177e4
LT
236 return;
237 }
f7ce3cc6
MCC
238 if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
239 tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n",
240 freq / 16, freq % 16 * 100 / 16, tv_range[0],
241 tv_range[1]);
27487d44
HV
242 /* V4L2 spec: if the freq is not possible then the closest
243 possible value should be selected */
244 if (freq < tv_range[0] * 16)
245 freq = tv_range[0] * 16;
246 else
247 freq = tv_range[1] * 16;
1da177e4 248 }
c7919d52
MK
249 params.frequency = freq;
250
bc3e5c7f 251 analog_ops->set_params(&t->fe, &params);
1da177e4
LT
252}
253
254static void set_radio_freq(struct i2c_client *c, unsigned int freq)
255{
e8a4a9e7 256 struct tuner *t = to_tuner(i2c_get_clientdata(c));
bc3e5c7f 257 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1da177e4 258
c7919d52
MK
259 struct analog_parameters params = {
260 .mode = t->mode,
261 .audmode = t->audmode,
262 .std = t->std
263 };
264
1da177e4 265 if (t->type == UNSET) {
f7ce3cc6 266 tuner_warn ("tuner type not set\n");
1da177e4
LT
267 return;
268 }
e545d6e2 269 if (NULL == analog_ops->set_params) {
f7ce3cc6 270 tuner_warn ("tuner has no way to set radio frequency\n");
1da177e4
LT
271 return;
272 }
27487d44 273 if (freq < radio_range[0] * 16000 || freq > radio_range[1] * 16000) {
f7ce3cc6
MCC
274 tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n",
275 freq / 16000, freq % 16000 * 100 / 16000,
276 radio_range[0], radio_range[1]);
27487d44
HV
277 /* V4L2 spec: if the freq is not possible then the closest
278 possible value should be selected */
279 if (freq < radio_range[0] * 16000)
280 freq = radio_range[0] * 16000;
281 else
282 freq = radio_range[1] * 16000;
1da177e4 283 }
c7919d52 284 params.frequency = freq;
586b0cab 285
bc3e5c7f 286 analog_ops->set_params(&t->fe, &params);
1da177e4
LT
287}
288
289static void set_freq(struct i2c_client *c, unsigned long freq)
290{
e8a4a9e7 291 struct tuner *t = to_tuner(i2c_get_clientdata(c));
1da177e4
LT
292
293 switch (t->mode) {
294 case V4L2_TUNER_RADIO:
295 tuner_dbg("radio freq set to %lu.%02lu\n",
f7ce3cc6
MCC
296 freq / 16000, freq % 16000 * 100 / 16000);
297 set_radio_freq(c, freq);
27487d44 298 t->radio_freq = freq;
1da177e4
LT
299 break;
300 case V4L2_TUNER_ANALOG_TV:
301 case V4L2_TUNER_DIGITAL_TV:
302 tuner_dbg("tv freq set to %lu.%02lu\n",
f7ce3cc6 303 freq / 16, freq % 16 * 100 / 16);
1da177e4 304 set_tv_freq(c, freq);
27487d44 305 t->tv_freq = freq;
1da177e4 306 break;
6cb45879
MCC
307 default:
308 tuner_dbg("freq set: unknown mode: 0x%04x!\n",t->mode);
1da177e4 309 }
1da177e4
LT
310}
311
27c685a4
ST
312static struct xc5000_config xc5000_cfg;
313
f7ce3cc6 314static void set_type(struct i2c_client *c, unsigned int type,
de956c1e 315 unsigned int new_mode_mask, unsigned int new_config,
d7cba043 316 int (*tuner_callback) (void *dev, int component, int cmd, int arg))
1da177e4 317{
e8a4a9e7 318 struct tuner *t = to_tuner(i2c_get_clientdata(c));
e18f9444 319 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
bc3e5c7f 320 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
586b0cab 321 unsigned char buffer[4];
1da177e4 322
f7ce3cc6
MCC
323 if (type == UNSET || type == TUNER_ABSENT) {
324 tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr);
1da177e4 325 return;
f7ce3cc6
MCC
326 }
327
80f90fba 328 t->type = type;
e7ddcd98
MK
329 /* prevent invalid config values */
330 t->config = ((new_config >= 0) && (new_config < 256)) ? new_config : 0;
80f90fba
HH
331 if (tuner_callback != NULL) {
332 tuner_dbg("defining GPIO callback\n");
d7cba043 333 t->fe.callback = tuner_callback;
80f90fba
HH
334 }
335
48aa336a 336 if (t->mode == T_UNINITIALIZED) {
f7ce3cc6
MCC
337 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr);
338
1da177e4
LT
339 return;
340 }
56fc08ca 341
b2083199 342 /* discard private data, in case set_type() was previously called */
a07c8779
MK
343 tuner_detach(&t->fe);
344 t->fe.analog_demod_priv = NULL;
be2b85a1 345
1da177e4
LT
346 switch (t->type) {
347 case TUNER_MT2032:
09fee5f8
MCC
348 if (!dvb_attach(microtune_attach,
349 &t->fe, t->i2c->adapter, t->i2c->addr))
350 goto attach_failed;
1da177e4
LT
351 break;
352 case TUNER_PHILIPS_TDA8290:
5bea1cd3 353 {
09fee5f8
MCC
354 struct tda829x_config cfg = {
355 .lna_cfg = t->config,
09fee5f8
MCC
356 };
357 if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter,
358 t->i2c->addr, &cfg))
359 goto attach_failed;
5bea1cd3
MK
360 break;
361 }
586b0cab 362 case TUNER_TEA5767:
a07c8779
MK
363 if (!dvb_attach(tea5767_attach, &t->fe,
364 t->i2c->adapter, t->i2c->addr))
b9ef6bbb 365 goto attach_failed;
f7ce3cc6 366 t->mode_mask = T_RADIO;
586b0cab 367 break;
8573a9e6 368 case TUNER_TEA5761:
a07c8779
MK
369 if (!dvb_attach(tea5761_attach, &t->fe,
370 t->i2c->adapter, t->i2c->addr))
b9ef6bbb 371 goto attach_failed;
8573a9e6
MCC
372 t->mode_mask = T_RADIO;
373 break;
586b0cab
MCC
374 case TUNER_PHILIPS_FMD1216ME_MK3:
375 buffer[0] = 0x0b;
376 buffer[1] = 0xdc;
377 buffer[2] = 0x9c;
378 buffer[3] = 0x60;
f7ce3cc6 379 i2c_master_send(c, buffer, 4);
586b0cab
MCC
380 mdelay(1);
381 buffer[2] = 0x86;
382 buffer[3] = 0x54;
f7ce3cc6 383 i2c_master_send(c, buffer, 4);
a07c8779
MK
384 if (!dvb_attach(simple_tuner_attach, &t->fe,
385 t->i2c->adapter, t->i2c->addr, t->type))
b9ef6bbb 386 goto attach_failed;
586b0cab 387 break;
93df3413
HH
388 case TUNER_PHILIPS_TD1316:
389 buffer[0] = 0x0b;
390 buffer[1] = 0xdc;
391 buffer[2] = 0x86;
392 buffer[3] = 0xa4;
a07c8779
MK
393 i2c_master_send(c, buffer, 4);
394 if (!dvb_attach(simple_tuner_attach, &t->fe,
395 t->i2c->adapter, t->i2c->addr, t->type))
b9ef6bbb 396 goto attach_failed;
ac272ed7 397 break;
690c544c
MCC
398 case TUNER_XC2028:
399 {
a37b4c9b
ML
400 struct xc2028_config cfg = {
401 .i2c_adap = t->i2c->adapter,
402 .i2c_addr = t->i2c->addr,
a37b4c9b 403 };
a07c8779 404 if (!dvb_attach(xc2028_attach, &t->fe, &cfg))
b9ef6bbb 405 goto attach_failed;
690c544c
MCC
406 break;
407 }
15396236 408 case TUNER_TDA9887:
09fee5f8
MCC
409 if (!dvb_attach(tda9887_attach,
410 &t->fe, t->i2c->adapter, t->i2c->addr))
411 goto attach_failed;
15396236 412 break;
27c685a4 413 case TUNER_XC5000:
b9ef6bbb 414 {
27c685a4 415 xc5000_cfg.i2c_address = t->i2c->addr;
ea227863
DH
416 /* if_khz will be set when the digital dvb_attach() occurs */
417 xc5000_cfg.if_khz = 0;
a07c8779 418 if (!dvb_attach(xc5000_attach,
30650961 419 &t->fe, t->i2c->adapter, &xc5000_cfg))
b9ef6bbb 420 goto attach_failed;
27c685a4 421 break;
b9ef6bbb 422 }
1da177e4 423 default:
a07c8779
MK
424 if (!dvb_attach(simple_tuner_attach, &t->fe,
425 t->i2c->adapter, t->i2c->addr, t->type))
b9ef6bbb
MCC
426 goto attach_failed;
427
1da177e4
LT
428 break;
429 }
f7ce3cc6 430
bc3e5c7f 431 if ((NULL == analog_ops->set_params) &&
1dde7a4f 432 (fe_tuner_ops->set_analog_params)) {
a07c8779 433
7271e60a 434 t->name = fe_tuner_ops->info.name;
e18f9444 435
4e9154b8 436 t->fe.analog_demod_priv = t;
e8a4a9e7 437 memcpy(analog_ops, &tuner_analog_ops,
bc3e5c7f 438 sizeof(struct analog_demod_ops));
a07c8779 439
a55db8cd 440 } else {
7271e60a 441 t->name = analog_ops->info.name;
e18f9444
MK
442 }
443
7271e60a 444 tuner_dbg("type set to %s\n", t->name);
e18f9444 445
f7ce3cc6
MCC
446 if (t->mode_mask == T_UNINITIALIZED)
447 t->mode_mask = new_mode_mask;
448
b9ef6bbb
MCC
449 /* xc2028/3028 and xc5000 requires a firmware to be set-up later
450 trying to set a frequency here will just fail
451 FIXME: better to move set_freq to the tuner code. This is needed
452 on analog tuners for PLL to properly work
453 */
454 if (t->type != TUNER_XC2028 && t->type != TUNER_XC5000)
455 set_freq(c, (V4L2_TUNER_RADIO == t->mode) ?
456 t->radio_freq : t->tv_freq);
457
f7ce3cc6 458 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
604f28e2 459 c->adapter->name, c->driver->driver.name, c->addr << 1, type,
f7ce3cc6 460 t->mode_mask);
b9ef6bbb
MCC
461 return;
462
463attach_failed:
464 tuner_dbg("Tuner attach for type = %d failed.\n", t->type);
465 t->type = TUNER_ABSENT;
466 t->mode_mask = T_UNINITIALIZED;
467
468 return;
1da177e4
LT
469}
470
f7ce3cc6
MCC
471/*
472 * This function apply tuner config to tuner specified
473 * by tun_setup structure. I addr is unset, then admin status
474 * and tun addr status is more precise then current status,
475 * it's applied. Otherwise status and type are applied only to
476 * tuner with exactly the same addr.
477*/
478
479static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
480{
e8a4a9e7 481 struct tuner *t = to_tuner(i2c_get_clientdata(c));
f7ce3cc6 482
de956c1e
HH
483 if ( (t->type == UNSET && ((tun_setup->addr == ADDR_UNSET) &&
484 (t->mode_mask & tun_setup->mode_mask))) ||
485 (tun_setup->addr == c->addr)) {
486 set_type(c, tun_setup->type, tun_setup->mode_mask,
cfeb8839 487 tun_setup->config, tun_setup->tuner_callback);
b9ef6bbb
MCC
488 } else
489 tuner_dbg("set addr discarded for type %i, mask %x. "
490 "Asked to change tuner at addr 0x%02x, with mask %x\n",
491 t->type, t->mode_mask,
492 tun_setup->addr, tun_setup->mode_mask);
f7ce3cc6 493}
56fc08ca 494
f7ce3cc6 495static inline int check_mode(struct tuner *t, char *cmd)
56fc08ca 496{
793cf9e6 497 if ((1 << t->mode & t->mode_mask) == 0) {
4d3437df 498 return -EINVAL;
793cf9e6
MCC
499 }
500
501 switch (t->mode) {
502 case V4L2_TUNER_RADIO:
503 tuner_dbg("Cmd %s accepted for radio\n", cmd);
504 break;
505 case V4L2_TUNER_ANALOG_TV:
506 tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
507 break;
508 case V4L2_TUNER_DIGITAL_TV:
509 tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
510 break;
56fc08ca 511 }
793cf9e6 512 return 0;
56fc08ca 513}
56fc08ca 514
f7ce3cc6 515/* get more precise norm info from insmod option */
1da177e4
LT
516static int tuner_fixup_std(struct tuner *t)
517{
518 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
1da177e4 519 switch (pal[0]) {
e71ced1a
HV
520 case '6':
521 tuner_dbg ("insmod fixup: PAL => PAL-60\n");
522 t->std = V4L2_STD_PAL_60;
523 break;
1da177e4
LT
524 case 'b':
525 case 'B':
526 case 'g':
527 case 'G':
f7ce3cc6 528 tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
1da177e4
LT
529 t->std = V4L2_STD_PAL_BG;
530 break;
531 case 'i':
532 case 'I':
f7ce3cc6 533 tuner_dbg ("insmod fixup: PAL => PAL-I\n");
1da177e4
LT
534 t->std = V4L2_STD_PAL_I;
535 break;
536 case 'd':
537 case 'D':
538 case 'k':
539 case 'K':
f7ce3cc6 540 tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
1da177e4
LT
541 t->std = V4L2_STD_PAL_DK;
542 break;
f7ce3cc6
MCC
543 case 'M':
544 case 'm':
545 tuner_dbg ("insmod fixup: PAL => PAL-M\n");
546 t->std = V4L2_STD_PAL_M;
547 break;
548 case 'N':
549 case 'n':
7e578191
MCC
550 if (pal[1] == 'c' || pal[1] == 'C') {
551 tuner_dbg("insmod fixup: PAL => PAL-Nc\n");
552 t->std = V4L2_STD_PAL_Nc;
553 } else {
554 tuner_dbg ("insmod fixup: PAL => PAL-N\n");
555 t->std = V4L2_STD_PAL_N;
556 }
f7ce3cc6 557 break;
21d4df37
MCC
558 case '-':
559 /* default parameter, do nothing */
560 break;
561 default:
562 tuner_warn ("pal= argument not recognised\n");
563 break;
1da177e4
LT
564 }
565 }
f7ce3cc6
MCC
566 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
567 switch (secam[0]) {
7e578191
MCC
568 case 'b':
569 case 'B':
570 case 'g':
571 case 'G':
572 case 'h':
573 case 'H':
574 tuner_dbg("insmod fixup: SECAM => SECAM-BGH\n");
575 t->std = V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H;
576 break;
f7ce3cc6
MCC
577 case 'd':
578 case 'D':
579 case 'k':
580 case 'K':
581 tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
582 t->std = V4L2_STD_SECAM_DK;
583 break;
584 case 'l':
585 case 'L':
800d3c6f
MCC
586 if ((secam[1]=='C')||(secam[1]=='c')) {
587 tuner_dbg ("insmod fixup: SECAM => SECAM-L'\n");
588 t->std = V4L2_STD_SECAM_LC;
589 } else {
590 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
591 t->std = V4L2_STD_SECAM_L;
592 }
f7ce3cc6 593 break;
21d4df37
MCC
594 case '-':
595 /* default parameter, do nothing */
596 break;
597 default:
598 tuner_warn ("secam= argument not recognised\n");
599 break;
f7ce3cc6
MCC
600 }
601 }
602
7e578191
MCC
603 if ((t->std & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
604 switch (ntsc[0]) {
605 case 'm':
606 case 'M':
607 tuner_dbg("insmod fixup: NTSC => NTSC-M\n");
608 t->std = V4L2_STD_NTSC_M;
609 break;
610 case 'j':
611 case 'J':
612 tuner_dbg("insmod fixup: NTSC => NTSC_M_JP\n");
613 t->std = V4L2_STD_NTSC_M_JP;
614 break;
d97a11e0
HV
615 case 'k':
616 case 'K':
617 tuner_dbg("insmod fixup: NTSC => NTSC_M_KR\n");
618 t->std = V4L2_STD_NTSC_M_KR;
619 break;
7e578191
MCC
620 case '-':
621 /* default parameter, do nothing */
622 break;
623 default:
624 tuner_info("ntsc= argument not recognised\n");
625 break;
626 }
627 }
1da177e4
LT
628 return 0;
629}
630
4e9154b8 631static void tuner_status(struct dvb_frontend *fe)
7e578191 632{
4e9154b8 633 struct tuner *t = fe->analog_demod_priv;
7e578191 634 unsigned long freq, freq_fraction;
a07c8779
MK
635 struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops;
636 struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
7e578191
MCC
637 const char *p;
638
639 switch (t->mode) {
640 case V4L2_TUNER_RADIO: p = "radio"; break;
641 case V4L2_TUNER_ANALOG_TV: p = "analog TV"; break;
642 case V4L2_TUNER_DIGITAL_TV: p = "digital TV"; break;
643 default: p = "undefined"; break;
644 }
645 if (t->mode == V4L2_TUNER_RADIO) {
27487d44
HV
646 freq = t->radio_freq / 16000;
647 freq_fraction = (t->radio_freq % 16000) * 100 / 16000;
7e578191 648 } else {
27487d44
HV
649 freq = t->tv_freq / 16;
650 freq_fraction = (t->tv_freq % 16) * 100 / 16;
7e578191
MCC
651 }
652 tuner_info("Tuner mode: %s\n", p);
653 tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
4ae5c2e5 654 tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std);
8a4b275f
HV
655 if (t->mode != V4L2_TUNER_RADIO)
656 return;
e18f9444
MK
657 if (fe_tuner_ops->get_status) {
658 u32 tuner_status;
659
660 fe_tuner_ops->get_status(&t->fe, &tuner_status);
661 if (tuner_status & TUNER_STATUS_LOCKED)
662 tuner_info("Tuner is locked.\n");
663 if (tuner_status & TUNER_STATUS_STEREO)
664 tuner_info("Stereo: yes\n");
665 }
bc3e5c7f
MK
666 if (analog_ops->has_signal)
667 tuner_info("Signal strength: %d\n",
668 analog_ops->has_signal(fe));
669 if (analog_ops->is_stereo)
670 tuner_info("Stereo: %s\n",
671 analog_ops->is_stereo(fe) ? "yes" : "no");
7e578191 672}
8a4b275f 673
1da177e4
LT
674/* ---------------------------------------------------------------------- */
675
f7ce3cc6
MCC
676/*
677 * Switch tuner to other mode. If tuner support both tv and radio,
678 * set another frequency to some value (This is needed for some pal
679 * tuners to avoid locking). Otherwise, just put second tuner in
680 * standby mode.
681 */
682
683static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
684{
bc3e5c7f 685 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1dde7a4f 686
4ac97914
MCC
687 if (mode == t->mode)
688 return 0;
689
690 t->mode = mode;
691
4d3437df 692 if (check_mode(t, cmd) == -EINVAL) {
16a5e53d
MCC
693 tuner_dbg("Tuner doesn't support this mode. "
694 "Putting tuner to sleep\n");
4ac97914 695 t->mode = T_STANDBY;
bc3e5c7f
MK
696 if (analog_ops->standby)
697 analog_ops->standby(&t->fe);
4d3437df 698 return -EINVAL;
4ac97914
MCC
699 }
700 return 0;
f7ce3cc6
MCC
701}
702
703#define switch_v4l2() if (!t->using_v4l2) \
4ac97914
MCC
704 tuner_dbg("switching to v4l2\n"); \
705 t->using_v4l2 = 1;
f7ce3cc6
MCC
706
707static inline int check_v4l2(struct tuner *t)
708{
3bbe5a83
HV
709 /* bttv still uses both v4l1 and v4l2 calls to the tuner (v4l2 for
710 TV, v4l1 for radio), until that is fixed this code is disabled.
711 Otherwise the radio (v4l1) wouldn't tune after using the TV (v4l2)
712 first. */
f7ce3cc6
MCC
713 return 0;
714}
1da177e4 715
e8a4a9e7 716static int tuner_s_type_addr(struct v4l2_subdev *sd, struct tuner_setup *type)
1da177e4 717{
e8a4a9e7
HV
718 struct tuner *t = to_tuner(sd);
719 struct i2c_client *client = v4l2_get_subdevdata(sd);
720
721 tuner_dbg("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n",
722 type->type,
723 type->addr,
724 type->mode_mask,
725 type->config);
726
727 set_addr(client, type);
728 return 0;
729}
730
731static int tuner_s_radio(struct v4l2_subdev *sd)
732{
733 struct tuner *t = to_tuner(sd);
734 struct i2c_client *client = v4l2_get_subdevdata(sd);
735
bccfa449 736 if (set_mode(client, t, V4L2_TUNER_RADIO, "s_radio") == -EINVAL)
e8a4a9e7
HV
737 return 0;
738 if (t->radio_freq)
739 set_freq(client, t->radio_freq);
740 return 0;
741}
742
7c9fc9d5 743static int tuner_s_standby(struct v4l2_subdev *sd)
e8a4a9e7
HV
744{
745 struct tuner *t = to_tuner(sd);
bc3e5c7f 746 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1da177e4 747
16a5e53d
MCC
748 tuner_dbg("Putting tuner to sleep\n");
749
bccfa449 750 if (check_mode(t, "s_standby") == -EINVAL)
e8a4a9e7
HV
751 return 0;
752 t->mode = T_STANDBY;
753 if (analog_ops->standby)
754 analog_ops->standby(&t->fe);
755 return 0;
756}
5e453dc7 757
e8a4a9e7
HV
758static int tuner_s_config(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *cfg)
759{
760 struct tuner *t = to_tuner(sd);
761 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1da177e4 762
e8a4a9e7
HV
763 if (t->type != cfg->tuner)
764 return 0;
7f171123 765
e8a4a9e7
HV
766 if (analog_ops->set_config) {
767 analog_ops->set_config(&t->fe, cfg->priv);
768 return 0;
7f171123 769 }
1da177e4 770
e8a4a9e7
HV
771 tuner_dbg("Tuner frontend module has no way to set config\n");
772 return 0;
773}
56fc08ca 774
e8a4a9e7
HV
775/* --- v4l ioctls --- */
776/* take care: bttv does userspace copying, we'll get a
777 kernel pointer here... */
778static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
779{
780 struct tuner *t = to_tuner(sd);
781 struct i2c_client *client = v4l2_get_subdevdata(sd);
f7ce3cc6 782
bccfa449 783 if (set_mode(client, t, V4L2_TUNER_ANALOG_TV, "s_std") == -EINVAL)
e8a4a9e7 784 return 0;
f7ce3cc6 785
e8a4a9e7 786 switch_v4l2();
c184ca36 787
e8a4a9e7
HV
788 t->std = std;
789 tuner_fixup_std(t);
790 if (t->tv_freq)
791 set_freq(client, t->tv_freq);
792 return 0;
793}
f7ce3cc6 794
e8a4a9e7
HV
795static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
796{
797 struct tuner *t = to_tuner(sd);
798 struct i2c_client *client = v4l2_get_subdevdata(sd);
f7ce3cc6 799
bccfa449 800 if (set_mode(client, t, f->type, "s_frequency") == -EINVAL)
e8a4a9e7
HV
801 return 0;
802 switch_v4l2();
803 set_freq(client, f->frequency);
8a4b275f 804
e8a4a9e7
HV
805 return 0;
806}
f7ce3cc6 807
e8a4a9e7
HV
808static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
809{
810 struct tuner *t = to_tuner(sd);
811 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
f7ce3cc6 812
bccfa449 813 if (check_mode(t, "g_frequency") == -EINVAL)
e8a4a9e7
HV
814 return 0;
815 switch_v4l2();
816 f->type = t->mode;
817 if (fe_tuner_ops->get_frequency) {
818 u32 abs_freq;
819
820 fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
821 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
822 (abs_freq * 2 + 125/2) / 125 :
823 (abs_freq + 62500/2) / 62500;
824 return 0;
825 }
826 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
827 t->radio_freq : t->tv_freq;
828 return 0;
829}
f7ce3cc6 830
e8a4a9e7
HV
831static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
832{
833 struct tuner *t = to_tuner(sd);
834 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
835 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
836
bccfa449 837 if (check_mode(t, "g_tuner") == -EINVAL)
e8a4a9e7
HV
838 return 0;
839 switch_v4l2();
840
841 vt->type = t->mode;
842 if (analog_ops->get_afc)
843 vt->afc = analog_ops->get_afc(&t->fe);
844 if (t->mode == V4L2_TUNER_ANALOG_TV)
845 vt->capability |= V4L2_TUNER_CAP_NORM;
846 if (t->mode != V4L2_TUNER_RADIO) {
847 vt->rangelow = tv_range[0] * 16;
848 vt->rangehigh = tv_range[1] * 16;
849 return 0;
850 }
851
852 /* radio mode */
853 vt->rxsubchans =
854 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
855 if (fe_tuner_ops->get_status) {
856 u32 tuner_status;
857
858 fe_tuner_ops->get_status(&t->fe, &tuner_status);
859 vt->rxsubchans =
860 (tuner_status & TUNER_STATUS_STEREO) ?
861 V4L2_TUNER_SUB_STEREO :
862 V4L2_TUNER_SUB_MONO;
863 } else {
864 if (analog_ops->is_stereo) {
865 vt->rxsubchans =
866 analog_ops->is_stereo(&t->fe) ?
867 V4L2_TUNER_SUB_STEREO :
868 V4L2_TUNER_SUB_MONO;
56fc08ca 869 }
1da177e4 870 }
e8a4a9e7
HV
871 if (analog_ops->has_signal)
872 vt->signal = analog_ops->has_signal(&t->fe);
873 vt->capability |=
874 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
875 vt->audmode = t->audmode;
876 vt->rangelow = radio_range[0] * 16000;
877 vt->rangehigh = radio_range[1] * 16000;
878 return 0;
879}
880
881static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
882{
883 struct tuner *t = to_tuner(sd);
884 struct i2c_client *client = v4l2_get_subdevdata(sd);
885
bccfa449 886 if (check_mode(t, "s_tuner") == -EINVAL)
e8a4a9e7
HV
887 return 0;
888
889 switch_v4l2();
890
891 /* do nothing unless we're a radio tuner */
892 if (t->mode != V4L2_TUNER_RADIO)
893 return 0;
894 t->audmode = vt->audmode;
895 set_radio_freq(client, t->radio_freq);
896 return 0;
897}
898
899static int tuner_log_status(struct v4l2_subdev *sd)
900{
901 struct tuner *t = to_tuner(sd);
902 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1da177e4 903
e8a4a9e7
HV
904 if (analog_ops->tuner_status)
905 analog_ops->tuner_status(&t->fe);
1da177e4
LT
906 return 0;
907}
908
21b48a70 909static int tuner_suspend(struct i2c_client *c, pm_message_t state)
1da177e4 910{
e8a4a9e7 911 struct tuner *t = to_tuner(i2c_get_clientdata(c));
1da177e4 912
9dd659de 913 tuner_dbg("suspend\n");
1da177e4
LT
914 /* FIXME: power down ??? */
915 return 0;
916}
917
21b48a70 918static int tuner_resume(struct i2c_client *c)
1da177e4 919{
e8a4a9e7 920 struct tuner *t = to_tuner(i2c_get_clientdata(c));
1da177e4 921
9dd659de 922 tuner_dbg("resume\n");
27487d44
HV
923 if (V4L2_TUNER_RADIO == t->mode) {
924 if (t->radio_freq)
925 set_freq(c, t->radio_freq);
926 } else {
927 if (t->tv_freq)
928 set_freq(c, t->tv_freq);
929 }
1da177e4
LT
930 return 0;
931}
932
75b4c260
HV
933static int tuner_command(struct i2c_client *client, unsigned cmd, void *arg)
934{
935 struct v4l2_subdev *sd = i2c_get_clientdata(client);
936
937 /* TUNER_SET_CONFIG is still called by tuner-simple.c, so we have
938 to handle it here.
939 There must be a better way of doing this... */
940 switch (cmd) {
941 case TUNER_SET_CONFIG:
942 return tuner_s_config(sd, arg);
943 }
944 return -ENOIOCTLCMD;
945}
946
e8a4a9e7
HV
947/* ----------------------------------------------------------------------- */
948
949static const struct v4l2_subdev_core_ops tuner_core_ops = {
950 .log_status = tuner_log_status,
f41737ec 951 .s_std = tuner_s_std,
e8a4a9e7
HV
952};
953
954static const struct v4l2_subdev_tuner_ops tuner_tuner_ops = {
e8a4a9e7
HV
955 .s_radio = tuner_s_radio,
956 .g_tuner = tuner_g_tuner,
957 .s_tuner = tuner_s_tuner,
958 .s_frequency = tuner_s_frequency,
959 .g_frequency = tuner_g_frequency,
960 .s_type_addr = tuner_s_type_addr,
961 .s_config = tuner_s_config,
7c9fc9d5 962 .s_standby = tuner_s_standby,
e8a4a9e7
HV
963};
964
965static const struct v4l2_subdev_ops tuner_ops = {
966 .core = &tuner_core_ops,
967 .tuner = &tuner_tuner_ops,
968};
969
92de1f16
HV
970/* ---------------------------------------------------------------------- */
971
c52c4d06 972static LIST_HEAD(tuner_list);
92de1f16
HV
973
974/* Search for existing radio and/or TV tuners on the given I2C adapter.
9dd659de 975 Note that when this function is called from tuner_probe you can be
92de1f16
HV
976 certain no other devices will be added/deleted at the same time, I2C
977 core protects against that. */
978static void tuner_lookup(struct i2c_adapter *adap,
979 struct tuner **radio, struct tuner **tv)
980{
981 struct tuner *pos;
982
983 *radio = NULL;
984 *tv = NULL;
985
986 list_for_each_entry(pos, &tuner_list, list) {
987 int mode_mask;
988
989 if (pos->i2c->adapter != adap ||
0c846743 990 strcmp(pos->i2c->driver->driver.name, "tuner"))
92de1f16
HV
991 continue;
992
993 mode_mask = pos->mode_mask & ~T_STANDBY;
994 if (*radio == NULL && mode_mask == T_RADIO)
995 *radio = pos;
996 /* Note: currently TDA9887 is the only demod-only
997 device. If other devices appear then we need to
998 make this test more general. */
999 else if (*tv == NULL && pos->type != TUNER_TDA9887 &&
1000 (pos->mode_mask & (T_ANALOG_TV | T_DIGITAL_TV)))
1001 *tv = pos;
1002 }
1003}
1004
1005/* During client attach, set_type is called by adapter's attach_inform callback.
9dd659de 1006 set_type must then be completed by tuner_probe.
92de1f16 1007 */
d2653e92
JD
1008static int tuner_probe(struct i2c_client *client,
1009 const struct i2c_device_id *id)
92de1f16 1010{
92de1f16
HV
1011 struct tuner *t;
1012 struct tuner *radio;
1013 struct tuner *tv;
1014
92de1f16 1015 t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
9dd659de 1016 if (NULL == t)
92de1f16 1017 return -ENOMEM;
e8a4a9e7 1018 v4l2_i2c_subdev_init(&t->sd, client, &tuner_ops);
92de1f16 1019 t->i2c = client;
7271e60a 1020 t->name = "(tuner unset)";
92de1f16
HV
1021 t->type = UNSET;
1022 t->audmode = V4L2_TUNER_MODE_STEREO;
1023 t->mode_mask = T_UNINITIALIZED;
1024
1025 if (show_i2c) {
1026 unsigned char buffer[16];
1027 int i, rc;
1028
1029 memset(buffer, 0, sizeof(buffer));
1030 rc = i2c_master_recv(client, buffer, sizeof(buffer));
1031 tuner_info("I2C RECV = ");
1032 for (i = 0; i < rc; i++)
1033 printk(KERN_CONT "%02x ", buffer[i]);
1034 printk("\n");
1035 }
9dd659de 1036 /* HACK: This test was added to avoid tuner to probe tda9840 and
92de1f16 1037 tea6415c on the MXB card */
9dd659de
HV
1038 if (client->adapter->id == I2C_HW_SAA7146 && client->addr < 0x4a) {
1039 kfree(t);
92de1f16 1040 return -ENODEV;
9dd659de 1041 }
92de1f16
HV
1042
1043 /* autodetection code based on the i2c addr */
1044 if (!no_autodetect) {
9dd659de 1045 switch (client->addr) {
92de1f16 1046 case 0x10:
a07c8779
MK
1047 if (tuner_symbol_probe(tea5761_autodetection,
1048 t->i2c->adapter,
1049 t->i2c->addr) >= 0) {
92de1f16
HV
1050 t->type = TUNER_TEA5761;
1051 t->mode_mask = T_RADIO;
1052 t->mode = T_STANDBY;
1053 /* Sets freq to FM range */
1054 t->radio_freq = 87.5 * 16000;
1055 tuner_lookup(t->i2c->adapter, &radio, &tv);
1056 if (tv)
1057 tv->mode_mask &= ~T_RADIO;
1058
1059 goto register_client;
1060 }
867e835f 1061 return -ENODEV;
92de1f16
HV
1062 case 0x42:
1063 case 0x43:
1064 case 0x4a:
1065 case 0x4b:
1066 /* If chip is not tda8290, don't register.
1067 since it can be tda9887*/
a07c8779 1068 if (tuner_symbol_probe(tda829x_probe, t->i2c->adapter,
b538d28c 1069 t->i2c->addr) >= 0) {
92de1f16
HV
1070 tuner_dbg("tda829x detected\n");
1071 } else {
1072 /* Default is being tda9887 */
1073 t->type = TUNER_TDA9887;
1074 t->mode_mask = T_RADIO | T_ANALOG_TV |
1075 T_DIGITAL_TV;
1076 t->mode = T_STANDBY;
1077 goto register_client;
1078 }
1079 break;
1080 case 0x60:
a07c8779
MK
1081 if (tuner_symbol_probe(tea5767_autodetection,
1082 t->i2c->adapter, t->i2c->addr)
b538d28c 1083 >= 0) {
92de1f16
HV
1084 t->type = TUNER_TEA5767;
1085 t->mode_mask = T_RADIO;
1086 t->mode = T_STANDBY;
1087 /* Sets freq to FM range */
1088 t->radio_freq = 87.5 * 16000;
1089 tuner_lookup(t->i2c->adapter, &radio, &tv);
1090 if (tv)
1091 tv->mode_mask &= ~T_RADIO;
1092
1093 goto register_client;
1094 }
1095 break;
1096 }
1097 }
1098
1099 /* Initializes only the first TV tuner on this adapter. Why only the
1100 first? Because there are some devices (notably the ones with TI
1101 tuners) that have more than one i2c address for the *same* device.
1102 Experience shows that, except for just one case, the first
1103 address is the right one. The exception is a Russian tuner
1104 (ACORP_Y878F). So, the desired behavior is just to enable the
1105 first found TV tuner. */
1106 tuner_lookup(t->i2c->adapter, &radio, &tv);
1107 if (tv == NULL) {
1108 t->mode_mask = T_ANALOG_TV | T_DIGITAL_TV;
1109 if (radio == NULL)
1110 t->mode_mask |= T_RADIO;
1111 tuner_dbg("Setting mode_mask to 0x%02x\n", t->mode_mask);
1112 t->tv_freq = 400 * 16; /* Sets freq to VHF High */
1113 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
1114 }
1115
1116 /* Should be just before return */
1117register_client:
9dd659de
HV
1118 tuner_info("chip found @ 0x%x (%s)\n", client->addr << 1,
1119 client->adapter->name);
92de1f16
HV
1120
1121 /* Sets a default mode */
1122 if (t->mode_mask & T_ANALOG_TV) {
864a6b81 1123 t->mode = V4L2_TUNER_ANALOG_TV;
92de1f16 1124 } else if (t->mode_mask & T_RADIO) {
864a6b81 1125 t->mode = V4L2_TUNER_RADIO;
92de1f16 1126 } else {
864a6b81 1127 t->mode = V4L2_TUNER_DIGITAL_TV;
92de1f16 1128 }
d7cba043 1129 set_type(client, t->type, t->mode_mask, t->config, t->fe.callback);
9dd659de 1130 list_add_tail(&t->list, &tuner_list);
92de1f16
HV
1131 return 0;
1132}
1133
9dd659de 1134static int tuner_remove(struct i2c_client *client)
92de1f16 1135{
e8a4a9e7 1136 struct tuner *t = to_tuner(i2c_get_clientdata(client));
92de1f16 1137
e8a4a9e7 1138 v4l2_device_unregister_subdev(&t->sd);
a07c8779
MK
1139 tuner_detach(&t->fe);
1140 t->fe.analog_demod_priv = NULL;
92de1f16
HV
1141
1142 list_del(&t->list);
1143 kfree(t);
92de1f16
HV
1144 return 0;
1145}
1146
1da177e4
LT
1147/* ----------------------------------------------------------------------- */
1148
af294867
JD
1149/* This driver supports many devices and the idea is to let the driver
1150 detect which device is present. So rather than listing all supported
1151 devices here, we pretend to support a single, fake device type. */
1152static const struct i2c_device_id tuner_id[] = {
1153 { "tuner", }, /* autodetect */
1154 { }
1155};
1156MODULE_DEVICE_TABLE(i2c, tuner_id);
1157
9dd659de
HV
1158static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1159 .name = "tuner",
9dd659de
HV
1160 .probe = tuner_probe,
1161 .remove = tuner_remove,
75b4c260 1162 .command = tuner_command,
21b48a70 1163 .suspend = tuner_suspend,
9dd659de 1164 .resume = tuner_resume,
af294867 1165 .id_table = tuner_id,
1da177e4 1166};
1da177e4 1167
1da177e4
LT
1168/*
1169 * Overrides for Emacs so that we follow Linus's tabbing style.
1170 * ---------------------------------------------------------------------------
1171 * Local variables:
1172 * c-basic-offset: 8
1173 * End:
1174 */