media-device.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Media device
  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. #ifndef _MEDIA_DEVICE_H
  23. #define _MEDIA_DEVICE_H
  24. #include <linux/list.h>
  25. #include <linux/mutex.h>
  26. #include <linux/spinlock.h>
  27. #include <media/media-devnode.h>
  28. #include <media/media-entity.h>
  29. struct device;
  30. /**
  31. * struct media_device - Media device
  32. * @dev: Parent device
  33. * @devnode: Media device node
  34. * @model: Device model name
  35. * @serial: Device serial number (optional)
  36. * @bus_info: Unique and stable device location identifier
  37. * @hw_revision: Hardware device revision
  38. * @driver_version: Device driver version
  39. * @entity_id: ID of the next entity to be registered
  40. * @entities: List of registered entities
  41. * @lock: Entities list lock
  42. * @graph_mutex: Entities graph operation lock
  43. * @link_notify: Link state change notification callback
  44. *
  45. * This structure represents an abstract high-level media device. It allows easy
  46. * access to entities and provides basic media device-level support. The
  47. * structure can be allocated directly or embedded in a larger structure.
  48. *
  49. * The parent @dev is a physical device. It must be set before registering the
  50. * media device.
  51. *
  52. * @model is a descriptive model name exported through sysfs. It doesn't have to
  53. * be unique.
  54. */
  55. struct media_device {
  56. /* dev->driver_data points to this struct. */
  57. struct device *dev;
  58. struct media_devnode devnode;
  59. char model[32];
  60. char serial[40];
  61. char bus_info[32];
  62. u32 hw_revision;
  63. u32 driver_version;
  64. u32 entity_id;
  65. struct list_head entities;
  66. /* Protects the entities list */
  67. spinlock_t lock;
  68. /* Serializes graph operations. */
  69. struct mutex graph_mutex;
  70. int (*link_notify)(struct media_link *link, u32 flags,
  71. unsigned int notification);
  72. };
  73. /* Supported link_notify @notification values. */
  74. #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
  75. #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
  76. /* media_devnode to media_device */
  77. #define to_media_device(node) container_of(node, struct media_device, devnode)
  78. int __must_check __media_device_register(struct media_device *mdev,
  79. struct module *owner);
  80. #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE)
  81. void media_device_unregister(struct media_device *mdev);
  82. int __must_check media_device_register_entity(struct media_device *mdev,
  83. struct media_entity *entity);
  84. void media_device_unregister_entity(struct media_entity *entity);
  85. /* Iterate over all entities. */
  86. #define media_device_for_each_entity(entity, mdev) \
  87. list_for_each_entry(entity, &(mdev)->entities, list)
  88. #endif