Commit bec2aec5 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (10882): radio-cadet: convert to v4l2_device.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent e697e12e
...@@ -35,333 +35,319 @@ ...@@ -35,333 +35,319 @@
#include <linux/init.h> /* Initdata */ #include <linux/init.h> /* Initdata */
#include <linux/ioport.h> /* request_region */ #include <linux/ioport.h> /* request_region */
#include <linux/delay.h> /* udelay */ #include <linux/delay.h> /* udelay */
#include <asm/io.h> /* outb, outb_p */
#include <asm/uaccess.h> /* copy to/from user */
#include <linux/videodev2.h> /* V4L2 API defs */ #include <linux/videodev2.h> /* V4L2 API defs */
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include <linux/param.h> #include <linux/param.h>
#include <linux/pnp.h> #include <linux/pnp.h>
#include <linux/io.h> /* outb, outb_p */
#include <linux/uaccess.h> /* copy to/from user */
#include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h>
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");
static int io = -1; /* default to isapnp activation */
static int radio_nr = -1;
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);
#define CADET_VERSION KERNEL_VERSION(0, 3, 3)
#define RDS_BUFFER 256 #define RDS_BUFFER 256
#define RDS_RX_FLAG 1 #define RDS_RX_FLAG 1
#define MBS_RX_FLAG 2 #define MBS_RX_FLAG 2
#define CADET_VERSION KERNEL_VERSION(0,3,3) struct cadet {
struct v4l2_device v4l2_dev;
static struct v4l2_queryctrl radio_qctrl[] = { struct video_device vdev;
{ int io;
.id = V4L2_CID_AUDIO_MUTE, int users;
.name = "Mute", int curtuner;
.minimum = 0, int tunestat;
.maximum = 1, int sigstrength;
.default_value = 1, wait_queue_head_t read_queue;
.type = V4L2_CTRL_TYPE_BOOLEAN, struct timer_list readtimer;
},{ __u8 rdsin, rdsout, rdsstat;
.id = V4L2_CID_AUDIO_VOLUME, unsigned char rdsbuf[RDS_BUFFER];
.name = "Volume", struct mutex lock;
.minimum = 0, int reading;
.maximum = 0xff,
.step = 1,
.default_value = 0xff,
.type = V4L2_CTRL_TYPE_INTEGER,
}
}; };
static int io=-1; /* default to isapnp activation */ static struct cadet cadet_card;
static int radio_nr = -1;
static int users;
static int curtuner;
static int tunestat;
static int sigstrength;
static wait_queue_head_t read_queue;
static struct timer_list readtimer;
static __u8 rdsin, rdsout, rdsstat;
static unsigned char rdsbuf[RDS_BUFFER];
static spinlock_t cadet_io_lock;
static int cadet_probe(void);
/* /*
* Signal Strength Threshold Values * Signal Strength Threshold Values
* The V4L API spec does not define any particular unit for the signal * The V4L API spec does not define any particular unit for the signal
* strength value. These values are in microvolts of RF at the tuner's input. * 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}}; static __u16 sigtable[2][4] = {
{ 5, 10, 30, 150 },
{ 28, 40, 63, 1000 }
};
static int static int cadet_getstereo(struct cadet *dev)
cadet_getstereo(void)
{ {
int ret = V4L2_TUNER_SUB_MONO; int ret = V4L2_TUNER_SUB_MONO;
if(curtuner != 0) /* Only FM has stereo capability! */
if (dev->curtuner != 0) /* Only FM has stereo capability! */
return V4L2_TUNER_SUB_MONO; return V4L2_TUNER_SUB_MONO;
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
if( (inb(io+1) & 0x40) == 0) if ((inb(dev->io + 1) & 0x40) == 0)
ret = V4L2_TUNER_SUB_STEREO; ret = V4L2_TUNER_SUB_STEREO;
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
return ret; return ret;
} }
static unsigned static unsigned cadet_gettune(struct cadet *dev)
cadet_gettune(void)
{ {
int curvol,i; int curvol, i;
unsigned fifo=0; unsigned fifo = 0;
/* /*
* Prepare for read * Prepare for read
*/ */
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
curvol=inb(io+1); /* Save current volume/mute setting */ curvol = inb(dev->io + 1); /* Save current volume/mute setting */
outb(0x00,io+1); /* Ensure WRITE-ENABLE is LOW */ outb(0x00, dev->io + 1); /* Ensure WRITE-ENABLE is LOW */
tunestat=0xffff; dev->tunestat = 0xffff;
/* /*
* Read the shift register * Read the shift register
*/ */
for(i=0;i<25;i++) { for (i = 0; i < 25; i++) {
fifo=(fifo<<1)|((inb(io+1)>>7)&0x01); fifo = (fifo << 1) | ((inb(dev->io + 1) >> 7) & 0x01);
if(i<24) { if (i < 24) {
outb(0x01,io+1); outb(0x01, dev->io + 1);
tunestat&=inb(io+1); dev->tunestat &= inb(dev->io + 1);
outb(0x00,io+1); outb(0x00, dev->io + 1);
} }
} }
/* /*
* Restore volume/mute setting * Restore volume/mute setting
*/ */
outb(curvol,io+1); outb(curvol, dev->io + 1);
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
return fifo; return fifo;
} }
static unsigned static unsigned cadet_getfreq(struct cadet *dev)
cadet_getfreq(void)
{ {
int i; int i;
unsigned freq=0,test,fifo=0; unsigned freq = 0, test, fifo = 0;
/* /*
* Read current tuning * Read current tuning
*/ */
fifo=cadet_gettune(); fifo = cadet_gettune(dev);
/* /*
* Convert to actual frequency * Convert to actual frequency
*/ */
if(curtuner==0) { /* FM */ if (dev->curtuner == 0) { /* FM */
test=12500; test = 12500;
for(i=0;i<14;i++) { for (i = 0; i < 14; i++) {
if((fifo&0x01)!=0) { if ((fifo & 0x01) != 0)
freq+=test; freq += test;
} test = test << 1;
test=test<<1; fifo = fifo >> 1;
fifo=fifo>>1;
} }
freq-=10700000; /* IF frequency is 10.7 MHz */ freq -= 10700000; /* IF frequency is 10.7 MHz */
freq=(freq*16)/1000000; /* Make it 1/16 MHz */ freq = (freq * 16) / 1000000; /* Make it 1/16 MHz */
}
if(curtuner==1) { /* AM */
freq=((fifo&0x7fff)-2010)*16;
} }
if (dev->curtuner == 1) /* AM */
freq = ((fifo & 0x7fff) - 2010) * 16;
return freq; return freq;
} }
static void static void cadet_settune(struct cadet *dev, unsigned fifo)
cadet_settune(unsigned fifo)
{ {
int i; int i;
unsigned test; unsigned test;
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
/* /*
* Write the shift register * Write the shift register
*/ */
test=0; test = 0;
test=(fifo>>23)&0x02; /* Align data for SDO */ test = (fifo >> 23) & 0x02; /* Align data for SDO */
test|=0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */ test |= 0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
outb(test,io+1); /* Initialize for write */ outb(test, dev->io + 1); /* Initialize for write */
for(i=0;i<25;i++) { for (i = 0; i < 25; i++) {
test|=0x01; /* Toggle SCK High */ test |= 0x01; /* Toggle SCK High */
outb(test,io+1); outb(test, dev->io + 1);
test&=0xfe; /* Toggle SCK Low */ test &= 0xfe; /* Toggle SCK Low */
outb(test,io+1); outb(test, dev->io + 1);
fifo=fifo<<1; /* Prepare the next bit */ fifo = fifo << 1; /* Prepare the next bit */
test=0x1c|((fifo>>23)&0x02); test = 0x1c | ((fifo >> 23) & 0x02);
outb(test,io+1); outb(test, dev->io + 1);
} }
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
} }
static void static void cadet_setfreq(struct cadet *dev, unsigned freq)
cadet_setfreq(unsigned freq)
{ {
unsigned fifo; unsigned fifo;
int i,j,test; int i, j, test;
int curvol; int curvol;
/* /*
* Formulate a fifo command * Formulate a fifo command
*/ */
fifo=0; fifo = 0;
if(curtuner==0) { /* FM */ if (dev->curtuner == 0) { /* FM */
test=102400; test = 102400;
freq=(freq*1000)/16; /* Make it kHz */ freq = (freq * 1000) / 16; /* Make it kHz */
freq+=10700; /* IF is 10700 kHz */ freq += 10700; /* IF is 10700 kHz */
for(i=0;i<14;i++) { for (i = 0; i < 14; i++) {
fifo=fifo<<1; fifo = fifo << 1;
if(freq>=test) { if (freq >= test) {
fifo|=0x01; fifo |= 0x01;
freq-=test; freq -= test;
} }
test=test>>1; test = test >> 1;
} }
} }
if(curtuner==1) { /* AM */ if (dev->curtuner == 1) { /* AM */
fifo=(freq/16)+2010; /* Make it kHz */ fifo = (freq / 16) + 2010; /* Make it kHz */
fifo|=0x100000; /* Select AM Band */ fifo |= 0x100000; /* Select AM Band */
} }
/* /*
* Save current volume/mute setting * Save current volume/mute setting
*/ */
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
curvol=inb(io+1); curvol = inb(dev->io + 1);
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
/* /*
* Tune the card * Tune the card
*/ */
for(j=3;j>-1;j--) { for (j = 3; j > -1; j--) {
cadet_settune(fifo|(j<<16)); cadet_settune(dev, fifo | (j << 16));
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
outb(curvol,io+1); outb(curvol, dev->io + 1);
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
msleep(100); msleep(100);
cadet_gettune(); cadet_gettune(dev);
if((tunestat & 0x40) == 0) { /* Tuned */ if ((dev->tunestat & 0x40) == 0) { /* Tuned */
sigstrength=sigtable[curtuner][j]; dev->sigstrength = sigtable[dev->curtuner][j];
return; return;
} }
} }
sigstrength=0; dev->sigstrength = 0;
} }
static int static int cadet_getvol(struct cadet *dev)
cadet_getvol(void)
{ {
int ret = 0; int ret = 0;
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
if((inb(io + 1) & 0x20) != 0) if ((inb(dev->io + 1) & 0x20) != 0)
ret = 0xffff; ret = 0xffff;
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
return ret; return ret;
} }
static void static void cadet_setvol(struct cadet *dev, int vol)
cadet_setvol(int vol)
{ {
spin_lock(&cadet_io_lock); mutex_lock(&dev->lock);
outb(7,io); /* Select tuner control */ outb(7, dev->io); /* Select tuner control */
if(vol>0) if (vol > 0)
outb(0x20,io+1); outb(0x20, dev->io + 1);
else else
outb(0x00,io+1); outb(0x00, dev->io + 1);
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
} }
static void static void cadet_handler(unsigned long data)
cadet_handler(unsigned long data)
{ {
/* struct cadet *dev = (void *)data;
* Service the RDS fifo
*/
if(spin_trylock(&cadet_io_lock)) /* Service the RDS fifo */
{ if (mutex_trylock(&dev->lock)) {
outb(0x3,io); /* Select RDS Decoder Control */ outb(0x3, dev->io); /* Select RDS Decoder Control */
if((inb(io+1)&0x20)!=0) { if ((inb(dev->io + 1) & 0x20) != 0)
printk(KERN_CRIT "cadet: RDS fifo overflow\n"); printk(KERN_CRIT "cadet: RDS fifo overflow\n");
} outb(0x80, dev->io); /* Select RDS fifo */
outb(0x80,io); /* Select RDS fifo */ while ((inb(dev->io) & 0x80) != 0) {
while((inb(io)&0x80)!=0) { dev->rdsbuf[dev->rdsin] = inb(dev->io + 1);
rdsbuf[rdsin]=inb(io+1); if (dev->rdsin == dev->rdsout)
if(rdsin==rdsout)
printk(KERN_WARNING "cadet: RDS buffer overflow\n"); printk(KERN_WARNING "cadet: RDS buffer overflow\n");
else else
rdsin++; dev->rdsin++;
} }
spin_unlock(&cadet_io_lock); mutex_unlock(&dev->lock);
} }
/* /*
* Service pending read * Service pending read
*/ */
if( rdsin!=rdsout) if (dev->rdsin != dev->rdsout)
wake_up_interruptible(&read_queue); wake_up_interruptible(&dev->read_queue);
/* /*
* Clean up and exit * Clean up and exit
*/ */
init_timer(&readtimer); init_timer(&dev->readtimer);
readtimer.function=cadet_handler; dev->readtimer.function = cadet_handler;
readtimer.data=(unsigned long)0; dev->readtimer.data = (unsigned long)0;
readtimer.expires=jiffies+msecs_to_jiffies(50); dev->readtimer.expires = jiffies + msecs_to_jiffies(50);
add_timer(&readtimer); add_timer(&dev->readtimer);
} }
static ssize_t cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
static ssize_t
cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
{ {
int i=0; struct cadet *dev = video_drvdata(file);
unsigned char readbuf[RDS_BUFFER]; unsigned char readbuf[RDS_BUFFER];
int i = 0;
if(rdsstat==0) {
spin_lock(&cadet_io_lock); if (dev->rdsstat == 0) {
rdsstat=1; mutex_lock(&dev->lock);
outb(0x80,io); /* Select RDS fifo */ dev->rdsstat = 1;
spin_unlock(&cadet_io_lock); outb(0x80, dev->io); /* Select RDS fifo */
init_timer(&readtimer); mutex_unlock(&dev->lock);
readtimer.function=cadet_handler; init_timer(&dev->readtimer);
readtimer.data=(unsigned long)0; dev->readtimer.function = cadet_handler;
readtimer.expires=jiffies+msecs_to_jiffies(50); dev->readtimer.data = (unsigned long)dev;
add_timer(&readtimer); dev->readtimer.expires = jiffies + msecs_to_jiffies(50);
} add_timer(&dev->readtimer);
if(rdsin==rdsout) { }
if (dev->rdsin == dev->rdsout) {
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return -EWOULDBLOCK; return -EWOULDBLOCK;
interruptible_sleep_on(&read_queue); interruptible_sleep_on(&dev->read_queue);
} }
while( i<count && rdsin!=rdsout) while (i < count && dev->rdsin != dev->rdsout)
readbuf[i++]=rdsbuf[rdsout++]; readbuf[i++] = dev->rdsbuf[dev->rdsout++];
if (copy_to_user(data,readbuf,i)) if (copy_to_user(data, readbuf, i))
return -EFAULT; return -EFAULT;
return i; return i;
} }
...@@ -370,38 +356,40 @@ cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos) ...@@ -370,38 +356,40 @@ cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
static int vidioc_querycap(struct file *file, void *priv, static int vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *v) struct v4l2_capability *v)
{ {
v->capabilities = strlcpy(v->driver, "ADS Cadet", sizeof(v->driver));
V4L2_CAP_TUNER | strlcpy(v->card, "ADS Cadet", sizeof(v->card));
V4L2_CAP_READWRITE; strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
v->version = CADET_VERSION; v->version = CADET_VERSION;
strcpy(v->driver, "ADS Cadet"); v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_READWRITE;
strcpy(v->card, "ADS Cadet");
return 0; return 0;
} }
static int vidioc_g_tuner(struct file *file, void *priv, static int vidioc_g_tuner(struct file *file, void *priv,
struct v4l2_tuner *v) struct v4l2_tuner *v)
{ {
struct cadet *dev = video_drvdata(file);
v->type = V4L2_TUNER_RADIO; v->type = V4L2_TUNER_RADIO;
switch (v->index) { switch (v->index) {
case 0: case 0:
strcpy(v->name, "FM"); strlcpy(v->name, "FM", sizeof(v->name));
v->capability = V4L2_TUNER_CAP_STEREO; v->capability = V4L2_TUNER_CAP_STEREO;
v->rangelow = 1400; /* 87.5 MHz */ v->rangelow = 1400; /* 87.5 MHz */
v->rangehigh = 1728; /* 108.0 MHz */ v->rangehigh = 1728; /* 108.0 MHz */
v->rxsubchans=cadet_getstereo(); v->rxsubchans = cadet_getstereo(dev);
switch (v->rxsubchans){ switch (v->rxsubchans) {
case V4L2_TUNER_SUB_MONO: case V4L2_TUNER_SUB_MONO:
v->audmode = V4L2_TUNER_MODE_MONO; v->audmode = V4L2_TUNER_MODE_MONO;
break; break;
case V4L2_TUNER_SUB_STEREO: case V4L2_TUNER_SUB_STEREO:
v->audmode = V4L2_TUNER_MODE_STEREO; v->audmode = V4L2_TUNER_MODE_STEREO;
break; break;
default: ; default:
break;
} }
break; break;
case 1: case 1:
strcpy(v->name, "AM"); strlcpy(v->name, "AM", sizeof(v->name));
v->capability = V4L2_TUNER_CAP_LOW; v->capability = V4L2_TUNER_CAP_LOW;
v->rangelow = 8320; /* 520 kHz */ v->rangelow = 8320; /* 520 kHz */
v->rangehigh = 26400; /* 1650 kHz */ v->rangehigh = 26400; /* 1650 kHz */
...@@ -411,25 +399,29 @@ static int vidioc_g_tuner(struct file *file, void *priv, ...@@ -411,25 +399,29 @@ static int vidioc_g_tuner(struct file *file, void *priv,
default: default:
return -EINVAL; return -EINVAL;
} }
v->signal = sigstrength; /* We might need to modify scaling of this */ v->signal = dev->sigstrength; /* We might need to modify scaling of this */
return 0; return 0;
} }
static int vidioc_s_tuner(struct file *file, void *priv, static int vidioc_s_tuner(struct file *file, void *priv,
struct v4l2_tuner *v) struct v4l2_tuner *v)
{ {
if((v->index != 0)&&(v->index != 1)) struct cadet *dev = video_drvdata(file);
if (v->index != 0 && v->index != 1)
return -EINVAL; return -EINVAL;
curtuner = v->index; dev->curtuner = v->index;
return 0; return 0;
} }
static int vidioc_g_frequency(struct file *file, void *priv, static int vidioc_g_frequency(struct file *file, void *priv,
struct v4l2_frequency *f) struct v4l2_frequency *f)
{ {
f->tuner = curtuner; struct cadet *dev = video_drvdata(file);
f->tuner = dev->curtuner;
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = cadet_getfreq(); f->frequency = cadet_getfreq(dev);
return 0; return 0;
} }
...@@ -437,27 +429,26 @@ static int vidioc_g_frequency(struct file *file, void *priv, ...@@ -437,27 +429,26 @@ static int vidioc_g_frequency(struct file *file, void *priv,
static int vidioc_s_frequency(struct file *file, void *priv, static int vidioc_s_frequency(struct file *file, void *priv,
struct v4l2_frequency *f) struct v4l2_frequency *f)
{ {
struct cadet *dev = video_drvdata(file);
if (f->type != V4L2_TUNER_RADIO) if (f->type != V4L2_TUNER_RADIO)
return -EINVAL; return -EINVAL;
if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728))) if (dev->curtuner == 0 && (f->frequency < 1400 || f->frequency > 1728))
return -EINVAL; return -EINVAL;
if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400))) if (dev->curtuner == 1 && (f->frequency < 8320 || f->frequency > 26400))
return -EINVAL; return -EINVAL;
cadet_setfreq(f->frequency); cadet_setfreq(dev, f->frequency);
return 0; return 0;
} }
static int vidioc_queryctrl(struct file *file, void *priv, static int vidioc_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *qc) struct v4l2_queryctrl *qc)
{ {
int i; switch (qc->id) {
case V4L2_CID_AUDIO_MUTE:
for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
if (qc->id && qc->id == radio_qctrl[i].id) { case V4L2_CID_AUDIO_VOLUME:
memcpy(qc, &(radio_qctrl[i]), return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
sizeof(*qc));
return 0;
}
} }
return -EINVAL; return -EINVAL;
} }
...@@ -465,12 +456,14 @@ static int vidioc_queryctrl(struct file *file, void *priv, ...@@ -465,12 +456,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
static int vidioc_g_ctrl(struct file *file, void *priv, static int vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
switch (ctrl->id){ struct cadet *dev = video_drvdata(file);
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
ctrl->value = (cadet_getvol() == 0); ctrl->value = (cadet_getvol(dev) == 0);
break; break;
case V4L2_CID_AUDIO_VOLUME: case V4L2_CID_AUDIO_VOLUME:
ctrl->value = cadet_getvol(); ctrl->value = cadet_getvol(dev);
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -481,15 +474,17 @@ static int vidioc_g_ctrl(struct file *file, void *priv, ...@@ -481,15 +474,17 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
static int vidioc_s_ctrl(struct file *file, void *priv, static int vidioc_s_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
struct cadet *dev = video_drvdata(file);
switch (ctrl->id){ switch (ctrl->id){
case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
if (ctrl->value) if (ctrl->value)
cadet_setvol(0); cadet_setvol(dev, 0);
else else
cadet_setvol(0xffff); cadet_setvol(dev, 0xffff);
break; break;
case V4L2_CID_AUDIO_VOLUME: case V4L2_CID_AUDIO_VOLUME:
cadet_setvol(ctrl->value); cadet_setvol(dev, ctrl->value);
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -497,16 +492,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv, ...@@ -497,16 +492,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
return 0; 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) static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
{ {
*i = 0; *i = 0;
...@@ -515,43 +500,52 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) ...@@ -515,43 +500,52 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
{ {
if (i != 0) return i ? -EINVAL : 0;
return -EINVAL; }
static int vidioc_g_audio(struct file *file, void *priv,
struct v4l2_audio *a)
{
a->index = 0;
strlcpy(a->name, "Radio", sizeof(a->name));
a->capability = V4L2_AUDCAP_STEREO;
return 0; return 0;
} }
static int vidioc_s_audio(struct file *file, void *priv, static int vidioc_s_audio(struct file *file, void *priv,
struct v4l2_audio *a) struct v4l2_audio *a)
{ {
if (a->index != 0) return a->index ? -EINVAL : 0;
return -EINVAL;
return 0;
} }
static int static int cadet_open(struct file *file)
cadet_open(struct file *file)
{ {
users++; struct cadet *dev = video_drvdata(file);
if (1 == users) init_waitqueue_head(&read_queue);
dev->users++;
if (1 == dev->users)
init_waitqueue_head(&dev->read_queue);
return 0; return 0;
} }
static int static int cadet_release(struct file *file)
cadet_release(struct file *file)
{ {
users--; struct cadet *dev = video_drvdata(file);
if (0 == users){
del_timer_sync(&readtimer); dev->users--;
rdsstat=0; if (0 == dev->users) {
del_timer_sync(&dev->readtimer);
dev->rdsstat = 0;
} }
return 0; return 0;
} }
static unsigned int static unsigned int cadet_poll(struct file *file, struct poll_table_struct *wait)
cadet_poll(struct file *file, struct poll_table_struct *wait)
{ {
poll_wait(file,&read_queue,wait); struct cadet *dev = video_drvdata(file);
if(rdsin != rdsout)
poll_wait(file, &dev->read_queue, wait);
if (dev->rdsin != dev->rdsout)
return POLLIN | POLLRDNORM; return POLLIN | POLLRDNORM;
return 0; return 0;
} }
...@@ -581,13 +575,6 @@ static const struct v4l2_ioctl_ops cadet_ioctl_ops = { ...@@ -581,13 +575,6 @@ static const struct v4l2_ioctl_ops cadet_ioctl_ops = {
.vidioc_s_input = vidioc_s_input, .vidioc_s_input = vidioc_s_input,
}; };
static struct video_device cadet_radio = {
.name = "Cadet radio",
.fops = &cadet_fops,
.ioctl_ops = &cadet_ioctl_ops,
.release = video_device_release_empty,
};
#ifdef CONFIG_PNP #ifdef CONFIG_PNP
static struct pnp_device_id cadet_pnp_devices[] = { static struct pnp_device_id cadet_pnp_devices[] = {
...@@ -598,7 +585,7 @@ static struct pnp_device_id cadet_pnp_devices[] = { ...@@ -598,7 +585,7 @@ static struct pnp_device_id cadet_pnp_devices[] = {
MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices); MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices);
static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) static int cadet_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
{ {
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
...@@ -606,13 +593,12 @@ static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev ...@@ -606,13 +593,12 @@ static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev
if (io > 0) if (io > 0)
return -EBUSY; return -EBUSY;
if (!pnp_port_valid(dev, 0)) { if (!pnp_port_valid(dev, 0))
return -ENODEV; return -ENODEV;
}
io = pnp_port_start(dev, 0); io = pnp_port_start(dev, 0);
printk ("radio-cadet: PnP reports device at %#x\n", io); printk(KERN_INFO "radio-cadet: PnP reports device at %#x\n", io);
return io; return io;
} }
...@@ -628,23 +614,23 @@ static struct pnp_driver cadet_pnp_driver = { ...@@ -628,23 +614,23 @@ static struct pnp_driver cadet_pnp_driver = {
static struct pnp_driver cadet_pnp_driver; static struct pnp_driver cadet_pnp_driver;
#endif #endif
static int cadet_probe(void) static void cadet_probe(struct cadet *dev)
{ {
static int iovals[8]={0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e}; static int iovals[8] = { 0x330, 0x332, 0x334, 0x336, 0x338, 0x33a, 0x33c, 0x33e };
int i; int i;
for(i=0;i<8;i++) { for (i = 0; i < 8; i++) {
io=iovals[i]; dev->io = iovals[i];
if (request_region(io, 2, "cadet-probe")) { if (request_region(dev->io, 2, "cadet-probe")) {
cadet_setfreq(1410); cadet_setfreq(dev, 1410);
if(cadet_getfreq()==1410) { if (cadet_getfreq(dev) == 1410) {
release_region(io, 2); release_region(dev->io, 2);
return io; return;
} }
release_region(io, 2); release_region(dev->io, 2);
} }
} }
return -1; dev->io = -1;
} }
/* /*
...@@ -654,59 +640,68 @@ static int cadet_probe(void) ...@@ -654,59 +640,68 @@ static int cadet_probe(void)
static int __init cadet_init(void) static int __init cadet_init(void)
{ {
spin_lock_init(&cadet_io_lock); struct cadet *dev = &cadet_card;
struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
int res;
/* strlcpy(v4l2_dev->name, "cadet", sizeof(v4l2_dev->name));
* If a probe was requested then probe ISAPnP first (safest) mutex_init(&dev->lock);
*/
/* If a probe was requested then probe ISAPnP first (safest) */
if (io < 0) if (io < 0)
pnp_register_driver(&cadet_pnp_driver); pnp_register_driver(&cadet_pnp_driver);
/* dev->io = io;
* If that fails then probe unsafely if probe is requested
*/
if(io < 0)
io = cadet_probe ();
/* /* If that fails then probe unsafely if probe is requested */
* Else we bail out if (dev->io < 0)
*/ cadet_probe(dev);
if(io < 0) { /* Else we bail out */
if (dev->io < 0) {
#ifdef MODULE #ifdef MODULE
printk(KERN_ERR "You must set an I/O address with io=0x???\n"); v4l2_err(v4l2_dev, "you must set an I/O address with io=0x???\n");
#endif #endif
goto fail; goto fail;
} }
if (!request_region(io,2,"cadet")) if (!request_region(dev->io, 2, "cadet"))
goto fail; goto fail;
if (video_register_device(&cadet_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
release_region(io,2); res = v4l2_device_register(NULL, v4l2_dev);
if (res < 0) {
release_region(dev->io, 2);
v4l2_err(v4l2_dev, "could not register v4l2_device\n");
goto fail; goto fail;
} }
printk(KERN_INFO "ADS Cadet Radio Card at 0x%x\n",io);
strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
dev->vdev.v4l2_dev = v4l2_dev;
dev->vdev.fops = &cadet_fops;
dev->vdev.ioctl_ops = &cadet_ioctl_ops;
dev->vdev.release = video_device_release_empty;
video_set_drvdata(&dev->vdev, dev);
if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
v4l2_device_unregister(v4l2_dev);
release_region(dev->io, 2);
goto fail;
}
v4l2_info(v4l2_dev, "ADS Cadet Radio Card at 0x%x\n", dev->io);
return 0; return 0;
fail: fail:
pnp_unregister_driver(&cadet_pnp_driver); pnp_unregister_driver(&cadet_pnp_driver);
return -1; return -ENODEV;
} }
static void __exit cadet_exit(void)
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); struct cadet *dev = &cadet_card;
release_region(io,2);
video_unregister_device(&dev->vdev);
v4l2_device_unregister(&dev->v4l2_dev);
release_region(dev->io, 2);
pnp_unregister_driver(&cadet_pnp_driver); pnp_unregister_driver(&cadet_pnp_driver);
} }
module_init(cadet_init); module_init(cadet_init);
module_exit(cadet_cleanup_module); module_exit(cadet_exit);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment