media-entity.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Media entity
  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_ENTITY_H
  23. #define _MEDIA_ENTITY_H
  24. #include <linux/list.h>
  25. #define MEDIA_ENT_TYPE_SHIFT 16
  26. #define MEDIA_ENT_TYPE_MASK 0x00ff0000
  27. #define MEDIA_ENT_SUBTYPE_MASK 0x0000ffff
  28. #define MEDIA_ENT_T_DEVNODE (1 << MEDIA_ENT_TYPE_SHIFT)
  29. #define MEDIA_ENT_T_DEVNODE_V4L (MEDIA_ENT_T_DEVNODE + 1)
  30. #define MEDIA_ENT_T_DEVNODE_FB (MEDIA_ENT_T_DEVNODE + 2)
  31. #define MEDIA_ENT_T_DEVNODE_ALSA (MEDIA_ENT_T_DEVNODE + 3)
  32. #define MEDIA_ENT_T_DEVNODE_DVB (MEDIA_ENT_T_DEVNODE + 4)
  33. #define MEDIA_ENT_T_V4L2_SUBDEV (2 << MEDIA_ENT_TYPE_SHIFT)
  34. #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR (MEDIA_ENT_T_V4L2_SUBDEV + 1)
  35. #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH (MEDIA_ENT_T_V4L2_SUBDEV + 2)
  36. #define MEDIA_ENT_T_V4L2_SUBDEV_LENS (MEDIA_ENT_T_V4L2_SUBDEV + 3)
  37. #define MEDIA_ENT_FL_DEFAULT (1 << 0)
  38. #define MEDIA_LNK_FL_ENABLED (1 << 0)
  39. #define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
  40. #define MEDIA_PAD_FL_SINK (1 << 0)
  41. #define MEDIA_PAD_FL_SOURCE (1 << 1)
  42. struct media_link {
  43. struct media_pad *source; /* Source pad */
  44. struct media_pad *sink; /* Sink pad */
  45. struct media_link *reverse; /* Link in the reverse direction */
  46. unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
  47. };
  48. struct media_pad {
  49. struct media_entity *entity; /* Entity this pad belongs to */
  50. u16 index; /* Pad index in the entity pads array */
  51. unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
  52. };
  53. struct media_entity {
  54. struct list_head list;
  55. struct media_device *parent; /* Media device this entity belongs to*/
  56. u32 id; /* Entity ID, unique in the parent media
  57. * device context */
  58. const char *name; /* Entity name */
  59. u32 type; /* Entity type (MEDIA_ENT_T_*) */
  60. u32 revision; /* Entity revision, driver specific */
  61. unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
  62. u32 group_id; /* Entity group ID */
  63. u16 num_pads; /* Number of sink and source pads */
  64. u16 num_links; /* Number of existing links, both
  65. * enabled and disabled */
  66. u16 num_backlinks; /* Number of backlinks */
  67. u16 max_links; /* Maximum number of links */
  68. struct media_pad *pads; /* Pads array (num_pads elements) */
  69. struct media_link *links; /* Links array (max_links elements)*/
  70. union {
  71. /* Node specifications */
  72. struct {
  73. u32 major;
  74. u32 minor;
  75. } v4l;
  76. struct {
  77. u32 major;
  78. u32 minor;
  79. } fb;
  80. struct {
  81. u32 card;
  82. u32 device;
  83. u32 subdevice;
  84. } alsa;
  85. int dvb;
  86. /* Sub-device specifications */
  87. /* Nothing needed yet */
  88. };
  89. };
  90. static inline u32 media_entity_type(struct media_entity *entity)
  91. {
  92. return entity->type & MEDIA_ENT_TYPE_MASK;
  93. }
  94. static inline u32 media_entity_subtype(struct media_entity *entity)
  95. {
  96. return entity->type & MEDIA_ENT_SUBTYPE_MASK;
  97. }
  98. #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
  99. struct media_entity_graph {
  100. struct {
  101. struct media_entity *entity;
  102. int link;
  103. } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
  104. int top;
  105. };
  106. int media_entity_init(struct media_entity *entity, u16 num_pads,
  107. struct media_pad *pads, u16 extra_links);
  108. void media_entity_cleanup(struct media_entity *entity);
  109. int media_entity_create_link(struct media_entity *source, u16 source_pad,
  110. struct media_entity *sink, u16 sink_pad, u32 flags);
  111. void media_entity_graph_walk_start(struct media_entity_graph *graph,
  112. struct media_entity *entity);
  113. struct media_entity *
  114. media_entity_graph_walk_next(struct media_entity_graph *graph);
  115. #endif