radio-cadet.c 14.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10
/* radio-cadet.c - A video4linux driver for the ADS Cadet AM/FM Radio Card
 *
 * by Fred Gleason <fredg@wava.com>
 * Version 0.3.3
 *
 * (Loosely) based on code for the Aztech radio card by
 *
 * Russell Kroll    (rkroll@exploits.org)
 * Quay Ly
 * Donald Song
11
 * Jason Lewis      (jlewis@twilight.vtc.vsc.edu)
L
Linus Torvalds 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * Scott McGrath    (smcgrath@twilight.vtc.vsc.edu)
 * William McGrath  (wmcgrath@twilight.vtc.vsc.edu)
 *
 * History:
 * 2000-04-29	Russell Kroll <rkroll@exploits.org>
 *		Added ISAPnP detection for Linux 2.3/2.4
 *
 * 2001-01-10	Russell Kroll <rkroll@exploits.org>
 *		Removed dead CONFIG_RADIO_CADET_PORT code
 *		PnP detection on load is now default (no args necessary)
 *
 * 2002-01-17	Adam Belay <ambx1@neo.rr.com>
 *		Updated to latest pnp code
 *
 * 2003-01-31	Alan Cox <alan@redhat.com>
 *		Cleaned up locking, delay code, general odds and ends
28 29 30
 *
 * 2006-07-30	Hans J. Koch <koch@hjk-az.de>
 *		Changed API to V4L2
L
Linus Torvalds 已提交
31 32
 */

33
#include <linux/version.h>
L
Linus Torvalds 已提交
34 35
#include <linux/module.h>	/* Modules 			*/
#include <linux/init.h>		/* Initdata			*/
36
#include <linux/ioport.h>	/* request_region		*/
L
Linus Torvalds 已提交
37 38 39
#include <linux/delay.h>	/* udelay			*/
#include <asm/io.h>		/* outb, outb_p			*/
#include <asm/uaccess.h>	/* copy to/from user		*/
40
#include <linux/videodev2.h>	/* V4L2 API defs		*/
41
#include <media/v4l2-common.h>
42
#include <media/v4l2-ioctl.h>
L
Linus Torvalds 已提交
43 44 45 46
#include <linux/param.h>
#include <linux/pnp.h>

#define RDS_BUFFER 256
47 48 49 50
#define RDS_RX_FLAG 1
#define MBS_RX_FLAG 2

#define CADET_VERSION KERNEL_VERSION(0,3,3)
L
Linus Torvalds 已提交
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
static struct v4l2_queryctrl radio_qctrl[] = {
	{
		.id            = V4L2_CID_AUDIO_MUTE,
		.name          = "Mute",
		.minimum       = 0,
		.maximum       = 1,
		.default_value = 1,
		.type          = V4L2_CTRL_TYPE_BOOLEAN,
	},{
		.id            = V4L2_CID_AUDIO_VOLUME,
		.name          = "Volume",
		.minimum       = 0,
		.maximum       = 0xff,
		.step          = 1,
		.default_value = 0xff,
		.type          = V4L2_CTRL_TYPE_INTEGER,
	}
};

L
Linus Torvalds 已提交
71 72
static int io=-1;		/* default to isapnp activation */
static int radio_nr = -1;
73 74 75 76
static int users;
static int curtuner;
static int tunestat;
static int sigstrength;
L
Linus Torvalds 已提交
77 78
static wait_queue_head_t read_queue;
static struct timer_list readtimer;
79
static __u8 rdsin, rdsout, rdsstat;
L
Linus Torvalds 已提交
80 81 82 83 84 85 86
static unsigned char rdsbuf[RDS_BUFFER];
static spinlock_t cadet_io_lock;

static int cadet_probe(void);

/*
 * Signal Strength Threshold Values
87
 * The V4L API spec does not define any particular unit for the signal
L
Linus Torvalds 已提交
88 89 90 91 92
 * strength value.  These values are in microvolts of RF at the tuner's input.
 */
static __u16 sigtable[2][4]={{5,10,30,150},{28,40,63,1000}};


