4 * Copyright (C) 2010 Nokia Corporation
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
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.
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.
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
23 #include <linux/types.h>
24 #include <linux/ioctl.h>
26 #include <media/media-device.h>
27 #include <media/media-devnode.h>
29 static const struct media_file_operations media_device_fops
= {
33 /* -----------------------------------------------------------------------------
37 static ssize_t
show_model(struct device
*cd
,
38 struct device_attribute
*attr
, char *buf
)
40 struct media_device
*mdev
= to_media_device(to_media_devnode(cd
));
42 return sprintf(buf
, "%.*s\n", (int)sizeof(mdev
->model
), mdev
->model
);
45 static DEVICE_ATTR(model
, S_IRUGO
, show_model
, NULL
);
47 /* -----------------------------------------------------------------------------
48 * Registration/unregistration
51 static void media_device_release(struct media_devnode
*mdev
)
56 * media_device_register - register a media device
57 * @mdev: The media device
59 * The caller is responsible for initializing the media device before
60 * registration. The following fields must be set:
62 * - dev must point to the parent device
63 * - model must be filled with the device model name
65 int __must_check
media_device_register(struct media_device
*mdev
)
69 if (WARN_ON(mdev
->dev
== NULL
|| mdev
->model
[0] == 0))
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
);
80 ret
= device_create_file(&mdev
->devnode
.dev
, &dev_attr_model
);
82 media_devnode_unregister(&mdev
->devnode
);
88 EXPORT_SYMBOL_GPL(media_device_register
);
91 * media_device_unregister - unregister a media device
92 * @mdev: The media device
95 void media_device_unregister(struct media_device
*mdev
)
97 device_remove_file(&mdev
->devnode
.dev
, &dev_attr_model
);
98 media_devnode_unregister(&mdev
->devnode
);
100 EXPORT_SYMBOL_GPL(media_device_unregister
);