* [rtc-linux] [PATCH] rtc: pcf85063: Add support for the PCF85063A device
@ 2016-07-12 21:15 Chris DeBruin
2016-07-19 17:03 ` [rtc-linux] " Alexandre Belloni
0 siblings, 1 reply; 2+ messages in thread
From: Chris DeBruin @ 2016-07-12 21:15 UTC (permalink / raw)
To: a.zummo, alexandre.belloni; +Cc: rtc-linux, Chris DeBruin
The current rtc-pcf85063 driver only supports the PCF85063TP device.
Using the existing driver on a PCF85063A will result in the time being
set correctly into the RTC, but the RTC is held in the stopped state.
Therefore, the time will no longer advance and no error is indicated.
The PCF85063A device has a bigger memory map than the PCF85063TP.
The existing driver make use of an address rollover condition,
but the rollover point is different in the two devices.
Signed-off-by: Chris DeBruin <cdeb5783@gmail.com>
---
drivers/rtc/rtc-pcf85063.c | 48 +++++++++++++++++++++++++++++++++++++-----=
----
1 file changed, 39 insertions(+), 9 deletions(-)
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index e8ddbb359..95b2b97 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -16,6 +16,17 @@
#include <linux/rtc.h>
#include <linux/module.h>
=20
+/*
+ * Information for this driver was pulled from the following datasheets.
+ *
+ * http://www.nxp.com/documents/data_sheet/PCF85063A.pdf
+ * http://www.nxp.com/documents/data_sheet/PCF85063TP.pdf
+ *
+ * PCF85063A -- Rev. 6 =E2=80=94 18 November 2015
+ * PCF85063TP -- Rev. 4 =E2=80=94 6 May 2015
+*/
+
+
#define PCF85063_REG_CTRL1 0x00 /* status */
#define PCF85063_REG_CTRL1_STOP BIT(5)
#define PCF85063_REG_CTRL2 0x01
@@ -55,6 +66,22 @@ static int pcf85063_stop_clock(struct i2c_client *client=
, u8 *ctrl1)
return 0;
}
=20
+static int pcf85063_start_clock(struct i2c_client *client, u8 ctrl1)
+{
+ s32 ret;
+
+ /* start the clock */
+ ctrl1 &=3D PCF85063_REG_CTRL1_STOP;
+
+ ret =3D i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1);
+ if (ret < 0) {
+ dev_err(&client->dev, "Failing to start the clock\n");
+ return -EIO;
+ }
+
+ return 0;
+}
+
/*
* In the routines that deal directly with the pcf85063 hardware, we use
* rtc_time -- month 0-11, hour 0-23, yr =3D calendar year-epoch.
@@ -99,13 +126,14 @@ static int pcf85063_get_datetime(struct i2c_client *cl=
ient, struct rtc_time *tm)
static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_tim=
e *tm)
{
int rc;
- u8 regs[8];
+ u8 regs[7];
+ u8 ctrl1;
=20
/*
* to accurately set the time, reset the divider chain and keep it in
* reset state until all time/date registers are written
*/
- rc =3D pcf85063_stop_clock(client, ®s[7]);
+ rc =3D pcf85063_stop_clock(client, &ctrl1);
if (rc !=3D 0)
return rc;
=20
@@ -127,13 +155,6 @@ static int pcf85063_set_datetime(struct i2c_client *cl=
ient, struct rtc_time *tm)
/* year and century */
regs[6] =3D bin2bcd(tm->tm_year % 100);
=20
- /*
- * after all time/date registers are written, let the 'address auto
- * increment' feature wrap around and write register CTRL1 to re-enable
- * the clock divider chain again
- */
- regs[7] &=3D ~PCF85063_REG_CTRL1_STOP;
-
/* write all registers at once */
rc =3D i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC,
sizeof(regs), regs);
@@ -142,6 +163,15 @@ static int pcf85063_set_datetime(struct i2c_client *cl=
ient, struct rtc_time *tm)
return rc;
}
=20
+ /*
+ * Write the control register as a seperate action since the size of
+ * the register space is different between the PCF85063TP and
+ * PCF85063A devices. The rollover point can not be used.
+ */
+ rc =3D pcf85063_start_clock(client, ctrl1);
+ if (rc !=3D 0)
+ return rc;
+
return 0;
}
=20
--=20
1.9.1
--=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 rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [rtc-linux] Re: [PATCH] rtc: pcf85063: Add support for the PCF85063A device
2016-07-12 21:15 [rtc-linux] [PATCH] rtc: pcf85063: Add support for the PCF85063A device Chris DeBruin
@ 2016-07-19 17:03 ` Alexandre Belloni
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2016-07-19 17:03 UTC (permalink / raw)
To: Chris DeBruin; +Cc: a.zummo, rtc-linux
On 12/07/2016 at 17:15:46 -0400, Chris DeBruin wrote :
> The current rtc-pcf85063 driver only supports the PCF85063TP device.
> Using the existing driver on a PCF85063A will result in the time being
> set correctly into the RTC, but the RTC is held in the stopped state.
> Therefore, the time will no longer advance and no error is indicated.
>
> The PCF85063A device has a bigger memory map than the PCF85063TP.
> The existing driver make use of an address rollover condition,
> but the rollover point is different in the two devices.
>
> Signed-off-by: Chris DeBruin <cdeb5783@gmail.com>
> ---
> drivers/rtc/rtc-pcf85063.c | 48 +++++++++++++++++++++++++++++++++++++---------
> 1 file changed, 39 insertions(+), 9 deletions(-)
>
Applied after fixing some whitespace issues, thanks.
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
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 rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-19 17:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-12 21:15 [rtc-linux] [PATCH] rtc: pcf85063: Add support for the PCF85063A device Chris DeBruin
2016-07-19 17:03 ` [rtc-linux] " Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox