aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2019-01-19 04:00:30 -0500
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-01-22 12:57:08 -0500
commit189927e719e36ceefbb8037f23d3849e47833aef (patch)
treeeaa926f119a6c93ebe86ef3baed9aac1ad9eacb3 /drivers/rtc
parente4a604cbee5470fc116ac9a4f852152070984286 (diff)
rtc: pcf8523: set xtal load capacitance from DT
Add support for specifying the xtal load capacitance in the DT node. The pcf8523 supports xtal load capacitance of 7pF or 12.5pF. If the rtc has the wrong configuration the time will drift several hours/week. The driver use the default value 12.5pF. The DT may specify either 7000fF or 12500fF. (The DT uses femto Farad to avoid decimal numbers). Other values are warned and the driver uses the default value. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-pcf8523.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index fb13933f4006..b5c61a70b5df 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -97,8 +97,9 @@ static int pcf8523_voltage_low(struct i2c_client *client)
97 return !!(value & REG_CONTROL3_BLF); 97 return !!(value & REG_CONTROL3_BLF);
98} 98}
99 99
100static int pcf8523_select_capacitance(struct i2c_client *client, bool high) 100static int pcf8523_load_capacitance(struct i2c_client *client)
101{ 101{
102 u32 load;
102 u8 value; 103 u8 value;
103 int err; 104 int err;
104 105
@@ -106,14 +107,24 @@ static int pcf8523_select_capacitance(struct i2c_client *client, bool high)
106 if (err < 0) 107 if (err < 0)
107 return err; 108 return err;
108 109
109 if (!high) 110 load = 12500;
110 value &= ~REG_CONTROL1_CAP_SEL; 111 of_property_read_u32(client->dev.of_node, "quartz-load-femtofarads",
111 else 112 &load);
113
114 switch (load) {
115 default:
116 dev_warn(&client->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 12500",
117 load);
118 /* fall through */
119 case 12500:
112 value |= REG_CONTROL1_CAP_SEL; 120 value |= REG_CONTROL1_CAP_SEL;
121 break;
122 case 7000:
123 value &= ~REG_CONTROL1_CAP_SEL;
124 break;
125 }
113 126
114 err = pcf8523_write(client, REG_CONTROL1, value); 127 err = pcf8523_write(client, REG_CONTROL1, value);
115 if (err < 0)
116 return err;
117 128
118 return err; 129 return err;
119} 130}
@@ -347,9 +358,10 @@ static int pcf8523_probe(struct i2c_client *client,
347 if (!pcf) 358 if (!pcf)
348 return -ENOMEM; 359 return -ENOMEM;
349 360
350 err = pcf8523_select_capacitance(client, true); 361 err = pcf8523_load_capacitance(client);
351 if (err < 0) 362 if (err < 0)
352 return err; 363 dev_warn(&client->dev, "failed to set xtal load capacitance: %d",
364 err);
353 365
354 err = pcf8523_set_pm(client, 0); 366 err = pcf8523_set_pm(client, 0);
355 if (err < 0) 367 if (err < 0)