Skip to content

Commit 3c87b35

Browse files
andrejpicejalexandrebelloni
authored andcommitted
rtc: rv3028: Add support for "aux-voltage-chargeable" property
Property "trickle-resistor-ohms" allows us to set trickle charger resistor. However there is no possibility to disable it afterwards. Add support for "aux-voltage-chargeable" property which can be used to enable/disable the trickle charger circuit explicitly. The default behavior of the code is kept as it is! Additionally, lets make sure we only update internal EEPROM in case of a change. This prevents wear due to excessive EEPROM writes on each probe. Signed-off-by: Andrej Picej <andrej.picej@norik.com> Link: https://lore.kernel.org/r/20230623081533.76334-1-andrej.picej@norik.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 766c3f8 commit 3c87b35

1 file changed

Lines changed: 61 additions & 19 deletions

File tree

drivers/rtc/rtc-rv3028.c

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,68 @@ static const struct regmap_config regmap_config = {
855855
.max_register = 0x37,
856856
};
857857

858+
static u8 rv3028_set_trickle_charger(struct rv3028_data *rv3028,
859+
struct i2c_client *client)
860+
{
861+
int ret, val_old, val;
862+
u32 ohms, chargeable;
863+
864+
ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &val_old);
865+
if (ret < 0)
866+
return ret;
867+
868+
/* mask out only trickle charger bits */
869+
val_old = val_old & (RV3028_BACKUP_TCE | RV3028_BACKUP_TCR_MASK);
870+
val = val_old;
871+
872+
/* setup trickle charger */
873+
if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms",
874+
&ohms)) {
875+
int i;
876+
877+
for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++)
878+
if (ohms == rv3028_trickle_resistors[i])
879+
break;
880+
881+
if (i < ARRAY_SIZE(rv3028_trickle_resistors)) {
882+
/* enable trickle charger and its resistor */
883+
val = RV3028_BACKUP_TCE | i;
884+
} else {
885+
dev_warn(&client->dev, "invalid trickle resistor value\n");
886+
}
887+
}
888+
889+
if (!device_property_read_u32(&client->dev, "aux-voltage-chargeable",
890+
&chargeable)) {
891+
switch (chargeable) {
892+
case 0:
893+
val &= ~RV3028_BACKUP_TCE;
894+
break;
895+
case 1:
896+
val |= RV3028_BACKUP_TCE;
897+
break;
898+
default:
899+
dev_warn(&client->dev,
900+
"unsupported aux-voltage-chargeable value\n");
901+
break;
902+
}
903+
}
904+
905+
/* only update EEPROM if changes are necessary */
906+
if (val_old != val) {
907+
ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE |
908+
RV3028_BACKUP_TCR_MASK, val);
909+
if (ret)
910+
return ret;
911+
}
912+
913+
return ret;
914+
}
915+
858916
static int rv3028_probe(struct i2c_client *client)
859917
{
860918
struct rv3028_data *rv3028;
861919
int ret, status;
862-
u32 ohms;
863920
struct nvmem_config nvmem_cfg = {
864921
.name = "rv3028_nvram",
865922
.word_size = 1,
@@ -937,24 +994,9 @@ static int rv3028_probe(struct i2c_client *client)
937994
if (ret)
938995
return ret;
939996

940-
/* setup trickle charger */
941-
if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms",
942-
&ohms)) {
943-
int i;
944-
945-
for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++)
946-
if (ohms == rv3028_trickle_resistors[i])
947-
break;
948-
949-
if (i < ARRAY_SIZE(rv3028_trickle_resistors)) {
950-
ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE |
951-
RV3028_BACKUP_TCR_MASK, RV3028_BACKUP_TCE | i);
952-
if (ret)
953-
return ret;
954-
} else {
955-
dev_warn(&client->dev, "invalid trickle resistor value\n");
956-
}
957-
}
997+
ret = rv3028_set_trickle_charger(rv3028, client);
998+
if (ret)
999+
return ret;
9581000

9591001
ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group);
9601002
if (ret)

0 commit comments

Comments
 (0)