summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Piepho <tpiepho@impinj.com>2019-01-02 11:00:17 -0500
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-01-10 16:27:06 -0500
commitc8c97a4fb52c526be7a78c4c1e61a95cf1c915cc (patch)
treebfe8657eefa93687bf2953d0d8e5f3a6f0099dfa
parent074b01a51d058f4216b7ce541e96b778aa6af60d (diff)
rtc: isl1208: fix negative digital trim reporting
isl1208_i2c_get_dtr() was returning the dtr value directly, but could also return a negative error code. Negative trimming values, e.g. -20, would get interpreted as an error code, e.g. -ENOTDIR. This patch offsets the dtr value by 100 so it's positive and won't alias an error code. Also fix check that considered a return value of -1 to be success. Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Trent Piepho <tpiepho@impinj.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r--drivers/rtc/rtc-isl1208.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index 37ab3e1d25f5..263af3d8cd9f 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -161,6 +161,7 @@ isl1208_i2c_get_atr(struct i2c_client *client)
161 return atr; 161 return atr;
162} 162}
163 163
164/* returns adjustment value + 100 */
164static int 165static int
165isl1208_i2c_get_dtr(struct i2c_client *client) 166isl1208_i2c_get_dtr(struct i2c_client *client)
166{ 167{
@@ -171,7 +172,7 @@ isl1208_i2c_get_dtr(struct i2c_client *client)
171 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */ 172 /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
172 dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1); 173 dtr = ((dtr & 0x3) * 20) * (dtr & (1 << 2) ? -1 : 1);
173 174
174 return dtr; 175 return dtr + 100;
175} 176}
176 177
177static int 178static int
@@ -248,8 +249,8 @@ isl1208_rtc_proc(struct device *dev, struct seq_file *seq)
248 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay"); 249 (sr & ISL1208_REG_SR_RTCF) ? "bad" : "okay");
249 250
250 dtr = isl1208_i2c_get_dtr(client); 251 dtr = isl1208_i2c_get_dtr(client);
251 if (dtr >= 0 - 1) 252 if (dtr >= 0)
252 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr); 253 seq_printf(seq, "digital_trim\t: %d ppm\n", dtr - 100);
253 254
254 atr = isl1208_i2c_get_atr(client); 255 atr = isl1208_i2c_get_atr(client);
255 if (atr >= 0) 256 if (atr >= 0)
@@ -637,7 +638,7 @@ isl1208_sysfs_show_dtrim(struct device *dev,
637 if (dtr < 0) 638 if (dtr < 0)
638 return dtr; 639 return dtr;
639 640
640 return sprintf(buf, "%d ppm\n", dtr); 641 return sprintf(buf, "%d ppm\n", dtr - 100);
641} 642}
642 643
643static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL); 644static DEVICE_ATTR(dtrim, S_IRUGO, isl1208_sysfs_show_dtrim, NULL);