media-devnode.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /*
  34. * Flag to mark the media_devnode struct as registered. Drivers must not touch
  35. * this flag directly, it will be set and cleared by media_devnode_register and
  36. * media_devnode_unregister.
  37. */
  38. #define MEDIA_FLAG_REGISTERED 0
  39. struct media_file_operations {
  40. struct module *owner;
  41. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  42. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  43. unsigned int (*poll) (struct file *, struct poll_table_struct *);
  44. long (*ioctl) (struct file *, unsigned int, unsigned long);
  45. int (*open) (struct file *);
  46. int (*release) (struct file *);
  47. };
  48. /**
  49. * struct media_devnode - Media device node
  50. * @parent: parent device
  51. * @minor: device node minor number
  52. * @flags: flags, combination of the MEDIA_FLAG_* constants
  53. *
  54. * This structure represents a media-related device node.
  55. *
  56. * The @parent is a physical device. It must be set by core or device drivers
  57. * before registering the node.
  58. */
  59. struct media_devnode {
  60. /* device ops */
  61. const struct media_file_operations *fops;
  62. /* sysfs */
  63. struct device dev; /* media device */
  64. struct cdev cdev; /* character device */
  65. struct device *parent; /* device parent */
  66. /* device info */
  67. int minor;
  68. unsigned long flags; /* Use bitops to access flags */
  69. /* callbacks */
  70. void (*release)(struct media_devnode *mdev);
  71. };
  72. /* dev to media_devnode */
  73. #define to_media_devnode(cd) container_of(cd, struct media_devnode, dev)
  74. int __must_check media_devnode_register(struct media_devnode *mdev);
  75. void media_devnode_unregister(struct media_devnode *mdev);
  76. static inline struct media_devnode *media_devnode_data(struct file *filp)
  77. {
  78. return filp->private_data;
  79. }
  80. static inline int media_devnode_is_registered(struct media_devnode *mdev)
  81. {
  82. return test_bit(MEDIA_FLAG_REGISTERED, &mdev->flags);
  83. }
  84. #endif /* _MEDIA_DEVNODE_H */