diff options
author | Michael Büsch <m@bues.ch> | 2016-03-10 12:34:23 -0500 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2016-03-14 12:08:39 -0400 |
commit | 39387dc2cf22bc5e9c310a4991c6a40852df4217 (patch) | |
tree | b86458bcbeb137c275788c04e39dd81ce0fc4202 | |
parent | 361c6ed6b1536d522815abba82bc676038259f72 (diff) |
rtc: rv3029: Add update_bits helper for eeprom access
This simplifies the update of single bits in the eeprom.
Signed-off-by: Michael Buesch <m@bues.ch>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
-rw-r--r-- | drivers/rtc/rtc-rv3029c2.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c index b416ed026168..3bbb581563c4 100644 --- a/drivers/rtc/rtc-rv3029c2.c +++ b/drivers/rtc/rtc-rv3029c2.c | |||
@@ -308,6 +308,24 @@ static int rv3029_eeprom_write(struct i2c_client *client, u8 reg, | |||
308 | return ret; | 308 | return ret; |
309 | } | 309 | } |
310 | 310 | ||
311 | static int rv3029_eeprom_update_bits(struct i2c_client *client, | ||
312 | u8 reg, u8 mask, u8 set) | ||
313 | { | ||
314 | u8 buf; | ||
315 | int ret; | ||
316 | |||
317 | ret = rv3029_eeprom_read(client, reg, &buf, 1); | ||
318 | if (ret < 0) | ||
319 | return ret; | ||
320 | buf &= ~mask; | ||
321 | buf |= set & mask; | ||
322 | ret = rv3029_eeprom_write(client, reg, &buf, 1); | ||
323 | if (ret < 0) | ||
324 | return ret; | ||
325 | |||
326 | return 0; | ||
327 | } | ||
328 | |||
311 | static int | 329 | static int |
312 | rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) | 330 | rv3029_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) |
313 | { | 331 | { |
@@ -588,23 +606,16 @@ static void rv3029_trickle_config(struct i2c_client *client) | |||
588 | const struct rv3029_trickle_tab_elem *elem; | 606 | const struct rv3029_trickle_tab_elem *elem; |
589 | int i, err; | 607 | int i, err; |
590 | u32 ohms; | 608 | u32 ohms; |
591 | u8 eectrl; | 609 | u8 trickle_set_bits; |
592 | 610 | ||
593 | if (!of_node) | 611 | if (!of_node) |
594 | return; | 612 | return; |
595 | 613 | ||
596 | /* Configure the trickle charger. */ | 614 | /* Configure the trickle charger. */ |
597 | err = rv3029_eeprom_read(client, RV3029_CONTROL_E2P_EECTRL, | ||
598 | &eectrl, 1); | ||
599 | if (err < 0) { | ||
600 | dev_err(&client->dev, | ||
601 | "Failed to read trickle charger config\n"); | ||
602 | return; | ||
603 | } | ||
604 | err = of_property_read_u32(of_node, "trickle-resistor-ohms", &ohms); | 615 | err = of_property_read_u32(of_node, "trickle-resistor-ohms", &ohms); |
605 | if (err) { | 616 | if (err) { |
606 | /* Disable trickle charger. */ | 617 | /* Disable trickle charger. */ |
607 | eectrl &= ~RV3029_TRICKLE_MASK; | 618 | trickle_set_bits = 0; |
608 | } else { | 619 | } else { |
609 | /* Enable trickle charger. */ | 620 | /* Enable trickle charger. */ |
610 | for (i = 0; i < ARRAY_SIZE(rv3029_trickle_tab); i++) { | 621 | for (i = 0; i < ARRAY_SIZE(rv3029_trickle_tab); i++) { |
@@ -612,17 +623,17 @@ static void rv3029_trickle_config(struct i2c_client *client) | |||
612 | if (elem->r >= ohms) | 623 | if (elem->r >= ohms) |
613 | break; | 624 | break; |
614 | } | 625 | } |
615 | eectrl &= ~RV3029_TRICKLE_MASK; | 626 | trickle_set_bits = elem->conf; |
616 | eectrl |= elem->conf; | ||
617 | dev_info(&client->dev, | 627 | dev_info(&client->dev, |
618 | "Trickle charger enabled at %d ohms resistance.\n", | 628 | "Trickle charger enabled at %d ohms resistance.\n", |
619 | elem->r); | 629 | elem->r); |
620 | } | 630 | } |
621 | err = rv3029_eeprom_write(client, RV3029_CONTROL_E2P_EECTRL, | 631 | err = rv3029_eeprom_update_bits(client, RV3029_CONTROL_E2P_EECTRL, |
622 | &eectrl, 1); | 632 | RV3029_TRICKLE_MASK, |
633 | trickle_set_bits); | ||
623 | if (err < 0) { | 634 | if (err < 0) { |
624 | dev_err(&client->dev, | 635 | dev_err(&client->dev, |
625 | "Failed to write trickle charger config\n"); | 636 | "Failed to update trickle charger config\n"); |
626 | } | 637 | } |
627 | } | 638 | } |
628 | 639 | ||