blob: bcd3985d415a5b7d52f027fdf9093e9d373d5121 [file] [log] [blame]
Laurent Pinchart176fb0d2009-12-09 08:39:58 -03001/*
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);