Skip to content

Commit 0862582

Browse files
Umang JainHans Verkuil
authored andcommitted
media: imx335: Use v4l2_link_freq_to_bitmap helper
Use the v4l2_link_freq_to_bitmap() helper to figure out which driver-supported link frequencies can be used on a given system. Signed-off-by: Umang Jain <[email protected]> Signed-off-by: Sakari Ailus <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 14a6078 commit 0862582

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

drivers/media/i2c/imx335.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#define IMX335_INCLK_RATE 24000000
5050

5151
/* CSI2 HW configuration */
52-
#define IMX335_LINK_FREQ 594000000
52+
#define IMX335_LINK_FREQ 594000000LL
5353
#define IMX335_NUM_DATA_LANES 4
5454

5555
#define IMX335_REG_MIN 0x00
@@ -134,6 +134,7 @@ struct imx335_mode {
134134
* @vblank: Vertical blanking in lines
135135
* @cur_mode: Pointer to current selected sensor mode
136136
* @mutex: Mutex for serializing sensor controls
137+
* @link_freq_bitmap: Menu bitmap for link_freq_ctrl
137138
* @cur_mbus_code: Currently selected media bus format code
138139
*/
139140
struct imx335 {
@@ -157,6 +158,7 @@ struct imx335 {
157158
u32 vblank;
158159
const struct imx335_mode *cur_mode;
159160
struct mutex mutex;
161+
unsigned long link_freq_bitmap;
160162
u32 cur_mbus_code;
161163
};
162164

@@ -405,7 +407,8 @@ static int imx335_update_controls(struct imx335 *imx335,
405407
{
406408
int ret;
407409

408-
ret = __v4l2_ctrl_s_ctrl(imx335->link_freq_ctrl, mode->link_freq_idx);
410+
ret = __v4l2_ctrl_s_ctrl(imx335->link_freq_ctrl,
411+
__ffs(imx335->link_freq_bitmap));
409412
if (ret)
410413
return ret;
411414

@@ -691,6 +694,13 @@ static int imx335_init_state(struct v4l2_subdev *sd,
691694
fmt.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
692695
imx335_fill_pad_format(imx335, &supported_mode, &fmt);
693696

697+
mutex_lock(&imx335->mutex);
698+
__v4l2_ctrl_modify_range(imx335->link_freq_ctrl, 0,
699+
__fls(imx335->link_freq_bitmap),
700+
~(imx335->link_freq_bitmap),
701+
__ffs(imx335->link_freq_bitmap));
702+
mutex_unlock(&imx335->mutex);
703+
694704
return imx335_set_pad_format(sd, sd_state, &fmt);
695705
}
696706

@@ -939,19 +949,10 @@ static int imx335_parse_hw_config(struct imx335 *imx335)
939949
goto done_endpoint_free;
940950
}
941951

942-
if (!bus_cfg.nr_of_link_frequencies) {
943-
dev_err(imx335->dev, "no link frequencies defined\n");
944-
ret = -EINVAL;
945-
goto done_endpoint_free;
946-
}
947-
948-
for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++)
949-
if (bus_cfg.link_frequencies[i] == IMX335_LINK_FREQ)
950-
goto done_endpoint_free;
951-
952-
dev_err(imx335->dev, "no compatible link frequencies found\n");
953-
954-
ret = -EINVAL;
952+
ret = v4l2_link_freq_to_bitmap(imx335->dev, bus_cfg.link_frequencies,
953+
bus_cfg.nr_of_link_frequencies,
954+
link_freq, ARRAY_SIZE(link_freq),
955+
&imx335->link_freq_bitmap);
955956

956957
done_endpoint_free:
957958
v4l2_fwnode_endpoint_free(&bus_cfg);
@@ -1099,9 +1100,8 @@ static int imx335_init_controls(struct imx335 *imx335)
10991100
imx335->link_freq_ctrl = v4l2_ctrl_new_int_menu(ctrl_hdlr,
11001101
&imx335_ctrl_ops,
11011102
V4L2_CID_LINK_FREQ,
1102-
ARRAY_SIZE(link_freq) -
1103-
1,
1104-
mode->link_freq_idx,
1103+
__fls(imx335->link_freq_bitmap),
1104+
__ffs(imx335->link_freq_bitmap),
11051105
link_freq);
11061106
if (imx335->link_freq_ctrl)
11071107
imx335->link_freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;

0 commit comments

Comments
 (0)