Skip to content

Commit 49dfc1f

Browse files
kpflemingalexandrebelloni
authored andcommitted
rtc: abx80x: Add utility function for writing configuration key
Writing one of key two values into the configuration key register is a common operation, so a utility function has been added to provide consistent behavior and eliminate code duplication. Signed-off-by: Kevin P. Fleming <[email protected]> Cc: Alessandro Zummo <[email protected]> Cc: Alexandre Belloni <[email protected]> To: [email protected] Signed-off-by: Alexandre Belloni <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2843d56 commit 49dfc1f

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

drivers/rtc/rtc-abx80x.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ struct abx80x_priv {
117117
struct watchdog_device wdog;
118118
};
119119

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+
120130
static int abx80x_is_rc_mode(struct i2c_client *client)
121131
{
122132
int flags = 0;
@@ -140,12 +150,8 @@ static int abx80x_enable_trickle_charger(struct i2c_client *client,
140150
* Write the configuration key register to enable access to the Trickle
141151
* register
142152
*/
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)
147154
return -EIO;
148-
}
149155

150156
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE,
151157
ABX8XX_TRICKLE_CHARGE_ENABLE |
@@ -358,12 +364,8 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
358364
}
359365

360366
/* 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;
367369

368370
retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags);
369371

@@ -450,12 +452,8 @@ static ssize_t oscillator_store(struct device *dev,
450452
flags |= (ABX8XX_OSC_OSEL);
451453

452454
/* 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;
459457

460458
retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags);
461459
if (retval < 0) {
@@ -762,13 +760,8 @@ static int abx80x_probe(struct i2c_client *client,
762760
* Write the configuration key register to enable access to
763761
* the config2 register
764762
*/
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)
770764
return -EIO;
771-
}
772765

773766
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_OUT_CTRL,
774767
data | ABX8XX_OUT_CTRL_EXDS);

0 commit comments

Comments
 (0)