Merge branch 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / include / media / media-devnode.h
blob37d494805944dafe17f0bb38e9e92a9728d8827c
1 /*
2 * Media device node
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
22 * --
24 * Common functions for media-related drivers to register and unregister media
25 * device nodes.
28 #ifndef _MEDIA_DEVNODE_H
29 #define _MEDIA_DEVNODE_H
31 #include <linux/poll.h>
32 #include <linux/fs.h>
33 #include <linux/device.h>
34 #include <linux/cdev.h>
36 struct media_device;
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 /**
46 * struct media_file_operations - Media device file operations
48 * @owner: should be filled with %THIS_MODULE
49 * @read: pointer to the function that implements read() syscall
50 * @write: pointer to the function that implements write() syscall
51 * @poll: pointer to the function that implements poll() syscall
52 * @ioctl: pointer to the function that implements ioctl() syscall
53 * @compat_ioctl: pointer to the function that will handle 32 bits userspace
54 * calls to the the ioctl() syscall on a Kernel compiled with 64 bits.
55 * @open: pointer to the function that implements open() syscall
56 * @release: pointer to the function that will release the resources allocated
57 * by the @open function.
59 struct media_file_operations {
60 struct module *owner;
61 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
62 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64 long (*ioctl) (struct file *, unsigned int, unsigned long);
65 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
66 int (*open) (struct file *);
67 int (*release) (struct file *);
70 /**
71 * struct media_devnode - Media device node
72 * @media_dev: pointer to struct &media_device
73 * @fops: pointer to struct &media_file_operations with media device ops
74 * @dev: pointer to struct &device containing the media controller device
75 * @cdev: struct cdev pointer character device
76 * @parent: parent device
77 * @minor: device node minor number
78 * @flags: flags, combination of the MEDIA_FLAG_* constants
79 * @release: release callback called at the end of media_devnode_release()
81 * This structure represents a media-related device node.
83 * The @parent is a physical device. It must be set by core or device drivers
84 * before registering the node.
86 struct media_devnode {
87 struct media_device *media_dev;
89 /* device ops */
90 const struct media_file_operations *fops;
92 /* sysfs */
93 struct device dev; /* media device */
94 struct cdev cdev; /* character device */
95 struct device *parent; /* device parent */
97 /* device info */
98 int minor;
99 unsigned long flags; /* Use bitops to access flags */
101 /* callbacks */
102 void (*release)(struct media_devnode *devnode);
105 /* dev to media_devnode */
106 #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev)
109 * media_devnode_register - register a media device node
111 * @mdev: struct media_device we want to register a device node
112 * @devnode: media device node structure we want to register
113 * @owner: should be filled with %THIS_MODULE
115 * The registration code assigns minor numbers and registers the new device node
116 * with the kernel. An error is returned if no free minor number can be found,
117 * or if the registration of the device node fails.
119 * Zero is returned on success.
121 * Note that if the media_devnode_register call fails, the release() callback of
122 * the media_devnode structure is *not* called, so the caller is responsible for
123 * freeing any data.
125 int __must_check media_devnode_register(struct media_device *mdev,
126 struct media_devnode *devnode,
127 struct module *owner);
130 * media_devnode_unregister_prepare - clear the media device node register bit
131 * @devnode: the device node to prepare for unregister
133 * This clears the passed device register bit. Future open calls will be met
134 * with errors. Should be called before media_devnode_unregister() to avoid
135 * races with unregister and device file open calls.
137 * This function can safely be called if the device node has never been
138 * registered or has already been unregistered.
140 void media_devnode_unregister_prepare(struct media_devnode *devnode);
143 * media_devnode_unregister - unregister a media device node
144 * @devnode: the device node to unregister
146 * This unregisters the passed device. Future open calls will be met with
147 * errors.
149 * Should be called after media_devnode_unregister_prepare()
151 void media_devnode_unregister(struct media_devnode *devnode);
154 * media_devnode_data - returns a pointer to the &media_devnode
156 * @filp: pointer to struct &file
158 static inline struct media_devnode *media_devnode_data(struct file *filp)
160 return filp->private_data;
164 * media_devnode_is_registered - returns true if &media_devnode is registered;
165 * false otherwise.
167 * @devnode: pointer to struct &media_devnode.
169 * Note: If mdev is NULL, it also returns false.
171 static inline int media_devnode_is_registered(struct media_devnode *devnode)
173 if (!devnode)
174 return false;
176 return test_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
179 #endif /* _MEDIA_DEVNODE_H */