93 94
static int
cadet_getstereo(void)
L
Linus Torvalds 已提交
95
{
96
	int ret = V4L2_TUNER_SUB_MONO;
97
	if(curtuner != 0)	/* Only FM has stereo capability! */
98
		return V4L2_TUNER_SUB_MONO;
L
Linus Torvalds 已提交
99 100

	spin_lock(&cadet_io_lock);
101
	outb(7,io);          /* Select tuner control */
L
Linus Torvalds 已提交
102
	if( (inb(io+1) & 0x40) == 0)
103
		ret = V4L2_TUNER_SUB_STEREO;
104 105
	spin_unlock(&cadet_io_lock);
	return ret;
L
Linus Torvalds 已提交
106 107
}

108 109
static unsigned
cadet_gettune(void)
L
Linus Torvalds 已提交
110
{
111
	int curvol,i;
L
Linus Torvalds 已提交
112 113
	unsigned fifo=0;

114 115 116
	/*
	 * Prepare for read
	 */
L
Linus Torvalds 已提交
117 118

	spin_lock(&cadet_io_lock);
119 120 121 122

	outb(7,io);       /* Select tuner control */
	curvol=inb(io+1); /* Save current volume/mute setting */
	outb(0x00,io+1);  /* Ensure WRITE-ENABLE is LOW */
L
Linus Torvalds 已提交
123 124
	tunestat=0xffff;

125 126 127 128 129 130 131
	/*
	 * Read the shift register
	 */
	for(i=0;i<25;i++) {
		fifo=(fifo<<1)|((inb(io+1)>>7)&0x01);
		if(i<24) {
			outb(0x01,io+1);
L
Linus Torvalds 已提交
132
			tunestat&=inb(io+1);
133 134 135 136 137 138 139 140
			outb(0x00,io+1);
		}
	}

	/*
	 * Restore volume/mute setting
	 */
	outb(curvol,io+1);
L
Linus Torvalds 已提交
141 142 143 144 145
	spin_unlock(&cadet_io_lock);

	return fifo;
}

146 147
static unsigned
cadet_getfreq(void)
L
Linus Torvalds 已提交
148
{
149 150
	int i;
	unsigned freq=0,test,fifo=0;
L
Linus Torvalds 已提交
151 152 153 154 155 156

	/*
	 * Read current tuning
	 */
	fifo=cadet_gettune();

157 158 159
	/*
	 * Convert to actual frequency
	 */
L
Linus Torvalds 已提交
160
	if(curtuner==0) {    /* FM */
161 162 163 164 165 166 167 168 169 170
		test=12500;
		for(i=0;i<14;i++) {
			if((fifo&0x01)!=0) {
				freq+=test;
			}
			test=test<<1;
			fifo=fifo>>1;
		}
		freq-=10700000;           /* IF frequency is 10.7 MHz */
		freq=(freq*16)/1000000;   /* Make it 1/16 MHz */
L
Linus Torvalds 已提交
171 172
	}
	if(curtuner==1) {    /* AM */
173
		freq=((fifo&0x7fff)-2010)*16;
L
Linus Torvalds 已提交
174 175
	}

176
	return freq;
L
Linus Torvalds 已提交
177 178
}

179 180
static void
cadet_settune(unsigned fifo)
L
Linus Torvalds 已提交
181
{
182 183
	int i;
	unsigned test;
L
Linus Torvalds 已提交
184 185

	spin_lock(&cadet_io_lock);
186

L
Linus Torvalds 已提交
187 188 189 190 191 192 193 194 195 196
	outb(7,io);                /* Select tuner control */
	/*
	 * Write the shift register
	 */
	test=0;
	test=(fifo>>23)&0x02;      /* Align data for SDO */
	test|=0x1c;                /* SDM=1, SWE=1, SEN=1, SCK=0 */
	outb(7,io);                /* Select tuner control */
	outb(test,io+1);           /* Initialize for write */
	for(i=0;i<25;i++) {
197
		test|=0x01;              /* Toggle SCK High */
L
Linus Torvalds 已提交
198 199 200 201 202 203 204 205 206 207
		outb(test,io+1);
		test&=0xfe;              /* Toggle SCK Low */
		outb(test,io+1);
		fifo=fifo<<1;            /* Prepare the next bit */
		test=0x1c|((fifo>>23)&0x02);
		outb(test,io+1);
	}
	spin_unlock(&cadet_io_lock);
}

