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
24 * Common functions for media-related drivers to register and unregister media
28 #ifndef _MEDIA_DEVNODE_H
29 #define _MEDIA_DEVNODE_H
31 #include <linux/poll.h>
33 #include <linux/device.h>
34 #include <linux/cdev.h>
39 * Flag to mark the media_devnode struct as registered. Drivers must not touch
40 * this flag directly, it will be set and cleared by media_devnode_register and
41 * media_devnode_unregister.
43 #define MEDIA_FLAG_REGISTERED 0
45 struct media_file_operations {
47 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
48 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
49 unsigned int (*poll) (struct file *, struct poll_table_struct *);
50 long (*ioctl) (struct file *, unsigned int, unsigned long);
51 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
52 int (*open) (struct file *);
53 int (*release) (struct file *);
57 * struct media_devnode - Media device node
58 * @fops: pointer to struct media_file_operations with media device ops
59 * @dev: struct device pointer for the media controller device
60 * @cdev: struct cdev pointer character device
61 * @parent: parent device
62 * @minor: device node minor number
63 * @flags: flags, combination of the MEDIA_FLAG_* constants
64 * @release: release callback called at the end of media_devnode_release()
66 * This structure represents a media-related device node.
68 * The @parent is a physical device. It must be set by core or device drivers
69 * before registering the node.
71 struct media_devnode {
72 struct media_device *media_dev;
75 const struct media_file_operations *fops;
78 struct device dev; /* media device */
79 struct cdev cdev; /* character device */
80 struct device *parent; /* device parent */
84 unsigned long flags; /* Use bitops to access flags */
87 void (*release)(struct media_devnode *devnode);
90 /* dev to media_devnode */
91 #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev)
93 int __must_check media_devnode_register(struct media_device *mdev,
94 struct media_devnode *devnode,
95 struct module *owner);
98 * media_devnode_unregister_prepare - clear the media device node register bit
99 * @devnode: the device node to prepare for unregister
101 * This clears the passed device register bit. Future open calls will be met
102 * with errors. Should be called before media_devnode_unregister() to avoid
103 * races with unregister and device file open calls.
105 * This function can safely be called if the device node has never been
106 * registered or has already been unregistered.
108 void media_devnode_unregister_prepare(struct media_devnode *devnode);
110 void media_devnode_unregister(struct media_devnode *devnode);
112 static inline struct media_devnode *media_devnode_data(struct file *filp)
114 return filp->private_data;
117 static inline int media_devnode_is_registered(struct media_devnode *devnode)
122 return test_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
125 #endif /* _MEDIA_DEVNODE_H */