Skip to content

Commit 11356c8

Browse files
committed
Fix sync_mode control range not applied for device-specific
1 parent 09c69c4 commit 11356c8

1 file changed

Lines changed: 83 additions & 5 deletions

File tree

kernel/realsense/d4xx.c

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ struct ds5_ctrls {
388388
struct v4l2_ctrl *link_freq;
389389
struct v4l2_ctrl *query_sub_stream;
390390
struct v4l2_ctrl *set_sub_stream;
391+
struct v4l2_ctrl *sync_mode;
391392
};
392393
};
393394

@@ -3351,15 +3352,31 @@ static const struct v4l2_ctrl_config ds5_ctrl_hw_reset = {
33513352
.flags = V4L2_CTRL_FLAG_EXECUTE_ON_WRITE,
33523353
};
33533354

3354-
static const struct v4l2_ctrl_config ds5_ctrl_sync_mode = {
3355+
/* Sync mode menu arrays for different camera platforms */
3356+
static const char * const sync_mode_menu_full[] = {
3357+
"Default", /* 0 */
3358+
"Master", /* 1 */
3359+
"Slave", /* 2 */
3360+
"Full Slave", /* 3 */
3361+
"Sub Pre-Master", /* 4 */
3362+
"Full Master", /* 5 */
3363+
};
3364+
3365+
static const char * const sync_mode_menu_d401[] = {
3366+
"Default", /* 0 */
3367+
"(unsupported)", /* 1 - rejected in s_ctrl for D401 */
3368+
"Slave", /* 2 */
3369+
};
3370+
3371+
static struct v4l2_ctrl_config ds5_ctrl_sync_mode = {
33553372
.ops = &ds5_ctrl_ops,
33563373
.id = DS5_CAMERA_CID_SYNC_MODE,
33573374
.name = "Camera Sync Mode",
3358-
.type = V4L2_CTRL_TYPE_INTEGER,
3375+
.type = V4L2_CTRL_TYPE_MENU,
33593376
.min = 0,
3360-
.max = 4,
3361-
.step = 1,
3377+
.max = 5,
33623378
.def = 0,
3379+
.qmenu = sync_mode_menu_full,
33633380
.flags = V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_EXECUTE_ON_WRITE,
33643381
};
33653382

@@ -4114,7 +4131,7 @@ static int ds5_ctrl_init(struct ds5 *state, int sid)
41144131
}
41154132
// DEPTH custom
41164133
if (sid == DEPTH_SID) {
4117-
v4l2_ctrl_new_custom(hdl, &ds5_ctrl_sync_mode, sensor);
4134+
ctrls->sync_mode = v4l2_ctrl_new_custom(hdl, &ds5_ctrl_sync_mode, sensor);
41184135
v4l2_ctrl_new_custom(hdl, &ds5_ctrl_pwm, sensor);
41194136
}
41204137
// IMU custom
@@ -5178,6 +5195,8 @@ static int ds5_fixed_configuration(struct i2c_client *client, struct ds5 *state)
51785195
sensor->formats = ds5_depth_formats_d40x;
51795196
break;
51805197
case DS5_DEVICE_TYPE_D43X:
5198+
sensor->formats = ds5_depth_formats_d43x;
5199+
break;
51815200
case DS5_DEVICE_TYPE_D45X:
51825201
sensor->formats = ds5_depth_formats_d43x;
51835202
break;
@@ -5628,6 +5647,61 @@ static int ds5_dfu_device_open(struct inode *inode, struct file *file)
56285647
return 0;
56295648
};
56305649

5650+
/* Adjust sync_mode control range based on device type.
5651+
* Must be called after ds5_mux_init() which creates the control.
5652+
*/
5653+
static void ds5_adjust_sync_mode_control(struct i2c_client *client, struct ds5 *state)
5654+
{
5655+
u16 dev_type = 0;
5656+
int ret;
5657+
5658+
if (!state->ctrls.sync_mode)
5659+
return;
5660+
5661+
ret = ds5_read(state, DS5_DEVICE_TYPE, &dev_type);
5662+
if (ret < 0) {
5663+
dev_warn(&client->dev, "%s(): Failed to read device type\n", __func__);
5664+
return;
5665+
}
5666+
5667+
switch (dev_type) {
5668+
case DS5_DEVICE_TYPE_D41X:
5669+
/* D41X does not support sync mode */
5670+
dev_info(&client->dev, "%s(): D41X does not support sync mode\n", __func__);
5671+
__v4l2_ctrl_modify_range(state->ctrls.sync_mode, 0, 0, 0, 0);
5672+
break;
5673+
case DS5_DEVICE_TYPE_D40X:
5674+
/* D401 only supports modes 0 (Default) and 2 (Slave) */
5675+
__v4l2_ctrl_modify_range(state->ctrls.sync_mode, 0, 2, 0, 0);
5676+
state->ctrls.sync_mode->qmenu = sync_mode_menu_d401;
5677+
dev_info(&client->dev, "%s(): D401 sync mode: 0 (Default), 2 (Slave)\n", __func__);
5678+
break;
5679+
case DS5_DEVICE_TYPE_D43X:
5680+
/* D430 GMSL supports all 6 sync modes (0-5) */
5681+
__v4l2_ctrl_modify_range(state->ctrls.sync_mode, 0, 5, 0, 0);
5682+
state->ctrls.sync_mode->qmenu = sync_mode_menu_full;
5683+
dev_info(&client->dev, "%s(): D430 GMSL sync mode: all modes 0-5 supported\n", __func__);
5684+
break;
5685+
case DS5_DEVICE_TYPE_D45X:
5686+
/* D450 supports all 6 sync modes (0-5) */
5687+
__v4l2_ctrl_modify_range(state->ctrls.sync_mode, 0, 5, 0, 0);
5688+
state->ctrls.sync_mode->qmenu = sync_mode_menu_full;
5689+
dev_info(&client->dev, "%s(): D450 sync mode: all modes 0-5 supported\n", __func__);
5690+
break;
5691+
case DS5_DEVICE_TYPE_D46X:
5692+
/* D46X does not support sync mode */
5693+
dev_info(&client->dev, "%s(): D46X does not support sync mode\n", __func__);
5694+
__v4l2_ctrl_modify_range(state->ctrls.sync_mode, 0, 0, 0, 0);
5695+
break;
5696+
default:
5697+
/* Unknown device - disable sync mode */
5698+
dev_warn(&client->dev, "%s(): Unknown device type %d, disabling sync mode\n",
5699+
__func__, dev_type);
5700+
__v4l2_ctrl_modify_range(state->ctrls.sync_mode, 0, 0, 0, 0);
5701+
break;
5702+
}
5703+
}
5704+
56315705
static int ds5_v4l_init(struct i2c_client *c, struct ds5 *state)
56325706
{
56335707
int ret;
@@ -5656,6 +5730,10 @@ static int ds5_v4l_init(struct i2c_client *c, struct ds5 *state)
56565730
if (ret < 0)
56575731
goto e_imu;
56585732

5733+
/* Adjust sync_mode control range based on device type - must be done
5734+
* after ds5_mux_init() creates the control */
5735+
ds5_adjust_sync_mode_control(c, state);
5736+
56595737
ret = ds5_hw_init(c, state);
56605738
if (ret < 0)
56615739
goto e_mux;

0 commit comments

Comments
 (0)