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));
sprintf(v->bus_info,"PCI");
v->version = RADIO_VERSION;
v->capabilities = V4L2_CAP_TUNER;
return 0; return 0;
} case VIDIOCGTUNER: { }
struct video_tuner *v = arg; case VIDIOC_G_TUNER:
if (v->tuner) {
struct v4l2_tuner *v = arg;
if (v->index > 0)
return -EINVAL; return -EINVAL;
(void)radio_bits_get(card); (void)radio_bits_get(card);
v->flags = VIDEO_TUNER_LOW | card->stereo;
v->signal = card->tuned; memset(v,0,sizeof(*v));
strcpy(v->name, "FM"); strcpy(v->name, "FM");
v->type = V4L2_TUNER_RADIO;
v->rangelow = FREQ_LO; v->rangelow = FREQ_LO;
v->rangehigh = FREQ_HI; v->rangehigh = FREQ_HI;
v->mode = VIDEO_MODE_AUTO; v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
v->capability=V4L2_TUNER_CAP_LOW;
if(card->stereo)
v->audmode = V4L2_TUNER_MODE_STEREO;
else
v->audmode = V4L2_TUNER_MODE_MONO;
v->signal=card->tuned;
return 0; return 0;
} case VIDIOCSTUNER: { }
struct video_tuner *v = arg; case VIDIOC_S_TUNER:
if (v->tuner != 0) {
struct v4l2_tuner *v = arg;
if (v->index > 0)
return -EINVAL; return -EINVAL;
return 0; return 0;
} case VIDIOCGFREQ: { }
unsigned long *freq = arg; case VIDIOC_S_FREQUENCY:
*freq = BITS2FREQ(radio_bits_get(card)); {
return 0; struct v4l2_frequency *f = arg;
} case VIDIOCSFREQ: {
unsigned long *freq = arg; if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
if (*freq < FREQ_LO || *freq > FREQ_HI)
return -EINVAL; return -EINVAL;
radio_bits_set(card, FREQ2BITS(*freq)); radio_bits_set(card, FREQ2BITS(f->frequency));
return 0; return 0;
} case VIDIOCGAUDIO: { }
struct video_audio *v = arg; case VIDIOC_G_FREQUENCY:
memset(v, 0, sizeof(*v)); {
strcpy(v->name, "Radio"); struct v4l2_frequency *f = arg;
v->flags = VIDEO_AUDIO_MUTABLE | card->muted;
v->mode = VIDEO_SOUND_STEREO; f->type = V4L2_TUNER_RADIO;
f->frequency = BITS2FREQ(radio_bits_get(card));
return 0; return 0;
} case VIDIOCSAUDIO: { }
struct video_audio *v = arg; case VIDIOC_QUERYCTRL:
if (v->audio) {
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;
}
case VIDIOC_G_CTRL:
{
struct v4l2_control *ctrl= arg;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
ctrl->value=card->muted;
return (0);
}
return -EINVAL;
}
case VIDIOC_S_CTRL:
{
struct v4l2_control *ctrl= arg;
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
{ {
register u16 io = card->io; register u16 io = card->io;
register u16 omask = inw(io + IO_MASK); register u16 omask = inw(io + IO_MASK);
outw(~STR_WREN, io + IO_MASK); outw(~STR_WREN, io + IO_MASK);
outw((card->muted = v->flags & VIDEO_AUDIO_MUTE) ? outw((card->muted = ctrl->value ) ?
STR_WREN : 0, io); STR_WREN : 0, io);
udelay(4); udelay(4);
outw(omask, io + IO_MASK); outw(omask, io + IO_MASK);
msleep(125); msleep(125);
return 0;
return (0);
} }
} case VIDIOCGUNIT: { }
struct video_unit *v = arg; return -EINVAL;
v->video = VIDEO_NO_UNIT; }
v->vbi = VIDEO_NO_UNIT; default:
v->radio = dev->minor; return v4l_compat_translate_ioctl(inode,file,cmd,arg,
v->audio = 0; radio_function);
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