From: Benjamin Mugnier benjamin.mugnier@foss.st.com
[ Upstream commit df2f8fd91bde57d5d5aca6adddf7e988f2e8c60e ]
Proper clock configuration is required to advance through FSM states. Prior than this having a different clock value than default sensor's value was used (12 MHz) could prevent the sensor from booting.
Signed-off-by: Benjamin Mugnier benjamin.mugnier@foss.st.com Signed-off-by: Sakari Ailus sakari.ailus@linux.intel.com Signed-off-by: Hans Verkuil hverkuil@xs4all.nl Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit should be backported to stable kernel trees for the following reasons:
## Bug Fix Analysis
1. **Critical Boot Issue**: The commit fixes a sensor initialization failure where the sensor could fail to boot if a non-default clock frequency was used. The commit message explicitly states: "Prior than this having a different clock value than default sensor's value was used (12 MHz) could prevent the sensor from booting."
2. **Clear Root Cause**: The issue is a timing/sequencing problem where the external clock must be configured BEFORE the patch is applied to allow proper FSM (Finite State Machine) state transitions. The commit message states: "Proper clock configuration is required to advance through FSM states."
3. **Small and Contained Fix**: The fix is minimal - it simply moves one line of code (`vd55g1_write(sensor, VD55G1_REG_EXT_CLOCK, sensor->xclk_freq, &ret);`) from the streaming enable function to the power-on sequence, specifically between sensor detection and patching.
## Code Analysis
Looking at the code changes: - **REMOVED** from `vd55g1_enable_streams()` at line 1040 (after power- on) - **ADDED** to `vd55g1_power_on()` at line 1614 (after detect, before patch)
The new sequence in `vd55g1_power_on()` becomes: 1. Enable power/clock → FSM state: READY_TO_BOOT 2. `vd55g1_detect()` - verify sensor ID 3. **NEW: Configure external clock** ← Critical for FSM advancement 4. `vd55g1_patch()` - apply firmware patch 5. Wait for FSM state: SW_STBY
## Stable Criteria Met
1. **Fixes a real bug**: Yes - sensor initialization failure with non- default clocks 2. **Small change**: Yes - single line moved between functions 3. **No new features**: Correct - just fixes sequencing 4. **Low regression risk**: Yes - moves existing code to proper location 5. **Hardware enablement**: Fixes broken hardware initialization for VD55G1 sensor 6. **Recently added driver**: The driver was added in April 2025 (commit e56616d7b23c), making this an early fix for a new driver that likely needs to work properly in stable kernels
The fix addresses a fundamental initialization issue that would prevent the sensor from working with any clock frequency other than the default 12 MHz, making it a critical fix for proper hardware support.
drivers/media/i2c/vd55g1.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/vd55g1.c b/drivers/media/i2c/vd55g1.c index 25e2fc88a036..8552ce75e1aa 100644 --- a/drivers/media/i2c/vd55g1.c +++ b/drivers/media/i2c/vd55g1.c @@ -1038,8 +1038,6 @@ static int vd55g1_enable_streams(struct v4l2_subdev *sd, if (ret < 0) return ret;
- vd55g1_write(sensor, VD55G1_REG_EXT_CLOCK, sensor->xclk_freq, &ret); - /* Configure output */ vd55g1_write(sensor, VD55G1_REG_MIPI_DATA_RATE, sensor->mipi_rate, &ret); @@ -1613,6 +1611,9 @@ static int vd55g1_power_on(struct device *dev) goto disable_clock; }
+ /* Setup clock now to advance through system FSM states */ + vd55g1_write(sensor, VD55G1_REG_EXT_CLOCK, sensor->xclk_freq, &ret); + ret = vd55g1_patch(sensor); if (ret) { dev_err(dev, "Sensor patch failed %d\n", ret);