diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2008-11-29 19:36:58 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2008-12-30 06:38:37 -0500 |
commit | 2a1fcdf08230522bd5024f91da24aaa6e8d81f59 (patch) | |
tree | 03781d767920d0569e6441ff9c74186d50f70a23 /drivers | |
parent | 07b1747c8d0bb463311f9dd05d4c013765abe2eb (diff) |
V4L/DVB (9820): v4l2: add v4l2_device and v4l2_subdev structs to the v4l2 framework.
Start implementing a proper v4l2 framework as discussed during the
Linux Plumbers Conference 2008.
Introduces v4l2_device (for device instances) and v4l2_subdev (representing
sub-device instances).
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Reviewed-by: Laurent Pinchart <laurent.pinchart@skynet.be>
Reviewed-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Reviewed-by: Andy Walls <awalls@radix.net>
Reviewed-by: David Brownell <david-b@pacbell.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/Makefile | 2 | ||||
-rw-r--r-- | drivers/media/video/v4l2-device.c | 86 | ||||
-rw-r--r-- | drivers/media/video/v4l2-subdev.c | 108 |
3 files changed, 195 insertions, 1 deletions
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 492ab3dce71b..84a2be0cbbe7 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
@@ -10,7 +10,7 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o | |||
10 | 10 | ||
11 | omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o | 11 | omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o |
12 | 12 | ||
13 | videodev-objs := v4l2-dev.o v4l2-ioctl.o | 13 | videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-subdev.o |
14 | 14 | ||
15 | obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-compat-ioctl32.o v4l2-int-device.o | 15 | obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-compat-ioctl32.o v4l2-int-device.o |
16 | 16 | ||
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c new file mode 100644 index 000000000000..9eefde031597 --- /dev/null +++ b/drivers/media/video/v4l2-device.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | V4L2 device support. | ||
3 | |||
4 | Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl> | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2 of the License, or | ||
9 | (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | #include <linux/ioctl.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/videodev2.h> | ||
25 | #include <media/v4l2-device.h> | ||
26 | |||
27 | int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) | ||
28 | { | ||
29 | if (dev == NULL || v4l2_dev == NULL) | ||
30 | return -EINVAL; | ||
31 | /* Warn if we apparently re-register a device */ | ||
32 | WARN_ON(dev_get_drvdata(dev)); | ||
33 | INIT_LIST_HEAD(&v4l2_dev->subdevs); | ||
34 | spin_lock_init(&v4l2_dev->lock); | ||
35 | v4l2_dev->dev = dev; | ||
36 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s", | ||
37 | dev->driver->name, dev->bus_id); | ||
38 | dev_set_drvdata(dev, v4l2_dev); | ||
39 | return 0; | ||
40 | } | ||
41 | EXPORT_SYMBOL_GPL(v4l2_device_register); | ||
42 | |||
43 | void v4l2_device_unregister(struct v4l2_device *v4l2_dev) | ||
44 | { | ||
45 | struct v4l2_subdev *sd, *next; | ||
46 | |||
47 | if (v4l2_dev == NULL || v4l2_dev->dev == NULL) | ||
48 | return; | ||
49 | dev_set_drvdata(v4l2_dev->dev, NULL); | ||
50 | /* unregister subdevs */ | ||
51 | list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) | ||
52 | v4l2_device_unregister_subdev(sd); | ||
53 | |||
54 | v4l2_dev->dev = NULL; | ||
55 | } | ||
56 | EXPORT_SYMBOL_GPL(v4l2_device_unregister); | ||
57 | |||
58 | int v4l2_device_register_subdev(struct v4l2_device *dev, struct v4l2_subdev *sd) | ||
59 | { | ||
60 | /* Check for valid input */ | ||
61 | if (dev == NULL || sd == NULL || !sd->name[0]) | ||
62 | return -EINVAL; | ||
63 | /* Warn if we apparently re-register a subdev */ | ||
64 | WARN_ON(sd->dev); | ||
65 | if (!try_module_get(sd->owner)) | ||
66 | return -ENODEV; | ||
67 | sd->dev = dev; | ||
68 | spin_lock(&dev->lock); | ||
69 | list_add_tail(&sd->list, &dev->subdevs); | ||
70 | spin_unlock(&dev->lock); | ||
71 | return 0; | ||
72 | } | ||
73 | EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); | ||
74 | |||
75 | void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) | ||
76 | { | ||
77 | /* return if it isn't registered */ | ||
78 | if (sd == NULL || sd->dev == NULL) | ||
79 | return; | ||
80 | spin_lock(&sd->dev->lock); | ||
81 | list_del(&sd->list); | ||
82 | spin_unlock(&sd->dev->lock); | ||
83 | sd->dev = NULL; | ||
84 | module_put(sd->owner); | ||
85 | } | ||
86 | EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); | ||
diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c new file mode 100644 index 000000000000..fe1f01c970ac --- /dev/null +++ b/drivers/media/video/v4l2-subdev.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | V4L2 sub-device support. | ||
3 | |||
4 | Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl> | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2 of the License, or | ||
9 | (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/types.h> | ||
22 | #include <linux/ioctl.h> | ||
23 | #include <linux/i2c.h> | ||
24 | #include <linux/videodev2.h> | ||
25 | #include <media/v4l2-subdev.h> | ||
26 | |||
27 | int v4l2_subdev_command(struct v4l2_subdev *sd, unsigned cmd, void *arg) | ||
28 | { | ||
29 | switch (cmd) { | ||
30 | case VIDIOC_QUERYCTRL: | ||
31 | return v4l2_subdev_call(sd, core, querymenu, arg); | ||
32 | case VIDIOC_G_CTRL: | ||
33 | return v4l2_subdev_call(sd, core, g_ctrl, arg); | ||
34 | case VIDIOC_S_CTRL: | ||
35 | return v4l2_subdev_call(sd, core, s_ctrl, arg); | ||
36 | case VIDIOC_QUERYMENU: | ||
37 | return v4l2_subdev_call(sd, core, queryctrl, arg); | ||
38 | case VIDIOC_LOG_STATUS: | ||
39 | return v4l2_subdev_call(sd, core, log_status); | ||
40 | case VIDIOC_G_CHIP_IDENT: | ||
41 | return v4l2_subdev_call(sd, core, g_chip_ident, arg); | ||
42 | case VIDIOC_INT_S_STANDBY: | ||
43 | return v4l2_subdev_call(sd, core, s_standby, *(u32 *)arg); | ||
44 | case VIDIOC_INT_RESET: | ||
45 | return v4l2_subdev_call(sd, core, reset, *(u32 *)arg); | ||
46 | case VIDIOC_INT_S_GPIO: | ||
47 | return v4l2_subdev_call(sd, core, s_gpio, *(u32 *)arg); | ||
48 | case VIDIOC_INT_INIT: | ||
49 | return v4l2_subdev_call(sd, core, init, *(u32 *)arg); | ||
50 | #ifdef CONFIG_VIDEO_ADV_DEBUG | ||
51 | case VIDIOC_DBG_G_REGISTER: | ||
52 | return v4l2_subdev_call(sd, core, g_register, arg); | ||
53 | case VIDIOC_DBG_S_REGISTER: | ||
54 | return v4l2_subdev_call(sd, core, s_register, arg); | ||
55 | #endif | ||
56 | |||
57 | case VIDIOC_INT_S_TUNER_MODE: | ||
58 | return v4l2_subdev_call(sd, tuner, s_mode, *(enum v4l2_tuner_type *)arg); | ||
59 | case AUDC_SET_RADIO: | ||
60 | return v4l2_subdev_call(sd, tuner, s_radio); | ||
61 | case VIDIOC_S_TUNER: | ||
62 | return v4l2_subdev_call(sd, tuner, s_tuner, arg); | ||
63 | case VIDIOC_G_TUNER: | ||
64 | return v4l2_subdev_call(sd, tuner, g_tuner, arg); | ||
65 | case VIDIOC_S_STD: | ||
66 | return v4l2_subdev_call(sd, tuner, s_std, *(v4l2_std_id *)arg); | ||
67 | case VIDIOC_S_FREQUENCY: | ||
68 | return v4l2_subdev_call(sd, tuner, s_frequency, arg); | ||
69 | case VIDIOC_G_FREQUENCY: | ||
70 | return v4l2_subdev_call(sd, tuner, g_frequency, arg); | ||
71 | case TUNER_SET_TYPE_ADDR: | ||
72 | return v4l2_subdev_call(sd, tuner, s_type_addr, arg); | ||
73 | case TUNER_SET_CONFIG: | ||
74 | return v4l2_subdev_call(sd, tuner, s_config, arg); | ||
75 | |||
76 | case VIDIOC_INT_AUDIO_CLOCK_FREQ: | ||
77 | return v4l2_subdev_call(sd, audio, s_clock_freq, *(u32 *)arg); | ||
78 | case VIDIOC_INT_S_AUDIO_ROUTING: | ||
79 | return v4l2_subdev_call(sd, audio, s_routing, arg); | ||
80 | case VIDIOC_INT_I2S_CLOCK_FREQ: | ||
81 | return v4l2_subdev_call(sd, audio, s_i2s_clock_freq, *(u32 *)arg); | ||
82 | |||
83 | case VIDIOC_INT_S_VIDEO_ROUTING: | ||
84 | return v4l2_subdev_call(sd, video, s_routing, arg); | ||
85 | case VIDIOC_INT_S_CRYSTAL_FREQ: | ||
86 | return v4l2_subdev_call(sd, video, s_crystal_freq, arg); | ||
87 | case VIDIOC_INT_DECODE_VBI_LINE: | ||
88 | return v4l2_subdev_call(sd, video, decode_vbi_line, arg); | ||
89 | case VIDIOC_INT_S_VBI_DATA: | ||
90 | return v4l2_subdev_call(sd, video, s_vbi_data, arg); | ||
91 | case VIDIOC_INT_G_VBI_DATA: | ||
92 | return v4l2_subdev_call(sd, video, g_vbi_data, arg); | ||
93 | case VIDIOC_S_FMT: | ||
94 | return v4l2_subdev_call(sd, video, s_fmt, arg); | ||
95 | case VIDIOC_G_FMT: | ||
96 | return v4l2_subdev_call(sd, video, g_fmt, arg); | ||
97 | case VIDIOC_INT_S_STD_OUTPUT: | ||
98 | return v4l2_subdev_call(sd, video, s_std_output, *(v4l2_std_id *)arg); | ||
99 | case VIDIOC_STREAMON: | ||
100 | return v4l2_subdev_call(sd, video, s_stream, 1); | ||
101 | case VIDIOC_STREAMOFF: | ||
102 | return v4l2_subdev_call(sd, video, s_stream, 0); | ||
103 | |||
104 | default: | ||
105 | return v4l2_subdev_call(sd, core, ioctl, cmd, arg); | ||
106 | } | ||
107 | } | ||
108 | EXPORT_SYMBOL_GPL(v4l2_subdev_command); | ||