Skip to content

Commit 6417c8e

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 711c3f2 commit 6417c8e

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

drivers/video/video_common.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <zephyr/kernel.h>
1111
#include <zephyr/drivers/video.h>
12+
#include <zephyr/drivers/video-controls.h>
1213

1314
#if defined(CONFIG_VIDEO_BUFFER_USE_SHARED_MULTI_HEAP)
1415
#include <zephyr/multi_heap/shared_multi_heap.h>
@@ -164,3 +165,27 @@ void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
164165
}
165166
}
166167
}
168+
169+
int64_t video_get_link_frequency(const struct device *dev, uint8_t bpp, uint8_t lane_nb)
170+
{
171+
int ret;
172+
173+
struct video_control ctrl = {
174+
.id = VIDEO_CID_LINK_FREQUENCY,
175+
};
176+
177+
/* Try to get the LINK_FREQUENCY value from the source device */
178+
ret = video_get_ctrl(dev, &ctrl);
179+
if (ret == 0) {
180+
return ctrl.val64;
181+
}
182+
183+
/* If VIDEO_CID_LINK_FREQUENCY is not available, approximate from VIDEO_CID_PIXEL_RATE */
184+
ctrl.id = VIDEO_CID_PIXEL_RATE;
185+
ret = video_get_ctrl(dev, &ctrl);
186+
if (ret < 0) {
187+
return ret;
188+
}
189+
190+
return ctrl.val64 * bpp / (2 * lane_nb);
191+
}

drivers/video/video_ctrls.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ static inline void set_type_flag(uint32_t id, enum video_ctrl_type *type, uint32
8181
*type = VIDEO_CTRL_TYPE_INTEGER64;
8282
*flags |= VIDEO_CTRL_FLAG_READ_ONLY;
8383
break;
84+
case VIDEO_CID_LINK_FREQUENCY:
85+
*type = VIDEO_CTRL_TYPE_INTEGER64;
86+
*flags |= VIDEO_CTRL_FLAG_READ_ONLY;
87+
break;
8488
default:
8589
*type = VIDEO_CTRL_TYPE_INTEGER;
8690
break;
@@ -416,6 +420,8 @@ static inline const char *video_get_ctrl_name(uint32_t id)
416420
return "Pixel Rate";
417421
case VIDEO_CID_TEST_PATTERN:
418422
return "Test Pattern";
423+
case VIDEO_CID_LINK_FREQUENCY:
424+
return "Link Frequency";
419425
default:
420426
return NULL;
421427
}

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)