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