X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fmedia%2Fradio%2Fradio-maestro.c;h=e8ce5f75cf1200630b20cf5981a192c0a39ba4e3;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=36c9f5bf8cdd09a0931b863aa770e7454276fdf2;hpb=76828883507a47dae78837ab5dec5a5b4513c667;p=linux-2.6.git diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c index 36c9f5bf8..e8ce5f75c 100644 --- a/drivers/media/radio/radio-maestro.c +++ b/drivers/media/radio/radio-maestro.c @@ -2,7 +2,7 @@ * (c) 2000 A. Tlalka, atlka@pg.gda.pl * Notes on the hardware * - * + Frequency control is done digitally + * + Frequency control is done digitally * + No volume control - only mute/unmute - you have to use Aux line volume * control on Maestro card to set the volume * + Radio status (tuned/not_tuned and stereo/mono) is valid some time after @@ -14,6 +14,8 @@ * version 0.04 * + code improvements * + VIDEO_TUNER_LOW is permanent + * + * Converted to V4L2 API by Mauro Carvalho Chehab */ #include @@ -23,11 +25,25 @@ #include #include #include -#include +#include #include -#include - -#define DRIVER_VERSION "0.05" +#include +#include + +#include /* 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 */ @@ -95,16 +111,16 @@ static struct file_operations maestro_fops = { static struct video_device maestro_radio = { .name = "Maestro radio", .type = VID_TYPE_TUNER, - .hardware = VID_HARDWARE_SF16MI, + .hardware = 0, .fops = &maestro_fops, }; struct radio_device { u16 io, /* base of Maestro card radio io (GPIO_DATA)*/ muted, /* VIDEO_AUDIO_MUTE */ - stereo, /* VIDEO_TUNER_STEREO_ON */ + stereo, /* VIDEO_TUNER_STEREO_ON */ tuned; /* signal strength (0 or 0xffff) */ - struct semaphore lock; + struct mutex lock; }; static u32 radio_bits_get(struct radio_device *dev) @@ -121,15 +137,15 @@ static u32 radio_bits_get(struct radio_device *dev) for (l=24;l--;) { outw(STR_CLK, io); /* HI state */ udelay(2); - if(!l) + if(!l) dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff; outw(0, io); /* LO state */ udelay(2); data <<= 1; /* shift data */ rdata = inw(io); if(!l) - dev->stereo = rdata & STR_MOST ? - 0 : VIDEO_TUNER_STEREO_ON; + dev->stereo = rdata & STR_MOST ? + 0 : 1; else if(rdata & STR_DATA) data++; @@ -182,72 +198,120 @@ static inline int radio_function(struct inode *inode, struct file *file, struct radio_device *card = video_get_drvdata(dev); switch (cmd) { - case VIDIOCGCAP: { - struct video_capability *v = arg; - memset(v, 0, sizeof(*v)); - strcpy(v->name, "Maestro radio"); - v->type = VID_TYPE_TUNER; - v->channels = v->audios = 1; - return 0; - } case VIDIOCGTUNER: { - struct video_tuner *v = arg; - if (v->tuner) - return -EINVAL; - (void)radio_bits_get(card); - v->flags = VIDEO_TUNER_LOW | card->stereo; - v->signal = card->tuned; - strcpy(v->name, "FM"); - v->rangelow = FREQ_LO; - v->rangehigh = FREQ_HI; - v->mode = VIDEO_MODE_AUTO; - return 0; - } case VIDIOCSTUNER: { - struct video_tuner *v = arg; - if (v->tuner != 0) - return -EINVAL; - return 0; - } case VIDIOCGFREQ: { - unsigned long *freq = arg; - *freq = BITS2FREQ(radio_bits_get(card)); - return 0; - } case VIDIOCSFREQ: { - unsigned long *freq = arg; - if (*freq < FREQ_LO || *freq > FREQ_HI) + case VIDIOC_QUERYCAP: + { + struct v4l2_capability *v = arg; + memset(v,0,sizeof(*v)); + strlcpy(v->driver, "radio-maestro", sizeof (v->driver)); + strlcpy(v->card, "Maestro Radio", sizeof (v->card)); + sprintf(v->bus_info,"PCI"); + v->version = RADIO_VERSION; + v->capabilities = V4L2_CAP_TUNER; + + return 0; + } + case VIDIOC_G_TUNER: + { + struct v4l2_tuner *v = arg; + + if (v->index > 0) + return -EINVAL; + + (void)radio_bits_get(card); + + memset(v,0,sizeof(*v)); + strcpy(v->name, "FM"); + v->type = V4L2_TUNER_RADIO; + + v->rangelow = FREQ_LO; + v->rangehigh = FREQ_HI; + 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; + } + 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; - radio_bits_set(card, FREQ2BITS(*freq)); - return 0; - } case VIDIOCGAUDIO: { - struct video_audio *v = arg; - memset(v, 0, sizeof(*v)); - strcpy(v->name, "Radio"); - v->flags = VIDEO_AUDIO_MUTABLE | card->muted; - v->mode = VIDEO_SOUND_STEREO; - return 0; - } case VIDIOCSAUDIO: { - struct video_audio *v = arg; - if (v->audio) + } + 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: { - register u16 io = card->io; - register u16 omask = inw(io + IO_MASK); - outw(~STR_WREN, io + IO_MASK); - outw((card->muted = v->flags & VIDEO_AUDIO_MUTE) ? - STR_WREN : 0, io); - udelay(4); - outw(omask, io + IO_MASK); - msleep(125); - return 0; + struct v4l2_control *ctrl= arg; + + switch (ctrl->id) { + case V4L2_CID_AUDIO_MUTE: + { + register u16 io = card->io; + register u16 omask = inw(io + IO_MASK); + outw(~STR_WREN, io + IO_MASK); + outw((card->muted = ctrl->value ) ? + STR_WREN : 0, io); + udelay(4); + outw(omask, io + IO_MASK); + msleep(125); + + return (0); + } + } + return -EINVAL; } - } case VIDIOCGUNIT: { - struct video_unit *v = arg; - v->video = VIDEO_NO_UNIT; - v->vbi = VIDEO_NO_UNIT; - v->radio = dev->minor; - v->audio = 0; - v->teletext = VIDEO_NO_UNIT; - return 0; - } default: - return -ENOIOCTLCMD; + default: + return v4l_compat_translate_ioctl(inode,file,cmd,arg, + radio_function); } } @@ -258,9 +322,9 @@ static int radio_ioctl(struct inode *inode, struct file *file, struct radio_device *card = video_get_drvdata(dev); int ret; - down(&card->lock); + mutex_lock(&card->lock); ret = video_usercopy(inode, file, cmd, arg, radio_function); - up(&card->lock); + mutex_unlock(&card->lock); return ret; } @@ -274,7 +338,7 @@ static u16 __devinit radio_power_on(struct radio_device *dev) omask = inw(io + IO_MASK); odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); 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(~(STR_WREN | STR_CLK), io + IO_MASK); outw(dev->muted ? 0 : STR_WREN, io); @@ -311,7 +375,7 @@ static int __devinit maestro_probe(struct pci_dev *pdev, } radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA; - init_MUTEX(&radio_unit->lock); + mutex_init(&radio_unit->lock); maestro_radio_inst = video_device_alloc(); if (maestro_radio_inst == NULL) {