From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=213.167.242.64 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796009284; b=mb91dZzHnpBA1Wm4ozzadFFtxj/Pqn2IjRZPEeVQvpv/Q/ZQnzxH8eByVhoM3ERkEcOk g5iF0BpcF7Wjj06WPbPb9Jn//y06fFxbttHw62IcDkQ/VRiHZzhdrt0vmQBf4eZMb+laR s/WuDfRzR3HOD9Vkoz6A3dzZDFTcJKigWy4dEyyw15Tyxqp1EL3lhwspwE5KrwJ0FmacA jIcpkRTEwzVcg7lkZ+iATyN3OzR/7Vz2FSnnu8A3Yv1fQtMhMy2Q10l8+nrCIR1DZTMRe 1vXbEcnTZzFiNkWxh/e3Ra+IcdBumBwwwdX++nh3cW37dZLYjqY7S3HYwSGPLP1nljA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796009284; h=DMARC-Filter:Received:DKIM-Signature:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; bh=2KuQIYH4/royY7vc0xbwmFkhbHHi03+CQxFVVUwJ9eA=; b=GvwCDtjonaJmBG6fIZWXHLNrG7qNJgJxLqoc4RfS6VPANAVUkrMMIzvf91sMJp+XtsD7 IAFnhkkhC3RPq4Cng9UNW4VqKgau+oyijxm5dmuPY4K8gY3lp9STG6Pd+GMD8LFCo2J4r UXJNnUeEog/AHAny+LK34GIThNLg93tqOuaWXDmm0eJyB2sZd5ArGS+13SdTHhT8OyYNo uwCneGVjg7E0uJ53G/uKvyHJ/ZisWNVZPS/7C7Z51ZeuZu9BcHaHfgrRGoq7il91CZtcK NqTzor3Hs2WLC/sKDaT3LzYMxsBL03LGtrahvO6l3jPtWJ+EADqW7z8HIgXQuapf2+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=sO9PiIII; arc=none smtp.remote-ip=213.167.242.64 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 999A0606A31C; Mon, 30 Nov 2026 03:28:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 999A0606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=sO9PiIII Received: from killaraus.ideasonboard.com (sp49-96-232-4.msc.dcmisp.ne.jp [49.96.232.4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A8B582F8; Mon, 30 Nov 2026 04:25:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796009124; bh=iUGDcCKsFIXrfBftQhAwGvBxajX6AZ+BLZit51KsDfk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sO9PiIIIAt4hxopF7IeY2xK0Opoz33DEsV5/lSQqsemUhlyo3UFnKz2EXdW479MNO cBFItcqXItwJyfsNpwLC+Swy1ZI5+gxiJEFSlRVcArbNuKe+VYMXcSPUYGZQANQeIr Ynt8QU9tU217YIIGA0/tO6jPFi2DsaopvLYIyL48= Date: Mon, 30 Nov 2026 12:27:51 +0900 From: Laurent Pinchart To: Dave Stevenson Cc: Sakari Ailus , Jai Luthra , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Alexander Shiyan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v7 06/18] media: sony-starvis2: Allow runtime control of link frequency Message-ID: <20261130032751.GA24781@killaraus.ideasonboard.com> References: <20261029-media-starvis2-v7-0-b33a1332fdfc@raspberrypi.com> <20261029-media-starvis2-v7-6-b33a1332fdfc@raspberrypi.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20261029-media-starvis2-v7-6-b33a1332fdfc@raspberrypi.com> On Thu, Oct 29, 2026 at 02:18:27PM +0000, Dave Stevenson wrote: > DT allows configuration of multiple link frequencies. > V4L2_CID_LINK_FREQ allows read write control. > > Join these up so that link frequency can be configured at run time, > as long as the sensor isn't streaming. > > Signed-off-by: Dave Stevenson > --- > drivers/media/i2c/sony-starvis2.c | 79 +++++++++++++++++++++++++++------------ > 1 file changed, 55 insertions(+), 24 deletions(-) > > diff --git a/drivers/media/i2c/sony-starvis2.c b/drivers/media/i2c/sony-starvis2.c > index 5dcd760c1a27..340f2ff0ef87 100644 > --- a/drivers/media/i2c/sony-starvis2.c > +++ b/drivers/media/i2c/sony-starvis2.c > @@ -727,6 +727,7 @@ struct starvis2 { > struct v4l2_ctrl *exposure; > struct v4l2_ctrl *vblank; > struct v4l2_ctrl *hblank; > + struct v4l2_ctrl *link_freq; > > /* Track VMAX for exposure updates */ > u32 vmax; > @@ -757,6 +758,7 @@ static int starvis2_set_ctrl(struct v4l2_ctrl *ctrl) > struct starvis2 *starvis2 = container_of_const(ctrl->handler, struct > starvis2, ctrl_handler); > struct i2c_client *client = v4l2_get_subdevdata(&starvis2->sd); > + const struct starvis2_variant *variant = starvis2->variant; > const struct v4l2_mbus_framefmt *format; > struct v4l2_subdev_state *state; > int ret = 0; > @@ -780,6 +782,23 @@ static int starvis2_set_ctrl(struct v4l2_ctrl *ctrl) > return ret; > } > > + if (ctrl->id == V4L2_CID_LINK_FREQ) { > + u32 hmax = variant->hmax_min_link_freq[ctrl->val]; > + s32 hblank; > + > + if (starvis2->lane_mode == STARVIS2_LANEMODE_4L) > + hmax = max(hmax >> 1, variant->hmax_min_pixel_array); > + > + hblank = hmax * variant->pix_per_clk - > + variant->active_area.width; Wrong indentation. > + > + ret = __v4l2_ctrl_modify_range(starvis2->hblank, hblank, > + starvis2->hblank->maximum, > + starvis2->hblank->step, hblank); > + if (ret) > + return ret; > + } > + > /* > * Only apply control values when device is powered on (RPM ACTIVE) > * and streaming (usage count != 0) > @@ -826,6 +845,12 @@ static int starvis2_set_ctrl(struct v4l2_ctrl *ctrl) > cci_write(starvis2->cci, STARVIS2_REG_WINMODEV, ctrl->val, > &ret); > break; > + case V4L2_CID_LINK_FREQ: > + /* The STARVIS2_LINK_FREQ_ enums match up with the register */ > + cci_write(starvis2->cci, STARVIS2_REG_DATARATE_SEL, ctrl->val, > + &ret); > + break; > + > default: > dev_warn(&client->dev, > "ctrl(id:0x%x,val:0x%x) is not handled\n", > @@ -940,9 +965,6 @@ static int starvis2_write_common(struct starvis2 *starvis2) > > cci_write(starvis2->cci, STARVIS2_REG_INCK_SEL, starvis2->inck_sel_val, > &ret); > - cci_write(starvis2->cci, STARVIS2_REG_DATARATE_SEL, > - __fls(starvis2->link_freq_bitmap), > - &ret); > cci_write(starvis2->cci, STARVIS2_REG_LANEMODE, starvis2->lane_mode, > &ret); > > @@ -1022,6 +1044,8 @@ static int starvis2_enable_streams(struct v4l2_subdev *sd, > goto err_rpm_put; > } > > + __v4l2_ctrl_grab(starvis2->link_freq, true); > + > return 0; > > err_rpm_put: > @@ -1046,6 +1070,8 @@ static int starvis2_disable_streams(struct v4l2_subdev *sd, > if (ret) > dev_err(&client->dev, "%s failed to stop stream\n", __func__); > > + __v4l2_ctrl_grab(starvis2->link_freq, false); > + > pm_runtime_put(&client->dev); > > return ret; > @@ -1212,7 +1238,6 @@ static int starvis2_init_controls(struct starvis2 *starvis2) > struct i2c_client *client = v4l2_get_subdevdata(&starvis2->sd); > const struct starvis2_variant *variant = starvis2->variant; > struct v4l2_fwnode_device_properties props; > - struct v4l2_ctrl *link_freq; > s32 hblank, max_hblank, vblank, max_vblank; > u32 hmax; > int ret; > @@ -1228,25 +1253,26 @@ static int starvis2_init_controls(struct starvis2 *starvis2) > > starvis2->vmax = starvis2->variant->vmax_default; > > - hmax = variant->hmax_min_link_freq[__fls(starvis2->link_freq_bitmap)]; > - if (starvis2->lane_mode == STARVIS2_LANEMODE_4L) > - hmax = max(hmax >> 1, variant->hmax_min_pixel_array); > - > /* PIXEL_RATE is fixed and read-only */ > v4l2_ctrl_new_std(ctrl_hdlr, &starvis2_ctrl_ops, V4L2_CID_PIXEL_RATE, > starvis2->variant->pixel_rate, > starvis2->variant->pixel_rate, 1, > starvis2->variant->pixel_rate); > > - /* LINK_FREQ is also read only */ > - link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, &starvis2_ctrl_ops, > - V4L2_CID_LINK_FREQ, > - ARRAY_SIZE(link_freqs) - 1, > - __ffs(starvis2->link_freq_bitmap), > - link_freqs); > - > - if (link_freq) > - link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; > + starvis2->link_freq = > + v4l2_ctrl_new_int_menu(ctrl_hdlr, &starvis2_ctrl_ops, > + V4L2_CID_LINK_FREQ, > + __fls(starvis2->link_freq_bitmap), > + __ffs(starvis2->link_freq_bitmap), > + link_freqs); > + if (!starvis2->link_freq) > + goto err_free_handler; > + > + v4l2_ctrl_modify_range(starvis2->link_freq, > + __ffs(starvis2->link_freq_bitmap), > + __fls(starvis2->link_freq_bitmap), > + ~starvis2->link_freq_bitmap, > + __ffs(starvis2->link_freq_bitmap)); > > vblank = starvis2->vmax - starvis2->variant->active_area.height; > max_vblank = STARVIS2_VMAX_MAX - starvis2->variant->active_area.height; > @@ -1254,6 +1280,10 @@ static int starvis2_init_controls(struct starvis2 *starvis2) > V4L2_CID_VBLANK, vblank, max_vblank, > 2, vblank); > > + hmax = variant->hmax_min_link_freq[starvis2->link_freq->val]; > + if (starvis2->lane_mode == STARVIS2_LANEMODE_4L) > + hmax = max(hmax >> 1, variant->hmax_min_pixel_array); > + > hblank = hmax * starvis2->variant->pix_per_clk - > starvis2->variant->active_area.width; There's a similar calculation in starvis2_set_ctrl(). Please factor them out to a separate function, with a comment to explain the logic. > max_hblank = STARVIS2_HMAX_MAX * starvis2->variant->pix_per_clk - > @@ -1288,17 +1318,18 @@ static int starvis2_init_controls(struct starvis2 *starvis2) > > v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &starvis2_ctrl_ops, &props); > > - if (ctrl_hdlr->error) { > - ret = ctrl_hdlr->error; > - dev_err(&client->dev, "%s control init failed (%d)\n", > - __func__, ret); > - v4l2_ctrl_handler_free(ctrl_hdlr); > - return ret; > - } > + if (ctrl_hdlr->error) > + goto err_free_handler; > > starvis2->sd.ctrl_handler = ctrl_hdlr; > > return 0; > + > +err_free_handler: > + dev_err(&client->dev, "%s control init failed (%d)\n", > + __func__, ctrl_hdlr->error); > + > + return v4l2_ctrl_handler_free(ctrl_hdlr); > } > > static int starvis2_check_hwcfg(struct device *dev, struct starvis2 *starvis2) -- Regards, Laurent Pinchart