media: i2c: ov5647: Modernize driver with CCI and new stream APIs
v2 cover media: i2c: ov5647: Modernize driver with CCI and new stream APIs
This patch series modernizes the OV5647 camera sensor driver by:
1. Converting from private I2C register access functions to the common CCI (Camera Control Interface) register access helpers, which simplifies the code and provides better error handling.
2. Switching from driver-specific mutex to the sub-device state lock and properly implementing v4l2_subdev_init_finalize() lifecycle.
3. Converting from the legacy s_stream callback to the new enable_streams/disable_streams operations to align with current V4L2 subsystem standards.
These changes reduce code complexity, improve maintainability, and ensure the driver follows modern V4L2 subsystem patterns.
Changes in V2:
- Proper register width definitions
- Fixed formatting and indentation
- Error chaining implementation
- Simplified chip detection logic
- Clean compilation with -Werror
- Add a new patch, switch from s_stream to enable_streams and disable_streams callbacks.
Link to V1: https://patchwork.kernel.org/project/linux-media/cover/[email protected]/
Xiaolei Wang (3):
media: i2c: ov5647: Convert to CCI register access helpers
media: i2c: ov5647: Switch to using the sub-device state lock
media: i2c: ov5647: switch to {enable,disable}_streams
drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov5647.c | 1098 ++++++++++++++++-------------------- 2 files changed, 492 insertions(+), 607 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/3 media: i2c: ov5647: Convert to CCI register access helpers
Use the new common CCI register access helpers to replace the private register access helpers in the ov5647 driver. This simplifies the driver by reducing the amount of code.
--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov5647.c | 997 +++++++++++++++++-------------------- 2 files changed, 453 insertions(+), 545 deletions(-)
drivers/media/i2c/Kconfig +1 -0
@@ -529,6 +529,7 @@ config VIDEO_OV5645 config VIDEO_OV5647 tristate "OmniVision OV5647 sensor support" + select V4L2_CCI_I2C help This is a Video4Linux2 sensor driver for the OmniVision OV5647 camera.
drivers/media/i2c/ov5647.c +452 -545
1,212 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 1/3] media: i2c: ov5647: Convert to CCI register access helpers
Hi Xiaolei,
Quoted 53 lines
Use the new common CCI register access helpers to replace the private register access helpers in the ov5647 driver. This simplifies the driver by reducing the amount of code.
Signed-off-by Xiaolei Wang <[email protected]>---
drivers/media/i2c/Kconfig | 1 +drivers/media/i2c/ov5647.c| 997 +++++++++++++++++--------------------2 files changed, 453 insertions(+), 545 deletions(-)drivers/media/i2c/Kconfig +0
-0@@ -529,6 +529,7 @@ config VIDEO_OV5645config
VIDEO_OV5647
tristate "OmniVision OV5647 sensor support"
+ selectV4L2_CCI_I2C
help
This is a Video4Linux2 sensor driver for the OmniVision OV5647 camera.drivers/media/i2c/ov5647.c +1
-15@@ -22,6 +22,7 @@ #include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/videodev2.h> +#include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-event.h>@@ -41,24 +42,19 @@ #define MIPI_CTRL00_BUS_IDLE BIT(2) #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0) -#define OV5647_SW_STANDBY 0x0100 -#define OV5647_SW_RESET 0x0103 -#define OV5647_REG_CHIPID_H 0x300a -#define OV5647_REG_CHIPID_L 0x300b -#define OV5640_REG_PAD_OUT 0x300d -#define OV5647_REG_EXP_HI 0x3500 -#define OV5647_REG_EXP_MID 0x3501 -#define OV5647_REG_EXP_LO 0x3502 -#define OV5647_REG_AEC_AGC 0x3503 -#define OV5647_REG_GAIN_HI 0x350a -#define OV5647_REG_GAIN_LO 0x350b -#define OV5647_REG_VTS_HI 0x380e -#define OV5647_REG_VTS_LO 0x380f -#define OV5647_REG_FRAME_OFF_NUMBER 0x4202 -#define OV5647_REG_MIPI_CTRL00 0x4800
drivers/media/i2c/ov5647.c line 51
Quoted 10 lines
drivers/media/i2c/ov5647.c +7
-3-#define OV5647_REG_MIPI_CTRL14 0x4814 -#define OV5647_REG_AWB 0x5001 -#define OV5647_REG_ISPCTRL3D 0x503d +#define OV5647_SW_STANDBY CCI_REG8(0x0100) +#define OV5647_SW_RESET CCI_REG8(0x0103) +#define OV5647_REG_CHIPID CCI_REG16(0x300a) +#define OV5640_REG_PAD_OUT CCI_REG8(0x300d) +#define OV5647_REG_EXPOSURE CCI_REG24(0x3500) +#define OV5647_REG_AEC_AGC CCI_REG8(0x3503) +#define OV5647_REG_GAIN CCI_REG16(0x350b)
It should be 0x350a, not 0x350b.
Quoted 12 lines
drivers/media/i2c/ov5647.c +6
-0+#define OV5647_REG_VTS CCI_REG16(0x380e) +#define OV5647_REG_FRAME_OFF_NUMBER CCI_REG8(0x4202) +#define OV5647_REG_MIPI_CTRL00 CCI_REG8(0x4800) +#define OV5647_REG_MIPI_CTRL14 CCI_REG8(0x4814) +#define OV5647_REG_AWB CCI_REG8(0x5001) +#define OV5647_REG_ISPCTRL3D CCI_REG8(0x503d) #define REG_TERM 0xfffe #define VAL_TERM 0xfe@@ -81,23 +77,19 @@ #define OV5647_EXPOSURE_DEFAULT 1000 #define OV5647_EXPOSURE_MAX 65535
...
drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 1341
Quoted 8 lines
drivers/media/i2c/ov5647.c +4
-0@@ -1435,6 +1335,13 @@ static int ov5647_probe(struct i2c_client *client) if (ret < 0) goto ctrl_handler_free; + sensor->regmap = devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(sensor->regmap)) { + ret = PTR_ERR(sensor->regmap); + dev_err(dev, "failed to initialize CCI: %d\n", ret);
Use return dev_err_probe();
Quoted 8 lines
drivers/media/i2c/ov5647.c +3
-1+ goto entity_cleanup; + } + ret = ov5647_power_on(dev); if (ret) goto entity_cleanup; --2.43.0
Best Regards,
Tarang
Re: [PATCH v2 1/3] media: i2c: ov5647: Convert to CCI register access helpers
Quoted 85 lines · Tarang Raval
Quoted 53 lines
Use the new common CCI register access helpers to replace the private register access helpers in the ov5647 driver. This simplifies the driver by reducing the amount of code.
Signed-off-by Xiaolei Wang <[email protected]>---
drivers/media/i2c/Kconfig | 1 +drivers/media/i2c/ov5647.c| 997 +++++++++++++++++--------------------2 files changed, 453 insertions(+), 545 deletions(-)drivers/media/i2c/Kconfig +0
-0@@ -529,6 +529,7 @@ config VIDEO_OV5645config
VIDEO_OV5647
tristate "OmniVision OV5647 sensor support"
+ selectV4L2_CCI_I2C
help
This is a Video4Linux2 sensor driver for the OmniVision OV5647 camera.drivers/media/i2c/ov5647.c +1
-15@@ -22,6 +22,7 @@ #include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/videodev2.h> +#include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-event.h>@@ -41,24 +42,19 @@ #define MIPI_CTRL00_BUS_IDLE BIT(2) #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0) -#define OV5647_SW_STANDBY 0x0100 -#define OV5647_SW_RESET 0x0103 -#define OV5647_REG_CHIPID_H 0x300a -#define OV5647_REG_CHIPID_L 0x300b -#define OV5640_REG_PAD_OUT 0x300d -#define OV5647_REG_EXP_HI 0x3500 -#define OV5647_REG_EXP_MID 0x3501 -#define OV5647_REG_EXP_LO 0x3502 -#define OV5647_REG_AEC_AGC 0x3503 -#define OV5647_REG_GAIN_HI 0x350a -#define OV5647_REG_GAIN_LO 0x350b -#define OV5647_REG_VTS_HI 0x380e -#define OV5647_REG_VTS_LO 0x380f -#define OV5647_REG_FRAME_OFF_NUMBER 0x4202 -#define OV5647_REG_MIPI_CTRL00 0x4800drivers/media/i2c/ov5647.c line 51
Quoted 10 lines
drivers/media/i2c/ov5647.c +7
-3-#define OV5647_REG_MIPI_CTRL14 0x4814 -#define OV5647_REG_AWB 0x5001 -#define OV5647_REG_ISPCTRL3D 0x503d +#define OV5647_SW_STANDBY CCI_REG8(0x0100) +#define OV5647_SW_RESET CCI_REG8(0x0103) +#define OV5647_REG_CHIPID CCI_REG16(0x300a) +#define OV5640_REG_PAD_OUT CCI_REG8(0x300d) +#define OV5647_REG_EXPOSURE CCI_REG24(0x3500) +#define OV5647_REG_AEC_AGC CCI_REG8(0x3503) +#define OV5647_REG_GAIN CCI_REG16(0x350b)It should be
0x350a, not0x350b.Quoted 12 lines
drivers/media/i2c/ov5647.c +6
-0+#define OV5647_REG_VTS CCI_REG16(0x380e) +#define OV5647_REG_FRAME_OFF_NUMBER CCI_REG8(0x4202) +#define OV5647_REG_MIPI_CTRL00 CCI_REG8(0x4800) +#define OV5647_REG_MIPI_CTRL14 CCI_REG8(0x4814) +#define OV5647_REG_AWB CCI_REG8(0x5001) +#define OV5647_REG_ISPCTRL3D CCI_REG8(0x503d) #define REG_TERM 0xfffe #define VAL_TERM 0xfe@@ -81,23 +77,19 @@ #define OV5647_EXPOSURE_DEFAULT 1000 #define OV5647_EXPOSURE_MAX 65535...
Quoted 4 lines
drivers/media/i2c/ov5647.c +0
-0@@ -1435,6 +1335,13 @@ static int ov5647_probe(struct i2c_client *client) if (ret < 0) goto ctrl_handler_free;
Quoted 6 lines
drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 1341
Quoted 4 lines
drivers/media/i2c/ov5647.c +4
-0+ sensor->regmap = devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(sensor->regmap)) { + ret = PTR_ERR(sensor->regmap); + dev_err(dev, "failed to initialize CCI: %d\n", ret);Use return
dev_err_probe();
dev_err_probe() is fine, but goto entity_cleanup is needed.
Quoted 6 lines
Quoted 6 lines
drivers/media/i2c/ov5647.c +3
-0+ goto entity_cleanup; + } + ret = ov5647_power_on(dev); if (ret) goto entity_cleanup;
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 1/3] media: i2c: ov5647: Convert to CCI register access helpers
Quoted 86 lines · Tarang Raval
Quoted 85 lines
Quoted 53 lines
Use the new common CCI register access helpers to replace the private register access helpers in the ov5647 driver. This simplifies the driver by reducing the amount of code.
Signed-off-by Xiaolei Wang <[email protected]>---
drivers/media/i2c/Kconfig | 1 +drivers/media/i2c/ov5647.c| 997 +++++++++++++++++--------------------2 files changed, 453 insertions(+), 545 deletions(-)drivers/media/i2c/Kconfig +0
-0@@ -529,6 +529,7 @@ config VIDEO_OV5645config
VIDEO_OV5647
tristate "OmniVision OV5647 sensor support"
+ selectV4L2_CCI_I2C
help
This is a Video4Linux2 sensor driver for the OmniVision OV5647 camera.drivers/media/i2c/ov5647.c +1
-15@@ -22,6 +22,7 @@ #include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/videodev2.h> +#include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-event.h>@@ -41,24 +42,19 @@ #define MIPI_CTRL00_BUS_IDLE BIT(2) #define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0) -#define OV5647_SW_STANDBY 0x0100 -#define OV5647_SW_RESET 0x0103 -#define OV5647_REG_CHIPID_H 0x300a -#define OV5647_REG_CHIPID_L 0x300b -#define OV5640_REG_PAD_OUT 0x300d -#define OV5647_REG_EXP_HI 0x3500 -#define OV5647_REG_EXP_MID 0x3501 -#define OV5647_REG_EXP_LO 0x3502 -#define OV5647_REG_AEC_AGC 0x3503 -#define OV5647_REG_GAIN_HI 0x350a -#define OV5647_REG_GAIN_LO 0x350b -#define OV5647_REG_VTS_HI 0x380e -#define OV5647_REG_VTS_LO 0x380f -#define OV5647_REG_FRAME_OFF_NUMBER 0x4202 -#define OV5647_REG_MIPI_CTRL00 0x4800drivers/media/i2c/ov5647.c line 51
Quoted 10 lines
drivers/media/i2c/ov5647.c +7
-3-#define OV5647_REG_MIPI_CTRL14 0x4814 -#define OV5647_REG_AWB 0x5001 -#define OV5647_REG_ISPCTRL3D 0x503d +#define OV5647_SW_STANDBY CCI_REG8(0x0100) +#define OV5647_SW_RESET CCI_REG8(0x0103) +#define OV5647_REG_CHIPID CCI_REG16(0x300a) +#define OV5640_REG_PAD_OUT CCI_REG8(0x300d) +#define OV5647_REG_EXPOSURE CCI_REG24(0x3500) +#define OV5647_REG_AEC_AGC CCI_REG8(0x3503) +#define OV5647_REG_GAIN CCI_REG16(0x350b)It should be
0x350a, not0x350b.Quoted 12 lines
drivers/media/i2c/ov5647.c +6
-0+#define OV5647_REG_VTS CCI_REG16(0x380e) +#define OV5647_REG_FRAME_OFF_NUMBER CCI_REG8(0x4202) +#define OV5647_REG_MIPI_CTRL00 CCI_REG8(0x4800) +#define OV5647_REG_MIPI_CTRL14 CCI_REG8(0x4814) +#define OV5647_REG_AWB CCI_REG8(0x5001) +#define OV5647_REG_ISPCTRL3D CCI_REG8(0x503d) #define REG_TERM 0xfffe #define VAL_TERM 0xfe@@ -81,23 +77,19 @@ #define OV5647_EXPOSURE_DEFAULT 1000 #define OV5647_EXPOSURE_MAX 65535...
Quoted 4 lines
drivers/media/i2c/ov5647.c +0
-0@@ -1435,6 +1335,13 @@ static int ov5647_probe(struct i2c_client *client) if (ret < 0) goto ctrl_handler_free;
Quoted 8 lines
Quoted 6 lines
drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 1341
Quoted 4 lines
drivers/media/i2c/ov5647.c +4
-0+ sensor->regmap = devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(sensor->regmap)) { + ret = PTR_ERR(sensor->regmap); + dev_err(dev, "failed to initialize CCI: %d\n", ret);Use return
dev_err_probe();
dev_err_probe()is fine, but gotoentity_cleanupis needed.
Yes, my bad.
Keep the existing return path.
Quoted 11 lines
Quoted 6 lines
drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 1347
Quoted 6 lines
drivers/media/i2c/ov5647.c +3
-0+ goto entity_cleanup; + } + ret = ov5647_power_on(dev); if (ret) goto entity_cleanup;
--
Regards,
Laurent Pinchart
Re: [PATCH v2 1/3] media: i2c: ov5647: Convert to CCI register access helpers
In reply to Laurent PinchartQuoted 87 lines · Laurent Pinchart
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 83 lines · Tarang Raval
Quoted 53 lines
Use the new common CCI register access helpers to replace the private register access helpers in the ov5647 driver. This simplifies the driver by reducing the amount of code.
Signed-off-by Xiaolei Wang <[email protected]>--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov5647.c | 997 +++++++++++++++++-------------------- 2 files changed, 453 insertions(+), 545 deletions(-)drivers/media/i2c/Kconfig +1
-0@@ -529,6 +529,7 @@ config VIDEO_OV5645 config VIDEO_OV5647 tristate "OmniVision OV5647 sensor support" + select V4L2_CCI_I2C help This is a Video4Linux2 sensor driver for the OmniVision OV5647 camera.drivers/media/i2c/ov5647.c +1
-15@@ -22,6 +22,7 @@#include <linux/pm_runtime.h> #include <linux/slab.h> #include <linux/videodev2.h> +#include <media/v4l2-cci.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-event.h> @@ -41,24 +42,19 @@#define MIPI_CTRL00_BUS_IDLE BIT(2)#define MIPI_CTRL00_CLOCK_LANE_DISABLE BIT(0) -#define OV5647_SW_STANDBY 0x0100 -#define OV5647_SW_RESET 0x0103 -#define OV5647_REG_CHIPID_H 0x300a -#define OV5647_REG_CHIPID_L 0x300b -#define OV5640_REG_PAD_OUT 0x300d -#define OV5647_REG_EXP_HI 0x3500 -#define OV5647_REG_EXP_MID 0x3501 -#define OV5647_REG_EXP_LO 0x3502 -#define OV5647_REG_AEC_AGC 0x3503 -#define OV5647_REG_GAIN_HI 0x350a -#define OV5647_REG_GAIN_LO 0x350b -#define OV5647_REG_VTS_HI 0x380e -#define OV5647_REG_VTS_LO 0x380f -#define OV5647_REG_FRAME_OFF_NUMBER 0x4202 -#define OV5647_REG_MIPI_CTRL00 0x4800drivers/media/i2c/ov5647.c line 51
Quoted 10 lines
drivers/media/i2c/ov5647.c +7
-3-#define OV5647_REG_MIPI_CTRL14 0x4814 -#define OV5647_REG_AWB 0x5001 -#define OV5647_REG_ISPCTRL3D 0x503d +#define OV5647_SW_STANDBY CCI_REG8(0x0100) +#define OV5647_SW_RESET CCI_REG8(0x0103) +#define OV5647_REG_CHIPID CCI_REG16(0x300a) +#define OV5640_REG_PAD_OUT CCI_REG8(0x300d) +#define OV5647_REG_EXPOSURE CCI_REG24(0x3500) +#define OV5647_REG_AEC_AGC CCI_REG8(0x3503) +#define OV5647_REG_GAIN CCI_REG16(0x350b)It should be
0x350a, not0x350b.Quoted 12 lines
drivers/media/i2c/ov5647.c +6
-0+#define OV5647_REG_VTS CCI_REG16(0x380e) +#define OV5647_REG_FRAME_OFF_NUMBER CCI_REG8(0x4202) +#define OV5647_REG_MIPI_CTRL00 CCI_REG8(0x4800) +#define OV5647_REG_MIPI_CTRL14 CCI_REG8(0x4814) +#define OV5647_REG_AWB CCI_REG8(0x5001) +#define OV5647_REG_ISPCTRL3D CCI_REG8(0x503d)#define REG_TERM 0xfffe#define VAL_TERM 0xfe@@ -81,23 +77,19 @@#define OV5647_EXPOSURE_DEFAULT 1000#define OV5647_EXPOSURE_MAX 65535...
Quoted 4 lines
drivers/media/i2c/ov5647.c +0
-0@@ -1435,6 +1335,13 @@ static int ov5647_probe(struct i2c_client *client)if (ret <0 ) goto ctrl_handler_free;
Quoted 6 lines
Quoted 5 lines
drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 1341
Quoted 4 lines
drivers/media/i2c/ov5647.c +4
-0+ sensor->regmap =devm_cci_regmap_init_i2c (client,16 ); +if (IS_ERR (sensor->regmap)) { + ret =PTR_ERR (sensor->regmap); +dev_err (dev,"failed to initialize CCI: %d\n" , ret);Use return
dev_err_probe();
dev_err_probe()is fine, but gotoentity_cleanupis needed.
Hi Tarang and Laurent,
Thank you both for the review feedback.
I'll address both issues in v3:
1. Fix OV5647_REG_GAIN to use CCI_REG16(0x350a) instead of 0x350b
2. Update the error handling to use dev_err_probe() while maintaining the goto entity_cleanup path for proper resource cleanup
Will send the updated patch shortly.
Best regards,
Xiaolei
Quoted 11 lines
Quoted 7 lines
drivers/media/i2c/ov5647.c static int ov5647_probe(struct i2c_client *client) · line 1347
Quoted 7 lines
drivers/media/i2c/ov5647.c +3
-0+ goto entity_cleanup; + } + ret =ov5647_power_on (dev);if (ret) goto entity_cleanup;--
Regards,Laurent Pinchart
Re: [PATCH v2 1/3] media: i2c: ov5647: Convert to CCI register access helpers
In reply to Xiaolei WangHi,
Quoted 3 lines · Xiaolei Wang
Use the new common CCI register access helpers to replace the private register access helpers in the ov5647 driver. This simplifies the driver by reducing the amount of code.
Thank you for your patch, it is great to see more drivers being converted to the CCI register access helpers.
Quoted 2 lines
Signed-off-by Xiaolei Wang <[email protected]>---
...
Quoted 4 lines
drivers/media/i2c/ov5647.c +0
-0
...
Quoted 13 lines
drivers/media/i2c/ov5647.c +4
-4@@ -130,377 +122,377 @@ static const u8 ov5647_test_pattern_val[] = { 0x81, /* Random Data */ }; -static const struct regval_list sensor_oe_disable_regs[] = { - {0x3000 ,0x00 }, - {0x3001 ,0x00 }, - {0x3002 ,0x00 }, +static const struct cci_reg_sequence sensor_oe_disable_regs[] = { + {CCI_REG8 (0x3000 ),0x00 }, + {CCI_REG8 (0x3001 ),0x00 }, + {CCI_REG8 (0x3002 ),0x00 }, };
drivers/media/i2c/ov5647.c static const u8 ov5647_test_pattern_val[] = { · line 135
Quoted 10 lines
drivers/media/i2c/ov5647.c +4
-4-static const struct regval_list sensor_oe_enable_regs[] = { - {0x3000 ,0x0f }, - {0x3001 ,0xff }, - {0x3002 ,0xe4 }, +static const struct cci_reg_sequence sensor_oe_enable_regs[] = { + {CCI_REG8 (0x3000 ),0x0f }, + {CCI_REG8 (0x3001 ),0xff }, + {CCI_REG8 (0x3002 ),0xe4 }, };
For these 2, but also for the 2 much longer arrays with address, value pairs which you are replacing, you are replacing all the register addresses with CCI_REG8(0x3000).
Even though some of these are like 16 bit or even 24bit registers, this in itself is not a problem.
But if you are replacing them 1:1 like this anyway then IMHO it is better to just:
- Directly use struct reg_sequence instead of struct cci_reg_sequence
- Call regmap_multi_reg_write() instead of cci_multi_reg_write()
then you can keep all the initializer values for the arrays the same (no need to add CCI_REG8() around the addresses). This is also how this was done in other drivers when they were converted to the CCI helpers.
This greatly reduces the size of the diff and makes it much easier to review the patch.
Regards,
Hans
Re: [PATCH v2 1/3] media: i2c: ov5647: Convert to CCI register access helpers
In reply to Xiaolei WangQuoted 23 lines
static int
ov5647_set_mode(struct v4l2_subdev *sd)
{
structi2c_client*client =v4l2_get_subdevdata(sd); struct ov5647 *sensor =to_sensor(sd);
- u8 resetval, rdval;
+ u64 resetval, rdval;
int ret;
- ret =ov5647_read(sd, OV5647_SW_STANDBY, &rdval);
+ ret =cci_read(sensor->regmap, OV5647_SW_STANDBY, &rdval, NULL); if (ret < 0)
return ret;
- ret = ov5647_write_array(sd,sensor->mode->reg_list,
-sensor->mode->num_regs);
+ ret = cci_multi_reg_write(sensor->regmap,sensor->mode->reg_list, +sensor->mode->num_regs, NULL); if (ret < 0) {
dev_err(&client->dev, "write sensor default regs error\n"); return ret;(quoted diff) +0
-0@@ -706,13 +624,13 @@ static int ov5647_set_mode(struct v4l2_subdev *sd) if (ret < 0) return ret;
Quoted 5 lines
- ret =ov5647_read(sd, OV5647_SW_STANDBY, &resetval);
+ ret =cci_read(sensor->regmap, OV5647_SW_STANDBY, &resetval, NULL); if (ret < 0)
return ret;
Are both read operations in ov5647_set_mode() really needed?
Every mode table already ends with writing 0x0100 => 0x01.
Does anyone know the purpose of these reads, or are they unused?
Best Regards,
Tarang
Quoted 7 lines
if (!(resetval &
0x01)) {
dev_err(&client->dev, "Device was in SW standby"); - ret =ov5647_write(sd, OV5647_SW_STANDBY, 0x01);
+ ret =cci_write(sensor->regmap, OV5647_SW_STANDBY, 0x01, NULL); if (ret < 0)
return ret;
}
PATCH v2 2/3 media: i2c: ov5647: Switch to using the sub-device state lock
In reply to Xiaolei WangSwitch to using the sub-device state lock and properly call v4l2_subdev_init_finalize() / v4l2_subdev_cleanup() on probe() / remove().
--- drivers/media/i2c/ov5647.c | 40 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-)
drivers/media/i2c/ov5647.c +14 -26
@@ -91,7 +91,6 @@ struct ov5647 {struct v4l2_subdev sd;struct regmap *regmap;struct media_pad pad; -struct mutex lock;struct clk *xclk;struct gpio_desc *pwdn;bool clock_ncont;
@@ -652,7 +651,7 @@ static int ov5647_stream_on(struct v4l2_subdev *sd) }/* Apply customized values from user when stream starts. */ - ret =__v4l2_ctrl_handler_setup (sd->ctrl_handler); + ret =v4l2_ctrl_handler_setup (sd->ctrl_handler);if (ret)return ret;
@@ -807,15 +806,12 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,static int ov5647_s_stream (struct v4l2_subdev *sd,int enable) {struct i2c_client *client =v4l2_get_subdevdata (sd); -struct ov5647 *sensor =to_sensor (sd);int ret; -mutex_lock (&sensor->lock); -if (enable) { ret =pm_runtime_resume_and_get (&client->dev);if (ret <0 ) - goto error_unlock; +return ret; ret =ov5647_stream_on (sd);if (ret <0 ) {
@@ -831,14 +827,10 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)pm_runtime_put (&client->dev); } -mutex_unlock (&sensor->lock); -return 0 ; error_pm:pm_runtime_put (&client->dev); -error_unlock: -mutex_unlock (&sensor->lock);return ret; }
@@ -886,7 +878,6 @@ static int ov5647_get_pad_fmt(struct v4l2_subdev *sd,const struct v4l2_mbus_framefmt *sensor_format;struct ov5647 *sensor =to_sensor (sd); -mutex_lock (&sensor->lock);switch (format->which) {case V4L2_SUBDEV_FORMAT_TRY : sensor_format = v4l2_subdev_state_get_format(sd_state,
@@ -898,7 +889,6 @@ static int ov5647_get_pad_fmt(struct v4l2_subdev *sd, } *fmt = *sensor_format; -mutex_unlock (&sensor->lock);return 0 ; }
@@ -916,7 +906,6 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd, fmt->width, fmt->height);/* Update the sensor mode and apply at it at streamon time. */ -mutex_lock (&sensor->lock);if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { *v4l2_subdev_state_get_format (sd_state, format->pad) = mode->format; }else {
@@ -945,7 +934,6 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd, exposure_def); } *fmt = mode->format; -mutex_unlock (&sensor->lock);return 0 ; }
@@ -958,10 +946,8 @@ static int ov5647_get_selection(struct v4l2_subdev *sd,case V4L2_SEL_TGT_CROP : {struct ov5647 *sensor =to_sensor (sd); -mutex_lock (&sensor->lock); sel->r = *__ov5647_get_pad_crop (sensor, sd_state, sel->pad, sel->which); -mutex_unlock (&sensor->lock);return 0 ; }
@@ -1114,9 +1100,6 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)struct i2c_client *client =v4l2_get_subdevdata (sd);int ret =0 ; - -/* v4l2_ctrl_lock() locks our own mutex */ -if (ctrl->id ==V4L2_CID_VBLANK ) {int exposure_max, exposure_def;
@@ -1316,13 +1299,11 @@ static int ov5647_probe(struct i2c_client *client)return -EINVAL ; } -mutex_init (&sensor->lock); - sensor->mode =OV5647_DEFAULT_MODE ; ret =ov5647_init_controls (sensor);if (ret) - goto mutex_destroy; +return ret; sd = &sensor->sd;v4l2_i2c_subdev_init (sd, client, &ov5647_subdev_ops);
@@ -1350,9 +1331,16 @@ static int ov5647_probe(struct i2c_client *client)if (ret <0 ) goto power_off; + sd->state_lock = sensor->ctrls.lock; + ret =v4l2_subdev_init_finalize (sd); +if (ret <0 ) { +dev_err (&client->dev,"failed to init subdev: %d" , ret); + goto power_off; + } + ret =v4l2_async_register_subdev (sd);if (ret <0 ) - goto power_off; + goto v4l2_subdev_cleanup;/* Enable runtime PM and turn off the device */ pm_runtime_set_active (dev);
@@ -1363,14 +1351,14 @@ static int ov5647_probe(struct i2c_client *client)return 0 ; +v4l2_subdev_cleanup: +v4l2_subdev_cleanup (sd); power_off:ov5647_power_off (dev); entity_cleanup:media_entity_cleanup (&sd->entity); ctrl_handler_free:v4l2_ctrl_handler_free (&sensor->ctrls); -mutex_destroy: -mutex_destroy (&sensor->lock);return ret; }
@@ -1381,11 +1369,11 @@ static void ov5647_remove(struct i2c_client *client)struct ov5647 *sensor =to_sensor (sd);v4l2_async_unregister_subdev (&sensor->sd); +v4l2_subdev_cleanup (sd);media_entity_cleanup (&sensor->sd.entity);v4l2_ctrl_handler_free (&sensor->ctrls);v4l2_device_unregister_subdev (sd);pm_runtime_disable (&client->dev); -mutex_destroy (&sensor->lock); }static const struct dev_pm_ops ov5647_pm_ops = {
Signature · 1 line
2.43.0
Sakari Ailus
maintainerRe: [PATCH v2 2/3] media: i2c: ov5647: Switch to using the sub-device state lock
Hi Xiaolei,
Quoted 31 lines · Xiaolei Wang
Switch to using the sub-device state lock and properly call
v4l2_subdev_init_finalize()/v4l2_subdev_cleanup()onprobe()/remove().Signed-off-by Xiaolei Wang <[email protected]>--- drivers/media/i2c/ov5647.c | 40 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-)drivers/media/i2c/ov5647.c +1
-2@@ -91,7 +91,6 @@ struct ov5647 {struct v4l2_subdev sd;struct regmap *regmap;struct media_pad pad; -struct mutex lock;struct clk *xclk;struct gpio_desc *pwdn;bool clock_ncont;@@ -652,7 +651,7 @@ static int ov5647_stream_on(struct v4l2_subdev *sd) }/* Apply customized values from user when stream starts. */ - ret =__v4l2_ctrl_handler_setup (sd->ctrl_handler); + ret =v4l2_ctrl_handler_setup (sd->ctrl_handler);if (ret)return ret;
drivers/media/i2c/ov5647.c __ov5647_get_pad_crop(struct ov5647 *ov5647, · line 813
Quoted 7 lines
drivers/media/i2c/ov5647.c +0
-2@@ -807,15 +806,12 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,static int ov5647_s_stream (struct v4l2_subdev *sd,int enable) {struct i2c_client *client =v4l2_get_subdevdata (sd); -struct ov5647 *sensor =to_sensor (sd);int ret; -mutex_lock (&sensor->lock);
Note that you shouldn't remove mutex_lock() here quite yet -- s_stream() callback won't involve sub-device state and thus the caller won't take the state lock either. In other words, the end result is fine after the third patch so you should explicitly lock the active state and remove that in the third patch (see e.g. v4l2_subdev_lock_and_get_active_state() in drivers/media/i2c/imx290.c).
Quoted 24 lines
drivers/media/i2c/ov5647.c +1
-6-if (enable) { ret =pm_runtime_resume_and_get (&client->dev);if (ret <0 ) - goto error_unlock; +return ret; ret =ov5647_stream_on (sd);if (ret <0 ) {@@ -831,14 +827,10 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)pm_runtime_put (&client->dev); } -mutex_unlock (&sensor->lock); -return 0 ; error_pm:pm_runtime_put (&client->dev); -error_unlock: -mutex_unlock (&sensor->lock);return ret; }
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH v2 2/3] media: i2c: ov5647: Switch to using the sub-device state lock
Quoted 43 lines · Sakari Ailus
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Hi Xiaolei,
Quoted 37 lines · Xiaolei Wang
Switch to using the sub-device state lock and properly call
v4l2_subdev_init_finalize()/v4l2_subdev_cleanup()onprobe()/remove().Signed-off-by Xiaolei Wang <[email protected]>--- drivers/media/i2c/ov5647.c | 40 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-)drivers/media/i2c/ov5647.c +1
-3@@ -91,7 +91,6 @@ struct ov5647 {struct v4l2_subdev sd;struct regmap *regmap;struct media_pad pad; -struct mutex lock;struct clk *xclk;struct gpio_desc *pwdn;bool clock_ncont;@@ -652,7 +651,7 @@ static int ov5647_stream_on(struct v4l2_subdev *sd) }/* Apply customized values from user when stream starts. */ - ret =__v4l2_ctrl_handler_setup (sd->ctrl_handler); + ret =v4l2_ctrl_handler_setup (sd->ctrl_handler);if (ret)return ret;@@ -807,15 +806,12 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,static int ov5647_s_stream (struct v4l2_subdev *sd,int enable) {struct i2c_client *client =v4l2_get_subdevdata (sd); -struct ov5647 *sensor =to_sensor (sd);int ret;
Quoted 7 lines
drivers/media/i2c/ov5647.c __ov5647_get_pad_crop(struct ov5647 *ov5647, · line 813
Quoted 1 line
drivers/media/i2c/ov5647.c +0
-1-mutex_lock (&sensor->lock);Note that you shouldn't remove
mutex_lock()here quite yet --s_stream()callback won't involve sub-device state and thus the caller won't take the state lock either. In other words, the end result is fine after the third patch so you should explicitly lock the active state and remove that in the third patch (see e.g.v4l2_subdev_lock_and_get_active_state()indrivers/media/i2c/imx290.c).
Hi Hans,
Thank you for the detailed review and suggestions.
You're absolutely right about the approach. Using regmap_multi_reg_write() with struct reg_sequence would indeed be cleaner and result in a much smaller, more reviewable diff.
I'll revise the patch to:
- Use struct reg_sequence instead of struct cci_reg_sequence
- Call regmap_multi_reg_write() instead of cci_multi_reg_write()
- Keep the existing array initializer values unchanged
This will maintain the same functionality while making the conversion more straightforward and consistent with other driver conversions.
I'll send v3 shortly.
Quoted 29 lines
Quoted 15 lines
drivers/media/i2c/ov5647.c +1
-3-if (enable) { ret =pm_runtime_resume_and_get (&client->dev);if (ret <0 ) - goto error_unlock; +return ret; ret =ov5647_stream_on (sd);if (ret <0 ) {@@ -831,14 +827,10 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)pm_runtime_put (&client->dev); } -mutex_unlock (&sensor->lock);drivers/media/i2c/ov5647.c static int ov5647_s_stream(struct v4l2_subdev *sd, int enable) · line 836
Quoted 10 lines
drivers/media/i2c/ov5647.c +0
-3-return 0 ; error_pm:pm_runtime_put (&client->dev); -error_unlock: -mutex_unlock (&sensor->lock);return ret; }--
Kind regards,Sakari Ailus
PATCH v2 3/3 media: i2c: ov5647: switch to {enable,disable}_streams
In reply to Xiaolei WangSwitch from s_stream to enable_streams and disable_streams callbacks.
--- drivers/media/i2c/ov5647.c | 69 ++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 40 deletions(-)
drivers/media/i2c/ov5647.c +29 -40
@@ -637,23 +637,29 @@ static int ov5647_set_mode(struct v4l2_subdev *sd)return 0 ; } -static int ov5647_stream_on (struct v4l2_subdev *sd) +static int ov5647_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) {struct i2c_client *client =v4l2_get_subdevdata (sd);struct ov5647 *sensor =to_sensor (sd);u8 val =MIPI_CTRL00_BUS_IDLE ;int ret =0 ; + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) +return ret; + ret =ov5647_set_mode (sd);if (ret) {dev_err (&client->dev,"Failed to program sensor mode: %d\n" , ret); -return ret; + goto err_rpm_put; }/* Apply customized values from user when stream starts. */ - ret =v4l2_ctrl_handler_setup (sd->ctrl_handler); + ret =__v4l2_ctrl_handler_setup (sd->ctrl_handler);if (ret) -return ret; + goto err_rpm_put;if (sensor->clock_ncont) val |= MIPI_CTRL00_CLOCK_LANE_GATE |
@@ -663,11 +669,18 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x00 , &ret);cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x00 , &ret); +err_rpm_put: +if (ret) +pm_runtime_put (&client->dev); +return ret; } -static int ov5647_stream_off (struct v4l2_subdev *sd) +static int ov5647_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) { +struct i2c_client *client =v4l2_get_subdevdata (sd);struct ov5647 *sensor =to_sensor (sd);int ret =0 ;
@@ -677,13 +690,15 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x0f , &ret);cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x01 , &ret); +pm_runtime_put (&client->dev); +return ret; }static int ov5647_power_on (struct device *dev) {struct ov5647 *sensor =dev_get_drvdata (dev); -int ret; +int ret =0 ;dev_dbg (dev,"OV5647 power on\n" );
@@ -706,7 +721,11 @@ static int ov5647_power_on(struct device *dev) }/* Stream off to coax lanes into LP-11 state. */ - ret =ov5647_stream_off (&sensor->sd); +cci_write (sensor->regmap,OV5647_REG_MIPI_CTRL00 , +MIPI_CTRL00_CLOCK_LANE_GATE |MIPI_CTRL00_BUS_IDLE | +MIPI_CTRL00_CLOCK_LANE_DISABLE , &ret); +cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x0f , &ret); +cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x01 , &ret);if (ret <0 ) {dev_err (dev,"camera not available, check power\n" ); goto error_clk_disable;
@@ -803,40 +822,8 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,return NULL ; } -static int ov5647_s_stream (struct v4l2_subdev *sd,int enable) -{ -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; - -if (enable) { - ret =pm_runtime_resume_and_get (&client->dev); -if (ret <0 ) -return ret; - - ret =ov5647_stream_on (sd); -if (ret <0 ) { -dev_err (&client->dev,"stream start failed: %d\n" , ret); - goto error_pm; - } - }else { - ret =ov5647_stream_off (sd); -if (ret <0 ) { -dev_err (&client->dev,"stream stop failed: %d\n" , ret); - goto error_pm; - } -pm_runtime_put (&client->dev); - } - -return 0 ; - -error_pm: -pm_runtime_put (&client->dev); - -return ret; -} -static const struct v4l2_subdev_video_ops ov5647_subdev_video_ops = { - .s_stream = ov5647_s_stream, + .s_stream = v4l2_subdev_s_stream_helper, }; static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,
@@ -979,6 +966,8 @@ static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = { .set_fmt = ov5647_set_pad_fmt, .get_fmt = ov5647_get_pad_fmt, .get_selection = ov5647_get_selection, + .enable_streams = ov5647_enable_streams, + .disable_streams = ov5647_disable_streams, };static const struct v4l2_subdev_ops ov5647_subdev_ops = {
Signature · 1 line
2.43.0
Re: [PATCH v2 3/3] media: i2c: ov5647: switch to {enable,disable}_streams
Quoted 46 lines · Xiaolei Wang
Switch from
s_streamtoenable_streamsanddisable_streamscallbacks.Signed-off-by Xiaolei Wang <[email protected]>--- drivers/media/i2c/ov5647.c | 69 ++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 40 deletions(-)drivers/media/i2c/ov5647.c +10
-4@@ -637,23 +637,29 @@ static int ov5647_set_mode(struct v4l2_subdev *sd)return 0 ; } -static int ov5647_stream_on (struct v4l2_subdev *sd) +static int ov5647_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) {struct i2c_client *client =v4l2_get_subdevdata (sd);struct ov5647 *sensor =to_sensor (sd);u8 val =MIPI_CTRL00_BUS_IDLE ;int ret =0 ; + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) +return ret; + ret =ov5647_set_mode (sd);if (ret) {dev_err (&client->dev,"Failed to program sensor mode: %d\n" , ret); -return ret; + goto err_rpm_put; }/* Apply customized values from user when stream starts. */ - ret =v4l2_ctrl_handler_setup (sd->ctrl_handler); + ret =__v4l2_ctrl_handler_setup (sd->ctrl_handler);if (ret) -return ret; + goto err_rpm_put;if (sensor->clock_ncont) val |= MIPI_CTRL00_CLOCK_LANE_GATE |
drivers/media/i2c/ov5647.c static int ov5647_stream_on(struct v4l2_subdev *sd) · line 672
Quoted 4 lines
drivers/media/i2c/ov5647.c +1
-0@@ -663,11 +669,18 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x00 , &ret);cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x00 , &ret); +err_rpm_put:
I would name the label 'done' as it's also used in the normal exit path, not only in case of errors.
Quoted 33 lines
drivers/media/i2c/ov5647.c +10
-2+if (ret) +pm_runtime_put (&client->dev); +return ret; } -static int ov5647_stream_off (struct v4l2_subdev *sd) +static int ov5647_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) { +struct i2c_client *client =v4l2_get_subdevdata (sd);struct ov5647 *sensor =to_sensor (sd);int ret =0 ;@@ -677,13 +690,15 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x0f , &ret);cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x01 , &ret); +pm_runtime_put (&client->dev); +return ret; }static int ov5647_power_on (struct device *dev) {struct ov5647 *sensor =dev_get_drvdata (dev); -int ret; +int ret =0 ;dev_dbg (dev,"OV5647 power on\n" );
drivers/media/i2c/ov5647.c static int ov5647_power_on(struct device *dev) · line 728
Quoted 9 lines
drivers/media/i2c/ov5647.c +5
-1@@ -706,7 +721,11 @@ static int ov5647_power_on(struct device *dev) }/* Stream off to coax lanes into LP-11 state. */ - ret =ov5647_stream_off (&sensor->sd); +cci_write (sensor->regmap,OV5647_REG_MIPI_CTRL00 , +MIPI_CTRL00_CLOCK_LANE_GATE |MIPI_CTRL00_BUS_IDLE | +MIPI_CTRL00_CLOCK_LANE_DISABLE , &ret); +cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x0f , &ret); +cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x01 , &ret);
Could you please factor this code out to a separate function (you can name it ov5647_stream_stop() for instance) instead of duplicating it ?
With that (and the 0 initialization of ret above dropped as it won't be needed anymore),
Quoted 54 lines
drivers/media/i2c/ov5647.c +3
-33if (ret <0 ) {dev_err (dev,"camera not available, check power\n" ); goto error_clk_disable;@@ -803,40 +822,8 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,return NULL ; } -static int ov5647_s_stream (struct v4l2_subdev *sd,int enable) -{ -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; - -if (enable) { - ret =pm_runtime_resume_and_get (&client->dev); -if (ret <0 ) -return ret; - - ret =ov5647_stream_on (sd); -if (ret <0 ) { -dev_err (&client->dev,"stream start failed: %d\n" , ret); - goto error_pm; - } - }else { - ret =ov5647_stream_off (sd); -if (ret <0 ) { -dev_err (&client->dev,"stream stop failed: %d\n" , ret); - goto error_pm; - } -pm_runtime_put (&client->dev); - } - -return 0 ; - -error_pm: -pm_runtime_put (&client->dev); - -return ret; -} -static const struct v4l2_subdev_video_ops ov5647_subdev_video_ops = { - .s_stream = ov5647_s_stream, + .s_stream = v4l2_subdev_s_stream_helper, }; static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,@@ -979,6 +966,8 @@ static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = { .set_fmt = ov5647_set_pad_fmt, .get_fmt = ov5647_get_pad_fmt, .get_selection = ov5647_get_selection, + .enable_streams = ov5647_enable_streams, + .disable_streams = ov5647_disable_streams, };static const struct v4l2_subdev_ops ov5647_subdev_ops = {
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 3/3] media: i2c: ov5647: switch to {enable,disable}_streams
Quoted 102 lines · Laurent Pinchart
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.Quoted 46 lines · Xiaolei Wang
Switch from
s_streamtoenable_streamsanddisable_streamscallbacks.Signed-off-by Xiaolei Wang <[email protected]>--- drivers/media/i2c/ov5647.c | 69 ++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 40 deletions(-)drivers/media/i2c/ov5647.c +10
-4@@ -637,23 +637,29 @@ static int ov5647_set_mode(struct v4l2_subdev *sd)return 0 ; } -static int ov5647_stream_on (struct v4l2_subdev *sd) +static int ov5647_enable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) {struct i2c_client *client =v4l2_get_subdevdata (sd);struct ov5647 *sensor =to_sensor (sd);u8 val =MIPI_CTRL00_BUS_IDLE ;int ret =0 ; + ret =pm_runtime_resume_and_get (&client->dev); +if (ret <0 ) +return ret; + ret =ov5647_set_mode (sd);if (ret) {dev_err (&client->dev,"Failed to program sensor mode: %d\n" , ret); -return ret; + goto err_rpm_put; }/* Apply customized values from user when stream starts. */ - ret =v4l2_ctrl_handler_setup (sd->ctrl_handler); + ret =__v4l2_ctrl_handler_setup (sd->ctrl_handler);if (ret) -return ret; + goto err_rpm_put;if (sensor->clock_ncont) val |= MIPI_CTRL00_CLOCK_LANE_GATE |drivers/media/i2c/ov5647.c static int ov5647_stream_on(struct v4l2_subdev *sd) · line 672
Quoted 4 lines
drivers/media/i2c/ov5647.c +1
-0@@ -663,11 +669,18 @@ static int ov5647_stream_on(struct v4l2_subdev *sd)cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x00 , &ret);cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x00 , &ret); +err_rpm_put:I would name the label 'done' as it's also used in the normal exit path, not only in case of errors.
Quoted 33 lines
drivers/media/i2c/ov5647.c +10
-2+if (ret) +pm_runtime_put (&client->dev); +return ret; } -static int ov5647_stream_off (struct v4l2_subdev *sd) +static int ov5647_disable_streams (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,u32 pad, +u64 streams_mask) { +struct i2c_client *client =v4l2_get_subdevdata (sd);struct ov5647 *sensor =to_sensor (sd);int ret =0 ;@@ -677,13 +690,15 @@ static int ov5647_stream_off(struct v4l2_subdev *sd)cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x0f , &ret);cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x01 , &ret); +pm_runtime_put (&client->dev); +return ret; }static int ov5647_power_on (struct device *dev) {struct ov5647 *sensor =dev_get_drvdata (dev); -int ret; +int ret =0 ;dev_dbg (dev,"OV5647 power on\n" );drivers/media/i2c/ov5647.c static int ov5647_power_on(struct device *dev) · line 728
Quoted 9 lines
drivers/media/i2c/ov5647.c +5
-1@@ -706,7 +721,11 @@ static int ov5647_power_on(struct device *dev) }/* Stream off to coax lanes into LP-11 state. */ - ret =ov5647_stream_off (&sensor->sd); +cci_write (sensor->regmap,OV5647_REG_MIPI_CTRL00 , +MIPI_CTRL00_CLOCK_LANE_GATE |MIPI_CTRL00_BUS_IDLE | +MIPI_CTRL00_CLOCK_LANE_DISABLE , &ret); +cci_write (sensor->regmap,OV5647_REG_FRAME_OFF_NUMBER ,0x0f , &ret); +cci_write (sensor->regmap,OV5640_REG_PAD_OUT ,0x01 , &ret);Could you please factor this code out to a separate function (you can name it
ov5647_stream_stop()for instance) instead of duplicating it ?
Quoted 4 lines
With that (and the 0 initialization of ret above dropped as it won't be needed anymore),
Reviewed-by Laurent Pinchart <[email protected]>
Hi Laurent,
Thank you for the review and the suggestions.
I'll address both points in v3:
1. Rename the label from 'err_rpm_put' to 'done' since it's used for both error and normal exit paths.
2. Extract the duplicated stream stop code into a separate ov5647_stream_stop() function to eliminate code duplication between ov5647_disable_streams() and ov5647_power_on().
3. Remove the unnecessary ret = 0 initialization once the function is extracted.
Will send the updated patch shortly.
Best regards,
Xiaolei
Quoted 59 lines
Quoted 47 lines
drivers/media/i2c/ov5647.c +1
-33if (ret <0 ) {dev_err (dev,"camera not available, check power\n" ); goto error_clk_disable;@@ -803,40 +822,8 @@ __ov5647_get_pad_crop(struct ov5647 *ov5647,return NULL ; } -static int ov5647_s_stream (struct v4l2_subdev *sd,int enable) -{ -struct i2c_client *client =v4l2_get_subdevdata (sd); -int ret; - -if (enable) { - ret =pm_runtime_resume_and_get (&client->dev); -if (ret <0 ) -return ret; - - ret =ov5647_stream_on (sd); -if (ret <0 ) { -dev_err (&client->dev,"stream start failed: %d\n" , ret); - goto error_pm; - } - }else { - ret =ov5647_stream_off (sd); -if (ret <0 ) { -dev_err (&client->dev,"stream stop failed: %d\n" , ret); - goto error_pm; - } -pm_runtime_put (&client->dev); - } - -return 0 ; - -error_pm: -pm_runtime_put (&client->dev); - -return ret; -} -static const struct v4l2_subdev_video_ops ov5647_subdev_video_ops = { - .s_stream = ov5647_s_stream, + .s_stream = v4l2_subdev_s_stream_helper, }; static int ov5647_enum_mbus_code(struct v4l2_subdev *sd,drivers/media/i2c/ov5647.c static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = { · line 973
Quoted 8 lines
drivers/media/i2c/ov5647.c +2
-0@@ -979,6 +966,8 @@ static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = { .set_fmt = ov5647_set_pad_fmt, .get_fmt = ov5647_get_pad_fmt, .get_selection = ov5647_get_selection, + .enable_streams = ov5647_enable_streams, + .disable_streams = ov5647_disable_streams, };static const struct v4l2_subdev_ops ov5647_subdev_ops = {--
Regards,Laurent Pinchart