diff mbox series

[05/19] media: i2c: ov4689: Refactor ov4689_set_ctrl

Message ID 20231211175023.1680247-6-mike.rudenko@gmail.com (mailing list archive)
State New
Headers show
Series Omnivision OV4689 refactoring and improvements | expand

Commit Message

Mikhail Rudenko Dec. 11, 2023, 5:50 p.m. UTC
Introduces local variables for regmap and the control value within the
ov4689_set_ctrl function. This adjustment eliminates repetition within
the function.

Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
---
 drivers/media/i2c/ov4689.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Comments

Laurent Pinchart Dec. 11, 2023, 6:11 p.m. UTC | #1
Hi Mikhail,

Thank you for the patch.

On Mon, Dec 11, 2023 at 08:50:08PM +0300, Mikhail Rudenko wrote:
> Introduces local variables for regmap and the control value within the
> ov4689_set_ctrl function. This adjustment eliminates repetition within
> the function.
> 
> Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
> ---
>  drivers/media/i2c/ov4689.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c
> index 8c120d7f7830..42700ecfbe0e 100644
> --- a/drivers/media/i2c/ov4689.c
> +++ b/drivers/media/i2c/ov4689.c
> @@ -584,7 +584,9 @@ 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;
> +	s32 val = ctrl->val;

For ctrl->val, I think the code is clearer without this change. When
reading the function, seeing "val", I need to look up what it is, while
seeing "ctrl->val" gives me more context and makes (in my opinion) the
code more readable.

>  	int sensor_gain;
>  	s64 max_expo;
>  	int ret;
> @@ -593,7 +595,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)
>  	switch (ctrl->id) {
>  	case V4L2_CID_VBLANK:
>  		/* Update max exposure while meeting expected vblanking */
> -		max_expo = ov4689->cur_mode->height + ctrl->val - 4;
> +		max_expo = ov4689->cur_mode->height + val - 4;
>  		__v4l2_ctrl_modify_range(ov4689->exposure,
>  					 ov4689->exposure->minimum, max_expo,
>  					 ov4689->exposure->step,
> @@ -607,36 +609,34 @@ 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, val << 4, &ret);
>  		break;
>  	case V4L2_CID_ANALOGUE_GAIN:
> -		ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain);
> +		ret = ov4689_map_gain(ov4689, val, &sensor_gain);
>  
> -		cci_write(ov4689->regmap, OV4689_REG_GAIN_H,
> +		cci_write(regmap, OV4689_REG_GAIN_H,
>  			  (sensor_gain >> OV4689_GAIN_H_SHIFT) &
>  			  OV4689_GAIN_H_MASK, &ret);
>  
> -		cci_write(ov4689->regmap, OV4689_REG_GAIN_L,
> +		cci_write(regmap, OV4689_REG_GAIN_L,
>  			  sensor_gain & OV4689_GAIN_L_MASK,
>  			  &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,
> +			  val + ov4689->cur_mode->height, &ret);
>  		break;
>  	case V4L2_CID_TEST_PATTERN:
> -		ret = ov4689_enable_test_pattern(ov4689, ctrl->val);
> +		ret = ov4689_enable_test_pattern(ov4689, val);
>  		break;
>  	default:
>  		dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n",
> -			 __func__, ctrl->id, ctrl->val);
> +			 __func__, ctrl->id, val);
>  		ret = -EINVAL;
>  		break;
>  	}
>  
>  	pm_runtime_put(dev);
> -
>  	return ret;
>  }
>  
> -- 
> 2.43.0
>
Mikhail Rudenko Dec. 12, 2023, 12:25 p.m. UTC | #2
On 2023-12-11 at 20:11 +02, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:

> Hi Mikhail,
>
> Thank you for the patch.
>
> On Mon, Dec 11, 2023 at 08:50:08PM +0300, Mikhail Rudenko wrote:
>> Introduces local variables for regmap and the control value within the
>> ov4689_set_ctrl function. This adjustment eliminates repetition within
>> the function.
>>
>> Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
>> ---
>>  drivers/media/i2c/ov4689.c | 22 +++++++++++-----------
>>  1 file changed, 11 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c
>> index 8c120d7f7830..42700ecfbe0e 100644
>> --- a/drivers/media/i2c/ov4689.c
>> +++ b/drivers/media/i2c/ov4689.c
>> @@ -584,7 +584,9 @@ 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;
>> +	s32 val = ctrl->val;
>
> For ctrl->val, I think the code is clearer without this change. When
> reading the function, seeing "val", I need to look up what it is, while
> seeing "ctrl->val" gives me more context and makes (in my opinion) the
> code more readable.

