U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Add support for two RTCs
@ 2025-11-14 15:12 Michael Walle
  2025-11-14 15:12 ` [PATCH 1/2] drivers: rtc: add PCF85063 support Michael Walle
  2025-11-14 15:12 ` [PATCH 2/2] drivers: rtc: add RV3032 support Michael Walle
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Walle @ 2025-11-14 15:12 UTC (permalink / raw)
  To: Tom Rini; +Cc: u-boot, Michael Walle

I'll soon post support for the Kontron SMARC-sAM67 u-boot support.
I'm still waiting for the linux device trees to be merged (in -next
right now) and then to be synced to the u-boot tree. That board
features two different RTCs and this will already support for these.

You can find the device tree at [1]. RTC nodes are in the overlays,
though there is none for the RV3032 at the moment.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/arch/arm64/boot/dts/ti/k3-am67a-kontron-sa67-base.dts

Michael Walle (2):
  drivers: rtc: add PCF85063 support
  drivers: rtc: add RV3032 support

 drivers/rtc/Kconfig    |  15 +++++
 drivers/rtc/Makefile   |   2 +
 drivers/rtc/pcf85063.c | 107 ++++++++++++++++++++++++++++++++++++
 drivers/rtc/rv3032.c   | 121 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 245 insertions(+)
 create mode 100644 drivers/rtc/pcf85063.c
 create mode 100644 drivers/rtc/rv3032.c

-- 
2.47.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] drivers: rtc: add PCF85063 support
  2025-11-14 15:12 [PATCH 0/2] Add support for two RTCs Michael Walle