208 209
static void
cadet_setfreq(unsigned freq)
L
Linus Torvalds 已提交
210
{
211 212 213
	unsigned fifo;
	int i,j,test;
	int curvol;
L
Linus Torvalds 已提交
214

215 216 217
	/*
	 * Formulate a fifo command
	 */
L
Linus Torvalds 已提交
218 219
	fifo=0;
	if(curtuner==0) {    /* FM */
220 221 222 223 224 225 226 227 228 229 230
		test=102400;
		freq=(freq*1000)/16;       /* Make it kHz */
		freq+=10700;               /* IF is 10700 kHz */
		for(i=0;i<14;i++) {
			fifo=fifo<<1;
			if(freq>=test) {
				fifo|=0x01;
				freq-=test;
			}
			test=test>>1;
		}
L
Linus Torvalds 已提交
231 232
	}
	if(curtuner==1) {    /* AM */
233
		fifo=(freq/16)+2010;            /* Make it kHz */
L
Linus Torvalds 已提交
234 235 236
		fifo|=0x100000;            /* Select AM Band */
	}

237 238 239
	/*
	 * Save current volume/mute setting
	 */
L
Linus Torvalds 已提交
240 241 242

	spin_lock(&cadet_io_lock);
	outb(7,io);                /* Select tuner control */
243 244
	curvol=inb(io+1);
	spin_unlock(&cadet_io_lock);
L
Linus Torvalds 已提交
245 246 247 248 249

	/*
	 * Tune the card
	 */
	for(j=3;j>-1;j--) {
250 251 252
		cadet_settune(fifo|(j<<16));

		spin_lock(&cadet_io_lock);
L
Linus Torvalds 已提交
253 254 255
		outb(7,io);         /* Select tuner control */
		outb(curvol,io+1);
		spin_unlock(&cadet_io_lock);
256

L
Linus Torvalds 已提交
257 258 259 260
		msleep(100);

		cadet_gettune();
		if((tunestat & 0x40) == 0) {   /* Tuned */
261
			sigstrength=sigtable[curtuner][j];
L
Linus Torvalds 已提交
262 263 264 265 266 267 268
			return;
		}
	}
	sigstrength=0;
}


269 270
static int
cadet_getvol(void)
L
Linus Torvalds 已提交
271 272
{
	int ret = 0;
273

L
Linus Torvalds 已提交
274
	spin_lock(&cadet_io_lock);
275 276 277 278 279 280 281

	outb(7,io);                /* Select tuner control */
	if((inb(io + 1) & 0x20) != 0)
		ret = 0xffff;

	spin_unlock(&cadet_io_lock);
	return ret;
L
Linus Torvalds 已提交
282 283 284
}


285 286
static void
cadet_setvol(int vol)
L
Linus Torvalds 已提交
287 288
{
	spin_lock(&cadet_io_lock);
289 290 291 292 293
	outb(7,io);                /* Select tuner control */
	if(vol>0)
		outb(0x20,io+1);
	else
		outb(0x00,io+1);
L
Linus Torvalds 已提交
294
	spin_unlock(&cadet_io_lock);
295
}
L
Linus Torvalds 已提交
296

297 298
static void
cadet_handler(unsigned long data)
L
Linus Torvalds 已提交
299 300 301 302 303 304 305
{
	/*
	 * Service the RDS fifo
	 */

	if(spin_trylock(&cadet_io_lock))
	{
306
		outb(0x3,io);       /* Select RDS Decoder Control */
L
Linus Torvalds 已提交
307
		if((inb(io+1)&0x20)!=0) {
308
			printk(KERN_CRIT "cadet: RDS fifo overflow\n");
L
Linus Torvalds 已提交
309 310 311
		}
		outb(0x80,io);      /* Select RDS fifo */
		while((inb(io)&0x80)!=0) {
312
			rdsbuf[rdsin]=inb(io+1);
L
Linus Torvalds 已提交
313
			if(rdsin==rdsout)
314
				printk(KERN_WARNING "cadet: RDS buffer overflow\n");
L
Linus Torvalds 已提交
315 316 317 318 319 320 321 322 323 324
			else
				rdsin++;
		}
		spin_unlock(&cadet_io_lock);
	}

	/*
	 * Service pending read
	 */
	if( rdsin!=rdsout)
325
		wake_up_interruptible(&read_queue);
L
Linus Torvalds 已提交
326

327
	/*
L
Linus Torvalds 已提交
328 329 330 331 332
	 * Clean up and exit
	 */
	init_timer(&readtimer);
	readtimer.function=cadet_handler;
	readtimer.data=(unsigned long)0;
333
	readtimer.expires=jiffies+msecs_to_jiffies(50);
L
Linus Torvalds 已提交
334 335 336 337 338
	add_timer(&readtimer);
}



