Omnivision OV4689 refactoring and improvements
Mikhail Rudenko
maintainerv2 cover Omnivision OV4689 refactoring and improvements
Hi,
This series contains refactoring and new features implementation for the Omnivision OV4689 sensor driver. Specifically, patches 1, 2, 3, 5, 6, 10, 15, 16, 18, and 19 are refactorings, and are not supposed to introduce any functional change. Patches 4 and 7 perform migration to CCI helpers and subdevice active state respectively, and should not introduce any hardware- and/or user-visible change either. Patch 8 fixes a possible race condition due to v4l2_async_register_subdev_sensor being called too early in ov4689_probe, and patch 9 migrates power management to PM autosuspend.
Patches 11-14 expose more sensor controls to the userspace, such as (read-write) HBLANK, VFLIP/HFLIP, digital gain, and color balance. Patch 17 implements configurable analogue crop rectangle via .set_selection callback. And finally, patch 20 enables 2x2 binning option. It should be noted that publicly available sensor documentation is lacking description of many registers and their value ranges, so a lot of values had to be found by experimentation.
Changes in v2:
- collect Laurent's r-b's
- squash together "CCI conversion" and "Set gain in one 16 bit write"
- use ctrl->val in ov4689_set_ctrl
- rename try_fmt to fmt in ov4689_init_cfg and drop corresponding comment
- rebase on top of media-stage and rename init_cfg->init_state
- sort register definitions by address throughout the whole series
- fix number of controls hint in v4l2_ctrl_handler_init
- make all hexadecimal constants lowercase
- disable runtime pm in probe error path
- implement pm autosuspend
Mikhail Rudenko (20):
media: i2c: ov4689: Clean up and annotate the register table
media: i2c: ov4689: Sort register definitions by address
media: i2c: ov4689: Fix typo in a comment
media: i2c: ov4689: CCI conversion
media: i2c: ov4689: Remove i2c_client from ov4689 struct
media: i2c: ov4689: Refactor ov4689_set_ctrl
media: i2c: ov4689: Use sub-device active state
media: i2c: ov4689: Enable runtime PM before registering sub-device
media: i2c: ov4689: Use runtime PM autosuspend
media: i2c: ov4689: Remove max_fps field from struct ov4689_mode
media: i2c: ov4689: Make horizontal blanking configurable
media: i2c: ov4689: Implement vflip/hflip controls
media: i2c: ov4689: Implement digital gain control
media: i2c: ov4689: Implement manual color balance controls
media: i2c: ov4689: Move pixel array size out of struct ov4689_mode
media: i2c: ov4689: Set timing registers programmatically
media: i2c: ov4689: Configurable analogue crop
media: i2c: ov4689: Eliminate struct ov4689_mode
media: i2c: ov4689: Refactor ov4689_s_stream
media: i2c: ov4689: Implement 2x2 binning
drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov4689.c | 964 +++++++++++++++++++++++-------------- 2 files changed, 592 insertions(+), 373 deletions(-)
--
2.43.0
Mikhail Rudenko
maintainerPATCH v2 1/20 media: i2c: ov4689: Clean up and annotate the register table
Many values in the register table are actually power-on defaults. Remove those and also unused HDR exposures and gains. Annotate the remaining values using the publicly available datasheet to facilitate further development. No functional change intended.
--- drivers/media/i2c/ov4689.c | 203 +++++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 85 deletions(-)
drivers/media/i2c/ov4689.c +118 -85
@@ -3,7 +3,7 @@* ov4689 driver * * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. -* Copyright (C) 2022 Mikhail Rudenko +* Copyright (C) 2022, 2023 Mikhail Rudenko */ #include <linux/clk.h>
@@ -123,90 +123,123 @@ struct ov4689_gain_range {* mipi_datarate per lane 1008Mbps */ static const struct regval ov4689_2688x1520_regs[] = { - {0x0103 ,0x01 }, {0x3638 ,0x00 }, {0x0300 ,0x00 }, - {0x0302 ,0x2a }, {0x0303 ,0x00 }, {0x0304 ,0x03 }, - {0x030b ,0x00 }, {0x030d ,0x1e }, {0x030e ,0x04 }, - {0x030f ,0x01 }, {0x0312 ,0x01 }, {0x031e ,0x00 }, - {0x3000 ,0x20 }, {0x3002 ,0x00 }, {0x3018 ,0x72 }, - {0x3020 ,0x93 }, {0x3021 ,0x03 }, {0x3022 ,0x01 }, - {0x3031 ,0x0a }, {0x303f ,0x0c }, {0x3305 ,0xf1 }, - {0x3307 ,0x04 }, {0x3309 ,0x29 }, {0x3500 ,0x00 }, - {0x3501 ,0x60 }, {0x3502 ,0x00 }, {0x3503 ,0x04 }, - {0x3504 ,0x00 }, {0x3505 ,0x00 }, {0x3506 ,0x00 }, - {0x3507 ,0x00 }, {0x3508 ,0x00 }, {0x3509 ,0x80 }, - {0x350a ,0x00 }, {0x350b ,0x00 }, {0x350c ,0x00 }, - {0x350d ,0x00 }, {0x350e ,0x00 }, {0x350f ,0x80 }, - {0x3510 ,0x00 }, {0x3511 ,0x00 }, {0x3512 ,0x00 }, - {0x3513 ,0x00 }, {0x3514 ,0x00 }, {0x3515 ,0x80 }, - {0x3516 ,0x00 }, {0x3517 ,0x00 }, {0x3518 ,0x00 }, - {0x3519 ,0x00 }, {0x351a ,0x00 }, {0x351b ,0x80 }, - {0x351c ,0x00 }, {0x351d ,0x00 }, {0x351e ,0x00 }, - {0x351f ,0x00 }, {0x3520 ,0x00 }, {0x3521 ,0x80 }, - {0x3522 ,0x08 }, {0x3524 ,0x08 }, {0x3526 ,0x08 }, - {0x3528 ,0x08 }, {0x352a ,0x08 }, {0x3602 ,0x00 }, - {0x3603 ,0x40 }, {0x3604 ,0x02 }, {0x3605 ,0x00 }, - {0x3606 ,0x00 }, {0x3607 ,0x00 }, {0x3609 ,0x12 }, - {0x360a ,0x40 }, {0x360c ,0x08 }, {0x360f ,0xe5 }, - {0x3608 ,0x8f }, {0x3611 ,0x00 }, {0x3613 ,0xf7 }, - {0x3616 ,0x58 }, {0x3619 ,0x99 }, {0x361b ,0x60 }, - {0x361c ,0x7a }, {0x361e ,0x79 }, {0x361f ,0x02 }, - {0x3632 ,0x00 }, {0x3633 ,0x10 }, {0x3634 ,0x10 }, - {0x3635 ,0x10 }, {0x3636 ,0x15 }, {0x3646 ,0x86 }, - {0x364a ,0x0b }, {0x3700 ,0x17 }, {0x3701 ,0x22 }, - {0x3703 ,0x10 }, {0x370a ,0x37 }, {0x3705 ,0x00 }, - {0x3706 ,0x63 }, {0x3709 ,0x3c }, {0x370b ,0x01 }, - {0x370c ,0x30 }, {0x3710 ,0x24 }, {0x3711 ,0x0c }, - {0x3716 ,0x00 }, {0x3720 ,0x28 }, {0x3729 ,0x7b }, - {0x372a ,0x84 }, {0x372b ,0xbd }, {0x372c ,0xbc }, - {0x372e ,0x52 }, {0x373c ,0x0e }, {0x373e ,0x33 }, - {0x3743 ,0x10 }, {0x3744 ,0x88 }, {0x3745 ,0xc0 }, - {0x374a ,0x43 }, {0x374c ,0x00 }, {0x374e ,0x23 }, - {0x3751 ,0x7b }, {0x3752 ,0x84 }, {0x3753 ,0xbd }, - {0x3754 ,0xbc }, {0x3756 ,0x52 }, {0x375c ,0x00 }, - {0x3760 ,0x00 }, {0x3761 ,0x00 }, {0x3762 ,0x00 }, - {0x3763 ,0x00 }, {0x3764 ,0x00 }, {0x3767 ,0x04 }, - {0x3768 ,0x04 }, {0x3769 ,0x08 }, {0x376a ,0x08 }, - {0x376b ,0x20 }, {0x376c ,0x00 }, {0x376d ,0x00 }, - {0x376e ,0x00 }, {0x3773 ,0x00 }, {0x3774 ,0x51 }, - {0x3776 ,0xbd }, {0x3777 ,0xbd }, {0x3781 ,0x18 }, - {0x3783 ,0x25 }, {0x3798 ,0x1b }, {0x3800 ,0x00 }, - {0x3801 ,0x08 }, {0x3802 ,0x00 }, {0x3803 ,0x04 }, - {0x3804 ,0x0a }, {0x3805 ,0x97 }, {0x3806 ,0x05 }, - {0x3807 ,0xfb }, {0x3808 ,0x0a }, {0x3809 ,0x80 }, - {0x380a ,0x05 }, {0x380b ,0xf0 }, {0x380c ,0x0a }, - {0x380d ,0x0e }, {0x380e ,0x06 }, {0x380f ,0x12 }, - {0x3810 ,0x00 }, {0x3811 ,0x08 }, {0x3812 ,0x00 }, - {0x3813 ,0x04 }, {0x3814 ,0x01 }, {0x3815 ,0x01 }, - {0x3819 ,0x01 }, {0x3820 ,0x00 }, {0x3821 ,0x06 }, - {0x3829 ,0x00 }, {0x382a ,0x01 }, {0x382b ,0x01 }, - {0x382d ,0x7f }, {0x3830 ,0x04 }, {0x3836 ,0x01 }, - {0x3837 ,0x00 }, {0x3841 ,0x02 }, {0x3846 ,0x08 }, - {0x3847 ,0x07 }, {0x3d85 ,0x36 }, {0x3d8c ,0x71 }, - {0x3d8d ,0xcb }, {0x3f0a ,0x00 }, {0x4000 ,0xf1 }, - {0x4001 ,0x40 }, {0x4002 ,0x04 }, {0x4003 ,0x14 }, - {0x400e ,0x00 }, {0x4011 ,0x00 }, {0x401a ,0x00 }, - {0x401b ,0x00 }, {0x401c ,0x00 }, {0x401d ,0x00 }, - {0x401f ,0x00 }, {0x4020 ,0x00 }, {0x4021 ,0x10 }, - {0x4022 ,0x07 }, {0x4023 ,0xcf }, {0x4024 ,0x09 }, - {0x4025 ,0x60 }, {0x4026 ,0x09 }, {0x4027 ,0x6f }, - {0x4028 ,0x00 }, {0x4029 ,0x02 }, {0x402a ,0x06 }, - {0x402b ,0x04 }, {0x402c ,0x02 }, {0x402d ,0x02 }, - {0x402e ,0x0e }, {0x402f ,0x04 }, {0x4302 ,0xff }, - {0x4303 ,0xff }, {0x4304 ,0x00 }, {0x4305 ,0x00 }, - {0x4306 ,0x00 }, {0x4308 ,0x02 }, {0x4500 ,0x6c }, - {0x4501 ,0xc4 }, {0x4502 ,0x40 }, {0x4503 ,0x01 }, - {0x4601 ,0xa7 }, {0x4800 ,0x04 }, {0x4813 ,0x08 }, - {0x481f ,0x40 }, {0x4829 ,0x78 }, {0x4837 ,0x10 }, - {0x4b00 ,0x2a }, {0x4b0d ,0x00 }, {0x4d00 ,0x04 }, - {0x4d01 ,0x42 }, {0x4d02 ,0xd1 }, {0x4d03 ,0x93 }, - {0x4d04 ,0xf5 }, {0x4d05 ,0xc1 }, {0x5000 ,0xf3 }, - {0x5001 ,0x11 }, {0x5004 ,0x00 }, {0x500a ,0x00 }, - {0x500b ,0x00 }, {0x5032 ,0x00 }, {0x5040 ,0x00 }, - {0x5050 ,0x0c }, {0x5500 ,0x00 }, {0x5501 ,0x10 }, - {0x5502 ,0x01 }, {0x5503 ,0x0f }, {0x8000 ,0x00 }, - {0x8001 ,0x00 }, {0x8002 ,0x00 }, {0x8003 ,0x00 }, - {0x8004 ,0x00 }, {0x8005 ,0x00 }, {0x8006 ,0x00 }, - {0x8007 ,0x00 }, {0x8008 ,0x00 }, {0x3638 ,0x00 }, +/* System control*/ + {0x0103 ,0x01 },/* SC_CTRL0103 software_reset = 1 */ + {0x3000 ,0x20 },/* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ + {0x3021 ,0x03 },/* +* SC_CMMN_MISC_CTRL fst_stby_ctr = 0, +* sleep_no_latch_enable = 0 +*/ + +/* AEC PK */ + {0x3503 ,0x04 },/* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ + {0x352a ,0x08 },/* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ + +/* ADC and analog control*/ + {0x3603 ,0x40 }, + {0x3604 ,0x02 }, + {0x3609 ,0x12 }, + {0x360c ,0x08 }, + {0x360f ,0xe5 }, + {0x3608 ,0x8f }, + {0x3611 ,0x00 }, + {0x3613 ,0xf7 }, + {0x3616 ,0x58 }, + {0x3619 ,0x99 }, + {0x361b ,0x60 }, + {0x361e ,0x79 }, + {0x3634 ,0x10 }, + {0x3635 ,0x10 }, + {0x3636 ,0x15 }, + {0x3646 ,0x86 }, + {0x364a ,0x0b }, + +/* Sensor control */ + {0x3700 ,0x17 }, + {0x3701 ,0x22 }, + {0x3703 ,0x10 }, + {0x370a ,0x37 }, + {0x3706 ,0x63 }, + {0x3709 ,0x3c }, + {0x370c ,0x30 }, + {0x3710 ,0x24 }, + {0x3720 ,0x28 }, + {0x3729 ,0x7b }, + {0x372b ,0xbd }, + {0x372c ,0xbc }, + {0x372e ,0x52 }, + {0x373c ,0x0e }, + {0x373e ,0x33 }, + {0x3743 ,0x10 }, + {0x3744 ,0x88 }, + {0x3745 ,0xc0 }, + {0x374c ,0x00 }, + {0x374e ,0x23 }, + {0x3751 ,0x7b }, + {0x3753 ,0xbd }, + {0x3754 ,0xbc }, + {0x3756 ,0x52 }, + {0x376b ,0x20 }, + {0x3774 ,0x51 }, + {0x3776 ,0xbd }, + {0x3777 ,0xbd }, + {0x3781 ,0x18 }, + {0x3783 ,0x25 }, + {0x3798 ,0x1b }, + +/* Timing control */ + {0x3801 ,0x08 },/* H_CROP_START_L h_crop_start[7:0] = 0x08 */ + {0x3805 ,0x97 },/* H_CROP_END_L h_crop_end[7:0] = 0x97 */ + {0x380c ,0x0a },/* TIMING_HTS_H hts[14:8] = 0x0a */ + {0x380d ,0x0e },/* TIMING_HTS_L hts[7:0] = 0x0e */ + {0x3811 ,0x08 },/* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ + {0x3813 ,0x04 },/* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ + {0x3819 ,0x01 },/* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ + {0x3821 ,0x06 },/* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ + +/* OTP control */ + {0x3d85 ,0x36 },/* OTP_REG85 OTP_power_up_load_setting_enable = 1, +* OTP_power_up_load_data_enable = 1, +* OTP_bist_select = 1 (compare with zero) +*/ + {0x3d8c ,0x71 },/* OTP_SETTING_STT_ADDRESS_H */ + {0x3d8d ,0xcb },/* OTP_SETTING_STT_ADDRESS_L */ + +/* BLC registers*/ + {0x4001 ,0x40 },/* DEBUG_MODE */ + {0x401b ,0x00 },/* DEBUG_MODE */ + {0x401d ,0x00 },/* DEBUG_MODE */ + {0x401f ,0x00 },/* DEBUG_MODE */ + {0x4020 ,0x00 },/* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ + {0x4021 ,0x10 },/* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ + {0x4022 ,0x07 },/* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ + {0x4023 ,0xcf },/* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ + {0x4024 ,0x09 },/* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ + {0x4025 ,0x60 },/* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ + {0x4026 ,0x09 },/* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ + {0x4027 ,0x6f },/* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ + +/* ADC sync control */ + {0x4500 ,0x6c },/* ADC_SYNC_CTRL */ + {0x4503 ,0x01 },/* ADC_SYNC_CTRL */ + +/* VFIFO */ + {0x4601 ,0xa7 },/* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ + +/* Temperature monitor */ + {0x4d00 ,0x04 },/* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ + {0x4d01 ,0x42 },/* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ + {0x4d02 ,0xd1 },/* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ + {0x4d03 ,0x93 },/* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ + {0x4d04 ,0xf5 },/* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ + {0x4d05 ,0xc1 },/* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ + +/* pre-ISP control */ + {0x5050 ,0x0c },/* DEBUG_MODE */ + +/* OTP-DPC control */ + {0x5501 ,0x10 },/* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ + {0x5503 ,0x0f },/* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ {REG_NULL ,0x00 }, };
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 2/20 media: i2c: ov4689: Sort register definitions by address
In reply to Mikhail RudenkoPut register defininitions in the order of increasing register address.
--- drivers/media/i2c/ov4689.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/i2c/ov4689.c +5 -5
@@ -19,15 +19,15 @@#include <media/v4l2-subdev.h> #include <media/v4l2-fwnode.h> -#define CHIP_ID 0x004688 -#define OV4689_REG_CHIP_ID 0x300a -#define OV4689_XVCLK_FREQ 24000000#define OV4689_REG_CTRL_MODE 0x0100#define OV4689_MODE_SW_STANDBY 0x0#define OV4689_MODE_STREAMING BIT(0) +#define OV4689_REG_CHIP_ID 0x300a +#define CHIP_ID 0x004688 +#define OV4689_REG_EXPOSURE 0x3500#define OV4689_EXPOSURE_MIN 4#define OV4689_EXPOSURE_STEP 1
@@ -41,12 +41,12 @@#define OV4689_GAIN_STEP 1#define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_VTS 0x380e +#define OV4689_REG_TEST_PATTERN 0x5040#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0 -#define OV4689_REG_VTS 0x380e -#define REG_NULL 0xFFFF#define OV4689_REG_VALUE_08BIT 1
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 3/20 media: i2c: ov4689: Fix typo in a comment
In reply to Mikhail RudenkoFix a spelling error in a comment.
--- drivers/media/i2c/ov4689.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov4689.c +1 -1
@@ -692,7 +692,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_EXPOSURE : -/* 4 least significant bits of expsoure are fractional part */ +/* 4 least significant bits of exposure are fractional part */ ret =ov4689_write_reg (ov4689->client,OV4689_REG_EXPOSURE ,OV4689_REG_VALUE_24BIT , ctrl->val <<4 );break ;
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 4/20 media: i2c: ov4689: CCI conversion
In reply to Mikhail RudenkoConvert the i2c register accesses to utilize the CCI helper library rather than relying on driver-specific functions. Also, set analogue gain in a single 16-bit write instead of two 8-bit writes.
--- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov4689.c | 358 ++++++++++++++----------------------- 2 files changed, 133 insertions(+), 226 deletions(-)
drivers/media/i2c/Kconfig +1 -0
@@ -404,6 +404,7 @@ config VIDEO_OV2740 config VIDEO_OV4689 tristate "OmniVision OV4689 sensor support" depends on GPIOLIB + select V4L2_CCI_I2C help This is a Video4Linux2 sensor-level driver for the OmniVision OV4689 camera.
drivers/media/i2c/ov4689.c +132 -226
496 lines not on this page · raw message
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 5/20 media: i2c: ov4689: Remove i2c_client from ov4689 struct
In reply to Mikhail RudenkoThe 'client' field within the 'ov4689' structure is solely used to access its 'dev' member. This commit removes the 'client' field and directly stores a pointer to the 'struct device'.
--- drivers/media/i2c/ov4689.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/media/i2c/ov4689.c +18 -18
@@ -74,7 +74,7 @@ struct ov4689_mode { };struct ov4689 { -struct i2c_client *client; +struct device *dev;struct regmap *regmap;struct clk *xvclk;struct gpio_desc *reset_gpio;
@@ -405,13 +405,13 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd); -struct i2c_client *client = ov4689->client; +struct device *dev = ov4689->dev;int ret =0 ;mutex_lock (&ov4689->mutex);if (on) { - ret =pm_runtime_resume_and_get (&client->dev); + ret =pm_runtime_resume_and_get (dev);if (ret <0 ) goto unlock_and_return;
@@ -420,26 +420,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (&client->dev); +pm_runtime_put (dev); goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (&client->dev); +pm_runtime_put (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (&client->dev); +pm_runtime_put (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (&client->dev); +pm_runtime_put (dev); } unlock_and_return:
@@ -553,7 +553,6 @@ static const struct v4l2_subdev_ops ov4689_subdev_ops = {*/ static int ov4689_map_gain (struct ov4689 *ov4689,int logical_gain,int *result) { -const struct device *dev = &ov4689->client->dev;const struct ov4689_gain_range *range;unsigned int n;
@@ -564,7 +563,8 @@ static int ov4689_map_gain(struct ov4689 *ov4689, int logical_gain, int *result) }if (n ==ARRAY_SIZE (ov4689_gain_ranges)) { -dev_warn_ratelimited (dev,"no mapping found for gain %d\n" , +dev_warn_ratelimited (ov4689->dev, +"no mapping found for gain %d\n" , logical_gain);return -EINVAL ; }
@@ -580,7 +580,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) {struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); -struct i2c_client *client = ov4689->client; +struct device *dev = ov4689->dev;int sensor_gain;s64 max_expo;int ret;
@@ -597,7 +597,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; } -if (!pm_runtime_get_if_in_use (&client->dev)) +if (!pm_runtime_get_if_in_use (dev))return 0 ;switch (ctrl->id) {
@@ -618,13 +618,13 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) ret =ov4689_enable_test_pattern (ov4689, ctrl->val);break ;default : -dev_warn (&client->dev,"%s Unhandled id:0x%x, val:0x%x\n" , +dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val); ret = -EINVAL ;break ; } -pm_runtime_put (&client->dev); +pm_runtime_put (dev);return ret; }
@@ -689,8 +689,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)if (handler->error) { ret = handler->error; -dev_err (&ov4689->client->dev,"Failed to init controls(%d)\n" , - ret); +dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret); goto err_free_handler; }
@@ -716,7 +715,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)static int ov4689_check_sensor_id (struct ov4689 *ov4689,struct i2c_client *client) { -struct device *dev = &ov4689->client->dev; +struct device *dev = ov4689->dev;u64 id =0 ;int ret;
@@ -744,7 +743,7 @@ static int ov4689_configure_regulators(struct ov4689 *ov4689)for (i =0 ; i <ARRAY_SIZE (ov4689_supply_names); i++) ov4689->supplies[i].supply = ov4689_supply_names[i]; -return devm_regulator_bulk_get (&ov4689->client->dev, +return devm_regulator_bulk_get (ov4689->dev,ARRAY_SIZE (ov4689_supply_names), ov4689->supplies); }
@@ -813,7 +812,8 @@ static int ov4689_probe(struct i2c_client *client)if (!ov4689)return -ENOMEM ; - ov4689->client = client; + ov4689->dev = dev; + ov4689->cur_mode = &supported_modes[OV4689_MODE_2688_1520 ]; ov4689->xvclk =devm_clk_get_optional (dev,NULL );
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 6/20 media: i2c: ov4689: Refactor ov4689_set_ctrl
In reply to Mikhail RudenkoIntroduce local variable for regmap within the ov4689_set_ctrl function. This adjustment eliminates repetition within the function.
--- drivers/media/i2c/ov4689.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/media/i2c/ov4689.c +5 -6
@@ -580,6 +580,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) {struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); +struct regmap *regmap = ov4689->regmap;struct device *dev = ov4689->dev;int sensor_gain;s64 max_expo;
@@ -603,16 +604,15 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_EXPOSURE :/* 4 least significant bits of exposure are fractional part */ - ret =cci_write (ov4689->regmap,OV4689_REG_EXPOSURE , - ctrl->val <<4 ,NULL ); +cci_write (regmap,OV4689_REG_EXPOSURE , ctrl->val <<4 , &ret);break ;case V4L2_CID_ANALOGUE_GAIN : ret =ov4689_map_gain (ov4689, ctrl->val, &sensor_gain); -cci_write (ov4689->regmap,OV4689_REG_GAIN , sensor_gain, &ret); +cci_write (regmap,OV4689_REG_GAIN , sensor_gain, &ret);break ;case V4L2_CID_VBLANK : - ret =cci_write (ov4689->regmap,OV4689_REG_VTS , - ctrl->val + ov4689->cur_mode->height,NULL ); +cci_write (regmap,OV4689_REG_VTS , + ctrl->val + ov4689->cur_mode->height, &ret);break ;case V4L2_CID_TEST_PATTERN : ret =ov4689_enable_test_pattern (ov4689, ctrl->val);
@@ -625,7 +625,6 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) }pm_runtime_put (dev); -return ret; }
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 7/20 media: i2c: ov4689: Use sub-device active state
In reply to Mikhail RudenkoUse sub-device active state. Employ control handler lock to synchronize access to the active state and s_stream.
--- drivers/media/i2c/ov4689.c | 75 ++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 43 deletions(-)
drivers/media/i2c/ov4689.c +32 -43
@@ -86,7 +86,6 @@ struct ov4689 {u32 clock_rate; -struct mutex mutex;/* lock to protect ctrls and cur_mode */ struct v4l2_ctrl_handler ctrl_handler;struct v4l2_ctrl *exposure;
@@ -319,19 +318,6 @@ static int ov4689_set_fmt(struct v4l2_subdev *sd,return 0 ; } -static int ov4689_get_fmt (struct v4l2_subdev *sd, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) -{ -struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; -struct ov4689 *ov4689 =to_ov4689 (sd); - -/* only one mode supported for now */ -ov4689_fill_fmt (ov4689->cur_mode, mbus_fmt); - -return 0 ; -} -static int ov4689_enum_mbus_code (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)
@@ -405,10 +391,11 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd); +struct v4l2_subdev_state *sd_state;struct device *dev = ov4689->dev;int ret =0 ; -mutex_lock (&ov4689->mutex); + sd_state =v4l2_subdev_lock_and_get_active_state (&ov4689->subdev);if (on) { ret =pm_runtime_resume_and_get (dev);
@@ -443,7 +430,7 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) } unlock_and_return: -mutex_unlock (&ov4689->mutex); +v4l2_subdev_unlock_state (sd_state);return ret; }
@@ -506,18 +493,13 @@ static int __maybe_unused ov4689_power_off(struct device *dev)return 0 ; } -static int ov4689_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +static int ov4689_init_state (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state) { -struct ov4689 *ov4689 =to_ov4689 (sd); -struct v4l2_mbus_framefmt *try_fmt; - -mutex_lock (&ov4689->mutex); - - try_fmt =v4l2_subdev_state_get_format (fh->state,0 ); -/* Initialize try_fmt */ -ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], try_fmt); +struct v4l2_mbus_framefmt *fmt = +v4l2_subdev_state_get_format (sd_state,0 ); -mutex_unlock (&ov4689->mutex); +ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], fmt);return 0 ; }
@@ -526,10 +508,6 @@ static const struct dev_pm_ops ov4689_pm_ops = { SET_RUNTIME_PM_OPS(ov4689_power_off, ov4689_power_on, NULL) }; -static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { - .open = ov4689_open, -}; -static const struct v4l2_subdev_video_ops ov4689_video_ops = { .s_stream = ov4689_s_stream, };
@@ -537,11 +515,15 @@ static const struct v4l2_subdev_video_ops ov4689_video_ops = {static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { .enum_mbus_code = ov4689_enum_mbus_code, .enum_frame_size = ov4689_enum_frame_sizes, - .get_fmt = ov4689_get_fmt, + .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov4689_set_fmt, .get_selection = ov4689_get_selection, }; +static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { + .init_state = ov4689_init_state, +}; +static const struct v4l2_subdev_ops ov4689_subdev_ops = { .video = &ov4689_video_ops, .pad = &ov4689_pad_ops,
@@ -648,7 +630,6 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ret =v4l2_ctrl_handler_init (handler,10 );if (ret)return ret; - handler->lock = &ov4689->mutex; ctrl =v4l2_ctrl_new_int_menu (handler,NULL ,V4L2_CID_LINK_FREQ ,0 ,0 , link_freq_menu_items);
@@ -861,13 +842,15 @@ static int ov4689_probe(struct i2c_client *client)return dev_err_probe (dev, ret,"Failed to get power regulators\n" ); -mutex_init (&ov4689->mutex); - sd = &ov4689->subdev;v4l2_i2c_subdev_init (sd, client, &ov4689_subdev_ops); + sd->internal_ops = &ov4689_internal_ops; + ret =ov4689_initialize_controls (ov4689); -if (ret) - goto err_destroy_mutex; +if (ret) { +dev_err (dev,"Failed to initialize controls\n" ); +return ret; + } ret =ov4689_power_on (dev);if (ret)
@@ -877,19 +860,26 @@ static int ov4689_probe(struct i2c_client *client)if (ret) goto err_power_off; - sd->internal_ops = &ov4689_internal_ops; sd->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ov4689->pad.flags =MEDIA_PAD_FL_SOURCE ; - sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ret =media_entity_pads_init (&sd->entity,1 , &ov4689->pad);if (ret <0 ) goto err_power_off; + sd->state_lock = ov4689->ctrl_handler.lock; + ret =v4l2_subdev_init_finalize (sd); + +if (ret) { +dev_err (dev,"Could not register v4l2 device\n" ); + goto err_clean_entity; + } + ret =v4l2_async_register_subdev_sensor (sd);if (ret) {dev_err (dev,"v4l2 async register subdev failed\n" ); - goto err_clean_entity; + goto err_clean_subdev; }pm_runtime_set_active (dev);
@@ -898,14 +888,14 @@ static int ov4689_probe(struct i2c_client *client)return 0 ; +err_clean_subdev: +v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity); err_power_off:ov4689_power_off (dev); err_free_handler:v4l2_ctrl_handler_free (&ov4689->ctrl_handler); -err_destroy_mutex: -mutex_destroy (&ov4689->mutex);return ret; }
@@ -917,9 +907,8 @@ static void ov4689_remove(struct i2c_client *client)v4l2_async_unregister_subdev (sd);media_entity_cleanup (&sd->entity); - +v4l2_subdev_cleanup (sd);v4l2_ctrl_handler_free (&ov4689->ctrl_handler); -mutex_destroy (&ov4689->mutex);pm_runtime_disable (&client->dev);if (!pm_runtime_status_suspended (&client->dev))
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 8/20 media: i2c: ov4689: Enable runtime PM before registering sub-device
In reply to Mikhail RudenkoAs the sensor may be accessible right after its async sub-device is registered, enable runtime PM before doing so.
--- drivers/media/i2c/ov4689.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/media/i2c/ov4689.c +8 -6
@@ -876,19 +876,21 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_entity; } +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_idle (dev); + ret =v4l2_async_register_subdev_sensor (sd);if (ret) {dev_err (dev,"v4l2 async register subdev failed\n" ); - goto err_clean_subdev; + goto err_clean_subdev_pm; } -pm_runtime_set_active (dev); -pm_runtime_enable (dev); -pm_runtime_idle (dev); -return 0 ; -err_clean_subdev: +err_clean_subdev_pm: +pm_runtime_disable (dev); +pm_runtime_set_suspended (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 9/20 media: i2c: ov4689: Use runtime PM autosuspend
In reply to Mikhail RudenkoUse runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/media/i2c/ov4689.c +15 -7
@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:
@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; } -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return ret; }
@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {
@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 10/20 media: i2c: ov4689: Remove max_fps field from struct ov4689_mode
In reply to Mikhail Rudenkomax_fps field of struct ov4689_mode is unused in this driver, so remove it.
--- drivers/media/i2c/ov4689.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/i2c/ov4689.c +0 -2
@@ -60,7 +60,6 @@ struct ov4689_mode {enum ov4689_mode_id id;u32 width;u32 height; -u32 max_fps;u32 hts_def;u32 vts_def;u32 exp_def;
@@ -237,7 +236,6 @@ static const struct ov4689_mode supported_modes[] = { .sensor_height = 1536, .crop_top = 8, .crop_left = 16, - .max_fps = 30, .exp_def = 1536, .hts_def = 4 * 2574, .vts_def = 1554,
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 11/20 media: i2c: ov4689: Make horizontal blanking configurable
In reply to Mikhail RudenkoMake horizontal blanking configurable. To do so, set HTS register according to the requested horizontal blanking in ov4689_set_ctrl instead of the register table. Default HTS value is not changed by this patch. Minimal HTS value is found experimentally and corresponds to 90 fps framerate at minimum vertical blanking. Real HTS value is the register value multiplied by 4.
--- drivers/media/i2c/ov4689.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/media/i2c/ov4689.c +20 -11
@@ -30,13 +30,17 @@#define OV4689_REG_EXPOSURE CCI_REG24(0x3500)#define OV4689_EXPOSURE_MIN 4#define OV4689_EXPOSURE_STEP 1 -#define OV4689_VTS_MAX 0x7fff#define OV4689_REG_GAIN CCI_REG16(0x3508)#define OV4689_GAIN_STEP 1#define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_HTS CCI_REG16(0x380c) +#define OV4689_HTS_DIVIDER 4 +#define OV4689_HTS_MAX 0x7fff +#define OV4689_REG_VTS CCI_REG16(0x380e) +#define OV4689_VTS_MAX 0x7fff#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80
@@ -61,6 +65,7 @@ struct ov4689_mode {u32 width;u32 height;u32 hts_def; +u32 hts_min;u32 vts_def;u32 exp_def;u32 pixel_rate;
@@ -104,7 +109,7 @@ struct ov4689_gain_range {/* * Xclk 24Mhz -* max_framerate 30fps +* max_framerate 90fps * mipi_datarate per lane 1008Mbps */ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = {
@@ -175,8 +180,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = {/* Timing control */ {CCI_REG8(0x3801), 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ {CCI_REG8(0x3805), 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ - {CCI_REG8(0x380c), 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ - {CCI_REG8(0x380d), 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */
@@ -237,7 +240,8 @@ static const struct ov4689_mode supported_modes[] = { .crop_top = 8, .crop_left = 16, .exp_def = 1536, - .hts_def = 4 * 2574, + .hts_def = 10296, + .hts_min = 3432, .vts_def = 1554, .pixel_rate = 480000000, .reg_list = ov4689_2688x1520_regs,
@@ -598,6 +602,11 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)case V4L2_CID_TEST_PATTERN : ret =ov4689_enable_test_pattern (ov4689, ctrl->val);break ; +case V4L2_CID_HBLANK : +cci_write (regmap,OV4689_REG_HTS , + (ctrl->val + ov4689->cur_mode->width) / +OV4689_HTS_DIVIDER , &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);
@@ -622,8 +631,8 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)struct v4l2_ctrl_handler *handler;const struct ov4689_mode *mode;s64 exposure_max, vblank_def; +s64 hblank_def, hblank_min;struct v4l2_ctrl *ctrl; -s64 h_blank_def;int ret; handler = &ov4689->ctrl_handler;
@@ -640,11 +649,11 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)v4l2_ctrl_new_std (handler,NULL ,V4L2_CID_PIXEL_RATE ,0 , mode->pixel_rate,1 , mode->pixel_rate); - h_blank_def = mode->hts_def - mode->width; - ctrl =v4l2_ctrl_new_std (handler,NULL ,V4L2_CID_HBLANK , h_blank_def, - h_blank_def,1 , h_blank_def); -if (ctrl) - ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; + hblank_def = mode->hts_def - mode->width; + hblank_min = mode->hts_min - mode->width; +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HBLANK , + hblank_min,OV4689_HTS_MAX - mode->width, +OV4689_HTS_DIVIDER , hblank_def); vblank_def = mode->vts_def - mode->height; v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_VBLANK,
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 12/20 media: i2c: ov4689: Implement vflip/hflip controls
In reply to Mikhail RudenkoThe OV4689 sensor supports horizontal and vertical flipping. Add appropriate controls to the driver. Toggling both array flip and digital flip bits allows to achieve flipping while maintaining output Bayer order. Note that the default value of hflip control corresponds to both bits set, as it was before this patch.
--- drivers/media/i2c/ov4689.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
drivers/media/i2c/ov4689.c +22 -2
@@ -42,6 +42,14 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) +#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) +#define OV4689_TIMING_FLIP_ARRAY BIT(1) +#define OV4689_TIMING_FLIP_DIGITAL BIT(2) +#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ + OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0
@@ -183,7 +191,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ - {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 *//* OTP control */ {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1,
@@ -607,6 +614,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) (ctrl->val + ov4689->cur_mode->width) / OV4689_HTS_DIVIDER, &ret);break ; +case V4L2_CID_VFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT1 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?OV4689_TIMING_FLIP_BOTH :0 , &ret); +break ; +case V4L2_CID_HFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT2 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?0 :OV4689_TIMING_FLIP_BOTH , &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);
@@ -637,7 +654,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,10 ); + ret =v4l2_ctrl_handler_init (handler,12 );if (ret)return ret;
@@ -677,6 +694,9 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)ARRAY_SIZE (ov4689_test_pattern_menu) -1 , 0, 0, ov4689_test_pattern_menu); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); +if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 13/20 media: i2c: ov4689: Implement digital gain control
In reply to Mikhail RudenkoThe OV4689 sensor supports digital gain up to 16x. Implement corresponding control in the driver. Default digital gain value is not modified by this patch.
--- drivers/media/i2c/ov4689.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/media/i2c/ov4689.c +14 -2
@@ -35,6 +35,12 @@#define OV4689_GAIN_STEP 1#define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_DIG_GAIN CCI_REG16(0x352a) +#define OV4689_DIG_GAIN_MIN 1 +#define OV4689_DIG_GAIN_MAX 0x7fff +#define OV4689_DIG_GAIN_STEP 1 +#define OV4689_DIG_GAIN_DEFAULT 0x800 +#define OV4689_REG_HTS CCI_REG16(0x380c)#define OV4689_HTS_DIVIDER 4#define OV4689_HTS_MAX 0x7fff
@@ -131,7 +137,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = {/* AEC PK */ {CCI_REG8(0x3503), 0x04}, /* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ - {CCI_REG8(0x352a), 0x08}, /* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) *//* ADC and analog control*/ {CCI_REG8(0x3603), 0x40},
@@ -624,6 +629,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)OV4689_TIMING_FLIP_MASK , ctrl->val ? 0 : OV4689_TIMING_FLIP_BOTH, &ret);break ; +case V4L2_CID_DIGITAL_GAIN : +cci_write (regmap,OV4689_REG_DIG_GAIN , ctrl->val, &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);
@@ -654,7 +662,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,12 ); + ret =v4l2_ctrl_handler_init (handler,13 );if (ret)return ret;
@@ -697,6 +705,10 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 );v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +OV4689_DIG_GAIN_MIN ,OV4689_DIG_GAIN_MAX , +OV4689_DIG_GAIN_STEP ,OV4689_DIG_GAIN_DEFAULT ); +if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 14/20 media: i2c: ov4689: Implement manual color balance controls
In reply to Mikhail RudenkoThe OV4689 sensor has separate red and blue gain settings (up to 4x). Implement appropriate controls in the driver. Default gain values are not modified.
--- drivers/media/i2c/ov4689.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/media/i2c/ov4689.c +22 -1
@@ -56,6 +56,13 @@#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_WB_GAIN_RED CCI_REG16(0x500c) +#define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010) +#define OV4689_WB_GAIN_MIN 1 +#define OV4689_WB_GAIN_MAX 0xfff +#define OV4689_WB_GAIN_STEP 1 +#define OV4689_WB_GAIN_DEFAULT 0x400 +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0
@@ -632,6 +639,12 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)case V4L2_CID_DIGITAL_GAIN :cci_write (regmap,OV4689_REG_DIG_GAIN , ctrl->val, &ret);break ; +case V4L2_CID_RED_BALANCE : +cci_write (regmap,OV4689_REG_WB_GAIN_RED , ctrl->val, &ret); +break ; +case V4L2_CID_BLUE_BALANCE : +cci_write (regmap,OV4689_REG_WB_GAIN_BLUE , ctrl->val, &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);
@@ -662,7 +675,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,13 ); + ret =v4l2_ctrl_handler_init (handler,15 );if (ret)return ret;
@@ -709,6 +722,14 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)OV4689_DIG_GAIN_MIN ,OV4689_DIG_GAIN_MAX , OV4689_DIG_GAIN_STEP, OV4689_DIG_GAIN_DEFAULT); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_RED_BALANCE , +OV4689_WB_GAIN_MIN ,OV4689_WB_GAIN_MAX , +OV4689_WB_GAIN_STEP ,OV4689_WB_GAIN_DEFAULT ); + +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_BLUE_BALANCE , +OV4689_WB_GAIN_MIN ,OV4689_WB_GAIN_MAX , +OV4689_WB_GAIN_STEP ,OV4689_WB_GAIN_DEFAULT ); +if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 15/20 media: i2c: ov4689: Move pixel array size out of struct ov4689_mode
In reply to Mikhail RudenkoPixel array dimensions and default crop size do not belong to the ov4689_mode structure, since they are mode independent. Make them defines instead.
--- drivers/media/i2c/ov4689.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)
drivers/media/i2c/ov4689.c +13 -16
@@ -70,6 +70,11 @@#define OV4689_LANES 4#define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_ARRAY_WIDTH 2720 +#define OV4689_PIXEL_ARRAY_HEIGHT 1536 +#define OV4689_DUMMY_ROWS 8 +#define OV4689_DUMMY_COLUMNS 16 +static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */ "dovdd" ,/* Digital I/O power */
@@ -90,10 +95,6 @@ struct ov4689_mode {u32 vts_def;u32 exp_def;u32 pixel_rate; -u32 sensor_width; -u32 sensor_height; -u32 crop_top; -u32 crop_left;const struct cci_reg_sequence *reg_list;unsigned int num_regs; };
@@ -254,10 +255,6 @@ static const struct ov4689_mode supported_modes[] = { .id = OV4689_MODE_2688_1520, .width = 2688, .height = 1520, - .sensor_width = 2720, - .sensor_height = 1536, - .crop_top = 8, - .crop_left = 16, .exp_def = 1536, .hts_def = 10296, .hts_min = 3432,
@@ -385,8 +382,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; -if (sel->which !=V4L2_SUBDEV_FORMAT_ACTIVE )return -EINVAL ;
@@ -394,15 +389,17 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,case V4L2_SEL_TGT_CROP_BOUNDS : sel->r.top =0 ; sel->r.left =0 ; - sel->r.width = mode->sensor_width; - sel->r.height = mode->sensor_height; + sel->r.width =OV4689_PIXEL_ARRAY_WIDTH ; + sel->r.height =OV4689_PIXEL_ARRAY_HEIGHT ;return 0 ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_CROP_DEFAULT : - sel->r.top = mode->crop_top; - sel->r.left = mode->crop_left; - sel->r.width = mode->width; - sel->r.height = mode->height; + sel->r.top =OV4689_DUMMY_ROWS ; + sel->r.left =OV4689_DUMMY_COLUMNS ; + sel->r.width = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_COLUMNS ; + sel->r.height = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_ROWS ;return 0 ; }
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 16/20 media: i2c: ov4689: Set timing registers programmatically
In reply to Mikhail RudenkoSet timing-related and BLC anchor registers via cci calls instead of hardcoding them in the register table. This prepares the driver for implementation of configurable analogue crop and binning. No functional change intended.
--- drivers/media/i2c/ov4689.c | 83 +++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 15 deletions(-)
drivers/media/i2c/ov4689.c +68 -15
@@ -41,6 +41,13 @@#define OV4689_DIG_GAIN_STEP 1#define OV4689_DIG_GAIN_DEFAULT 0x800 +#define OV4689_REG_H_CROP_START CCI_REG16(0x3800) +#define OV4689_REG_V_CROP_START CCI_REG16(0x3802) +#define OV4689_REG_H_CROP_END CCI_REG16(0x3804) +#define OV4689_REG_V_CROP_END CCI_REG16(0x3806) +#define OV4689_REG_H_OUTPUT_SIZE CCI_REG16(0x3808) +#define OV4689_REG_V_OUTPUT_SIZE CCI_REG16(0x380a) +#define OV4689_REG_HTS CCI_REG16(0x380c)#define OV4689_HTS_DIVIDER 4#define OV4689_HTS_MAX 0x7fff
@@ -48,6 +55,9 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810) +#define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820)#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821)#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1)
@@ -56,6 +66,17 @@#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_ANCHOR_LEFT_START CCI_REG16(0x4020) +#define OV4689_ANCHOR_LEFT_START_DEF 576 +#define OV4689_REG_ANCHOR_LEFT_END CCI_REG16(0x4022) +#define OV4689_ANCHOR_LEFT_END_DEF 831 +#define OV4689_REG_ANCHOR_RIGHT_START CCI_REG16(0x4024) +#define OV4689_ANCHOR_RIGHT_START_DEF 1984 +#define OV4689_REG_ANCHOR_RIGHT_END CCI_REG16(0x4026) +#define OV4689_ANCHOR_RIGHT_END_DEF 2239 + +#define OV4689_REG_VFIFO_CTRL_01 CCI_REG8(0x4601) +#define OV4689_REG_WB_GAIN_RED CCI_REG16(0x500c)#define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010)#define OV4689_WB_GAIN_MIN 1
@@ -199,10 +220,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3798), 0x1b},/* Timing control */ - {CCI_REG8(0x3801), 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ - {CCI_REG8(0x3805), 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ - {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ - {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 *//* OTP control */
@@ -218,22 +235,11 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x401b), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401d), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401f), 0x00}, /* DEBUG_MODE */ - {CCI_REG8(0x4020), 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ - {CCI_REG8(0x4021), 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ - {CCI_REG8(0x4022), 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ - {CCI_REG8(0x4023), 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ - {CCI_REG8(0x4024), 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ - {CCI_REG8(0x4025), 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ - {CCI_REG8(0x4026), 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ - {CCI_REG8(0x4027), 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f *//* ADC sync control */ {CCI_REG8(0x4500), 0x6c}, /* ADC_SYNC_CTRL */ {CCI_REG8(0x4503), 0x01}, /* ADC_SYNC_CTRL */ -/* VFIFO */ - {CCI_REG8(0x4601), 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ -/* Temperature monitor */ {CCI_REG8(0x4d00), 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ {CCI_REG8(0x4d01), 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */
@@ -406,6 +412,41 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,return -EINVAL ; } +static int ov4689_setup_timings (struct ov4689 *ov4689) +{ +const struct ov4689_mode *mode = ov4689->cur_mode; +struct regmap *rm = ov4689->regmap; +int ret =0 ; + +cci_write (rm,OV4689_REG_H_CROP_START ,8 , &ret); +cci_write (rm,OV4689_REG_V_CROP_START ,8 , &ret); +cci_write (rm,OV4689_REG_H_CROP_END ,2711 , &ret); +cci_write (rm,OV4689_REG_V_CROP_END ,1531 , &ret); + +cci_write (rm,OV4689_REG_H_OUTPUT_SIZE , mode->width, &ret); +cci_write (rm,OV4689_REG_V_OUTPUT_SIZE , mode->height, &ret); + +cci_write (rm,OV4689_REG_H_WIN_OFF ,8 , &ret); +cci_write (rm,OV4689_REG_V_WIN_OFF ,4 , &ret); + +cci_write (rm,OV4689_REG_VFIFO_CTRL_01 ,167 , &ret); + +return ret; +} + +static int ov4689_setup_blc_anchors (struct ov4689 *ov4689) +{ +struct regmap *rm = ov4689->regmap; +int ret =0 ; + +cci_write (rm,OV4689_REG_ANCHOR_LEFT_START ,16 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_LEFT_END ,1999 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_START ,2400 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_END ,2415 , &ret); + +return ret; +} +static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd);
@@ -429,6 +470,18 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; } + ret =ov4689_setup_timings (ov4689); +if (ret) { +pm_runtime_put (dev); + goto unlock_and_return; + } + + ret =ov4689_setup_blc_anchors (ov4689); +if (ret) { +pm_runtime_put (dev); + goto unlock_and_return; + } + ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) {pm_runtime_put_sync (dev);
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 17/20 media: i2c: ov4689: Configurable analogue crop
In reply to Mikhail RudenkoImplement configurable analogue crop via .set_selectiong call. ov4689_init_cfg is modified to initialize default subdev selection. Offsets are aligned to 2 to preserve Bayer order, selection width is aligned to 4 and height to 2 to meet hardware requirements.
Experimentally discovered values of the cropping-related registers and vfifo_read_start for various output sizes are used. Default BLC anchor positions are used for the default analogue crop, scaling down proportionally for the smaller crop sizes.
When analogue crop is adjusted, several consequential actions take
place: the output format is reset, exposure/vblank/hblank control ranges and default values are adjusted accordingly. Additionally, ov4689_set_ctrl utilizes pad crop instead of cur_mode width and height for HTS and VTS calculation. Also, ov4689_enum_frame_sizes is modified to report crop size as available frame size.
--- drivers/media/i2c/ov4689.c | 276 ++++++++++++++++++++++++++++--------- 1 file changed, 212 insertions(+), 64 deletions(-)
drivers/media/i2c/ov4689.c +212 -64
@@ -45,8 +45,12 @@#define OV4689_REG_V_CROP_START CCI_REG16(0x3802)#define OV4689_REG_H_CROP_END CCI_REG16(0x3804)#define OV4689_REG_V_CROP_END CCI_REG16(0x3806) +#define OV4689_REG_H_OUTPUT_SIZE CCI_REG16(0x3808) +#define OV4689_H_OUTPUT_SIZE_DEFAULT 2688 +#define OV4689_REG_V_OUTPUT_SIZE CCI_REG16(0x380a) +#define OV4689_V_OUTPUT_SIZE_DEFAULT 1520#define OV4689_REG_HTS CCI_REG16(0x380c)#define OV4689_HTS_DIVIDER 4
@@ -96,6 +100,19 @@#define OV4689_DUMMY_ROWS 8#define OV4689_DUMMY_COLUMNS 16 +/* +* These values are not hardware limits, but rather the minimums that +* the driver has been tested to. +*/ +#define OV4689_H_CROP_MIN 128 +#define OV4689_V_CROP_MIN 128 + +/* +* Minimum working vertical blanking value. Found experimentally at +* minimum HTS values. +*/ +#define OV4689_VBLANK_MIN 31 +static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */ "dovdd" ,/* Digital I/O power */
@@ -134,7 +151,7 @@ struct ov4689 {u32 clock_rate;struct v4l2_ctrl_handler ctrl_handler; -struct v4l2_ctrl *exposure; +struct v4l2_ctrl *exposure, *hblank, *vblank;const struct ov4689_mode *cur_mode; };
@@ -320,24 +337,27 @@ static const struct ov4689_gain_range ov4689_gain_ranges[] = { }, }; -static void ov4689_fill_fmt (const struct ov4689_mode *mode, -struct v4l2_mbus_framefmt *fmt) -{ - fmt->code =MEDIA_BUS_FMT_SBGGR10_1X10 ; - fmt->width = mode->width; - fmt->height = mode->height; - fmt->field =V4L2_FIELD_NONE ; -} -static int ov4689_set_fmt (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_format *fmt) { -struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; -struct ov4689 *ov4689 =to_ov4689 (sd); +struct v4l2_mbus_framefmt *format; +struct v4l2_rect *crop; + + crop =v4l2_subdev_state_get_crop (sd_state, fmt->pad); + format =v4l2_subdev_state_get_format (sd_state, fmt->pad); + + format->width = crop->width; + format->height = crop->height; -/* only one mode supported for now */ -ov4689_fill_fmt (ov4689->cur_mode, mbus_fmt); + format->code =MEDIA_BUS_FMT_SBGGR10_1X10 ; + format->field =V4L2_FIELD_NONE ; + format->colorspace =V4L2_COLORSPACE_RAW ; + format->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; + format->quantization =V4L2_QUANTIZATION_FULL_RANGE ; + format->xfer_func =V4L2_XFER_FUNC_NONE ; + + fmt->format = *format;return 0 ; }
@@ -357,16 +377,20 @@ static int ov4689_enum_frame_sizes(struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { -if (fse->index >=ARRAY_SIZE (supported_modes)) + const struct v4l2_rect *crop; + +if (fse->index >=1 )return -EINVAL ;if (fse->code !=MEDIA_BUS_FMT_SBGGR10_1X10 )return -EINVAL ; - fse->min_width = supported_modes[fse->index].width; - fse->max_width = supported_modes[fse->index].width; - fse->max_height = supported_modes[fse->index].height; - fse->min_height = supported_modes[fse->index].height; + crop =v4l2_subdev_state_get_crop (sd_state,0 ); + + fse->min_width = crop->width; + fse->max_width = crop->width; + fse->max_height = crop->height; + fse->min_height = crop->height;return 0 ; }
@@ -388,20 +412,14 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { -if (sel->which !=V4L2_SUBDEV_FORMAT_ACTIVE ) -return -EINVAL ; -switch (sel->target) { -case V4L2_SEL_TGT_CROP_BOUNDS : - sel->r.top =0 ; - sel->r.left =0 ; - sel->r.width =OV4689_PIXEL_ARRAY_WIDTH ; - sel->r.height =OV4689_PIXEL_ARRAY_HEIGHT ; -return 0 ;case V4L2_SEL_TGT_CROP : + sel->r = *v4l2_subdev_state_get_crop (state, sel->pad); +return 0 ; +case V4L2_SEL_TGT_CROP_BOUNDS :case V4L2_SEL_TGT_CROP_DEFAULT : - sel->r.top =OV4689_DUMMY_ROWS ; sel->r.left =OV4689_DUMMY_COLUMNS ; + sel->r.top =OV4689_DUMMY_ROWS ; sel->r.width =OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_COLUMNS ; sel->r.height =
@@ -412,37 +430,141 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,return -EINVAL ; } -static int ov4689_setup_timings (struct ov4689 *ov4689) +/* +* Minimum working HTS value for given output width (found +* experimentally). +*/ +static unsigned int ov4689_hts_min (unsigned int width) +{ + return max_t(unsigned int, 3156, 224 + width * 19 / 16); +} + +static void ov4689_update_ctrl_ranges (struct ov4689 *ov4689, +struct v4l2_rect *crop) +{ +struct v4l2_ctrl *exposure = ov4689->exposure; +struct v4l2_ctrl *vblank = ov4689->vblank; +struct v4l2_ctrl *hblank = ov4689->hblank; +s64 def_val, min_val, max_val; + + min_val =ov4689_hts_min (crop->width) - crop->width; + max_val =OV4689_HTS_MAX - crop->width; + def_val =clamp_t (s64, hblank->default_value, min_val, max_val); +__v4l2_ctrl_modify_range (hblank, min_val, max_val, hblank->step, + def_val); + + min_val =OV4689_VBLANK_MIN ; + max_val =OV4689_HTS_MAX - crop->width; + def_val =clamp_t (s64, vblank->default_value, min_val, max_val); +__v4l2_ctrl_modify_range (vblank, min_val, max_val, vblank->step, + def_val); + + min_val = exposure->minimum; + max_val = crop->height + vblank->val -4 ; + def_val =clamp_t (s64, exposure->default_value, min_val, max_val); +__v4l2_ctrl_modify_range (exposure, min_val, max_val, exposure->step, + def_val); +} + +static int ov4689_set_selection (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state, +struct v4l2_subdev_selection *sel) { -const struct ov4689_mode *mode = ov4689->cur_mode; +struct ov4689 *ov4689 =to_ov4689 (sd); +struct v4l2_mbus_framefmt *format; +struct v4l2_rect *crop; +struct v4l2_rect rect; + +if (sel->target !=V4L2_SEL_TGT_CROP ) +return -EINVAL ; + + rect.left =clamp (ALIGN (sel->r.left,2 ),OV4689_DUMMY_COLUMNS , +OV4689_PIXEL_ARRAY_WIDTH ); + rect.top =clamp (ALIGN (sel->r.top,2 ),OV4689_DUMMY_ROWS , +OV4689_PIXEL_ARRAY_HEIGHT ); + + rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 4), +OV4689_H_CROP_MIN ,OV4689_PIXEL_ARRAY_WIDTH - +2 *OV4689_DUMMY_COLUMNS ); + rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2), +OV4689_V_CROP_MIN ,OV4689_PIXEL_ARRAY_HEIGHT - +2 *OV4689_DUMMY_ROWS ); + + crop =v4l2_subdev_state_get_crop (state, sel->pad); + +if (rect.width != crop->width || rect.height != crop->height) { +/* +* Reset the output image size if the crop rectangle size has +* been modified. +*/ + format =v4l2_subdev_state_get_format (state, sel->pad); + format->width = rect.width; + format->height = rect.height; + +if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) +ov4689_update_ctrl_ranges (ov4689, &rect); + } + + *crop = rect; + sel->r = rect; + +return 0 ; +} + +static int ov4689_setup_timings (struct ov4689 *ov4689, +struct v4l2_subdev_state *state) +{ +const struct v4l2_mbus_framefmt *format;struct regmap *rm = ov4689->regmap; +const struct v4l2_rect *crop;int ret =0 ; -cci_write (rm,OV4689_REG_H_CROP_START ,8 , &ret); -cci_write (rm,OV4689_REG_V_CROP_START ,8 , &ret); -cci_write (rm,OV4689_REG_H_CROP_END ,2711 , &ret); -cci_write (rm,OV4689_REG_V_CROP_END ,1531 , &ret); + format =v4l2_subdev_state_get_format (state,0 ); + crop =v4l2_subdev_state_get_crop (state,0 ); + +cci_write (rm,OV4689_REG_H_CROP_START , crop->left, &ret); +cci_write (rm,OV4689_REG_V_CROP_START , crop->top, &ret); +cci_write (rm,OV4689_REG_H_CROP_END , crop->left + crop->width +1 , &ret); +cci_write (rm,OV4689_REG_V_CROP_END , crop->top + crop->height +1 , &ret); -cci_write (rm,OV4689_REG_H_OUTPUT_SIZE , mode->width, &ret); -cci_write (rm,OV4689_REG_V_OUTPUT_SIZE , mode->height, &ret); +cci_write (rm,OV4689_REG_H_OUTPUT_SIZE , format->width, &ret); +cci_write (rm,OV4689_REG_V_OUTPUT_SIZE , format->height, &ret); -cci_write (rm,OV4689_REG_H_WIN_OFF ,8 , &ret); -cci_write (rm,OV4689_REG_V_WIN_OFF ,4 , &ret); +cci_write (rm,OV4689_REG_H_WIN_OFF ,0 , &ret); +cci_write (rm,OV4689_REG_V_WIN_OFF ,0 , &ret); -cci_write (rm,OV4689_REG_VFIFO_CTRL_01 ,167 , &ret); +/* +* Maximum working value of vfifo_read_start for given output +* width (found experimentally). +*/ +cci_write (rm,OV4689_REG_VFIFO_CTRL_01 , format->width /16 -1 , &ret);return ret; } -static int ov4689_setup_blc_anchors (struct ov4689 *ov4689) +/* +* Setup black level compensation anchors. For the default frame width +* default anchors positions are used. For smaller crop sizes they are +* scaled accordingly. +*/ +static int ov4689_setup_blc_anchors (struct ov4689 *ov4689, +struct v4l2_subdev_state *state) { +unsigned int width_def =OV4689_H_OUTPUT_SIZE_DEFAULT ;struct regmap *rm = ov4689->regmap; +const struct v4l2_rect *crop;int ret =0 ; -cci_write (rm,OV4689_REG_ANCHOR_LEFT_START ,16 , &ret); -cci_write (rm,OV4689_REG_ANCHOR_LEFT_END ,1999 , &ret); -cci_write (rm,OV4689_REG_ANCHOR_RIGHT_START ,2400 , &ret); -cci_write (rm,OV4689_REG_ANCHOR_RIGHT_END ,2415 , &ret); + crop =v4l2_subdev_state_get_crop (state,0 ); + +cci_write (rm,OV4689_REG_ANCHOR_LEFT_START , +OV4689_ANCHOR_LEFT_START_DEF * crop->width / width_def, &ret); +cci_write (rm,OV4689_REG_ANCHOR_LEFT_END , +OV4689_ANCHOR_LEFT_END_DEF * crop->width / width_def, &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_START , +OV4689_ANCHOR_RIGHT_START_DEF * crop->width / width_def, &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_END , +OV4689_ANCHOR_RIGHT_END_DEF * crop->width / width_def, &ret);return ret; }
@@ -470,13 +592,13 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; } - ret =ov4689_setup_timings (ov4689); + ret =ov4689_setup_timings (ov4689, sd_state);if (ret) {pm_runtime_put (dev); goto unlock_and_return; } - ret =ov4689_setup_blc_anchors (ov4689); + ret =ov4689_setup_blc_anchors (ov4689, sd_state);if (ret) {pm_runtime_put (dev); goto unlock_and_return;
@@ -568,10 +690,25 @@ static int __maybe_unused ov4689_power_off(struct device *dev)static int ov4689_init_state (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state) { -struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_state_get_format (sd_state,0 ); +u32 width_def =OV4689_H_OUTPUT_SIZE_DEFAULT ; +u32 height_def =OV4689_V_OUTPUT_SIZE_DEFAULT ; + +struct v4l2_subdev_selection sel = { + .target =V4L2_SEL_TGT_CROP , + .r.left =OV4689_DUMMY_COLUMNS , + .r.top =OV4689_DUMMY_ROWS , + .r.width = width_def, + .r.height = height_def, + }; +struct v4l2_subdev_format format = { + .format = { + .width = width_def, + .height = height_def, + }, + }; -ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], fmt); +ov4689_set_selection (sd, sd_state, &sel); +ov4689_set_fmt (sd, sd_state, &format);return 0 ; }
@@ -590,6 +727,7 @@ static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov4689_set_fmt, .get_selection = ov4689_get_selection, + .set_selection = ov4689_set_selection, };static const struct v4l2_subdev_internal_ops ov4689_internal_ops = {
@@ -635,20 +773,28 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler);struct regmap *regmap = ov4689->regmap; +struct v4l2_subdev_state *sd_state;struct device *dev = ov4689->dev; +struct v4l2_rect *crop; +s64 max_expo, def_expo;int sensor_gain; -s64 max_expo;int ret; + sd_state =v4l2_subdev_get_locked_active_state (&ov4689->subdev); + crop =v4l2_subdev_state_get_crop (sd_state,0 ); +/* Propagate change of current control to all related controls */ switch (ctrl->id) {case V4L2_CID_VBLANK :/* Update max exposure while meeting expected vblanking */ - max_expo = ov4689->cur_mode->height + ctrl->val -4 ; -__v4l2_ctrl_modify_range (ov4689->exposure, - ov4689->exposure->minimum, max_expo, - ov4689->exposure->step, - ov4689->exposure->default_value); + max_expo = crop->height + ctrl->val -4 ; + def_expo =clamp_t (s64, ov4689->exposure->default_value, + ov4689->exposure->minimum, max_expo); + + ret =__v4l2_ctrl_modify_range (ov4689->exposure, + ov4689->exposure->minimum, + max_expo, ov4689->exposure->step, + def_expo);break ; }
@@ -666,14 +812,14 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_VBLANK :cci_write (regmap,OV4689_REG_VTS , - ctrl->val + ov4689->cur_mode->height, &ret); + ctrl->val + crop->height, &ret);break ;case V4L2_CID_TEST_PATTERN : ret =ov4689_enable_test_pattern (ov4689, ctrl->val);break ;case V4L2_CID_HBLANK :cci_write (regmap,OV4689_REG_HTS , - (ctrl->val + ov4689->cur_mode->width) / + (ctrl->val + crop->width) /OV4689_HTS_DIVIDER , &ret);break ;case V4L2_CID_VFLIP :
@@ -739,14 +885,16 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) hblank_def = mode->hts_def - mode->width; hblank_min = mode->hts_min - mode->width; -v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HBLANK , - hblank_min,OV4689_HTS_MAX - mode->width, -OV4689_HTS_DIVIDER , hblank_def); + ov4689->hblank =v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops, +V4L2_CID_HBLANK , hblank_min, +OV4689_HTS_MAX - mode->width, +OV4689_HTS_DIVIDER , hblank_def); vblank_def = mode->vts_def - mode->height; -v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VBLANK , - vblank_def,OV4689_VTS_MAX - mode->height,1 , - vblank_def); + ov4689->vblank =v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops, +V4L2_CID_VBLANK ,OV4689_VBLANK_MIN , +OV4689_VTS_MAX - mode->height,1 , + vblank_def); exposure_max = mode->vts_def -4 ; ov4689->exposure =
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 18/20 media: i2c: ov4689: Eliminate struct ov4689_mode
In reply to Mikhail RudenkoWith the output frame size now controlled by selection rather than cur_mode, this commit relocates pixel rate and default VTS to defines. Consequently, it removes struct ov4689_mode and the cur_mode field from struct ov4689.
--- drivers/media/i2c/ov4689.c | 70 +++++++++----------------------------- 1 file changed, 17 insertions(+), 53 deletions(-)
drivers/media/i2c/ov4689.c +17 -53
@@ -57,6 +57,8 @@#define OV4689_HTS_MAX 0x7fff#define OV4689_REG_VTS CCI_REG16(0x380e) +/* Default VTS corresponds to 30 fps at default crop and minimal HTS */ +#define OV4689_VTS_DEF 4683#define OV4689_VTS_MAX 0x7fff#define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810)
@@ -94,6 +96,7 @@#define OV4689_LANES 4#define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_RATE 480000000#define OV4689_PIXEL_ARRAY_WIDTH 2720#define OV4689_PIXEL_ARRAY_HEIGHT 1536
@@ -119,24 +122,6 @@ static const char *const ov4689_supply_names[] = { "dvdd", /* Digital core power */ }; -enum ov4689_mode_id { -OV4689_MODE_2688_1520 =0 , -OV4689_NUM_MODES , -}; - -struct ov4689_mode { -enum ov4689_mode_id id; -u32 width; -u32 height; -u32 hts_def; -u32 hts_min; -u32 vts_def; -u32 exp_def; -u32 pixel_rate; -const struct cci_reg_sequence *reg_list; -unsigned int num_regs; -}; -struct ov4689 {struct device *dev;struct regmap *regmap;
@@ -152,8 +137,6 @@ struct ov4689 {struct v4l2_ctrl_handler ctrl_handler;struct v4l2_ctrl *exposure, *hblank, *vblank; - -const struct ov4689_mode *cur_mode; };#define to_ov4689 (sd) container_of(sd, struct ov4689, subdev)
@@ -172,7 +155,7 @@ struct ov4689_gain_range {* max_framerate 90fps * mipi_datarate per lane 1008Mbps */ -static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { +static const struct cci_reg_sequence ov4689_common_regs[] = {/* System control*/ {CCI_REG8 (0x0103 ),0x01 },/* SC_CTRL0103 software_reset = 1 */ {CCI_REG8 (0x3000 ),0x20 },/* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */
@@ -273,21 +256,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x5503), 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ }; -static const struct ov4689_mode supported_modes[] = { - { - .id =OV4689_MODE_2688_1520 , - .width =2688 , - .height =1520 , - .exp_def =1536 , - .hts_def =10296 , - .hts_min =3432 , - .vts_def =1554 , - .pixel_rate =480000000 , - .reg_list = ov4689_2688x1520_regs, - .num_regs =ARRAY_SIZE (ov4689_2688x1520_regs), - }, -}; -static const u64 link_freq_menu_items[] = {504000000 }; static const char *const ov4689_test_pattern_menu[] = {
@@ -584,8 +552,8 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; ret =cci_multi_reg_write (ov4689->regmap, - ov4689->cur_mode->reg_list, - ov4689->cur_mode->num_regs, + ov4689_common_regs, +ARRAY_SIZE (ov4689_common_regs),NULL );if (ret) {pm_runtime_put_sync (dev);
@@ -863,14 +831,12 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)struct i2c_client *client =v4l2_get_subdevdata (&ov4689->subdev);struct v4l2_fwnode_device_properties props;struct v4l2_ctrl_handler *handler; -const struct ov4689_mode *mode;s64 exposure_max, vblank_def; -s64 hblank_def, hblank_min;struct v4l2_ctrl *ctrl; +s64 hblank_def;int ret; handler = &ov4689->ctrl_handler; - mode = ov4689->cur_mode; ret =v4l2_ctrl_handler_init (handler,15 );if (ret)return ret;
@@ -881,26 +847,26 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ;v4l2_ctrl_new_std (handler,NULL ,V4L2_CID_PIXEL_RATE ,0 , - mode->pixel_rate,1 , mode->pixel_rate); +OV4689_PIXEL_RATE ,1 ,OV4689_PIXEL_RATE ); - hblank_def = mode->hts_def - mode->width; - hblank_min = mode->hts_min - mode->width; + hblank_def =ov4689_hts_min (OV4689_H_OUTPUT_SIZE_DEFAULT ) - +OV4689_H_OUTPUT_SIZE_DEFAULT ; ov4689->hblank =v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops, -V4L2_CID_HBLANK , hblank_min, -OV4689_HTS_MAX - mode->width, +V4L2_CID_HBLANK , hblank_def, +OV4689_HTS_MAX -OV4689_H_OUTPUT_SIZE_DEFAULT ,OV4689_HTS_DIVIDER , hblank_def); - vblank_def = mode->vts_def - mode->height; + vblank_def =OV4689_VTS_DEF -OV4689_V_OUTPUT_SIZE_DEFAULT ; ov4689->vblank =v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VBLANK ,OV4689_VBLANK_MIN , -OV4689_VTS_MAX - mode->height,1 , - vblank_def); +OV4689_VTS_MAX -OV4689_V_OUTPUT_SIZE_DEFAULT , +1 , vblank_def); - exposure_max = mode->vts_def -4 ; + exposure_max =OV4689_VTS_DEF -4 ; ov4689->exposure =v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_EXPOSURE ,OV4689_EXPOSURE_MIN , exposure_max, -OV4689_EXPOSURE_STEP , mode->exp_def); +OV4689_EXPOSURE_STEP , exposure_max); v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, ov4689_gain_ranges[0].logical_min,
@@ -1055,8 +1021,6 @@ static int ov4689_probe(struct i2c_client *client) ov4689->dev = dev; - ov4689->cur_mode = &supported_modes[OV4689_MODE_2688_1520 ]; - ov4689->xvclk =devm_clk_get_optional (dev,NULL );if (IS_ERR (ov4689->xvclk)) return dev_err_probe(dev, PTR_ERR(ov4689->xvclk),
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 19/20 media: i2c: ov4689: Refactor ov4689_s_stream
In reply to Mikhail RudenkoRemove repetitive pm_runtime_put calls in ov4689_s_stream function, and call pm_runtime_put once at the end of the "on" branch if any error occurred.
--- drivers/media/i2c/ov4689.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-)
drivers/media/i2c/ov4689.c +10 -19
@@ -555,35 +555,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689_common_regs,ARRAY_SIZE (ov4689_common_regs), NULL); -if (ret) { -pm_runtime_put_sync (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =ov4689_setup_timings (ov4689, sd_state); -if (ret) { -pm_runtime_put (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =ov4689_setup_blc_anchors (ov4689, sd_state); -if (ret) { -pm_runtime_put (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler); -if (ret) { -pm_runtime_put_sync (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL ); -if (ret) { +cleanup_pm: +if (ret)pm_runtime_put_sync (dev); - goto unlock_and_return; - } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL );
Signature · 1 line
2.43.0
Mikhail Rudenko
maintainerPATCH v2 20/20 media: i2c: ov4689: Implement 2x2 binning
In reply to Mikhail RudenkoImplement 2x2 binning support. Compute best binning mode (none or 2x2) from pad crop and pad format in ov4689_set_fmt. Use output frame size instead of analogue crop to compute control ranges and BLC anchors.
Also move ov4689_hts_min and ov4689_update_ctrl_ranges, since they are now also called from ov4689_set_fmt. Update frame timings to accommodate the requirements of binning mode and avoid visual artefacts. Additionally, report 2x2 binned mode in addition to non-binned one in ov4689_enum_frame_sizes.
--- drivers/media/i2c/ov4689.c | 192 +++++++++++++++++++++++++------------ 1 file changed, 130 insertions(+), 62 deletions(-)
drivers/media/i2c/ov4689.c +130 -62
@@ -114,7 +114,7 @@* Minimum working vertical blanking value. Found experimentally at * minimum HTS values. */ -#define OV4689_VBLANK_MIN 31 +#define OV4689_VBLANK_MIN 35static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */
@@ -256,6 +256,18 @@ static const struct cci_reg_sequence ov4689_common_regs[] = { {CCI_REG8(0x5503), 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ }; +static const struct cci_reg_sequence ov4689_2x2_binning_regs[] = { + {CCI_REG8 (0x3632 ),0x05 },/* ADC */ + {CCI_REG8 (0x376b ),0x40 },/* Sensor control */ + {CCI_REG8 (0x3814 ),0x03 },/* H_INC_ODD */ + {CCI_REG8 (0x3821 ),0x07 },/* TIMING_FORMAT_2 hor_binning = 1*/ + {CCI_REG8 (0x382a ),0x03 },/* V_INC_ODD */ + {CCI_REG8 (0x3830 ),0x08 },/* BLC_NUM_OPTION blc_use_num_2 = 1 */ + {CCI_REG8 (0x3836 ),0x02 },/* TIMING_REG_36 r_zline_use_num_2 = 1 */ + {CCI_REG8 (0x4001 ),0x50 },/* BLC DEBUG MODE */ + {CCI_REG8 (0x4502 ),0x44 },/* ADC synch control*/ +}; +static const u64 link_freq_menu_items[] = {504000000 }; static const char *const ov4689_test_pattern_menu[] = {
@@ -305,18 +317,96 @@ static const struct ov4689_gain_range ov4689_gain_ranges[] = { }, }; +/* +* For now, only 2x2 binning implemented in this driver. +*/ +static int ov4689_best_binning (struct ov4689 *ov4689, +const struct v4l2_mbus_framefmt *format, +const struct v4l2_rect *crop, +unsigned int *binning) +{ +const struct v4l2_area candidates[] = { + { crop->width, crop->height }, + { crop->width /2 , crop->height /2 }, + }; + +const struct v4l2_area *best; +int index; + + best =v4l2_find_nearest_size (candidates,ARRAY_SIZE (candidates), width, + height, format->width, format->height); +if (!best) { +dev_err (ov4689->dev, +"failed to find best binning for requested mode\n" ); +return -EINVAL ; + } + + index = best - candidates; + *binning = index +1 ; + +dev_dbg (ov4689->dev, +"best_binning: crop=%dx%d format=%dx%d binning=%d\n" , + crop->width, crop->height, format->width, format->height, + *binning); + +return 0 ; +} + +/* +* Minimum working HTS value for given output width (found +* experimentally). +*/ +static unsigned int ov4689_hts_min (unsigned int width) +{ + return max_t(unsigned int, 3156, 224 + width * 19 / 16); +} + +static void ov4689_update_ctrl_ranges (struct ov4689 *ov4689,unsigned int width, +unsigned int height) +{ +struct v4l2_ctrl *exposure = ov4689->exposure; +struct v4l2_ctrl *vblank = ov4689->vblank; +struct v4l2_ctrl *hblank = ov4689->hblank; +s64 def_val, min_val, max_val; + + min_val =ov4689_hts_min (width) - width; + max_val =OV4689_HTS_MAX - width; + def_val =clamp_t (s64, hblank->default_value, min_val, max_val); +__v4l2_ctrl_modify_range (hblank, min_val, max_val, hblank->step, + def_val); + + min_val =OV4689_VBLANK_MIN ; + max_val =OV4689_HTS_MAX - width; + def_val =clamp_t (s64, vblank->default_value, min_val, max_val); +__v4l2_ctrl_modify_range (vblank, min_val, max_val, vblank->step, + def_val); + + min_val = exposure->minimum; + max_val = height + vblank->val -4 ; + def_val =clamp_t (s64, exposure->default_value, min_val, max_val); +__v4l2_ctrl_modify_range (exposure, min_val, max_val, exposure->step, + def_val); +} +static int ov4689_set_fmt (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_format *fmt) { +struct ov4689 *ov4689 =to_ov4689 (sd);struct v4l2_mbus_framefmt *format;struct v4l2_rect *crop; +unsigned int binning; +int ret; crop =v4l2_subdev_state_get_crop (sd_state, fmt->pad); format =v4l2_subdev_state_get_format (sd_state, fmt->pad); - format->width = crop->width; - format->height = crop->height; + ret =ov4689_best_binning (ov4689, &fmt->format, crop, &binning); +if (ret) +return ret; + + format->width = crop->width / binning; + format->height = crop->height / binning; format->code =MEDIA_BUS_FMT_SBGGR10_1X10 ; format->field =V4L2_FIELD_NONE ;
@@ -327,6 +417,9 @@ static int ov4689_set_fmt(struct v4l2_subdev *sd, fmt->format = *format; +if (fmt->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) +ov4689_update_ctrl_ranges (ov4689, format->width, format->height); +return 0 ; }
@@ -346,8 +439,9 @@ static int ov4689_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_frame_size_enum *fse) {const struct v4l2_rect *crop; +int binning; -if (fse->index >=1 ) +if (fse->index >=2 )return -EINVAL ;if (fse->code !=MEDIA_BUS_FMT_SBGGR10_1X10 )
@@ -355,10 +449,11 @@ static int ov4689_enum_frame_sizes(struct v4l2_subdev *sd, crop =v4l2_subdev_state_get_crop (sd_state,0 ); - fse->min_width = crop->width; - fse->max_width = crop->width; - fse->max_height = crop->height; - fse->min_height = crop->height; + binning = fse->index +1 ; + fse->min_width = crop->width / binning; + fse->max_width = crop->width / binning; + fse->max_height = crop->height / binning; + fse->min_height = crop->height / binning;return 0 ; }
@@ -398,42 +493,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,return -EINVAL ; } -/* -* Minimum working HTS value for given output width (found -* experimentally). -*/ -static unsigned int ov4689_hts_min (unsigned int width) -{ - return max_t(unsigned int, 3156, 224 + width * 19 / 16); -} - -static void ov4689_update_ctrl_ranges (struct ov4689 *ov4689, -struct v4l2_rect *crop) -{ -struct v4l2_ctrl *exposure = ov4689->exposure; -struct v4l2_ctrl *vblank = ov4689->vblank; -struct v4l2_ctrl *hblank = ov4689->hblank; -s64 def_val, min_val, max_val; - - min_val =ov4689_hts_min (crop->width) - crop->width; - max_val =OV4689_HTS_MAX - crop->width; - def_val =clamp_t (s64, hblank->default_value, min_val, max_val); -__v4l2_ctrl_modify_range (hblank, min_val, max_val, hblank->step, - def_val); - - min_val =OV4689_VBLANK_MIN ; - max_val =OV4689_HTS_MAX - crop->width; - def_val =clamp_t (s64, vblank->default_value, min_val, max_val); -__v4l2_ctrl_modify_range (vblank, min_val, max_val, vblank->step, - def_val); - - min_val = exposure->minimum; - max_val = crop->height + vblank->val -4 ; - def_val =clamp_t (s64, exposure->default_value, min_val, max_val); -__v4l2_ctrl_modify_range (exposure, min_val, max_val, exposure->step, - def_val); -} -static int ov4689_set_selection (struct v4l2_subdev *sd,struct v4l2_subdev_state *state,struct v4l2_subdev_selection *sel)
@@ -470,7 +529,8 @@ static int ov4689_set_selection(struct v4l2_subdev *sd, format->height = rect.height;if (sel->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) -ov4689_update_ctrl_ranges (ov4689, &rect); +ov4689_update_ctrl_ranges (ov4689, rect.width, + rect.height); } *crop = rect;
@@ -485,21 +545,27 @@ static int ov4689_setup_timings(struct ov4689 *ov4689,const struct v4l2_mbus_framefmt *format;struct regmap *rm = ov4689->regmap;const struct v4l2_rect *crop; +const int v_offset =2 ; +unsigned int binning;int ret =0 ; format =v4l2_subdev_state_get_format (state,0 ); crop =v4l2_subdev_state_get_crop (state,0 ); + ret =ov4689_best_binning (ov4689, format, crop, &binning); +if (ret) +return ret; +cci_write (rm,OV4689_REG_H_CROP_START , crop->left, &ret); -cci_write (rm,OV4689_REG_V_CROP_START , crop->top, &ret); -cci_write (rm,OV4689_REG_H_CROP_END , crop->left + crop->width +1 , &ret); -cci_write (rm,OV4689_REG_V_CROP_END , crop->top + crop->height +1 , &ret); +cci_write (rm,OV4689_REG_V_CROP_START , crop->top - v_offset, &ret); +cci_write (rm,OV4689_REG_H_CROP_END , crop->left + crop->width +3 , &ret); +cci_write (rm,OV4689_REG_V_CROP_END , crop->top + crop->height +7 , &ret);cci_write (rm,OV4689_REG_H_OUTPUT_SIZE , format->width, &ret);cci_write (rm,OV4689_REG_V_OUTPUT_SIZE , format->height, &ret);cci_write (rm,OV4689_REG_H_WIN_OFF ,0 , &ret); -cci_write (rm,OV4689_REG_V_WIN_OFF ,0 , &ret); +cci_write (rm,OV4689_REG_V_WIN_OFF , v_offset, &ret);/* * Maximum working value of vfifo_read_start for given output
@@ -507,6 +573,10 @@ static int ov4689_setup_timings(struct ov4689 *ov4689,*/ cci_write (rm,OV4689_REG_VFIFO_CTRL_01 , format->width /16 -1 , &ret); +if (binning ==2 ) +cci_multi_reg_write (ov4689->regmap, ov4689_2x2_binning_regs, +ARRAY_SIZE (ov4689_2x2_binning_regs), + &ret);return ret; }
@@ -519,20 +589,20 @@ static int ov4689_setup_blc_anchors(struct ov4689 *ov4689, struct v4l2_subdev_state *state) {unsigned int width_def =OV4689_H_OUTPUT_SIZE_DEFAULT ; +const struct v4l2_mbus_framefmt *format;struct regmap *rm = ov4689->regmap; -const struct v4l2_rect *crop;int ret =0 ; - crop =v4l2_subdev_state_get_crop (state,0 ); + format =v4l2_subdev_state_get_format (state,0 );cci_write (rm,OV4689_REG_ANCHOR_LEFT_START , -OV4689_ANCHOR_LEFT_START_DEF * crop->width / width_def, &ret); +OV4689_ANCHOR_LEFT_START_DEF * format->width / width_def, &ret);cci_write (rm,OV4689_REG_ANCHOR_LEFT_END , -OV4689_ANCHOR_LEFT_END_DEF * crop->width / width_def, &ret); +OV4689_ANCHOR_LEFT_END_DEF * format->width / width_def, &ret);cci_write (rm,OV4689_REG_ANCHOR_RIGHT_START , -OV4689_ANCHOR_RIGHT_START_DEF * crop->width / width_def, &ret); +OV4689_ANCHOR_RIGHT_START_DEF * format->width / width_def, &ret);cci_write (rm,OV4689_REG_ANCHOR_RIGHT_END , -OV4689_ANCHOR_RIGHT_END_DEF * crop->width / width_def, &ret); +OV4689_ANCHOR_RIGHT_END_DEF * format->width / width_def, &ret);return ret; }
@@ -734,19 +804,19 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)struct regmap *regmap = ov4689->regmap;struct v4l2_subdev_state *sd_state;struct device *dev = ov4689->dev; -struct v4l2_rect *crop; +struct v4l2_mbus_framefmt *fmt;s64 max_expo, def_expo;int sensor_gain;int ret; sd_state =v4l2_subdev_get_locked_active_state (&ov4689->subdev); - crop =v4l2_subdev_state_get_crop (sd_state,0 ); + fmt =v4l2_subdev_state_get_format (sd_state,0 );/* Propagate change of current control to all related controls */ switch (ctrl->id) {case V4L2_CID_VBLANK :/* Update max exposure while meeting expected vblanking */ - max_expo = crop->height + ctrl->val -4 ; + max_expo = fmt->height + ctrl->val -4 ; def_expo =clamp_t (s64, ov4689->exposure->default_value, ov4689->exposure->minimum, max_expo);
@@ -770,16 +840,14 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)cci_write (regmap,OV4689_REG_GAIN , sensor_gain, &ret);break ;case V4L2_CID_VBLANK : -cci_write (regmap,OV4689_REG_VTS , - ctrl->val + crop->height, &ret); +cci_write (regmap,OV4689_REG_VTS , ctrl->val + fmt->height, &ret);break ;case V4L2_CID_TEST_PATTERN : ret =ov4689_enable_test_pattern (ov4689, ctrl->val);break ;case V4L2_CID_HBLANK :cci_write (regmap,OV4689_REG_HTS , - (ctrl->val + crop->width) / -OV4689_HTS_DIVIDER , &ret); + (ctrl->val + fmt->width) /OV4689_HTS_DIVIDER , &ret);break ;case V4L2_CID_VFLIP : cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT1,
Signature · 1 line
2.43.0
Re: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
In reply to Mikhail RudenkoHi Mikhail,
Quoted 13 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)drivers/media/i2c/ov4689.c +0
-0
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 5 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);
Why are you switching to pm_runtime_put_sync() here? That isn't covered by the commit message (nor I think should be done).
Quoted 27 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:
drivers/media/i2c/ov4689.c static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) · line 611
Quoted 6 lines
drivers/media/i2c/ov4689.c +2
-1@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; } -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);
Also note that with runtime PM autosuspend, you have to use pm_runtime_get_if_active() instead of pm_runtime_get_if_in_use().
Quoted 32 lines
drivers/media/i2c/ov4689.c +8
-2+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ; err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH v2 06/20] media: i2c: ov4689: Refactor ov4689_set_ctrl
In reply to Mikhail RudenkoHi Mikhail,
Quoted 21 lines · Mikhail Rudenko
Introduce local variable for regmap within the
ov4689_set_ctrlfunction. This adjustment eliminates repetition within the function.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ov4689.c +1
-0@@ -580,6 +580,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) {struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); +struct regmap *regmap = ov4689->regmap;struct device *dev = ov4689->dev;int sensor_gain;s64 max_expo;
drivers/media/i2c/ov4689.c static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) · line 607
Quoted 6 lines
drivers/media/i2c/ov4689.c +1
-2@@ -603,16 +604,15 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_EXPOSURE :/* 4 least significant bits of exposure are fractional part */ - ret =cci_write (ov4689->regmap,OV4689_REG_EXPOSURE , - ctrl->val <<4 ,NULL ); +cci_write (regmap,OV4689_REG_EXPOSURE , ctrl->val <<4 , &ret);
If you do this, ret needs to have been initialised to 0, but it isn't.
Same for the changes below.
Quoted 15 lines
drivers/media/i2c/ov4689.c +3
-3break ;case V4L2_CID_ANALOGUE_GAIN : ret =ov4689_map_gain (ov4689, ctrl->val, &sensor_gain); -cci_write (ov4689->regmap,OV4689_REG_GAIN , sensor_gain, &ret); +cci_write (regmap,OV4689_REG_GAIN , sensor_gain, &ret);break ;case V4L2_CID_VBLANK : - ret =cci_write (ov4689->regmap,OV4689_REG_VTS , - ctrl->val + ov4689->cur_mode->height,NULL ); +cci_write (regmap,OV4689_REG_VTS , + ctrl->val + ov4689->cur_mode->height, &ret);break ;case V4L2_CID_TEST_PATTERN : ret =ov4689_enable_test_pattern (ov4689, ctrl->val);
drivers/media/i2c/ov4689.c static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) · line 628
Quoted 4 lines
drivers/media/i2c/ov4689.c +0
-1@@ -625,7 +625,6 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) }pm_runtime_put (dev); -
I thought it was nice.
Quoted 3 lines
drivers/media/i2c/ov4689.c +0
-0return ret; }
Signature · 3 lines
Regards, Sakari Ailus
Mikhail Rudenko
maintainerRe: [PATCH v2 06/20] media: i2c: ov4689: Refactor ov4689_set_ctrl
Hi Sakari,
Thanks for the review!
Quoted 33 lines · Sakari Ailus
Hi Mikhail,
Quoted 21 lines · Mikhail Rudenko
Introduce local variable for regmap within the
ov4689_set_ctrlfunction. This adjustment eliminates repetition within the function.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)drivers/media/i2c/ov4689.c +1
-0@@ -580,6 +580,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) {struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); +struct regmap *regmap = ov4689->regmap;struct device *dev = ov4689->dev;int sensor_gain;s64 max_expo;drivers/media/i2c/ov4689.c static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) · line 607
Quoted 6 lines
drivers/media/i2c/ov4689.c +1
-2@@ -603,16 +604,15 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_EXPOSURE :/* 4 least significant bits of exposure are fractional part */ - ret =cci_write (ov4689->regmap,OV4689_REG_EXPOSURE , - ctrl->val <<4 ,NULL ); +cci_write (regmap,OV4689_REG_EXPOSURE , ctrl->val <<4 , &ret);If you do this, ret needs to have been initialised to 0, but it isn't.
Quoted 1 line
Same for the changes below.
Nice catch, will fix it in v3.
Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/ov4689.c +3
-3break ;case V4L2_CID_ANALOGUE_GAIN : ret =ov4689_map_gain (ov4689, ctrl->val, &sensor_gain); -cci_write (ov4689->regmap,OV4689_REG_GAIN , sensor_gain, &ret); +cci_write (regmap,OV4689_REG_GAIN , sensor_gain, &ret);break ;case V4L2_CID_VBLANK : - ret =cci_write (ov4689->regmap,OV4689_REG_VTS , - ctrl->val + ov4689->cur_mode->height,NULL ); +cci_write (regmap,OV4689_REG_VTS , + ctrl->val + ov4689->cur_mode->height, &ret);break ;case V4L2_CID_TEST_PATTERN : ret =ov4689_enable_test_pattern (ov4689, ctrl->val);@@ -625,7 +625,6 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) }
Quoted 4 lines
drivers/media/i2c/ov4689.c static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) · line 628
Quoted 2 lines
drivers/media/i2c/ov4689.c +0
-1pm_runtime_put (dev); -I thought it was nice.
Will get the blank line back in v3, especially since "Use runtime autosuspend" patch (09/20) restores it.
Quoted 3 lines
drivers/media/i2c/ov4689.c static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) · line 630
Quoted 3 lines
drivers/media/i2c/ov4689.c +0
-0return ret; }
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
In reply to Sakari AilusHi Sakari,
Thanks for the review!
Quoted 11 lines · Sakari Ailus
Hi Mikhail,
Quoted 8 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
Quoted 13 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 10 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);Why are you switching to
pm_runtime_put_sync()here? That isn't covered by the commit message (nor I think should be done).
PM autosuspend conversion was suggested earlier by Laurent in his review of this series [1], and he adviced looking at how it was done for the imx290 driver. I followed along the lines of the corresponding patch [2].
Quoted 30 lines
Quoted 30 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; }
Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 430
Quoted 3 lines
drivers/media/i2c/ov4689.c +2
-1-pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);Also note that with runtime PM autosuspend, you have to use
pm_runtime_get_if_active()instead ofpm_runtime_get_if_in_use().
Noted, will do so in v3.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/ov4689.c +7
-1+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ;
Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 904
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-1err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
--
Best regards,
Mikhail Rudenko
Sakari Ailus
maintainerRe: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
Hi Mikhail,
Quoted 31 lines · Mikhail Rudenko
Hi Sakari,
Thanks for the review!
Quoted 11 lines · Sakari Ailus
Hi Mikhail,
Quoted 8 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)Quoted 13 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 10 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);Why are you switching to
pm_runtime_put_sync()here? That isn't covered by the commit message (nor I think should be done).
Quoted 4 lines
PM autosuspend conversion was suggested earlier by Laurent in his review of this series [1], and he adviced looking at how it was done for the imx290 driver. I followed along the lines of the corresponding patch [2].
Ah, I suppose all of these are error cases. I suppose it won't do any harm in this case but it's not really useful either.
You can get more benefits from autosuspend if you can avoid writing registers that already have the same values you're writing to them. Thay may be better left outside this set as it's already fairly big.
Quoted 76 lines
Quoted 31 lines
Quoted 31 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; }Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 430
Quoted 3 lines
drivers/media/i2c/ov4689.c +2
-1-pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);Also note that with runtime PM autosuspend, you have to use
pm_runtime_get_if_active()instead ofpm_runtime_get_if_in_use().Noted, will do so in v3.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/ov4689.c +7
-1+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ;Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 904
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-1err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Signature · 3 lines
Regards, Sakari Ailus
Mikhail Rudenko
maintainerHi,
Quoted 12 lines · Mikhail Rudenko
Hi,
This series contains refactoring and new features implementation for the Omnivision OV4689 sensor driver. Specifically, patches 1, 2, 3, 5, 6, 10, 15, 16, 18, and 19 are refactorings, and are not supposed to introduce any functional change. Patches 4 and 7 perform migration to CCI helpers and subdevice active state respectively, and should not introduce any hardware- and/or user-visible change either. Patch 8 fixes a possible race condition due to
v4l2_async_register_subdev_sensorbeing called too early inov4689_probe, and patch 9 migrates power management to PM autosuspend.
Quoted 7 lines
Patches 11-14 expose more sensor controls to the userspace, such as (read-write) HBLANK, VFLIP/HFLIP, digital gain, and color balance. Patch 17 implements configurable analogue crop rectangle via .set_selection callback. And finally, patch 20 enables 2x2 binning option. It should be noted that publicly available sensor documentation is lacking description of many registers and their value ranges, so a lot of values had to be found by experimentation.
Gentle ping on this series. Anything I can do to help getting it reviewed and merged? Maybe split patches 15-20 which implement cropping and binning and change the driver away from register list based model into a separate series? Anyone?
Quoted 34 lines
Changes in v2:
- collect Laurent's r-b's
- squash together "CCI conversion" and "Set gain in one 16 bit write"
- usectrl->valinov4689_set_ctrl
- renametry_fmtto fmt inov4689_init_cfgand drop corresponding comment
- rebase on top of media-stage and renameinit_cfg->init_state
- sort register definitions by address throughout the whole series
- fix number of controls hint inv4l2_ctrl_handler_init
- make all hexadecimal constants lowercase
- disable runtime pm in probe error path
- implement pm autosuspendMikhail Rudenko (20):
media: i2c: ov4689: Clean up and annotate the register table
media: i2c: ov4689: Sort register definitions by address
media: i2c: ov4689: Fix typo in a comment
media: i2c: ov4689: CCI conversion
media: i2c: ov4689: Removei2c_clientfrom ov4689 struct
media: i2c: ov4689: Refactorov4689_set_ctrl
media: i2c: ov4689: Use sub-device active state
media: i2c: ov4689: Enable runtime PM before registering sub-device
media: i2c: ov4689: Use runtime PM autosuspend
media: i2c: ov4689: Removemax_fpsfield from structov4689_mode
media: i2c: ov4689: Make horizontal blanking configurable
media: i2c: ov4689: Implement vflip/hflip controls
media: i2c: ov4689: Implement digital gain control
media: i2c: ov4689: Implement manual color balance controls
media: i2c: ov4689: Move pixel array size out of structov4689_mode
media: i2c: ov4689: Set timing registers programmatically
media: i2c: ov4689: Configurable analogue crop
media: i2c: ov4689: Eliminate structov4689_mode
media: i2c: ov4689: Refactorov4689_s_stream
media: i2c: ov4689: Implement 2x2 binning
Quoted 3 lines
drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov4689.c | 964 +++++++++++++++++++++++-------------- 2 files changed, 592 insertions(+), 373 deletions(-)
--
Best regards,
Mikhail Rudenko
Sakari Ailus
maintainerHi Mikhail,
Quoted 25 lines · Mikhail Rudenko
Hi,
Quoted 12 lines · Mikhail Rudenko
Hi,
This series contains refactoring and new features implementation for the Omnivision OV4689 sensor driver. Specifically, patches 1, 2, 3, 5, 6, 10, 15, 16, 18, and 19 are refactorings, and are not supposed to introduce any functional change. Patches 4 and 7 perform migration to CCI helpers and subdevice active state respectively, and should not introduce any hardware- and/or user-visible change either. Patch 8 fixes a possible race condition due to
v4l2_async_register_subdev_sensorbeing called too early inov4689_probe, and patch 9 migrates power management to PM autosuspend.Quoted 7 lines
Patches 11-14 expose more sensor controls to the userspace, such as (read-write) HBLANK, VFLIP/HFLIP, digital gain, and color balance. Patch 17 implements configurable analogue crop rectangle via .set_selection callback. And finally, patch 20 enables 2x2 binning option. It should be noted that publicly available sensor documentation is lacking description of many registers and their value ranges, so a lot of values had to be found by experimentation.
Quoted 4 lines
Gentle ping on this series. Anything I can do to help getting it reviewed and merged? Maybe split patches 15-20 which implement cropping and binning and change the driver away from register list based model into a separate series? Anyone?
Oops, my bad. I'll review these shortly. I can already tell there's not much to do though.
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
In reply to Mikhail RudenkoHi Mikhail,
Quoted 31 lines · Mikhail Rudenko
Hi Sakari,
Thanks for the review!
Quoted 11 lines · Sakari Ailus
Hi Mikhail,
Quoted 8 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)Quoted 13 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 10 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);Why are you switching to
pm_runtime_put_sync()here? That isn't covered by the commit message (nor I think should be done).
Quoted 4 lines
PM autosuspend conversion was suggested earlier by Laurent in his review of this series [1], and he adviced looking at how it was done for the imx290 driver. I followed along the lines of the corresponding patch [2].
There's no need to use the _sync() variant here. And at least it wouldn't be related to autosuspend, were you to switch to that.
Quoted 76 lines
Quoted 31 lines
Quoted 31 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; }Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 430
Quoted 3 lines
drivers/media/i2c/ov4689.c +2
-1-pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);Also note that with runtime PM autosuspend, you have to use
pm_runtime_get_if_active()instead ofpm_runtime_get_if_in_use().Noted, will do so in v3.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/ov4689.c +7
-1+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ;Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 904
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-1err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH v2 12/20] media: i2c: ov4689: Implement vflip/hflip controls
In reply to Mikhail RudenkoHi Mikhail,
Quoted 65 lines · Mikhail Rudenko
The OV4689 sensor supports horizontal and vertical flipping. Add appropriate controls to the driver. Toggling both array flip and digital flip bits allows to achieve flipping while maintaining output Bayer order. Note that the default value of hflip control corresponds to both bits set, as it was before this patch.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/media/i2c/ov4689.c +19
-2@@ -42,6 +42,14 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) +#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) +#define OV4689_TIMING_FLIP_ARRAY BIT(1) +#define OV4689_TIMING_FLIP_DIGITAL BIT(2) +#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ + OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0@@ -183,7 +191,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ - {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 *//* OTP control */ {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1,@@ -607,6 +614,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) (ctrl->val + ov4689->cur_mode->width) / OV4689_HTS_DIVIDER, &ret);break ; +case V4L2_CID_VFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT1 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?OV4689_TIMING_FLIP_BOTH :0 , &ret); +break ; +case V4L2_CID_HFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT2 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?0 :OV4689_TIMING_FLIP_BOTH , &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);@@ -637,7 +654,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,10 ); + ret =v4l2_ctrl_handler_init (handler,12 );if (ret)return ret;
drivers/media/i2c/ov4689.c static int ov4689_initialize_controls(struct ov4689 *ov4689) · line 698
Quoted 5 lines
drivers/media/i2c/ov4689.c +2
-0@@ -677,6 +694,9 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)ARRAY_SIZE (ov4689_test_pattern_menu) -1 , 0, 0, ov4689_test_pattern_menu); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 );
Could you take the default value from the mounting rotation?
The default should be upside-up, but this is an existing driver and
changing the flipping now could affect existing users. <URL:https://hverkuil.home.xs4all.nl/spec/userspace-api/drivers/camera-sensor.html#rotation-orientation-and-flipping>
Quoted 4 lines
drivers/media/i2c/ov4689.c +1
-0+if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerQuoted 28 lines · Sakari Ailus
Hi Mikhail,
Quoted 25 lines · Mikhail Rudenko
Hi,
Quoted 19 lines · Mikhail Rudenko
Hi,
This series contains refactoring and new features implementation for the Omnivision OV4689 sensor driver. Specifically, patches 1, 2, 3, 5, 6, 10, 15, 16, 18, and 19 are refactorings, and are not supposed to introduce any functional change. Patches 4 and 7 perform migration to CCI helpers and subdevice active state respectively, and should not introduce any hardware- and/or user-visible change either. Patch 8 fixes a possible race condition due to
v4l2_async_register_subdev_sensorbeing called too early inov4689_probe, and patch 9 migrates power management to PM autosuspend.Patches 11-14 expose more sensor controls to the userspace, such as (read-write) HBLANK, VFLIP/HFLIP, digital gain, and color balance. Patch 17 implements configurable analogue crop rectangle via .set_selection callback. And finally, patch 20 enables 2x2 binning option. It should be noted that publicly available sensor documentation is lacking description of many registers and their value ranges, so a lot of values had to be found by experimentation.
Quoted 7 lines
Quoted 4 lines
Gentle ping on this series. Anything I can do to help getting it reviewed and merged? Maybe split patches 15-20 which implement cropping and binning and change the driver away from register list based model into a separate series? Anyone?
Oops, my bad. I'll review these shortly. I can already tell there's not much to do though.
Done.
Signature · 1 line
Sakari Ailus
Re: [PATCH v2 02/20] media: i2c: ov4689: Sort register definitions by address
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 4 lines · Mikhail Rudenko
Put register defininitions in the order of increasing register address.
Signed-off-by Mikhail Rudenko <[email protected]>
Quoted 42 lines
--- drivers/media/i2c/ov4689.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/media/i2c/ov4689.c +5
-5@@ -19,15 +19,15 @@#include <media/v4l2-subdev.h> #include <media/v4l2-fwnode.h> -#define CHIP_ID 0x004688 -#define OV4689_REG_CHIP_ID 0x300a -#define OV4689_XVCLK_FREQ 24000000#define OV4689_REG_CTRL_MODE 0x0100#define OV4689_MODE_SW_STANDBY 0x0#define OV4689_MODE_STREAMING BIT(0) +#define OV4689_REG_CHIP_ID 0x300a +#define CHIP_ID 0x004688 +#define OV4689_REG_EXPOSURE 0x3500#define OV4689_EXPOSURE_MIN 4#define OV4689_EXPOSURE_STEP 1@@ -41,12 +41,12 @@#define OV4689_GAIN_STEP 1#define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_VTS 0x380e +#define OV4689_REG_TEST_PATTERN 0x5040#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0 -#define OV4689_REG_VTS 0x380e -#define REG_NULL 0xFFFF#define OV4689_REG_VALUE_08BIT 1
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 01/20] media: i2c: ov4689: Clean up and annotate the register table
In reply to Mikhail RudenkoHiMikhail,
Thank you for the patch.
Quoted 4 lines · Mikhail Rudenko
Many values in the register table are actually power-on defaults. Remove those and also unused HDR exposures and gains. Annotate the remaining values using the publicly available datasheet to facilitate further development. No functional change intended.
I'll trust you on that as I can't test the patch.
Quoted 162 lines
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 203 +++++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 85 deletions(-)drivers/media/i2c/ov4689.c +57
-85@@ -3,7 +3,7 @@* ov4689 driver * * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. -* Copyright (C) 2022 Mikhail Rudenko +* Copyright (C) 2022, 2023 Mikhail Rudenko */ #include <linux/clk.h> @@ -123,90 +123,123 @@ struct ov4689_gain_range {* mipi_datarate per lane 1008Mbps */ static const struct regval ov4689_2688x1520_regs[] = { - {0x0103 ,0x01 }, {0x3638 ,0x00 }, {0x0300 ,0x00 }, - {0x0302 ,0x2a }, {0x0303 ,0x00 }, {0x0304 ,0x03 }, - {0x030b ,0x00 }, {0x030d ,0x1e }, {0x030e ,0x04 }, - {0x030f ,0x01 }, {0x0312 ,0x01 }, {0x031e ,0x00 }, - {0x3000 ,0x20 }, {0x3002 ,0x00 }, {0x3018 ,0x72 }, - {0x3020 ,0x93 }, {0x3021 ,0x03 }, {0x3022 ,0x01 }, - {0x3031 ,0x0a }, {0x303f ,0x0c }, {0x3305 ,0xf1 }, - {0x3307 ,0x04 }, {0x3309 ,0x29 }, {0x3500 ,0x00 }, - {0x3501 ,0x60 }, {0x3502 ,0x00 }, {0x3503 ,0x04 }, - {0x3504 ,0x00 }, {0x3505 ,0x00 }, {0x3506 ,0x00 }, - {0x3507 ,0x00 }, {0x3508 ,0x00 }, {0x3509 ,0x80 }, - {0x350a ,0x00 }, {0x350b ,0x00 }, {0x350c ,0x00 }, - {0x350d ,0x00 }, {0x350e ,0x00 }, {0x350f ,0x80 }, - {0x3510 ,0x00 }, {0x3511 ,0x00 }, {0x3512 ,0x00 }, - {0x3513 ,0x00 }, {0x3514 ,0x00 }, {0x3515 ,0x80 }, - {0x3516 ,0x00 }, {0x3517 ,0x00 }, {0x3518 ,0x00 }, - {0x3519 ,0x00 }, {0x351a ,0x00 }, {0x351b ,0x80 }, - {0x351c ,0x00 }, {0x351d ,0x00 }, {0x351e ,0x00 }, - {0x351f ,0x00 }, {0x3520 ,0x00 }, {0x3521 ,0x80 }, - {0x3522 ,0x08 }, {0x3524 ,0x08 }, {0x3526 ,0x08 }, - {0x3528 ,0x08 }, {0x352a ,0x08 }, {0x3602 ,0x00 }, - {0x3603 ,0x40 }, {0x3604 ,0x02 }, {0x3605 ,0x00 }, - {0x3606 ,0x00 }, {0x3607 ,0x00 }, {0x3609 ,0x12 }, - {0x360a ,0x40 }, {0x360c ,0x08 }, {0x360f ,0xe5 }, - {0x3608 ,0x8f }, {0x3611 ,0x00 }, {0x3613 ,0xf7 }, - {0x3616 ,0x58 }, {0x3619 ,0x99 }, {0x361b ,0x60 }, - {0x361c ,0x7a }, {0x361e ,0x79 }, {0x361f ,0x02 }, - {0x3632 ,0x00 }, {0x3633 ,0x10 }, {0x3634 ,0x10 }, - {0x3635 ,0x10 }, {0x3636 ,0x15 }, {0x3646 ,0x86 }, - {0x364a ,0x0b }, {0x3700 ,0x17 }, {0x3701 ,0x22 }, - {0x3703 ,0x10 }, {0x370a ,0x37 }, {0x3705 ,0x00 }, - {0x3706 ,0x63 }, {0x3709 ,0x3c }, {0x370b ,0x01 }, - {0x370c ,0x30 }, {0x3710 ,0x24 }, {0x3711 ,0x0c }, - {0x3716 ,0x00 }, {0x3720 ,0x28 }, {0x3729 ,0x7b }, - {0x372a ,0x84 }, {0x372b ,0xbd }, {0x372c ,0xbc }, - {0x372e ,0x52 }, {0x373c ,0x0e }, {0x373e ,0x33 }, - {0x3743 ,0x10 }, {0x3744 ,0x88 }, {0x3745 ,0xc0 }, - {0x374a ,0x43 }, {0x374c ,0x00 }, {0x374e ,0x23 }, - {0x3751 ,0x7b }, {0x3752 ,0x84 }, {0x3753 ,0xbd }, - {0x3754 ,0xbc }, {0x3756 ,0x52 }, {0x375c ,0x00 }, - {0x3760 ,0x00 }, {0x3761 ,0x00 }, {0x3762 ,0x00 }, - {0x3763 ,0x00 }, {0x3764 ,0x00 }, {0x3767 ,0x04 }, - {0x3768 ,0x04 }, {0x3769 ,0x08 }, {0x376a ,0x08 }, - {0x376b ,0x20 }, {0x376c ,0x00 }, {0x376d ,0x00 }, - {0x376e ,0x00 }, {0x3773 ,0x00 }, {0x3774 ,0x51 }, - {0x3776 ,0xbd }, {0x3777 ,0xbd }, {0x3781 ,0x18 }, - {0x3783 ,0x25 }, {0x3798 ,0x1b }, {0x3800 ,0x00 }, - {0x3801 ,0x08 }, {0x3802 ,0x00 }, {0x3803 ,0x04 }, - {0x3804 ,0x0a }, {0x3805 ,0x97 }, {0x3806 ,0x05 }, - {0x3807 ,0xfb }, {0x3808 ,0x0a }, {0x3809 ,0x80 }, - {0x380a ,0x05 }, {0x380b ,0xf0 }, {0x380c ,0x0a }, - {0x380d ,0x0e }, {0x380e ,0x06 }, {0x380f ,0x12 }, - {0x3810 ,0x00 }, {0x3811 ,0x08 }, {0x3812 ,0x00 }, - {0x3813 ,0x04 }, {0x3814 ,0x01 }, {0x3815 ,0x01 }, - {0x3819 ,0x01 }, {0x3820 ,0x00 }, {0x3821 ,0x06 }, - {0x3829 ,0x00 }, {0x382a ,0x01 }, {0x382b ,0x01 }, - {0x382d ,0x7f }, {0x3830 ,0x04 }, {0x3836 ,0x01 }, - {0x3837 ,0x00 }, {0x3841 ,0x02 }, {0x3846 ,0x08 }, - {0x3847 ,0x07 }, {0x3d85 ,0x36 }, {0x3d8c ,0x71 }, - {0x3d8d ,0xcb }, {0x3f0a ,0x00 }, {0x4000 ,0xf1 }, - {0x4001 ,0x40 }, {0x4002 ,0x04 }, {0x4003 ,0x14 }, - {0x400e ,0x00 }, {0x4011 ,0x00 }, {0x401a ,0x00 }, - {0x401b ,0x00 }, {0x401c ,0x00 }, {0x401d ,0x00 }, - {0x401f ,0x00 }, {0x4020 ,0x00 }, {0x4021 ,0x10 }, - {0x4022 ,0x07 }, {0x4023 ,0xcf }, {0x4024 ,0x09 }, - {0x4025 ,0x60 }, {0x4026 ,0x09 }, {0x4027 ,0x6f }, - {0x4028 ,0x00 }, {0x4029 ,0x02 }, {0x402a ,0x06 }, - {0x402b ,0x04 }, {0x402c ,0x02 }, {0x402d ,0x02 }, - {0x402e ,0x0e }, {0x402f ,0x04 }, {0x4302 ,0xff }, - {0x4303 ,0xff }, {0x4304 ,0x00 }, {0x4305 ,0x00 }, - {0x4306 ,0x00 }, {0x4308 ,0x02 }, {0x4500 ,0x6c }, - {0x4501 ,0xc4 }, {0x4502 ,0x40 }, {0x4503 ,0x01 }, - {0x4601 ,0xa7 }, {0x4800 ,0x04 }, {0x4813 ,0x08 }, - {0x481f ,0x40 }, {0x4829 ,0x78 }, {0x4837 ,0x10 }, - {0x4b00 ,0x2a }, {0x4b0d ,0x00 }, {0x4d00 ,0x04 }, - {0x4d01 ,0x42 }, {0x4d02 ,0xd1 }, {0x4d03 ,0x93 }, - {0x4d04 ,0xf5 }, {0x4d05 ,0xc1 }, {0x5000 ,0xf3 }, - {0x5001 ,0x11 }, {0x5004 ,0x00 }, {0x500a ,0x00 }, - {0x500b ,0x00 }, {0x5032 ,0x00 }, {0x5040 ,0x00 }, - {0x5050 ,0x0c }, {0x5500 ,0x00 }, {0x5501 ,0x10 }, - {0x5502 ,0x01 }, {0x5503 ,0x0f }, {0x8000 ,0x00 }, - {0x8001 ,0x00 }, {0x8002 ,0x00 }, {0x8003 ,0x00 }, - {0x8004 ,0x00 }, {0x8005 ,0x00 }, {0x8006 ,0x00 }, - {0x8007 ,0x00 }, {0x8008 ,0x00 }, {0x3638 ,0x00 }, +/* System control*/ + {0x0103 ,0x01 },/* SC_CTRL0103 software_reset = 1 */ + {0x3000 ,0x20 },/* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ + {0x3021 ,0x03 },/* +* SC_CMMN_MISC_CTRL fst_stby_ctr = 0, +* sleep_no_latch_enable = 0 +*/ + +/* AEC PK */ + {0x3503 ,0x04 },/* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ + {0x352a ,0x08 },/* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ + +/* ADC and analog control*/ + {0x3603 ,0x40 }, + {0x3604 ,0x02 }, + {0x3609 ,0x12 }, + {0x360c ,0x08 }, + {0x360f ,0xe5 }, + {0x3608 ,0x8f }, + {0x3611 ,0x00 }, + {0x3613 ,0xf7 }, + {0x3616 ,0x58 }, + {0x3619 ,0x99 }, + {0x361b ,0x60 }, + {0x361e ,0x79 }, + {0x3634 ,0x10 }, + {0x3635 ,0x10 }, + {0x3636 ,0x15 }, + {0x3646 ,0x86 }, + {0x364a ,0x0b }, + +/* Sensor control */ + {0x3700 ,0x17 }, + {0x3701 ,0x22 }, + {0x3703 ,0x10 }, + {0x370a ,0x37 }, + {0x3706 ,0x63 }, + {0x3709 ,0x3c }, + {0x370c ,0x30 }, + {0x3710 ,0x24 }, + {0x3720 ,0x28 }, + {0x3729 ,0x7b }, + {0x372b ,0xbd }, + {0x372c ,0xbc }, + {0x372e ,0x52 }, + {0x373c ,0x0e }, + {0x373e ,0x33 }, + {0x3743 ,0x10 }, + {0x3744 ,0x88 }, + {0x3745 ,0xc0 }, + {0x374c ,0x00 }, + {0x374e ,0x23 }, + {0x3751 ,0x7b }, + {0x3753 ,0xbd }, + {0x3754 ,0xbc }, + {0x3756 ,0x52 },
drivers/media/i2c/ov4689.c struct ov4689_gain_range { · line 191
Quoted 10 lines
drivers/media/i2c/ov4689.c +10
-0+ {0x376b, 0x20}, + {0x3774, 0x51}, + {0x3776, 0xbd}, + {0x3777, 0xbd}, + {0x3781, 0x18}, + {0x3783, 0x25}, + {0x3798, 0x1b}, + +/* Timing control */ + {0x3801, 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */
It would be nice to define register macros for the known registers. This can be done in a separate patch.
Quoted 54 lines
drivers/media/i2c/ov4689.c +51
-0+ {0x3805, 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ + {0x380c, 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ + {0x380d, 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ + {0x3811, 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ + {0x3813, 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ + {0x3819, 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ + {0x3821, 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ + +/* OTP control */ + {0x3d85, 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, +* OTP_power_up_load_data_enable = 1, +* OTP_bist_select = 1 (compare with zero) +*/ + {0x3d8c, 0x71}, /* OTP_SETTING_STT_ADDRESS_H */ + {0x3d8d, 0xcb}, /* OTP_SETTING_STT_ADDRESS_L */ + +/* BLC registers*/ + {0x4001, 0x40}, /* DEBUG_MODE */ + {0x401b, 0x00}, /* DEBUG_MODE */ + {0x401d, 0x00}, /* DEBUG_MODE */ + {0x401f, 0x00}, /* DEBUG_MODE */ + {0x4020, 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ + {0x4021, 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ + {0x4022, 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ + {0x4023, 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ + {0x4024, 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ + {0x4025, 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ + {0x4026, 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ + {0x4027, 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ + +/* ADC sync control */ + {0x4500, 0x6c}, /* ADC_SYNC_CTRL */ + {0x4503, 0x01}, /* ADC_SYNC_CTRL */ + +/* VFIFO */ + {0x4601, 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ + +/* Temperature monitor */ + {0x4d00, 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ + {0x4d01, 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ + {0x4d02, 0xd1}, /* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ + {0x4d03, 0x93}, /* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ + {0x4d04, 0xf5}, /* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ + {0x4d05, 0xc1}, /* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ + +/* pre-ISP control */ + {0x5050, 0x0c}, /* DEBUG_MODE */ + +/* OTP-DPC control */ + {0x5501, 0x10}, /* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ + {0x5503, 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ {REG_NULL, 0x00}, };
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 07/20] media: i2c: ov4689: Use sub-device active state
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 143 lines · Mikhail Rudenko
Use sub-device active state. Employ control handler lock to synchronize access to the active state and
s_stream.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 75 ++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 43 deletions(-)drivers/media/i2c/ov4689.c +19
-36@@ -86,7 +86,6 @@ struct ov4689 {u32 clock_rate; -struct mutex mutex;/* lock to protect ctrls and cur_mode */ struct v4l2_ctrl_handler ctrl_handler;struct v4l2_ctrl *exposure;@@ -319,19 +318,6 @@ static int ov4689_set_fmt(struct v4l2_subdev *sd,return 0 ; } -static int ov4689_get_fmt (struct v4l2_subdev *sd, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) -{ -struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; -struct ov4689 *ov4689 =to_ov4689 (sd); - -/* only one mode supported for now */ -ov4689_fill_fmt (ov4689->cur_mode, mbus_fmt); - -return 0 ; -} -static int ov4689_enum_mbus_code (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)@@ -405,10 +391,11 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd); +struct v4l2_subdev_state *sd_state;struct device *dev = ov4689->dev;int ret =0 ; -mutex_lock (&ov4689->mutex); + sd_state =v4l2_subdev_lock_and_get_active_state (&ov4689->subdev);if (on) { ret =pm_runtime_resume_and_get (dev);@@ -443,7 +430,7 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) } unlock_and_return: -mutex_unlock (&ov4689->mutex); +v4l2_subdev_unlock_state (sd_state);return ret; }@@ -506,18 +493,13 @@ static int __maybe_unused ov4689_power_off(struct device *dev)return 0 ; } -static int ov4689_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +static int ov4689_init_state (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state) { -struct ov4689 *ov4689 =to_ov4689 (sd); -struct v4l2_mbus_framefmt *try_fmt; - -mutex_lock (&ov4689->mutex); - - try_fmt =v4l2_subdev_state_get_format (fh->state,0 ); -/* Initialize try_fmt */ -ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], try_fmt); +struct v4l2_mbus_framefmt *fmt = +v4l2_subdev_state_get_format (sd_state,0 ); -mutex_unlock (&ov4689->mutex); +ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], fmt);return 0 ; }@@ -526,10 +508,6 @@ static const struct dev_pm_ops ov4689_pm_ops = { SET_RUNTIME_PM_OPS(ov4689_power_off, ov4689_power_on, NULL) }; -static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { - .open = ov4689_open, -}; -static const struct v4l2_subdev_video_ops ov4689_video_ops = { .s_stream = ov4689_s_stream, };@@ -537,11 +515,15 @@ static const struct v4l2_subdev_video_ops ov4689_video_ops = {static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { .enum_mbus_code = ov4689_enum_mbus_code, .enum_frame_size = ov4689_enum_frame_sizes, - .get_fmt = ov4689_get_fmt, + .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov4689_set_fmt, .get_selection = ov4689_get_selection, }; +static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { + .init_state = ov4689_init_state, +}; +static const struct v4l2_subdev_ops ov4689_subdev_ops = { .video = &ov4689_video_ops, .pad = &ov4689_pad_ops,@@ -648,7 +630,6 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ret =v4l2_ctrl_handler_init (handler,10 );if (ret)return ret; - handler->lock = &ov4689->mutex; ctrl =v4l2_ctrl_new_int_menu (handler,NULL ,V4L2_CID_LINK_FREQ ,0 ,0 , link_freq_menu_items);@@ -861,13 +842,15 @@ static int ov4689_probe(struct i2c_client *client)return dev_err_probe (dev, ret,"Failed to get power regulators\n" ); -mutex_init (&ov4689->mutex); - sd = &ov4689->subdev;v4l2_i2c_subdev_init (sd, client, &ov4689_subdev_ops); + sd->internal_ops = &ov4689_internal_ops; + ret =ov4689_initialize_controls (ov4689); -if (ret) - goto err_destroy_mutex; +if (ret) { +dev_err (dev,"Failed to initialize controls\n" ); +return ret; + } ret =ov4689_power_on (dev);if (ret)
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 863
Quoted 5 lines
drivers/media/i2c/ov4689.c +0
-1@@ -877,19 +860,26 @@ static int ov4689_probe(struct i2c_client *client)if (ret) goto err_power_off; - sd->internal_ops = &ov4689_internal_ops; sd->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;
I would move this line above, just before calling ov4689_initialize_controls(), to group all subdev initialization code.
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 873
Quoted 11 lines
drivers/media/i2c/ov4689.c +4
-1+ sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ov4689->pad.flags =MEDIA_PAD_FL_SOURCE ; - sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ret =media_entity_pads_init (&sd->entity,1 , &ov4689->pad);if (ret <0 ) goto err_power_off; + sd->state_lock = ov4689->ctrl_handler.lock; + ret =v4l2_subdev_init_finalize (sd); +
No need for a blank line.
With these small changes,
Quoted 41 lines
drivers/media/i2c/ov4689.c +9
-5+if (ret) { +dev_err (dev,"Could not register v4l2 device\n" ); + goto err_clean_entity; + } + ret =v4l2_async_register_subdev_sensor (sd);if (ret) {dev_err (dev,"v4l2 async register subdev failed\n" ); - goto err_clean_entity; + goto err_clean_subdev; }pm_runtime_set_active (dev);@@ -898,14 +888,14 @@ static int ov4689_probe(struct i2c_client *client)return 0 ; +err_clean_subdev: +v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity); err_power_off:ov4689_power_off (dev); err_free_handler:v4l2_ctrl_handler_free (&ov4689->ctrl_handler); -err_destroy_mutex: -mutex_destroy (&ov4689->mutex);return ret; }@@ -917,9 +907,8 @@ static void ov4689_remove(struct i2c_client *client)v4l2_async_unregister_subdev (sd);media_entity_cleanup (&sd->entity); - +v4l2_subdev_cleanup (sd);v4l2_ctrl_handler_free (&ov4689->ctrl_handler); -mutex_destroy (&ov4689->mutex);pm_runtime_disable (&client->dev);if (!pm_runtime_status_suspended (&client->dev))
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 08/20] media: i2c: ov4689: Enable runtime PM before registering sub-device
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 4 lines · Mikhail Rudenko
As the sensor may be accessible right after its async sub-device is registered, enable runtime PM before doing so.
Signed-off-by Mikhail Rudenko <[email protected]>
Quoted 36 lines
--- drivers/media/i2c/ov4689.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/media/i2c/ov4689.c +8
-6@@ -876,19 +876,21 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_entity; } +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_idle (dev); + ret =v4l2_async_register_subdev_sensor (sd);if (ret) {dev_err (dev,"v4l2 async register subdev failed\n" ); - goto err_clean_subdev; + goto err_clean_subdev_pm; } -pm_runtime_set_active (dev); -pm_runtime_enable (dev); -pm_runtime_idle (dev); -return 0 ; -err_clean_subdev: +err_clean_subdev_pm: +pm_runtime_disable (dev); +pm_runtime_set_suspended (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 13/20] media: i2c: ov4689: Implement digital gain control
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 5 lines · Mikhail Rudenko
The OV4689 sensor supports digital gain up to 16x. Implement corresponding control in the driver. Default digital gain value is not modified by this patch.
Signed-off-by Mikhail Rudenko <[email protected]>
Quoted 59 lines
--- drivers/media/i2c/ov4689.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)drivers/media/i2c/ov4689.c +14
-2@@ -35,6 +35,12 @@#define OV4689_GAIN_STEP 1#define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_DIG_GAIN CCI_REG16(0x352a) +#define OV4689_DIG_GAIN_MIN 1 +#define OV4689_DIG_GAIN_MAX 0x7fff +#define OV4689_DIG_GAIN_STEP 1 +#define OV4689_DIG_GAIN_DEFAULT 0x800 +#define OV4689_REG_HTS CCI_REG16(0x380c)#define OV4689_HTS_DIVIDER 4#define OV4689_HTS_MAX 0x7fff@@ -131,7 +137,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = {/* AEC PK */ {CCI_REG8(0x3503), 0x04}, /* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ - {CCI_REG8(0x352a), 0x08}, /* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) *//* ADC and analog control*/ {CCI_REG8(0x3603), 0x40},@@ -624,6 +629,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)OV4689_TIMING_FLIP_MASK , ctrl->val ? 0 : OV4689_TIMING_FLIP_BOTH, &ret);break ; +case V4L2_CID_DIGITAL_GAIN : +cci_write (regmap,OV4689_REG_DIG_GAIN , ctrl->val, &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);@@ -654,7 +662,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,12 ); + ret =v4l2_ctrl_handler_init (handler,13 );if (ret)return ret;@@ -697,6 +705,10 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 );v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +OV4689_DIG_GAIN_MIN ,OV4689_DIG_GAIN_MAX , +OV4689_DIG_GAIN_STEP ,OV4689_DIG_GAIN_DEFAULT ); +if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 14/20] media: i2c: ov4689: Implement manual color balance controls
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 5 lines · Mikhail Rudenko
The OV4689 sensor has separate red and blue gain settings (up to 4x). Implement appropriate controls in the driver. Default gain values are not modified.
Signed-off-by Mikhail Rudenko <[email protected]>
Quoted 59 lines
--- drivers/media/i2c/ov4689.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/media/i2c/ov4689.c +22
-1@@ -56,6 +56,13 @@#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_WB_GAIN_RED CCI_REG16(0x500c) +#define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010) +#define OV4689_WB_GAIN_MIN 1 +#define OV4689_WB_GAIN_MAX 0xfff +#define OV4689_WB_GAIN_STEP 1 +#define OV4689_WB_GAIN_DEFAULT 0x400 +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0@@ -632,6 +639,12 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)case V4L2_CID_DIGITAL_GAIN :cci_write (regmap,OV4689_REG_DIG_GAIN , ctrl->val, &ret);break ; +case V4L2_CID_RED_BALANCE : +cci_write (regmap,OV4689_REG_WB_GAIN_RED , ctrl->val, &ret); +break ; +case V4L2_CID_BLUE_BALANCE : +cci_write (regmap,OV4689_REG_WB_GAIN_BLUE , ctrl->val, &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);@@ -662,7 +675,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,13 ); + ret =v4l2_ctrl_handler_init (handler,15 );if (ret)return ret;@@ -709,6 +722,14 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)OV4689_DIG_GAIN_MIN ,OV4689_DIG_GAIN_MAX , OV4689_DIG_GAIN_STEP, OV4689_DIG_GAIN_DEFAULT); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_RED_BALANCE , +OV4689_WB_GAIN_MIN ,OV4689_WB_GAIN_MAX , +OV4689_WB_GAIN_STEP ,OV4689_WB_GAIN_DEFAULT ); + +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_BLUE_BALANCE , +OV4689_WB_GAIN_MIN ,OV4689_WB_GAIN_MAX , +OV4689_WB_GAIN_STEP ,OV4689_WB_GAIN_DEFAULT ); +if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 15/20] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 14 lines · Mikhail Rudenko
Pixel array dimensions and default crop size do not belong to the
ov4689_modestructure, since they are mode independent. Make them defines instead.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)drivers/media/i2c/ov4689.c +0
-0
drivers/media/i2c/ov4689.c line 76
Quoted 7 lines
drivers/media/i2c/ov4689.c +4
-0@@ -70,6 +70,11 @@#define OV4689_LANES 4#define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_ARRAY_WIDTH 2720 +#define OV4689_PIXEL_ARRAY_HEIGHT 1536 +#define OV4689_DUMMY_ROWS 8 +#define OV4689_DUMMY_COLUMNS 16
Adding a comment here to indicate that there are dummy columns in each side would be useful:
#define OV4689_DUMMY_ROWS 8 /* 8 dummy rows on each side */
#define OV4689_DUMMY_COLUMNS 16 /* 16 dummy columns on each side */
Quoted 59 lines
drivers/media/i2c/ov4689.c +9
-16+static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */ "dovdd" ,/* Digital I/O power */ @@ -90,10 +95,6 @@ struct ov4689_mode {u32 vts_def;u32 exp_def;u32 pixel_rate; -u32 sensor_width; -u32 sensor_height; -u32 crop_top; -u32 crop_left;const struct cci_reg_sequence *reg_list;unsigned int num_regs; };@@ -254,10 +255,6 @@ static const struct ov4689_mode supported_modes[] = { .id = OV4689_MODE_2688_1520, .width = 2688, .height = 1520, - .sensor_width = 2720, - .sensor_height = 1536, - .crop_top = 8, - .crop_left = 16, .exp_def = 1536, .hts_def = 10296, .hts_min = 3432,@@ -385,8 +382,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; -if (sel->which !=V4L2_SUBDEV_FORMAT_ACTIVE )return -EINVAL ;@@ -394,15 +389,17 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,case V4L2_SEL_TGT_CROP_BOUNDS : sel->r.top =0 ; sel->r.left =0 ; - sel->r.width = mode->sensor_width; - sel->r.height = mode->sensor_height; + sel->r.width =OV4689_PIXEL_ARRAY_WIDTH ; + sel->r.height =OV4689_PIXEL_ARRAY_HEIGHT ;return 0 ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_CROP_DEFAULT : - sel->r.top = mode->crop_top; - sel->r.left = mode->crop_left; - sel->r.width = mode->width; - sel->r.height = mode->height; + sel->r.top =OV4689_DUMMY_ROWS ; + sel->r.left =OV4689_DUMMY_COLUMNS ; + sel->r.width = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_COLUMNS ; + sel->r.height = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_ROWS ;return 0 ; }
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 15/20] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode
Quoted 83 lines · Laurent Pinchart
Hi Mikhail,
Thank you for the patch.
Quoted 14 lines · Mikhail Rudenko
Pixel array dimensions and default crop size do not belong to the
ov4689_modestructure, since they are mode independent. Make them defines instead.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)drivers/media/i2c/ov4689.c +0
-0drivers/media/i2c/ov4689.c line 76
Quoted 7 lines
drivers/media/i2c/ov4689.c +4
-0@@ -70,6 +70,11 @@#define OV4689_LANES 4#define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_ARRAY_WIDTH 2720 +#define OV4689_PIXEL_ARRAY_HEIGHT 1536 +#define OV4689_DUMMY_ROWS 8 +#define OV4689_DUMMY_COLUMNS 16Adding a comment here to indicate that there are dummy columns in each side would be useful:
#define
OV4689_DUMMY_ROWS8 /* 8 dummy rows on each side */
#defineOV4689_DUMMY_COLUMNS16 /* 16 dummy columns on each side */Reviewed-by Laurent Pinchart <[email protected]>Quoted 48 lines
drivers/media/i2c/ov4689.c +3
-14+static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */ "dovdd" ,/* Digital I/O power */ @@ -90,10 +95,6 @@ struct ov4689_mode {u32 vts_def;u32 exp_def;u32 pixel_rate; -u32 sensor_width; -u32 sensor_height; -u32 crop_top; -u32 crop_left;const struct cci_reg_sequence *reg_list;unsigned int num_regs; };@@ -254,10 +255,6 @@ static const struct ov4689_mode supported_modes[] = { .id = OV4689_MODE_2688_1520, .width = 2688, .height = 1520, - .sensor_width = 2720, - .sensor_height = 1536, - .crop_top = 8, - .crop_left = 16, .exp_def = 1536, .hts_def = 10296, .hts_min = 3432,@@ -385,8 +382,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; -if (sel->which !=V4L2_SUBDEV_FORMAT_ACTIVE )return -EINVAL ;@@ -394,15 +389,17 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,case V4L2_SEL_TGT_CROP_BOUNDS : sel->r.top =0 ; sel->r.left =0 ; - sel->r.width = mode->sensor_width; - sel->r.height = mode->sensor_height; + sel->r.width =OV4689_PIXEL_ARRAY_WIDTH ; + sel->r.height =OV4689_PIXEL_ARRAY_HEIGHT ;return 0 ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_CROP_DEFAULT : - sel->r.top = mode->crop_top; - sel->r.left = mode->crop_left;
Quoted 8 lines
drivers/media/i2c/ov4689.c static int ov4689_get_selection(struct v4l2_subdev *sd, · line 402
Quoted 8 lines
drivers/media/i2c/ov4689.c +6
-2- sel->r.width = mode->width; - sel->r.height = mode->height; + sel->r.top =OV4689_DUMMY_ROWS ; + sel->r.left =OV4689_DUMMY_COLUMNS ; + sel->r.width = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_COLUMNS ; + sel->r.height = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_ROWS ;
I spoke too fast: this should be OV4689_PIXEL_ARRAY_HEIGHT, not OV4689_PIXEL_ARRAY_WIDTH.
Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ov4689.c +0
-0return 0 ; }
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 16/20] media: i2c: ov4689: Set timing registers programmatically
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 94 lines · Mikhail Rudenko
Set timing-related and BLC anchor registers via cci calls instead of hardcoding them in the register table. This prepares the driver for implementation of configurable analogue crop and binning. No functional change intended.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 83 +++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 15 deletions(-)drivers/media/i2c/ov4689.c +21
-15@@ -41,6 +41,13 @@#define OV4689_DIG_GAIN_STEP 1#define OV4689_DIG_GAIN_DEFAULT 0x800 +#define OV4689_REG_H_CROP_START CCI_REG16(0x3800) +#define OV4689_REG_V_CROP_START CCI_REG16(0x3802) +#define OV4689_REG_H_CROP_END CCI_REG16(0x3804) +#define OV4689_REG_V_CROP_END CCI_REG16(0x3806) +#define OV4689_REG_H_OUTPUT_SIZE CCI_REG16(0x3808) +#define OV4689_REG_V_OUTPUT_SIZE CCI_REG16(0x380a) +#define OV4689_REG_HTS CCI_REG16(0x380c)#define OV4689_HTS_DIVIDER 4#define OV4689_HTS_MAX 0x7fff@@ -48,6 +55,9 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810) +#define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820)#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821)#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1)@@ -56,6 +66,17 @@#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_ANCHOR_LEFT_START CCI_REG16(0x4020) +#define OV4689_ANCHOR_LEFT_START_DEF 576 +#define OV4689_REG_ANCHOR_LEFT_END CCI_REG16(0x4022) +#define OV4689_ANCHOR_LEFT_END_DEF 831 +#define OV4689_REG_ANCHOR_RIGHT_START CCI_REG16(0x4024) +#define OV4689_ANCHOR_RIGHT_START_DEF 1984 +#define OV4689_REG_ANCHOR_RIGHT_END CCI_REG16(0x4026) +#define OV4689_ANCHOR_RIGHT_END_DEF 2239 + +#define OV4689_REG_VFIFO_CTRL_01 CCI_REG8(0x4601) +#define OV4689_REG_WB_GAIN_RED CCI_REG16(0x500c)#define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010)#define OV4689_WB_GAIN_MIN 1@@ -199,10 +220,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3798), 0x1b},/* Timing control */ - {CCI_REG8(0x3801), 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ - {CCI_REG8(0x3805), 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ - {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ - {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 *//* OTP control */ @@ -218,22 +235,11 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x401b), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401d), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401f), 0x00}, /* DEBUG_MODE */ - {CCI_REG8(0x4020), 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ - {CCI_REG8(0x4021), 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ - {CCI_REG8(0x4022), 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ - {CCI_REG8(0x4023), 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ - {CCI_REG8(0x4024), 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ - {CCI_REG8(0x4025), 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ - {CCI_REG8(0x4026), 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ - {CCI_REG8(0x4027), 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f *//* ADC sync control */ {CCI_REG8(0x4500), 0x6c}, /* ADC_SYNC_CTRL */ {CCI_REG8(0x4503), 0x01}, /* ADC_SYNC_CTRL */ -/* VFIFO */ - {CCI_REG8(0x4601), 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ -/* Temperature monitor */ {CCI_REG8(0x4d00), 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ {CCI_REG8(0x4d01), 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */@@ -406,6 +412,41 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,return -EINVAL ; }
drivers/media/i2c/ov4689.c static int ov4689_get_selection(struct v4l2_subdev *sd, · line 424
Quoted 10 lines
drivers/media/i2c/ov4689.c +10
-0+static int ov4689_setup_timings (struct ov4689 *ov4689) +{ +const struct ov4689_mode *mode = ov4689->cur_mode; +struct regmap *rm = ov4689->regmap; +int ret =0 ; + +cci_write (rm,OV4689_REG_H_CROP_START ,8 , &ret); +cci_write (rm,OV4689_REG_V_CROP_START ,8 , &ret); +cci_write (rm,OV4689_REG_H_CROP_END ,2711 , &ret); +cci_write (rm,OV4689_REG_V_CROP_END ,1531 , &ret);
This is interesting. The previous patch defines
#define OV4689_PIXEL_ARRAY_WIDTH 2720
#define OV4689_PIXEL_ARRAY_HEIGHT 1536
#define OV4689_DUMMY_ROWS 8
#define OV4689_DUMMY_COLUMNS 16
and the (only) mode has
.width = 2688, .height = 1520,
The above register values should result in an analog crop rectangle size of 2704x1524. Then, the digital crop is configured below to (8,4)/2688x1520. The combined crop rectangle, relative to the pixel array, is thus (16,12)/2688x1520. This centers the crop rectangle horizontally but not vertically. I wonder why, and I also wonder why there's a need to apply both analog crop and digital crop, instead of setting
OV4689_REG_H_CROP_START = 16 OV4689_REG_V_CROP_START = 8 OV4689_REG_H_CROP_END = 2703 OV4689_REG_V_CROP_END = 1527 OV4689_REG_H_WIN_OFF = 0 OV4689_REG_V_WIN_OFF = 0 OV4689_REG_H_OUTPUT_SIZE = 2688 OV4689_REG_V_OUTPUT_SIZE = 1520
Anyway, this is not an issue introduced by this patch, so
Quoted 47 lines
drivers/media/i2c/ov4689.c +37
-0+ +cci_write (rm,OV4689_REG_H_OUTPUT_SIZE , mode->width, &ret); +cci_write (rm,OV4689_REG_V_OUTPUT_SIZE , mode->height, &ret); + +cci_write (rm,OV4689_REG_H_WIN_OFF ,8 , &ret); +cci_write (rm,OV4689_REG_V_WIN_OFF ,4 , &ret); + +cci_write (rm,OV4689_REG_VFIFO_CTRL_01 ,167 , &ret); + +return ret; +} + +static int ov4689_setup_blc_anchors (struct ov4689 *ov4689) +{ +struct regmap *rm = ov4689->regmap; +int ret =0 ; + +cci_write (rm,OV4689_REG_ANCHOR_LEFT_START ,16 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_LEFT_END ,1999 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_START ,2400 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_END ,2415 , &ret); + +return ret; +} +static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd);@@ -429,6 +470,18 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; } + ret =ov4689_setup_timings (ov4689); +if (ret) { +pm_runtime_put (dev); + goto unlock_and_return; + } + + ret =ov4689_setup_blc_anchors (ov4689); +if (ret) { +pm_runtime_put (dev); + goto unlock_and_return; + } + ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) {pm_runtime_put_sync (dev);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH v2 19/20] media: i2c: ov4689: Refactor ov4689_s_stream
In reply to Mikhail RudenkoHi Mikhail,
Thank you for the patch.
Quoted 42 lines · Mikhail Rudenko
Remove repetitive
pm_runtime_putcalls inov4689_s_streamfunction, and callpm_runtime_putonce at the end of the "on" branch if any error occurred.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-)drivers/media/i2c/ov4689.c +6
-13@@ -555,35 +555,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689_common_regs,ARRAY_SIZE (ov4689_common_regs), NULL); -if (ret) { -pm_runtime_put_sync (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =ov4689_setup_timings (ov4689, sd_state); -if (ret) { -pm_runtime_put (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =ov4689_setup_blc_anchors (ov4689, sd_state); -if (ret) { -pm_runtime_put (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler); -if (ret) {
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 575
Quoted 10 lines
drivers/media/i2c/ov4689.c +3
-4-pm_runtime_put_sync (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL ); -if (ret) { +cleanup_pm:
A label within an if branch isn't great, readability-wise :-S Could we maybe split the ov4687_s_stream() function in two (streamon and streamoff, or similar names) ? You would then have a single pm_runtime_put_sync() call in ov4689_s_stream(), in the error handling path for the streamon function call.
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-2+if (ret)pm_runtime_put_sync (dev); - goto unlock_and_return; - } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL );
Signature · 3 lines
Regards, Laurent Pinchart
Mikhail Rudenko
maintainerRe: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
In reply to Sakari AilusHi Sakari,
and thanks for the review!
Quoted 34 lines · Sakari Ailus
Hi Mikhail,
Quoted 31 lines · Mikhail Rudenko
Hi Sakari,
Thanks for the review!
Quoted 24 lines · Sakari Ailus
Hi Mikhail,
Quoted 13 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)drivers/media/i2c/ov4689.c +0
-0drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 5 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);Why are you switching to
pm_runtime_put_sync()here? That isn't covered by the commit message (nor I think should be done).
Quoted 7 lines
Quoted 4 lines
PM autosuspend conversion was suggested earlier by Laurent in his review of this series [1], and he adviced looking at how it was done for the imx290 driver. I followed along the lines of the corresponding patch [2].
There's no need to use the
_sync()variant here. And at least it wouldn't be related to autosuspend, were you to switch to that.
Ok, will use pm_runtime_put in v3. Or do you suggest dropping this patch altogether? Laurent?
Quoted 65 lines
Quoted 65 lines
Quoted 31 lines
Quoted 31 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; }Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 430
Quoted 3 lines
drivers/media/i2c/ov4689.c +2
-1-pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);Also note that with runtime PM autosuspend, you have to use
pm_runtime_get_if_active()instead ofpm_runtime_get_if_in_use().Noted, will do so in v3.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/ov4689.c +7
-1+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ;
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 904
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-1err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 12/20] media: i2c: ov4689: Implement vflip/hflip controls
In reply to Sakari AilusHi Sakari,
and thanks for the review!
Quoted 67 lines · Sakari Ailus
Hi Mikhail,
Quoted 64 lines · Mikhail Rudenko
The OV4689 sensor supports horizontal and vertical flipping. Add appropriate controls to the driver. Toggling both array flip and digital flip bits allows to achieve flipping while maintaining output Bayer order. Note that the default value of hflip control corresponds to both bits set, as it was before this patch.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/media/i2c/ov4689.c +19
-2@@ -42,6 +42,14 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) +#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) +#define OV4689_TIMING_FLIP_ARRAY BIT(1) +#define OV4689_TIMING_FLIP_DIGITAL BIT(2) +#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ + OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0@@ -183,7 +191,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ - {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 *//* OTP control */ {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1,@@ -607,6 +614,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) (ctrl->val + ov4689->cur_mode->width) / OV4689_HTS_DIVIDER, &ret);break ; +case V4L2_CID_VFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT1 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?OV4689_TIMING_FLIP_BOTH :0 , &ret); +break ; +case V4L2_CID_HFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT2 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?0 :OV4689_TIMING_FLIP_BOTH , &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);@@ -637,7 +654,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,10 ); + ret =v4l2_ctrl_handler_init (handler,12 );if (ret)return ret;
Quoted 8 lines
drivers/media/i2c/ov4689.c static int ov4689_initialize_controls(struct ov4689 *ov4689) · line 698
Quoted 6 lines
drivers/media/i2c/ov4689.c +2
-0@@ -677,6 +694,9 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)ARRAY_SIZE (ov4689_test_pattern_menu) -1 , 0, 0, ov4689_test_pattern_menu); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 );Could you take the default value from the mounting rotation?
Could you provide an example (maybe a link to an existing driver) which does this right? If I understand you correctly, I should flip default for both flip controls for 180 degree rotation. But what should I do for 90, 270 and all the rest rotation values?
Quoted 2 lines
The default should be upside-up, but this is an existing driver and changing the flipping now could affect existing users.
Do you mean default rotation value when missing device tree property?
Quoted 9 lines
Quoted 4 lines
drivers/media/i2c/ov4689.c +1
-0+if (handler->error) { ret = handler->error;dev_err (ov4689->dev,"Failed to init controls(%d)\n" , ret);
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerHi Sakari,
Quoted 34 lines · Sakari Ailus
Quoted 33 lines · Sakari Ailus
Hi Mikhail,
Quoted 29 lines · Mikhail Rudenko
Hi,
Quoted 12 lines · Mikhail Rudenko
Hi,
This series contains refactoring and new features implementation for the Omnivision OV4689 sensor driver. Specifically, patches 1, 2, 3, 5, 6, 10, 15, 16, 18, and 19 are refactorings, and are not supposed to introduce any functional change. Patches 4 and 7 perform migration to CCI helpers and subdevice active state respectively, and should not introduce any hardware- and/or user-visible change either. Patch 8 fixes a possible race condition due to
v4l2_async_register_subdev_sensorbeing called too early inov4689_probe, and patch 9 migrates power management to PM autosuspend.Quoted 7 lines
Patches 11-14 expose more sensor controls to the userspace, such as (read-write) HBLANK, VFLIP/HFLIP, digital gain, and color balance. Patch 17 implements configurable analogue crop rectangle via .set_selection callback. And finally, patch 20 enables 2x2 binning option. It should be noted that publicly available sensor documentation is lacking description of many registers and their value ranges, so a lot of values had to be found by experimentation.
Gentle ping on this series. Anything I can do to help getting it reviewed and merged? Maybe split patches 15-20 which implement cropping and binning and change the driver away from register list based model into a separate series? Anyone?
Quoted 4 lines
Quoted 2 lines
Oops, my bad. I'll review these shortly. I can already tell there's not much to do though.
Done.
Thanks for the prompt review! I'll wait a few days to collect more comments (especially on patches 17, 18, 20) and then post v3.
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 07/20] media: i2c: ov4689: Use sub-device active state
In reply to Laurent PinchartHi Laurent,
and thanks for the review!
Quoted 151 lines · Laurent Pinchart
Hi Mikhail,
Thank you for the patch.
Quoted 146 lines · Mikhail Rudenko
Use sub-device active state. Employ control handler lock to synchronize access to the active state and
s_stream.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 75 ++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 43 deletions(-)drivers/media/i2c/ov4689.c +19
-36@@ -86,7 +86,6 @@ struct ov4689 {u32 clock_rate; -struct mutex mutex;/* lock to protect ctrls and cur_mode */ struct v4l2_ctrl_handler ctrl_handler;struct v4l2_ctrl *exposure;@@ -319,19 +318,6 @@ static int ov4689_set_fmt(struct v4l2_subdev *sd,return 0 ; } -static int ov4689_get_fmt (struct v4l2_subdev *sd, -struct v4l2_subdev_state *sd_state, -struct v4l2_subdev_format *fmt) -{ -struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; -struct ov4689 *ov4689 =to_ov4689 (sd); - -/* only one mode supported for now */ -ov4689_fill_fmt (ov4689->cur_mode, mbus_fmt); - -return 0 ; -} -static int ov4689_enum_mbus_code (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)@@ -405,10 +391,11 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd); +struct v4l2_subdev_state *sd_state;struct device *dev = ov4689->dev;int ret =0 ; -mutex_lock (&ov4689->mutex); + sd_state =v4l2_subdev_lock_and_get_active_state (&ov4689->subdev);if (on) { ret =pm_runtime_resume_and_get (dev);@@ -443,7 +430,7 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) } unlock_and_return: -mutex_unlock (&ov4689->mutex); +v4l2_subdev_unlock_state (sd_state);return ret; }@@ -506,18 +493,13 @@ static int __maybe_unused ov4689_power_off(struct device *dev)return 0 ; } -static int ov4689_open (struct v4l2_subdev *sd,struct v4l2_subdev_fh *fh) +static int ov4689_init_state (struct v4l2_subdev *sd, +struct v4l2_subdev_state *sd_state) { -struct ov4689 *ov4689 =to_ov4689 (sd); -struct v4l2_mbus_framefmt *try_fmt; - -mutex_lock (&ov4689->mutex); - - try_fmt =v4l2_subdev_state_get_format (fh->state,0 ); -/* Initialize try_fmt */ -ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], try_fmt); +struct v4l2_mbus_framefmt *fmt = +v4l2_subdev_state_get_format (sd_state,0 ); -mutex_unlock (&ov4689->mutex); +ov4689_fill_fmt (&supported_modes[OV4689_MODE_2688_1520 ], fmt);return 0 ; }@@ -526,10 +508,6 @@ static const struct dev_pm_ops ov4689_pm_ops = { SET_RUNTIME_PM_OPS(ov4689_power_off, ov4689_power_on, NULL) }; -static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { - .open = ov4689_open, -}; -static const struct v4l2_subdev_video_ops ov4689_video_ops = { .s_stream = ov4689_s_stream, };@@ -537,11 +515,15 @@ static const struct v4l2_subdev_video_ops ov4689_video_ops = {static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { .enum_mbus_code = ov4689_enum_mbus_code, .enum_frame_size = ov4689_enum_frame_sizes, - .get_fmt = ov4689_get_fmt, + .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov4689_set_fmt, .get_selection = ov4689_get_selection, }; +static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { + .init_state = ov4689_init_state, +}; +static const struct v4l2_subdev_ops ov4689_subdev_ops = { .video = &ov4689_video_ops, .pad = &ov4689_pad_ops,@@ -648,7 +630,6 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ret =v4l2_ctrl_handler_init (handler,10 );if (ret)return ret; - handler->lock = &ov4689->mutex; ctrl =v4l2_ctrl_new_int_menu (handler,NULL ,V4L2_CID_LINK_FREQ ,0 ,0 , link_freq_menu_items);@@ -861,13 +842,15 @@ static int ov4689_probe(struct i2c_client *client)return dev_err_probe (dev, ret,"Failed to get power regulators\n" ); -mutex_init (&ov4689->mutex); - sd = &ov4689->subdev;v4l2_i2c_subdev_init (sd, client, &ov4689_subdev_ops); + sd->internal_ops = &ov4689_internal_ops; + ret =ov4689_initialize_controls (ov4689); -if (ret) - goto err_destroy_mutex; +if (ret) { +dev_err (dev,"Failed to initialize controls\n" ); +return ret; + } ret =ov4689_power_on (dev);if (ret)@@ -877,19 +860,26 @@ static int ov4689_probe(struct i2c_client *client)if (ret) goto err_power_off;
Quoted 5 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 863
Quoted 2 lines
drivers/media/i2c/ov4689.c +0
-1- sd->internal_ops = &ov4689_internal_ops; sd->flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ;I would move this line above, just before calling
ov4689_initialize_controls(), to group all subdev initialization code.
Will do it in v3.
Quoted 8 lines
Quoted 8 lines
drivers/media/i2c/ov4689.c +1
-1+ sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ov4689->pad.flags =MEDIA_PAD_FL_SOURCE ; - sd->entity.function =MEDIA_ENT_F_CAM_SENSOR ; ret =media_entity_pads_init (&sd->entity,1 , &ov4689->pad);if (ret <0 ) goto err_power_off;
Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 873
Quoted 3 lines
drivers/media/i2c/ov4689.c +3
-0+ sd->state_lock = ov4689->ctrl_handler.lock; + ret =v4l2_subdev_init_finalize (sd); +No need for a blank line.
Will remove it in v3.
Quoted 43 lines
With these small changes,
Reviewed-by Laurent Pinchart <[email protected]>Quoted 39 lines
drivers/media/i2c/ov4689.c +9
-5+if (ret) { +dev_err (dev,"Could not register v4l2 device\n" ); + goto err_clean_entity; + } + ret =v4l2_async_register_subdev_sensor (sd);if (ret) {dev_err (dev,"v4l2 async register subdev failed\n" ); - goto err_clean_entity; + goto err_clean_subdev; }pm_runtime_set_active (dev);@@ -898,14 +888,14 @@ static int ov4689_probe(struct i2c_client *client)return 0 ; +err_clean_subdev: +v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity); err_power_off:ov4689_power_off (dev); err_free_handler:v4l2_ctrl_handler_free (&ov4689->ctrl_handler); -err_destroy_mutex: -mutex_destroy (&ov4689->mutex);return ret; }@@ -917,9 +907,8 @@ static void ov4689_remove(struct i2c_client *client)v4l2_async_unregister_subdev (sd);media_entity_cleanup (&sd->entity); - +v4l2_subdev_cleanup (sd);v4l2_ctrl_handler_free (&ov4689->ctrl_handler); -mutex_destroy (&ov4689->mutex);
Quoted 2 lines
drivers/media/i2c/ov4689.c static void ov4689_remove(struct i2c_client *client) · line 914
Quoted 2 lines
drivers/media/i2c/ov4689.c +0
-0pm_runtime_disable (&client->dev);if (!pm_runtime_status_suspended (&client->dev))
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 15/20] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode
In reply to Laurent PinchartHi Laurent,
and thanks for the review!
Quoted 30 lines · Laurent Pinchart
Hi Mikhail,
Thank you for the patch.
Quoted 14 lines · Mikhail Rudenko
Pixel array dimensions and default crop size do not belong to the
ov4689_modestructure, since they are mode independent. Make them defines instead.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)drivers/media/i2c/ov4689.c +0
-0drivers/media/i2c/ov4689.c line 76
Quoted 7 lines
drivers/media/i2c/ov4689.c +4
-0@@ -70,6 +70,11 @@#define OV4689_LANES 4#define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_ARRAY_WIDTH 2720 +#define OV4689_PIXEL_ARRAY_HEIGHT 1536 +#define OV4689_DUMMY_ROWS 8 +#define OV4689_DUMMY_COLUMNS 16Adding a comment here to indicate that there are dummy columns in each side would be useful:
Quoted 2 lines
#define
OV4689_DUMMY_ROWS8 /* 8 dummy rows on each side */
#defineOV4689_DUMMY_COLUMNS16 /* 16 dummy columns on each side */
Will add the comments in v3.
Quoted 54 lines
Reviewed-by Laurent Pinchart <[email protected]>Quoted 51 lines
drivers/media/i2c/ov4689.c +4
-16+static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */ "dovdd" ,/* Digital I/O power */ @@ -90,10 +95,6 @@ struct ov4689_mode {u32 vts_def;u32 exp_def;u32 pixel_rate; -u32 sensor_width; -u32 sensor_height; -u32 crop_top; -u32 crop_left;const struct cci_reg_sequence *reg_list;unsigned int num_regs; };@@ -254,10 +255,6 @@ static const struct ov4689_mode supported_modes[] = { .id = OV4689_MODE_2688_1520, .width = 2688, .height = 1520, - .sensor_width = 2720, - .sensor_height = 1536, - .crop_top = 8, - .crop_left = 16, .exp_def = 1536, .hts_def = 10296, .hts_min = 3432,@@ -385,8 +382,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; -if (sel->which !=V4L2_SUBDEV_FORMAT_ACTIVE )return -EINVAL ;@@ -394,15 +389,17 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,case V4L2_SEL_TGT_CROP_BOUNDS : sel->r.top =0 ; sel->r.left =0 ; - sel->r.width = mode->sensor_width; - sel->r.height = mode->sensor_height; + sel->r.width =OV4689_PIXEL_ARRAY_WIDTH ; + sel->r.height =OV4689_PIXEL_ARRAY_HEIGHT ;return 0 ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_CROP_DEFAULT : - sel->r.top = mode->crop_top; - sel->r.left = mode->crop_left; - sel->r.width = mode->width; - sel->r.height = mode->height; + sel->r.top =OV4689_DUMMY_ROWS ;
Quoted 8 lines
drivers/media/i2c/ov4689.c static int ov4689_get_selection(struct v4l2_subdev *sd, · line 405
Quoted 8 lines
drivers/media/i2c/ov4689.c +5
-0+ sel->r.left =OV4689_DUMMY_COLUMNS ; + sel->r.width = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_COLUMNS ; + sel->r.height = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_ROWS ;return 0 ; }
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 15/20] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode
In reply to Laurent PinchartHi Laurent,
and thanks for the review!
Quoted 87 lines · Laurent Pinchart
Quoted 86 lines · Laurent Pinchart
Hi Mikhail,
Thank you for the patch.
Quoted 14 lines · Mikhail Rudenko
Pixel array dimensions and default crop size do not belong to the
ov4689_modestructure, since they are mode independent. Make them defines instead.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-)drivers/media/i2c/ov4689.c +0
-0drivers/media/i2c/ov4689.c line 76
Quoted 7 lines
drivers/media/i2c/ov4689.c +4
-0@@ -70,6 +70,11 @@#define OV4689_LANES 4#define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_ARRAY_WIDTH 2720 +#define OV4689_PIXEL_ARRAY_HEIGHT 1536 +#define OV4689_DUMMY_ROWS 8 +#define OV4689_DUMMY_COLUMNS 16Adding a comment here to indicate that there are dummy columns in each side would be useful:
#define
OV4689_DUMMY_ROWS8 /* 8 dummy rows on each side */
#defineOV4689_DUMMY_COLUMNS16 /* 16 dummy columns on each side */Reviewed-by Laurent Pinchart <[email protected]>Quoted 51 lines
drivers/media/i2c/ov4689.c +4
-16+static const char *const ov4689_supply_names[] = {"avdd" ,/* Analog power */ "dovdd" ,/* Digital I/O power */ @@ -90,10 +95,6 @@ struct ov4689_mode {u32 vts_def;u32 exp_def;u32 pixel_rate; -u32 sensor_width; -u32 sensor_height; -u32 crop_top; -u32 crop_left;const struct cci_reg_sequence *reg_list;unsigned int num_regs; };@@ -254,10 +255,6 @@ static const struct ov4689_mode supported_modes[] = { .id = OV4689_MODE_2688_1520, .width = 2688, .height = 1520, - .sensor_width = 2720, - .sensor_height = 1536, - .crop_top = 8, - .crop_left = 16, .exp_def = 1536, .hts_def = 10296, .hts_min = 3432,@@ -385,8 +382,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; -if (sel->which !=V4L2_SUBDEV_FORMAT_ACTIVE )return -EINVAL ;@@ -394,15 +389,17 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,case V4L2_SEL_TGT_CROP_BOUNDS : sel->r.top =0 ; sel->r.left =0 ; - sel->r.width = mode->sensor_width; - sel->r.height = mode->sensor_height; + sel->r.width =OV4689_PIXEL_ARRAY_WIDTH ; + sel->r.height =OV4689_PIXEL_ARRAY_HEIGHT ;return 0 ;case V4L2_SEL_TGT_CROP :case V4L2_SEL_TGT_CROP_DEFAULT : - sel->r.top = mode->crop_top; - sel->r.left = mode->crop_left; - sel->r.width = mode->width; - sel->r.height = mode->height; + sel->r.top =OV4689_DUMMY_ROWS ;
Quoted 8 lines
Quoted 5 lines
drivers/media/i2c/ov4689.c static int ov4689_get_selection(struct v4l2_subdev *sd, · line 402
Quoted 5 lines
drivers/media/i2c/ov4689.c +5
-0+ sel->r.left =OV4689_DUMMY_COLUMNS ; + sel->r.width = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_COLUMNS ; + sel->r.height = +OV4689_PIXEL_ARRAY_WIDTH -2 *OV4689_DUMMY_ROWS ;I spoke too fast: this should be
OV4689_PIXEL_ARRAY_HEIGHT, notOV4689_PIXEL_ARRAY_WIDTH.
Good catch, will fix in v3.
Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ov4689.c static int ov4689_get_selection(struct v4l2_subdev *sd, · line 405
Quoted 3 lines
drivers/media/i2c/ov4689.c +0
-0return 0 ; }
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 16/20] media: i2c: ov4689: Set timing registers programmatically
In reply to Laurent PinchartHi Laurent,
and thanks for the review!
Quoted 130 lines · Laurent Pinchart
Hi Mikhail,
Thank you for the patch.
Quoted 94 lines · Mikhail Rudenko
Set timing-related and BLC anchor registers via cci calls instead of hardcoding them in the register table. This prepares the driver for implementation of configurable analogue crop and binning. No functional change intended.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 83 +++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 15 deletions(-)drivers/media/i2c/ov4689.c +21
-15@@ -41,6 +41,13 @@#define OV4689_DIG_GAIN_STEP 1#define OV4689_DIG_GAIN_DEFAULT 0x800 +#define OV4689_REG_H_CROP_START CCI_REG16(0x3800) +#define OV4689_REG_V_CROP_START CCI_REG16(0x3802) +#define OV4689_REG_H_CROP_END CCI_REG16(0x3804) +#define OV4689_REG_V_CROP_END CCI_REG16(0x3806) +#define OV4689_REG_H_OUTPUT_SIZE CCI_REG16(0x3808) +#define OV4689_REG_V_OUTPUT_SIZE CCI_REG16(0x380a) +#define OV4689_REG_HTS CCI_REG16(0x380c)#define OV4689_HTS_DIVIDER 4#define OV4689_HTS_MAX 0x7fff@@ -48,6 +55,9 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810) +#define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820)#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821)#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1)@@ -56,6 +66,17 @@#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_ANCHOR_LEFT_START CCI_REG16(0x4020) +#define OV4689_ANCHOR_LEFT_START_DEF 576 +#define OV4689_REG_ANCHOR_LEFT_END CCI_REG16(0x4022) +#define OV4689_ANCHOR_LEFT_END_DEF 831 +#define OV4689_REG_ANCHOR_RIGHT_START CCI_REG16(0x4024) +#define OV4689_ANCHOR_RIGHT_START_DEF 1984 +#define OV4689_REG_ANCHOR_RIGHT_END CCI_REG16(0x4026) +#define OV4689_ANCHOR_RIGHT_END_DEF 2239 + +#define OV4689_REG_VFIFO_CTRL_01 CCI_REG8(0x4601) +#define OV4689_REG_WB_GAIN_RED CCI_REG16(0x500c)#define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010)#define OV4689_WB_GAIN_MIN 1@@ -199,10 +220,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3798), 0x1b},/* Timing control */ - {CCI_REG8(0x3801), 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ - {CCI_REG8(0x3805), 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ - {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ - {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 *//* OTP control */ @@ -218,22 +235,11 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x401b), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401d), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401f), 0x00}, /* DEBUG_MODE */ - {CCI_REG8(0x4020), 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ - {CCI_REG8(0x4021), 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ - {CCI_REG8(0x4022), 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ - {CCI_REG8(0x4023), 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ - {CCI_REG8(0x4024), 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ - {CCI_REG8(0x4025), 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ - {CCI_REG8(0x4026), 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ - {CCI_REG8(0x4027), 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f *//* ADC sync control */ {CCI_REG8(0x4500), 0x6c}, /* ADC_SYNC_CTRL */ {CCI_REG8(0x4503), 0x01}, /* ADC_SYNC_CTRL */ -/* VFIFO */ - {CCI_REG8(0x4601), 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ -/* Temperature monitor */ {CCI_REG8(0x4d00), 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ {CCI_REG8(0x4d01), 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */@@ -406,6 +412,41 @@ static int ov4689_get_selection(struct v4l2_subdev *sd,return -EINVAL ; }drivers/media/i2c/ov4689.c static int ov4689_get_selection(struct v4l2_subdev *sd, · line 424
Quoted 10 lines
drivers/media/i2c/ov4689.c +10
-0+static int ov4689_setup_timings (struct ov4689 *ov4689) +{ +const struct ov4689_mode *mode = ov4689->cur_mode; +struct regmap *rm = ov4689->regmap; +int ret =0 ; + +cci_write (rm,OV4689_REG_H_CROP_START ,8 , &ret); +cci_write (rm,OV4689_REG_V_CROP_START ,8 , &ret); +cci_write (rm,OV4689_REG_H_CROP_END ,2711 , &ret); +cci_write (rm,OV4689_REG_V_CROP_END ,1531 , &ret);This is interesting. The previous patch defines
#define
OV4689_PIXEL_ARRAY_WIDTH2720
#defineOV4689_PIXEL_ARRAY_HEIGHT1536
#defineOV4689_DUMMY_ROWS8
#defineOV4689_DUMMY_COLUMNS16and the (only) mode has
.width = 2688, .height = 1520,The above register values should result in an analog crop rectangle size of 2704x1524. Then, the digital crop is configured below to (8,4)/2688x1520. The combined crop rectangle, relative to the pixel array, is thus (16,12)/2688x1520. This centers the crop rectangle horizontally but not vertically. I wonder why, and I also wonder why there's a need to apply both analog crop and digital crop, instead of setting
Quoted 9 lines
OV4689_REG_H_CROP_START = 16 OV4689_REG_V_CROP_START = 8 OV4689_REG_H_CROP_END = 2703 OV4689_REG_V_CROP_END = 1527 OV4689_REG_H_WIN_OFF = 0 OV4689_REG_V_WIN_OFF = 0 OV4689_REG_H_OUTPUT_SIZE = 2688 OV4689_REG_V_OUTPUT_SIZE = 1520
The only reason for this is purely historical: these cropping/windowing settings were used in the register-table-based driver from Rockchip BSP, and there was no reason to change them until now. In fact, the next patch ([PATCH v2 17/20] media: i2c: ov4689: Configurable analogue crop) does exactly what you suggest. :)
Quoted 36 lines
Anyway, this is not an issue introduced by this patch, so
Reviewed-by Laurent Pinchart <[email protected]>Quoted 32 lines
drivers/media/i2c/ov4689.c +25
-0+ +cci_write (rm,OV4689_REG_H_OUTPUT_SIZE , mode->width, &ret); +cci_write (rm,OV4689_REG_V_OUTPUT_SIZE , mode->height, &ret); + +cci_write (rm,OV4689_REG_H_WIN_OFF ,8 , &ret); +cci_write (rm,OV4689_REG_V_WIN_OFF ,4 , &ret); + +cci_write (rm,OV4689_REG_VFIFO_CTRL_01 ,167 , &ret); + +return ret; +} + +static int ov4689_setup_blc_anchors (struct ov4689 *ov4689) +{ +struct regmap *rm = ov4689->regmap; +int ret =0 ; + +cci_write (rm,OV4689_REG_ANCHOR_LEFT_START ,16 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_LEFT_END ,1999 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_START ,2400 , &ret); +cci_write (rm,OV4689_REG_ANCHOR_RIGHT_END ,2415 , &ret); + +return ret; +} +static int ov4689_s_stream (struct v4l2_subdev *sd,int on) {struct ov4689 *ov4689 =to_ov4689 (sd);@@ -429,6 +470,18 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; }
Quoted 15 lines
Quoted 5 lines
drivers/media/i2c/ov4689.c +5
-0+ ret =ov4689_setup_timings (ov4689); +if (ret) { +pm_runtime_put (dev); + goto unlock_and_return; + }drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 487
Quoted 10 lines
drivers/media/i2c/ov4689.c +7
-0+ + ret =ov4689_setup_blc_anchors (ov4689); +if (ret) { +pm_runtime_put (dev); + goto unlock_and_return; + } + ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) {pm_runtime_put_sync (dev);
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 01/20] media: i2c: ov4689: Clean up and annotate the register table
In reply to Laurent PinchartHi Laurent,
and thank for the review!
Quoted 179 lines · Laurent Pinchart
HiMikhail,
Thank you for the patch.
Quoted 4 lines · Mikhail Rudenko
Many values in the register table are actually power-on defaults. Remove those and also unused HDR exposures and gains. Annotate the remaining values using the publicly available datasheet to facilitate further development. No functional change intended.
I'll trust you on that as I can't test the patch.
Quoted 167 lines
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 203 +++++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 85 deletions(-)drivers/media/i2c/ov4689.c +62
-85@@ -3,7 +3,7 @@* ov4689 driver * * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. -* Copyright (C) 2022 Mikhail Rudenko +* Copyright (C) 2022, 2023 Mikhail Rudenko */ #include <linux/clk.h> @@ -123,90 +123,123 @@ struct ov4689_gain_range {* mipi_datarate per lane 1008Mbps */ static const struct regval ov4689_2688x1520_regs[] = { - {0x0103 ,0x01 }, {0x3638 ,0x00 }, {0x0300 ,0x00 }, - {0x0302 ,0x2a }, {0x0303 ,0x00 }, {0x0304 ,0x03 }, - {0x030b ,0x00 }, {0x030d ,0x1e }, {0x030e ,0x04 }, - {0x030f ,0x01 }, {0x0312 ,0x01 }, {0x031e ,0x00 }, - {0x3000 ,0x20 }, {0x3002 ,0x00 }, {0x3018 ,0x72 }, - {0x3020 ,0x93 }, {0x3021 ,0x03 }, {0x3022 ,0x01 }, - {0x3031 ,0x0a }, {0x303f ,0x0c }, {0x3305 ,0xf1 }, - {0x3307 ,0x04 }, {0x3309 ,0x29 }, {0x3500 ,0x00 }, - {0x3501 ,0x60 }, {0x3502 ,0x00 }, {0x3503 ,0x04 }, - {0x3504 ,0x00 }, {0x3505 ,0x00 }, {0x3506 ,0x00 }, - {0x3507 ,0x00 }, {0x3508 ,0x00 }, {0x3509 ,0x80 }, - {0x350a ,0x00 }, {0x350b ,0x00 }, {0x350c ,0x00 }, - {0x350d ,0x00 }, {0x350e ,0x00 }, {0x350f ,0x80 }, - {0x3510 ,0x00 }, {0x3511 ,0x00 }, {0x3512 ,0x00 }, - {0x3513 ,0x00 }, {0x3514 ,0x00 }, {0x3515 ,0x80 }, - {0x3516 ,0x00 }, {0x3517 ,0x00 }, {0x3518 ,0x00 }, - {0x3519 ,0x00 }, {0x351a ,0x00 }, {0x351b ,0x80 }, - {0x351c ,0x00 }, {0x351d ,0x00 }, {0x351e ,0x00 }, - {0x351f ,0x00 }, {0x3520 ,0x00 }, {0x3521 ,0x80 }, - {0x3522 ,0x08 }, {0x3524 ,0x08 }, {0x3526 ,0x08 }, - {0x3528 ,0x08 }, {0x352a ,0x08 }, {0x3602 ,0x00 }, - {0x3603 ,0x40 }, {0x3604 ,0x02 }, {0x3605 ,0x00 }, - {0x3606 ,0x00 }, {0x3607 ,0x00 }, {0x3609 ,0x12 }, - {0x360a ,0x40 }, {0x360c ,0x08 }, {0x360f ,0xe5 }, - {0x3608 ,0x8f }, {0x3611 ,0x00 }, {0x3613 ,0xf7 }, - {0x3616 ,0x58 }, {0x3619 ,0x99 }, {0x361b ,0x60 }, - {0x361c ,0x7a }, {0x361e ,0x79 }, {0x361f ,0x02 }, - {0x3632 ,0x00 }, {0x3633 ,0x10 }, {0x3634 ,0x10 }, - {0x3635 ,0x10 }, {0x3636 ,0x15 }, {0x3646 ,0x86 }, - {0x364a ,0x0b }, {0x3700 ,0x17 }, {0x3701 ,0x22 }, - {0x3703 ,0x10 }, {0x370a ,0x37 }, {0x3705 ,0x00 }, - {0x3706 ,0x63 }, {0x3709 ,0x3c }, {0x370b ,0x01 }, - {0x370c ,0x30 }, {0x3710 ,0x24 }, {0x3711 ,0x0c }, - {0x3716 ,0x00 }, {0x3720 ,0x28 }, {0x3729 ,0x7b }, - {0x372a ,0x84 }, {0x372b ,0xbd }, {0x372c ,0xbc }, - {0x372e ,0x52 }, {0x373c ,0x0e }, {0x373e ,0x33 }, - {0x3743 ,0x10 }, {0x3744 ,0x88 }, {0x3745 ,0xc0 }, - {0x374a ,0x43 }, {0x374c ,0x00 }, {0x374e ,0x23 }, - {0x3751 ,0x7b }, {0x3752 ,0x84 }, {0x3753 ,0xbd }, - {0x3754 ,0xbc }, {0x3756 ,0x52 }, {0x375c ,0x00 }, - {0x3760 ,0x00 }, {0x3761 ,0x00 }, {0x3762 ,0x00 }, - {0x3763 ,0x00 }, {0x3764 ,0x00 }, {0x3767 ,0x04 }, - {0x3768 ,0x04 }, {0x3769 ,0x08 }, {0x376a ,0x08 }, - {0x376b ,0x20 }, {0x376c ,0x00 }, {0x376d ,0x00 }, - {0x376e ,0x00 }, {0x3773 ,0x00 }, {0x3774 ,0x51 }, - {0x3776 ,0xbd }, {0x3777 ,0xbd }, {0x3781 ,0x18 }, - {0x3783 ,0x25 }, {0x3798 ,0x1b }, {0x3800 ,0x00 }, - {0x3801 ,0x08 }, {0x3802 ,0x00 }, {0x3803 ,0x04 }, - {0x3804 ,0x0a }, {0x3805 ,0x97 }, {0x3806 ,0x05 }, - {0x3807 ,0xfb }, {0x3808 ,0x0a }, {0x3809 ,0x80 }, - {0x380a ,0x05 }, {0x380b ,0xf0 }, {0x380c ,0x0a }, - {0x380d ,0x0e }, {0x380e ,0x06 }, {0x380f ,0x12 }, - {0x3810 ,0x00 }, {0x3811 ,0x08 }, {0x3812 ,0x00 }, - {0x3813 ,0x04 }, {0x3814 ,0x01 }, {0x3815 ,0x01 }, - {0x3819 ,0x01 }, {0x3820 ,0x00 }, {0x3821 ,0x06 }, - {0x3829 ,0x00 }, {0x382a ,0x01 }, {0x382b ,0x01 }, - {0x382d ,0x7f }, {0x3830 ,0x04 }, {0x3836 ,0x01 }, - {0x3837 ,0x00 }, {0x3841 ,0x02 }, {0x3846 ,0x08 }, - {0x3847 ,0x07 }, {0x3d85 ,0x36 }, {0x3d8c ,0x71 }, - {0x3d8d ,0xcb }, {0x3f0a ,0x00 }, {0x4000 ,0xf1 }, - {0x4001 ,0x40 }, {0x4002 ,0x04 }, {0x4003 ,0x14 }, - {0x400e ,0x00 }, {0x4011 ,0x00 }, {0x401a ,0x00 }, - {0x401b ,0x00 }, {0x401c ,0x00 }, {0x401d ,0x00 }, - {0x401f ,0x00 }, {0x4020 ,0x00 }, {0x4021 ,0x10 }, - {0x4022 ,0x07 }, {0x4023 ,0xcf }, {0x4024 ,0x09 }, - {0x4025 ,0x60 }, {0x4026 ,0x09 }, {0x4027 ,0x6f }, - {0x4028 ,0x00 }, {0x4029 ,0x02 }, {0x402a ,0x06 }, - {0x402b ,0x04 }, {0x402c ,0x02 }, {0x402d ,0x02 }, - {0x402e ,0x0e }, {0x402f ,0x04 }, {0x4302 ,0xff }, - {0x4303 ,0xff }, {0x4304 ,0x00 }, {0x4305 ,0x00 }, - {0x4306 ,0x00 }, {0x4308 ,0x02 }, {0x4500 ,0x6c }, - {0x4501 ,0xc4 }, {0x4502 ,0x40 }, {0x4503 ,0x01 }, - {0x4601 ,0xa7 }, {0x4800 ,0x04 }, {0x4813 ,0x08 }, - {0x481f ,0x40 }, {0x4829 ,0x78 }, {0x4837 ,0x10 }, - {0x4b00 ,0x2a }, {0x4b0d ,0x00 }, {0x4d00 ,0x04 }, - {0x4d01 ,0x42 }, {0x4d02 ,0xd1 }, {0x4d03 ,0x93 }, - {0x4d04 ,0xf5 }, {0x4d05 ,0xc1 }, {0x5000 ,0xf3 }, - {0x5001 ,0x11 }, {0x5004 ,0x00 }, {0x500a ,0x00 }, - {0x500b ,0x00 }, {0x5032 ,0x00 }, {0x5040 ,0x00 }, - {0x5050 ,0x0c }, {0x5500 ,0x00 }, {0x5501 ,0x10 }, - {0x5502 ,0x01 }, {0x5503 ,0x0f }, {0x8000 ,0x00 }, - {0x8001 ,0x00 }, {0x8002 ,0x00 }, {0x8003 ,0x00 }, - {0x8004 ,0x00 }, {0x8005 ,0x00 }, {0x8006 ,0x00 }, - {0x8007 ,0x00 }, {0x8008 ,0x00 }, {0x3638 ,0x00 }, +/* System control*/ + {0x0103 ,0x01 },/* SC_CTRL0103 software_reset = 1 */ + {0x3000 ,0x20 },/* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ + {0x3021 ,0x03 },/* +* SC_CMMN_MISC_CTRL fst_stby_ctr = 0, +* sleep_no_latch_enable = 0 +*/ + +/* AEC PK */ + {0x3503 ,0x04 },/* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ + {0x352a ,0x08 },/* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ + +/* ADC and analog control*/ + {0x3603 ,0x40 }, + {0x3604 ,0x02 }, + {0x3609 ,0x12 }, + {0x360c ,0x08 }, + {0x360f ,0xe5 }, + {0x3608 ,0x8f }, + {0x3611 ,0x00 }, + {0x3613 ,0xf7 }, + {0x3616 ,0x58 }, + {0x3619 ,0x99 }, + {0x361b ,0x60 }, + {0x361e ,0x79 }, + {0x3634 ,0x10 }, + {0x3635 ,0x10 }, + {0x3636 ,0x15 }, + {0x3646 ,0x86 }, + {0x364a ,0x0b }, + +/* Sensor control */ + {0x3700 ,0x17 }, + {0x3701 ,0x22 }, + {0x3703 ,0x10 }, + {0x370a ,0x37 }, + {0x3706 ,0x63 }, + {0x3709 ,0x3c }, + {0x370c ,0x30 }, + {0x3710 ,0x24 }, + {0x3720 ,0x28 }, + {0x3729 ,0x7b }, + {0x372b ,0xbd }, + {0x372c ,0xbc }, + {0x372e ,0x52 }, + {0x373c ,0x0e }, + {0x373e ,0x33 }, + {0x3743 ,0x10 }, + {0x3744 ,0x88 }, + {0x3745 ,0xc0 }, + {0x374c ,0x00 }, + {0x374e ,0x23 }, + {0x3751 ,0x7b }, + {0x3753 ,0xbd }, + {0x3754 ,0xbc }, + {0x3756 ,0x52 }, + {0x376b ,0x20 }, + {0x3774 ,0x51 }, + {0x3776 ,0xbd }, + {0x3777 ,0xbd }, + {0x3781 ,0x18 },
Quoted 8 lines
drivers/media/i2c/ov4689.c struct ov4689_gain_range { · line 191
Quoted 5 lines
drivers/media/i2c/ov4689.c +5
-0+ {0x3783, 0x25}, + {0x3798, 0x1b}, + +/* Timing control */ + {0x3801, 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */It would be nice to define register macros for the known registers. This can be done in a separate patch.
Register defines are introduced throughout the series as soon they get users outside the register tables. For the remaining known registers, I'd prefer to introduce corresponding defines in a separate patch outside this series.
Quoted 48 lines
Acked-by Laurent Pinchart <[email protected]>Quoted 46 lines
drivers/media/i2c/ov4689.c +46
-0+ {0x3805, 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ + {0x380c, 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ + {0x380d, 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ + {0x3811, 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ + {0x3813, 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ + {0x3819, 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ + {0x3821, 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ + +/* OTP control */ + {0x3d85, 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, +* OTP_power_up_load_data_enable = 1, +* OTP_bist_select = 1 (compare with zero) +*/ + {0x3d8c, 0x71}, /* OTP_SETTING_STT_ADDRESS_H */ + {0x3d8d, 0xcb}, /* OTP_SETTING_STT_ADDRESS_L */ + +/* BLC registers*/ + {0x4001, 0x40}, /* DEBUG_MODE */ + {0x401b, 0x00}, /* DEBUG_MODE */ + {0x401d, 0x00}, /* DEBUG_MODE */ + {0x401f, 0x00}, /* DEBUG_MODE */ + {0x4020, 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ + {0x4021, 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ + {0x4022, 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ + {0x4023, 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ + {0x4024, 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ + {0x4025, 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ + {0x4026, 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ + {0x4027, 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ + +/* ADC sync control */ + {0x4500, 0x6c}, /* ADC_SYNC_CTRL */ + {0x4503, 0x01}, /* ADC_SYNC_CTRL */ + +/* VFIFO */ + {0x4601, 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ + +/* Temperature monitor */ + {0x4d00, 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ + {0x4d01, 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ + {0x4d02, 0xd1}, /* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ + {0x4d03, 0x93}, /* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ + {0x4d04, 0xf5}, /* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ + {0x4d05, 0xc1}, /* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ + + /* pre-ISP control */
Quoted 8 lines
drivers/media/i2c/ov4689.c struct ov4689_gain_range { · line 245
Quoted 8 lines
drivers/media/i2c/ov4689.c +5
-0+ {0x5050, 0x0c}, /* DEBUG_MODE */ + +/* OTP-DPC control */ + {0x5501, 0x10}, /* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ + {0x5503, 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ {REG_NULL, 0x00}, };
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 19/20] media: i2c: ov4689: Refactor ov4689_s_stream
In reply to Laurent PinchartHi Laurent,
and thanks for the review!
Quoted 53 lines · Laurent Pinchart
Hi Mikhail,
Thank you for the patch.
Quoted 48 lines · Mikhail Rudenko
Remove repetitive
pm_runtime_putcalls inov4689_s_streamfunction, and callpm_runtime_putonce at the end of the "on" branch if any error occurred.Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-)drivers/media/i2c/ov4689.c +8
-16@@ -555,35 +555,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689_common_regs,ARRAY_SIZE (ov4689_common_regs), NULL); -if (ret) { -pm_runtime_put_sync (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =ov4689_setup_timings (ov4689, sd_state); -if (ret) { -pm_runtime_put (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =ov4689_setup_blc_anchors (ov4689, sd_state); -if (ret) { -pm_runtime_put (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm; ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler); -if (ret) { -pm_runtime_put_sync (dev); - goto unlock_and_return; - } +if (ret) + goto cleanup_pm;
Quoted 10 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 575
Quoted 4 lines
drivers/media/i2c/ov4689.c +1
-1ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL ); -if (ret) { +cleanup_pm:A label within an if branch isn't great, readability-wise :-S Could we maybe split the
ov4687_s_stream()function in two (streamon and streamoff, or similar names) ? You would then have a singlepm_runtime_put_sync()call inov4689_s_stream(), in the error handling path for the streamon function call.
Okay, will split it in v3.
Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 580
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-2+if (ret)pm_runtime_put_sync (dev); - goto unlock_and_return; - } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL );
--
Best regards,
Mikhail Rudenko
Re: [PATCH v2 01/20] media: i2c: ov4689: Clean up and annotate the register table
In reply to Mikhail RudenkoHi Mikhail,
Quoted 185 lines · Mikhail Rudenko
Quoted 175 lines · Laurent Pinchart
Quoted 4 lines · Mikhail Rudenko
Many values in the register table are actually power-on defaults. Remove those and also unused HDR exposures and gains. Annotate the remaining values using the publicly available datasheet to facilitate further development. No functional change intended.
I'll trust you on that as I can't test the patch.
Quoted 167 lines
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 203 +++++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 85 deletions(-)drivers/media/i2c/ov4689.c +62
-85@@ -3,7 +3,7 @@* ov4689 driver * * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. -* Copyright (C) 2022 Mikhail Rudenko +* Copyright (C) 2022, 2023 Mikhail Rudenko */ #include <linux/clk.h> @@ -123,90 +123,123 @@ struct ov4689_gain_range {* mipi_datarate per lane 1008Mbps */ static const struct regval ov4689_2688x1520_regs[] = { - {0x0103 ,0x01 }, {0x3638 ,0x00 }, {0x0300 ,0x00 }, - {0x0302 ,0x2a }, {0x0303 ,0x00 }, {0x0304 ,0x03 }, - {0x030b ,0x00 }, {0x030d ,0x1e }, {0x030e ,0x04 }, - {0x030f ,0x01 }, {0x0312 ,0x01 }, {0x031e ,0x00 }, - {0x3000 ,0x20 }, {0x3002 ,0x00 }, {0x3018 ,0x72 }, - {0x3020 ,0x93 }, {0x3021 ,0x03 }, {0x3022 ,0x01 }, - {0x3031 ,0x0a }, {0x303f ,0x0c }, {0x3305 ,0xf1 }, - {0x3307 ,0x04 }, {0x3309 ,0x29 }, {0x3500 ,0x00 }, - {0x3501 ,0x60 }, {0x3502 ,0x00 }, {0x3503 ,0x04 }, - {0x3504 ,0x00 }, {0x3505 ,0x00 }, {0x3506 ,0x00 }, - {0x3507 ,0x00 }, {0x3508 ,0x00 }, {0x3509 ,0x80 }, - {0x350a ,0x00 }, {0x350b ,0x00 }, {0x350c ,0x00 }, - {0x350d ,0x00 }, {0x350e ,0x00 }, {0x350f ,0x80 }, - {0x3510 ,0x00 }, {0x3511 ,0x00 }, {0x3512 ,0x00 }, - {0x3513 ,0x00 }, {0x3514 ,0x00 }, {0x3515 ,0x80 }, - {0x3516 ,0x00 }, {0x3517 ,0x00 }, {0x3518 ,0x00 }, - {0x3519 ,0x00 }, {0x351a ,0x00 }, {0x351b ,0x80 }, - {0x351c ,0x00 }, {0x351d ,0x00 }, {0x351e ,0x00 }, - {0x351f ,0x00 }, {0x3520 ,0x00 }, {0x3521 ,0x80 }, - {0x3522 ,0x08 }, {0x3524 ,0x08 }, {0x3526 ,0x08 }, - {0x3528 ,0x08 }, {0x352a ,0x08 }, {0x3602 ,0x00 }, - {0x3603 ,0x40 }, {0x3604 ,0x02 }, {0x3605 ,0x00 }, - {0x3606 ,0x00 }, {0x3607 ,0x00 }, {0x3609 ,0x12 }, - {0x360a ,0x40 }, {0x360c ,0x08 }, {0x360f ,0xe5 }, - {0x3608 ,0x8f }, {0x3611 ,0x00 }, {0x3613 ,0xf7 }, - {0x3616 ,0x58 }, {0x3619 ,0x99 }, {0x361b ,0x60 }, - {0x361c ,0x7a }, {0x361e ,0x79 }, {0x361f ,0x02 }, - {0x3632 ,0x00 }, {0x3633 ,0x10 }, {0x3634 ,0x10 }, - {0x3635 ,0x10 }, {0x3636 ,0x15 }, {0x3646 ,0x86 }, - {0x364a ,0x0b }, {0x3700 ,0x17 }, {0x3701 ,0x22 }, - {0x3703 ,0x10 }, {0x370a ,0x37 }, {0x3705 ,0x00 }, - {0x3706 ,0x63 }, {0x3709 ,0x3c }, {0x370b ,0x01 }, - {0x370c ,0x30 }, {0x3710 ,0x24 }, {0x3711 ,0x0c }, - {0x3716 ,0x00 }, {0x3720 ,0x28 }, {0x3729 ,0x7b }, - {0x372a ,0x84 }, {0x372b ,0xbd }, {0x372c ,0xbc }, - {0x372e ,0x52 }, {0x373c ,0x0e }, {0x373e ,0x33 }, - {0x3743 ,0x10 }, {0x3744 ,0x88 }, {0x3745 ,0xc0 }, - {0x374a ,0x43 }, {0x374c ,0x00 }, {0x374e ,0x23 }, - {0x3751 ,0x7b }, {0x3752 ,0x84 }, {0x3753 ,0xbd }, - {0x3754 ,0xbc }, {0x3756 ,0x52 }, {0x375c ,0x00 }, - {0x3760 ,0x00 }, {0x3761 ,0x00 }, {0x3762 ,0x00 }, - {0x3763 ,0x00 }, {0x3764 ,0x00 }, {0x3767 ,0x04 }, - {0x3768 ,0x04 }, {0x3769 ,0x08 }, {0x376a ,0x08 }, - {0x376b ,0x20 }, {0x376c ,0x00 }, {0x376d ,0x00 }, - {0x376e ,0x00 }, {0x3773 ,0x00 }, {0x3774 ,0x51 }, - {0x3776 ,0xbd }, {0x3777 ,0xbd }, {0x3781 ,0x18 }, - {0x3783 ,0x25 }, {0x3798 ,0x1b }, {0x3800 ,0x00 }, - {0x3801 ,0x08 }, {0x3802 ,0x00 }, {0x3803 ,0x04 }, - {0x3804 ,0x0a }, {0x3805 ,0x97 }, {0x3806 ,0x05 }, - {0x3807 ,0xfb }, {0x3808 ,0x0a }, {0x3809 ,0x80 }, - {0x380a ,0x05 }, {0x380b ,0xf0 }, {0x380c ,0x0a }, - {0x380d ,0x0e }, {0x380e ,0x06 }, {0x380f ,0x12 }, - {0x3810 ,0x00 }, {0x3811 ,0x08 }, {0x3812 ,0x00 }, - {0x3813 ,0x04 }, {0x3814 ,0x01 }, {0x3815 ,0x01 }, - {0x3819 ,0x01 }, {0x3820 ,0x00 }, {0x3821 ,0x06 }, - {0x3829 ,0x00 }, {0x382a ,0x01 }, {0x382b ,0x01 }, - {0x382d ,0x7f }, {0x3830 ,0x04 }, {0x3836 ,0x01 }, - {0x3837 ,0x00 }, {0x3841 ,0x02 }, {0x3846 ,0x08 }, - {0x3847 ,0x07 }, {0x3d85 ,0x36 }, {0x3d8c ,0x71 }, - {0x3d8d ,0xcb }, {0x3f0a ,0x00 }, {0x4000 ,0xf1 }, - {0x4001 ,0x40 }, {0x4002 ,0x04 }, {0x4003 ,0x14 }, - {0x400e ,0x00 }, {0x4011 ,0x00 }, {0x401a ,0x00 }, - {0x401b ,0x00 }, {0x401c ,0x00 }, {0x401d ,0x00 }, - {0x401f ,0x00 }, {0x4020 ,0x00 }, {0x4021 ,0x10 }, - {0x4022 ,0x07 }, {0x4023 ,0xcf }, {0x4024 ,0x09 }, - {0x4025 ,0x60 }, {0x4026 ,0x09 }, {0x4027 ,0x6f }, - {0x4028 ,0x00 }, {0x4029 ,0x02 }, {0x402a ,0x06 }, - {0x402b ,0x04 }, {0x402c ,0x02 }, {0x402d ,0x02 }, - {0x402e ,0x0e }, {0x402f ,0x04 }, {0x4302 ,0xff }, - {0x4303 ,0xff }, {0x4304 ,0x00 }, {0x4305 ,0x00 }, - {0x4306 ,0x00 }, {0x4308 ,0x02 }, {0x4500 ,0x6c }, - {0x4501 ,0xc4 }, {0x4502 ,0x40 }, {0x4503 ,0x01 }, - {0x4601 ,0xa7 }, {0x4800 ,0x04 }, {0x4813 ,0x08 }, - {0x481f ,0x40 }, {0x4829 ,0x78 }, {0x4837 ,0x10 }, - {0x4b00 ,0x2a }, {0x4b0d ,0x00 }, {0x4d00 ,0x04 }, - {0x4d01 ,0x42 }, {0x4d02 ,0xd1 }, {0x4d03 ,0x93 }, - {0x4d04 ,0xf5 }, {0x4d05 ,0xc1 }, {0x5000 ,0xf3 }, - {0x5001 ,0x11 }, {0x5004 ,0x00 }, {0x500a ,0x00 }, - {0x500b ,0x00 }, {0x5032 ,0x00 }, {0x5040 ,0x00 }, - {0x5050 ,0x0c }, {0x5500 ,0x00 }, {0x5501 ,0x10 }, - {0x5502 ,0x01 }, {0x5503 ,0x0f }, {0x8000 ,0x00 }, - {0x8001 ,0x00 }, {0x8002 ,0x00 }, {0x8003 ,0x00 }, - {0x8004 ,0x00 }, {0x8005 ,0x00 }, {0x8006 ,0x00 }, - {0x8007 ,0x00 }, {0x8008 ,0x00 }, {0x3638 ,0x00 }, +/* System control*/ + {0x0103 ,0x01 },/* SC_CTRL0103 software_reset = 1 */ + {0x3000 ,0x20 },/* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ + {0x3021 ,0x03 },/* +* SC_CMMN_MISC_CTRL fst_stby_ctr = 0, +* sleep_no_latch_enable = 0 +*/ + +/* AEC PK */ + {0x3503 ,0x04 },/* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ + {0x352a ,0x08 },/* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ + +/* ADC and analog control*/ + {0x3603 ,0x40 }, + {0x3604 ,0x02 }, + {0x3609 ,0x12 }, + {0x360c ,0x08 }, + {0x360f ,0xe5 }, + {0x3608 ,0x8f }, + {0x3611 ,0x00 }, + {0x3613 ,0xf7 }, + {0x3616 ,0x58 }, + {0x3619 ,0x99 }, + {0x361b ,0x60 }, + {0x361e ,0x79 }, + {0x3634 ,0x10 }, + {0x3635 ,0x10 }, + {0x3636 ,0x15 }, + {0x3646 ,0x86 }, + {0x364a ,0x0b }, + +/* Sensor control */ + {0x3700 ,0x17 }, + {0x3701 ,0x22 }, + {0x3703 ,0x10 }, + {0x370a ,0x37 }, + {0x3706 ,0x63 }, + {0x3709 ,0x3c }, + {0x370c ,0x30 }, + {0x3710 ,0x24 }, + {0x3720 ,0x28 }, + {0x3729 ,0x7b }, + {0x372b ,0xbd }, + {0x372c ,0xbc }, + {0x372e ,0x52 }, + {0x373c ,0x0e }, + {0x373e ,0x33 }, + {0x3743 ,0x10 }, + {0x3744 ,0x88 }, + {0x3745 ,0xc0 }, + {0x374c ,0x00 }, + {0x374e ,0x23 }, + {0x3751 ,0x7b }, + {0x3753 ,0xbd }, + {0x3754 ,0xbc }, + {0x3756 ,0x52 }, + {0x376b ,0x20 }, + {0x3774 ,0x51 }, + {0x3776 ,0xbd }, + {0x3777 ,0xbd }, + {0x3781 ,0x18 },Quoted 8 lines
drivers/media/i2c/ov4689.c struct ov4689_gain_range { · line 191
Quoted 5 lines
drivers/media/i2c/ov4689.c +5
-0+ {0x3783, 0x25}, + {0x3798, 0x1b}, + +/* Timing control */ + {0x3801, 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */It would be nice to define register macros for the known registers. This can be done in a separate patch.
Quoted 4 lines
Register defines are introduced throughout the series as soon they get users outside the register tables. For the remaining known registers, I'd prefer to introduce corresponding defines in a separate patch outside this series.
Sure, it can be done in a separate series (or just separate patch), no problem.
Quoted 56 lines
Quoted 56 lines
Acked-by Laurent Pinchart <[email protected]>Quoted 54 lines
drivers/media/i2c/ov4689.c +51
-0+ {0x3805, 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ + {0x380c, 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ + {0x380d, 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ + {0x3811, 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ + {0x3813, 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ + {0x3819, 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ + {0x3821, 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ + +/* OTP control */ + {0x3d85, 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, +* OTP_power_up_load_data_enable = 1, +* OTP_bist_select = 1 (compare with zero) +*/ + {0x3d8c, 0x71}, /* OTP_SETTING_STT_ADDRESS_H */ + {0x3d8d, 0xcb}, /* OTP_SETTING_STT_ADDRESS_L */ + +/* BLC registers*/ + {0x4001, 0x40}, /* DEBUG_MODE */ + {0x401b, 0x00}, /* DEBUG_MODE */ + {0x401d, 0x00}, /* DEBUG_MODE */ + {0x401f, 0x00}, /* DEBUG_MODE */ + {0x4020, 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ + {0x4021, 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ + {0x4022, 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ + {0x4023, 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ + {0x4024, 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ + {0x4025, 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ + {0x4026, 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ + {0x4027, 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ + +/* ADC sync control */ + {0x4500, 0x6c}, /* ADC_SYNC_CTRL */ + {0x4503, 0x01}, /* ADC_SYNC_CTRL */ + +/* VFIFO */ + {0x4601, 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ + +/* Temperature monitor */ + {0x4d00, 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ + {0x4d01, 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ + {0x4d02, 0xd1}, /* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ + {0x4d03, 0x93}, /* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ + {0x4d04, 0xf5}, /* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ + {0x4d05, 0xc1}, /* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ + +/* pre-ISP control */ + {0x5050, 0x0c}, /* DEBUG_MODE */ + +/* OTP-DPC control */ + {0x5501, 0x10}, /* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ + {0x5503, 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ {REG_NULL, 0x00}, };
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
In reply to Mikhail RudenkoHi Mikhail,
Quoted 46 lines · Mikhail Rudenko
Hi Sakari,
and thanks for the review!
Quoted 39 lines · Sakari Ailus
Hi Mikhail,
Quoted 35 lines · Mikhail Rudenko
Hi Sakari,
Thanks for the review!
Quoted 11 lines · Sakari Ailus
Hi Mikhail,
Quoted 8 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)Quoted 13 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 10 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);Why are you switching to
pm_runtime_put_sync()here? That isn't covered by the commit message (nor I think should be done).PM autosuspend conversion was suggested earlier by Laurent in his review of this series [1], and he adviced looking at how it was done for the imx290 driver. I followed along the lines of the corresponding patch [2].
Quoted 5 lines
Quoted 2 lines
There's no need to use the
_sync()variant here. And at least it wouldn't be related to autosuspend, were you to switch to that.Ok, will use
pm_runtime_putin v3. Or do you suggest dropping this patch altogether? Laurent?
Using autosuspend is preferred.
Much of the benefit come from avoiding redundant register writes but that's a separate matter.
Quoted 79 lines
Quoted 77 lines
Quoted 77 lines
Quoted 32 lines
Quoted 32 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; }Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 430
Quoted 3 lines
drivers/media/i2c/ov4689.c +2
-1-pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);Also note that with runtime PM autosuspend, you have to use
pm_runtime_get_if_active()instead ofpm_runtime_get_if_in_use().Noted, will do so in v3.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/ov4689.c +7
-1+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ;Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 904
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-1err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Signature · 3 lines
Kind regards, Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH v2 12/20] media: i2c: ov4689: Implement vflip/hflip controls
In reply to Mikhail RudenkoHi Mikhail,
Quoted 83 lines · Mikhail Rudenko
Hi Sakari,
and thanks for the review!
Quoted 67 lines · Sakari Ailus
Hi Mikhail,
Quoted 64 lines · Mikhail Rudenko
The OV4689 sensor supports horizontal and vertical flipping. Add appropriate controls to the driver. Toggling both array flip and digital flip bits allows to achieve flipping while maintaining output Bayer order. Note that the default value of hflip control corresponds to both bits set, as it was before this patch.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/media/i2c/ov4689.c +19
-2@@ -42,6 +42,14 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) +#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) +#define OV4689_TIMING_FLIP_ARRAY BIT(1) +#define OV4689_TIMING_FLIP_DIGITAL BIT(2) +#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ + OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0@@ -183,7 +191,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ - {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 *//* OTP control */ {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1,@@ -607,6 +614,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) (ctrl->val + ov4689->cur_mode->width) / OV4689_HTS_DIVIDER, &ret);break ; +case V4L2_CID_VFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT1 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?OV4689_TIMING_FLIP_BOTH :0 , &ret); +break ; +case V4L2_CID_HFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT2 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?0 :OV4689_TIMING_FLIP_BOTH , &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);@@ -637,7 +654,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,10 ); + ret =v4l2_ctrl_handler_init (handler,12 );if (ret)return ret;Quoted 8 lines
drivers/media/i2c/ov4689.c static int ov4689_initialize_controls(struct ov4689 *ov4689) · line 698
Quoted 6 lines
drivers/media/i2c/ov4689.c +2
-0@@ -677,6 +694,9 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)ARRAY_SIZE (ov4689_test_pattern_menu) -1 , 0, 0, ov4689_test_pattern_menu); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 );Could you take the default value from the mounting rotation?
Quoted 4 lines
Could you provide an example (maybe a link to an existing driver) which does this right? If I understand you correctly, I should flip default for both flip controls for 180 degree rotation. But what should I do for 90, 270 and all the rest rotation values?
Looking at the patch again, it seems that the image wasn't flipped both vertically and horizontally, but only horizontally. Was that the case?
Shouldn't the default then be no flipping?
Quoted 11 lines
Quoted 3 lines
The default should be upside-up, but this is an existing driver and changing the flipping now could affect existing users.
Do you mean default rotation value when missing device tree property?
Signature · 3 lines
Regards, Sakari Ailus
Mikhail Rudenko
maintainerRe: [PATCH v2 12/20] media: i2c: ov4689: Implement vflip/hflip controls
Quoted 91 lines · Sakari Ailus
Hi Mikhail,
Quoted 83 lines · Mikhail Rudenko
Hi Sakari,
and thanks for the review!
Quoted 67 lines · Sakari Ailus
Hi Mikhail,
Quoted 64 lines · Mikhail Rudenko
The OV4689 sensor supports horizontal and vertical flipping. Add appropriate controls to the driver. Toggling both array flip and digital flip bits allows to achieve flipping while maintaining output Bayer order. Note that the default value of hflip control corresponds to both bits set, as it was before this patch.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)drivers/media/i2c/ov4689.c +19
-2@@ -42,6 +42,14 @@#define OV4689_REG_VTS CCI_REG16(0x380e)#define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) +#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) +#define OV4689_TIMING_FLIP_ARRAY BIT(1) +#define OV4689_TIMING_FLIP_DIGITAL BIT(2) +#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ + OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040)#define OV4689_TEST_PATTERN_ENABLE 0x80#define OV4689_TEST_PATTERN_DISABLE 0x0@@ -183,7 +191,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ - {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 *//* OTP control */ {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1,@@ -607,6 +614,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) (ctrl->val + ov4689->cur_mode->width) / OV4689_HTS_DIVIDER, &ret);break ; +case V4L2_CID_VFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT1 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?OV4689_TIMING_FLIP_BOTH :0 , &ret); +break ; +case V4L2_CID_HFLIP : +cci_update_bits (regmap,OV4689_REG_TIMING_FORMAT2 , +OV4689_TIMING_FLIP_MASK , + ctrl->val ?0 :OV4689_TIMING_FLIP_BOTH , &ret); +break ;default :dev_warn (dev,"%s Unhandled id:0x%x, val:0x%x\n" , __func__, ctrl->id, ctrl->val);@@ -637,7 +654,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret =v4l2_ctrl_handler_init (handler,10 ); + ret =v4l2_ctrl_handler_init (handler,12 );if (ret)return ret;Quoted 8 lines
drivers/media/i2c/ov4689.c static int ov4689_initialize_controls(struct ov4689 *ov4689) · line 698
Quoted 6 lines
drivers/media/i2c/ov4689.c +2
-0@@ -677,6 +694,9 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689)ARRAY_SIZE (ov4689_test_pattern_menu) -1 , 0, 0, ov4689_test_pattern_menu); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (handler, &ov4689_ctrl_ops,V4L2_CID_HFLIP ,0 ,1 ,1 ,0 );Could you take the default value from the mounting rotation?
Quoted 4 lines
Could you provide an example (maybe a link to an existing driver) which does this right? If I understand you correctly, I should flip default for both flip controls for 180 degree rotation. But what should I do for 90, 270 and all the rest rotation values?
Quoted 5 lines
Looking at the patch again, it seems that the image wasn't flipped both vertically and horizontally, but only horizontally. Was that the case?
Shouldn't the default then be no flipping?
Do you mean setting FORMAT1 and FORMAT2 to 0x0 and HFLIP and VFLIP controls to 0 by default, and doing
case V4L2_CID_VFLIP:
cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT1, OV4689_TIMING_FLIP_MASK, ctrl->val ? OV4689_TIMING_FLIP_BOTH : 0, &ret); break; case V4L2_CID_HFLIP: cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT2, OV4689_TIMING_FLIP_MASK, ctrl->val ? OV4689_TIMING_FLIP_BOTH : 0, &ret); // do not invert! break;
in ov4689_set_ctrl? The issue is that we get a mirrored image in this case.
The publicly available documentation doesn't clarify this, but it looks like the horizontal flipping bits in FORMAT2 are somehow inverted. All the other drivers for this sensor I've found default to FORMAT2 = 0x6 (none implement flipping controls, though).
So I see two options here:
(1) default to HFLIP = 0, FORMAT2 = 0x6 (as done is this patch)
(2) default to HFLIP = 1, FORMAT2 = 0x0
I like (1) better, because it results in non-mirrored image by default. What is your opinion?
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
The default should be upside-up, but this is an existing driver and changing the flipping now could affect existing users.
Do you mean default rotation value when missing device tree property?
--
Best regards,
Mikhail Rudenko
Mikhail Rudenko
maintainerRe: [PATCH v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend
In reply to Sakari AilusQuoted 52 lines · Sakari Ailus
Hi Mikhail,
Quoted 49 lines · Mikhail Rudenko
Hi Sakari,
and thanks for the review!
Quoted 41 lines · Sakari Ailus
Hi Mikhail,
Quoted 31 lines · Mikhail Rudenko
Hi Sakari,
Thanks for the review!
Quoted 11 lines · Sakari Ailus
Hi Mikhail,
Quoted 8 lines · Mikhail Rudenko
Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles.
Signed-off-by Mikhail Rudenko <[email protected]>--- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)Quoted 13 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 410
Quoted 10 lines
drivers/media/i2c/ov4689.c +1
-1@@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev);Why are you switching to
pm_runtime_put_sync()here? That isn't covered by the commit message (nor I think should be done).Quoted 4 lines
PM autosuspend conversion was suggested earlier by Laurent in his review of this series [1], and he adviced looking at how it was done for the imx290 driver. I followed along the lines of the corresponding patch [2].
There's no need to use the
_sync()variant here. And at least it wouldn't be related to autosuspend, were you to switch to that.
Quoted 7 lines
Quoted 2 lines
Ok, will use
pm_runtime_putin v3. Or do you suggest dropping this patch altogether? Laurent?Using autosuspend is preferred.
Much of the benefit come from avoiding redundant register writes but that's a separate matter.
I see, will try to do it in a separate patch outside this series. Could you please point to a driver which does this right?
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
Quoted 33 lines
Quoted 33 lines
drivers/media/i2c/ov4689.c +4
-3goto unlock_and_return; } ret =__v4l2_ctrl_handler_setup (&ov4689->ctrl_handler);if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } ret =cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_STREAMING ,NULL );if (ret) { -pm_runtime_put (dev); +pm_runtime_put_sync (dev); goto unlock_and_return; } }else {cci_write (ov4689->regmap,OV4689_REG_CTRL_MODE ,OV4689_MODE_SW_STANDBY ,NULL ); -pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); } unlock_and_return:@@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)break ; }Quoted 6 lines
drivers/media/i2c/ov4689.c static int ov4689_s_stream(struct v4l2_subdev *sd, int on) · line 430
Quoted 3 lines
drivers/media/i2c/ov4689.c +2
-1-pm_runtime_put (dev); +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev);Also note that with runtime PM autosuspend, you have to use
pm_runtime_get_if_active()instead ofpm_runtime_get_if_in_use().Noted, will do so in v3.
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/ov4689.c +7
-1+return ret; }@@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) }pm_runtime_set_active (dev); +pm_runtime_get_noresume (dev);pm_runtime_enable (dev); -pm_runtime_idle (dev); +pm_runtime_set_autosuspend_delay (dev,1000 ); +pm_runtime_use_autosuspend (dev); ret =v4l2_async_register_subdev_sensor (sd);if (ret) {@@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } +pm_runtime_mark_last_busy (dev); +pm_runtime_put_autosuspend (dev); +return 0 ;
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
drivers/media/i2c/ov4689.c static int ov4689_probe(struct i2c_client *client) · line 904
Quoted 7 lines
drivers/media/i2c/ov4689.c +1
-1err_clean_subdev_pm:pm_runtime_disable (dev); -pm_runtime_set_suspended (dev); +pm_runtime_put_noidle (dev);v4l2_subdev_cleanup (sd); err_clean_entity:media_entity_cleanup (&sd->entity);[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
--
Best regards,
Mikhail Rudenko