4 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
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.
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.
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
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>
27 int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
29 if (dev == NULL || v4l2_dev == NULL)
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);
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);
41 EXPORT_SYMBOL_GPL(v4l2_device_register);
43 void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
45 struct v4l2_subdev *sd, *next;
47 if (v4l2_dev == NULL || v4l2_dev->dev == NULL)
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);
56 EXPORT_SYMBOL_GPL(v4l2_device_unregister);
58 int v4l2_device_register_subdev(struct v4l2_device *dev, struct v4l2_subdev *sd)
60 /* Check for valid input */
61 if (dev == NULL || sd == NULL || !sd->name[0])
63 /* Warn if we apparently re-register a subdev */
65 if (!try_module_get(sd->owner))
68 spin_lock(&dev->lock);
69 list_add_tail(&sd->list, &dev->subdevs);
70 spin_unlock(&dev->lock);
73 EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
75 void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
77 /* return if it isn't registered */
78 if (sd == NULL || sd->dev == NULL)
80 spin_lock(&sd->dev->lock);
82 spin_unlock(&sd->dev->lock);
84 module_put(sd->owner);
86 EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);