339 340
static ssize_t
cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
L
Linus Torvalds 已提交
341
{
342
	int i=0;
L
Linus Torvalds 已提交
343 344
	unsigned char readbuf[RDS_BUFFER];

345
	if(rdsstat==0) {
L
Linus Torvalds 已提交
346
		spin_lock(&cadet_io_lock);
347
		rdsstat=1;
L
Linus Torvalds 已提交
348 349 350 351 352
		outb(0x80,io);        /* Select RDS fifo */
		spin_unlock(&cadet_io_lock);
		init_timer(&readtimer);
		readtimer.function=cadet_handler;
		readtimer.data=(unsigned long)0;
353
		readtimer.expires=jiffies+msecs_to_jiffies(50);
L
Linus Torvalds 已提交
354 355 356
		add_timer(&readtimer);
	}
	if(rdsin==rdsout) {
357 358 359 360
		if (file->f_flags & O_NONBLOCK)
			return -EWOULDBLOCK;
		interruptible_sleep_on(&read_queue);
	}
L
Linus Torvalds 已提交
361
	while( i<count && rdsin!=rdsout)
362
		readbuf[i++]=rdsbuf[rdsout++];
L
Linus Torvalds 已提交
363 364

	if (copy_to_user(data,readbuf,i))
365
		return -EFAULT;
L
Linus Torvalds 已提交
366 367 368 369
	return i;
}


370 371 372 373 374 375 376 377 378 379 380
static int vidioc_querycap(struct file *file, void *priv,
				struct v4l2_capability *v)
{
	v->capabilities =
		V4L2_CAP_TUNER |
		V4L2_CAP_READWRITE;
	v->version = CADET_VERSION;
	strcpy(v->driver, "ADS Cadet");
	strcpy(v->card, "ADS Cadet");
	return 0;
}
L
Linus Torvalds 已提交
381

382 383
static int vidioc_g_tuner(struct file *file, void *priv,
				struct v4l2_tuner *v)
L
Linus Torvalds 已提交
384
{
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
	v->type = V4L2_TUNER_RADIO;
	switch (v->index) {
	case 0:
		strcpy(v->name, "FM");
		v->capability = V4L2_TUNER_CAP_STEREO;
		v->rangelow = 1400;     /* 87.5 MHz */
		v->rangehigh = 1728;    /* 108.0 MHz */
		v->rxsubchans=cadet_getstereo();
		switch (v->rxsubchans){
		case V4L2_TUNER_SUB_MONO:
			v->audmode = V4L2_TUNER_MODE_MONO;
			break;
		case V4L2_TUNER_SUB_STEREO:
			v->audmode = V4L2_TUNER_MODE_STEREO;
			break;
		default: ;
L
Linus Torvalds 已提交
401
		}
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
		break;
	case 1:
		strcpy(v->name, "AM");
		v->capability = V4L2_TUNER_CAP_LOW;
		v->rangelow = 8320;      /* 520 kHz */
		v->rangehigh = 26400;    /* 1650 kHz */
		v->rxsubchans = V4L2_TUNER_SUB_MONO;
		v->audmode = V4L2_TUNER_MODE_MONO;
		break;
	default:
		return -EINVAL;
	}
	v->signal = sigstrength; /* We might need to modify scaling of this */
	return 0;
}
417

418 419 420 421 422 423 424 425
static int vidioc_s_tuner(struct file *file, void *priv,
				struct v4l2_tuner *v)
{
	if((v->index != 0)&&(v->index != 1))
		return -EINVAL;
	curtuner = v->index;
	return 0;
}
426

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
static int vidioc_g_frequency(struct file *file, void *priv,
				struct v4l2_frequency *f)
{
	f->tuner = curtuner;
	f->type = V4L2_TUNER_RADIO;
	f->frequency = cadet_getfreq();
	return 0;
}


