gb-camera.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Greybus Camera protocol driver.
  3. *
  4. * Copyright 2015 Google Inc.
  5. *
  6. * Released under the GPLv2 only.
  7. */
  8. #ifndef __GB_CAMERA_H
  9. #define __GB_CAMERA_H
  10. #include <linux/v4l2-mediabus.h>
  11. /* Input flags need to be set from the caller */
  12. #define GB_CAMERA_IN_FLAG_TEST (1 << 0)
  13. /* Output flags returned */
  14. #define GB_CAMERA_OUT_FLAG_ADJUSTED (1 << 0)
  15. /**
  16. * struct gb_camera_stream - Represents greybus camera stream.
  17. * @width: Stream width in pixels.
  18. * @height: Stream height in pixels.
  19. * @pixel_code: Media bus pixel code.
  20. * @vc: MIPI CSI virtual channel.
  21. * @dt: MIPI CSI data types. Most formats use a single data type, in which case
  22. * the second element will be ignored.
  23. * @max_size: Maximum size of a frame in bytes. The camera module guarantees
  24. * that all data between the Frame Start and Frame End packet for
  25. * the associated virtual channel and data type(s) will not exceed
  26. * this size.
  27. */
  28. struct gb_camera_stream {
  29. unsigned int width;
  30. unsigned int height;
  31. enum v4l2_mbus_pixelcode pixel_code;
  32. unsigned int vc;
  33. unsigned int dt[2];
  34. unsigned int max_size;
  35. };
  36. /**
  37. * struct gb_camera_csi_params - CSI configuration parameters
  38. * @num_lanes: number of CSI data lanes
  39. * @clk_freq: CSI clock frequency in Hz
  40. */
  41. struct gb_camera_csi_params {
  42. unsigned int num_lanes;
  43. unsigned int clk_freq;
  44. };
  45. /**
  46. * struct gb_camera_ops - Greybus camera operations, used by the Greybus camera
  47. * driver to expose operations to the host camera driver.
  48. * @capabilities: Retrieve camera capabilities and store them in the buffer
  49. * 'buf' capabilities. The buffer maximum size is specified by
  50. * the caller in the 'size' parameter, and the effective
  51. * capabilities size is returned from the function. If the buffer
  52. * size is too small to hold the capabilities an error is
  53. * returned and the buffer is left untouched.
  54. *
  55. * @configure_streams: Negotiate configuration and prepare the module for video
  56. * capture. The caller specifies the number of streams it
  57. * requests in the 'nstreams' argument and the associated
  58. * streams configurations in the 'streams' argument. The
  59. * GB_CAMERA_IN_FLAG_TEST 'flag' can be set to test a
  60. * configuration without applying it, otherwise the
  61. * configuration is applied by the module. The module can
  62. * decide to modify the requested configuration, including
  63. * using a different number of streams. In that case the
  64. * modified configuration won't be applied, the
  65. * GB_CAMERA_OUT_FLAG_ADJUSTED 'flag' will be set upon
  66. * return, and the modified configuration and number of
  67. * streams stored in 'streams' and 'array'. The module
  68. * returns its CSI-2 bus parameters in the 'csi_params'
  69. * structure in all cases.
  70. *
  71. * @capture: Submit a capture request. The supplied 'request_id' must be unique
  72. * and higher than the IDs of all the previously submitted requests.
  73. * The 'streams' argument specifies which streams are affected by the
  74. * request in the form of a bitmask, with bits corresponding to the
  75. * configured streams indexes. If the request contains settings, the
  76. * 'settings' argument points to the settings buffer and its size is
  77. * specified by the 'settings_size' argument. Otherwise the 'settings'
  78. * argument should be set to NULL and 'settings_size' to 0.
  79. *
  80. * @flush: Flush the capture requests queue. Return the ID of the last request
  81. * that will processed by the device before it stops transmitting video
  82. * frames. All queued capture requests with IDs higher than the returned
  83. * ID will be dropped without being processed.
  84. */
  85. struct gb_camera_ops {
  86. ssize_t (*capabilities)(void *priv, char *buf, size_t len);
  87. int (*configure_streams)(void *priv, unsigned int *nstreams,
  88. unsigned int *flags, struct gb_camera_stream *streams,
  89. struct gb_camera_csi_params *csi_params);
  90. int (*capture)(void *priv, u32 request_id,
  91. unsigned int streams, unsigned int num_frames,
  92. size_t settings_size, const void *settings);
  93. int (*flush)(void *priv, u32 *request_id);
  94. };
  95. /**
  96. * struct gb_camera_module - Represents greybus camera module.
  97. * @priv: Module private data, passed to all camera operations.
  98. * @ops: Greybus camera operation callbacks.
  99. * @interface_id: Interface id of the module.
  100. * @refcount: Reference counting object.
  101. * @release: Module release function.
  102. * @list: List entry in the camera modules list.
  103. */
  104. struct gb_camera_module {
  105. void *priv;
  106. const struct gb_camera_ops *ops;
  107. unsigned int interface_id;
  108. struct kref refcount;
  109. void (*release)(struct kref *kref);
  110. struct list_head list; /* Global list */
  111. };
  112. #define gb_camera_call(f, op, args...) \
  113. (!(f) ? -ENODEV : (((f)->ops->op) ? \
  114. (f)->ops->op((f)->priv, ##args) : -ENOIOCTLCMD))
  115. int gb_camera_register(struct gb_camera_module *module);
  116. int gb_camera_unregister(struct gb_camera_module *module);
  117. #endif /* __GB_CAMERA_H */