Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Greybus Camera protocol driver.
0004  *
0005  * Copyright 2015 Google Inc.
0006  */
0007 #ifndef __GB_CAMERA_H
0008 #define __GB_CAMERA_H
0009 
0010 #include <linux/v4l2-mediabus.h>
0011 
0012 /* Input flags need to be set from the caller */
0013 #define GB_CAMERA_IN_FLAG_TEST      (1 << 0)
0014 /* Output flags returned */
0015 #define GB_CAMERA_OUT_FLAG_ADJUSTED (1 << 0)
0016 
0017 /**
0018  * struct gb_camera_stream - Represents greybus camera stream.
0019  * @width: Stream width in pixels.
0020  * @height: Stream height in pixels.
0021  * @pixel_code: Media bus pixel code.
0022  * @vc: MIPI CSI virtual channel.
0023  * @dt: MIPI CSI data types. Most formats use a single data type, in which case
0024  *      the second element will be ignored.
0025  * @max_size: Maximum size of a frame in bytes. The camera module guarantees
0026  *            that all data between the Frame Start and Frame End packet for
0027  *            the associated virtual channel and data type(s) will not exceed
0028  *            this size.
0029  */
0030 struct gb_camera_stream {
0031     unsigned int width;
0032     unsigned int height;
0033     enum v4l2_mbus_pixelcode pixel_code;
0034     unsigned int vc;
0035     unsigned int dt[2];
0036     unsigned int max_size;
0037 };
0038 
0039 /**
0040  * struct gb_camera_csi_params - CSI configuration parameters
0041  * @num_lanes: number of CSI data lanes
0042  * @clk_freq: CSI clock frequency in Hz
0043  */
0044 struct gb_camera_csi_params {
0045     unsigned int num_lanes;
0046     unsigned int clk_freq;
0047 };
0048 
0049 /**
0050  * struct gb_camera_ops - Greybus camera operations, used by the Greybus camera
0051  *                        driver to expose operations to the host camera driver.
0052  * @capabilities: Retrieve camera capabilities and store them in the buffer
0053  *                'buf' capabilities. The buffer maximum size is specified by
0054  *                the caller in the 'size' parameter, and the effective
0055  *                capabilities size is returned from the function. If the buffer
0056  *                size is too small to hold the capabilities an error is
0057  *                returned and the buffer is left untouched.
0058  *
0059  * @configure_streams: Negotiate configuration and prepare the module for video
0060  *                     capture. The caller specifies the number of streams it
0061  *                     requests in the 'nstreams' argument and the associated
0062  *                     streams configurations in the 'streams' argument. The
0063  *                     GB_CAMERA_IN_FLAG_TEST 'flag' can be set to test a
0064  *                     configuration without applying it, otherwise the
0065  *                     configuration is applied by the module. The module can
0066  *                     decide to modify the requested configuration, including
0067  *                     using a different number of streams. In that case the
0068  *                     modified configuration won't be applied, the
0069  *                     GB_CAMERA_OUT_FLAG_ADJUSTED 'flag' will be set upon
0070  *                     return, and the modified configuration and number of
0071  *                     streams stored in 'streams' and 'array'. The module
0072  *                     returns its CSI-2 bus parameters in the 'csi_params'
0073  *                     structure in all cases.
0074  *
0075  * @capture: Submit a capture request. The supplied 'request_id' must be unique
0076  *           and higher than the IDs of all the previously submitted requests.
0077  *           The 'streams' argument specifies which streams are affected by the
0078  *           request in the form of a bitmask, with bits corresponding to the
0079  *           configured streams indexes. If the request contains settings, the
0080  *           'settings' argument points to the settings buffer and its size is
0081  *           specified by the 'settings_size' argument. Otherwise the 'settings'
0082  *           argument should be set to NULL and 'settings_size' to 0.
0083  *
0084  * @flush: Flush the capture requests queue. Return the ID of the last request
0085  *         that will processed by the device before it stops transmitting video
0086  *         frames. All queued capture requests with IDs higher than the returned
0087  *         ID will be dropped without being processed.
0088  */
0089 struct gb_camera_ops {
0090     ssize_t (*capabilities)(void *priv, char *buf, size_t len);
0091     int (*configure_streams)(void *priv, unsigned int *nstreams,
0092             unsigned int *flags, struct gb_camera_stream *streams,
0093             struct gb_camera_csi_params *csi_params);
0094     int (*capture)(void *priv, u32 request_id,
0095             unsigned int streams, unsigned int num_frames,
0096             size_t settings_size, const void *settings);
0097     int (*flush)(void *priv, u32 *request_id);
0098 };
0099 
0100 /**
0101  * struct gb_camera_module - Represents greybus camera module.
0102  * @priv: Module private data, passed to all camera operations.
0103  * @ops: Greybus camera operation callbacks.
0104  * @interface_id: Interface id of the module.
0105  * @refcount: Reference counting object.
0106  * @release: Module release function.
0107  * @list: List entry in the camera modules list.
0108  */
0109 struct gb_camera_module {
0110     void *priv;
0111     const struct gb_camera_ops *ops;
0112 
0113     unsigned int interface_id;
0114     struct kref refcount;
0115     void (*release)(struct kref *kref);
0116     struct list_head list; /* Global list */
0117 };
0118 
0119 #define gb_camera_call(f, op, args...)      \
0120     (!(f) ? -ENODEV : (((f)->ops->op) ?  \
0121     (f)->ops->op((f)->priv, ##args) : -ENOIOCTLCMD))
0122 
0123 int gb_camera_register(struct gb_camera_module *module);
0124 int gb_camera_unregister(struct gb_camera_module *module);
0125 
0126 #endif /* __GB_CAMERA_H */