v4l2-async.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. enum v4l2_async_match_type {
  22. V4L2_ASYNC_MATCH_CUSTOM,
  23. V4L2_ASYNC_MATCH_DEVNAME,
  24. V4L2_ASYNC_MATCH_I2C,
  25. V4L2_ASYNC_MATCH_OF,
  26. };
  27. /**
  28. * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
  29. * @bus_type: subdevice bus type to select the appropriate matching method
  30. * @match: union of per-bus type matching data sets
  31. * @list: used to link struct v4l2_async_subdev objects, waiting to be
  32. * probed, to a notifier->waiting list
  33. */
  34. struct v4l2_async_subdev {
  35. enum v4l2_async_match_type match_type;
  36. union {
  37. struct {
  38. const struct device_node *node;
  39. } of;
  40. struct {
  41. const char *name;
  42. } device_name;
  43. struct {
  44. int adapter_id;
  45. unsigned short address;
  46. } i2c;
  47. struct {
  48. bool (*match)(struct device *,
  49. struct v4l2_async_subdev *);
  50. void *priv;
  51. } custom;
  52. } match;
  53. /* v4l2-async core private: not to be used by drivers */
  54. struct list_head list;
  55. };
  56. /**
  57. * v4l2_async_subdev_list - provided by subdevices
  58. * @list: links struct v4l2_async_subdev_list objects to a global list
  59. * before probing, and onto notifier->done after probing
  60. * @asd: pointer to respective struct v4l2_async_subdev
  61. * @notifier: pointer to managing notifier
  62. */
  63. struct v4l2_async_subdev_list {
  64. struct list_head list;
  65. struct v4l2_async_subdev *asd;
  66. struct v4l2_async_notifier *notifier;
  67. };
  68. /**
  69. * v4l2_async_notifier - v4l2_device notifier data
  70. * @num_subdevs:number of subdevices
  71. * @subdev: array of pointers to subdevice descriptors
  72. * @v4l2_dev: pointer to struct v4l2_device
  73. * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
  74. * @done: list of struct v4l2_async_subdev_list, already probed
  75. * @list: member in a global list of notifiers
  76. * @bound: a subdevice driver has successfully probed one of subdevices
  77. * @complete: all subdevices have been probed successfully
  78. * @unbind: a subdevice is leaving
  79. */
  80. struct v4l2_async_notifier {
  81. unsigned int num_subdevs;
  82. struct v4l2_async_subdev **subdev;
  83. struct v4l2_device *v4l2_dev;
  84. struct list_head waiting;
  85. struct list_head done;
  86. struct list_head list;
  87. int (*bound)(struct v4l2_async_notifier *notifier,
  88. struct v4l2_subdev *subdev,
  89. struct v4l2_async_subdev *asd);
  90. int (*complete)(struct v4l2_async_notifier *notifier);
  91. void (*unbind)(struct v4l2_async_notifier *notifier,
  92. struct v4l2_subdev *subdev,
  93. struct v4l2_async_subdev *asd);
  94. };
  95. int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
  96. struct v4l2_async_notifier *notifier);
  97. void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
  98. int v4l2_async_register_subdev(struct v4l2_subdev *sd);
  99. void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
  100. #endif