blob: eaabfc85870368f1f9b25127a8de054cefe73387 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -07002 * $Id: tuner-core.c,v 1.15 2005/06/12 01:36:14 mchehab Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * i2c tv tuner chip device driver
5 * core core, i.e. kernel interfaces, registering and so on
6 */
7
8#include <linux/module.h>
9#include <linux/moduleparam.h>
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/string.h>
13#include <linux/timer.h>
14#include <linux/delay.h>
15#include <linux/errno.h>
16#include <linux/slab.h>
17#include <linux/poll.h>
18#include <linux/i2c.h>
19#include <linux/types.h>
20#include <linux/videodev.h>
21#include <linux/init.h>
22
23#include <media/tuner.h>
24#include <media/audiochip.h>
25
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -070026/*
27 * comment line bellow to return to old behavor, where only one I2C device is supported
28 */
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -070029#define CONFIG_TUNER_MULTI_I2C /**/
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define UNSET (-1U)
32
33/* standard i2c insmod options */
34static unsigned short normal_i2c[] = {
35 0x4b, /* tda8290 */
Mauro Carvalho Chehabf5bec392005-06-23 22:05:13 -070036 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
37 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 I2C_CLIENT_END
39};
40I2C_CLIENT_INSMOD;
41
42/* insmod options used at init time => read/only */
43static unsigned int addr = 0;
44module_param(addr, int, 0444);
45
46/* insmod options used at runtime => read/write */
47unsigned int tuner_debug = 0;
48module_param(tuner_debug, int, 0644);
49
50static unsigned int tv_range[2] = { 44, 958 };
51static unsigned int radio_range[2] = { 65, 108 };
52
53module_param_array(tv_range, int, NULL, 0644);
54module_param_array(radio_range, int, NULL, 0644);
55
56MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
57MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
58MODULE_LICENSE("GPL");
59
60static int this_adap;
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -070061#ifdef CONFIG_TUNER_MULTI_I2C
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -070062static unsigned short first_tuner, tv_tuner, radio_tuner;
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -070063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65static struct i2c_driver driver;
66static struct i2c_client client_template;
67
68/* ---------------------------------------------------------------------- */
69
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -070070/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static void set_tv_freq(struct i2c_client *c, unsigned int freq)
72{
73 struct tuner *t = i2c_get_clientdata(c);
74
75 if (t->type == UNSET) {
76 tuner_info("tuner type not set\n");
77 return;
78 }
79 if (NULL == t->tv_freq) {
80 tuner_info("Huh? tv_set is NULL?\n");
81 return;
82 }
83 if (freq < tv_range[0]*16 || freq > tv_range[1]*16) {
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -070084
85 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
86 /* V4L2_TUNER_CAP_LOW frequency */
87
88 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for TV. Tuners yet doesn't support converting it to valid freq.\n");
89
90 t->tv_freq(c,freq>>10);
91
92 return;
93 } else {
94 /* FIXME: better do that chip-specific, but
95 right now we don't have that in the config
96 struct and this way is still better than no
97 check at all */
98 tuner_info("TV freq (%d.%02d) out of range (%d-%d)\n",
99 freq/16,freq%16*100/16,tv_range[0],tv_range[1]);
100 return;
101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700103 tuner_dbg("62.5 Khz freq step selected for TV.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 t->tv_freq(c,freq);
105}
106
107static void set_radio_freq(struct i2c_client *c, unsigned int freq)
108{
109 struct tuner *t = i2c_get_clientdata(c);
110
111 if (t->type == UNSET) {
112 tuner_info("tuner type not set\n");
113 return;
114 }
115 if (NULL == t->radio_freq) {
116 tuner_info("no radio tuning for this one, sorry.\n");
117 return;
118 }
119 if (freq < radio_range[0]*16 || freq > radio_range[1]*16) {
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700120 if (freq >= tv_range[0]*16364 && freq <= tv_range[1]*16384) {
121 /* V4L2_TUNER_CAP_LOW frequency */
122 if (t->type == TUNER_TEA5767) {
123 tuner_info("radio freq step 62.5Hz (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
124 t->radio_freq(c,freq>>10);
125 return;
126 }
127
128 tuner_dbg("V4L2_TUNER_CAP_LOW freq selected for Radio. Tuners yet doesn't support converting it to valid freq.\n");
129
130 tuner_info("radio freq (%d.%06d)\n",(freq>>14),freq%(1<<14)*10000);
131
132 t->radio_freq(c,freq>>10);
133 return;
134
135 } else {
136 tuner_info("radio freq (%d.%02d) out of range (%d-%d)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 freq/16,freq%16*100/16,
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700138 radio_range[0],radio_range[1]);
139 return;
140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700142 tuner_dbg("62.5 Khz freq step selected for Radio.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 t->radio_freq(c,freq);
144}
145
146static void set_freq(struct i2c_client *c, unsigned long freq)
147{
148 struct tuner *t = i2c_get_clientdata(c);
149
150 switch (t->mode) {
151 case V4L2_TUNER_RADIO:
152 tuner_dbg("radio freq set to %lu.%02lu\n",
153 freq/16,freq%16*100/16);
154 set_radio_freq(c,freq);
155 break;
156 case V4L2_TUNER_ANALOG_TV:
157 case V4L2_TUNER_DIGITAL_TV:
158 tuner_dbg("tv freq set to %lu.%02lu\n",
159 freq/16,freq%16*100/16);
160 set_tv_freq(c, freq);
161 break;
162 }
163 t->freq = freq;
164}
165
166static void set_type(struct i2c_client *c, unsigned int type)
167{
168 struct tuner *t = i2c_get_clientdata(c);
169
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700170 tuner_dbg ("I2C addr 0x%02x with type %d\n",c->addr<<1,type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /* sanity check */
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700172 if (type == UNSET || type == TUNER_ABSENT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 return;
174 if (type >= tuner_count)
175 return;
176
177 if (NULL == t->i2c.dev.driver) {
178 /* not registered yet */
179 t->type = type;
180 return;
181 }
182 if (t->initialized)
183 /* run only once */
184 return;
185
186 t->initialized = 1;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 t->type = type;
189 switch (t->type) {
190 case TUNER_MT2032:
191 microtune_init(c);
192 break;
193 case TUNER_PHILIPS_TDA8290:
194 tda8290_init(c);
195 break;
196 default:
197 default_tuner_init(c);
198 break;
199 }
200}
201
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700202#ifdef CONFIG_TUNER_MULTI_I2C
203#define CHECK_ADDR(tp,cmd,tun) if (client->addr!=tp) { \
204 return 0; } else \
205 tuner_info ("Cmd %s accepted to "tun"\n",cmd);
206#define CHECK_MODE(cmd) if (t->mode == V4L2_TUNER_RADIO) { \
207 CHECK_ADDR(radio_tuner,cmd,"radio") } else \
208 { CHECK_ADDR(tv_tuner,cmd,"TV"); }
209#else
210#define CHECK_ADDR(tp,cmd,tun) tuner_info ("Cmd %s accepted to "tun"\n",cmd);
211#define CHECK_MODE(cmd) tuner_info ("Cmd %s accepted\n",cmd);
212#endif
213
214#ifdef CONFIG_TUNER_MULTI_I2C
215
216static void set_addr(struct i2c_client *c, struct tuner_addr *tun_addr)
217{
218 /* ADDR_UNSET defaults to first available tuner */
219 if ( tun_addr->addr == ADDR_UNSET ) {
220 if (first_tuner != c->addr)
221 return;
222 switch (tun_addr->v4l2_tuner) {
223 case V4L2_TUNER_RADIO:
224 radio_tuner=c->addr;
225 break;
226 default:
227 tv_tuner=c->addr;
228 break;
229 }
230 } else {
231 /* Sets tuner to its configured value */
232 switch (tun_addr->v4l2_tuner) {
233 case V4L2_TUNER_RADIO:
234 radio_tuner=tun_addr->addr;
235 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
236 return;
237 default:
238 tv_tuner=tun_addr->addr;
239 if ( tun_addr->addr == c->addr ) set_type(c,tun_addr->type);
240 return;
241 }
242 }
243 set_type(c,tun_addr->type);
244}
245#else
246#define set_addr(c,tun_addr) set_type(c,(tun_addr)->type)
247#endif
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249static char pal[] = "-";
Bert Wesarg975e0462005-04-16 15:25:43 -0700250module_param_string(pal, pal, sizeof(pal), 0644);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252static int tuner_fixup_std(struct tuner *t)
253{
254 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
255 /* get more precise norm info from insmod option */
256 switch (pal[0]) {
257 case 'b':
258 case 'B':
259 case 'g':
260 case 'G':
261 tuner_dbg("insmod fixup: PAL => PAL-BG\n");
262 t->std = V4L2_STD_PAL_BG;
263 break;
264 case 'i':
265 case 'I':
266 tuner_dbg("insmod fixup: PAL => PAL-I\n");
267 t->std = V4L2_STD_PAL_I;
268 break;
269 case 'd':
270 case 'D':
271 case 'k':
272 case 'K':
273 tuner_dbg("insmod fixup: PAL => PAL-DK\n");
274 t->std = V4L2_STD_PAL_DK;
275 break;
276 }
277 }
278 return 0;
279}
280
281/* ---------------------------------------------------------------------- */
282
283static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
284{
285 struct tuner *t;
286
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700287#ifndef CONFIG_TUNER_MULTI_I2C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (this_adap > 0)
289 return -1;
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700290#else
291 /* by default, first I2C card is both tv and radio tuner */
292 if (this_adap == 0) {
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700293 first_tuner = addr;
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700294 tv_tuner = addr;
295 radio_tuner = addr;
296 }
297#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 this_adap++;
299
300 client_template.adapter = adap;
301 client_template.addr = addr;
302
303 t = kmalloc(sizeof(struct tuner),GFP_KERNEL);
304 if (NULL == t)
305 return -ENOMEM;
306 memset(t,0,sizeof(struct tuner));
307 memcpy(&t->i2c,&client_template,sizeof(struct i2c_client));
308 i2c_set_clientdata(&t->i2c, t);
309 t->type = UNSET;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700310 t->radio_if2 = 10700*1000; /* 10.7MHz - FM radio */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 i2c_attach_client(&t->i2c);
313 tuner_info("chip found @ 0x%x (%s)\n",
314 addr << 1, adap->name);
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 set_type(&t->i2c, t->type);
317 return 0;
318}
319
320static int tuner_probe(struct i2c_adapter *adap)
321{
322 if (0 != addr) {
Mauro Carvalho Chehabf5bec392005-06-23 22:05:13 -0700323 normal_i2c[0] = addr;
324 normal_i2c[1] = I2C_CLIENT_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326 this_adap = 0;
327
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700328#ifdef CONFIG_TUNER_MULTI_I2C
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700329 first_tuner = 0;
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700330 tv_tuner = 0;
331 radio_tuner = 0;
332#endif
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 if (adap->class & I2C_CLASS_TV_ANALOG)
335 return i2c_probe(adap, &addr_data, tuner_attach);
336 return 0;
337}
338
339static int tuner_detach(struct i2c_client *client)
340{
341 struct tuner *t = i2c_get_clientdata(client);
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700342 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700344 err=i2c_detach_client(&t->i2c);
345 if (err) {
346 tuner_warn ("Client deregistration failed, client not detached.\n");
347 return err;
348 }
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 kfree(t);
351 return 0;
352}
353
354#define SWITCH_V4L2 if (!t->using_v4l2 && tuner_debug) \
355 tuner_info("switching to v4l2\n"); \
356 t->using_v4l2 = 1;
357#define CHECK_V4L2 if (t->using_v4l2) { if (tuner_debug) \
358 tuner_info("ignore v4l1 call\n"); \
359 return 0; }
360
361static int
362tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
363{
364 struct tuner *t = i2c_get_clientdata(client);
365 unsigned int *iarg = (int*)arg;
366
367 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* --- configuration --- */
369 case TUNER_SET_TYPE:
370 set_type(client,*iarg);
371 break;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700372 case TUNER_SET_TYPE_ADDR:
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700373 set_addr(client,(struct tuner_addr *)arg);
374 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 case AUDC_SET_RADIO:
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700376 t->mode = V4L2_TUNER_RADIO;
377 CHECK_ADDR(tv_tuner,"AUDC_SET_RADIO","TV");
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 if (V4L2_TUNER_RADIO != t->mode) {
380 set_tv_freq(client,400 * 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382 break;
383 case AUDC_CONFIG_PINNACLE:
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700384 CHECK_ADDR(tv_tuner,"AUDC_CONFIG_PINNACLE","TV");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 switch (*iarg) {
386 case 2:
387 tuner_dbg("pinnacle pal\n");
388 t->radio_if2 = 33300 * 1000;
389 break;
390 case 3:
391 tuner_dbg("pinnacle ntsc\n");
392 t->radio_if2 = 41300 * 1000;
393 break;
394 }
395 break;
396
397 /* --- v4l ioctls --- */
398 /* take care: bttv does userspace copying, we'll get a
399 kernel pointer here... */
400 case VIDIOCSCHAN:
401 {
402 static const v4l2_std_id map[] = {
403 [ VIDEO_MODE_PAL ] = V4L2_STD_PAL,
404 [ VIDEO_MODE_NTSC ] = V4L2_STD_NTSC_M,
405 [ VIDEO_MODE_SECAM ] = V4L2_STD_SECAM,
406 [ 4 /* bttv */ ] = V4L2_STD_PAL_M,
407 [ 5 /* bttv */ ] = V4L2_STD_PAL_N,
408 [ 6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
409 };
410 struct video_channel *vc = arg;
411
412 CHECK_V4L2;
413 t->mode = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700414 CHECK_ADDR(tv_tuner,"VIDIOCSCHAN","TV");
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (vc->norm < ARRAY_SIZE(map))
417 t->std = map[vc->norm];
418 tuner_fixup_std(t);
419 if (t->freq)
420 set_tv_freq(client,t->freq);
421 return 0;
422 }
423 case VIDIOCSFREQ:
424 {
425 unsigned long *v = arg;
426
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700427 CHECK_MODE("VIDIOCSFREQ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 CHECK_V4L2;
429 set_freq(client,*v);
430 return 0;
431 }
432 case VIDIOCGTUNER:
433 {
434 struct video_tuner *vt = arg;
435
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700436 CHECK_ADDR(radio_tuner,"VIDIOCGTUNER","radio");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 CHECK_V4L2;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700438 if (V4L2_TUNER_RADIO == t->mode) {
439 if (t->has_signal)
440 vt->signal = t->has_signal(client);
441 if (t->is_stereo) {
442 if (t->is_stereo(client))
443 vt-> flags |= VIDEO_TUNER_STEREO_ON;
444 else
445 vt-> flags &= 0xffff ^ VIDEO_TUNER_STEREO_ON;
446 }
447 vt->flags |= V4L2_TUNER_CAP_LOW; /* Allow freqs at 62.5 Hz */
448 }
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 return 0;
451 }
452 case VIDIOCGAUDIO:
453 {
454 struct video_audio *va = arg;
455
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700456 CHECK_ADDR(radio_tuner,"VIDIOCGAUDIO","radio");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 CHECK_V4L2;
458 if (V4L2_TUNER_RADIO == t->mode && t->is_stereo)
459 va->mode = t->is_stereo(client)
460 ? VIDEO_SOUND_STEREO
461 : VIDEO_SOUND_MONO;
462 return 0;
463 }
464
465 case VIDIOC_S_STD:
466 {
467 v4l2_std_id *id = arg;
468
469 SWITCH_V4L2;
470 t->mode = V4L2_TUNER_ANALOG_TV;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700471 CHECK_ADDR(tv_tuner,"VIDIOC_S_STD","TV");
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 t->std = *id;
474 tuner_fixup_std(t);
475 if (t->freq)
476 set_freq(client,t->freq);
477 break;
478 }
479 case VIDIOC_S_FREQUENCY:
480 {
481 struct v4l2_frequency *f = arg;
482
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700483 CHECK_MODE("VIDIOC_S_FREQUENCY");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 SWITCH_V4L2;
485 if (V4L2_TUNER_RADIO == f->type &&
486 V4L2_TUNER_RADIO != t->mode)
487 set_tv_freq(client,400*16);
488 t->mode = f->type;
Jiri Bence99d3432005-05-06 21:30:42 -0700489 set_freq(client,f->frequency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 break;
491 }
Jiri Bencc184ca32005-05-06 21:30:42 -0700492 case VIDIOC_G_FREQUENCY:
493 {
494 struct v4l2_frequency *f = arg;
495
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700496 CHECK_MODE("VIDIOC_G_FREQUENCY");
Jiri Bencc184ca32005-05-06 21:30:42 -0700497 SWITCH_V4L2;
498 f->type = t->mode;
499 f->frequency = t->freq;
500 break;
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 case VIDIOC_G_TUNER:
503 {
504 struct v4l2_tuner *tuner = arg;
505
Mauro Carvalho Chehab391cd722005-06-23 22:02:43 -0700506 CHECK_MODE("VIDIOC_G_TUNER");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 SWITCH_V4L2;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700508 if (V4L2_TUNER_RADIO == t->mode) {
509 if (t->has_signal)
510 tuner -> signal = t->has_signal(client);
511 if (t->is_stereo) {
512 if (t->is_stereo(client)) {
513 tuner -> capability |= V4L2_TUNER_CAP_STEREO;
514 tuner -> rxsubchans |= V4L2_TUNER_SUB_STEREO;
515 } else {
516 tuner -> rxsubchans &= 0xffff ^ V4L2_TUNER_SUB_STEREO;
517 }
518 }
519 }
520 /* Wow to deal with V4L2_TUNER_CAP_LOW ? For now, it accepts from low at 62.5KHz step to high at 62.5 Hz */
Jiri Bencc184ca32005-05-06 21:30:42 -0700521 tuner->rangelow = tv_range[0] * 16;
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700522// tuner->rangehigh = tv_range[1] * 16;
523// tuner->rangelow = tv_range[0] * 16384;
524 tuner->rangehigh = tv_range[1] * 16384;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 break;
526 }
527 default:
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700528 tuner_dbg ("Unimplemented IOCTL 0x%08x called to tuner.\n", cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 /* nothing */
530 break;
531 }
532
533 return 0;
534}
535
Mauro Carvalho Chehab56fc08c2005-06-23 22:05:07 -0700536static int tuner_suspend(struct device * dev, u32 state, u32 level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
538 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
539 struct tuner *t = i2c_get_clientdata(c);
540
541 tuner_dbg("suspend\n");
542 /* FIXME: power down ??? */
543 return 0;
544}
545
546static int tuner_resume(struct device * dev, u32 level)
547{
548 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
549 struct tuner *t = i2c_get_clientdata(c);
550
551 tuner_dbg("resume\n");
552 if (t->freq)
553 set_freq(c,t->freq);
554 return 0;
555}
556
557/* ----------------------------------------------------------------------- */
558
559static struct i2c_driver driver = {
560 .owner = THIS_MODULE,
561 .name = "tuner",
562 .id = I2C_DRIVERID_TUNER,
563 .flags = I2C_DF_NOTIFY,
564 .attach_adapter = tuner_probe,
565 .detach_client = tuner_detach,
566 .command = tuner_command,
567 .driver = {
568 .suspend = tuner_suspend,
569 .resume = tuner_resume,
570 },
571};
572static struct i2c_client client_template =
573{
574 I2C_DEVNAME("(tuner unset)"),
575 .flags = I2C_CLIENT_ALLOW_USE,
576 .driver = &driver,
577};
578
579static int __init tuner_init_module(void)
580{
581 return i2c_add_driver(&driver);
582}
583
584static void __exit tuner_cleanup_module(void)
585{
586 i2c_del_driver(&driver);
587}
588
589module_init(tuner_init_module);
590module_exit(tuner_cleanup_module);
591
592/*
593 * Overrides for Emacs so that we follow Linus's tabbing style.
594 * ---------------------------------------------------------------------------
595 * Local variables:
596 * c-basic-offset: 8
597 * End:
598 */