Commit b6055d7b authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

V4L/DVB (4351): V4L2 conversion: radio-maestro

Driver conversion to V4L2 API.
Require some testing, since I don't have such hardware
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 52afbc2f
...@@ -160,7 +160,7 @@ config RADIO_MAXIRADIO ...@@ -160,7 +160,7 @@ config RADIO_MAXIRADIO
config RADIO_MAESTRO config RADIO_MAESTRO
tristate "Maestro on board radio" tristate "Maestro on board radio"
depends on VIDEO_V4L1 depends on VIDEO_V4L2 && PCI
---help--- ---help---
Say Y here to directly support the on-board radio tuner on the Say Y here to directly support the on-board radio tuner on the
Maestro 2 or 2E sound card. Maestro 2 or 2E sound card.
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
* version 0.04 * version 0.04
* + code improvements * + code improvements
* + VIDEO_TUNER_LOW is permanent * + VIDEO_TUNER_LOW is permanent
*
* Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -25,10 +27,23 @@ ...@@ -25,10 +27,23 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/mutex.h> #include <linux/mutex.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>
#define DRIVER_VERSION "0.05" #include <linux/version.h> /* for KERNEL_VERSION MACRO */
#define RADIO_VERSION KERNEL_VERSION(0,0,6)
#define DRIVER_VERSION "0.06"
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,
}
};
#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */ #define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */
...@@ -96,7 +111,7 @@ static struct file_operations maestro_fops = { ...@@ -96,7 +111,7 @@ static struct file_operations maestro_fops = {
static struct video_device maestro_radio = { static struct video_device maestro_radio = {
.name = "Maestro radio", .name = "Maestro radio",
.type = VID_TYPE_TUNER, .type = VID_TYPE_TUNER,
.hardware = VID_HARDWARE_SF16MI, .hardware = 0,
.fops = &maestro_fops, .fops = &maestro_fops,
}; };
...@@ -130,7 +145,7 @@ static u32 radio_bits_get(struct radio_device *dev) ...@@ -130,7 +145,7 @@ static u32 radio_bits_get(struct radio_device *dev)
rdata = inw(io); rdata = inw(io);
if(!l) if(!l)
dev->stereo = rdata & STR_MOST ? dev->stereo = rdata & STR_MOST ?
0 : VIDEO_TUNER_STEREO_ON; 0 : 1;
else else
if(rdata & STR_DATA) if(rdata & STR_DATA)
data++; data++;
...@@ -183,72 +198,120 @@ static inline int radio_function(struct inode *inode, struct file *file, ...@@ -183,72 +198,120 @@ static inline int radio_function(struct inode *inode, struct file *file,
struct radio_device *card = video_get_drvdata(dev); struct radio_device *card = video_get_drvdata(dev);
switch (cmd) { switch (cmd) {
case VIDIOCGCAP: { case VIDIOC_QUERYCAP:
struct video_capability *v = arg; {
memset(v, 0, sizeof(*v)); struct v4l2_capability *v = arg;
strcpy(v->name, "Maestro radio"); memset(v,0,sizeof(*v));
v->type = VID_TYPE_TUNER; strlcpy(v->driver, "radio-maestro", sizeof (v->driver));
v->channels = v->audios = 1; strlcpy(v->card, "Maestro Radio", sizeof (v->card));
return 0; sprintf(v->bus_info,"PCI");
} case VIDIOCGTUNER: { v->version = RADIO_VERSION;
struct video_tuner *v = arg; v->capabilities = V4L2_CAP_TUNER;
if (v->tuner)
return -EINVAL; return 0;
(void)radio_bits_get(card); }
v->flags = VIDEO_TUNER_LOW | card->stereo; case VIDIOC_G_TUNER:
v->signal = card->tuned; {
strcpy(v->name, "FM"); struct v4l2_tuner *v = arg;
v->rangelow = FREQ_LO;
v->rangehigh = FREQ_HI; if (v->index > 0)
v->mode = VIDEO_MODE_AUTO; return -EINVAL;
return 0;
} case VIDIOCSTUNER: { (void)radio_bits_get(card);
struct video_tuner *v = arg;
if (v->tuner != 0) memset(v,0,sizeof(*v));
return -EINVAL; strcpy(v->name, "FM");
return 0; v->type = V4L2_TUNER_RADIO;
} case VIDIOCGFREQ: {
unsigned long *freq = arg; v->rangelow = FREQ_LO;
*freq = BITS2FREQ(radio_bits_get(card)); v->rangehigh = FREQ_HI;
return 0; v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
} case VIDIOCSFREQ: { v->capability=V4L2_TUNER_CAP_LOW;
unsigned long *freq = arg; if(card->stereo)
if (*freq < FREQ_LO || *freq > FREQ_HI) v->audmode = V4L2_TUNER_MODE_STEREO;
else
v->audmode = V4L2_TUNER_MODE_MONO;
v->signal=card->tuned;
return 0;
}
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *v = arg;
if (v->index > 0)
return -EINVAL;
return 0;
}
case VIDIOC_S_FREQUENCY:
{
struct v4l2_frequency *f = arg;
if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
return -EINVAL;
radio_bits_set(card, FREQ2BITS(f->frequency));
return 0;
}
case VIDIOC_G_FREQUENCY:
{
struct v4l2_frequency *f = arg;
f->type = V4L2_TUNER_RADIO;
f->frequency = BITS2FREQ(radio_bits_get(card));
return 0;
}
case VIDIOC_QUERYCTRL:
{
struct v4l2_queryctrl *qc = arg;
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));
return (0);
}
}
return -EINVAL; return -EINVAL;
radio_bits_set(card, FREQ2BITS(*freq)); }
return 0; case VIDIOC_G_CTRL:
} case VIDIOCGAUDIO: { {
struct video_audio *v = arg; struct v4l2_control *ctrl= arg;
memset(v, 0, sizeof(*v));
strcpy(v->name, "Radio"); switch (ctrl->id) {
v->flags = VIDEO_AUDIO_MUTABLE | card->muted; case V4L2_CID_AUDIO_MUTE:
v->mode = VIDEO_SOUND_STEREO; ctrl->value=card->muted;
return 0; return (0);
} case VIDIOCSAUDIO: { }
struct video_audio *v = arg;
if (v->audio)
return -EINVAL; return -EINVAL;
}
case VIDIOC_S_CTRL:
{ {
register u16 io = card->io; struct v4l2_control *ctrl= arg;
register u16 omask = inw(io + IO_MASK);
outw(~STR_WREN, io + IO_MASK); switch (ctrl->id) {
outw((card->muted = v->flags & VIDEO_AUDIO_MUTE) ? case V4L2_CID_AUDIO_MUTE:
STR_WREN : 0, io); {
udelay(4); register u16 io = card->io;
outw(omask, io + IO_MASK); register u16 omask = inw(io + IO_MASK);
msleep(125); outw(~STR_WREN, io + IO_MASK);
return 0; outw((card->muted = ctrl->value ) ?
STR_WREN : 0, io);
udelay(4);
outw(omask, io + IO_MASK);
msleep(125);
return (0);
}
}
return -EINVAL;
} }
} case VIDIOCGUNIT: { default:
struct video_unit *v = arg; return v4l_compat_translate_ioctl(inode,file,cmd,arg,
v->video = VIDEO_NO_UNIT; radio_function);
v->vbi = VIDEO_NO_UNIT;
v->radio = dev->minor;
v->audio = 0;
v->teletext = VIDEO_NO_UNIT;
return 0;
} default:
return -ENOIOCTLCMD;
} }
} }
...@@ -275,7 +338,7 @@ static u16 __devinit radio_power_on(struct radio_device *dev) ...@@ -275,7 +338,7 @@ static u16 __devinit radio_power_on(struct radio_device *dev)
omask = inw(io + IO_MASK); omask = inw(io + IO_MASK);
odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
outw(odir & ~STR_WREN, io + IO_DIR); outw(odir & ~STR_WREN, io + IO_DIR);
dev->muted = inw(io) & STR_WREN ? 0 : VIDEO_AUDIO_MUTE; dev->muted = inw(io) & STR_WREN ? 0 : 1;
outw(odir, io + IO_DIR); outw(odir, io + IO_DIR);
outw(~(STR_WREN | STR_CLK), io + IO_MASK); outw(~(STR_WREN | STR_CLK), io + IO_MASK);
outw(dev->muted ? 0 : STR_WREN, io); outw(dev->muted ? 0 : STR_WREN, io);
......
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