static int vidioc_s_frequency(struct file *file, void *priv,
				struct v4l2_frequency *f)
{
	if (f->type != V4L2_TUNER_RADIO)
		return -EINVAL;
	if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728)))
		return -EINVAL;
	if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400)))
		return -EINVAL;
	cadet_setfreq(f->frequency);
	return 0;
}

static int vidioc_queryctrl(struct file *file, void *priv,
				struct v4l2_queryctrl *qc)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
		if (qc->id && qc->id == radio_qctrl[i].id) {
			memcpy(qc, &(radio_qctrl[i]),
						sizeof(*qc));
L
Linus Torvalds 已提交
459 460
			return 0;
		}
461 462 463
	}
	return -EINVAL;
}
464

465 466 467 468 469 470 471 472 473 474 475 476
static int vidioc_g_ctrl(struct file *file, void *priv,
				struct v4l2_control *ctrl)
{
	switch (ctrl->id){
	case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
		ctrl->value = (cadet_getvol() == 0);
		break;
	case V4L2_CID_AUDIO_VOLUME:
		ctrl->value = cadet_getvol();
		break;
	default:
		return -EINVAL;
L
Linus Torvalds 已提交
477
	}
478
	return 0;
L
Linus Torvalds 已提交
479 480
}

481 482
static int vidioc_s_ctrl(struct file *file, void *priv,
				struct v4l2_control *ctrl)
L
Linus Torvalds 已提交
483
{
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
	switch (ctrl->id){
	case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
		if (ctrl->value)
			cadet_setvol(0);
		else
			cadet_setvol(0xffff);
		break;
	case V4L2_CID_AUDIO_VOLUME:
		cadet_setvol(ctrl->value);
		break;
	default:
		return -EINVAL;
	}
	return 0;
}

static int vidioc_g_audio(struct file *file, void *priv,
				struct v4l2_audio *a)
{
	if (a->index > 1)
		return -EINVAL;
	strcpy(a->name, "Radio");
	a->capability = V4L2_AUDCAP_STEREO;
	return 0;
}

static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
{
	*i = 0;
	return 0;
}

static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
{
	if (i != 0)
		return -EINVAL;
	return 0;
}

static int vidioc_s_audio(struct file *file, void *priv,
				struct v4l2_audio *a)
{
	if (a->index != 0)
		return -EINVAL;
	return 0;
L
Linus Torvalds 已提交
529 530
}

531 532
static int
cadet_open(struct inode *inode, struct file *file)
L
Linus Torvalds 已提交
533 534
{
	users++;
535
	if (1 == users) init_waitqueue_head(&read_queue);
L
Linus Torvalds 已提交
536 537 538
	return 0;
}

539 540
static int
cadet_release(struct inode *inode, struct file *file)
L
Linus Torvalds 已提交
541 542
{
	users--;
543 544 545 546 547 548 549 550 551 552 553 554 555
	if (0 == users){
		del_timer_sync(&readtimer);
		rdsstat=0;
	}
	return 0;
}

static unsigned int
cadet_poll(struct file *file, struct poll_table_struct *wait)
{
	poll_wait(file,&read_queue,wait);
	if(rdsin != rdsout)
		return POLLIN | POLLRDNORM;
L
Linus Torvalds 已提交
556 557 558 559
	return 0;
}


560
static const struct file_operations cadet_fops = {
L
Linus Torvalds 已提交
561 562 563 564
	.owner		= THIS_MODULE,
	.open		= cadet_open,
	.release       	= cadet_release,
	.read		= cadet_read,
565
	.ioctl		= video_ioctl2,
566
	.poll		= cadet_poll,
567
#ifdef CONFIG_COMPAT
568
	.compat_ioctl	= v4l_compat_ioctl32,
569
#endif
L
Linus Torvalds 已提交
570 571 572
	.llseek         = no_llseek,
};

