Re: [PATCH v7 02/18] media: sony-starvis2: Reorder link frequencies to remove lookup

From: Laurent Pinchart

Date: Sun Nov 29 2026 - 21:44:18 EST


On Thu, Oct 29, 2026 at 02:18:23PM +0000, Dave Stevenson wrote:
> link_freqs_reg_value is table that just reverses the order of the
> link frequency enum.
>
> Reverse the order of the link frequencies so that the table is
> redundant, and remove it.
>
> Signed-off-by: Dave Stevenson <dave.stevenson@xxxxxxxxxxxxxxx>
> ---
> drivers/media/i2c/sony-starvis2.c | 31 ++++++++++---------------------
> 1 file changed, 10 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/media/i2c/sony-starvis2.c b/drivers/media/i2c/sony-starvis2.c
> index e62cde583324..134fececac5c 100644
> --- a/drivers/media/i2c/sony-starvis2.c
> +++ b/drivers/media/i2c/sony-starvis2.c
> @@ -187,25 +187,14 @@ enum starvis2_lanemode {
>
> /* Link frequency setup (DDR: lane rate = 2 x link freq) */
> enum {
> - STARVIS2_LINK_FREQ_297MHZ,
> - STARVIS2_LINK_FREQ_360MHZ,
> - STARVIS2_LINK_FREQ_445MHZ,
> - STARVIS2_LINK_FREQ_594MHZ,
> - STARVIS2_LINK_FREQ_720MHZ,
> - STARVIS2_LINK_FREQ_891MHZ,
> - STARVIS2_LINK_FREQ_1039MHZ,
> - STARVIS2_LINK_FREQ_1188MHZ,
> -};
> -
> -static const u8 link_freqs_reg_value[] = {
> - [STARVIS2_LINK_FREQ_297MHZ] = 0x07,
> - [STARVIS2_LINK_FREQ_360MHZ] = 0x06,
> - [STARVIS2_LINK_FREQ_445MHZ] = 0x05,
> - [STARVIS2_LINK_FREQ_594MHZ] = 0x04,
> - [STARVIS2_LINK_FREQ_720MHZ] = 0x03,
> - [STARVIS2_LINK_FREQ_891MHZ] = 0x02,
> - [STARVIS2_LINK_FREQ_1039MHZ] = 0x01,
> - [STARVIS2_LINK_FREQ_1188MHZ] = 0x00,
> + STARVIS2_LINK_FREQ_1188MHZ = 0x00,
> + STARVIS2_LINK_FREQ_1039MHZ = 0x01,
> + STARVIS2_LINK_FREQ_891MHZ = 0x02,
> + STARVIS2_LINK_FREQ_720MHZ = 0x03,
> + STARVIS2_LINK_FREQ_594MHZ = 0x04,
> + STARVIS2_LINK_FREQ_445MHZ = 0x05,
> + STARVIS2_LINK_FREQ_360MHZ = 0x06,
> + STARVIS2_LINK_FREQ_297MHZ = 0x07,
> };
>
> static const u64 link_freqs[] = {
> @@ -914,7 +903,7 @@ 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,
> - link_freqs_reg_value[__ffs(starvis2->link_freq_bitmap)],
> + __fls(starvis2->link_freq_bitmap),
> &ret);
> cci_write(starvis2->cci, STARVIS2_REG_LANEMODE, starvis2->lane_mode,
> &ret);
> @@ -1177,7 +1166,7 @@ static int starvis2_init_controls(struct starvis2 *starvis2)
> {
> struct v4l2_ctrl_handler *ctrl_hdlr;
> const u32 hmax_4lane =
> - min_hmax_4lane[__ffs(starvis2->link_freq_bitmap)];
> + min_hmax_4lane[__fls(starvis2->link_freq_bitmap)];
> const u32 lane_scale =
> starvis2->lane_mode == STARVIS2_LANEMODE_2L ? 2 : 1;
> struct i2c_client *client = v4l2_get_subdevdata(&starvis2->sd);

As far as I understand, the driver hardcodes usage of the lowest link
frequency. The LINK_FREQ control is initialized with

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);

which I think should also be updated, otherwise the control will report
the highest frequency.

A side effect of this patch is that it reverses the order of link
frequencies exposed to userspace in the LINK_FREQ control, from highest
to lowest. The order isn't defined in the V4L2 specification, but I
wonder if it could cause breakages in userspace.

--
Regards,

Laurent Pinchart