]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fd3113e8 | 2 | * $Id: tuner-core.c,v 1.63 2005/07/28 18:19:55 mchehab Exp $ |
1da177e4 LT |
3 | * |
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 | ||
fd3113e8 MCC |
26 | #include "msp3400.h" |
27 | ||
1da177e4 LT |
28 | #define UNSET (-1U) |
29 | ||
30 | /* standard i2c insmod options */ | |
31 | static unsigned short normal_i2c[] = { | |
f7ce3cc6 | 32 | 0x4b, /* tda8290 */ |
f5bec396 MCC |
33 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
34 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, | |
1da177e4 LT |
35 | I2C_CLIENT_END |
36 | }; | |
f7ce3cc6 | 37 | |
1da177e4 LT |
38 | I2C_CLIENT_INSMOD; |
39 | ||
40 | /* insmod options used at init time => read/only */ | |
f7ce3cc6 | 41 | static unsigned int addr = 0; |
1da177e4 LT |
42 | module_param(addr, int, 0444); |
43 | ||
c5287ba1 MCC |
44 | static unsigned int no_autodetect = 0; |
45 | module_param(no_autodetect, int, 0444); | |
46 | ||
fd3113e8 MCC |
47 | static unsigned int show_i2c = 0; |
48 | module_param(show_i2c, int, 0444); | |
49 | ||
1da177e4 | 50 | /* insmod options used at runtime => read/write */ |
f7ce3cc6 MCC |
51 | unsigned int tuner_debug = 0; |
52 | module_param(tuner_debug, int, 0644); | |
1da177e4 | 53 | |
f7ce3cc6 | 54 | static unsigned int tv_range[2] = { 44, 958 }; |
1da177e4 LT |
55 | static unsigned int radio_range[2] = { 65, 108 }; |
56 | ||
f7ce3cc6 | 57 | module_param_array(tv_range, int, NULL, 0644); |
1da177e4 LT |
58 | module_param_array(radio_range, int, NULL, 0644); |
59 | ||
60 | MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners"); | |
61 | MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); | |
62 | MODULE_LICENSE("GPL"); | |
63 | ||
1da177e4 LT |
64 | static struct i2c_driver driver; |
65 | static struct i2c_client client_template; | |
66 | ||
67 | /* ---------------------------------------------------------------------- */ | |
68 | ||
56fc08ca | 69 | /* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */ |
1da177e4 LT |
70 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
71 | { | |
72 | struct tuner *t = i2c_get_clientdata(c); | |
73 | ||
74 | if (t->type == UNSET) { | |
f7ce3cc6 | 75 | tuner_warn ("tuner type not set\n"); |
1da177e4 LT |
76 | return; |
77 | } | |
78 | if (NULL == t->tv_freq) { | |
f7ce3cc6 | 79 | tuner_warn ("Tuner has no way to set tv freq\n"); |
1da177e4 LT |
80 | return; |
81 | } | |
f7ce3cc6 MCC |
82 | if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) { |
83 | tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n", | |
84 | freq / 16, freq % 16 * 100 / 16, tv_range[0], | |
85 | tv_range[1]); | |
1da177e4 | 86 | } |
f7ce3cc6 | 87 | t->tv_freq(c, freq); |
1da177e4 LT |
88 | } |
89 | ||
90 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) | |
91 | { | |
92 | struct tuner *t = i2c_get_clientdata(c); | |
93 | ||
94 | if (t->type == UNSET) { | |
f7ce3cc6 | 95 | tuner_warn ("tuner type not set\n"); |
1da177e4 LT |
96 | return; |
97 | } | |
98 | if (NULL == t->radio_freq) { | |
f7ce3cc6 | 99 | tuner_warn ("tuner has no way to set radio frequency\n"); |
1da177e4 LT |
100 | return; |
101 | } | |
f7ce3cc6 MCC |
102 | if (freq <= radio_range[0] * 16000 || freq >= radio_range[1] * 16000) { |
103 | tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n", | |
104 | freq / 16000, freq % 16000 * 100 / 16000, | |
105 | radio_range[0], radio_range[1]); | |
1da177e4 | 106 | } |
586b0cab | 107 | |
f7ce3cc6 | 108 | t->radio_freq(c, freq); |
586b0cab | 109 | return; |
1da177e4 LT |
110 | } |
111 | ||
112 | static void set_freq(struct i2c_client *c, unsigned long freq) | |
113 | { | |
114 | struct tuner *t = i2c_get_clientdata(c); | |
115 | ||
116 | switch (t->mode) { | |
117 | case V4L2_TUNER_RADIO: | |
118 | tuner_dbg("radio freq set to %lu.%02lu\n", | |
f7ce3cc6 MCC |
119 | freq / 16000, freq % 16000 * 100 / 16000); |
120 | set_radio_freq(c, freq); | |
1da177e4 LT |
121 | break; |
122 | case V4L2_TUNER_ANALOG_TV: | |
123 | case V4L2_TUNER_DIGITAL_TV: | |
124 | tuner_dbg("tv freq set to %lu.%02lu\n", | |
f7ce3cc6 | 125 | freq / 16, freq % 16 * 100 / 16); |
1da177e4 LT |
126 | set_tv_freq(c, freq); |
127 | break; | |
128 | } | |
129 | t->freq = freq; | |
130 | } | |
131 | ||
f7ce3cc6 MCC |
132 | static void set_type(struct i2c_client *c, unsigned int type, |
133 | unsigned int new_mode_mask) | |
1da177e4 LT |
134 | { |
135 | struct tuner *t = i2c_get_clientdata(c); | |
586b0cab | 136 | unsigned char buffer[4]; |
1da177e4 | 137 | |
f7ce3cc6 MCC |
138 | if (type == UNSET || type == TUNER_ABSENT) { |
139 | tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr); | |
1da177e4 | 140 | return; |
f7ce3cc6 MCC |
141 | } |
142 | ||
143 | if (type >= tuner_count) { | |
144 | tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count); | |
1da177e4 | 145 | return; |
f7ce3cc6 | 146 | } |
1da177e4 | 147 | |
f7ce3cc6 | 148 | /* This code detects calls by card attach_inform */ |
1da177e4 | 149 | if (NULL == t->i2c.dev.driver) { |
f7ce3cc6 MCC |
150 | tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr); |
151 | ||
152 | t->type=type; | |
1da177e4 LT |
153 | return; |
154 | } | |
56fc08ca | 155 | |
1da177e4 | 156 | t->type = type; |
f7ce3cc6 | 157 | |
1da177e4 LT |
158 | switch (t->type) { |
159 | case TUNER_MT2032: | |
160 | microtune_init(c); | |
161 | break; | |
162 | case TUNER_PHILIPS_TDA8290: | |
163 | tda8290_init(c); | |
164 | break; | |
586b0cab | 165 | case TUNER_TEA5767: |
f7ce3cc6 MCC |
166 | if (tea5767_tuner_init(c) == EINVAL) { |
167 | t->type = TUNER_ABSENT; | |
168 | t->mode_mask = T_UNINITIALIZED; | |
169 | return; | |
170 | } | |
171 | t->mode_mask = T_RADIO; | |
586b0cab MCC |
172 | break; |
173 | case TUNER_PHILIPS_FMD1216ME_MK3: | |
174 | buffer[0] = 0x0b; | |
175 | buffer[1] = 0xdc; | |
176 | buffer[2] = 0x9c; | |
177 | buffer[3] = 0x60; | |
f7ce3cc6 | 178 | i2c_master_send(c, buffer, 4); |
586b0cab MCC |
179 | mdelay(1); |
180 | buffer[2] = 0x86; | |
181 | buffer[3] = 0x54; | |
f7ce3cc6 | 182 | i2c_master_send(c, buffer, 4); |
586b0cab MCC |
183 | default_tuner_init(c); |
184 | break; | |
1da177e4 LT |
185 | default: |
186 | default_tuner_init(c); | |
187 | break; | |
188 | } | |
f7ce3cc6 MCC |
189 | |
190 | if (t->mode_mask == T_UNINITIALIZED) | |
191 | t->mode_mask = new_mode_mask; | |
192 | ||
193 | set_freq(c, t->freq); | |
194 | tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n", | |
195 | c->adapter->name, c->driver->name, c->addr << 1, type, | |
196 | t->mode_mask); | |
1da177e4 LT |
197 | } |
198 | ||
f7ce3cc6 MCC |
199 | /* |
200 | * This function apply tuner config to tuner specified | |
201 | * by tun_setup structure. I addr is unset, then admin status | |
202 | * and tun addr status is more precise then current status, | |
203 | * it's applied. Otherwise status and type are applied only to | |
204 | * tuner with exactly the same addr. | |
205 | */ | |
206 | ||
207 | static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup) | |
208 | { | |
209 | struct tuner *t = i2c_get_clientdata(c); | |
210 | ||
211 | if (tun_setup->addr == ADDR_UNSET) { | |
212 | if (t->mode_mask & tun_setup->mode_mask) | |
213 | set_type(c, tun_setup->type, tun_setup->mode_mask); | |
214 | } else if (tun_setup->addr == c->addr) { | |
215 | set_type(c, tun_setup->type, tun_setup->mode_mask); | |
216 | } | |
217 | } | |
56fc08ca | 218 | |
f7ce3cc6 | 219 | static inline int check_mode(struct tuner *t, char *cmd) |
56fc08ca | 220 | { |
f7ce3cc6 MCC |
221 | if (1 << t->mode & t->mode_mask) { |
222 | switch (t->mode) { | |
56fc08ca | 223 | case V4L2_TUNER_RADIO: |
f7ce3cc6 | 224 | tuner_dbg("Cmd %s accepted for radio\n", cmd); |
56fc08ca | 225 | break; |
f7ce3cc6 MCC |
226 | case V4L2_TUNER_ANALOG_TV: |
227 | tuner_dbg("Cmd %s accepted for analog TV\n", cmd); | |
228 | break; | |
229 | case V4L2_TUNER_DIGITAL_TV: | |
230 | tuner_dbg("Cmd %s accepted for digital TV\n", cmd); | |
56fc08ca MCC |
231 | break; |
232 | } | |
f7ce3cc6 | 233 | return 0; |
56fc08ca | 234 | } |
f7ce3cc6 | 235 | return EINVAL; |
56fc08ca | 236 | } |
56fc08ca | 237 | |
1da177e4 | 238 | static char pal[] = "-"; |
975e046c | 239 | module_param_string(pal, pal, sizeof(pal), 0644); |
f7ce3cc6 MCC |
240 | static char secam[] = "-"; |
241 | module_param_string(secam, secam, sizeof(secam), 0644); | |
1da177e4 | 242 | |
f7ce3cc6 | 243 | /* get more precise norm info from insmod option */ |
1da177e4 LT |
244 | static int tuner_fixup_std(struct tuner *t) |
245 | { | |
246 | if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { | |
1da177e4 LT |
247 | switch (pal[0]) { |
248 | case 'b': | |
249 | case 'B': | |
250 | case 'g': | |
251 | case 'G': | |
f7ce3cc6 | 252 | tuner_dbg ("insmod fixup: PAL => PAL-BG\n"); |
1da177e4 LT |
253 | t->std = V4L2_STD_PAL_BG; |
254 | break; | |
255 | case 'i': | |
256 | case 'I': | |
f7ce3cc6 | 257 | tuner_dbg ("insmod fixup: PAL => PAL-I\n"); |
1da177e4 LT |
258 | t->std = V4L2_STD_PAL_I; |
259 | break; | |
260 | case 'd': | |
261 | case 'D': | |
262 | case 'k': | |
263 | case 'K': | |
f7ce3cc6 | 264 | tuner_dbg ("insmod fixup: PAL => PAL-DK\n"); |
1da177e4 LT |
265 | t->std = V4L2_STD_PAL_DK; |
266 | break; | |
f7ce3cc6 MCC |
267 | case 'M': |
268 | case 'm': | |
269 | tuner_dbg ("insmod fixup: PAL => PAL-M\n"); | |
270 | t->std = V4L2_STD_PAL_M; | |
271 | break; | |
272 | case 'N': | |
273 | case 'n': | |
274 | tuner_dbg ("insmod fixup: PAL => PAL-N\n"); | |
275 | t->std = V4L2_STD_PAL_N; | |
276 | break; | |
1da177e4 LT |
277 | } |
278 | } | |
f7ce3cc6 MCC |
279 | if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) { |
280 | switch (secam[0]) { | |
281 | case 'd': | |
282 | case 'D': | |
283 | case 'k': | |
284 | case 'K': | |
285 | tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n"); | |
286 | t->std = V4L2_STD_SECAM_DK; | |
287 | break; | |
288 | case 'l': | |
289 | case 'L': | |
290 | tuner_dbg ("insmod fixup: SECAM => SECAM-L\n"); | |
291 | t->std = V4L2_STD_SECAM_L; | |
292 | break; | |
293 | } | |
294 | } | |
295 | ||
1da177e4 LT |
296 | return 0; |
297 | } | |
298 | ||
299 | /* ---------------------------------------------------------------------- */ | |
300 | ||
f7ce3cc6 MCC |
301 | /* static var Used only in tuner_attach and tuner_probe */ |
302 | static unsigned default_mode_mask; | |
303 | ||
304 | /* During client attach, set_type is called by adapter's attach_inform callback. | |
305 | set_type must then be completed by tuner_attach. | |
306 | */ | |
1da177e4 LT |
307 | static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) |
308 | { | |
309 | struct tuner *t; | |
310 | ||
f7ce3cc6 MCC |
311 | client_template.adapter = adap; |
312 | client_template.addr = addr; | |
1da177e4 | 313 | |
f7ce3cc6 MCC |
314 | t = kmalloc(sizeof(struct tuner), GFP_KERNEL); |
315 | if (NULL == t) | |
316 | return -ENOMEM; | |
317 | memset(t, 0, sizeof(struct tuner)); | |
318 | memcpy(&t->i2c, &client_template, sizeof(struct i2c_client)); | |
1da177e4 | 319 | i2c_set_clientdata(&t->i2c, t); |
f7ce3cc6 MCC |
320 | t->type = UNSET; |
321 | t->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ | |
322 | t->audmode = V4L2_TUNER_MODE_STEREO; | |
323 | t->mode_mask = T_UNINITIALIZED; | |
324 | ||
325 | ||
326 | tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name); | |
327 | ||
fd3113e8 MCC |
328 | if (show_i2c) { |
329 | unsigned char buffer[16]; | |
330 | int i,rc; | |
331 | ||
332 | memset(buffer, 0, sizeof(buffer)); | |
333 | rc = i2c_master_recv(&t->i2c, buffer, sizeof(buffer)); | |
334 | printk("tuner-%04x I2C RECV = ",addr); | |
335 | for (i=0;i<rc;i++) | |
336 | printk("%02x ",buffer[i]); | |
337 | printk("\n"); | |
338 | } | |
f7ce3cc6 | 339 | /* TEA5767 autodetection code - only for addr = 0xc0 */ |
c5287ba1 MCC |
340 | if (!no_autodetect) { |
341 | if (addr == 0x60) { | |
342 | if (tea5767_autodetection(&t->i2c) != EINVAL) { | |
343 | t->type = TUNER_TEA5767; | |
344 | t->mode_mask = T_RADIO; | |
345 | t->mode = T_STANDBY; | |
346 | t->freq = 87.5 * 16; /* Sets freq to FM range */ | |
347 | default_mode_mask &= ~T_RADIO; | |
348 | ||
349 | i2c_attach_client (&t->i2c); | |
350 | set_type(&t->i2c,t->type, t->mode_mask); | |
351 | return 0; | |
352 | } | |
f7ce3cc6 MCC |
353 | } |
354 | } | |
1da177e4 | 355 | |
f7ce3cc6 MCC |
356 | /* Initializes only the first adapter found */ |
357 | if (default_mode_mask != T_UNINITIALIZED) { | |
358 | tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask); | |
359 | t->mode_mask = default_mode_mask; | |
360 | t->freq = 400 * 16; /* Sets freq to VHF High */ | |
361 | default_mode_mask = T_UNINITIALIZED; | |
362 | } | |
56fc08ca | 363 | |
f7ce3cc6 MCC |
364 | /* Should be just before return */ |
365 | i2c_attach_client (&t->i2c); | |
366 | set_type (&t->i2c,t->type, t->mode_mask); | |
1da177e4 LT |
367 | return 0; |
368 | } | |
369 | ||
370 | static int tuner_probe(struct i2c_adapter *adap) | |
371 | { | |
372 | if (0 != addr) { | |
f5bec396 MCC |
373 | normal_i2c[0] = addr; |
374 | normal_i2c[1] = I2C_CLIENT_END; | |
1da177e4 | 375 | } |
1da177e4 | 376 | |
f7ce3cc6 | 377 | default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; |
391cd727 | 378 | |
1da177e4 LT |
379 | if (adap->class & I2C_CLASS_TV_ANALOG) |
380 | return i2c_probe(adap, &addr_data, tuner_attach); | |
381 | return 0; | |
382 | } | |
383 | ||
384 | static int tuner_detach(struct i2c_client *client) | |
385 | { | |
386 | struct tuner *t = i2c_get_clientdata(client); | |
391cd727 MCC |
387 | int err; |
388 | ||
f7ce3cc6 | 389 | err = i2c_detach_client(&t->i2c); |
391cd727 | 390 | if (err) { |
f7ce3cc6 MCC |
391 | tuner_warn |
392 | ("Client deregistration failed, client not detached.\n"); | |
391cd727 MCC |
393 | return err; |
394 | } | |
1da177e4 | 395 | |
1da177e4 LT |
396 | kfree(t); |
397 | return 0; | |
398 | } | |
399 | ||
f7ce3cc6 MCC |
400 | /* |
401 | * Switch tuner to other mode. If tuner support both tv and radio, | |
402 | * set another frequency to some value (This is needed for some pal | |
403 | * tuners to avoid locking). Otherwise, just put second tuner in | |
404 | * standby mode. | |
405 | */ | |
406 | ||
407 | static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd) | |
408 | { | |
409 | if (mode != t->mode) { | |
410 | ||
411 | t->mode = mode; | |
412 | if (check_mode(t, cmd) == EINVAL) { | |
413 | t->mode = T_STANDBY; | |
414 | if (V4L2_TUNER_RADIO == mode) { | |
415 | set_tv_freq(client, 400 * 16); | |
416 | } else { | |
417 | set_radio_freq(client, 87.5 * 16000); | |
418 | } | |
419 | return EINVAL; | |
420 | } | |
421 | } | |
422 | return 0; | |
423 | } | |
424 | ||
425 | #define switch_v4l2() if (!t->using_v4l2) \ | |
426 | tuner_dbg("switching to v4l2\n"); \ | |
427 | t->using_v4l2 = 1; | |
428 | ||
429 | static inline int check_v4l2(struct tuner *t) | |
430 | { | |
431 | if (t->using_v4l2) { | |
432 | tuner_dbg ("ignore v4l1 call\n"); | |
433 | return EINVAL; | |
434 | } | |
435 | return 0; | |
436 | } | |
1da177e4 | 437 | |
f7ce3cc6 | 438 | static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) |
1da177e4 LT |
439 | { |
440 | struct tuner *t = i2c_get_clientdata(client); | |
f7ce3cc6 | 441 | unsigned int *iarg = (int *)arg; |
1da177e4 | 442 | |
f7ce3cc6 | 443 | switch (cmd) { |
1da177e4 | 444 | /* --- configuration --- */ |
56fc08ca | 445 | case TUNER_SET_TYPE_ADDR: |
f7ce3cc6 MCC |
446 | tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x\n", |
447 | ((struct tuner_setup *)arg)->type, | |
448 | ((struct tuner_setup *)arg)->addr, | |
449 | ((struct tuner_setup *)arg)->mode_mask); | |
450 | ||
451 | set_addr(client, (struct tuner_setup *)arg); | |
391cd727 | 452 | break; |
1da177e4 | 453 | case AUDC_SET_RADIO: |
f7ce3cc6 | 454 | set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO"); |
1da177e4 LT |
455 | break; |
456 | case AUDC_CONFIG_PINNACLE: | |
f7ce3cc6 MCC |
457 | if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL) |
458 | return 0; | |
1da177e4 LT |
459 | switch (*iarg) { |
460 | case 2: | |
461 | tuner_dbg("pinnacle pal\n"); | |
462 | t->radio_if2 = 33300 * 1000; | |
463 | break; | |
464 | case 3: | |
465 | tuner_dbg("pinnacle ntsc\n"); | |
466 | t->radio_if2 = 41300 * 1000; | |
467 | break; | |
468 | } | |
586b0cab | 469 | break; |
fd3113e8 MCC |
470 | case VIDIOCSAUDIO: |
471 | if (check_mode(t, "VIDIOCSAUDIO") == EINVAL) | |
472 | return 0; | |
473 | if (check_v4l2(t) == EINVAL) | |
474 | return 0; | |
475 | ||
476 | /* Should be implemented, since bttv calls it */ | |
477 | tuner_dbg("VIDIOCSAUDIO not implemented.\n"); | |
478 | ||
479 | break; | |
480 | case MSP_SET_MATRIX: | |
f7ce3cc6 MCC |
481 | case TDA9887_SET_CONFIG: |
482 | break; | |
1da177e4 LT |
483 | /* --- v4l ioctls --- */ |
484 | /* take care: bttv does userspace copying, we'll get a | |
485 | kernel pointer here... */ | |
486 | case VIDIOCSCHAN: | |
f7ce3cc6 MCC |
487 | { |
488 | static const v4l2_std_id map[] = { | |
489 | [VIDEO_MODE_PAL] = V4L2_STD_PAL, | |
490 | [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M, | |
491 | [VIDEO_MODE_SECAM] = V4L2_STD_SECAM, | |
492 | [4 /* bttv */ ] = V4L2_STD_PAL_M, | |
493 | [5 /* bttv */ ] = V4L2_STD_PAL_N, | |
494 | [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP, | |
495 | }; | |
496 | struct video_channel *vc = arg; | |
497 | ||
498 | if (check_v4l2(t) == EINVAL) | |
499 | return 0; | |
500 | ||
501 | if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL) | |
502 | return 0; | |
503 | ||
504 | if (vc->norm < ARRAY_SIZE(map)) | |
505 | t->std = map[vc->norm]; | |
506 | tuner_fixup_std(t); | |
507 | if (t->freq) | |
508 | set_tv_freq(client, t->freq); | |
509 | return 0; | |
510 | } | |
1da177e4 | 511 | case VIDIOCSFREQ: |
f7ce3cc6 MCC |
512 | { |
513 | unsigned long *v = arg; | |
1da177e4 | 514 | |
f7ce3cc6 MCC |
515 | if (check_mode(t, "VIDIOCSFREQ") == EINVAL) |
516 | return 0; | |
517 | if (check_v4l2(t) == EINVAL) | |
518 | return 0; | |
519 | ||
520 | set_freq(client, *v); | |
521 | return 0; | |
522 | } | |
1da177e4 | 523 | case VIDIOCGTUNER: |
f7ce3cc6 MCC |
524 | { |
525 | struct video_tuner *vt = arg; | |
526 | ||
527 | if (check_mode(t, "VIDIOCGTUNER") == EINVAL) | |
528 | return 0; | |
529 | if (check_v4l2(t) == EINVAL) | |
530 | return 0; | |
531 | ||
532 | if (V4L2_TUNER_RADIO == t->mode) { | |
533 | if (t->has_signal) | |
534 | vt->signal = t->has_signal(client); | |
535 | if (t->is_stereo) { | |
536 | if (t->is_stereo(client)) | |
537 | vt->flags |= | |
538 | VIDEO_TUNER_STEREO_ON; | |
539 | else | |
540 | vt->flags &= | |
541 | ~VIDEO_TUNER_STEREO_ON; | |
542 | } | |
543 | vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */ | |
586b0cab | 544 | |
f7ce3cc6 MCC |
545 | vt->rangelow = radio_range[0] * 16000; |
546 | vt->rangehigh = radio_range[1] * 16000; | |
586b0cab | 547 | |
f7ce3cc6 MCC |
548 | } else { |
549 | vt->rangelow = tv_range[0] * 16; | |
550 | vt->rangehigh = tv_range[1] * 16; | |
551 | } | |
56fc08ca | 552 | |
f7ce3cc6 MCC |
553 | return 0; |
554 | } | |
1da177e4 | 555 | case VIDIOCGAUDIO: |
f7ce3cc6 MCC |
556 | { |
557 | struct video_audio *va = arg; | |
558 | ||
559 | if (check_mode(t, "VIDIOCGAUDIO") == EINVAL) | |
560 | return 0; | |
561 | if (check_v4l2(t) == EINVAL) | |
562 | return 0; | |
563 | ||
564 | if (V4L2_TUNER_RADIO == t->mode && t->is_stereo) | |
565 | va->mode = t->is_stereo(client) | |
566 | ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; | |
567 | return 0; | |
568 | } | |
1da177e4 LT |
569 | |
570 | case VIDIOC_S_STD: | |
f7ce3cc6 MCC |
571 | { |
572 | v4l2_std_id *id = arg; | |
1da177e4 | 573 | |
f7ce3cc6 MCC |
574 | if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD") |
575 | == EINVAL) | |
576 | return 0; | |
56fc08ca | 577 | |
f7ce3cc6 MCC |
578 | switch_v4l2(); |
579 | ||
580 | t->std = *id; | |
581 | tuner_fixup_std(t); | |
582 | if (t->freq) | |
583 | set_freq(client, t->freq); | |
584 | break; | |
585 | } | |
1da177e4 | 586 | case VIDIOC_S_FREQUENCY: |
f7ce3cc6 MCC |
587 | { |
588 | struct v4l2_frequency *f = arg; | |
589 | ||
590 | t->freq = f->frequency; | |
591 | switch_v4l2(); | |
592 | if (V4L2_TUNER_RADIO == f->type && | |
593 | V4L2_TUNER_RADIO != t->mode) { | |
594 | if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY") | |
595 | == EINVAL) | |
596 | return 0; | |
597 | } | |
598 | set_freq(client,t->freq); | |
c184ca36 | 599 | |
f7ce3cc6 MCC |
600 | break; |
601 | } | |
602 | case VIDIOC_G_FREQUENCY: | |
603 | { | |
604 | struct v4l2_frequency *f = arg; | |
605 | ||
606 | if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL) | |
607 | return 0; | |
608 | switch_v4l2(); | |
609 | f->type = t->mode; | |
610 | f->frequency = t->freq; | |
611 | break; | |
612 | } | |
1da177e4 | 613 | case VIDIOC_G_TUNER: |
f7ce3cc6 MCC |
614 | { |
615 | struct v4l2_tuner *tuner = arg; | |
616 | ||
617 | if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL) | |
618 | return 0; | |
619 | switch_v4l2(); | |
620 | ||
621 | if (V4L2_TUNER_RADIO == t->mode) { | |
622 | ||
623 | if (t->has_signal) | |
624 | tuner->signal = t->has_signal(client); | |
625 | ||
626 | if (t->is_stereo) { | |
627 | if (t->is_stereo(client)) { | |
628 | tuner->rxsubchans = | |
629 | V4L2_TUNER_SUB_STEREO | | |
630 | V4L2_TUNER_SUB_MONO; | |
631 | } else { | |
632 | tuner->rxsubchans = | |
633 | V4L2_TUNER_SUB_MONO; | |
634 | } | |
56fc08ca | 635 | } |
f7ce3cc6 MCC |
636 | |
637 | tuner->capability |= | |
638 | V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; | |
639 | ||
640 | tuner->audmode = t->audmode; | |
641 | ||
642 | tuner->rangelow = radio_range[0] * 16000; | |
643 | tuner->rangehigh = radio_range[1] * 16000; | |
644 | } else { | |
645 | tuner->rangelow = tv_range[0] * 16; | |
646 | tuner->rangehigh = tv_range[1] * 16; | |
56fc08ca | 647 | } |
f7ce3cc6 MCC |
648 | break; |
649 | } | |
650 | case VIDIOC_S_TUNER: | |
651 | { | |
652 | struct v4l2_tuner *tuner = arg; | |
653 | ||
654 | if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL) | |
655 | return 0; | |
656 | ||
657 | switch_v4l2(); | |
658 | ||
659 | if (V4L2_TUNER_RADIO == t->mode) { | |
660 | t->audmode = tuner->audmode; | |
661 | set_radio_freq(client, t->freq); | |
662 | } | |
663 | break; | |
56fc08ca | 664 | } |
1da177e4 | 665 | default: |
c5287ba1 MCC |
666 | tuner_dbg("Unimplemented IOCTL 0x%08x(dir=%d,tp=0x%02x,nr=%d,sz=%d)\n", |
667 | cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd), | |
668 | _IOC_NR(cmd), _IOC_SIZE(cmd)); | |
1da177e4 LT |
669 | break; |
670 | } | |
671 | ||
672 | return 0; | |
673 | } | |
674 | ||
829ca9a3 | 675 | static int tuner_suspend(struct device *dev, pm_message_t state, u32 level) |
1da177e4 | 676 | { |
f7ce3cc6 MCC |
677 | struct i2c_client *c = container_of (dev, struct i2c_client, dev); |
678 | struct tuner *t = i2c_get_clientdata (c); | |
1da177e4 | 679 | |
f7ce3cc6 | 680 | tuner_dbg ("suspend\n"); |
1da177e4 LT |
681 | /* FIXME: power down ??? */ |
682 | return 0; | |
683 | } | |
684 | ||
f7ce3cc6 | 685 | static int tuner_resume(struct device *dev, u32 level) |
1da177e4 | 686 | { |
f7ce3cc6 MCC |
687 | struct i2c_client *c = container_of (dev, struct i2c_client, dev); |
688 | struct tuner *t = i2c_get_clientdata (c); | |
1da177e4 | 689 | |
f7ce3cc6 | 690 | tuner_dbg ("resume\n"); |
1da177e4 | 691 | if (t->freq) |
f7ce3cc6 | 692 | set_freq(c, t->freq); |
1da177e4 LT |
693 | return 0; |
694 | } | |
695 | ||
696 | /* ----------------------------------------------------------------------- */ | |
697 | ||
698 | static struct i2c_driver driver = { | |
f7ce3cc6 MCC |
699 | .owner = THIS_MODULE, |
700 | .name = "tuner", | |
701 | .id = I2C_DRIVERID_TUNER, | |
702 | .flags = I2C_DF_NOTIFY, | |
703 | .attach_adapter = tuner_probe, | |
704 | .detach_client = tuner_detach, | |
705 | .command = tuner_command, | |
1da177e4 | 706 | .driver = { |
f7ce3cc6 MCC |
707 | .suspend = tuner_suspend, |
708 | .resume = tuner_resume, | |
709 | }, | |
1da177e4 | 710 | }; |
f7ce3cc6 | 711 | static struct i2c_client client_template = { |
1da177e4 | 712 | I2C_DEVNAME("(tuner unset)"), |
f7ce3cc6 MCC |
713 | .flags = I2C_CLIENT_ALLOW_USE, |
714 | .driver = &driver, | |
1da177e4 LT |
715 | }; |
716 | ||
717 | static int __init tuner_init_module(void) | |
718 | { | |
719 | return i2c_add_driver(&driver); | |
720 | } | |
721 | ||
722 | static void __exit tuner_cleanup_module(void) | |
723 | { | |
724 | i2c_del_driver(&driver); | |
725 | } | |
726 | ||
727 | module_init(tuner_init_module); | |
728 | module_exit(tuner_cleanup_module); | |
729 | ||
730 | /* | |
731 | * Overrides for Emacs so that we follow Linus's tabbing style. | |
732 | * --------------------------------------------------------------------------- | |
733 | * Local variables: | |
734 | * c-basic-offset: 8 | |
735 | * End: | |
736 | */ |