573
static const struct v4l2_ioctl_ops cadet_ioctl_ops = {
574 575 576 577 578 579 580 581 582 583 584 585
	.vidioc_querycap    = vidioc_querycap,
	.vidioc_g_tuner     = vidioc_g_tuner,
	.vidioc_s_tuner     = vidioc_s_tuner,
	.vidioc_g_frequency = vidioc_g_frequency,
	.vidioc_s_frequency = vidioc_s_frequency,
	.vidioc_queryctrl   = vidioc_queryctrl,
	.vidioc_g_ctrl      = vidioc_g_ctrl,
	.vidioc_s_ctrl      = vidioc_s_ctrl,
	.vidioc_g_audio     = vidioc_g_audio,
	.vidioc_s_audio     = vidioc_s_audio,
	.vidioc_g_input     = vidioc_g_input,
	.vidioc_s_input     = vidioc_s_input,
L
Linus Torvalds 已提交
586 587
};

588 589 590 591
static struct video_device cadet_radio = {
	.name		= "Cadet radio",
	.fops           = &cadet_fops,
	.ioctl_ops 	= &cadet_ioctl_ops,
592
	.release	= video_device_release_empty,
593 594
};

595 596
#ifdef CONFIG_PNP

L
Linus Torvalds 已提交
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
static struct pnp_device_id cadet_pnp_devices[] = {
	/* ADS Cadet AM/FM Radio Card */
	{.id = "MSM0c24", .driver_data = 0},
	{.id = ""}
};

MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices);

static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
{
	if (!dev)
		return -ENODEV;
	/* only support one device */
	if (io > 0)
		return -EBUSY;

	if (!pnp_port_valid(dev, 0)) {
		return -ENODEV;
	}

	io = pnp_port_start(dev, 0);

	printk ("radio-cadet: PnP reports device at %#x\n", io);

	return io;
}

static struct pnp_driver cadet_pnp_driver = {
	.name		= "radio-cadet",
	.id_table	= cadet_pnp_devices,
	.probe		= cadet_pnp_probe,
	.remove		= NULL,
};

631 632 633 634
#else
static struct pnp_driver cadet_pnp_driver;
#endif

L
Linus Torvalds 已提交
635 636
static int cadet_probe(void)
{
637
	static int iovals[8]={0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e};
L
Linus Torvalds 已提交
638 639 640
	int i;

	for(i=0;i<8;i++) {
641
		io=iovals[i];
642
		if (request_region(io, 2, "cadet-probe")) {
643
			cadet_setfreq(1410);
L
Linus Torvalds 已提交
644 645
			if(cadet_getfreq()==1410) {
				release_region(io, 2);
646
				return io;
L
Linus Torvalds 已提交
647 648 649 650 651 652 653
			}
			release_region(io, 2);
		}
	}
	return -1;
}

654
/*
L
Linus Torvalds 已提交
655 656 657 658 659 660 661
 * io should only be set if the user has used something like
 * isapnp (the userspace program) to initialize this card for us
 */

static int __init cadet_init(void)
{
	spin_lock_init(&cadet_io_lock);
662

L
Linus Torvalds 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676
	/*
	 *	If a probe was requested then probe ISAPnP first (safest)
	 */
	if (io < 0)
		pnp_register_driver(&cadet_pnp_driver);
	/*
	 *	If that fails then probe unsafely if probe is requested
	 */
	if(io < 0)
		io = cadet_probe ();

	/*
	 *	Else we bail out
	 */
677 678 679

	if(io < 0) {
#ifdef MODULE
L
Linus Torvalds 已提交
680 681
		printk(KERN_ERR "You must set an I/O address with io=0x???\n");
#endif
682
		goto fail;
L
Linus Torvalds 已提交
683 684 685
	}
	if (!request_region(io,2,"cadet"))
		goto fail;
686
	if (video_register_device(&cadet_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
L
Linus Torvalds 已提交
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
		release_region(io,2);
		goto fail;
	}
	printk(KERN_INFO "ADS Cadet Radio Card at 0x%x\n",io);
	return 0;
fail:
	pnp_unregister_driver(&cadet_pnp_driver);
	return -1;
}



MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");
MODULE_LICENSE("GPL");

module_param(io, int, 0);
MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)");
module_param(radio_nr, int, 0);

static void __exit cadet_cleanup_module(void)
{
	video_unregister_device(&cadet_radio);
	release_region(io,2);
	pnp_unregister_driver(&cadet_pnp_driver);
}

module_init(cadet_init);
module_exit(cadet_cleanup_module);