bq32000 fixes
cover bq32000 fixes
Hi all,
This is a couple of patches for the bq32000 RTC.
The first one is purely cosmetic, fixing a case where the wrong mask (but correct value) was used when reading a register value.
The second patch adds a check for a failure flag in the read function. If t= he
register contents can't be trusted, an error is returned instead. The patch also removes some code in the probe function that would clear the failure flag without resolving the error condition. The error is now only cleared when writing a new time to the RTC.
Jan =C3=96stlund (2):
rtc: bq32k: Use correct mask name for 'minutes' register.
rtc: bq32k: Fix handling of oscillator failure flag
drivers/rtc/rtc-bq32k.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
--
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
PATCH 1/2 rtc: bq32k: Use correct mask name for 'minutes' register.
From: Jan =C3=96stlund <[email protected]>
The BQ32K_SECONDS_MASK and BQ32K_MINUTES_MASK both has the same value. This is no functional change.
--- drivers/rtc/rtc-bq32k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-bq32k.c +0 -0
@@ -94,7 +94,7 @@ static int bq32k_rtc_read_time(struct device *dev, struct= rtc_time *tm)return error;
=20
tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
- tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_SECONDS_MASK);
+ tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK); tm->tm_mday =3D bcd2bin(regs.date);
tm->tm_wday =3D bcd2bin(regs.day) - 1;
--=20
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
PATCH 2/2 rtc: bq32k: Fix handling of oscillator failure flag
In reply to Daniel RomellFrom: Jan =C3=96stlund <[email protected]>
While the oscillator failure flag is set, the RTC registers should be considered invalid. bq32k_rtc_read_time() now returns an error instead of an invalid time.
The failure flag is cleared the next time the clock is set.
--- drivers/rtc/rtc-bq32k.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/rtc/rtc-bq32k.c +0 -0
@@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struc=
t rtc_time *tm)
if (error)
return error;
=20
+ /*
+ * In case of oscillator failure, the register contents should be
+ * considered invalid. The flag is cleared the next time the RTC is set.
+ */
+ if (regs.minutes & BQ32K_OF)
+ return -EIO;
+
tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
@@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client, =20
/* Check Oscillator Failure flag */
error =3D bq32k_read(dev, ®, BQ32K_MINUTES, 1);
- if (!error && (reg & BQ32K_OF)) {
- dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
- reg &=3D ~BQ32K_OF;
- error =3D bq32k_write(dev, ®, BQ32K_MINUTES, 1);
- }
if (error)
return error;
+ if (reg & BQ32K_OF)
+ dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
=20
if (client->dev.of_node)
trickle_charger_of_init(dev, client->dev.of_node);
--=20
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
Re: [PATCH 2/2] rtc: bq32k: Fix handling of oscillator failure flag
drivers/rtc/rtc-bq32k.c static int bq32k_rtc_read_time(struct device *dev, str=
Quoted 18 lines · Daniel Romell
From: Jan =C3=96stlund <[email protected]>
=20
While the oscillator failure flag is set, the RTC registers should be considered invalid.bq32k_rtc_read_time()now returns an error instead of an invalid time.
=20
The failure flag is cleared the next time the clock is set. =20Signed-off-by Daniel Romell <[email protected]>--- drivers/rtc/rtc-bq32k.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)=20
drivers/rtc/rtc-bq32k.c +0
-0@@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, str=
uct rtc_time *tm)
drivers/rtc/rtc-bq32k.c
Quoted 6 lines
drivers/rtc/rtc-bq32k.c +0
-0if (error)return error;=20
drivers/rtc/rtc-bq32k.c +3
-0+/* +* In case of oscillator failure, the register contents should be +* considered invalid. The flag is cleared the next time the RTC is set=
.
drivers/rtc/rtc-bq32k.c
Quoted 3 lines
drivers/rtc/rtc-bq32k.c +3
-0+*/ +if (regs.minutes &BQ32K_OF ) +return -EIO ;
The other drivers return -EINVAL in that case. Else, the change is fine.
Quoted 21 lines
drivers/rtc/rtc-bq32k.c +1
-0+ tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);@@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client,=20
drivers/rtc/rtc-bq32k.c +2
-5/* Check Oscillator Failure flag */ error =3D bq32k_read(dev, ®, BQ32K_MINUTES, 1); -if (!error && (reg &BQ32K_OF )) { -dev_warn (dev,"Oscillator Failure. Check RTC battery.\n" ); - reg &=3D ~BQ32K_OF; - error =3D bq32k_write(dev, ®, BQ32K_MINUTES, 1); - }if (error)return error; +if (reg &BQ32K_OF ) +dev_warn (dev,"Oscillator Failure. Check RTC battery.\n" );=20
drivers/rtc/rtc-bq32k.c +0
-1if (client->dev.of_node)trickle_charger_of_init (dev, client->dev.of_node); --=20
Quoted 2 lines
2.7.4
=20
--=20
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
v2 cover bq32000 fixes
In reply to Daniel RomellChanges since v1:
* Return -EINVAL instead of -EIO when failure flag is set.
Jan =C3=96stlund (2):
rtc: bq32k: Use correct mask name for 'minutes' register.
rtc: bq32k: Fix handling of oscillator failure flag
drivers/rtc/rtc-bq32k.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
--
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
PATCH v2 1/2 rtc: bq32k: Use correct mask name for 'minutes' register.
From: Jan =C3=96stlund <[email protected]>
The BQ32K_SECONDS_MASK and BQ32K_MINUTES_MASK both has the same value. This is no functional change.
--- drivers/rtc/rtc-bq32k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-bq32k.c +0 -0
@@ -94,7 +94,7 @@ static int bq32k_rtc_read_time(struct device *dev, struct= rtc_time *tm)return error;
=20
tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
- tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_SECONDS_MASK);
+ tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK); tm->tm_mday =3D bcd2bin(regs.date);
tm->tm_wday =3D bcd2bin(regs.day) - 1;
--=20
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
Re: [PATCH v2 1/2] rtc: bq32k: Use correct mask name for 'minutes' register.
Quoted 6 lines · Daniel Romell
From: Jan =C3=96stlund <[email protected]>
=20
TheBQ32K_SECONDS_MASKandBQ32K_MINUTES_MASKboth has the same value. This is no functional change.
=20Signed-off-by Daniel Romell <[email protected]>
Sorry, I saw it only before trying apply but both patches also need Jan's S= oB.
drivers/rtc/rtc-bq32k.c static int bq32k_rtc_read_time(struct device *dev, stru=
Quoted 9 lines
--- drivers/rtc/rtc-bq32k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)=20
drivers/rtc/rtc-bq32k.c +0
-0@@ -94,7 +94,7 @@ static int bq32k_rtc_read_time(struct device *dev, stru=
ct rtc_time *tm)
Quoted 11 lines
drivers/rtc/rtc-bq32k.c +0
-0return error;=20
drivers/rtc/rtc-bq32k.c +1
-2tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); - tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_SECONDS_MASK); + tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK); tm->tm_mday =3D bcd2bin(regs.date); tm->tm_wday =3D bcd2bin(regs.day) - 1; --=202.7.4
=20
--=20
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
[rtc-linux] Re: [PATCH v2 1/2] rtc: bq32k: Use correct mask name for 'minutes' register.
Den torsdag 11 augusti 2016 kl. 15:42:58 UTC+2 skrev alexandre.belloni:
Quoted 12 lines · Daniel Romell
Quoted 6 lines
From: Jan Östlund <[email protected] <javascript:>>
The
BQ32K_SECONDS_MASKandBQ32K_MINUTES_MASKboth has the same value. This is no functional change.Signed-off-by Daniel Romell <[email protected] <javascript:>>Sorry, I saw it only before trying apply but both patches also need Jan's SoB.
Ah, sorry, my bad. I'll ask him to add that.
Is it ok if he just reply to the emails with his SoB line, or do you need a new patch set?
Quoted 28 lines
drivers/rtc/rtc-bq32k.c static int bq32k_rtc_read_time(struct device *dev,
Quoted 10 lines
---
drivers/rtc/rtc-bq32k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/rtc/rtc-bq32k.c +0
-0@@ -94,7 +94,7 @@ static int bq32k_rtc_read_time(struct device *dev,struct
rtc_time*tm)Quoted 11 lines
drivers/rtc/rtc-bq32k.c +1
-1return error; tm->tm_sec =bcd2bin (regs.seconds &BQ32K_SECONDS_MASK ); - tm->tm_min =bcd2bin (regs.minutes &BQ32K_SECONDS_MASK ); + tm->tm_min =bcd2bin (regs.minutes &BQ32K_MINUTES_MASK ); tm->tm_hour =bcd2bin (regs.cent_hours &BQ32K_HOURS_MASK ); tm->tm_mday =bcd2bin (regs.date); tm->tm_wday =bcd2bin (regs.day) -1 ;Signature · 1 line
2.7.4Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Signature · 8 lines
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. --- You received this message because you are subscribed to the Google Groups "rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
Re: [rtc-linux] Re: [PATCH v2 1/2] rtc: bq32k: Use correct mask name for 'minutes' register.
Quoted 12 lines · On 11/08/2016 at 07:56:03 -0700, [email protected] wrote :
Den torsdag 11 augusti 2016 kl. 15:42:58 UTC+2 skrev alexandre.belloni:
Quoted 9 lines · Daniel Romell
Quoted 6 lines
From: Jan Östlund <[email protected] <javascript:>>
The
BQ32K_SECONDS_MASKandBQ32K_MINUTES_MASKboth has the same value. This is no functional change.Signed-off-by Daniel Romell <[email protected] <javascript:>>
Quoted 8 lines
Quoted 3 lines
Sorry, I saw it only before trying apply but both patches also need Jan's SoB.
Ah, sorry, my bad. I'll ask him to add that.
Is it ok if he just reply to the emails with his SoB line, or do you need a new patch set?
That's a bit unconventional but I'm fine with a simple mail.
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
RE: [PATCH v2 1/2] rtc: bq32k: Use correct mask name for 'minutes' register.
In reply to Daniel Romell-----Original Message-----
From: Daniel Romell [mailto:[email protected]]=20
Sent: den 11 augusti 2016 13:32
To: [email protected]
Cc: [email protected]; [email protected]; linux= [email protected]; Daniel Romell <[email protected]>; Jan =C3=96stlund <jao= @hms.se>; Magnus Olsson <[email protected]>
Subject: [PATCH v2 1/2] rtc: bq32k: Use correct mask name for 'minutes' reg= ister.
From: Jan =C3=96stlund <[email protected]>
The BQ32K_SECONDS_MASK and BQ32K_MINUTES_MASK both has the same value. This is no functional change.
--- drivers/rtc/rtc-bq32k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-bq32k.c +0 -0
@@ -94,7 +94,7 @@ static int bq32k_rtc_read_time(struct device *dev, struct= rtc_time *tm)return error;
=20
tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
- tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_SECONDS_MASK);
+ tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK); tm->tm_mday =3D bcd2bin(regs.date);
tm->tm_wday =3D bcd2bin(regs.day) - 1;
--=20
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
PATCH v2 2/2 rtc: bq32k: Fix handling of oscillator failure flag
In reply to Daniel RomellFrom: Jan =C3=96stlund <[email protected]>
While the oscillator failure flag is set, the RTC registers should be considered invalid. bq32k_rtc_read_time() now returns an error instead of an invalid time.
The failure flag is cleared the next time the clock is set.
--- drivers/rtc/rtc-bq32k.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/rtc/rtc-bq32k.c +0 -0
@@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struc=
t rtc_time *tm)
if (error)
return error;
=20
+ /*
+ * In case of oscillator failure, the register contents should be
+ * considered invalid. The flag is cleared the next time the RTC is set.
+ */
+ if (regs.minutes & BQ32K_OF)
+ return -EINVAL;
+
tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
@@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client, =20
/* Check Oscillator Failure flag */
error =3D bq32k_read(dev, ®, BQ32K_MINUTES, 1);
- if (!error && (reg & BQ32K_OF)) {
- dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
- reg &=3D ~BQ32K_OF;
- error =3D bq32k_write(dev, ®, BQ32K_MINUTES, 1);
- }
if (error)
return error;
+ if (reg & BQ32K_OF)
+ dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
=20
if (client->dev.of_node)
trickle_charger_of_init(dev, client->dev.of_node);
--=20
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.
RE: [PATCH v2 2/2] rtc: bq32k: Fix handling of oscillator failure flag
-----Original Message-----
From: Daniel Romell [mailto:[email protected]]=20
Sent: den 11 augusti 2016 13:32
To: [email protected]
Cc: [email protected]; [email protected]; linux= [email protected]; Daniel Romell <[email protected]>; Jan =C3=96stlund <jao= @hms.se>; Magnus Olsson <[email protected]>
Subject: [PATCH v2 2/2] rtc: bq32k: Fix handling of oscillator failure flag
From: Jan =C3=96stlund <[email protected]>
While the oscillator failure flag is set, the RTC registers should be considered invalid. bq32k_rtc_read_time() now returns an error instead of an invalid time.
The failure flag is cleared the next time the clock is set.
--- drivers/rtc/rtc-bq32k.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/rtc/rtc-bq32k.c +0 -0
@@ -93,6 +93,13 @@ static int bq32k_rtc_read_time(struct device *dev, struc=
t rtc_time *tm)
if (error)
return error;
=20
+ /*
+ * In case of oscillator failure, the register contents should be
+ * considered invalid. The flag is cleared the next time the RTC is set.
+ */
+ if (regs.minutes & BQ32K_OF)
+ return -EINVAL;
+
tm->tm_sec =3D bcd2bin(regs.seconds & BQ32K_SECONDS_MASK); tm->tm_min =3D bcd2bin(regs.minutes & BQ32K_MINUTES_MASK); tm->tm_hour =3D bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
@@ -204,13 +211,10 @@ static int bq32k_probe(struct i2c_client *client, =20
/* Check Oscillator Failure flag */
error =3D bq32k_read(dev, ®, BQ32K_MINUTES, 1);
- if (!error && (reg & BQ32K_OF)) {
- dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
- reg &=3D ~BQ32K_OF;
- error =3D bq32k_write(dev, ®, BQ32K_MINUTES, 1);
- }
if (error)
return error;
+ if (reg & BQ32K_OF)
+ dev_warn(dev, "Oscillator Failure. Check RTC battery.\n");
=20
if (client->dev.of_node)
trickle_charger_of_init(dev, client->dev.of_node);
--=20
2.7.4
--=20
You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "= rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected].
For more options, visit https://groups.google.com/d/optout.