Commit 49dfc1f1 authored by Kevin P. Fleming's avatar Kevin P. Fleming Committed by Alexandre Belloni

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: default avatarKevin P. Fleming <kevin+linux@km6g.us>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20200615105113.57770-2-kevin+linux@km6g.us
parent 2843d565
...@@ -117,6 +117,16 @@ struct abx80x_priv { ...@@ -117,6 +117,16 @@ struct abx80x_priv {
struct watchdog_device wdog; struct watchdog_device wdog;
}; };
static int abx80x_write_config_key(struct i2c_client *client, u8 key)
{
if (i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, key) < 0) {
dev_err(&client->dev, "Unable to write configuration key\n");
return -EIO;
}
return 0;
}
static int abx80x_is_rc_mode(struct i2c_client *client) static int abx80x_is_rc_mode(struct i2c_client *client)
{ {
int flags = 0; int flags = 0;
...@@ -140,12 +150,8 @@ static int abx80x_enable_trickle_charger(struct i2c_client *client, ...@@ -140,12 +150,8 @@ static int abx80x_enable_trickle_charger(struct i2c_client *client,
* Write the configuration key register to enable access to the Trickle * Write the configuration key register to enable access to the Trickle
* register * register
*/ */
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0)
ABX8XX_CFG_KEY_MISC);
if (err < 0) {
dev_err(&client->dev, "Unable to write configuration key\n");
return -EIO; return -EIO;
}
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE, err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE,
ABX8XX_TRICKLE_CHARGE_ENABLE | ABX8XX_TRICKLE_CHARGE_ENABLE |
...@@ -358,12 +364,8 @@ static int abx80x_rtc_set_autocalibration(struct device *dev, ...@@ -358,12 +364,8 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
} }
/* Unlock write access to Oscillator Control Register */ /* Unlock write access to Oscillator Control Register */
retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_OSC) < 0)
ABX8XX_CFG_KEY_OSC); return -EIO;
if (retval < 0) {
dev_err(dev, "Failed to write CONFIG_KEY register\n");
return retval;
}
retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags); retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags);
...@@ -450,12 +452,8 @@ static ssize_t oscillator_store(struct device *dev, ...@@ -450,12 +452,8 @@ static ssize_t oscillator_store(struct device *dev,
flags |= (ABX8XX_OSC_OSEL); flags |= (ABX8XX_OSC_OSEL);
/* Unlock write access on Oscillator Control register */ /* Unlock write access on Oscillator Control register */
retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_OSC) < 0)
ABX8XX_CFG_KEY_OSC); return -EIO;
if (retval < 0) {
dev_err(dev, "Failed to write CONFIG_KEY register\n");
return retval;
}
retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags); retval = i2c_smbus_write_byte_data(client, ABX8XX_REG_OSC, flags);
if (retval < 0) { if (retval < 0) {
...@@ -762,13 +760,8 @@ static int abx80x_probe(struct i2c_client *client, ...@@ -762,13 +760,8 @@ static int abx80x_probe(struct i2c_client *client,
* Write the configuration key register to enable access to * Write the configuration key register to enable access to
* the config2 register * the config2 register
*/ */
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0)
ABX8XX_CFG_KEY_MISC);
if (err < 0) {
dev_err(&client->dev,
"Unable to write configuration key\n");
return -EIO; return -EIO;
}
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_OUT_CTRL, err = i2c_smbus_write_byte_data(client, ABX8XX_REG_OUT_CTRL,
data | ABX8XX_OUT_CTRL_EXDS); data | ABX8XX_OUT_CTRL_EXDS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment