media: ov5640: Fix power up sequence delays
v4 cover media: ov5640: Fix power up sequence delays
This series fixes the power-up sequence delays to support some 15-pin FFC compatible OV5640 modules.
Without appropriate delays after both gpio and register-based powerdown and reset the sensor SCCB was not very stable, and probe would sometimes fail at check_chip_id.
Changes in v4:
- Swap order of patches [1/3] and [2/3]
- Drop patch [3/3] as SW powerup does not have same timing constraints
- Move soft powerdown from the register table to powerup_sequence() along with soft reset
v3: https://lore.kernel.org/all/[email protected]/
Jai Luthra (2):
media: ov5640: Fix soft reset sequence and timings
media: ov5640: Handle delays when no reset_gpio set
drivers/media/i2c/ov5640.c | 55 +++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 16 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/2 media: ov5640: Fix soft reset sequence and timings
Move the register-based reset out of the init_setting[] and into the powerup_sequence function. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.
This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
--- drivers/media/i2c/ov5640.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
drivers/media/i2c/ov5640.c +23 -10
@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017
@@ -532,7 +533,7 @@ static const struct v4l2_mbus_framefmt ov5640_default_fmt = { };static const struct reg_value ov5640_init_setting[] = { - {0x3103 ,0x11 ,0 ,0 }, {0x3008 ,0x82 ,0 ,5 }, {0x3008 ,0x42 ,0 ,0 }, + {0x3103 ,0x11 ,0 ,0 }, {0x3103 ,0x03 ,0 ,0 }, {0x3630 ,0x36 ,0 ,0 }, {0x3631 ,0x0e ,0 ,0 }, {0x3632 ,0xe2 ,0 ,0 }, {0x3633 ,0x12 ,0 ,0 }, {0x3621 ,0xe0 ,0 ,0 }, {0x3704 ,0xa0 ,0 ,0 }, {0x3703 ,0x5a ,0 ,0 },
@@ -2429,19 +2430,31 @@ static void ov5640_reset(struct ov5640_dev *sensor)if (!sensor->reset_gpio)return ; -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); + }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); + }usleep_range (20000 ,25000 ); + +/* software standby: allows registers programming; +* exit at restore_mode() for CSI, s_stream(1) for DVP +*/ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); }static int ov5640_set_power_on (struct ov5640_dev *sensor)
Signature · 1 line
2.17.1
Re: [PATCH v4 1/2] media: ov5640: Fix soft reset sequence and timings
Hi Jai,
bear with me a little longer..
Quoted 64 lines · Jai Luthra
Move the register-based reset out of the init_setting[] and into the
powerup_sequencefunction. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Reported-by Nishanth Menon <[email protected]>Suggested-by Jacopo Mondi <[email protected]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)drivers/media/i2c/ov5640.c +12
-10@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017@@ -532,7 +533,7 @@ static const struct v4l2_mbus_framefmt ov5640_default_fmt = { };static const struct reg_value ov5640_init_setting[] = { - {0x3103 ,0x11 ,0 ,0 }, {0x3008 ,0x82 ,0 ,5 }, {0x3008 ,0x42 ,0 ,0 }, + {0x3103 ,0x11 ,0 ,0 }, {0x3103 ,0x03 ,0 ,0 }, {0x3630 ,0x36 ,0 ,0 }, {0x3631 ,0x0e ,0 ,0 }, {0x3632 ,0xe2 ,0 ,0 }, {0x3633 ,0x12 ,0 ,0 }, {0x3621 ,0xe0 ,0 ,0 }, {0x3704 ,0xa0 ,0 ,0 }, {0x3703 ,0x5a ,0 ,0 },@@ -2429,19 +2430,31 @@ static void ov5640_reset(struct ov5640_dev *sensor)if (!sensor->reset_gpio)return ; -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 );
drivers/media/i2c/ov5640.c static void ov5640_reset(struct ov5640_dev *sensor) · line 2455
Quoted 10 lines
drivers/media/i2c/ov5640.c +9
-0+ }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); + }usleep_range (20000 ,25000 ); + +/* software standby: allows registers programming; +* exit at restore_mode() for CSI, s_stream(1) for DVP +*/
Multiline comments are usually written as
/*
* Software standby: allows registers programming;
* exit at restore_mode() for CSI, s_stream(1) for DVP
*/It's a trivial change, I'm not collecting patches so I can't offer to change it when doing so, but maybe Sakari could help with that so that you don't have to send a new version ? (if that's the only comment you receive ofc)
The patch looks good to me
Quoted 8 lines
drivers/media/i2c/ov5640.c +2
-1+ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); }static int ov5640_set_power_on (struct ov5640_dev *sensor) --2.17.1
Re: [PATCH v4 1/2] media: ov5640: Fix soft reset sequence and timings
Quoted 11 lines · Jacopo Mondi
drivers/media/i2c/ov5640.c static void ov5640_reset(struct ov5640_dev *sensor) · line 2455
Quoted 3 lines
drivers/media/i2c/ov5640.c +3
-0+/* software standby: allows registers programming; +* exit at restore_mode() for CSI, s_stream(1) for DVP +*/ Multiline comments are usually written as
/* * Software standby: allows registers programming; * exit at restore_mode() for CSI, s_stream(1) for DVP */
Quoted 4 lines
It's a trivial change, I'm not collecting patches so I can't offer to change it when doing so, but maybe Sakari could help with that so that you don't have to send a new version ? (if that's the only comment you receive ofc)
Works for me.
Quoted 4 lines
The patch looks good to me
Reviewed-by Jacopo Mondi <[email protected]>
Thanks!
Signature · 1 line
Sakari Ailus
PATCH v4 2/2 media: ov5640: Handle delays when no reset_gpio set
In reply to Jai LuthraSome module manufacturers [1][2] don't expose the RESETB and PWDN pins of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN gpio to the sensor pins with appropriate delays.
In such cases, reset_gpio will not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.
Also, rename the function to ov5640_powerup_sequence to better match the datasheet (section 2.7).
[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
--- drivers/media/i2c/ov5640.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/media/i2c/ov5640.c +16 -6
@@ -2425,11 +2425,22 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)gpiod_set_value_cansleep (sensor->pwdn_gpio, enable ?0 :1 ); } -static void ov5640_reset (struct ov5640_dev *sensor) +/* +* From section 2.7 power up sequence: +* t0 + t1 + t2 >= 5ms Delay from DOVDD stable to PWDN pull down +* t3 >= 1ms Delay from PWDN pull down to RESETB pull up +* t4 >= 20ms Delay from RESETB pull up to SCCB (i2c) stable +* +* Some modules don't expose RESETB/PWDN pins directly, instead providing a +* "PWUP" GPIO which is wired through appropriate delays and inverters to the +* pins. +* +* In such cases, this gpio should be mapped to pwdn_gpio in the driver, and we +* should still toggle the pwdn_gpio below with the appropriate delays, while +* the calls to reset_gpio will be ignored. +*/ +static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -if (!sensor->reset_gpio) -return ; -if (sensor->pwdn_gpio) {gpiod_set_value_cansleep (sensor->reset_gpio,0 );
@@ -2477,8 +2488,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor) goto xclk_off; } -ov5640_reset (sensor); -ov5640_power (sensor, true); +ov5640_powerup_sequence (sensor); ret =ov5640_init_slave_id (sensor);if (ret)
Signature · 1 line
2.17.1