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