Agreed, will revert to ctrl->val in v2.

>>  	int sensor_gain;
>>  	s64 max_expo;
>>  	int ret;
>> @@ -593,7 +595,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)
>>  	switch (ctrl->id) {
>>  	case V4L2_CID_VBLANK:
>>  		/* Update max exposure while meeting expected vblanking */
>> -		max_expo = ov4689->cur_mode->height + ctrl->val - 4;
>> +		max_expo = ov4689->cur_mode->height + val - 4;
>>  		__v4l2_ctrl_modify_range(ov4689->exposure,
>>  					 ov4689->exposure->minimum, max_expo,
>>  					 ov4689->exposure->step,
>> @@ -607,36 +609,34 @@ 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, val << 4, &ret);
>>  		break;
>>  	case V4L2_CID_ANALOGUE_GAIN:
>> -		ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain);
>> +		ret = ov4689_map_gain(ov4689, val, &sensor_gain);
>>
>> -		cci_write(ov4689->regmap, OV4689_REG_GAIN_H,
>> +		cci_write(regmap, OV4689_REG_GAIN_H,
>>  			  (sensor_gain >> OV4689_GAIN_H_SHIFT) &
>>  			  OV4689_GAIN_H_MASK, &ret);
>>
>> -		cci_write(ov4689->regmap, OV4689_REG_GAIN_L,
>> +		cci_write(regmap, OV4689_REG_GAIN_L,
>>  			  sensor_gain & OV4689_GAIN_L_MASK,
>>  			  &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,
>> +			  val + ov4689->cur_mode->height, &ret);
>>  		break;
>>  	case V4L2_CID_TEST_PATTERN:
>> -		ret = ov4689_enable_test_pattern(ov4689, ctrl->val);
>> +		ret = ov4689_enable_test_pattern(ov4689, val);
>>  		break;
>>  	default:
>>  		dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n",
>> -			 __func__, ctrl->id, ctrl->val);
>> +			 __func__, ctrl->id, val);
>>  		ret = -EINVAL;
>>  		break;
>>  	}
>>
>>  	pm_runtime_put(dev);
>> -
>>  	return ret;
>>  }
>>
>> --
>> 2.43.0
>>


--
Best regards,
Mikhail Rudenko
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c
index 8c120d7f7830..42700ecfbe0e 100644
--- a/drivers/media/i2c/ov4689.c
+++ b/drivers/media/i2c/ov4689.c
@@ -584,7 +584,9 @@  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;
+	s32 val = ctrl->val;
 	int sensor_gain;
 	s64 max_expo;
 	int ret;
@@ -593,7 +595,7 @@  static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl)
 	switch (ctrl->id) {
 	case V4L2_CID_VBLANK:
 		/* Update max exposure while meeting expected vblanking */
-		max_expo = ov4689->cur_mode->height + ctrl->val - 4;
+		max_expo = ov4689->cur_mode->height + val - 4;
 		__v4l2_ctrl_modify_range(ov4689->exposure,
 					 ov4689->exposure->minimum, max_expo,
 					 ov4689->exposure->step,
@@ -607,36 +609,34 @@  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, val << 4, &ret);
 		break;
 	case V4L2_CID_ANALOGUE_GAIN:
-		ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain);
+		ret = ov4689_map_gain(ov4689, val, &sensor_gain);
 
-		cci_write(ov4689->regmap, OV4689_REG_GAIN_H,
+		cci_write(regmap, OV4689_REG_GAIN_H,
 			  (sensor_gain >> OV4689_GAIN_H_SHIFT) &
 			  OV4689_GAIN_H_MASK, &ret);
 
-		cci_write(ov4689->regmap, OV4689_REG_GAIN_L,
+		cci_write(regmap, OV4689_REG_GAIN_L,
 			  sensor_gain & OV4689_GAIN_L_MASK,
 			  &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,
+			  val + ov4689->cur_mode->height, &ret);
 		break;
 	case V4L2_CID_TEST_PATTERN:
-		ret = ov4689_enable_test_pattern(ov4689, ctrl->val);
+		ret = ov4689_enable_test_pattern(ov4689, val);
 		break;
 	default:
 		dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n",
-			 __func__, ctrl->id, ctrl->val);
+			 __func__, ctrl->id, val);
 		ret = -EINVAL;
 		break;
 	}
 
 	pm_runtime_put(dev);
-
 	return ret;
 }