Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d455cf5d authored by Douglas Landgraf's avatar Douglas Landgraf Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (5563): Radio-maestro.c Replace radio_ioctl to use video_ioctl2



Convert radio-maestro to use video_ioctl2

Signed-off-by: default avatarDouglas Schilling Landgraf <dougsland@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 6f66446c
Loading
Loading
Loading
Loading
+143 −123
Original line number Original line Diff line number Diff line
@@ -75,8 +75,6 @@ static struct v4l2_queryctrl radio_qctrl[] = {
static int radio_nr = -1;
static int radio_nr = -1;
module_param(radio_nr, int, 0);
module_param(radio_nr, int, 0);


static int radio_ioctl(struct inode *inode, struct file *file,
	unsigned int cmd, unsigned long arg);
static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
static void maestro_remove(struct pci_dev *pdev);
static void maestro_remove(struct pci_dev *pdev);


@@ -102,18 +100,11 @@ static const struct file_operations maestro_fops = {
	.owner		= THIS_MODULE,
	.owner		= THIS_MODULE,
	.open           = video_exclusive_open,
	.open           = video_exclusive_open,
	.release        = video_exclusive_release,
	.release        = video_exclusive_release,
	.ioctl		= radio_ioctl,
	.ioctl		= video_ioctl2,
	.compat_ioctl	= v4l_compat_ioctl32,
	.compat_ioctl	= v4l_compat_ioctl32,
	.llseek         = no_llseek,
	.llseek         = no_llseek,
};
};


static struct video_device maestro_radio = {
	.name		= "Maestro radio",
	.type		= VID_TYPE_TUNER,
	.hardware	= 0,
	.fops		= &maestro_fops,
};

struct radio_device {
struct radio_device {
	u16	io,	/* base of Maestro card radio io (GPIO_DATA)*/
	u16	io,	/* base of Maestro card radio io (GPIO_DATA)*/
		muted,	/* VIDEO_AUDIO_MUTE */
		muted,	/* VIDEO_AUDIO_MUTE */
@@ -190,38 +181,30 @@ static void radio_bits_set(struct radio_device *dev, u32 data)
	msleep(125);
	msleep(125);
}
}


static inline int radio_function(struct inode *inode, struct file *file,
static int vidioc_querycap(struct file *file, void  *priv,
	unsigned int cmd, void *arg)
					struct v4l2_capability *v)
{
{
	struct video_device *dev = video_devdata(file);
	struct radio_device *card = video_get_drvdata(dev);

	switch (cmd) {
		case VIDIOC_QUERYCAP:
		{
			struct v4l2_capability *v = arg;
			memset(v,0,sizeof(*v));
	strlcpy(v->driver, "radio-maestro", sizeof(v->driver));
	strlcpy(v->driver, "radio-maestro", sizeof(v->driver));
	strlcpy(v->card, "Maestro Radio", sizeof(v->card));
	strlcpy(v->card, "Maestro Radio", sizeof(v->card));
	sprintf(v->bus_info, "PCI");
	sprintf(v->bus_info, "PCI");
	v->version = RADIO_VERSION;
	v->version = RADIO_VERSION;
	v->capabilities = V4L2_CAP_TUNER;
	v->capabilities = V4L2_CAP_TUNER;

	return 0;
	return 0;
}
}
		case VIDIOC_G_TUNER:

static int vidioc_g_tuner(struct file *file, void *priv,
					struct v4l2_tuner *v)
{
{
			struct v4l2_tuner *v = arg;
	struct video_device *dev = video_devdata(file);
	struct radio_device *card = video_get_drvdata(dev);


	if (v->index > 0)
	if (v->index > 0)
		return -EINVAL;
		return -EINVAL;


	(void)radio_bits_get(card);
	(void)radio_bits_get(card);


			memset(v,0,sizeof(*v));
	strcpy(v->name, "FM");
	strcpy(v->name, "FM");
	v->type = V4L2_TUNER_RADIO;
	v->type = V4L2_TUNER_RADIO;

	v->rangelow = FREQ_LO;
	v->rangelow = FREQ_LO;
	v->rangehigh = FREQ_HI;
	v->rangehigh = FREQ_HI;
	v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
	v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
@@ -231,101 +214,120 @@ static inline int radio_function(struct inode *inode, struct file *file,
	else
	else
		v->audmode = V4L2_TUNER_MODE_MONO;
		v->audmode = V4L2_TUNER_MODE_MONO;
	v->signal = card->tuned;
	v->signal = card->tuned;

	return 0;
	return 0;
}
}
		case VIDIOC_S_TUNER:
		{
			struct v4l2_tuner *v = arg;


static int vidioc_s_tuner(struct file *file, void *priv,
					struct v4l2_tuner *v)
{
	if (v->index > 0)
	if (v->index > 0)
		return -EINVAL;
		return -EINVAL;

	return 0;
	return 0;
}
}
		case VIDIOC_S_FREQUENCY:

static int vidioc_s_frequency(struct file *file, void *priv,
					struct v4l2_frequency *f)
{
{
			struct v4l2_frequency *f = arg;
	struct video_device *dev = video_devdata(file);
	struct radio_device *card = video_get_drvdata(dev);


	if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
	if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
		return -EINVAL;
		return -EINVAL;
	radio_bits_set(card, FREQ2BITS(f->frequency));
	radio_bits_set(card, FREQ2BITS(f->frequency));

	return 0;
	return 0;
}
}
		case VIDIOC_G_FREQUENCY:

static int vidioc_g_frequency(struct file *file, void *priv,
					struct v4l2_frequency *f)
{
{
			struct v4l2_frequency *f = arg;
	struct video_device *dev = video_devdata(file);
	struct radio_device *card = video_get_drvdata(dev);


	f->type = V4L2_TUNER_RADIO;
	f->type = V4L2_TUNER_RADIO;
	f->frequency = BITS2FREQ(radio_bits_get(card));
	f->frequency = BITS2FREQ(radio_bits_get(card));

	return 0;
	return 0;
}
}
		case VIDIOC_QUERYCTRL:

static int vidioc_queryctrl(struct file *file, void *priv,
					struct v4l2_queryctrl *qc)
{
{
			struct v4l2_queryctrl *qc = arg;
	int i;
	int i;


	for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
	for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
		if (qc->id && qc->id == radio_qctrl[i].id) {
		if (qc->id && qc->id == radio_qctrl[i].id) {
			memcpy(qc, &(radio_qctrl[i]),
			memcpy(qc, &(radio_qctrl[i]),
						sizeof(*qc));
						sizeof(*qc));
					return (0);
			return 0;
		}
		}
	}
	}
	return -EINVAL;
	return -EINVAL;
}
}
		case VIDIOC_G_CTRL:

static int vidioc_g_ctrl(struct file *file, void *priv,
					struct v4l2_control *ctrl)
{
{
			struct v4l2_control *ctrl= arg;
	struct video_device *dev = video_devdata(file);
	struct radio_device *card = video_get_drvdata(dev);


	switch (ctrl->id) {
	switch (ctrl->id) {
	case V4L2_CID_AUDIO_MUTE:
	case V4L2_CID_AUDIO_MUTE:
		ctrl->value = card->muted;
		ctrl->value = card->muted;
					return (0);
		return 0;
	}
	}
	return -EINVAL;
	return -EINVAL;
}
}
		case VIDIOC_S_CTRL:
		{
			struct v4l2_control *ctrl= arg;


			switch (ctrl->id) {
static int vidioc_s_ctrl(struct file *file, void *priv,
				case V4L2_CID_AUDIO_MUTE:
					struct v4l2_control *ctrl)
{
{
	struct video_device *dev = video_devdata(file);
	struct radio_device *card = video_get_drvdata(dev);
	register u16 io = card->io;
	register u16 io = card->io;
	register u16 omask = inw(io + IO_MASK);
	register u16 omask = inw(io + IO_MASK);

	switch (ctrl->id) {
	case V4L2_CID_AUDIO_MUTE:
		outw(~STR_WREN, io + IO_MASK);
		outw(~STR_WREN, io + IO_MASK);
		outw((card->muted = ctrl->value ) ?
		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);
				}
	}
	}
	return -EINVAL;
	return -EINVAL;
}
}
		default:

