v4l2-async.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. * @asd_list: used to add struct v4l2_async_subdev objects to the
  71. * master notifier @asd_list
  72. * @list: used to link struct v4l2_async_subdev objects, waiting to be
  73. * probed, to a notifier->waiting list
  74. *
  75. * When this struct is used as a member in a driver specific struct,
  76. * the driver specific struct shall contain the &struct
  77. * v4l2_async_subdev as its first member.
  78. */
  79. struct v4l2_async_subdev {
  80. enum v4l2_async_match_type match_type;
  81. union {
  82. struct fwnode_handle *fwnode;
  83. const char *device_name;
  84. struct {
  85. int adapter_id;
  86. unsigned short address;
  87. } i2c;
  88. struct {
  89. bool (*match)(struct device *,
  90. struct v4l2_async_subdev *);
  91. void *priv;
  92. } custom;
  93. } match;
  94. /* v4l2-async core private: not to be used by drivers */
  95. struct list_head list;
  96. struct list_head asd_list;
  97. };
  98. /**
  99. * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
  100. * @bound: a subdevice driver has successfully probed one of the subdevices
  101. * @complete: All subdevices have been probed successfully. The complete
  102. * callback is only executed for the root notifier.
  103. * @unbind: a subdevice is leaving
  104. */
  105. struct v4l2_async_notifier_operations {
  106. int (*bound)(struct v4l2_async_notifier *notifier,
  107. struct v4l2_subdev *subdev,
  108. struct v4l2_async_subdev *asd);
  109. int (*complete)(struct v4l2_async_notifier *notifier);
  110. void (*unbind)(struct v4l2_async_notifier *notifier,
  111. struct v4l2_subdev *subdev,
  112. struct v4l2_async_subdev *asd);
  113. };
  114. /**
  115. * struct v4l2_async_notifier - v4l2_device notifier data
  116. *
  117. * @ops: notifier operations
  118. * @num_subdevs: number of subdevices used in the subdevs array
  119. * @max_subdevs: number of subdevices allocated in the subdevs array
  120. * @subdevs: array of pointers to subdevice descriptors
  121. * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
  122. * @sd: sub-device that registered the notifier, NULL otherwise
  123. * @parent: parent notifier
  124. * @asd_list: master list of struct v4l2_async_subdev, replaces @subdevs
  125. * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
  126. * @done: list of struct v4l2_subdev, already probed
  127. * @list: member in a global list of notifiers
  128. */
  129. struct v4l2_async_notifier {
  130. const struct v4l2_async_notifier_operations *ops;
  131. unsigned int num_subdevs;
  132. unsigned int max_subdevs;
  133. struct v4l2_async_subdev **subdevs;
  134. struct v4l2_device *v4l2_dev;
  135. struct v4l2_subdev *sd;
  136. struct v4l2_async_notifier *parent;
  137. struct list_head asd_list;
  138. struct list_head waiting;
  139. struct list_head done;
  140. struct list_head list;
  141. };
  142. /**
  143. * v4l2_async_notifier_init - Initialize a notifier.
  144. *
  145. * @notifier: pointer to &struct v4l2_async_notifier
  146. *
  147. * This function initializes the notifier @asd_list. It must be called
  148. * before the first call to @v4l2_async_notifier_add_subdev.
  149. */
  150. void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier);
  151. /**
  152. * v4l2_async_notifier_add_subdev - Add an async subdev to the
  153. * notifier's master asd list.
  154. *
  155. * @notifier: pointer to &struct v4l2_async_notifier
  156. * @asd: pointer to &struct v4l2_async_subdev
  157. *
  158. * This can be used before registering a notifier to add an
  159. * asd to the notifiers @asd_list. If the caller uses this
  160. * method to compose an asd list, it must never allocate
  161. * or place asd's in the @subdevs array.
  162. */
  163. int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
  164. struct v4l2_async_subdev *asd);
  165. /**
  166. * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
  167. *
  168. * @v4l2_dev: pointer to &struct v4l2_device
  169. * @notifier: pointer to &struct v4l2_async_notifier
  170. */
  171. int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
  172. struct v4l2_async_notifier *notifier);
  173. /**
  174. * v4l2_async_subdev_notifier_register - registers a subdevice asynchronous
  175. * notifier for a sub-device
  176. *
  177. * @sd: pointer to &struct v4l2_subdev
  178. * @notifier: pointer to &struct v4l2_async_notifier
  179. */
  180. int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd,
  181. struct v4l2_async_notifier *notifier);
  182. /**
  183. * v4l2_async_notifier_unregister - unregisters a subdevice asynchronous notifier
  184. *
  185. * @notifier: pointer to &struct v4l2_async_notifier
  186. */
  187. void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
  188. /**
  189. * v4l2_async_notifier_cleanup - clean up notifier resources
  190. * @notifier: the notifier the resources of which are to be cleaned up
  191. *
  192. * Release memory resources related to a notifier, including the async
  193. * sub-devices allocated for the purposes of the notifier but not the notifier
  194. * itself. The user is responsible for calling this function to clean up the
  195. * notifier after calling
  196. * @v4l2_async_notifier_add_subdev,
  197. * @v4l2_async_notifier_parse_fwnode_endpoints or
  198. * @v4l2_fwnode_reference_parse_sensor_common.
  199. *
  200. * There is no harm from calling v4l2_async_notifier_cleanup in other
  201. * cases as long as its memory has been zeroed after it has been
  202. * allocated.
  203. */
  204. void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
  205. /**
  206. * v4l2_async_register_subdev - registers a sub-device to the asynchronous
  207. * subdevice framework
  208. *
  209. * @sd: pointer to &struct v4l2_subdev
  210. */
  211. int v4l2_async_register_subdev(struct v4l2_subdev *sd);
  212. /**
  213. * v4l2_async_register_subdev_sensor_common - registers a sensor sub-device to
  214. * the asynchronous sub-device
  215. * framework and parse set up common
  216. * sensor related devices
  217. *
  218. * @sd: pointer to struct &v4l2_subdev
  219. *
  220. * This function is just like v4l2_async_register_subdev() with the exception
  221. * that calling it will also parse firmware interfaces for remote references
  222. * using v4l2_async_notifier_parse_fwnode_sensor_common() and registers the
  223. * async sub-devices. The sub-device is similarly unregistered by calling
  224. * v4l2_async_unregister_subdev().
  225. *
  226. * While registered, the subdev module is marked as in-use.
  227. *
  228. * An error is returned if the module is no longer loaded on any attempts
  229. * to register it.
  230. */
  231. int __must_check v4l2_async_register_subdev_sensor_common(
  232. struct v4l2_subdev *sd);
  233. /**
  234. * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
  235. * subdevice framework
  236. *
  237. * @sd: pointer to &struct v4l2_subdev
  238. */
  239. void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
  240. #endif