Skip to content

Commit 455b0e7

Browse files
author
Alain Volmat
committed
video: add LINK_FREQUENCY ctrl and a helper to retrieve it
Add a read-only ctrl VIDEO_CID_LINK_FREQUENCY to indicate to a sink the frequency at which a device streams data over CSI2. Since not all source device currently provide the LINK_FREQUENCY control, add a helper function to retrieve it, with a fall-back by doing an approximate via the PIXEL_RATE control. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1 parent 97c96de commit 455b0e7

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

drivers/video/video_common.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <zephyr/device.h>
1111
#include <zephyr/drivers/i2c.h>
1212
#include <zephyr/drivers/video.h>
13+
#include <zephyr/drivers/video-controls.h>
1314
#include <zephyr/kernel.h>
1415
#include <zephyr/logging/log.h>
1516
#include <zephyr/sys/byteorder.h>
@@ -342,3 +343,27 @@ int video_write_cci_multiregs16(const struct i2c_dt_spec *i2c, const struct vide
342343

343344
return 0;
344345
}
346+
347+
int64_t video_get_link_frequency(const struct device *dev, uint8_t bpp, uint8_t lane_nb)
348+
{
349+
int ret;
350+
351+
struct video_control ctrl = {
352+
.id = VIDEO_CID_LINK_FREQUENCY,
353+
};
354+
355+
/* Try to get the LINK_FREQUENCY value from the source device */
356+
ret = video_get_ctrl(dev, &ctrl);
357+
if (ret == 0) {
358+
return ctrl.val64;
359+
}
360+
361+
/* If VIDEO_CID_LINK_FREQUENCY is not available, approximate from VIDEO_CID_PIXEL_RATE */
362+
ctrl.id = VIDEO_CID_PIXEL_RATE;
363+
ret = video_get_ctrl(dev, &ctrl);
364+
if (ret < 0) {
365+
return ret;
366+
}
367+
368+
return ctrl.val64 * bpp / (2 * lane_nb);
369+
}

drivers/video/video_ctrls.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static inline void set_type_flag(uint32_t id, enum video_ctrl_type *type, uint32
7878
*type = VIDEO_CTRL_TYPE_MENU;
7979
break;
8080
case VIDEO_CID_PIXEL_RATE:
81+
case VIDEO_CID_LINK_FREQUENCY:
8182
*type = VIDEO_CTRL_TYPE_INTEGER64;
8283
*flags |= VIDEO_CTRL_FLAG_READ_ONLY;
8384
break;
@@ -416,6 +417,8 @@ static inline const char *video_get_ctrl_name(uint32_t id)
416417
return "Pixel Rate";
417418
case VIDEO_CID_TEST_PATTERN:
418419
return "Test Pattern";
420+
case VIDEO_CID_LINK_FREQUENCY:
421+
return "Link Frequency";
419422
default:
420423
return NULL;
421424
}

include/zephyr/drivers/video-controls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ enum video_exposure_auto_type {
171171
/** Selection of the type of test pattern to represent */
172172
#define VIDEO_CID_TEST_PATTERN (VIDEO_CID_IMAGE_PROC_CLASS_BASE + 3)
173173

174+
/** Link frequency, applicable for the CSI2 based devices. This control is read-only. */
175+
#define VIDEO_CID_LINK_FREQUENCY (VIDEO_CID_IMAGE_PROC_CLASS_BASE + 4)
176+
174177
/**
175178
* @}
176179
*/

include/zephyr/drivers/video.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,23 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis
819819
void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
820820
struct video_frmival_enum *match);
821821

822+
/**
823+
* @brief Return the link-frequency advertised by a device
824+
*
825+
* Device exposing a CSI link will should advertise at least one of the following two controls:
826+
* VIDEO_CID_LINK_FREQUENCY
827+
* VIDEO_CID_PIXEL_RATE
828+
*
829+
* At first the helper will try read the VIDEO_CID_LINK_FREQUENCY and if not available will
830+
* approximate the link-frequency from the VIDEO_CID_PIXEL_RATE value, taking into consideration
831+
* the bits per pixel of the format and the number of lanes.
832+
*
833+
* @param dev Video device to query.
834+
* @param bpp Amount of bits per pixel of the pixel format produced by the device
835+
* @param lane_nb Number of CSI-2 lanes used
836+
*/
837+
int64_t video_get_link_frequency(const struct device *dev, uint8_t bpp, uint8_t lane_nb);
838+
822839
/**
823840
* @defgroup video_pixel_formats Video pixel formats
824841
* The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.

0 commit comments

Comments
 (0)