V4L/DVB (10893): radio-zoltrix: convert to v4l2_device.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
		
					parent
					
						
							
								f1bfe89b67
							
						
					
				
			
			
				commit
				
					
						ec632c8a10
					
				
			
		
					 1 changed files with 180 additions and 203 deletions
				
			
		| 
						 | 
					@ -33,33 +33,17 @@
 | 
				
			||||||
#include <linux/init.h>		/* Initdata                       */
 | 
					#include <linux/init.h>		/* Initdata                       */
 | 
				
			||||||
#include <linux/ioport.h>	/* request_region		  */
 | 
					#include <linux/ioport.h>	/* request_region		  */
 | 
				
			||||||
#include <linux/delay.h>	/* udelay, msleep                 */
 | 
					#include <linux/delay.h>	/* udelay, msleep                 */
 | 
				
			||||||
#include <asm/io.h>		/* outb, outb_p                   */
 | 
					 | 
				
			||||||
#include <asm/uaccess.h>	/* copy to/from user              */
 | 
					 | 
				
			||||||
#include <linux/videodev2.h>	/* kernel radio structs           */
 | 
					#include <linux/videodev2.h>	/* kernel radio structs           */
 | 
				
			||||||
#include <media/v4l2-common.h>
 | 
					#include <linux/mutex.h>
 | 
				
			||||||
 | 
					#include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 | 
				
			||||||
 | 
					#include <linux/io.h>		/* outb, outb_p                   */
 | 
				
			||||||
 | 
					#include <linux/uaccess.h>	/* copy to/from user              */
 | 
				
			||||||
 | 
					#include <media/v4l2-device.h>
 | 
				
			||||||
#include <media/v4l2-ioctl.h>
 | 
					#include <media/v4l2-ioctl.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <linux/version.h>      /* for KERNEL_VERSION MACRO     */
 | 
					MODULE_AUTHOR("C.van Schaik");
 | 
				
			||||||
#define RADIO_VERSION KERNEL_VERSION(0,0,2)
 | 
					MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
 | 
				
			||||||
 | 
					MODULE_LICENSE("GPL");
 | 
				
			||||||
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          = 4096,
 | 
					 | 
				
			||||||
		.default_value = 0xff,
 | 
					 | 
				
			||||||
		.type          = V4L2_CTRL_TYPE_INTEGER,
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef CONFIG_RADIO_ZOLTRIX_PORT
 | 
					#ifndef CONFIG_RADIO_ZOLTRIX_PORT
 | 
				
			||||||
#define CONFIG_RADIO_ZOLTRIX_PORT -1
 | 
					#define CONFIG_RADIO_ZOLTRIX_PORT -1
 | 
				
			||||||
