@@ -146,6 +146,7 @@ struct ov5640_data {
146146 uint32_t cur_pixrate ;
147147 uint16_t cur_frmrate ;
148148 const struct ov5640_mode_config * cur_mode ;
149+ bool auto_gain ;
149150};
150151
151152static const struct ov5640_reg init_params_common [] = {
@@ -997,25 +998,35 @@ static int ov5640_set_ctrl_contrast(const struct device *dev, int value)
997998static int ov5640_set_ctrl_gain (const struct device * dev , int value )
998999{
9991000 const struct ov5640_config * cfg = dev -> config ;
1001+ struct ov5640_data * data = dev -> data ;
10001002
1001- if (!IN_RANGE (value , 0 , UINT16_MAX )) {
1003+ if (data -> auto_gain ) {
1004+ return - ENOTSUP ;
1005+ }
1006+
1007+ if (!IN_RANGE (value , 0 , 1023 )) {
10021008 return - EINVAL ;
10031009 }
10041010
1005- if (value ) {
1006- int ret = ov5640_modify_reg (& cfg -> i2c , AEC_PK_MANUAL , BIT (1 ), BIT (0 ));
1011+ int ret = ov5640_modify_reg (& cfg -> i2c , AEC_PK_REAL_GAIN , 0x03 , (value >> 8 ) & 0x03 );
10071012
1008- if (ret ) {
1009- return ret ;
1010- }
1013+ if (ret ) {
1014+ return ret ;
1015+ }
10111016
1012- struct ov5640_reg gain_params [] = {{AEC_PK_REAL_GAIN , value >> 8 },
1013- {AEC_PK_REAL_GAIN + 1 , value & 0xff }};
1017+ ret = ov5640_write_reg (& cfg -> i2c , AEC_PK_REAL_GAIN + 1 , value & 0xff );
1018+ return ret ;
1019+ }
10141020
1015- return ov5640_write_multi_regs (& cfg -> i2c , gain_params , ARRAY_SIZE (gain_params ));
1016- } else {
1017- return ov5640_write_reg (& cfg -> i2c , AEC_PK_MANUAL , 0 );
1018- }
1021+ static int ov5640_set_ctrl_autogain (const struct device * dev , bool value )
1022+ {
1023+ const struct ov5640_config * cfg = dev -> config ;
1024+ struct ov5640_data * data = dev -> data ;
1025+ int ret ;
1026+
1027+ data -> auto_gain = value ;
1028+
1029+ return ov5640_modify_reg (& cfg -> i2c , AEC_PK_MANUAL , BIT (1 ), data -> auto_gain ? 0 : BIT (1 ));
10191030}
10201031
10211032static int ov5640_set_ctrl_hflip (const struct device * dev , int value )
@@ -1073,6 +1084,8 @@ static int ov5640_set_ctrl(const struct device *dev, unsigned int cid, void *val
10731084 return ov5640_set_ctrl_brightness (dev , (int )(value ));
10741085 case VIDEO_CID_CONTRAST :
10751086 return ov5640_set_ctrl_contrast (dev , (int )value );
1087+ case VIDEO_CID_AUTOGAIN :
1088+ return ov5640_set_ctrl_autogain (dev , (bool )(value ));
10761089 case VIDEO_CID_GAIN :
10771090 return ov5640_set_ctrl_gain (dev , (int )(value ));
10781091 case VIDEO_CID_HFLIP :
0 commit comments