media-devnode.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifndef _MEDIA_DEVNODE_H
  28. #define _MEDIA_DEVNODE_H
  29. #include <linux/poll.h>
  30. #include <linux/fs.h>
  31. #include <linux/device.h>
  32. #include <linux/cdev.h>
  33. struct media_device;
  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. struct media_file_operations {
  41. struct module *owner;
  42. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  43. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  44. unsigned int (*poll) (struct file *, struct poll_table_struct *);
  45. long (*ioctl) (struct file *, unsigned int, unsigned long);
  46. int (*open) (struct file *);
  47. int (*release) (struct file *);
  48. };
  49. /**
  50. * struct media_devnode - Media device node
  51. * @parent: parent device
  52. * @minor: device node minor number
  53. * @flags: flags, combination of the MEDIA_FLAG_* constants
  54. *
  55. * This structure represents a media-related device node.
  56. *
  57. * The @parent is a physical device. It must be set by core or device drivers
  58. * before registering the node.
  59. */
  60. struct media_devnode {
  61. struct media_device *media_dev;
  62. /* device ops */
  63. const struct media_file_operations *fops;
  64. /* sysfs */
  65. struct device dev; /* media device */
  66. struct cdev cdev; /* character device */
  67. struct device *parent; /* device parent */
  68. /* device info */
  69. int minor;
  70. unsigned long flags; /* Use bitops to access flags */
  71. /* callbacks */
  72. void (*release)(struct media_devnode *devnode);
  73. };
  74. /* dev to media_devnode */
  75. #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev)
  76. int __must_check media_devnode_register(struct media_device *mdev,
  77. struct media_devnode *devnode,
  78. struct module *owner);
  79. /**
  80. * media_devnode_unregister_prepare - clear the media device node register bit
  81. * @devnode: the device node to prepare for unregister
  82. *
  83. * This clears the passed device register bit. Future open calls will be met
  84. * with errors. Should be called before media_devnode_unregister() to avoid
  85. * races with unregister and device file open calls.
  86. *
  87. * This function can safely be called if the device node has never been
  88. * registered or has already been unregistered.
  89. */
  90. void media_devnode_unregister_prepare(struct media_devnode *devnode);
  91. void media_devnode_unregister(struct media_devnode *devnode);
  92. static inline struct media_devnode *media_devnode_data(struct file *filp)
  93. {
  94. return filp->private_data;
  95. }
  96. static inline int media_devnode_is_registered(struct media_devnode *devnode)
  97. {
  98. if (!devnode)
  99. return false;
  100. return test_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
  101. }
  102. #endif /* _MEDIA_DEVNODE_H */