OSDN Git Service

media: v4l: Add a helper for obtaining the link frequency
authorSakari Ailus <sakari.ailus@linux.intel.com>
Tue, 13 Oct 2020 14:54:00 +0000 (16:54 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 16 Nov 2020 09:31:15 +0000 (10:31 +0100)
Add a helper for obtaining the link frequency from transmitter drivers.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/v4l2-core/v4l2-common.c
include/media/v4l2-common.h

index 3dc17eb..78007db 100644 (file)
@@ -441,3 +441,36 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
        return 0;
 }
 EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt);
+
+s64 v4l2_get_link_rate(struct v4l2_ctrl_handler *handler, unsigned int mul,
+                      unsigned int div)
+{
+       struct v4l2_ctrl *ctrl;
+       s64 freq;
+
+       ctrl = v4l2_ctrl_find(handler, V4L2_CID_LINK_FREQ);
+       if (ctrl) {
+               struct v4l2_querymenu qm = { .id = V4L2_CID_LINK_FREQ };
+               int ret;
+
+               qm.index = v4l2_ctrl_g_ctrl(ctrl);
+
+               ret = v4l2_querymenu(handler, &qm);
+               if (ret)
+                       return -ENOENT;
+
+               freq = qm.value;
+       } else {
+               if (!mul || !div)
+                       return -ENOENT;
+
+               ctrl = v4l2_ctrl_find(handler, V4L2_CID_PIXEL_RATE);
+               if (!ctrl)
+                       return -ENOENT;
+
+               freq = div_u64(v4l2_ctrl_g_ctrl_int64(ctrl) * mul, div);
+       }
+
+       return freq > 0 ? freq : -EINVAL;
+}
+EXPORT_SYMBOL_GPL(v4l2_get_link_rate);
index a308352..be36cbd 100644 (file)
@@ -519,6 +519,27 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
 int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat,
                        u32 width, u32 height);
 
+/**
+ * v4l2_get_link_rate - Get link rate from transmitter
+ *
+ * @handler: The transmitter's control handler
+ * @mul: The multiplier between pixel rate and link frequency. Bits per pixel on
+ *      D-PHY, samples per clock on parallel. 0 otherwise.
+ * @div: The divisor between pixel rate and link frequency. Number of data lanes
+ *      times two on D-PHY, 1 on parallel. 0 otherwise.
+ *
+ * This function is intended for obtaining the link frequency from the
+ * transmitter sub-devices. It returns the link rate, either from the
+ * V4L2_CID_LINK_FREQ control implemented by the transmitter, or value
+ * calculated based on the V4L2_CID_PIXEL_RATE implemented by the transmitter.
+ *
+ * Returns link frequency on success, otherwise a negative error code:
+ *     -ENOENT: Link frequency or pixel rate control not found
+ *     -EINVAL: Invalid link frequency value
+ */
+s64 v4l2_get_link_rate(struct v4l2_ctrl_handler *handler, unsigned int mul,
+                      unsigned int div);
+
 static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
 {
        /*