			return v4l_compat_translate_ioctl(inode,file,cmd,arg,
static int vidioc_g_audio(struct file *file, void *priv,
							  radio_function);
					struct v4l2_audio *a)
	}
{
	if (a->index > 1)
		return -EINVAL;

	strcpy(a->name, "Radio");
	a->capability = V4L2_AUDCAP_STEREO;
	return 0;
}
}


static int radio_ioctl(struct inode *inode, struct file *file,
static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
	unsigned int cmd, unsigned long arg)
{
{
	struct video_device *dev = video_devdata(file);
	*i = 0;
	struct radio_device *card = video_get_drvdata(dev);
	return 0;
	int ret;
}


	mutex_lock(&card->lock);
static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
	ret = video_usercopy(inode, file, cmd, arg, radio_function);
{
	mutex_unlock(&card->lock);
	if (i != 0)
		return -EINVAL;
	return 0;
}


	return ret;
static int vidioc_s_audio(struct file *file, void *priv,
					struct v4l2_audio *a)
{
	if (a->index != 0)
		return -EINVAL;
	return 0;
}
}


static u16 __devinit radio_power_on(struct radio_device *dev)
static u16 __devinit radio_power_on(struct radio_device *dev)
@@ -352,6 +354,24 @@ static u16 __devinit radio_power_on(struct radio_device *dev)
	return (ofreq == radio_bits_get(dev));
	return (ofreq == radio_bits_get(dev));
}
}


static struct video_device maestro_radio = {
	.name           = "Maestro radio",
	.type           = VID_TYPE_TUNER,
	.fops           = &maestro_fops,
	.vidioc_querycap    = vidioc_querycap,
	.vidioc_g_tuner     = vidioc_g_tuner,
	.vidioc_s_tuner     = vidioc_s_tuner,
	.vidioc_g_audio     = vidioc_g_audio,
	.vidioc_s_audio     = vidioc_s_audio,
	.vidioc_g_input     = vidioc_g_input,
	.vidioc_s_input     = vidioc_s_input,
	.vidioc_g_frequency = vidioc_g_frequency,
	.vidioc_s_frequency = vidioc_s_frequency,
	.vidioc_queryctrl   = vidioc_queryctrl,
	.vidioc_g_ctrl      = vidioc_g_ctrl,
	.vidioc_s_ctrl      = vidioc_s_ctrl,
};

static int __devinit maestro_probe(struct pci_dev *pdev,
static int __devinit maestro_probe(struct pci_dev *pdev,
	const struct pci_device_id *ent)
	const struct pci_device_id *ent)
{
{