* [PATCH] rtc: ds1307: check for oscillator fault on ds1388
@ 2019-11-07 1:12 Chris Packham
2019-11-07 10:24 ` Alexandre Belloni
0 siblings, 1 reply; 2+ messages in thread
From: Chris Packham @ 2019-11-07 1:12 UTC (permalink / raw)
To: a.zummo, alexandre.belloni
Cc: linux-rtc, linux-kernel, John Collis, Chris Packham
Ensure that the oscillator is running and check the OSF bit for the
ds1388 variant. The FLAG and CONTROL registers are at a different
location to the other supported RTCs so this requires an extra case in
the existing switch statement.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/rtc/rtc-ds1307.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 1f7e8aefc1eb..865c06347d0a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -101,6 +101,10 @@ enum ds_type {
# define DS1337_BIT_A2I 0x02
# define DS1337_BIT_A1I 0x01
#define DS1339_REG_ALARM1_SECS 0x07
+#define DS1388_REG_FLAG 0x0b
+# define DS1388_BIT_OSF 0x80
+#define DS1388_REG_CONTROL 0x0c
+# define DS1388_BIT_nEOSC 0x80
#define DS13XX_TRICKLE_CHARGER_MAGIC 0xa0
@@ -1688,6 +1692,26 @@ static int ds1307_probe(struct i2c_client *client,
}
break;
+ case ds_1388:
+ err = regmap_bulk_read(ds1307->regmap, DS1388_REG_FLAG,
+ regs, 2);
+ if (err) {
+ dev_dbg(ds1307->dev, "read error %d\n", err);
+ goto exit;
+ }
+
+ if (regs[1] & DS1388_BIT_nEOSC) {
+ regmap_write(ds1307->regmap, DS1388_REG_CONTROL,
+ regs[1] & ~DS1388_BIT_nEOSC);
+ }
+
+ if (regs[0] & DS1388_BIT_OSF) {
+ regmap_write(ds1307->regmap, DS1388_REG_FLAG,
+ regs[0] & ~DS1388_BIT_OSF);
+ dev_warn(ds1307->dev, "SET TIME!\n");
+ }
+ break;
+
case rx_8025:
err = regmap_bulk_read(ds1307->regmap,
RX8025_REG_CTRL1 << 4 | 0x08, regs, 2);
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] rtc: ds1307: check for oscillator fault on ds1388
2019-11-07 1:12 [PATCH] rtc: ds1307: check for oscillator fault on ds1388 Chris Packham
@ 2019-11-07 10:24 ` Alexandre Belloni
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2019-11-07 10:24 UTC (permalink / raw)
To: Chris Packham; +Cc: a.zummo, linux-rtc, linux-kernel, John Collis
Hi,
On 07/11/2019 14:12:45+1300, Chris Packham wrote:
> Ensure that the oscillator is running and check the OSF bit for the
> ds1388 variant. The FLAG and CONTROL registers are at a different
> location to the other supported RTCs so this requires an extra case in
> the existing switch statement.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> drivers/rtc/rtc-ds1307.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
> index 1f7e8aefc1eb..865c06347d0a 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -101,6 +101,10 @@ enum ds_type {
> # define DS1337_BIT_A2I 0x02
> # define DS1337_BIT_A1I 0x01
> #define DS1339_REG_ALARM1_SECS 0x07
> +#define DS1388_REG_FLAG 0x0b
> +# define DS1388_BIT_OSF 0x80
> +#define DS1388_REG_CONTROL 0x0c
> +# define DS1388_BIT_nEOSC 0x80
>
> #define DS13XX_TRICKLE_CHARGER_MAGIC 0xa0
>
> @@ -1688,6 +1692,26 @@ static int ds1307_probe(struct i2c_client *client,
> }
> break;
>
> + case ds_1388:
> + err = regmap_bulk_read(ds1307->regmap, DS1388_REG_FLAG,
> + regs, 2);
> + if (err) {
> + dev_dbg(ds1307->dev, "read error %d\n", err);
> + goto exit;
> + }
> +
> + if (regs[1] & DS1388_BIT_nEOSC) {
> + regmap_write(ds1307->regmap, DS1388_REG_CONTROL,
> + regs[1] & ~DS1388_BIT_nEOSC);
> + }
> +
> + if (regs[0] & DS1388_BIT_OSF) {
> + regmap_write(ds1307->regmap, DS1388_REG_FLAG,
> + regs[0] & ~DS1388_BIT_OSF);
> + dev_warn(ds1307->dev, "SET TIME!\n");
This is not the correct way to handle that. This information is valuable
in .read_time where you should return -EINVAL when the time is know to
be invalid. Then the bit can be reset in .set_time.
--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-07 10:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 1:12 [PATCH] rtc: ds1307: check for oscillator fault on ds1388 Chris Packham
2019-11-07 10:24 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).