[PATCH 2/2] media: atomisp: Report frame interval for sensors without enum_frame_interval
From: Volodymyr Chapman
Date: Mon Nov 16 2026 - 12:58:54 EST
atomisp_enum_frameintervals() passes VIDIOC_ENUM_FRAMEINTERVALS on to the
sensor's enum_frame_interval pad op. Most sensor drivers used with atomisp
do not implement it, e.g. the OV2722 driver only implements
get_frame_interval and raw sensor drivers such as the IMX175 driver set
their frame rate with the pixel rate and blanking controls instead. For
these sensors VIDIOC_ENUM_FRAMEINTERVALS fails, so userspace does not know
the frame rate.
PipeWire's V4L2 source then advertises a framerate range of 1/1 to 120/1.
Firefox (libwebrtc) takes the minimum of such a range as the camera's
maximum framerate and drops all but 1 frame per second, while the sensor
runs at 30 fps.
When the sensor has no enum_frame_interval, report one discrete frame
interval: the sensor's get_frame_interval if it has that, or else the one
following from its V4L2_CID_PIXEL_RATE, V4L2_CID_HBLANK and V4L2_CID_VBLANK
controls and active format, rounded to a whole number of frames per
second. This is the interval of the sensor's current mode, which is
reported for every frame size; for the OV2722 and IMX175 all modes run at
30 fps.
Tested on a Lenovo ThinkPad 10 (20C3, Atom Z3795) with this file built out
of tree against a 7.2.15 kernel: ENUM_FRAMEINTERVALS reports 30 fps for
both the OV2722 front sensor (from get_frame_interval) and the IMX175 rear
sensor (256 MHz / (3430 * 2500)), and webcamtests.com in Firefox 160 shows
about 30 fps for both instead of 1 fps. This was build-tested on top of
media.git next.
The problem was investigated and this patch drafted with the help of an
AI coding assistant (Claude); the testing was done on the hardware by the
submitter.
Signed-off-by: Volodymyr Chapman <volodymyrchapman@xxxxxxxxx>
---
.../staging/media/atomisp/pci/atomisp_ioctl.c | 64 +++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 046a95857..c83834405 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -576,6 +576,65 @@ static int atomisp_enum_framesizes(struct file *file, void *priv,
return 0;
}
+/*
+ * For sensors without enum_frame_interval, get the frame interval of the
+ * sensor's current mode: from get_frame_interval, or else from the pixel rate
+ * and blanking controls which raw sensor drivers use to set the frame rate.
+ */
+static int atomisp_sensor_frame_interval(struct atomisp_input_subdev *input,
+ struct v4l2_fract *interval)
+{
+ struct v4l2_subdev_frame_interval fi = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
+ struct v4l2_ctrl *pixel_rate, *hblank, *vblank;
+ struct v4l2_subdev_state *act_sd_state;
+ u64 frame_size, fps;
+ int ret;
+
+ act_sd_state = v4l2_subdev_lock_and_get_active_state(input->sensor);
+ ret = v4l2_subdev_call(input->sensor, pad, get_frame_interval,
+ act_sd_state, &fi);
+ if (ret != -ENOIOCTLCMD) {
+ if (act_sd_state)
+ v4l2_subdev_unlock_state(act_sd_state);
+ if (ret)
+ return ret;
+ if (!fi.interval.numerator || !fi.interval.denominator)
+ return -EINVAL;
+ *interval = fi.interval;
+ return 0;
+ }
+
+ ret = v4l2_subdev_call(input->sensor, pad, get_fmt, act_sd_state, &fmt);
+ if (act_sd_state)
+ v4l2_subdev_unlock_state(act_sd_state);
+ if (ret)
+ return ret;
+
+ pixel_rate = v4l2_ctrl_find(input->sensor->ctrl_handler,
+ V4L2_CID_PIXEL_RATE);
+ hblank = v4l2_ctrl_find(input->sensor->ctrl_handler, V4L2_CID_HBLANK);
+ vblank = v4l2_ctrl_find(input->sensor->ctrl_handler, V4L2_CID_VBLANK);
+ if (!pixel_rate || !hblank || !vblank)
+ return -EINVAL;
+
+ frame_size = (u64)(fmt.format.width + v4l2_ctrl_g_ctrl(hblank)) *
+ (fmt.format.height + v4l2_ctrl_g_ctrl(vblank));
+ fps = div64_u64(v4l2_ctrl_g_ctrl_int64(pixel_rate) + frame_size / 2,
+ frame_size);
+ if (!fps)
+ return -EINVAL;
+
+ interval->numerator = 1;
+ interval->denominator = fps;
+
+ return 0;
+}
+
static int atomisp_enum_frameintervals(struct file *file, void *priv,
struct v4l2_frmivalenum *fival)
{
@@ -601,6 +660,11 @@ static int atomisp_enum_frameintervals(struct file *file, void *priv,
act_sd_state, &fie);
if (act_sd_state)
v4l2_subdev_unlock_state(act_sd_state);
+ if (ret == -ENOIOCTLCMD) {
+ if (fival->index)
+ return -EINVAL;
+ ret = atomisp_sensor_frame_interval(input, &fie.interval);
+ }
if (ret)
return ret;
--
2.43.0