@ 2025-11-14 15:12 ` Michael Walle
  2025-11-14 15:22   ` Tom Rini
  2025-11-14 15:12 ` [PATCH 2/2] drivers: rtc: add RV3032 support Michael Walle
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Walle @ 2025-11-14 15:12 UTC (permalink / raw)
  To: Tom Rini; +Cc: u-boot, Michael Walle

Add support for the Microcrystal RV8263 and compatible RTCs. The
driver's name was taken from linux. It should work with any NXP PCF85063
compatible RTCs. It was tested with a RV8263.

Signed-off-by: Michael Walle <mwalle@kernel.org>
---
 drivers/rtc/Kconfig    |   8 +++
 drivers/rtc/Makefile   |   1 +
 drivers/rtc/pcf85063.c | 107 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 drivers/rtc/pcf85063.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index ed903999f06..2336f2e57c9 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -161,6 +161,14 @@ config RTC_MAX313XX
 	  - Temperature sensor
 	  - CLKOUT generation
 
+config RTC_PCF85063
+	tristate "Enable PCF85063 driver"
+	depends on DM_I2C
+	depends on DM_RTC
+	help
+	  If you say yes here you get support for the NXP PCF85063 RTC
+	  and compatible chips.
+
 config RTC_PCF8563
 	tristate "Philips PCF8563"
 	help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index a4ede413cd1..9d84aa836a1 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_RTC_MC146818) += mc146818.o
 obj-$(CONFIG_MCFRTC) += mcfrtc.o
 obj-$(CONFIG_RTC_MV) += mvrtc.o
 obj-$(CONFIG_RTC_MXS) += mxsrtc.o
+obj-$(CONFIG_RTC_PCF85063) += pcf85063.o
 obj-$(CONFIG_RTC_PCF8563) += pcf8563.o
 obj-$(CONFIG_RTC_PCF2127) += pcf2127.o
 obj-$(CONFIG_RTC_PL031) += pl031.o
diff --git a/drivers/rtc/pcf85063.c b/drivers/rtc/pcf85063.c
new file mode 100644
index 00000000000..737d4547aca
--- /dev/null
+++ b/drivers/rtc/pcf85063.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * PCF85063 and compatible I2C RTC driver
+ *
+ * Copyright (c) 2025 Kontron Europe GmbH.
+ */
+
+#include <dm.h>
+#include <i2c.h>
+#include <rtc.h>
+#include <dm/device_compat.h>
+
+#define PCF85063_REG_CTRL1		0x00 /* status */
+#define PCF85063_REG_CTRL1_SR		0x58
+
+#define PCF85063_REG_SC			0x04 /* datetime */
+#define PCF85063_REG_SC_OS		0x80
+
+static int pcf85063_get_time(struct udevice *dev, struct rtc_time *tm)
+{
+	u8 regs[7];
+	int ret;
+
+	ret = dm_i2c_read(dev, PCF85063_REG_SC, regs, sizeof(regs));
+	if (ret)
+		return ret;
+
+	if (regs[0] & PCF85063_REG_SC_OS) {
+		dev_err(dev, "Power loss detected, Invalid time\n");
+		return -EINVAL;
+	}
+
+	tm->tm_sec = bcd2bin(regs[0] & 0x7f);
+	tm->tm_min = bcd2bin(regs[1] & 0x7f);
+	tm->tm_hour = bcd2bin(regs[2] & 0x3f);
+	tm->tm_mday = bcd2bin(regs[3] & 0x3f);
+	tm->tm_wday = regs[4] & 0x07;
+	tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1;
+	tm->tm_year = bcd2bin(regs[6]) + 2000;
+
+	return 0;
+}
+
+static int pcf85063_set_time(struct udevice *dev, const struct rtc_time *tm)
+{
+	u8 regs[7];
+
+	if (tm->tm_year < 2000 || tm->tm_year > 2099) {
+		dev_err(dev, "Year must be between 2000 and 2099.\n");
+		return -EINVAL;
+	}
+
+	regs[0] = bin2bcd(tm->tm_sec);
+	regs[1] = bin2bcd(tm->tm_min);
+	regs[2] = bin2bcd(tm->tm_hour);
+	regs[3] = bin2bcd(tm->tm_mday);
+	regs[4] = tm->tm_wday;
+	regs[5] = bin2bcd(tm->tm_mon + 1);
+	regs[6] = bin2bcd(tm->tm_year % 100);
+
+	return dm_i2c_write(dev, PCF85063_REG_SC, regs, sizeof(regs));
+}
+
+static int pcf85063_reset(struct udevice *dev)
+{
+	return dm_i2c_reg_write(dev, PCF85063_REG_CTRL1, PCF85063_REG_CTRL1_SR);
+}
+
+static int pcf85063_read(struct udevice *dev, unsigned int offset, u8 *buf,
+			 unsigned int len)
+{
+	return dm_i2c_read(dev, offset, buf, len);
+}
+
+static int pcf85063_write(struct udevice *dev, unsigned int offset,
+			  const u8 *buf, unsigned int len)
+{
+	return dm_i2c_write(dev, offset, buf, len);
+}
+
+static const struct rtc_ops pcf85063_rtc_ops = {
+	.get = pcf85063_get_time,
+	.set = pcf85063_set_time,
+	.reset = pcf85063_reset,
+	.read = pcf85063_read,
+	.write = pcf85063_write,
+};
+
+static int pcf85063_probe(struct udevice *dev)
+{
+	i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS);
+
+	return 0;
+}
+
+static const struct udevice_id pcf85063_of_id[] = {
+	{ .compatible = "microcrystal,rv8263" },
+	{ }
+};
+
+U_BOOT_DRIVER(rtc_pcf85063) = {
+	.name	= "rtc-pcf85063",
+	.id     = UCLASS_RTC,
+	.probe  = pcf85063_probe,
+	.of_match = pcf85063_of_id,
+	.ops    = &pcf85063_rtc_ops,
+};
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] drivers: rtc: add RV3032 support
  2025-11-14 15:12 [PATCH 0/2] Add support for two RTCs Michael Walle
  2025-11-14 15:12 ` [PATCH 1/2] drivers: rtc: add PCF85063 support Michael Walle
