Archived
14
0
Fork 0

V4L/DVB (4356): V4L2 conversion: radio-terratec

Driver conversion to V4L2 API.
Require some testing, since this obsolete hardware is not
common those days.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
This commit is contained in:
Mauro Carvalho Chehab 2006-08-08 09:10:03 -03:00
parent acda0e7185
commit 55ac7b690f
2 changed files with 112 additions and 45 deletions

View file

@ -239,7 +239,7 @@ config RADIO_SF16FMR2
config RADIO_TERRATEC config RADIO_TERRATEC
tristate "TerraTec ActiveRadio ISA Standalone" tristate "TerraTec ActiveRadio ISA Standalone"
depends on ISA && VIDEO_V4L1 depends on ISA && VIDEO_V4L2
---help--- ---help---
Choose Y here if you have this FM radio card, and then fill in the Choose Y here if you have this FM radio card, and then fill in the
port address below. (TODO) port address below. (TODO)

View file

@ -21,6 +21,7 @@
* If you can help me out with that, please contact me!! * If you can help me out with that, please contact me!!
* *
* *
* Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
*/ */
#include <linux/module.h> /* Modules */ #include <linux/module.h> /* Modules */
@ -29,10 +30,32 @@
#include <linux/delay.h> /* udelay */ #include <linux/delay.h> /* udelay */
#include <asm/io.h> /* outb, outb_p */ #include <asm/io.h> /* outb, outb_p */
#include <asm/uaccess.h> /* copy to/from user */ #include <asm/uaccess.h> /* copy to/from user */
#include <linux/videodev.h> /* kernel radio structs */ #include <linux/videodev2.h> /* kernel radio structs */
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/version.h> /* for KERNEL_VERSION MACRO */
#define RADIO_VERSION KERNEL_VERSION(0,0,2)
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,
}
};
#ifndef CONFIG_RADIO_TERRATEC_PORT #ifndef CONFIG_RADIO_TERRATEC_PORT
#define CONFIG_RADIO_TERRATEC_PORT 0x590 #define CONFIG_RADIO_TERRATEC_PORT 0x590
#endif #endif
@ -193,73 +216,117 @@ static int tt_do_ioctl(struct inode *inode, struct file *file,
switch(cmd) switch(cmd)
{ {
case VIDIOCGCAP: case VIDIOC_QUERYCAP:
{ {
struct video_capability *v = arg; struct v4l2_capability *v = arg;
memset(v,0,sizeof(*v)); memset(v,0,sizeof(*v));
v->type=VID_TYPE_TUNER; strlcpy(v->driver, "radio-terratec", sizeof (v->driver));
v->channels=1; strlcpy(v->card, "ActiveRadio", sizeof (v->card));
v->audios=1; sprintf(v->bus_info,"ISA");
strcpy(v->name, "ActiveRadio"); v->version = RADIO_VERSION;
v->capabilities = V4L2_CAP_TUNER;
return 0; return 0;
} }
case VIDIOCGTUNER: case VIDIOC_G_TUNER:
{ {
struct video_tuner *v = arg; struct v4l2_tuner *v = arg;
if(v->tuner) /* Only 1 tuner */
if (v->index > 0)
return -EINVAL; return -EINVAL;
memset(v,0,sizeof(*v));
strcpy(v->name, "FM");
v->type = V4L2_TUNER_RADIO;
v->rangelow=(87*16000); v->rangelow=(87*16000);
v->rangehigh=(108*16000); v->rangehigh=(108*16000);
v->flags=VIDEO_TUNER_LOW; v->rxsubchans =V4L2_TUNER_SUB_MONO;
v->mode=VIDEO_MODE_AUTO; v->capability=V4L2_TUNER_CAP_LOW;
strcpy(v->name, "FM"); v->audmode = V4L2_TUNER_MODE_MONO;
v->signal=0xFFFF*tt_getsigstr(tt); v->signal=0xFFFF*tt_getsigstr(tt);
return 0; return 0;
} }
case VIDIOCSTUNER: case VIDIOC_S_TUNER:
{ {
struct video_tuner *v = arg; struct v4l2_tuner *v = arg;
if(v->tuner!=0)
if (v->index > 0)
return -EINVAL; return -EINVAL;
/* Only 1 tuner so no setting needed ! */
return 0; return 0;
} }
case VIDIOCGFREQ: case VIDIOC_S_FREQUENCY:
{ {
unsigned long *freq = arg; struct v4l2_frequency *f = arg;
*freq = tt->curfreq;
return 0; tt->curfreq = f->frequency;
}
case VIDIOCSFREQ:
{
unsigned long *freq = arg;
tt->curfreq = *freq;
tt_setfreq(tt, tt->curfreq); tt_setfreq(tt, tt->curfreq);
return 0; return 0;
} }
case VIDIOCGAUDIO: case VIDIOC_G_FREQUENCY:
{ {
struct video_audio *v = arg; struct v4l2_frequency *f = arg;
memset(v,0, sizeof(*v));
v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME; f->type = V4L2_TUNER_RADIO;
v->volume=tt->curvol * 6554; f->frequency = tt->curfreq;
v->step=6554;
strcpy(v->name, "Radio");
return 0; return 0;
} }
case VIDIOCSAUDIO: case VIDIOC_QUERYCTRL:
{ {
struct video_audio *v = arg; struct v4l2_queryctrl *qc = arg;
if(v->audio) int i;
return -EINVAL;
if(v->flags&VIDEO_AUDIO_MUTE) for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
tt_mute(tt); if (qc->id && qc->id == radio_qctrl[i].id) {
else memcpy(qc, &(radio_qctrl[i]),
tt_setvol(tt,v->volume/6554); sizeof(*qc));
return 0; return (0);
}
}
return -EINVAL;
} }
case VIDIOC_G_CTRL:
{
struct v4l2_control *ctrl= arg;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
if (tt->muted)
ctrl->value=1;
else
ctrl->value=0;
return (0);
case V4L2_CID_AUDIO_VOLUME:
ctrl->value=tt->curvol * 6554;
return (0);
}
return -EINVAL;
}
case VIDIOC_S_CTRL:
{
struct v4l2_control *ctrl= arg;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
if (ctrl->value) {
tt_mute(tt);
} else {
tt_setvol(tt,tt->curvol);
}
return (0);
case V4L2_CID_AUDIO_VOLUME:
tt_setvol(tt,ctrl->value);
return (0);
}
return -EINVAL;
}
default: default:
return -ENOIOCTLCMD; return v4l_compat_translate_ioctl(inode,file,cmd,arg,
tt_do_ioctl);
} }
} }
@ -285,7 +352,7 @@ static struct video_device terratec_radio=
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "TerraTec ActiveRadio", .name = "TerraTec ActiveRadio",
.type = VID_TYPE_TUNER, .type = VID_TYPE_TUNER,
.hardware = VID_HARDWARE_TERRATEC, .hardware = 0,
.fops = &terratec_fops, .fops = &terratec_fops,
}; };