mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
rtc: rv3028: Add backup switchover mode support
Signed-off-by: Phil Howard <phil@pimoroni.com>
This commit is contained in:
@@ -865,16 +865,17 @@ static const struct regmap_config regmap_config = {
|
||||
static u8 rv3028_set_trickle_charger(struct rv3028_data *rv3028,
|
||||
struct i2c_client *client)
|
||||
{
|
||||
int ret, val_old, val;
|
||||
int ret, val_old, val, val_mask;
|
||||
u32 ohms, chargeable;
|
||||
u32 bsm;
|
||||
|
||||
ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &val_old);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* mask out only trickle charger bits */
|
||||
val_old = val_old & (RV3028_BACKUP_TCE | RV3028_BACKUP_TCR_MASK);
|
||||
val = val_old;
|
||||
val_mask = RV3028_BACKUP_TCE | RV3028_BACKUP_TCR_MASK;
|
||||
val = val_old & val_mask;
|
||||
|
||||
/* setup trickle charger */
|
||||
if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms",
|
||||
@@ -909,10 +910,21 @@ static u8 rv3028_set_trickle_charger(struct rv3028_data *rv3028,
|
||||
}
|
||||
}
|
||||
|
||||
/* setup backup switchover mode */
|
||||
if (!device_property_read_u32(&client->dev,
|
||||
"backup-switchover-mode",
|
||||
&bsm)) {
|
||||
if (bsm <= 3) {
|
||||
val_mask |= RV3028_BACKUP_BSM;
|
||||
val |= (u8)(bsm << 2);
|
||||
} else {
|
||||
dev_warn(&client->dev, "invalid backup switchover mode value\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* only update EEPROM if changes are necessary */
|
||||
if (val_old != val) {
|
||||
ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE |
|
||||
RV3028_BACKUP_TCR_MASK, val);
|
||||
if ((val_old & val_mask) != val) {
|
||||
ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, val_mask, val);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user