@ 2025-11-14 15:12 ` Michael Walle
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Walle @ 2025-11-14 15:12 UTC (permalink / raw)
  To: Tom Rini; +Cc: u-boot, Michael Walle

Add support for the Microcrystal RV3032 RTC.

Signed-off-by: Michael Walle <mwalle@kernel.org>
---
 drivers/rtc/Kconfig  |   7 +++
 drivers/rtc/Makefile |   1 +
 drivers/rtc/rv3032.c | 121 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 drivers/rtc/rv3032.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 2336f2e57c9..c6c6a02221a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -194,6 +194,13 @@ config RTC_RV3029
 	  This driver supports reading and writing the RTC/calendar and the
 	  battery-baced SRAM section.
 
+config RTC_RV3032
+	bool "Enable RV3032 driver"
+	depends on DM_RTC
+	help
+	  If you say yes here you get support for the Micro Crystal RV3032
+	  RTC.
+
 config RTC_RV8803
 	bool "Enable RV8803 driver"
 	depends on DM_RTC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 9d84aa836a1..9df373d5148 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_RTC_PL031) += pl031.o
 obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
 obj-$(CONFIG_RTC_RV3028) += rv3028.o
 obj-$(CONFIG_RTC_RV3029) += rv3029.o
+obj-$(CONFIG_RTC_RV3032) += rv3032.o
 obj-$(CONFIG_RTC_RV8803) += rv8803.o
 obj-$(CONFIG_RTC_RX8025) += rx8025.o
 obj-$(CONFIG_RTC_RX8010SJ) += rx8010sj.o
diff --git a/drivers/rtc/rv3032.c b/drivers/rtc/rv3032.c
new file mode 100644
index 00000000000..87ff5204e73
--- /dev/null
+++ b/drivers/rtc/rv3032.c
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Micro Crystal RV3032 I2C RTC driver
+ *
+ * Copyright (c) 2025 Kontron Europe GmbH.
+ */
+
+#include <dm.h>
+#include <i2c.h>
+#include <rtc.h>
+#include <dm/device_compat.h>
+
+#define RV3032_REG_SEC			0x01
+#define RV3032_REG_STATUS		0x0d
+#define RV3032_REG_STATUS_VLF		BIT(0)
+#define RV3032_REG_STATUS_PORF		BIT(1)
+
+static int rv3032_get_time(struct udevice *dev, struct rtc_time *tm)
+{
+	int ret, status;
+	u8 regs[7];
+
+	status = dm_i2c_reg_read(dev, RV3032_REG_STATUS);
+	if (status < 0)
+		return status;
+
+	if (status & (RV3032_REG_STATUS_PORF | RV3032_REG_STATUS_VLF)) {
+		dev_err(dev, "Power loss detected, Invalid time\n");
+		return -EINVAL;
+	}
+
+	ret = dm_i2c_read(dev, RV3032_REG_SEC, regs, sizeof(regs));
+	if (ret)
+		return ret;
+
+	tm->tm_sec = bcd2bin(regs[0] & 0x7f);
+	tm->tm_min = bcd2bin(regs[1] & 0x7f);
+	tm->tm_hour = bcd2bin(regs[2] & 0x3f);
+	tm->tm_mday = bcd2bin(regs[3] & 0x3f);
+	tm->tm_wday = regs[4] & 0x07;
+	tm->tm_mon = bcd2bin(regs[5] & 0x1f) - 1;
+	tm->tm_year = bcd2bin(regs[6]) + 2000;
+
+	return 0;
+}
+
+static int rv3032_set_time(struct udevice *dev, const struct rtc_time *tm)
+{
+	u8 regs[7];
+	int ret;
+
+	if (tm->tm_year < 2000 || tm->tm_year > 2099) {
+		dev_err(dev, "Year must be between 2000 and 2099.\n");
+		return -EINVAL;
+	}
+
+	regs[0] = bin2bcd(tm->tm_sec);
+	regs[1] = bin2bcd(tm->tm_min);
+	regs[2] = bin2bcd(tm->tm_hour);
+	regs[3] = bin2bcd(tm->tm_mday);
+	regs[4] = tm->tm_wday;
+	regs[5] = bin2bcd(tm->tm_mon + 1);
+	regs[6] = bin2bcd(tm->tm_year % 100);
+
+	ret = dm_i2c_write(dev, RV3032_REG_SEC, regs, sizeof(regs));
+	if (ret)
+		return ret;
+
+	return dm_i2c_reg_clrset(dev, RV3032_REG_STATUS,
+				 RV3032_REG_STATUS_PORF | RV3032_REG_STATUS_VLF,
+				 0);
+}
+
+static int rv3032_read(struct udevice *dev, unsigned int offset, u8 *buf,
+		       unsigned int len)
+{
+	return dm_i2c_read(dev, offset, buf, len);
+}
+
+static int rv3032_write(struct udevice *dev, unsigned int offset,
+			const u8 *buf, unsigned int len)
+{
+	return dm_i2c_write(dev, offset, buf, len);
+}
+
+static int rv3032_reset(struct udevice *dev)
+{
+	/*
+	 * There is no reset, but the "date reset" command needs this op to
+	 * actually set the default time
+	 */
+	return 0;
+}
+
+static const struct rtc_ops rv3032_rtc_ops = {
+	.get = rv3032_get_time,
+	.set = rv3032_set_time,
+	.read = rv3032_read,
+	.write = rv3032_write,
+	.reset = rv3032_reset,
+};
+
+static int rv3032_probe(struct udevice *dev)
+{
+	i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS | DM_I2C_CHIP_WR_ADDRESS);
+
+	return 0;
+}
+
+static const struct udevice_id rv3032_of_id[] = {
+	{ .compatible = "microcrystal,rv3032" },
+	{ }
+};
+
+U_BOOT_DRIVER(rtc_rv3032) = {
+	.name	= "rtc-rv3032",
+	.id     = UCLASS_RTC,
+	.probe  = rv3032_probe,
+	.of_match = rv3032_of_id,
+	.ops    = &rv3032_rtc_ops,
+};
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drivers: rtc: add PCF85063 support
  2025-11-14 15:12 ` [PATCH 1/2] drivers: rtc: add PCF85063 support Michael Walle
