]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/media/media-devnode.h
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / include / media / media-devnode.h
CommitLineData
cf4b9211
LP
1/*
2 * Media device node
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 *
cf4b9211
LP
18 * --
19 *
20 * Common functions for media-related drivers to register and unregister media
21 * device nodes.
22 */
23
24#ifndef _MEDIA_DEVNODE_H
25#define _MEDIA_DEVNODE_H
26
27#include <linux/poll.h>
28#include <linux/fs.h>
29#include <linux/device.h>
30#include <linux/cdev.h>
31
a087ce70
MCC
32struct media_device;
33
cf4b9211
LP
34/*
35 * Flag to mark the media_devnode struct as registered. Drivers must not touch
36 * this flag directly, it will be set and cleared by media_devnode_register and
37 * media_devnode_unregister.
38 */
39#define MEDIA_FLAG_REGISTERED 0
40
75c7e295
MCC
41/**
42 * struct media_file_operations - Media device file operations
43 *
44 * @owner: should be filled with %THIS_MODULE
45 * @read: pointer to the function that implements read() syscall
46 * @write: pointer to the function that implements write() syscall
47 * @poll: pointer to the function that implements poll() syscall
48 * @ioctl: pointer to the function that implements ioctl() syscall
49 * @compat_ioctl: pointer to the function that will handle 32 bits userspace
50 * calls to the the ioctl() syscall on a Kernel compiled with 64 bits.
51 * @open: pointer to the function that implements open() syscall
52 * @release: pointer to the function that will release the resources allocated
53 * by the @open function.
54 */
cf4b9211
LP
55struct media_file_operations {
56 struct module *owner;
57 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
58 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
59 unsigned int (*poll) (struct file *, struct poll_table_struct *);
60 long (*ioctl) (struct file *, unsigned int, unsigned long);
c6c1d50b 61 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
cf4b9211
LP
62 int (*open) (struct file *);
63 int (*release) (struct file *);
64};
65
66/**
67 * struct media_devnode - Media device node
0db5c799 68 * @media_dev: pointer to struct &media_device
75c7e295 69 * @fops: pointer to struct &media_file_operations with media device ops
0db5c799 70 * @dev: pointer to struct &device containing the media controller device
ec0255ca 71 * @cdev: struct cdev pointer character device
cf4b9211
LP
72 * @parent: parent device
73 * @minor: device node minor number
48a7c4ba 74 * @flags: flags, combination of the ``MEDIA_FLAG_*`` constants
82631b5b
MCC
75 * @release: release callback called at the end of ``media_devnode_release()``
76 * routine at media-device.c.
cf4b9211
LP
77 *
78 * This structure represents a media-related device node.
79 *
80 * The @parent is a physical device. It must be set by core or device drivers
81 * before registering the node.
82 */
83struct media_devnode {
a087ce70
MCC
84 struct media_device *media_dev;
85
cf4b9211
LP
86 /* device ops */
87 const struct media_file_operations *fops;
88
89 /* sysfs */
90 struct device dev; /* media device */
91 struct cdev cdev; /* character device */
92 struct device *parent; /* device parent */
93
94 /* device info */
95 int minor;
96 unsigned long flags; /* Use bitops to access flags */
97
98 /* callbacks */
163f1e93 99 void (*release)(struct media_devnode *devnode);
cf4b9211
LP
100};
101
102/* dev to media_devnode */
103#define to_media_devnode(cd) container_of(cd, struct media_devnode, dev)
104
fe3c565e
MCC
105/**
106 * media_devnode_register - register a media device node
107 *
0db5c799 108 * @mdev: struct media_device we want to register a device node
163f1e93 109 * @devnode: media device node structure we want to register
fe3c565e
MCC
110 * @owner: should be filled with %THIS_MODULE
111 *
112 * The registration code assigns minor numbers and registers the new device node
113 * with the kernel. An error is returned if no free minor number can be found,
114 * or if the registration of the device node fails.
115 *
116 * Zero is returned on success.
117 *
118 * Note that if the media_devnode_register call fails, the release() callback of
119 * the media_devnode structure is *not* called, so the caller is responsible for
120 * freeing any data.
121 */
a087ce70
MCC
122int __must_check media_devnode_register(struct media_device *mdev,
123 struct media_devnode *devnode,
85de721c 124 struct module *owner);
fe3c565e 125
6f0dd24a
SK
126/**
127 * media_devnode_unregister_prepare - clear the media device node register bit
128 * @devnode: the device node to prepare for unregister
129 *
130 * This clears the passed device register bit. Future open calls will be met
131 * with errors. Should be called before media_devnode_unregister() to avoid
132 * races with unregister and device file open calls.
133 *
134 * This function can safely be called if the device node has never been
135 * registered or has already been unregistered.
136 */
137void media_devnode_unregister_prepare(struct media_devnode *devnode);
138
fe3c565e
MCC
139/**
140 * media_devnode_unregister - unregister a media device node
163f1e93 141 * @devnode: the device node to unregister
fe3c565e
MCC
142 *
143 * This unregisters the passed device. Future open calls will be met with
144 * errors.
145 *
6f0dd24a 146 * Should be called after media_devnode_unregister_prepare()
fe3c565e 147 */
163f1e93 148void media_devnode_unregister(struct media_devnode *devnode);
cf4b9211 149
75c7e295
MCC
150/**
151 * media_devnode_data - returns a pointer to the &media_devnode
152 *
153 * @filp: pointer to struct &file
154 */
cf4b9211
LP
155static inline struct media_devnode *media_devnode_data(struct file *filp)
156{
157 return filp->private_data;
158}
159
75c7e295
MCC
160/**
161 * media_devnode_is_registered - returns true if &media_devnode is registered;
162 * false otherwise.
163 *
163f1e93 164 * @devnode: pointer to struct &media_devnode.
a087ce70
MCC
165 *
166 * Note: If mdev is NULL, it also returns false.
75c7e295 167 */
163f1e93 168static inline int media_devnode_is_registered(struct media_devnode *devnode)
cf4b9211 169{
a087ce70
MCC
170 if (!devnode)
171 return false;
172
163f1e93 173 return test_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
cf4b9211
LP
174}
175
176#endif /* _MEDIA_DEVNODE_H */