v4l2-async.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * V4L2 asynchronous subdevice registration API
  3. *
  4. * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef V4L2_ASYNC_H
  11. #define V4L2_ASYNC_H
  12. #include <linux/list.h>
  13. #include <linux/mutex.h>
  14. struct device;
  15. struct device_node;
  16. struct v4l2_device;
  17. struct v4l2_subdev;
  18. struct v4l2_async_notifier;
  19. /* A random max subdevice number, used to allocate an array on stack */
  20. #define V4L2_MAX_SUBDEVS 128U
  21. /**
  22. * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used
  23. * in order to identify a match
  24. *
  25. * @V4L2_ASYNC_MATCH_CUSTOM: Match will use the logic provided by &struct
  26. * v4l2_async_subdev.match ops
  27. * @V4L2_ASYNC_MATCH_DEVNAME: Match will use the device name
  28. * @V4L2_ASYNC_MATCH_I2C: Match will check for I2C adapter ID and address
  29. * @V4L2_ASYNC_MATCH_OF: Match will use OF node
  30. *
  31. * This enum is used by the asyncrhronous sub-device logic to define the
  32. * algorithm that will be used to match an asynchronous device.
  33. */
  34. enum v4l2_async_match_type {
  35. V4L2_ASYNC_MATCH_CUSTOM,
  36. V4L2_ASYNC_MATCH_DEVNAME,
  37. V4L2_ASYNC_MATCH_I2C,
  38. V4L2_ASYNC_MATCH_OF,
  39. };
  40. /**
  41. * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
  42. *
  43. * @match_type: type of match that will be used
  44. * @match: union of per-bus type matching data sets
  45. * @list: used to link struct v4l2_async_subdev objects, waiting to be
  46. * probed, to a notifier->waiting list
  47. */
  48. struct v4l2_async_subdev {
  49. enum v4l2_async_match_type match_type;
  50. union {
  51. struct {
  52. const struct device_node *node;
  53. } of;
  54. struct {
  55. const char *name;
  56. } device_name;
  57. struct {
  58. int adapter_id;
  59. unsigned short address;
  60. } i2c;
  61. struct {
  62. bool (*match)(struct device *,
  63. struct v4l2_async_subdev *);
  64. void *priv;
  65. } custom;
  66. } match;
  67. /* v4l2-async core private: not to be used by drivers */
  68. struct list_head list;
  69. };
  70. /**
  71. * struct v4l2_async_notifier - v4l2_device notifier data
  72. *
  73. * @num_subdevs: number of subdevices
  74. * @subdevs: array of pointers to subdevice descriptors
  75. * @v4l2_dev: pointer to struct v4l2_device
  76. * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
  77. * @done: list of struct v4l2_subdev, already probed
  78. * @list: member in a global list of notifiers
  79. * @bound: a subdevice driver has successfully probed one of subdevices
  80. * @complete: all subdevices have been probed successfully
  81. * @unbind: a subdevice is leaving
  82. */
  83. struct v4l2_async_notifier {
  84. unsigned int num_subdevs;
  85. struct v4l2_async_subdev **subdevs;
  86. struct v4l2_device *v4l2_dev;
  87. struct list_head waiting;
  88. struct list_head done;
  89. struct list_head list;
  90. int (*bound)(struct v4l2_async_notifier *notifier,
  91. struct v4l2_subdev *subdev,
  92. struct v4l2_async_subdev *asd);
  93. int (*complete)(struct v4l2_async_notifier *notifier);
  94. void (*unbind)(struct v4l2_async_notifier *notifier,
  95. struct v4l2_subdev *subdev,
  96. struct v4l2_async_subdev *asd);
  97. };
  98. /**
  99. * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
  100. *
  101. * @v4l2_dev: pointer to &struct v4l2_device
  102. * @notifier: pointer to &struct v4l2_async_notifier
  103. */
  104. int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
  105. struct v4l2_async_notifier *notifier);
  106. /**
  107. * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
  108. *
  109. * @notifier: pointer to &struct v4l2_async_notifier
  110. */
  111. void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
  112. /**
  113. * v4l2_async_register_subdev - registers a sub-device to the asynchronous
  114. * subdevice framework
  115. *
  116. * @sd: pointer to &struct v4l2_subdev
  117. */
  118. int v4l2_async_register_subdev(struct v4l2_subdev *sd);
  119. /**
  120. * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
  121. * subdevice framework
  122. *
  123. * @sd: pointer to &struct v4l2_subdev
  124. */
  125. void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
  126. #endif