aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/media-device.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2009-12-09 06:39:58 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 03:53:09 -0400
commit176fb0d108f7495ccf9aa127e1342a1a0d87e004 (patch)
treea1b54ad186dde663853d4d2d24f42cd7c0f94bfb /drivers/media/media-device.c
parentcf4b9211b5680cd9ca004232e517fb7ec5bf5316 (diff)
[media] media: Media device
The media_device structure abstracts functions common to all kind of media devices (v4l2, dvb, alsa, ...). It manages media entities and offers a userspace API to discover and configure the media device internal topology. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/media-device.c')
-rw-r--r--drivers/media/media-device.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
new file mode 100644
index 000000000000..bcd3985d415a
--- /dev/null
+++ b/drivers/media/media-device.c
@@ -0,0 +1,100 @@
1/*
2 * Media device
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/types.h>
24#include <linux/ioctl.h>
25
26#include <media/media-device.h>
27#include <media/media-devnode.h>
28
29static const struct media_file_operations media_device_fops = {
30 .owner = THIS_MODULE,
31};
32
33/* -----------------------------------------------------------------------------
34 * sysfs
35 */
36
37static ssize_t show_model(struct device *cd,
38 struct device_attribute *attr, char *buf)
39{
40 struct media_device *mdev = to_media_device(to_media_devnode(cd));
41
42 return sprintf(buf, "%.*s\n", (int)sizeof(mdev->model), mdev->model);
43}
44
45static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
46
47/* -----------------------------------------------------------------------------
48 * Registration/unregistration
49 */
50
51static void media_device_release(struct media_devnode *mdev)
52{
53}
54
55/**
56 * media_device_register - register a media device
57 * @mdev: The media device
58 *
59 * The caller is responsible for initializing the media device before
60 * registration. The following fields must be set:
61 *
62 * - dev must point to the parent device
63 * - model must be filled with the device model name
64 */
65int __must_check media_device_register(struct media_device *mdev)
66{
67 int ret;
68
69 if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
70 return -EINVAL;
71
72 /* Register the device node. */
73 mdev->devnode.fops = &media_device_fops;
74 mdev->devnode.parent = mdev->dev;
75 mdev->devnode.release = media_device_release;
76 ret = media_devnode_register(&mdev->devnode);
77 if (ret < 0)
78 return ret;
79
80 ret = device_create_file(&mdev->devnode.dev, &dev_attr_model);
81 if (ret < 0) {
82 media_devnode_unregister(&mdev->devnode);
83 return ret;
84 }
85
86 return 0;
87}
88EXPORT_SYMBOL_GPL(media_device_register);
89
90/**
91 * media_device_unregister - unregister a media device
92 * @mdev: The media device
93 *
94 */
95void media_device_unregister(struct media_device *mdev)
96{
97 device_remove_file(&mdev->devnode.dev, &dev_attr_model);
98 media_devnode_unregister(&mdev->devnode);
99}
100EXPORT_SYMBOL_GPL(media_device_unregister);