V4L/DVB (4350): V4L2 conversion: radio_gemtek-pci

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:01 -03:00
parent d1c4ecdeec
commit 52afbc2f4f
2 changed files with 113 additions and 63 deletions

View file

@ -131,7 +131,7 @@ config RADIO_GEMTEK_PORT
config RADIO_GEMTEK_PCI config RADIO_GEMTEK_PCI
tristate "GemTek PCI Radio Card support" tristate "GemTek PCI Radio Card support"
depends on VIDEO_V4L1 && PCI depends on VIDEO_V4L2 && PCI
---help--- ---help---
Choose Y here if you have this PCI FM radio card. Choose Y here if you have this PCI FM radio card.

View file

@ -34,6 +34,8 @@
* *
* TODO: multiple device support and portability were not tested * TODO: multiple device support and portability were not tested
* *
* Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
*
*************************************************************************** ***************************************************************************
*/ */
@ -42,10 +44,32 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/videodev.h> #include <linux/videodev2.h>
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <linux/errno.h> #include <linux/errno.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 = 65535,
.step = 65535,
.default_value = 0xff,
.type = V4L2_CTRL_TYPE_INTEGER,
}
};
#include <asm/io.h> #include <asm/io.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
@ -183,91 +207,117 @@ static int gemtek_pci_do_ioctl(struct inode *inode, struct file *file,
struct gemtek_pci_card *card = dev->priv; struct gemtek_pci_card *card = dev->priv;
switch ( cmd ) { switch ( cmd ) {
case VIDIOCGCAP: case VIDIOC_QUERYCAP:
{ {
struct video_capability *c = arg; struct v4l2_capability *v = arg;
memset(v,0,sizeof(*v));
strlcpy(v->driver, "radio-gemtek-pci", sizeof (v->driver));
strlcpy(v->card, "GemTek PCI Radio", sizeof (v->card));
sprintf(v->bus_info,"ISA");
v->version = RADIO_VERSION;
v->capabilities = V4L2_CAP_TUNER;
memset(c,0,sizeof(*c));
c->type = VID_TYPE_TUNER;
c->channels = 1;
c->audios = 1;
strcpy( c->name, "Gemtek PCI Radio" );
return 0; return 0;
} }
case VIDIOC_G_TUNER:
case VIDIOCGTUNER:
{ {
struct video_tuner *t = arg; struct v4l2_tuner *v = arg;
if ( t->tuner ) if (v->index > 0)
return -EINVAL; return -EINVAL;
t->rangelow = GEMTEK_PCI_RANGE_LOW; memset(v,0,sizeof(*v));
t->rangehigh = GEMTEK_PCI_RANGE_HIGH; strcpy(v->name, "FM");
t->flags = VIDEO_TUNER_LOW; v->type = V4L2_TUNER_RADIO;
t->mode = VIDEO_MODE_AUTO;
t->signal = 0xFFFF * gemtek_pci_getsignal( card ); v->rangelow = GEMTEK_PCI_RANGE_LOW;
strcpy( t->name, "FM" ); v->rangehigh = GEMTEK_PCI_RANGE_HIGH;
v->rxsubchans =V4L2_TUNER_SUB_MONO;
v->capability=V4L2_TUNER_CAP_LOW;
v->audmode = V4L2_TUNER_MODE_MONO;
v->signal=0xFFFF*gemtek_pci_getsignal( card );
return 0; return 0;
} }
case VIDIOC_S_TUNER:
case VIDIOCSTUNER:
{ {
struct video_tuner *t = arg; struct v4l2_tuner *v = arg;
if ( t->tuner )
return -EINVAL;
return 0;
}
case VIDIOCGFREQ: if (v->index > 0)
{
unsigned long *freq = arg;
*freq = card->current_frequency;
return 0;
}
case VIDIOCSFREQ:
{
unsigned long *freq = arg;
if ( (*freq < GEMTEK_PCI_RANGE_LOW) ||
(*freq > GEMTEK_PCI_RANGE_HIGH) )
return -EINVAL; return -EINVAL;
gemtek_pci_setfrequency( card, *freq ); return 0;
card->current_frequency = *freq; }
case VIDIOC_S_FREQUENCY:
{
struct v4l2_frequency *f = arg;
if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) ||
(f->frequency > GEMTEK_PCI_RANGE_HIGH) )
return -EINVAL;
gemtek_pci_setfrequency( card, f->frequency );
card->current_frequency = f->frequency;
card->mute = FALSE; card->mute = FALSE;
return 0; return 0;
} }
case VIDIOC_QUERYCTRL:
case VIDIOCGAUDIO:
{ {
struct video_audio *a = arg; struct v4l2_queryctrl *qc = arg;
int i;
memset( a, 0, sizeof( *a ) ); for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
a->flags |= VIDEO_AUDIO_MUTABLE; if (qc->id && qc->id == radio_qctrl[i].id) {
a->volume = 1; memcpy(qc, &(radio_qctrl[i]),
a->step = 65535; sizeof(*qc));
strcpy( a->name, "Radio" ); return (0);
return 0; }
}
return -EINVAL;
} }
case VIDIOC_G_CTRL:
case VIDIOCSAUDIO:
{ {
struct video_audio *a = arg; struct v4l2_control *ctrl= arg;
if ( a->audio ) switch (ctrl->id) {
return -EINVAL; case V4L2_CID_AUDIO_MUTE:
ctrl->value=card->mute;
if ( a->flags & VIDEO_AUDIO_MUTE ) return (0);
gemtek_pci_mute( card ); case V4L2_CID_AUDIO_VOLUME:
else if (card->mute)
gemtek_pci_unmute( card ); ctrl->value=0;
return 0; else
ctrl->value=65535;
return (0);
}
return -EINVAL;
} }
case VIDIOC_S_CTRL:
{
struct v4l2_control *ctrl= arg;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
if (ctrl->value) {
gemtek_pci_mute(card);
} else {
gemtek_pci_unmute(card);
}
return (0);
case V4L2_CID_AUDIO_VOLUME:
if (ctrl->value) {
gemtek_pci_unmute(card);
} else {
gemtek_pci_mute(card);
}
return (0);
}
return -EINVAL;
}
default: default:
return -ENOIOCTLCMD; return v4l_compat_translate_ioctl(inode,file,cmd,arg,
gemtek_do_ioctl);
} }
} }
@ -309,7 +359,7 @@ static struct video_device vdev_template = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "Gemtek PCI Radio", .name = "Gemtek PCI Radio",
.type = VID_TYPE_TUNER, .type = VID_TYPE_TUNER,
.hardware = VID_HARDWARE_GEMTEK, .hardware = 0,
.fops = &gemtek_pci_fops, .fops = &gemtek_pci_fops,
}; };