@ 2025-11-14 15:22   ` Tom Rini
  2025-11-17  8:13     ` Michael Walle
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Rini @ 2025-11-14 15:22 UTC (permalink / raw)
  To: Michael Walle; +Cc: u-boot

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

On Fri, Nov 14, 2025 at 04:12:47PM +0100, Michael Walle wrote:

> Add support for the Microcrystal RV8263 and compatible RTCs. The
> driver's name was taken from linux. It should work with any NXP PCF85063
> compatible RTCs. It was tested with a RV8263.
> 
> Signed-off-by: Michael Walle <mwalle@kernel.org>
> ---
>  drivers/rtc/Kconfig    |   8 +++
>  drivers/rtc/Makefile   |   1 +
>  drivers/rtc/pcf85063.c | 107 +++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 116 insertions(+)
>  create mode 100644 drivers/rtc/pcf85063.c
> 
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index ed903999f06..2336f2e57c9 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -161,6 +161,14 @@ config RTC_MAX313XX
>  	  - Temperature sensor
>  	  - CLKOUT generation
>  
> +config RTC_PCF85063
> +	tristate "Enable PCF85063 driver"

tristate is wrong for U-Boot, only bool is meaningful (and I need to go
update checkpatch.pl to complain about this). This is I assume otherwise
checkpatch warning free and compiles on sandbox?

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drivers: rtc: add PCF85063 support
  2025-11-14 15:22   ` Tom Rini
@ 2025-11-17  8:13     ` Michael Walle
  2025-11-17 13:30       ` Tom Rini
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Walle @ 2025-11-17  8:13 UTC (permalink / raw)
  To: Tom Rini; +Cc: u-boot

[-- Attachment #1: Type: text/plain, Size: 498 bytes --]

>> +config RTC_PCF85063
>> +	tristate "Enable PCF85063 driver"
>
> tristate is wrong for U-Boot, only bool is meaningful (and I need to go
> update checkpatch.pl to complain about this).

Yeah, sorry, This was a copy and paste error from the very next
config entry. I'll fix it in v2 and add a patch to convert the
existing tristate to bool.

> This is I assume otherwise
> checkpatch warning free and compiles on sandbox?

Yeah, except for the missing maintainers entry.

-michael

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 297 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drivers: rtc: add PCF85063 support
  2025-11-17  8:13     ` Michael Walle
@ 2025-11-17 13:30       ` Tom Rini
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Rini @ 2025-11-17 13:30 UTC (permalink / raw)
  To: Michael Walle; +Cc: u-boot

[-- Attachment #1: Type: text/plain, Size: 605 bytes --]

On Mon, Nov 17, 2025 at 09:13:36AM +0100, Michael Walle wrote:
> >> +config RTC_PCF85063
> >> +	tristate "Enable PCF85063 driver"
> >
> > tristate is wrong for U-Boot, only bool is meaningful (and I need to go
> > update checkpatch.pl to complain about this).
> 
> Yeah, sorry, This was a copy and paste error from the very next
> config entry. I'll fix it in v2 and add a patch to convert the
> existing tristate to bool.
> 
> > This is I assume otherwise
> > checkpatch warning free and compiles on sandbox?
> 
> Yeah, except for the missing maintainers entry.

OK, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-17 13:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 15:12 [PATCH 0/2] Add support for two RTCs Michael Walle
2025-11-14 15:12 ` [PATCH 1/2] drivers: rtc: add PCF85063 support Michael Walle
2025-11-14 15:22   ` Tom Rini
2025-11-17  8:13     ` Michael Walle
2025-11-17 13:30       ` Tom Rini
2025-11-14 15:12 ` [PATCH 2/2] drivers: rtc: add RV3032 support Michael Walle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox