v4l2-async.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_FWNODE: Match will use firmware 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_FWNODE,
  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. * @match.fwnode:
  46. * pointer to &struct fwnode_handle to be matched.
  47. * Used if @match_type is %V4L2_ASYNC_MATCH_FWNODE.
  48. * @match.device_name:
  49. * string containing the device name to be matched.
  50. * Used if @match_type is %V4L2_ASYNC_MATCH_DEVNAME.
  51. * @match.i2c: embedded struct with I2C parameters to be matched.
  52. * Both @match.i2c.adapter_id and @match.i2c.address
  53. * should be matched.
  54. * Used if @match_type is %V4L2_ASYNC_MATCH_I2C.
  55. * @match.i2c.adapter_id:
  56. * I2C adapter ID to be matched.
  57. * Used if @match_type is %V4L2_ASYNC_MATCH_I2C.
  58. * @match.i2c.address:
  59. * I2C address to be matched.
  60. * Used if @match_type is %V4L2_ASYNC_MATCH_I2C.
  61. * @match.custom:
  62. * Driver-specific match criteria.
  63. * Used if @match_type is %V4L2_ASYNC_MATCH_CUSTOM.
  64. * @match.custom.match:
  65. * Driver-specific match function to be used if
  66. * %V4L2_ASYNC_MATCH_CUSTOM.
  67. * @match.custom.priv:
  68. * Driver-specific private struct with match parameters
  69. * to be used if %V4L2_ASYNC_MATCH_CUSTOM.
  70. * @list: used to link struct v4l2_async_subdev objects, waiting to be
  71. * probed, to a notifier->waiting list
  72. *
  73. * When this struct is used as a member in a driver specific struct,
  74. * the driver specific struct shall contain the &struct
  75. * v4l2_async_subdev as its first member.
  76. */
  77. struct v4l2_async_subdev {
  78. enum v4l2_async_match_type match_type;
  79. union {
  80. struct fwnode_handle *fwnode;
  81. const char *device_name;
  82. struct {
  83. int adapter_id;
  84. unsigned short address;
  85. } i2c;
  86. struct {
  87. bool (*match)(struct device *,
  88. struct v4l2_async_subdev *);
  89. void *priv;
  90. } custom;
  91. } match;
  92. /* v4l2-async core private: not to be used by drivers */
  93. struct list_head list;
  94. };
  95. /**
  96. * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
  97. * @bound: a subdevice driver has successfully probed one of the subdevices
  98. * @complete: All subdevices have been probed successfully. The complete
  99. * callback is only executed for the root notifier.
  100. * @unbind: a subdevice is leaving
  101. */
  102. struct v4l2_async_notifier_operations {
  103. int (*bound)(struct v4l2_async_notifier *notifier,
  104. struct v4l2_subdev *subdev,
  105. struct v4l2_async_subdev *asd);
  106. int (*complete)(struct v4l2_async_notifier *notifier);
  107. void (*unbind)(struct v4l2_async_notifier *notifier,
  108. struct v4l2_subdev *subdev,
  109. struct v4l2_async_subdev *asd);
  110. };
  111. /**
  112. * struct v4l2_async_notifier - v4l2_device notifier data
  113. *
  114. * @ops: notifier operations
  115. * @num_subdevs: number of subdevices used in the subdevs array
  116. * @max_subdevs: number of subdevices allocated in the subdevs array
  117. * @subdevs: array of pointers to subdevice descriptors
  118. * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
  119. * @sd: sub-device that registered the notifier, NULL otherwise
  120. * @parent: parent notifier
  121. * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
  122. * @done: list of struct v4l2_subdev, already probed
  123. * @list: member in a global list of notifiers
  124. */
  125. struct v4l2_async_notifier {
  126. const struct v4l2_async_notifier_operations *ops;
  127. unsigned int num_subdevs;
  128. unsigned int max_subdevs;
  129. struct v4l2_async_subdev **subdevs;
  130. struct v4l2_device *v4l2_dev;
  131. struct v4l2_subdev *sd;
  132. struct v4l2_async_notifier *parent;
  133. struct list_head waiting;
  134. struct list_head done;
  135. struct list_head list;
  136. };
  137. /**
  138. * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
  139. *
  140. * @v4l2_dev: pointer to &struct v4l2_device
  141. * @notifier: pointer to &struct v4l2_async_notifier
  142. */
  143. int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
  144. struct v4l2_async_notifier *notifier);
  145. /**
  146. * v4l2_async_subdev_notifier_register - registers a subdevice asynchronous
  147. * notifier for a sub-device
  148. *
  149. * @sd: pointer to &struct v4l2_subdev
  150. * @notifier: pointer to &struct v4l2_async_notifier
  151. */
  152. int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd,
  153. struct v4l2_async_notifier *notifier);
  154. /**
  155. * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
  156. *
  157. * @notifier: pointer to &struct v4l2_async_notifier
  158. */
  159. void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
  160. /**
  161. * v4l2_async_notifier_cleanup - clean up notifier resources
  162. * @notifier: the notifier the resources of which are to be cleaned up
  163. *
  164. * Release memory resources related to a notifier, including the async
  165. * sub-devices allocated for the purposes of the notifier but not the notifier
  166. * itself. The user is responsible for calling this function to clean up the
  167. * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or
  168. * @v4l2_fwnode_reference_parse_sensor_common.
  169. *
  170. * There is no harm from calling v4l2_async_notifier_cleanup in other
  171. * cases as long as its memory has been zeroed after it has been
  172. * allocated.
  173. */
  174. void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
  175. /**
  176. * v4l2_async_register_subdev - registers a sub-device to the asynchronous
  177. * subdevice framework
  178. *
  179. * @sd: pointer to &struct v4l2_subdev
  180. */
  181. int v4l2_async_register_subdev(struct v4l2_subdev *sd);
  182. /**
  183. * v4l2_async_register_subdev_sensor_common - registers a sensor sub-device to
  184. * the asynchronous sub-device
  185. * framework and parse set up common
  186. * sensor related devices
  187. *
  188. * @sd: pointer to struct &v4l2_subdev
  189. *
  190. * This function is just like v4l2_async_register_subdev() with the exception
  191. * that calling it will also parse firmware interfaces for remote references
  192. * using v4l2_async_notifier_parse_fwnode_sensor_common() and registers the
  193. * async sub-devices. The sub-device is similarly unregistered by calling
  194. * v4l2_async_unregister_subdev().
  195. *
  196. * While registered, the subdev module is marked as in-use.
  197. *
  198. * An error is returned if the module is no longer loaded on any attempts
  199. * to register it.
  200. */
  201. int __must_check v4l2_async_register_subdev_sensor_common(
  202. struct v4l2_subdev *sd);
  203. /**
  204. * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
  205. * subdevice framework
  206. *
  207. * @sd: pointer to &struct v4l2_subdev
  208. */
  209. void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
  210. #endif