v4l2-async.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. /**
  20. * enum v4l2_async_match_type - type of asynchronous subdevice logic to be used
  21. * in order to identify a match
  22. *
  23. * @V4L2_ASYNC_MATCH_CUSTOM: Match will use the logic provided by &struct
  24. * v4l2_async_subdev.match ops
  25. * @V4L2_ASYNC_MATCH_DEVNAME: Match will use the device name
  26. * @V4L2_ASYNC_MATCH_I2C: Match will check for I2C adapter ID and address
  27. * @V4L2_ASYNC_MATCH_FWNODE: Match will use firmware node
  28. *
  29. * This enum is used by the asyncrhronous sub-device logic to define the
  30. * algorithm that will be used to match an asynchronous device.
  31. */
  32. enum v4l2_async_match_type {
  33. V4L2_ASYNC_MATCH_CUSTOM,
  34. V4L2_ASYNC_MATCH_DEVNAME,
  35. V4L2_ASYNC_MATCH_I2C,
  36. V4L2_ASYNC_MATCH_FWNODE,
  37. };
  38. /**
  39. * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
  40. *
  41. * @match_type: type of match that will be used
  42. * @match: union of per-bus type matching data sets
  43. * @match.fwnode:
  44. * pointer to &struct fwnode_handle to be matched.
  45. * Used if @match_type is %V4L2_ASYNC_MATCH_FWNODE.
  46. * @match.device_name:
  47. * string containing the device name to be matched.
  48. * Used if @match_type is %V4L2_ASYNC_MATCH_DEVNAME.
  49. * @match.i2c: embedded struct with I2C parameters to be matched.
  50. * Both @match.i2c.adapter_id and @match.i2c.address
  51. * should be matched.
  52. * Used if @match_type is %V4L2_ASYNC_MATCH_I2C.
  53. * @match.i2c.adapter_id:
  54. * I2C adapter ID to be matched.
  55. * Used if @match_type is %V4L2_ASYNC_MATCH_I2C.
  56. * @match.i2c.address:
  57. * I2C address to be matched.
  58. * Used if @match_type is %V4L2_ASYNC_MATCH_I2C.
  59. * @match.custom:
  60. * Driver-specific match criteria.
  61. * Used if @match_type is %V4L2_ASYNC_MATCH_CUSTOM.
  62. * @match.custom.match:
  63. * Driver-specific match function to be used if
  64. * %V4L2_ASYNC_MATCH_CUSTOM.
  65. * @match.custom.priv:
  66. * Driver-specific private struct with match parameters
  67. * to be used if %V4L2_ASYNC_MATCH_CUSTOM.
  68. * @asd_list: used to add struct v4l2_async_subdev objects to the
  69. * master notifier @asd_list
  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 *dev,
  88. struct v4l2_async_subdev *sd);
  89. void *priv;
  90. } custom;
  91. } match;
  92. /* v4l2-async core private: not to be used by drivers */
  93. struct list_head list;
  94. struct list_head asd_list;
  95. };
  96. /**
  97. * struct v4l2_async_notifier_operations - Asynchronous V4L2 notifier operations
  98. * @bound: a subdevice driver has successfully probed one of the subdevices
  99. * @complete: All subdevices have been probed successfully. The complete
  100. * callback is only executed for the root notifier.
  101. * @unbind: a subdevice is leaving
  102. */
  103. struct v4l2_async_notifier_operations {
  104. int (*bound)(struct v4l2_async_notifier *notifier,
  105. struct v4l2_subdev *subdev,
  106. struct v4l2_async_subdev *asd);
  107. int (*complete)(struct v4l2_async_notifier *notifier);
  108. void (*unbind)(struct v4l2_async_notifier *notifier,
  109. struct v4l2_subdev *subdev,
  110. struct v4l2_async_subdev *asd);
  111. };
  112. /**
  113. * struct v4l2_async_notifier - v4l2_device notifier data
  114. *
  115. * @ops: notifier operations
  116. * @v4l2_dev: v4l2_device of the root notifier, NULL otherwise
  117. * @sd: sub-device that registered the notifier, NULL otherwise
  118. * @parent: parent notifier
  119. * @asd_list: master list of struct v4l2_async_subdev
  120. * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
  121. * @done: list of struct v4l2_subdev, already probed
  122. * @list: member in a global list of notifiers
  123. */
  124. struct v4l2_async_notifier {
  125. const struct v4l2_async_notifier_operations *ops;
  126. struct v4l2_device *v4l2_dev;
  127. struct v4l2_subdev *sd;
  128. struct v4l2_async_notifier *parent;
  129. struct list_head asd_list;
  130. struct list_head waiting;
  131. struct list_head done;
  132. struct list_head list;
  133. };
  134. /**
  135. * v4l2_async_notifier_init - Initialize a notifier.
  136. *
  137. * @notifier: pointer to &struct v4l2_async_notifier
  138. *
  139. * This function initializes the notifier @asd_list. It must be called
  140. * before the first call to @v4l2_async_notifier_add_subdev.
  141. */
  142. void v4l2_async_notifier_init(struct v4l2_async_notifier *notifier);
  143. /**
  144. * v4l2_async_notifier_add_subdev - Add an async subdev to the
  145. * notifier's master asd list.
  146. *
  147. * @notifier: pointer to &struct v4l2_async_notifier
  148. * @asd: pointer to &struct v4l2_async_subdev
  149. *
  150. * Call this function before registering a notifier to link the
  151. * provided asd to the notifiers master @asd_list.
  152. */
  153. int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier,
  154. struct v4l2_async_subdev *asd);
  155. /**
  156. * v4l2_async_notifier_add_fwnode_subdev - Allocate and add a fwnode async
  157. * subdev to the notifier's master asd_list.
  158. *
  159. * @notifier: pointer to &struct v4l2_async_notifier
  160. * @fwnode: fwnode handle of the sub-device to be matched
  161. * @asd_struct_size: size of the driver's async sub-device struct, including
  162. * sizeof(struct v4l2_async_subdev). The &struct
  163. * v4l2_async_subdev shall be the first member of
  164. * the driver's async sub-device struct, i.e. both
  165. * begin at the same memory address.
  166. *
  167. * Allocate a fwnode-matched asd of size asd_struct_size, and add it
  168. * to the notifiers @asd_list.
  169. */
  170. struct v4l2_async_subdev *
  171. v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier,
  172. struct fwnode_handle *fwnode,
  173. unsigned int asd_struct_size);
  174. /**
  175. * v4l2_async_notifier_add_i2c_subdev - Allocate and add an i2c async
  176. * subdev to the notifier's master asd_list.
  177. *
  178. * @notifier: pointer to &struct v4l2_async_notifier
  179. * @adapter_id: I2C adapter ID to be matched
  180. * @address: I2C address of sub-device to be matched
  181. * @asd_struct_size: size of the driver's async sub-device struct, including
  182. * sizeof(struct v4l2_async_subdev). The &struct
  183. * v4l2_async_subdev shall be the first member of
  184. * the driver's async sub-device struct, i.e. both
  185. * begin at the same memory address.
  186. *
  187. * Same as above but for I2C matched sub-devices.
  188. */
  189. struct v4l2_async_subdev *
  190. v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier,
  191. int adapter_id, unsigned short address,
  192. unsigned int asd_struct_size);
  193. /**
  194. * v4l2_async_notifier_add_devname_subdev - Allocate and add a device-name
  195. * async subdev to the notifier's master asd_list.
  196. *
  197. * @notifier: pointer to &struct v4l2_async_notifier
  198. * @device_name: device name string to be matched
  199. * @asd_struct_size: size of the driver's async sub-device struct, including
  200. * sizeof(struct v4l2_async_subdev). The &struct
  201. * v4l2_async_subdev shall be the first member of
  202. * the driver's async sub-device struct, i.e. both
  203. * begin at the same memory address.
  204. *
  205. * Same as above but for device-name matched sub-devices.
  206. */
  207. struct v4l2_async_subdev *
  208. v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier,
  209. const char *device_name,
  210. unsigned int asd_struct_size);
  211. /**
  212. * v4l2_async_notifier_register - registers a subdevice asynchronous notifier
  213. *
  214. * @v4l2_dev: pointer to &struct v4l2_device
  215. * @notifier: pointer to &struct v4l2_async_notifier
  216. */
  217. int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
  218. struct v4l2_async_notifier *notifier);
  219. /**
  220. * v4l2_async_subdev_notifier_register - registers a subdevice asynchronous
  221. * notifier for a sub-device
  222. *
  223. * @sd: pointer to &struct v4l2_subdev
  224. * @notifier: pointer to &struct v4l2_async_notifier
  225. */
  226. int v4l2_async_subdev_notifier_register(struct v4l2_subdev *sd,
  227. struct v4l2_async_notifier *notifier);
  228. /**
  229. * v4l2_async_notifier_unregister - unregisters a subdevice
  230. * asynchronous notifier
  231. *
  232. * @notifier: pointer to &struct v4l2_async_notifier
  233. */
  234. void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
  235. /**
  236. * v4l2_async_notifier_cleanup - clean up notifier resources
  237. * @notifier: the notifier the resources of which are to be cleaned up
  238. *
  239. * Release memory resources related to a notifier, including the async
  240. * sub-devices allocated for the purposes of the notifier but not the notifier
  241. * itself. The user is responsible for calling this function to clean up the
  242. * notifier after calling
  243. * @v4l2_async_notifier_add_subdev,
  244. * @v4l2_async_notifier_parse_fwnode_endpoints or
  245. * @v4l2_fwnode_reference_parse_sensor_common.
  246. *
  247. * There is no harm from calling v4l2_async_notifier_cleanup in other
  248. * cases as long as its memory has been zeroed after it has been
  249. * allocated.
  250. */
  251. void v4l2_async_notifier_cleanup(struct v4l2_async_notifier *notifier);
  252. /**
  253. * v4l2_async_register_subdev - registers a sub-device to the asynchronous
  254. * subdevice framework
  255. *
  256. * @sd: pointer to &struct v4l2_subdev
  257. */
  258. int v4l2_async_register_subdev(struct v4l2_subdev *sd);
  259. /**
  260. * v4l2_async_register_subdev_sensor_common - registers a sensor sub-device to
  261. * the asynchronous sub-device
  262. * framework and parse set up common
  263. * sensor related devices
  264. *
  265. * @sd: pointer to struct &v4l2_subdev
  266. *
  267. * This function is just like v4l2_async_register_subdev() with the exception
  268. * that calling it will also parse firmware interfaces for remote references
  269. * using v4l2_async_notifier_parse_fwnode_sensor_common() and registers the
  270. * async sub-devices. The sub-device is similarly unregistered by calling
  271. * v4l2_async_unregister_subdev().
  272. *
  273. * While registered, the subdev module is marked as in-use.
  274. *
  275. * An error is returned if the module is no longer loaded on any attempts
  276. * to register it.
  277. */
  278. int __must_check
  279. v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd);
  280. /**
  281. * v4l2_async_unregister_subdev - unregisters a sub-device to the asynchronous
  282. * subdevice framework
  283. *
  284. * @sd: pointer to &struct v4l2_subdev
  285. */
  286. void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
  287. #endif