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