uvc_entity.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * uvc_entity.c -- USB Video Class driver
  3. *
  4. * Copyright (C) 2005-2011
  5. * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/list.h>
  15. #include <linux/videodev2.h>
  16. #include <media/v4l2-common.h>
  17. #include "uvcvideo.h"
  18. /* ------------------------------------------------------------------------
  19. * Video subdevices registration and unregistration
  20. */
  21. static int uvc_mc_register_entity(struct uvc_video_chain *chain,
  22. struct uvc_entity *entity)
  23. {
  24. const u32 flags = MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE;
  25. struct uvc_entity *remote;
  26. unsigned int i;
  27. u8 remote_pad;
  28. int ret;
  29. for (i = 0; i < entity->num_pads; ++i) {
  30. struct media_entity *source;
  31. struct media_entity *sink;
  32. if (!(entity->pads[i].flags & MEDIA_PAD_FL_SINK))
  33. continue;
  34. remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
  35. if (remote == NULL)
  36. return -EINVAL;
  37. source = (UVC_ENTITY_TYPE(remote) == UVC_TT_STREAMING)
  38. ? &remote->vdev->entity : &remote->subdev.entity;
  39. sink = (UVC_ENTITY_TYPE(entity) == UVC_TT_STREAMING)
  40. ? &entity->vdev->entity : &entity->subdev.entity;
  41. remote_pad = remote->num_pads - 1;
  42. ret = media_entity_create_link(source, remote_pad,
  43. sink, i, flags);
  44. if (ret < 0)
  45. return ret;
  46. }
  47. if (UVC_ENTITY_TYPE(entity) != UVC_TT_STREAMING)
  48. ret = v4l2_device_register_subdev(&chain->dev->vdev,
  49. &entity->subdev);
  50. return ret;
  51. }
  52. static struct v4l2_subdev_ops uvc_subdev_ops = {
  53. };
  54. void uvc_mc_cleanup_entity(struct uvc_entity *entity)
  55. {
  56. if (UVC_ENTITY_TYPE(entity) != UVC_TT_STREAMING)
  57. media_entity_cleanup(&entity->subdev.entity);
  58. else if (entity->vdev != NULL)
  59. media_entity_cleanup(&entity->vdev->entity);
  60. }
  61. static int uvc_mc_init_entity(struct uvc_entity *entity)
  62. {
  63. int ret;
  64. if (UVC_ENTITY_TYPE(entity) != UVC_TT_STREAMING) {
  65. v4l2_subdev_init(&entity->subdev, &uvc_subdev_ops);
  66. strlcpy(entity->subdev.name, entity->name,
  67. sizeof(entity->subdev.name));
  68. ret = media_entity_init(&entity->subdev.entity,
  69. entity->num_pads, entity->pads, 0);
  70. } else
  71. ret = media_entity_init(&entity->vdev->entity,
  72. entity->num_pads, entity->pads, 0);
  73. return ret;
  74. }
  75. int uvc_mc_register_entities(struct uvc_video_chain *chain)
  76. {
  77. struct uvc_entity *entity;
  78. int ret;
  79. list_for_each_entry(entity, &chain->entities, chain) {
  80. ret = uvc_mc_init_entity(entity);
  81. if (ret < 0) {
  82. uvc_printk(KERN_INFO, "Failed to initialize entity for "
  83. "entity %u\n", entity->id);
  84. return ret;
  85. }
  86. }
  87. list_for_each_entry(entity, &chain->entities, chain) {
  88. ret = uvc_mc_register_entity(chain, entity);
  89. if (ret < 0) {
  90. uvc_printk(KERN_INFO, "Failed to register entity for "
  91. "entity %u\n", entity->id);
  92. return ret;
  93. }
  94. }
  95. return 0;
  96. }