Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* radio-cadet.c - A video4linux driver for the ADS Cadet AM/FM Radio Card |
2 | * | |
3 | * by Fred Gleason <fredg@wava.com> | |
4 | * Version 0.3.3 | |
5 | * | |
6 | * (Loosely) based on code for the Aztech radio card by | |
7 | * | |
8 | * Russell Kroll (rkroll@exploits.org) | |
9 | * Quay Ly | |
10 | * Donald Song | |
4286c6f6 | 11 | * Jason Lewis (jlewis@twilight.vtc.vsc.edu) |
1da177e4 LT |
12 | * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) |
13 | * William McGrath (wmcgrath@twilight.vtc.vsc.edu) | |
14 | * | |
15 | * History: | |
16 | * 2000-04-29 Russell Kroll <rkroll@exploits.org> | |
17 | * Added ISAPnP detection for Linux 2.3/2.4 | |
18 | * | |
19 | * 2001-01-10 Russell Kroll <rkroll@exploits.org> | |
20 | * Removed dead CONFIG_RADIO_CADET_PORT code | |
21 | * PnP detection on load is now default (no args necessary) | |
22 | * | |
23 | * 2002-01-17 Adam Belay <ambx1@neo.rr.com> | |
24 | * Updated to latest pnp code | |
25 | * | |
d9b01449 | 26 | * 2003-01-31 Alan Cox <alan@lxorguk.ukuu.org.uk> |
1da177e4 | 27 | * Cleaned up locking, delay code, general odds and ends |
c0c7fa09 HK |
28 | * |
29 | * 2006-07-30 Hans J. Koch <koch@hjk-az.de> | |
30 | * Changed API to V4L2 | |
1da177e4 LT |
31 | */ |
32 | ||
d591b9cc | 33 | #include <linux/version.h> |
1da177e4 LT |
34 | #include <linux/module.h> /* Modules */ |
35 | #include <linux/init.h> /* Initdata */ | |
fb911ee8 | 36 | #include <linux/ioport.h> /* request_region */ |
1da177e4 LT |
37 | #include <linux/delay.h> /* udelay */ |
38 | #include <asm/io.h> /* outb, outb_p */ | |
39 | #include <asm/uaccess.h> /* copy to/from user */ | |
c0c7fa09 | 40 | #include <linux/videodev2.h> /* V4L2 API defs */ |
5e87efa3 | 41 | #include <media/v4l2-common.h> |
35ea11ff | 42 | #include <media/v4l2-ioctl.h> |
1da177e4 LT |
43 | #include <linux/param.h> |
44 | #include <linux/pnp.h> | |
45 | ||
46 | #define RDS_BUFFER 256 | |
c0c7fa09 HK |
47 | #define RDS_RX_FLAG 1 |
48 | #define MBS_RX_FLAG 2 | |
49 | ||
50 | #define CADET_VERSION KERNEL_VERSION(0,3,3) | |
1da177e4 | 51 | |
c1c4fd3e DL |
52 | static struct v4l2_queryctrl radio_qctrl[] = { |
53 | { | |
54 | .id = V4L2_CID_AUDIO_MUTE, | |
55 | .name = "Mute", | |
56 | .minimum = 0, | |
57 | .maximum = 1, | |
58 | .default_value = 1, | |
59 | .type = V4L2_CTRL_TYPE_BOOLEAN, | |
60 | },{ | |
61 | .id = V4L2_CID_AUDIO_VOLUME, | |
62 | .name = "Volume", | |
63 | .minimum = 0, | |
64 | .maximum = 0xff, | |
65 | .step = 1, | |
66 | .default_value = 0xff, | |
67 | .type = V4L2_CTRL_TYPE_INTEGER, | |
68 | } | |
69 | }; | |
70 | ||
1da177e4 LT |
71 | static int io=-1; /* default to isapnp activation */ |
72 | static int radio_nr = -1; | |
ff699e6b DSL |
73 | static int users; |
74 | static int curtuner; | |
75 | static int tunestat; | |
76 | static int sigstrength; | |
1da177e4 LT |
77 | static wait_queue_head_t read_queue; |
78 | static struct timer_list readtimer; | |
ff699e6b | 79 | static __u8 rdsin, rdsout, rdsstat; |
1da177e4 LT |
80 | static unsigned char rdsbuf[RDS_BUFFER]; |
81 | static spinlock_t cadet_io_lock; | |
82 | ||
83 | static int cadet_probe(void); | |
84 | ||
85 | /* | |
86 | * Signal Strength Threshold Values | |
4286c6f6 | 87 | * The V4L API spec does not define any particular unit for the signal |
1da177e4 LT |
88 | * strength value. These values are in microvolts of RF at the tuner's input. |
89 | */ | |
90 | static __u16 sigtable[2][4]={{5,10,30,150},{28,40,63,1000}}; | |
91 | ||
1da177e4 | 92 | |
c0c7fa09 HK |
93 | static int |
94 | cadet_getstereo(void) | |
1da177e4 | 95 | { |
c0c7fa09 | 96 | int ret = V4L2_TUNER_SUB_MONO; |
4286c6f6 | 97 | if(curtuner != 0) /* Only FM has stereo capability! */ |
c0c7fa09 | 98 | return V4L2_TUNER_SUB_MONO; |
1da177e4 LT |
99 | |
100 | spin_lock(&cadet_io_lock); | |
4286c6f6 | 101 | outb(7,io); /* Select tuner control */ |
1da177e4 | 102 | if( (inb(io+1) & 0x40) == 0) |
c0c7fa09 | 103 | ret = V4L2_TUNER_SUB_STEREO; |
4286c6f6 MCC |
104 | spin_unlock(&cadet_io_lock); |
105 | return ret; | |
1da177e4 LT |
106 | } |
107 | ||
c0c7fa09 HK |
108 | static unsigned |
109 | cadet_gettune(void) | |
1da177e4 | 110 | { |
4286c6f6 | 111 | int curvol,i; |
1da177e4 LT |
112 | unsigned fifo=0; |
113 | ||
4286c6f6 MCC |
114 | /* |
115 | * Prepare for read | |
116 | */ | |
1da177e4 LT |
117 | |
118 | spin_lock(&cadet_io_lock); | |
4286c6f6 MCC |
119 | |
120 | outb(7,io); /* Select tuner control */ | |
121 | curvol=inb(io+1); /* Save current volume/mute setting */ | |
122 | outb(0x00,io+1); /* Ensure WRITE-ENABLE is LOW */ | |
1da177e4 LT |
123 | tunestat=0xffff; |
124 | ||
4286c6f6 MCC |
125 | /* |
126 | * Read the shift register | |
127 | */ | |
128 | for(i=0;i<25;i++) { | |
129 | fifo=(fifo<<1)|((inb(io+1)>>7)&0x01); | |
130 | if(i<24) { | |
131 | outb(0x01,io+1); | |
1da177e4 | 132 | tunestat&=inb(io+1); |
4286c6f6 MCC |
133 | outb(0x00,io+1); |
134 | } | |
135 | } | |
136 | ||
137 | /* | |
138 | * Restore volume/mute setting | |
139 | */ | |
140 | outb(curvol,io+1); | |
1da177e4 LT |
141 | spin_unlock(&cadet_io_lock); |
142 | ||
143 | return fifo; | |
144 | } | |
145 | ||
c0c7fa09 HK |
146 | static unsigned |
147 | cadet_getfreq(void) | |
1da177e4 | 148 | { |
4286c6f6 MCC |
149 | int i; |
150 | unsigned freq=0,test,fifo=0; | |
1da177e4 LT |
151 | |
152 | /* | |
153 | * Read current tuning | |
154 | */ | |
155 | fifo=cadet_gettune(); | |
156 | ||
4286c6f6 MCC |
157 | /* |
158 | * Convert to actual frequency | |
159 | */ | |
1da177e4 | 160 | if(curtuner==0) { /* FM */ |
4286c6f6 MCC |
161 | test=12500; |
162 | for(i=0;i<14;i++) { | |
163 | if((fifo&0x01)!=0) { | |
164 | freq+=test; | |
165 | } | |
166 | test=test<<1; | |
167 | fifo=fifo>>1; | |
168 | } | |
169 | freq-=10700000; /* IF frequency is 10.7 MHz */ | |
170 | freq=(freq*16)/1000000; /* Make it 1/16 MHz */ | |
1da177e4 LT |
171 | } |
172 | if(curtuner==1) { /* AM */ | |
4286c6f6 | 173 | freq=((fifo&0x7fff)-2010)*16; |
1da177e4 LT |
174 | } |
175 | ||
4286c6f6 | 176 | return freq; |
1da177e4 LT |
177 | } |
178 | ||
c0c7fa09 HK |
179 | static void |
180 | cadet_settune(unsigned fifo) | |
1da177e4 | 181 | { |
4286c6f6 MCC |
182 | int i; |
183 | unsigned test; | |
1da177e4 LT |
184 | |
185 | spin_lock(&cadet_io_lock); | |
4286c6f6 | 186 | |
1da177e4 LT |
187 | outb(7,io); /* Select tuner control */ |
188 | /* | |
189 | * Write the shift register | |
190 | */ | |
191 | test=0; | |
192 | test=(fifo>>23)&0x02; /* Align data for SDO */ | |
193 | test|=0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */ | |
194 | outb(7,io); /* Select tuner control */ | |
195 | outb(test,io+1); /* Initialize for write */ | |
196 | for(i=0;i<25;i++) { | |
4286c6f6 | 197 | test|=0x01; /* Toggle SCK High */ |
1da177e4 LT |
198 | outb(test,io+1); |
199 | test&=0xfe; /* Toggle SCK Low */ | |
200 | outb(test,io+1); | |
201 | fifo=fifo<<1; /* Prepare the next bit */ | |
202 | test=0x1c|((fifo>>23)&0x02); | |
203 | outb(test,io+1); | |
204 | } | |
205 | spin_unlock(&cadet_io_lock); | |
206 | } | |
207 | ||
c0c7fa09 HK |
208 | static void |
209 | cadet_setfreq(unsigned freq) | |
1da177e4 | 210 | { |
4286c6f6 MCC |
211 | unsigned fifo; |
212 | int i,j,test; | |
213 | int curvol; | |
1da177e4 | 214 | |
4286c6f6 MCC |
215 | /* |
216 | * Formulate a fifo command | |
217 | */ | |
1da177e4 LT |
218 | fifo=0; |
219 | if(curtuner==0) { /* FM */ | |
4286c6f6 MCC |
220 | test=102400; |
221 | freq=(freq*1000)/16; /* Make it kHz */ | |
222 | freq+=10700; /* IF is 10700 kHz */ | |
223 | for(i=0;i<14;i++) { | |
224 | fifo=fifo<<1; | |
225 | if(freq>=test) { | |
226 | fifo|=0x01; | |
227 | freq-=test; | |
228 | } | |
229 | test=test>>1; | |
230 | } | |
1da177e4 LT |
231 | } |
232 | if(curtuner==1) { /* AM */ | |
4286c6f6 | 233 | fifo=(freq/16)+2010; /* Make it kHz */ |
1da177e4 LT |
234 | fifo|=0x100000; /* Select AM Band */ |
235 | } | |
236 | ||
4286c6f6 MCC |
237 | /* |
238 | * Save current volume/mute setting | |
239 | */ | |
1da177e4 LT |
240 | |
241 | spin_lock(&cadet_io_lock); | |
242 | outb(7,io); /* Select tuner control */ | |
4286c6f6 MCC |
243 | curvol=inb(io+1); |
244 | spin_unlock(&cadet_io_lock); | |
1da177e4 LT |
245 | |
246 | /* | |
247 | * Tune the card | |
248 | */ | |
249 | for(j=3;j>-1;j--) { | |
4286c6f6 MCC |
250 | cadet_settune(fifo|(j<<16)); |
251 | ||
252 | spin_lock(&cadet_io_lock); | |
1da177e4 LT |
253 | outb(7,io); /* Select tuner control */ |
254 | outb(curvol,io+1); | |
255 | spin_unlock(&cadet_io_lock); | |
4286c6f6 | 256 | |
1da177e4 LT |
257 | msleep(100); |
258 | ||
259 | cadet_gettune(); | |
260 | if((tunestat & 0x40) == 0) { /* Tuned */ | |
4286c6f6 | 261 | sigstrength=sigtable[curtuner][j]; |
1da177e4 LT |
262 | return; |
263 | } | |
264 | } | |
265 | sigstrength=0; | |
266 | } | |
267 | ||
268 | ||
c0c7fa09 HK |
269 | static int |
270 | cadet_getvol(void) | |
1da177e4 LT |
271 | { |
272 | int ret = 0; | |
4286c6f6 | 273 | |
1da177e4 | 274 | spin_lock(&cadet_io_lock); |
4286c6f6 MCC |
275 | |
276 | outb(7,io); /* Select tuner control */ | |
277 | if((inb(io + 1) & 0x20) != 0) | |
278 | ret = 0xffff; | |
279 | ||
280 | spin_unlock(&cadet_io_lock); | |
281 | return ret; | |
1da177e4 LT |
282 | } |
283 | ||
284 | ||
c0c7fa09 HK |
285 | static void |
286 | cadet_setvol(int vol) | |
1da177e4 LT |
287 | { |
288 | spin_lock(&cadet_io_lock); | |
4286c6f6 MCC |
289 | outb(7,io); /* Select tuner control */ |
290 | if(vol>0) | |
291 | outb(0x20,io+1); | |
292 | else | |
293 | outb(0x00,io+1); | |
1da177e4 | 294 | spin_unlock(&cadet_io_lock); |
4286c6f6 | 295 | } |
1da177e4 | 296 | |
c0c7fa09 HK |
297 | static void |
298 | cadet_handler(unsigned long data) | |
1da177e4 LT |
299 | { |
300 | /* | |
301 | * Service the RDS fifo | |
302 | */ | |
303 | ||
304 | if(spin_trylock(&cadet_io_lock)) | |
305 | { | |
4286c6f6 | 306 | outb(0x3,io); /* Select RDS Decoder Control */ |
1da177e4 | 307 | if((inb(io+1)&0x20)!=0) { |
4286c6f6 | 308 | printk(KERN_CRIT "cadet: RDS fifo overflow\n"); |
1da177e4 LT |
309 | } |
310 | outb(0x80,io); /* Select RDS fifo */ | |
311 | while((inb(io)&0x80)!=0) { | |
4286c6f6 | 312 | rdsbuf[rdsin]=inb(io+1); |
1da177e4 | 313 | if(rdsin==rdsout) |
4286c6f6 | 314 | printk(KERN_WARNING "cadet: RDS buffer overflow\n"); |
1da177e4 LT |
315 | else |
316 | rdsin++; | |
317 | } | |
318 | spin_unlock(&cadet_io_lock); | |
319 | } | |
320 | ||
321 | /* | |
322 | * Service pending read | |
323 | */ | |
324 | if( rdsin!=rdsout) | |
4286c6f6 | 325 | wake_up_interruptible(&read_queue); |
1da177e4 | 326 | |
4286c6f6 | 327 | /* |
1da177e4 LT |
328 | * Clean up and exit |
329 | */ | |
330 | init_timer(&readtimer); | |
331 | readtimer.function=cadet_handler; | |
332 | readtimer.data=(unsigned long)0; | |
a2d66a37 | 333 | readtimer.expires=jiffies+msecs_to_jiffies(50); |
1da177e4 LT |
334 | add_timer(&readtimer); |
335 | } | |
336 | ||
337 | ||
338 | ||
c0c7fa09 HK |
339 | static ssize_t |
340 | cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos) | |
1da177e4 | 341 | { |
4286c6f6 | 342 | int i=0; |
1da177e4 LT |
343 | unsigned char readbuf[RDS_BUFFER]; |
344 | ||
4286c6f6 | 345 | if(rdsstat==0) { |
1da177e4 | 346 | spin_lock(&cadet_io_lock); |
4286c6f6 | 347 | rdsstat=1; |
1da177e4 LT |
348 | outb(0x80,io); /* Select RDS fifo */ |
349 | spin_unlock(&cadet_io_lock); | |
350 | init_timer(&readtimer); | |
351 | readtimer.function=cadet_handler; | |
352 | readtimer.data=(unsigned long)0; | |
a2d66a37 | 353 | readtimer.expires=jiffies+msecs_to_jiffies(50); |
1da177e4 LT |
354 | add_timer(&readtimer); |
355 | } | |
356 | if(rdsin==rdsout) { | |
4286c6f6 MCC |
357 | if (file->f_flags & O_NONBLOCK) |
358 | return -EWOULDBLOCK; | |
359 | interruptible_sleep_on(&read_queue); | |
360 | } | |
1da177e4 | 361 | while( i<count && rdsin!=rdsout) |
4286c6f6 | 362 | readbuf[i++]=rdsbuf[rdsout++]; |
1da177e4 LT |
363 | |
364 | if (copy_to_user(data,readbuf,i)) | |
4286c6f6 | 365 | return -EFAULT; |
1da177e4 LT |
366 | return i; |
367 | } | |
368 | ||
369 | ||
c1c4fd3e DL |
370 | static int vidioc_querycap(struct file *file, void *priv, |
371 | struct v4l2_capability *v) | |
372 | { | |
373 | v->capabilities = | |
374 | V4L2_CAP_TUNER | | |
375 | V4L2_CAP_READWRITE; | |
376 | v->version = CADET_VERSION; | |
377 | strcpy(v->driver, "ADS Cadet"); | |
378 | strcpy(v->card, "ADS Cadet"); | |
379 | return 0; | |
380 | } | |
1da177e4 | 381 | |
c1c4fd3e DL |
382 | static int vidioc_g_tuner(struct file *file, void *priv, |
383 | struct v4l2_tuner *v) | |
1da177e4 | 384 | { |
c1c4fd3e DL |
385 | v->type = V4L2_TUNER_RADIO; |
386 | switch (v->index) { | |
387 | case 0: | |
388 | strcpy(v->name, "FM"); | |
389 | v->capability = V4L2_TUNER_CAP_STEREO; | |
390 | v->rangelow = 1400; /* 87.5 MHz */ | |
391 | v->rangehigh = 1728; /* 108.0 MHz */ | |
392 | v->rxsubchans=cadet_getstereo(); | |
393 | switch (v->rxsubchans){ | |
394 | case V4L2_TUNER_SUB_MONO: | |
395 | v->audmode = V4L2_TUNER_MODE_MONO; | |
396 | break; | |
397 | case V4L2_TUNER_SUB_STEREO: | |
398 | v->audmode = V4L2_TUNER_MODE_STEREO; | |
399 | break; | |
400 | default: ; | |
1da177e4 | 401 | } |
c1c4fd3e DL |
402 | break; |
403 | case 1: | |
404 | strcpy(v->name, "AM"); | |
405 | v->capability = V4L2_TUNER_CAP_LOW; | |
406 | v->rangelow = 8320; /* 520 kHz */ | |
407 | v->rangehigh = 26400; /* 1650 kHz */ | |
408 | v->rxsubchans = V4L2_TUNER_SUB_MONO; | |
409 | v->audmode = V4L2_TUNER_MODE_MONO; | |
410 | break; | |
411 | default: | |
412 | return -EINVAL; | |
413 | } | |
414 | v->signal = sigstrength; /* We might need to modify scaling of this */ | |
415 | return 0; | |
416 | } | |
c0c7fa09 | 417 | |
c1c4fd3e DL |
418 | static int vidioc_s_tuner(struct file *file, void *priv, |
419 | struct v4l2_tuner *v) | |
420 | { | |
421 | if((v->index != 0)&&(v->index != 1)) | |
422 | return -EINVAL; | |
423 | curtuner = v->index; | |
424 | return 0; | |
425 | } | |
c0c7fa09 | 426 | |
c1c4fd3e DL |
427 | static int vidioc_g_frequency(struct file *file, void *priv, |
428 | struct v4l2_frequency *f) | |
429 | { | |
430 | f->tuner = curtuner; | |
431 | f->type = V4L2_TUNER_RADIO; | |
432 | f->frequency = cadet_getfreq(); | |
433 | return 0; | |
434 | } | |
435 | ||
436 | ||
437 | static int vidioc_s_frequency(struct file *file, void *priv, | |
438 | struct v4l2_frequency *f) | |
439 | { | |
440 | if (f->type != V4L2_TUNER_RADIO) | |
441 | return -EINVAL; | |
442 | if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728))) | |
443 | return -EINVAL; | |
444 | if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400))) | |
445 | return -EINVAL; | |
446 | cadet_setfreq(f->frequency); | |
447 | return 0; | |
448 | } | |
449 | ||
450 | static int vidioc_queryctrl(struct file *file, void *priv, | |
451 | struct v4l2_queryctrl *qc) | |
452 | { | |
453 | int i; | |
454 | ||
455 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { | |
456 | if (qc->id && qc->id == radio_qctrl[i].id) { | |
457 | memcpy(qc, &(radio_qctrl[i]), | |
458 | sizeof(*qc)); | |
1da177e4 LT |
459 | return 0; |
460 | } | |
c1c4fd3e DL |
461 | } |
462 | return -EINVAL; | |
463 | } | |
c0c7fa09 | 464 | |
c1c4fd3e DL |
465 | static int vidioc_g_ctrl(struct file *file, void *priv, |
466 | struct v4l2_control *ctrl) | |
467 | { | |
468 | switch (ctrl->id){ | |
469 | case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ | |
470 | ctrl->value = (cadet_getvol() == 0); | |
471 | break; | |
472 | case V4L2_CID_AUDIO_VOLUME: | |
473 | ctrl->value = cadet_getvol(); | |
474 | break; | |
475 | default: | |
476 | return -EINVAL; | |
1da177e4 | 477 | } |
c1c4fd3e | 478 | return 0; |
1da177e4 LT |
479 | } |
480 | ||
c1c4fd3e DL |
481 | static int vidioc_s_ctrl(struct file *file, void *priv, |
482 | struct v4l2_control *ctrl) | |
1da177e4 | 483 | { |
c1c4fd3e DL |
484 | switch (ctrl->id){ |
485 | case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ | |
486 | if (ctrl->value) | |
487 | cadet_setvol(0); | |
488 | else | |
489 | cadet_setvol(0xffff); | |
490 | break; | |
491 | case V4L2_CID_AUDIO_VOLUME: | |
492 | cadet_setvol(ctrl->value); | |
493 | break; | |
494 | default: | |
495 | return -EINVAL; | |
496 | } | |
497 | return 0; | |
498 | } | |
499 | ||
500 | static int vidioc_g_audio(struct file *file, void *priv, | |
501 | struct v4l2_audio *a) | |
502 | { | |
503 | if (a->index > 1) | |
504 | return -EINVAL; | |
505 | strcpy(a->name, "Radio"); | |
506 | a->capability = V4L2_AUDCAP_STEREO; | |
507 | return 0; | |
508 | } | |
509 | ||
510 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) | |
511 | { | |
512 | *i = 0; | |
513 | return 0; | |
514 | } | |
515 | ||
516 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) | |
517 | { | |
518 | if (i != 0) | |
519 | return -EINVAL; | |
520 | return 0; | |
521 | } | |
522 | ||
523 | static int vidioc_s_audio(struct file *file, void *priv, | |
524 | struct v4l2_audio *a) | |
525 | { | |
526 | if (a->index != 0) | |
527 | return -EINVAL; | |
528 | return 0; | |
1da177e4 LT |
529 | } |
530 | ||
c0c7fa09 | 531 | static int |
bec43661 | 532 | cadet_open(struct file *file) |
1da177e4 | 533 | { |
1da177e4 | 534 | users++; |
c0c7fa09 | 535 | if (1 == users) init_waitqueue_head(&read_queue); |
1da177e4 LT |
536 | return 0; |
537 | } | |
538 | ||
c0c7fa09 | 539 | static int |
bec43661 | 540 | cadet_release(struct file *file) |
1da177e4 | 541 | { |
1da177e4 | 542 | users--; |
c0c7fa09 HK |
543 | if (0 == users){ |
544 | del_timer_sync(&readtimer); | |
545 | rdsstat=0; | |
546 | } | |
547 | return 0; | |
548 | } | |
549 | ||
550 | static unsigned int | |
551 | cadet_poll(struct file *file, struct poll_table_struct *wait) | |
552 | { | |
553 | poll_wait(file,&read_queue,wait); | |
554 | if(rdsin != rdsout) | |
555 | return POLLIN | POLLRDNORM; | |
1da177e4 LT |
556 | return 0; |
557 | } | |
558 | ||
559 | ||
bec43661 | 560 | static const struct v4l2_file_operations cadet_fops = { |
1da177e4 LT |
561 | .owner = THIS_MODULE, |
562 | .open = cadet_open, | |
563 | .release = cadet_release, | |
564 | .read = cadet_read, | |
c1c4fd3e | 565 | .ioctl = video_ioctl2, |
c0c7fa09 | 566 | .poll = cadet_poll, |
1da177e4 LT |
567 | }; |
568 | ||
a399810c | 569 | static const struct v4l2_ioctl_ops cadet_ioctl_ops = { |
c1c4fd3e DL |
570 | .vidioc_querycap = vidioc_querycap, |
571 | .vidioc_g_tuner = vidioc_g_tuner, | |
572 | .vidioc_s_tuner = vidioc_s_tuner, | |
573 | .vidioc_g_frequency = vidioc_g_frequency, | |
574 | .vidioc_s_frequency = vidioc_s_frequency, | |
575 | .vidioc_queryctrl = vidioc_queryctrl, | |
576 | .vidioc_g_ctrl = vidioc_g_ctrl, | |
577 | .vidioc_s_ctrl = vidioc_s_ctrl, | |
578 | .vidioc_g_audio = vidioc_g_audio, | |
579 | .vidioc_s_audio = vidioc_s_audio, | |
580 | .vidioc_g_input = vidioc_g_input, | |
581 | .vidioc_s_input = vidioc_s_input, | |
1da177e4 LT |
582 | }; |
583 | ||
a399810c | 584 | static struct video_device cadet_radio = { |
a399810c | 585 | .name = "Cadet radio", |
a399810c HV |
586 | .fops = &cadet_fops, |
587 | .ioctl_ops = &cadet_ioctl_ops, | |
aa5e90af | 588 | .release = video_device_release_empty, |
a399810c HV |
589 | }; |
590 | ||
044dfc99 BH |
591 | #ifdef CONFIG_PNP |
592 | ||
1da177e4 LT |
593 | static struct pnp_device_id cadet_pnp_devices[] = { |
594 | /* ADS Cadet AM/FM Radio Card */ | |
595 | {.id = "MSM0c24", .driver_data = 0}, | |
596 | {.id = ""} | |
597 | }; | |
598 | ||
599 | MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices); | |
600 | ||
601 | static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) | |
602 | { | |
603 | if (!dev) | |
604 | return -ENODEV; | |
605 | /* only support one device */ | |
606 | if (io > 0) | |
607 | return -EBUSY; | |
608 | ||
609 | if (!pnp_port_valid(dev, 0)) { | |
610 | return -ENODEV; | |
611 | } | |
612 | ||
613 | io = pnp_port_start(dev, 0); | |
614 | ||
615 | printk ("radio-cadet: PnP reports device at %#x\n", io); | |
616 | ||
617 | return io; | |
618 | } | |
619 | ||
620 | static struct pnp_driver cadet_pnp_driver = { | |
621 | .name = "radio-cadet", | |
622 | .id_table = cadet_pnp_devices, | |
623 | .probe = cadet_pnp_probe, | |
624 | .remove = NULL, | |
625 | }; | |
626 | ||
044dfc99 BH |
627 | #else |
628 | static struct pnp_driver cadet_pnp_driver; | |
629 | #endif | |
630 | ||
1da177e4 LT |
631 | static int cadet_probe(void) |
632 | { | |
4286c6f6 | 633 | static int iovals[8]={0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e}; |
1da177e4 LT |
634 | int i; |
635 | ||
636 | for(i=0;i<8;i++) { | |
4286c6f6 | 637 | io=iovals[i]; |
f1ac046d | 638 | if (request_region(io, 2, "cadet-probe")) { |
4286c6f6 | 639 | cadet_setfreq(1410); |
1da177e4 LT |
640 | if(cadet_getfreq()==1410) { |
641 | release_region(io, 2); | |
4286c6f6 | 642 | return io; |
1da177e4 LT |
643 | } |
644 | release_region(io, 2); | |
645 | } | |
646 | } | |
647 | return -1; | |
648 | } | |
649 | ||
4286c6f6 | 650 | /* |
1da177e4 LT |
651 | * io should only be set if the user has used something like |
652 | * isapnp (the userspace program) to initialize this card for us | |
653 | */ | |
654 | ||
655 | static int __init cadet_init(void) | |
656 | { | |
657 | spin_lock_init(&cadet_io_lock); | |
4286c6f6 | 658 | |
1da177e4 LT |
659 | /* |
660 | * If a probe was requested then probe ISAPnP first (safest) | |
661 | */ | |
662 | if (io < 0) | |
663 | pnp_register_driver(&cadet_pnp_driver); | |
664 | /* | |
665 | * If that fails then probe unsafely if probe is requested | |
666 | */ | |
667 | if(io < 0) | |
668 | io = cadet_probe (); | |
669 | ||
670 | /* | |
671 | * Else we bail out | |
672 | */ | |
4286c6f6 MCC |
673 | |
674 | if(io < 0) { | |
675 | #ifdef MODULE | |
1da177e4 LT |
676 | printk(KERN_ERR "You must set an I/O address with io=0x???\n"); |
677 | #endif | |
4286c6f6 | 678 | goto fail; |
1da177e4 LT |
679 | } |
680 | if (!request_region(io,2,"cadet")) | |
681 | goto fail; | |
cba99ae8 | 682 | if (video_register_device(&cadet_radio, VFL_TYPE_RADIO, radio_nr) < 0) { |
1da177e4 LT |
683 | release_region(io,2); |
684 | goto fail; | |
685 | } | |
686 | printk(KERN_INFO "ADS Cadet Radio Card at 0x%x\n",io); | |
687 | return 0; | |
688 | fail: | |
689 | pnp_unregister_driver(&cadet_pnp_driver); | |
690 | return -1; | |
691 | } | |
692 | ||
693 | ||
694 | ||
695 | MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); | |
696 | MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card."); | |
697 | MODULE_LICENSE("GPL"); | |
698 | ||
699 | module_param(io, int, 0); | |
700 | MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)"); | |
701 | module_param(radio_nr, int, 0); | |
702 | ||
703 | static void __exit cadet_cleanup_module(void) | |
704 | { | |
705 | video_unregister_device(&cadet_radio); | |
706 | release_region(io,2); | |
707 | pnp_unregister_driver(&cadet_pnp_driver); | |
708 | } | |
709 | ||
710 | module_init(cadet_init); | |
711 | module_exit(cadet_cleanup_module); | |
712 |