Skip to content

Commit b86d154

Browse files
Hans VerkuilMauro Carvalho Chehab
authored andcommitted
[media] cx231xx-417: share ioctls with cx231xx-video
Share tuner, frequency, debug and input ioctls with cx231xx-video. These are all shared resources, so no need to implement them again. [mchehab@redhat.com: Fix merge conflict and a checkpatch issue] Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 5b8acdc commit b86d154

File tree

3 files changed

+68
-114
lines changed

3 files changed

+68
-114
lines changed

drivers/media/usb/cx231xx/cx231xx-417.c

Lines changed: 26 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <media/v4l2-common.h>
3636
#include <media/v4l2-ioctl.h>
3737
#include <media/cx2341x.h>
38+
#include <media/tuner.h>
3839
#include <linux/usb.h>
3940

4041
#include "cx231xx.h"
@@ -1551,68 +1552,6 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
15511552
return 0;
15521553
}
15531554

1554-
static const char * const iname[] = {
1555-
[CX231XX_VMUX_COMPOSITE1] = "Composite1",
1556-
[CX231XX_VMUX_SVIDEO] = "S-Video",
1557-
[CX231XX_VMUX_TELEVISION] = "Television",
1558-
[CX231XX_VMUX_CABLE] = "Cable TV",
1559-
[CX231XX_VMUX_DVB] = "DVB",
1560-
[CX231XX_VMUX_DEBUG] = "for debug only",
1561-
};
1562-
1563-
static int vidioc_enum_input(struct file *file, void *priv,
1564-
struct v4l2_input *i)
1565-
{
1566-
struct cx231xx_fh *fh = file->private_data;
1567-
struct cx231xx *dev = fh->dev;
1568-
struct cx231xx_input *input;
1569-
int n;
1570-
dprintk(3, "enter vidioc_enum_input()i->index=%d\n", i->index);
1571-
1572-
if (i->index >= 4)
1573-
return -EINVAL;
1574-
1575-
input = &cx231xx_boards[dev->model].input[i->index];
1576-
1577-
if (input->type == 0)
1578-
return -EINVAL;
1579-
1580-
/* FIXME
1581-
* strcpy(i->name, input->name); */
1582-
1583-
n = i->index;
1584-
strcpy(i->name, iname[INPUT(n)->type]);
1585-
1586-
if (input->type == CX231XX_VMUX_TELEVISION ||
1587-
input->type == CX231XX_VMUX_CABLE)
1588-
i->type = V4L2_INPUT_TYPE_TUNER;
1589-
else
1590-
i->type = V4L2_INPUT_TYPE_CAMERA;
1591-
return 0;
1592-
}
1593-
1594-
static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1595-
{
1596-
*i = 0;
1597-
return 0;
1598-
}
1599-
1600-
static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1601-
{
1602-
struct cx231xx_fh *fh = file->private_data;
1603-
struct cx231xx *dev = fh->dev;
1604-
1605-
dprintk(3, "enter vidioc_s_input() i=%d\n", i);
1606-
1607-
video_mux(dev, i);
1608-
1609-
if (i >= 4)
1610-
return -EINVAL;
1611-
dev->input = i;
1612-
dprintk(3, "exit vidioc_s_input()\n");
1613-
return 0;
1614-
}
1615-
16161555
static int vidioc_s_ctrl(struct file *file, void *priv,
16171556
struct v4l2_control *ctl)
16181557
{
@@ -1831,22 +1770,12 @@ static int vidioc_queryctrl(struct file *file, void *priv,
18311770

18321771
static int mpeg_open(struct file *file)
18331772
{
1834-
int minor = video_devdata(file)->minor;
1835-
struct cx231xx *h, *dev = NULL;
1836-
/*struct list_head *list;*/
1773+
struct video_device *vdev = video_devdata(file);
1774+
struct cx231xx *dev = video_drvdata(file);
18371775
struct cx231xx_fh *fh;
1838-
/*u32 value = 0;*/
18391776

18401777
dprintk(2, "%s()\n", __func__);
18411778

1842-
list_for_each_entry(h, &cx231xx_devlist, devlist) {
1843-
if (h->v4l_device->minor == minor)
1844-
dev = h;
1845-
}
1846-
1847-
if (dev == NULL)
1848-
return -ENODEV;
1849-
18501779
if (mutex_lock_interruptible(&dev->lock))
18511780
return -ERESTARTSYS;
18521781

@@ -1858,7 +1787,8 @@ static int mpeg_open(struct file *file)
18581787
}
18591788

18601789
file->private_data = fh;
1861-
fh->dev = dev;
1790+
v4l2_fh_init(&fh->fh, vdev);
1791+
fh->dev = dev;
18621792

18631793

18641794
videobuf_queue_vmalloc_init(&fh->vidq, &cx231xx_qops,
@@ -1880,6 +1810,7 @@ static int mpeg_open(struct file *file)
18801810
cx231xx_initialize_codec(dev);
18811811

18821812
mutex_unlock(&dev->lock);
1813+
v4l2_fh_add(&fh->fh);
18831814
cx231xx_start_TS1(dev);
18841815

18851816
return 0;
@@ -1892,11 +1823,6 @@ static int mpeg_release(struct file *file)
18921823

18931824
dprintk(3, "mpeg_release()! dev=0x%p\n", dev);
18941825

1895-
if (!dev) {
1896-
dprintk(3, "abort!!!\n");
1897-
return 0;
1898-
}
1899-
19001826
mutex_lock(&dev->lock);
19011827

19021828
cx231xx_stop_TS1(dev);
@@ -1930,7 +1856,8 @@ static int mpeg_release(struct file *file)
19301856
videobuf_read_stop(&fh->vidq);
19311857

19321858
videobuf_mmap_free(&fh->vidq);
1933-
file->private_data = NULL;
1859+
v4l2_fh_del(&fh->fh);
1860+
v4l2_fh_exit(&fh->fh);
19341861
kfree(fh);
19351862
mutex_unlock(&dev->lock);
19361863
return 0;
@@ -1986,9 +1913,13 @@ static struct v4l2_file_operations mpeg_fops = {
19861913
static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
19871914
.vidioc_s_std = vidioc_s_std,
19881915
.vidioc_g_std = vidioc_g_std,
1989-
.vidioc_enum_input = vidioc_enum_input,
1990-
.vidioc_g_input = vidioc_g_input,
1991-
.vidioc_s_input = vidioc_s_input,
1916+
.vidioc_g_tuner = cx231xx_g_tuner,
1917+
.vidioc_s_tuner = cx231xx_s_tuner,
1918+
.vidioc_g_frequency = cx231xx_g_frequency,
1919+
.vidioc_s_frequency = cx231xx_s_frequency,
1920+
.vidioc_enum_input = cx231xx_enum_input,
1921+
.vidioc_g_input = cx231xx_g_input,
1922+
.vidioc_s_input = cx231xx_s_input,
19921923
.vidioc_s_ctrl = vidioc_s_ctrl,
19931924
.vidioc_querycap = cx231xx_querycap,
19941925
.vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
@@ -2007,10 +1938,10 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
20071938
.vidioc_log_status = vidioc_log_status,
20081939
.vidioc_querymenu = vidioc_querymenu,
20091940
.vidioc_queryctrl = vidioc_queryctrl,
2010-
/* .vidioc_g_chip_ident = cx231xx_g_chip_ident,*/
1941+
.vidioc_g_chip_ident = cx231xx_g_chip_ident,
20111942
#ifdef CONFIG_VIDEO_ADV_DEBUG
2012-
/* .vidioc_g_register = cx231xx_g_register,*/
2013-
/* .vidioc_s_register = cx231xx_s_register,*/
1943+
.vidioc_g_register = cx231xx_g_register,
1944+
.vidioc_s_register = cx231xx_s_register,
20141945
#endif
20151946
};
20161947

@@ -2055,6 +1986,14 @@ static struct video_device *cx231xx_video_dev_alloc(
20551986
vfd->v4l2_dev = &dev->v4l2_dev;
20561987
vfd->lock = &dev->lock;
20571988
vfd->release = video_device_release;
1989+
set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
1990+
video_set_drvdata(vfd, dev);
1991+
if (dev->tuner_type == TUNER_ABSENT) {
1992+
v4l2_disable_ioctl(vfd, VIDIOC_G_FREQUENCY);
1993+
v4l2_disable_ioctl(vfd, VIDIOC_S_FREQUENCY);
1994+
v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER);
1995+
v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER);
1996+
}
20581997

20591998
return vfd;
20601999

drivers/media/usb/cx231xx/cx231xx-video.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static const char *iname[] = {
10361036
[CX231XX_VMUX_DEBUG] = "for debug only",
10371037
};
10381038

1039-
static int vidioc_enum_input(struct file *file, void *priv,
1039+
int cx231xx_enum_input(struct file *file, void *priv,
10401040
struct v4l2_input *i)
10411041
{
10421042
struct cx231xx_fh *fh = priv;
@@ -1076,7 +1076,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
10761076
return 0;
10771077
}
10781078

1079-
static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1079+
int cx231xx_g_input(struct file *file, void *priv, unsigned int *i)
10801080
{
10811081
struct cx231xx_fh *fh = priv;
10821082
struct cx231xx *dev = fh->dev;
@@ -1086,7 +1086,7 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
10861086
return 0;
10871087
}
10881088

1089-
static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1089+
int cx231xx_s_input(struct file *file, void *priv, unsigned int i)
10901090
{
10911091
struct cx231xx_fh *fh = priv;
10921092
struct cx231xx *dev = fh->dev;
@@ -1115,7 +1115,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
11151115
return 0;
11161116
}
11171117

1118-
static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1118+
int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
11191119
{
11201120
struct cx231xx_fh *fh = priv;
11211121
struct cx231xx *dev = fh->dev;
@@ -1139,7 +1139,7 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
11391139
return 0;
11401140
}
11411141

1142-
static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1142+
int cx231xx_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
11431143
{
11441144
struct cx231xx_fh *fh = priv;
11451145
struct cx231xx *dev = fh->dev;
@@ -1157,7 +1157,7 @@ static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
11571157
return 0;
11581158
}
11591159

1160-
static int vidioc_g_frequency(struct file *file, void *priv,
1160+
int cx231xx_g_frequency(struct file *file, void *priv,
11611161
struct v4l2_frequency *f)
11621162
{
11631163
struct cx231xx_fh *fh = priv;
@@ -1171,7 +1171,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
11711171
return 0;
11721172
}
11731173

1174-
static int vidioc_s_frequency(struct file *file, void *priv,
1174+
int cx231xx_s_frequency(struct file *file, void *priv,
11751175
struct v4l2_frequency *f)
11761176
{
11771177
struct cx231xx_fh *fh = priv;
@@ -1227,8 +1227,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
12271227
return rc;
12281228
}
12291229

1230-
static int vidioc_g_chip_ident(struct file *file, void *fh,
1231-
struct v4l2_dbg_chip_ident *chip)
1230+
int vidioc_g_chip_ident(struct file *file, void *fh,
1231+
struct v4l2_dbg_chip_ident *chip)
12321232
{
12331233
chip->ident = V4L2_IDENT_NONE;
12341234
chip->revision = 0;
@@ -1255,7 +1255,7 @@ static int vidioc_g_chip_ident(struct file *file, void *fh,
12551255
if type == i2caddr, then <chip> is the 7-bit I2C address
12561256
*/
12571257

1258-
static int vidioc_g_register(struct file *file, void *priv,
1258+
int cx231xx_g_register(struct file *file, void *priv,
12591259
struct v4l2_dbg_register *reg)
12601260
{
12611261
struct cx231xx_fh *fh = priv;
@@ -1402,7 +1402,7 @@ static int vidioc_g_register(struct file *file, void *priv,
14021402
return ret;
14031403
}
14041404

1405-
static int vidioc_s_register(struct file *file, void *priv,
1405+
int cx231xx_s_register(struct file *file, void *priv,
14061406
struct v4l2_dbg_register *reg)
14071407
{
14081408
struct cx231xx_fh *fh = priv;
@@ -1811,7 +1811,7 @@ static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
18111811
{
18121812
struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev;
18131813

1814-
if (0 != t->index)
1814+
if (t->index)
18151815
return -EINVAL;
18161816

18171817
call_all(dev, tuner, s_tuner, t);
@@ -2201,19 +2201,19 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
22012201
.vidioc_dqbuf = vidioc_dqbuf,
22022202
.vidioc_s_std = vidioc_s_std,
22032203
.vidioc_g_std = vidioc_g_std,
2204-
.vidioc_enum_input = vidioc_enum_input,
2205-
.vidioc_g_input = vidioc_g_input,
2206-
.vidioc_s_input = vidioc_s_input,
2204+
.vidioc_enum_input = cx231xx_enum_input,
2205+
.vidioc_g_input = cx231xx_g_input,
2206+
.vidioc_s_input = cx231xx_s_input,
22072207
.vidioc_streamon = vidioc_streamon,
22082208
.vidioc_streamoff = vidioc_streamoff,
2209-
.vidioc_g_tuner = vidioc_g_tuner,
2210-
.vidioc_s_tuner = vidioc_s_tuner,
2211-
.vidioc_g_frequency = vidioc_g_frequency,
2212-
.vidioc_s_frequency = vidioc_s_frequency,
2213-
.vidioc_g_chip_ident = vidioc_g_chip_ident,
2209+
.vidioc_g_tuner = cx231xx_g_tuner,
2210+
.vidioc_s_tuner = cx231xx_s_tuner,
2211+
.vidioc_g_frequency = cx231xx_g_frequency,
2212+
.vidioc_s_frequency = cx231xx_s_frequency,
2213+
.vidioc_g_chip_ident = cx231xx_g_chip_ident,
22142214
#ifdef CONFIG_VIDEO_ADV_DEBUG
2215-
.vidioc_g_register = vidioc_g_register,
2216-
.vidioc_s_register = vidioc_s_register,
2215+
.vidioc_g_register = cx231xx_g_register,
2216+
.vidioc_s_register = cx231xx_s_register,
22172217
#endif
22182218
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
22192219
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
@@ -2240,12 +2240,12 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
22402240
.vidioc_querycap = cx231xx_querycap,
22412241
.vidioc_g_tuner = radio_g_tuner,
22422242
.vidioc_s_tuner = radio_s_tuner,
2243-
.vidioc_g_frequency = vidioc_g_frequency,
2244-
.vidioc_s_frequency = vidioc_s_frequency,
2245-
.vidioc_g_chip_ident = vidioc_g_chip_ident,
2243+
.vidioc_g_frequency = cx231xx_g_frequency,
2244+
.vidioc_s_frequency = cx231xx_s_frequency,
2245+
.vidioc_g_chip_ident = cx231xx_g_chip_ident,
22462246
#ifdef CONFIG_VIDEO_ADV_DEBUG
2247-
.vidioc_g_register = vidioc_g_register,
2248-
.vidioc_s_register = vidioc_s_register,
2247+
.vidioc_g_register = cx231xx_g_register,
2248+
.vidioc_s_register = cx231xx_s_register,
22492249
#endif
22502250
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
22512251
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,

drivers/media/usb/cx231xx/cx231xx.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,21 @@ void cx231xx_init_extension(struct cx231xx *dev);
936936
void cx231xx_close_extension(struct cx231xx *dev);
937937
int cx231xx_querycap(struct file *file, void *priv,
938938
struct v4l2_capability *cap);
939+
int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
940+
int cx231xx_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
941+
int cx231xx_g_frequency(struct file *file, void *priv,
942+
struct v4l2_frequency *f);
943+
int cx231xx_s_frequency(struct file *file, void *priv,
944+
struct v4l2_frequency *f);
945+
int cx231xx_enum_input(struct file *file, void *priv,
946+
struct v4l2_input *i);
947+
int cx231xx_g_input(struct file *file, void *priv, unsigned int *i);
948+
int cx231xx_s_input(struct file *file, void *priv, unsigned int i);
949+
int cx231xx_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip);
950+
int cx231xx_g_register(struct file *file, void *priv,
951+
struct v4l2_dbg_register *reg);
952+
int cx231xx_s_register(struct file *file, void *priv,
953+
struct v4l2_dbg_register *reg);
939954

940955
/* Provided by cx231xx-cards.c */
941956
extern void cx231xx_pre_card_setup(struct cx231xx *dev);

0 commit comments

Comments
 (0)