@@ -117,6 +117,16 @@ struct abx80x_priv {
117
117
struct watchdog_device wdog ;
118
118
};
119
119
120
+ static int abx80x_write_config_key (struct i2c_client * client , u8 key )
121
+ {
122
+ if (i2c_smbus_write_byte_data (client , ABX8XX_REG_CFG_KEY , key ) < 0 ) {
123
+ dev_err (& client -> dev , "Unable to write configuration key\n" );
124
+ return - EIO ;
125
+ }
126
+
127
+ return 0 ;
128
+ }
129
+
120
130
static int abx80x_is_rc_mode (struct i2c_client * client )
121
131
{
122
132
int flags = 0 ;
@@ -140,12 +150,8 @@ static int abx80x_enable_trickle_charger(struct i2c_client *client,
140
150
* Write the configuration key register to enable access to the Trickle
141
151
* register
142
152
*/
143
- err = i2c_smbus_write_byte_data (client , ABX8XX_REG_CFG_KEY ,
144
- ABX8XX_CFG_KEY_MISC );
145
- if (err < 0 ) {
146
- dev_err (& client -> dev , "Unable to write configuration key\n" );
153
+ if (abx80x_write_config_key (client , ABX8XX_CFG_KEY_MISC ) < 0 )
147
154
return - EIO ;
148
- }
149
155
150
156
err = i2c_smbus_write_byte_data (client , ABX8XX_REG_TRICKLE ,
151
157
ABX8XX_TRICKLE_CHARGE_ENABLE |
@@ -358,12 +364,8 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
358
364
}
359
365
360
366
/* Unlock write access to Oscillator Control Register */
361
- retval = i2c_smbus_write_byte_data (client , ABX8XX_REG_CFG_KEY ,
362
- ABX8XX_CFG_KEY_OSC );
363
- if (retval < 0 ) {
364
- dev_err (dev , "Failed to write CONFIG_KEY register\n" );
365
- return retval ;
366
- }
367
+ if (abx80x_write_config_key (client , ABX8XX_CFG_KEY_OSC ) < 0 )
368
+ return - EIO ;
367
369
368
370
retval = i2c_smbus_write_byte_data (client , ABX8XX_REG_OSC , flags );
369
371
@@ -450,12 +452,8 @@ static ssize_t oscillator_store(struct device *dev,
450
452
flags |= (ABX8XX_OSC_OSEL );
451
453
452
454
/* Unlock write access on Oscillator Control register */
453
- retval = i2c_smbus_write_byte_data (client , ABX8XX_REG_CFG_KEY ,
454
- ABX8XX_CFG_KEY_OSC );
455
- if (retval < 0 ) {
456
- dev_err (dev , "Failed to write CONFIG_KEY register\n" );
457
- return retval ;
458
- }
455
+ if (abx80x_write_config_key (client , ABX8XX_CFG_KEY_OSC ) < 0 )
456
+ return - EIO ;
459
457
460
458
retval = i2c_smbus_write_byte_data (client , ABX8XX_REG_OSC , flags );
461
459
if (retval < 0 ) {
@@ -762,13 +760,8 @@ static int abx80x_probe(struct i2c_client *client,
762
760
* Write the configuration key register to enable access to
763
761
* the config2 register
764
762
*/
765
- err = i2c_smbus_write_byte_data (client , ABX8XX_REG_CFG_KEY ,
766
- ABX8XX_CFG_KEY_MISC );
767
- if (err < 0 ) {
768
- dev_err (& client -> dev ,
769
- "Unable to write configuration key\n" );
763
+ if (abx80x_write_config_key (client , ABX8XX_CFG_KEY_MISC ) < 0 )
770
764
return - EIO ;
771
- }
772
765
773
766
err = i2c_smbus_write_byte_data (client , ABX8XX_REG_OUT_CTRL ,
774
767
data | ABX8XX_OUT_CTRL_EXDS );
0 commit comments