| 
						 | 
					@ -68,9 +52,16 @@ static struct v4l2_queryctrl radio_qctrl[] = {
 | 
				
			||||||
static int io = CONFIG_RADIO_ZOLTRIX_PORT;
 | 
					static int io = CONFIG_RADIO_ZOLTRIX_PORT;
 | 
				
			||||||
static int radio_nr = -1;
 | 
					static int radio_nr = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct zol_device {
 | 
					module_param(io, int, 0);
 | 
				
			||||||
	unsigned long in_use;
 | 
					MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
 | 
				
			||||||
	int port;
 | 
					module_param(radio_nr, int, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct zoltrix {
 | 
				
			||||||
 | 
						struct v4l2_device v4l2_dev;
 | 
				
			||||||
 | 
						struct video_device vdev;
 | 
				
			||||||
 | 
						int io;
 | 
				
			||||||
	int curvol;
 | 
						int curvol;
 | 
				
			||||||
	unsigned long curfreq;
 | 
						unsigned long curfreq;
 | 
				
			||||||
	int muted;
 | 
						int muted;
 | 
				
			||||||
| 
						 | 
					@ -78,161 +69,158 @@ struct zol_device {
 | 
				
			||||||
	struct mutex lock;
 | 
						struct mutex lock;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int zol_setvol(struct zol_device *dev, int vol)
 | 
					static struct zoltrix zoltrix_card;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int zol_setvol(struct zoltrix *zol, int vol)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	dev->curvol = vol;
 | 
						zol->curvol = vol;
 | 
				
			||||||
	if (dev->muted)
 | 
						if (zol->muted)
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&dev->lock);
 | 
						mutex_lock(&zol->lock);
 | 
				
			||||||
	if (vol == 0) {
 | 
						if (vol == 0) {
 | 
				
			||||||
		outb(0, io);
 | 
							outb(0, zol->io);
 | 
				
			||||||
		outb(0, io);
 | 
							outb(0, zol->io);
 | 
				
			||||||
		inb(io + 3);    /* Zoltrix needs to be read to confirm */
 | 
							inb(zol->io + 3);    /* Zoltrix needs to be read to confirm */
 | 
				
			||||||
		mutex_unlock(&dev->lock);
 | 
							mutex_unlock(&zol->lock);
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	outb(dev->curvol-1, io);
 | 
						outb(zol->curvol-1, zol->io);
 | 
				
			||||||
	msleep(10);
 | 
						msleep(10);
 | 
				
			||||||
	inb(io + 2);
 | 
						inb(zol->io + 2);
 | 
				
			||||||
	mutex_unlock(&dev->lock);
 | 
						mutex_unlock(&zol->lock);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void zol_mute(struct zol_device *dev)
 | 
					static void zol_mute(struct zoltrix *zol)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	dev->muted = 1;
 | 
						zol->muted = 1;
 | 
				
			||||||
	mutex_lock(&dev->lock);
 | 
						mutex_lock(&zol->lock);
 | 
				
			||||||
	outb(0, io);
 | 
						outb(0, zol->io);
 | 
				
			||||||
	outb(0, io);
 | 
						outb(0, zol->io);
 | 
				
			||||||
	inb(io + 3);            /* Zoltrix needs to be read to confirm */
 | 
						inb(zol->io + 3);            /* Zoltrix needs to be read to confirm */
 | 
				
			||||||
	mutex_unlock(&dev->lock);
 | 
						mutex_unlock(&zol->lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void zol_unmute(struct zol_device *dev)
 | 
					static void zol_unmute(struct zoltrix *zol)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	dev->muted = 0;
 | 
						zol->muted = 0;
 | 
				
			||||||
	zol_setvol(dev, dev->curvol);
 | 
						zol_setvol(zol, zol->curvol);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int zol_setfreq(struct zol_device *dev, unsigned long freq)
 | 
					static int zol_setfreq(struct zoltrix *zol, unsigned long freq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/* tunes the radio to the desired frequency */
 | 
						/* tunes the radio to the desired frequency */
 | 
				
			||||||
 | 
						struct v4l2_device *v4l2_dev = &zol->v4l2_dev;
 | 
				
			||||||
	unsigned long long bitmask, f, m;
 | 
						unsigned long long bitmask, f, m;
 | 
				
			||||||
	unsigned int stereo = dev->stereo;
 | 
						unsigned int stereo = zol->stereo;
 | 
				
			||||||
	int i;
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (freq == 0) {
 | 
						if (freq == 0) {
 | 
				
			||||||
		printk(KERN_WARNING "zoltrix: received zero freq. Failed to set.\n");
 | 
							v4l2_warn(v4l2_dev, "cannot set a frequency of 0.\n");
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m = (freq / 160 - 8800) * 2;
 | 
						m = (freq / 160 - 8800) * 2;
 | 
				
			||||||
	f = (unsigned long long) m + 0x4d1c;
 | 
						f = (unsigned long long)m + 0x4d1c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bitmask = 0xc480402c10080000ull;
 | 
						bitmask = 0xc480402c10080000ull;
 | 
				
			||||||
	i = 45;
 | 
						i = 45;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&dev->lock);
 | 
						mutex_lock(&zol->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	outb(0, io);
 | 
						zol->curfreq = freq;
 | 
				
			||||||
	outb(0, io);
 | 
					 | 
				
			||||||
	inb(io + 3);            /* Zoltrix needs to be read to confirm */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	outb(0x40, io);
 | 
						outb(0, zol->io);
 | 
				
			||||||
	outb(0xc0, io);
 | 
						outb(0, zol->io);
 | 
				
			||||||
 | 
						inb(zol->io + 3);            /* Zoltrix needs to be read to confirm */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ ( stereo << 31));
 | 
						outb(0x40, zol->io);
 | 
				
			||||||
 | 
						outb(0xc0, zol->io);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ (stereo << 31));
 | 
				
			||||||
	while (i--) {
 | 
						while (i--) {
 | 
				
			||||||
		if ((bitmask & 0x8000000000000000ull) != 0) {
 | 
							if ((bitmask & 0x8000000000000000ull) != 0) {
 | 
				
			||||||
			outb(0x80, io);
 | 
								outb(0x80, zol->io);
 | 
				
			||||||
			udelay(50);
 | 
								udelay(50);
 | 
				
			||||||
			outb(0x00, io);
 | 
								outb(0x00, zol->io);
 | 
				
			||||||
			udelay(50);
 | 
								udelay(50);
 | 
				
			||||||
			outb(0x80, io);
 | 
								outb(0x80, zol->io);
 | 
				
			||||||
			udelay(50);
 | 
								udelay(50);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			outb(0xc0, io);
 | 
								outb(0xc0, zol->io);
 | 
				
			||||||
			udelay(50);
 | 
								udelay(50);
 | 
				
			||||||
			outb(0x40, io);
 | 
								outb(0x40, zol->io);
 | 
				
			||||||
			udelay(50);
 | 
								udelay(50);
 | 
				
			||||||
			outb(0xc0, io);
 | 
								outb(0xc0, zol->io);
 | 
				
			||||||
			udelay(50);
 | 
								udelay(50);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		bitmask *= 2;
 | 
							bitmask *= 2;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	/* termination sequence */
 | 
						/* termination sequence */
 | 
				
			||||||
	outb(0x80, io);
 | 
						outb(0x80, zol->io);
 | 
				
			||||||
	outb(0xc0, io);
 | 
						outb(0xc0, zol->io);
 | 
				
			||||||
	outb(0x40, io);
 | 
						outb(0x40, zol->io);
 | 
				
			||||||
	udelay(1000);
 | 
						udelay(1000);
 | 
				
			||||||
	inb(io+2);
 | 
						inb(zol->io + 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	udelay(1000);
 | 
						udelay(1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (dev->muted)
 | 
						if (zol->muted) {
 | 
				
			||||||
	{
 | 
							outb(0, zol->io);
 | 
				
			||||||
		outb(0, io);
 | 
							outb(0, zol->io);
 | 
				
			||||||
		outb(0, io);
 | 
							inb(zol->io + 3);
 | 
				
			||||||
		inb(io + 3);
 | 
					 | 
				
			||||||
		udelay(1000);
 | 
							udelay(1000);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_unlock(&dev->lock);
 | 
						mutex_unlock(&zol->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(!dev->muted)
 | 
						if (!zol->muted)
 | 
				
			||||||
	{
 | 
							zol_setvol(zol, zol->curvol);
 | 
				
			||||||
		zol_setvol(dev, dev->curvol);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Get signal strength */
 | 
					/* Get signal strength */
 | 
				
			||||||
 | 
					static int zol_getsigstr(struct zoltrix *zol)
 | 
				
			||||||
static int zol_getsigstr(struct zol_device *dev)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int a, b;
 | 
						int a, b;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&dev->lock);
 | 
						mutex_lock(&zol->lock);
 | 
				
			||||||
	outb(0x00, io);         /* This stuff I found to do nothing */
 | 
						outb(0x00, zol->io);         /* This stuff I found to do nothing */
 | 
				
			||||||
	outb(dev->curvol, io);
 | 
						outb(zol->curvol, zol->io);
 | 
				
			||||||
	msleep(20);
 | 
						msleep(20);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	a = inb(io);
 | 
						a = inb(zol->io);
 | 
				
			||||||
	msleep(10);
 | 
						msleep(10);
 | 
				
			||||||
	b = inb(io);
 | 
						b = inb(zol->io);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_unlock(&dev->lock);
 | 
						mutex_unlock(&zol->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (a != b)
 | 
						if (a != b)
 | 
				
			||||||
		return (0);
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((a == 0xcf) || (a == 0xdf)  /* I found this out by playing */
 | 
						/* I found this out by playing with a binary scanner on the card io */
 | 
				
			||||||
		|| (a == 0xef))       /* with a binary scanner on the card io */
 | 
						return a == 0xcf || a == 0xdf || a == 0xef;
 | 
				
			||||||
		return (1);
 | 
					 | 
				
			||||||
	return (0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int zol_is_stereo (struct zol_device *dev)
 | 
					static int zol_is_stereo(struct zoltrix *zol)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int x1, x2;
 | 
						int x1, x2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&dev->lock);
 | 
						mutex_lock(&zol->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	outb(0x00, io);
 | 
						outb(0x00, zol->io);
 | 
				
			||||||
	outb(dev->curvol, io);
 | 
						outb(zol->curvol, zol->io);
 | 
				
			||||||
	msleep(20);
 | 
						msleep(20);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	x1 = inb(io);
 | 
						x1 = inb(zol->io);
 | 
				
			||||||
	msleep(10);
 | 
						msleep(10);
 | 
				
			||||||
	x2 = inb(io);
 | 
						x2 = inb(zol->io);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_unlock(&dev->lock);
 | 
						mutex_unlock(&zol->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((x1 == x2) && (x1 == 0xcf))
 | 
						return x1 == x2 && x1 == 0xcf;
 | 
				
			||||||
		return 1;
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_querycap(struct file *file, void  *priv,
 | 
					static int vidioc_querycap(struct file *file, void  *priv,
 | 
				
			||||||
| 
						 | 
					@ -240,59 +228,54 @@ static int vidioc_querycap(struct file *file, void  *priv,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	strlcpy(v->driver, "radio-zoltrix", sizeof(v->driver));
 | 
						strlcpy(v->driver, "radio-zoltrix", sizeof(v->driver));
 | 
				
			||||||
	strlcpy(v->card, "Zoltrix Radio", sizeof(v->card));
 | 
						strlcpy(v->card, "Zoltrix Radio", sizeof(v->card));
 | 
				
			||||||
	sprintf(v->bus_info, "ISA");
 | 
						strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
 | 
				
			||||||
	v->version = RADIO_VERSION;
 | 
						v->version = RADIO_VERSION;
 | 
				
			||||||
	v->capabilities = V4L2_CAP_TUNER;
 | 
						v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_g_tuner(struct file *file, void *priv,
 | 
					static int vidioc_g_tuner(struct file *file, void *priv,
 | 
				
			||||||
					struct v4l2_tuner *v)
 | 
										struct v4l2_tuner *v)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct zol_device *zol = video_drvdata(file);
 | 
						struct zoltrix *zol = video_drvdata(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (v->index > 0)
 | 
						if (v->index > 0)
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	strcpy(v->name, "FM");
 | 
						strlcpy(v->name, "FM", sizeof(v->name));
 | 
				
			||||||
	v->type = V4L2_TUNER_RADIO;
 | 
						v->type = V4L2_TUNER_RADIO;
 | 
				
			||||||
	v->rangelow = (88*16000);
 | 
						v->rangelow = 88 * 16000;
 | 
				
			||||||
	v->rangehigh = (108*16000);
 | 
						v->rangehigh = 108 * 16000;
 | 
				
			||||||
	v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
 | 
						v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
 | 
				
			||||||
	v->capability = V4L2_TUNER_CAP_LOW;
 | 
						v->capability = V4L2_TUNER_CAP_LOW;
 | 
				
			||||||
	if (zol_is_stereo(zol))
 | 
						if (zol_is_stereo(zol))
 | 
				
			||||||
		v->audmode = V4L2_TUNER_MODE_STEREO;
 | 
							v->audmode = V4L2_TUNER_MODE_STEREO;
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		v->audmode = V4L2_TUNER_MODE_MONO;
 | 
							v->audmode = V4L2_TUNER_MODE_MONO;
 | 
				
			||||||
	v->signal = 0xFFFF*zol_getsigstr(zol);
 | 
						v->signal = 0xFFFF * zol_getsigstr(zol);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_s_tuner(struct file *file, void *priv,
 | 
					static int vidioc_s_tuner(struct file *file, void *priv,
 | 
				
			||||||
					struct v4l2_tuner *v)
 | 
										struct v4l2_tuner *v)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (v->index > 0)
 | 
						return v->index ? -EINVAL : 0;
 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_s_frequency(struct file *file, void *priv,
 | 
					static int vidioc_s_frequency(struct file *file, void *priv,
 | 
				
			||||||
					struct v4l2_frequency *f)
 | 
										struct v4l2_frequency *f)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct zol_device *zol = video_drvdata(file);
 | 
						struct zoltrix *zol = video_drvdata(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	zol->curfreq = f->frequency;
 | 
						if (zol_setfreq(zol, f->frequency) != 0)
 | 
				
			||||||
	if (zol_setfreq(zol, zol->curfreq) != 0) {
 | 
					 | 
				
			||||||
		printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_g_frequency(struct file *file, void *priv,
 | 
					static int vidioc_g_frequency(struct file *file, void *priv,
 | 
				
			||||||
					struct v4l2_frequency *f)
 | 
										struct v4l2_frequency *f)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct zol_device *zol = video_drvdata(file);
 | 
						struct zoltrix *zol = video_drvdata(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	f->type = V4L2_TUNER_RADIO;
 | 
						f->type = V4L2_TUNER_RADIO;
 | 
				
			||||||
	f->frequency = zol->curfreq;
 | 
						f->frequency = zol->curfreq;
 | 
				
			||||||
| 
						 | 
					@ -302,14 +285,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
 | 
				
			||||||
static int vidioc_queryctrl(struct file *file, void *priv,
 | 
					static int vidioc_queryctrl(struct file *file, void *priv,
 | 
				
			||||||
					struct v4l2_queryctrl *qc)
 | 
										struct v4l2_queryctrl *qc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
						switch (qc->id) {
 | 
				
			||||||
 | 
						case V4L2_CID_AUDIO_MUTE:
 | 
				
			||||||
	for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
 | 
							return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
 | 
				
			||||||
		if (qc->id && qc->id == radio_qctrl[i].id) {
 | 
						case V4L2_CID_AUDIO_VOLUME:
 | 
				
			||||||
			memcpy(qc, &(radio_qctrl[i]),
 | 
							return v4l2_ctrl_query_fill(qc, 0, 65535, 4096, 65535);
 | 
				
			||||||
						sizeof(*qc));
 | 
					 | 
				
			||||||
			return 0;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return -EINVAL;
 | 
						return -EINVAL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -317,7 +297,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 | 
				
			||||||
static int vidioc_g_ctrl(struct file *file, void *priv,
 | 
					static int vidioc_g_ctrl(struct file *file, void *priv,
 | 
				
			||||||
				struct v4l2_control *ctrl)
 | 
									struct v4l2_control *ctrl)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct zol_device *zol = video_drvdata(file);
 | 
						struct zoltrix *zol = video_drvdata(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (ctrl->id) {
 | 
						switch (ctrl->id) {
 | 
				
			||||||
	case V4L2_CID_AUDIO_MUTE:
 | 
						case V4L2_CID_AUDIO_MUTE:
 | 
				
			||||||
| 
						 | 
					@ -333,7 +313,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 | 
				
			||||||
static int vidioc_s_ctrl(struct file *file, void *priv,
 | 
					static int vidioc_s_ctrl(struct file *file, void *priv,
 | 
				
			||||||
				struct v4l2_control *ctrl)
 | 
									struct v4l2_control *ctrl)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct zol_device *zol = video_drvdata(file);
 | 
						struct zoltrix *zol = video_drvdata(file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (ctrl->id) {
 | 
						switch (ctrl->id) {
 | 
				
			||||||
	case V4L2_CID_AUDIO_MUTE:
 | 
						case V4L2_CID_AUDIO_MUTE:
 | 
				
			||||||
| 
						 | 
					@ -341,43 +321,30 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
 | 
				
			||||||
			zol_mute(zol);
 | 
								zol_mute(zol);
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			zol_unmute(zol);
 | 
								zol_unmute(zol);
 | 
				
			||||||
			zol_setvol(zol,zol->curvol);
 | 
								zol_setvol(zol, zol->curvol);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	case V4L2_CID_AUDIO_VOLUME:
 | 
						case V4L2_CID_AUDIO_VOLUME:
 | 
				
			||||||
		zol_setvol(zol,ctrl->value/4096);
 | 
							zol_setvol(zol, ctrl->value / 4096);
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	zol->stereo = 1;
 | 
						zol->stereo = 1;
 | 
				
			||||||
	if (zol_setfreq(zol, zol->curfreq) != 0) {
 | 
						if (zol_setfreq(zol, zol->curfreq) != 0)
 | 
				
			||||||
		printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
#if 0
 | 
					#if 0
 | 
				
			||||||
/* FIXME: Implement stereo/mono switch on V4L2 */
 | 
					/* FIXME: Implement stereo/mono switch on V4L2 */
 | 
				
			||||||
			if (v->mode & VIDEO_SOUND_STEREO) {
 | 
						if (v->mode & VIDEO_SOUND_STEREO) {
 | 
				
			||||||
				zol->stereo = 1;
 | 
							zol->stereo = 1;
 | 
				
			||||||
				zol_setfreq(zol, zol->curfreq);
 | 
							zol_setfreq(zol, zol->curfreq);
 | 
				
			||||||
			}
 | 
						}
 | 
				
			||||||
			if (v->mode & VIDEO_SOUND_MONO) {
 | 
						if (v->mode & VIDEO_SOUND_MONO) {
 | 
				
			||||||
				zol->stereo = 0;
 | 
							zol->stereo = 0;
 | 
				
			||||||
				zol_setfreq(zol, zol->curfreq);
 | 
							zol_setfreq(zol, zol->curfreq);
 | 
				
			||||||
			}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	return -EINVAL;
 | 
						return -EINVAL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_g_audio(struct file *file, void *priv,
 | 
					 | 
				
			||||||
					struct v4l2_audio *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (a->index > 1)
 | 
					 | 
				
			||||||
		return -EINVAL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	strcpy(a->name, "Radio");
 | 
					 | 
				
			||||||
	a->capability = V4L2_AUDCAP_STEREO;
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
 | 
					static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	*i = 0;
 | 
						*i = 0;
 | 
				
			||||||
| 
						 | 
					@ -386,37 +353,39 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
 | 
					static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (i != 0)
 | 
						return i ? -EINVAL : 0;
 | 
				
			||||||
		return -EINVAL;
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int vidioc_g_audio(struct file *file, void *priv,
 | 
				
			||||||
 | 
										struct v4l2_audio *a)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						a->index = 0;
 | 
				
			||||||
 | 
						strlcpy(a->name, "Radio", sizeof(a->name));
 | 
				
			||||||
 | 
						a->capability = V4L2_AUDCAP_STEREO;
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int vidioc_s_audio(struct file *file, void *priv,
 | 
					static int vidioc_s_audio(struct file *file, void *priv,
 | 
				
			||||||
					struct v4l2_audio *a)
 | 
										struct v4l2_audio *a)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (a->index != 0)
 | 
						return a->index ? -EINVAL : 0;
 | 
				
			||||||
		return -EINVAL;
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int zoltrix_open(struct file *file)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct zol_device zoltrix_unit;
 | 
					static int zoltrix_release(struct file *file)
 | 
				
			||||||
 | 
					 | 
				
			||||||
static int zoltrix_exclusive_open(struct file *file)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return test_and_set_bit(0, &zoltrix_unit.in_use) ? -EBUSY : 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int zoltrix_exclusive_release(struct file *file)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	clear_bit(0, &zoltrix_unit.in_use);
 | 
					 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct v4l2_file_operations zoltrix_fops =
 | 
					static const struct v4l2_file_operations zoltrix_fops =
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	.owner		= THIS_MODULE,
 | 
						.owner		= THIS_MODULE,
 | 
				
			||||||
	.open           = zoltrix_exclusive_open,
 | 
						.open           = zoltrix_open,
 | 
				
			||||||
	.release        = zoltrix_exclusive_release,
 | 
						.release        = zoltrix_release,
 | 
				
			||||||
	.ioctl		= video_ioctl2,
 | 
						.ioctl		= video_ioctl2,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -435,67 +404,75 @@ static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = {
 | 
				
			||||||
	.vidioc_s_ctrl      = vidioc_s_ctrl,
 | 
						.vidioc_s_ctrl      = vidioc_s_ctrl,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct video_device zoltrix_radio = {
 | 
					 | 
				
			||||||
	.name		= "Zoltrix Radio Plus",
 | 
					 | 
				
			||||||
	.fops           = &zoltrix_fops,
 | 
					 | 
				
			||||||
	.ioctl_ops 	= &zoltrix_ioctl_ops,
 | 
					 | 
				
			||||||
	.release	= video_device_release_empty,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int __init zoltrix_init(void)
 | 
					static int __init zoltrix_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (io == -1) {
 | 
						struct zoltrix *zol = &zoltrix_card;
 | 
				
			||||||
		printk(KERN_ERR "You must set an I/O address with io=0x???\n");
 | 
						struct v4l2_device *v4l2_dev = &zol->v4l2_dev;
 | 
				
			||||||
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						strlcpy(v4l2_dev->name, "zoltrix", sizeof(v4l2_dev->name));
 | 
				
			||||||
 | 
						zol->io = io;
 | 
				
			||||||
 | 
						if (zol->io == -1) {
 | 
				
			||||||
 | 
							v4l2_err(v4l2_dev, "You must set an I/O address with io=0x???\n");
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if ((io != 0x20c) && (io != 0x30c)) {
 | 
						if (zol->io != 0x20c && zol->io != 0x30c) {
 | 
				
			||||||
		printk(KERN_ERR "zoltrix: invalid port, try 0x20c or 0x30c\n");
 | 
							v4l2_err(v4l2_dev, "invalid port, try 0x20c or 0x30c\n");
 | 
				
			||||||
		return -ENXIO;
 | 
							return -ENXIO;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	video_set_drvdata(&zoltrix_radio, &zoltrix_unit);
 | 
						if (!request_region(zol->io, 2, "zoltrix")) {
 | 
				
			||||||
	if (!request_region(io, 2, "zoltrix")) {
 | 
							v4l2_err(v4l2_dev, "port 0x%x already in use\n", zol->io);
 | 
				
			||||||
		printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
 | 
					 | 
				
			||||||
		return -EBUSY;
 | 
							return -EBUSY;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (video_register_device(&zoltrix_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
 | 
						res = v4l2_device_register(NULL, v4l2_dev);
 | 
				
			||||||
		release_region(io, 2);
 | 
						if (res < 0) {
 | 
				
			||||||
 | 
							release_region(zol->io, 2);
 | 
				
			||||||
 | 
							v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
 | 
				
			||||||
 | 
							return res;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						strlcpy(zol->vdev.name, v4l2_dev->name, sizeof(zol->vdev.name));
 | 
				
			||||||
 | 
						zol->vdev.v4l2_dev = v4l2_dev;
 | 
				
			||||||
 | 
						zol->vdev.fops = &zoltrix_fops;
 | 
				
			||||||
 | 
						zol->vdev.ioctl_ops = &zoltrix_ioctl_ops;
 | 
				
			||||||
 | 
						zol->vdev.release = video_device_release_empty;
 | 
				
			||||||
 | 
						video_set_drvdata(&zol->vdev, zol);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (video_register_device(&zol->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
 | 
				
			||||||
 | 
							v4l2_device_unregister(v4l2_dev);
 | 
				
			||||||
 | 
							release_region(zol->io, 2);
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	printk(KERN_INFO "Zoltrix Radio Plus card driver.\n");
 | 
						v4l2_info(v4l2_dev, "Zoltrix Radio Plus card driver.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_init(&zoltrix_unit.lock);
 | 
						mutex_init(&zol->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* mute card - prevents noisy bootups */
 | 
						/* mute card - prevents noisy bootups */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* this ensures that the volume is all the way down  */
 | 
						/* this ensures that the volume is all the way down  */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	outb(0, io);
 | 
						outb(0, zol->io);
 | 
				
			||||||
	outb(0, io);
 | 
						outb(0, zol->io);
 | 
				
			||||||
	msleep(20);
 | 
						msleep(20);
 | 
				
			||||||
	inb(io + 3);
 | 
						inb(zol->io + 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	zoltrix_unit.curvol = 0;
 | 
						zol->curvol = 0;
 | 
				
			||||||
	zoltrix_unit.stereo = 1;
 | 
						zol->stereo = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MODULE_AUTHOR("C.van Schaik");
 | 
					static void __exit zoltrix_exit(void)
 | 
				
			||||||
MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
 | 
					 | 
				
			||||||
MODULE_LICENSE("GPL");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module_param(io, int, 0);
 | 
					 | 
				
			||||||
MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
 | 
					 | 
				
			||||||
module_param(radio_nr, int, 0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void __exit zoltrix_cleanup_module(void)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	video_unregister_device(&zoltrix_radio);
 | 
						struct zoltrix *zol = &zoltrix_card;
 | 
				
			||||||
	release_region(io, 2);
 | 
					
 | 
				
			||||||
 | 
						video_unregister_device(&zol->vdev);
 | 
				
			||||||
 | 
						v4l2_device_unregister(&zol->v4l2_dev);
 | 
				
			||||||
 | 
						release_region(zol->io, 2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module_init(zoltrix_init);
 | 
					module_init(zoltrix_init);
 | 
				
			||||||
module_exit(zoltrix_cleanup_module);
 | 
					module_exit(zoltrix_exit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue