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