uvc_entity.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if (!(entity->pads[i].flags & MEDIA_PAD_FL_SINK))
  31. continue;
  32. remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
  33. if (remote == NULL)
  34. return -EINVAL;
  35. remote_pad = remote->num_pads - 1;
  36. ret = media_entity_create_link(&remote->subdev.entity,
  37. remote_pad, &entity->subdev.entity, i, flags);
  38. if (ret < 0)
  39. return ret;
  40. }
  41. return v4l2_device_register_subdev(&chain->dev->vdev, &entity->subdev);
  42. }
  43. static struct v4l2_subdev_ops uvc_subdev_ops = {
  44. };
  45. void uvc_mc_cleanup_entity(struct uvc_entity *entity)
  46. {
  47. media_entity_cleanup(&entity->subdev.entity);
  48. }
  49. static int uvc_mc_init_entity(struct uvc_entity *entity)
  50. {
  51. v4l2_subdev_init(&entity->subdev, &uvc_subdev_ops);
  52. strlcpy(entity->subdev.name, entity->name, sizeof(entity->subdev.name));
  53. return media_entity_init(&entity->subdev.entity, entity->num_pads,
  54. entity->pads, 0);
  55. }
  56. int uvc_mc_register_entities(struct uvc_video_chain *chain)
  57. {
  58. struct uvc_entity *entity;
  59. int ret;
  60. list_for_each_entry(entity, &chain->entities, chain) {
  61. ret = uvc_mc_init_entity(entity);
  62. if (ret < 0) {
  63. uvc_printk(KERN_INFO, "Failed to initialize entity for "
  64. "entity %u\n", entity->id);
  65. return ret;
  66. }
  67. }
  68. list_for_each_entry(entity, &chain->entities, chain) {
  69. ret = uvc_mc_register_entity(chain, entity);
  70. if (ret < 0) {
  71. uvc_printk(KERN_INFO, "Failed to register entity for "
  72. "entity %u\n", entity->id);
  73. return ret;
  74. }
  75. }
  76. return 0;
  77. }