Skip to contentSkip to conversation

rtc: m41t62: Convert the m41t62 driver to use driver model (DM)

PATCH Superseded Lukasz Majewski 4 participants 19 messages Nov 21, 2018 – Dec 3, 2018 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

cover rtc: m41t62: Convert the m41t62 driver to use driver model (DM)

This series enables using this driver with DM aware boards

Dependency:
"ARM: pinctrl: Provide pinctrl driver for Vybrid (vf610)"
https://patchwork.ozlabs.org/project/uboot/list/?series=76877

Changes in v1:
- New

Lukasz Majewski (3):
Kconfig: Migrate CONFIG_RTC_M41T62 define to Kconfig
rtc: m41t62: Break i2c_write() arguments to fix checkpatch warning
rtc: m41t62: Convert the RTC driver to support the driver model (DM)

 configs/bk4r1_defconfig      |  1 +
 configs/m53menlo_defconfig   |  1 +
 configs/pcm052_defconfig     |  1 +
 configs/x600_defconfig       |  1 +
 drivers/rtc/Kconfig          |  6 ++++
 drivers/rtc/m41t62.c         | 74 ++++++++++++++++++++++++++++++++++++++++++--
 include/configs/m53menlo.h   |  1 -
 include/configs/pcm052.h     |  1 -
 include/configs/x600.h       |  1 -
 scripts/config_whitelist.txt |  1 -
 10 files changed, 82 insertions(+), 6 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 Kconfig: Migrate CONFIG_RTC_M41T62 define to Kconfig

This patch moves the RTC M41T62 config define to Kconfig.

---

Changes in v1: None

 configs/bk4r1_defconfig      | 1 +
 configs/m53menlo_defconfig   | 1 +
 configs/pcm052_defconfig     | 1 +
 configs/x600_defconfig       | 1 +
 drivers/rtc/Kconfig          | 6 ++++++
 include/configs/m53menlo.h   | 1 -
 include/configs/pcm052.h     | 1 -
 include/configs/x600.h       | 1 -
 scripts/config_whitelist.txt | 1 -
 9 files changed, 10 insertions(+), 4 deletions(-)
configs/bk4r1_defconfig +1 -0
index 03592f7d2a..32d36b4f49 100644
@@ -69,6 +69,7 @@ CONFIG_DM_ETH=y
 CONFIG_MII=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_VYBRID=y
+CONFIG_RTC_M41T62=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
 CONFIG_SPI=y
configs/m53menlo_defconfig +1 -0
index 795f8a3ebc..dd7aed324f 100644
@@ -49,6 +49,7 @@ CONFIG_NAND=y
 CONFIG_NAND_MXC=y
 CONFIG_PHYLIB=y
 CONFIG_PHY_MICREL=y
+CONFIG_RTC_M41T62=y
 CONFIG_USB=y
 CONFIG_USB_STORAGE=y
 CONFIG_USB_HOST_ETHER=y
configs/pcm052_defconfig +1 -0
index 0c8e31a9ec..e207df51a8 100644
@@ -35,5 +35,6 @@ CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_PHYLIB=y
 CONFIG_PHY_MICREL=y
 CONFIG_MII=y
+CONFIG_RTC_M41T62=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
configs/x600_defconfig +1 -0
index c8f5f66232..a96f54c737 100644
@@ -52,6 +52,7 @@ CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_MII=y
+CONFIG_RTC_M41T62=y
 CONFIG_CONS_INDEX=0
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
drivers/rtc/Kconfig +6 -0
index bcc01b135e..c27730798e 100644
@@ -94,4 +94,10 @@ config RTC_MC146818
 	  clock with a wide array of features and 50 bytes of general-purpose,
 	  battery-backed RAM. The driver supports access to the clock and RAM.
 
+config RTC_M41T62
+	bool "Enable M41T62 driver"
+	help
+	  Enable driver for ST's M41T62 compatible RTC devices (like RV-4162).
+	  It is a serial (I2C) real-time clock (RTC) with alarm.
+
 endmenu
include/configs/m53menlo.h +0 -1
index 94214b135d..3fca28da6b 100644
@@ -110,7 +110,6 @@
  * RTC
  */
 #ifdef CONFIG_CMD_DATE
-#define CONFIG_RTC_M41T62
 #define CONFIG_SYS_I2C_RTC_ADDR		0x68
 #define CONFIG_SYS_M41T11_BASE_YEAR	2000
 #endif
include/configs/pcm052.h +0 -1
index 2f00be6240..c553fa629e 100644
@@ -48,7 +48,6 @@
 #endif
 
 /* RTC (actually an RV-4162 but M41T62-compatible) */
-#define CONFIG_RTC_M41T62
 #define CONFIG_SYS_I2C_RTC_ADDR 0x68
 #define CONFIG_SYS_RTC_BUS_NUM 2
 
include/configs/x600.h +0 -1
index a6835ebbd5..639da8012c 100644
@@ -75,7 +75,6 @@
 #define CONFIG_SYS_I2C_SLAVE			0x02
 #define CONFIG_I2C_CHIPADDRESS			0x50
 
-#define CONFIG_RTC_M41T62	1
 #define CONFIG_SYS_I2C_RTC_ADDR	0x68
 
 /* FPGA config options */
scripts/config_whitelist.txt +0 -1
index 0627024e71..6d5b8c35d9 100644
@@ -1664,7 +1664,6 @@ CONFIG_RTC_DS3231
 CONFIG_RTC_FTRTC010
 CONFIG_RTC_IMXDI
 CONFIG_RTC_M41T11
-CONFIG_RTC_M41T62
 CONFIG_RTC_MC13XXX
 CONFIG_RTC_MCFRRTC
 CONFIG_RTC_MCP79411
Signature · 1 line
2.11.0
#3 lore raw

PATCH 2/3 rtc: m41t62: Break i2c_write() arguments to fix checkpatch warning

In reply to Lukasz Majewski

No functional change for this commit.

---

Changes in v1: None

 drivers/rtc/m41t62.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/m41t62.c +2 -1
index 137438389d..cc230e2b78 100644
@@ -108,7 +108,8 @@ int rtc_set(struct rtc_time *tm)
 	/* assume 20YY not 19YY */
 	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
 
-	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE)) {
+	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
+		      M41T62_DATETIME_REG_SIZE)) {
 		printf("I2C write failed in %s()\n", __func__);
 		return -1;
 	}
Signature · 1 line
2.11.0
#5 lore raw

PATCH 3/3 rtc: m41t62: Convert the RTC driver to support the driver model (DM)

In reply to Lukasz Majewski

After this change the m41t62.c can be used with RTC subsystem (i.e. date command) which uses device model (DM).

---

Changes in v1:
- New

 drivers/rtc/m41t62.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 72 insertions(+), 3 deletions(-)
drivers/rtc/m41t62.c +72 -3
index cc230e2b78..2dcc1f2a63 100644
@@ -1,5 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
+ * (C) Copyright 2018
+ * Lukasz Majewski, DENX Software Engineering, lukma at denx.de.
+ *
  * (C) Copyright 2008
  * Stefan Roese, DENX Software Engineering, sr at denx.de.
  *
@@ -15,6 +18,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <rtc.h>
 #include <i2c.h>
 
@@ -49,11 +53,23 @@
 
 #define M41T80_ALHOUR_HT	(1 << 6)	/* HT: Halt Update Bit */
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_get(struct udevice *dev, struct rtc_time *tm)
+{
+#else
 int rtc_get(struct rtc_time *tm)
 {
+#endif /* CONFIG_DM_RTC */
 	u8 buf[M41T62_DATETIME_REG_SIZE];
 
+#ifdef CONFIG_DM_RTC
+	int ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+
+	if (ret)
+		return ret;
+#else
 	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+#endif /* CONFIG_DM_RTC */
 
 	debug("%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
 	      "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
@@ -81,15 +97,28 @@ int rtc_get(struct rtc_time *tm)
 	return 0;
 }
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_set(struct udevice *dev, const struct rtc_time *tm)
+{
+#else
 int rtc_set(struct rtc_time *tm)
 {
+#endif /* CONFIG_DM_RTC */
 	u8 buf[M41T62_DATETIME_REG_SIZE];
+	int ret;
 
 	debug("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
 	      tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
 	      tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+#ifdef CONFIG_DM_RTC
+	ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+#else
+	ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
+		       M41T62_DATETIME_REG_SIZE);
+#endif /* CONFIG_DM_RTC */
+	if (ret)
+		return ret;
 
 	/* Merge time-data and register flags into buf[0..7] */
 	buf[M41T62_REG_SSEC] = 0;
@@ -108,8 +137,13 @@ int rtc_set(struct rtc_time *tm)
 	/* assume 20YY not 19YY */
 	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
 
-	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
-		      M41T62_DATETIME_REG_SIZE)) {
+#ifdef CONFIG_DM_RTC
+	ret = dm_i2c_write(dev, 0, buf, sizeof(buf));
+#else
+	ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
+			M41T62_DATETIME_REG_SIZE);
+#endif /* CONFIG_DM_RTC */
+	if (ret) {
 		printf("I2C write failed in %s()\n", __func__);
 		return -1;
 	}
@@ -117,15 +151,50 @@ int rtc_set(struct rtc_time *tm)
 	return 0;
 }
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_reset(struct udevice *dev)
+{
+#else
 void rtc_reset(void)
 {
+#endif /* CONFIG_DM_RTC */
 	u8 val;
 
 	/*
 	 * M41T82: Make sure HT (Halt Update) bit is cleared.
 	 * This bit is 0 in M41T62 so its save to clear it always.
 	 */
+#ifdef CONFIG_DM_RTC
+	int ret = dm_i2c_read(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	val &= ~M41T80_ALHOUR_HT;
+	ret |= dm_i2c_write(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	return ret;
+#else
 	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, M41T62_REG_ALARM_HOUR, 1, &val, 1);
 	val &= ~M41T80_ALHOUR_HT;
 	i2c_write(CONFIG_SYS_I2C_RTC_ADDR, M41T62_REG_ALARM_HOUR, 1, &val, 1);
+#endif /* CONFIG_DM_RTC */
 }
+
+#ifdef CONFIG_DM_RTC
+static const struct rtc_ops m41t62_rtc_ops = {
+	.get = m41t62_rtc_get,
+	.set = m41t62_rtc_set,
+	.reset = m41t62_rtc_reset,
+};
+
+static const struct udevice_id m41t62_rtc_ids[] = {
+	{ .compatible = "st,m41t62" },
+	{ .compatible = "microcrystal,rv4162" },
+	{ }
+};
+
+U_BOOT_DRIVER(rtc_m41t62) = {
+	.name	= "rtc-m41t62",
+	.id	= UCLASS_RTC,
+	.of_match = m41t62_rtc_ids,
+	.ops	= &m41t62_rtc_ops,
+};
+#endif /* CONFIG_DM_RTC */
Signature · 1 line
2.11.0
#6 lore raw

PATCH 3/3 rtc: m41t62: Convert the RTC driver to support the driver model (DM)

Quoted 59 lines · Lukasz Majewski

After this change the m41t62.c can be used with RTC subsystem (i.e. date command) which uses device model (DM).

---

Changes in v1:
- New

  drivers/rtc/m41t62.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++---
  1 file changed, 72 insertions(+), 3 deletions(-)
drivers/rtc/m41t62.c +16 -0
index cc230e2b78..2dcc1f2a63 100644
@@ -1,5 +1,8 @@
  // SPDX-License-Identifier: GPL-2.0+
  /*
+ * (C) Copyright 2018
+ * Lukasz Majewski, DENX Software Engineering, lukma at denx.de.
+ *
   * (C) Copyright 2008
   * Stefan Roese, DENX Software Engineering, sr at denx.de.
   *
@@ -15,6 +18,7 @@
 
  #include <common.h>
  #include <command.h>
+#include <dm.h>
  #include <rtc.h>
  #include <i2c.h>
 
@@ -49,11 +53,23 @@
 
  #define M41T80_ALHOUR_HT	(1 << 6)	/* HT: Halt Update Bit */
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_get(struct udevice *dev, struct rtc_time *tm)
+{
+#else
  int rtc_get(struct rtc_time *tm)
  {
+#endif /* CONFIG_DM_RTC */
  	u8 buf[M41T62_DATETIME_REG_SIZE];
 
+#ifdef CONFIG_DM_RTC
+	int ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+
+	if (ret)
+		return ret;
+#else
  	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+#endif /* CONFIG_DM_RTC */
 
  	debug("%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
  	      "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",

drivers/rtc/m41t62.c int rtc_get(struct rtc_time *tm) · line 98

Quoted 2 lines
drivers/rtc/m41t62.c +0 -0
@@ -81,15 +97,28 @@ int rtc_get(struct rtc_time *tm)
  	return 0;
  }

These #ifdef's in the function headers are a bit ugly. I personally prefer to create a common function and call this from the "old" (non-DM) function and the newly created DM function instead.

Perhaps you can rework this for all these functions (below as well) and re-submit?

Thanks,
Stefan

Quoted 85 lines
drivers/rtc/m41t62.c +46 -3
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_set(struct udevice *dev, const struct rtc_time *tm)
+{
+#else
  int rtc_set(struct rtc_time *tm)
  {
+#endif /* CONFIG_DM_RTC */
  	u8 buf[M41T62_DATETIME_REG_SIZE];
+	int ret;
 
  	debug("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
  	      tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
  	      tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+#ifdef CONFIG_DM_RTC
+	ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+#else
+	ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
+		       M41T62_DATETIME_REG_SIZE);
+#endif /* CONFIG_DM_RTC */
+	if (ret)
+		return ret;
 
  	/* Merge time-data and register flags into buf[0..7] */
  	buf[M41T62_REG_SSEC] = 0;
@@ -108,8 +137,13 @@ int rtc_set(struct rtc_time *tm)
  	/* assume 20YY not 19YY */
  	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
 
-	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
-		      M41T62_DATETIME_REG_SIZE)) {
+#ifdef CONFIG_DM_RTC
+	ret = dm_i2c_write(dev, 0, buf, sizeof(buf));
+#else
+	ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
+			M41T62_DATETIME_REG_SIZE);
+#endif /* CONFIG_DM_RTC */
+	if (ret) {
  		printf("I2C write failed in %s()\n", __func__);
  		return -1;
  	}
@@ -117,15 +151,50 @@ int rtc_set(struct rtc_time *tm)
  	return 0;
  }
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_reset(struct udevice *dev)
+{
+#else
  void rtc_reset(void)
  {
+#endif /* CONFIG_DM_RTC */
  	u8 val;
 
  	/*
  	 * M41T82: Make sure HT (Halt Update) bit is cleared.
  	 * This bit is 0 in M41T62 so its save to clear it always.
  	 */
+#ifdef CONFIG_DM_RTC
+	int ret = dm_i2c_read(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	val &= ~M41T80_ALHOUR_HT;
+	ret |= dm_i2c_write(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	return ret;
+#else
  	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, M41T62_REG_ALARM_HOUR, 1, &val, 1);
  	val &= ~M41T80_ALHOUR_HT;
  	i2c_write(CONFIG_SYS_I2C_RTC_ADDR, M41T62_REG_ALARM_HOUR, 1, &val, 1);
+#endif /* CONFIG_DM_RTC */
  }
+
+#ifdef CONFIG_DM_RTC
+static const struct rtc_ops m41t62_rtc_ops = {
+	.get = m41t62_rtc_get,
+	.set = m41t62_rtc_set,
+	.reset = m41t62_rtc_reset,
+};
+
+static const struct udevice_id m41t62_rtc_ids[] = {
+	{ .compatible = "st,m41t62" },
+	{ .compatible = "microcrystal,rv4162" },

drivers/rtc/m41t62.c int rtc_set(struct rtc_time *tm) · line 200

Quoted 10 lines
drivers/rtc/m41t62.c +10 -0
+	{ }
+};
+
+U_BOOT_DRIVER(rtc_m41t62) = {
+	.name	= "rtc-m41t62",
+	.id	= UCLASS_RTC,
+	.of_match = m41t62_rtc_ids,
+	.ops	= &m41t62_rtc_ops,
+};
+#endif /* CONFIG_DM_RTC */

Viele Grüße,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#7 lore raw

v2 cover rtc: m41t62: Convert the m41t62 driver to use driver model (DM)

In reply to Lukasz Majewski

This series enables using this driver with DM aware boards

Changes in v2:
- New patch
- Extract common RTC handling code to avoid #ifdefs for CONFIG_DM_RTC
- Provide extra patch to group DM_RTC functions together (easier to maintain)

Changes in v1:
- None

Lukasz Majewski (4):
Kconfig: Migrate CONFIG_RTC_M41T62 define to Kconfig
rtc: m41t62: Break i2c_write() arguments to fix checkpatch warning
rtc: m41t62: Extract common RTC handling code to facilitate DM
conversion
rtc: m41t62: Convert the RTC driver to support the driver model (DM)

 configs/bk4r1_defconfig      |   1 +
 configs/m53menlo_defconfig   |   1 +
 configs/pcm052_defconfig     |   1 +
 configs/x600_defconfig       |   1 +
 drivers/rtc/Kconfig          |   6 +++
 drivers/rtc/m41t62.c         | 112 ++++++++++++++++++++++++++++++++++++++-----
 include/configs/m53menlo.h   |   1 -
 include/configs/pcm052.h     |   1 -
 include/configs/x600.h       |   1 -
 scripts/config_whitelist.txt |   1 -
 10 files changed, 109 insertions(+), 17 deletions(-)
Signature · 1 line
2.11.0
#8 lore raw

PATCH v2 1/1 Kconfig: Migrate CONFIG_RTC_M41T62 define to Kconfig

This patch moves the RTC M41T62 config define to Kconfig.

---
 configs/bk4r1_defconfig      | 1 +
 configs/m53menlo_defconfig   | 1 +
 configs/pcm052_defconfig     | 1 +
 configs/x600_defconfig       | 1 +
 drivers/rtc/Kconfig          | 6 ++++++
 include/configs/m53menlo.h   | 1 -
 include/configs/pcm052.h     | 1 -
 include/configs/x600.h       | 1 -
 scripts/config_whitelist.txt | 1 -
 9 files changed, 10 insertions(+), 4 deletions(-)
configs/bk4r1_defconfig +1 -0
index cf1fd0b6c6..9e31b4ac97 100644
@@ -40,6 +40,7 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHYLIB=y
 CONFIG_PHY_MICREL=y
 CONFIG_MII=y
+CONFIG_RTC_M41T62=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
 CONFIG_SPI=y
configs/m53menlo_defconfig +1 -0
index 795f8a3ebc..dd7aed324f 100644
@@ -49,6 +49,7 @@ CONFIG_NAND=y
 CONFIG_NAND_MXC=y
 CONFIG_PHYLIB=y
 CONFIG_PHY_MICREL=y
+CONFIG_RTC_M41T62=y
 CONFIG_USB=y
 CONFIG_USB_STORAGE=y
 CONFIG_USB_HOST_ETHER=y
configs/pcm052_defconfig +1 -0
index 0c8e31a9ec..e207df51a8 100644
@@ -35,5 +35,6 @@ CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_PHYLIB=y
 CONFIG_PHY_MICREL=y
 CONFIG_MII=y
+CONFIG_RTC_M41T62=y
 CONFIG_DM_SERIAL=y
 CONFIG_FSL_LPUART=y
configs/x600_defconfig +1 -0
index c8f5f66232..a96f54c737 100644
@@ -52,6 +52,7 @@ CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_MII=y
+CONFIG_RTC_M41T62=y
 CONFIG_CONS_INDEX=0
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
drivers/rtc/Kconfig +6 -0
index bcc01b135e..c27730798e 100644
@@ -94,4 +94,10 @@ config RTC_MC146818
 	  clock with a wide array of features and 50 bytes of general-purpose,
 	  battery-backed RAM. The driver supports access to the clock and RAM.
 
+config RTC_M41T62
+	bool "Enable M41T62 driver"
+	help
+	  Enable driver for ST's M41T62 compatible RTC devices (like RV-4162).
+	  It is a serial (I2C) real-time clock (RTC) with alarm.
+
 endmenu
include/configs/m53menlo.h +0 -1
index 94214b135d..3fca28da6b 100644
@@ -110,7 +110,6 @@
  * RTC
  */
 #ifdef CONFIG_CMD_DATE
-#define CONFIG_RTC_M41T62
 #define CONFIG_SYS_I2C_RTC_ADDR		0x68
 #define CONFIG_SYS_M41T11_BASE_YEAR	2000
 #endif
include/configs/pcm052.h +0 -1
index 9997795434..e125a38e7d 100644
@@ -58,7 +58,6 @@
 #define CONFIG_SYS_I2C_MXC
 
 /* RTC (actually an RV-4162 but M41T62-compatible) */
-#define CONFIG_RTC_M41T62
 #define CONFIG_SYS_I2C_RTC_ADDR 0x68
 #define CONFIG_SYS_RTC_BUS_NUM 2
 
include/configs/x600.h +0 -1
index a6835ebbd5..639da8012c 100644
@@ -75,7 +75,6 @@
 #define CONFIG_SYS_I2C_SLAVE			0x02
 #define CONFIG_I2C_CHIPADDRESS			0x50
 
-#define CONFIG_RTC_M41T62	1
 #define CONFIG_SYS_I2C_RTC_ADDR	0x68
 
 /* FPGA config options */
scripts/config_whitelist.txt +0 -1
index 0627024e71..6d5b8c35d9 100644
@@ -1664,7 +1664,6 @@ CONFIG_RTC_DS3231
 CONFIG_RTC_FTRTC010
 CONFIG_RTC_IMXDI
 CONFIG_RTC_M41T11
-CONFIG_RTC_M41T62
 CONFIG_RTC_MC13XXX
 CONFIG_RTC_MCFRRTC
 CONFIG_RTC_MCP79411
Signature · 1 line
2.11.0
#9 lore raw

PATCH v2 1/1 Kconfig: Migrate CONFIG_RTC_M41T62 define to Kconfig

Quoted 5 lines · Lukasz Majewski

This patch moves the RTC M41T62 config define to Kconfig.

Quoted 11 lines
---
 configs/bk4r1_defconfig      | 1 +
 configs/m53menlo_defconfig   | 1 +
 configs/pcm052_defconfig     | 1 +
 configs/x600_defconfig       | 1 +
 drivers/rtc/Kconfig          | 6 ++++++
 include/configs/m53menlo.h   | 1 -
 include/configs/pcm052.h     | 1 -
 include/configs/x600.h       | 1 -
 scripts/config_whitelist.txt | 1 -
 9 files changed, 10 insertions(+), 4 deletions(-)
#10 lore raw

PATCH v2 1/1 Kconfig: Migrate CONFIG_RTC_M41T62 define to Kconfig

In reply to Lukasz Majewski
Quoted 5 lines · Lukasz Majewski

This patch moves the RTC M41T62 config define to Kconfig.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181203/5464233f/attachment.sig>
#11 lore raw

PATCH v2 2/4 rtc: m41t62: Break i2c_write() arguments to fix checkpatch warning

In reply to Lukasz Majewski

No functional change for this commit.

---

Changes in v2: None
Changes in v1: None

 drivers/rtc/m41t62.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/rtc/m41t62.c +2 -1
index 137438389d..cc230e2b78 100644
@@ -108,7 +108,8 @@ int rtc_set(struct rtc_time *tm)
 	/* assume 20YY not 19YY */
 	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
 
-	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE)) {
+	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
+		      M41T62_DATETIME_REG_SIZE)) {
 		printf("I2C write failed in %s()\n", __func__);
 		return -1;
 	}
Signature · 1 line
2.11.0
#12 lore raw

PATCH v2 2/4 rtc: m41t62: Break i2c_write() arguments to fix checkpatch warning

Quoted 4 lines · Lukasz Majewski

No functional change for this commit.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181203/13357a2e/attachment.sig>
#13 lore raw

PATCH v2 3/4 rtc: m41t62: Extract common RTC handling code to facilitate DM conversion

In reply to Lukasz Majewski

This change facilitates the conversion of m41t62 RTC driver to device model (DM).

---

Changes in v2:
- New patch

Changes in v1: None

 drivers/rtc/m41t62.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/rtc/m41t62.c +20 -12
index cc230e2b78..94f2e0f332 100644
@@ -49,12 +49,8 @@
 
 #define M41T80_ALHOUR_HT	(1 << 6)	/* HT: Halt Update Bit */
 
-int rtc_get(struct rtc_time *tm)
+static void m41t62_update_rtc_time(struct rtc_time *tm, u8 *buf)
 {
-	u8 buf[M41T62_DATETIME_REG_SIZE];
-
-	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
-
 	debug("%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
 	      "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
 	      __FUNCTION__,
@@ -77,20 +73,14 @@ int rtc_get(struct rtc_time *tm)
 	      __FUNCTION__,
 	      tm->tm_sec, tm->tm_min, tm->tm_hour,
 	      tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
-
-	return 0;
 }
 
-int rtc_set(struct rtc_time *tm)
+static void m41t62_set_rtc_buf(const struct rtc_time *tm, u8 *buf)
 {
-	u8 buf[M41T62_DATETIME_REG_SIZE];
-
 	debug("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
 	      tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
 	      tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
-
 	/* Merge time-data and register flags into buf[0..7] */
 	buf[M41T62_REG_SSEC] = 0;
 	buf[M41T62_REG_SEC] =
@@ -107,6 +97,24 @@ int rtc_set(struct rtc_time *tm)
 		bin2bcd(tm->tm_mon) | (buf[M41T62_REG_MON] & ~0x1f);
 	/* assume 20YY not 19YY */
 	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
+}
+
+int rtc_get(struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+
+	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+	m41t62_update_rtc_time(tm, buf);
+
+	return 0;
+}
+
+int rtc_set(struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+
+	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+	m41t62_set_rtc_buf(tm, buf);
 
 	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
 		      M41T62_DATETIME_REG_SIZE)) {
Signature · 1 line
2.11.0
#14 lore raw

PATCH v2 3/4 rtc: m41t62: Extract common RTC handling code to facilitate DM conversion

Quoted 71 lines · Lukasz Majewski

This change facilitates the conversion of m41t62 RTC driver to device model (DM).

---

Changes in v2:
- New patch

Changes in v1: None

  drivers/rtc/m41t62.c | 32 ++++++++++++++++++++------------
  1 file changed, 20 insertions(+), 12 deletions(-)
drivers/rtc/m41t62.c +13 -12
index cc230e2b78..94f2e0f332 100644
@@ -49,12 +49,8 @@
 
  #define M41T80_ALHOUR_HT	(1 << 6)	/* HT: Halt Update Bit */
 
-int rtc_get(struct rtc_time *tm)
+static void m41t62_update_rtc_time(struct rtc_time *tm, u8 *buf)
  {
-	u8 buf[M41T62_DATETIME_REG_SIZE];
-
-	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
-
  	debug("%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
  	      "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
  	      __FUNCTION__,
@@ -77,20 +73,14 @@ int rtc_get(struct rtc_time *tm)
  	      __FUNCTION__,
  	      tm->tm_sec, tm->tm_min, tm->tm_hour,
  	      tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
-
-	return 0;
  }
 
-int rtc_set(struct rtc_time *tm)
+static void m41t62_set_rtc_buf(const struct rtc_time *tm, u8 *buf)
  {
-	u8 buf[M41T62_DATETIME_REG_SIZE];
-
  	debug("Set DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
  	      tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
  	      tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
-
  	/* Merge time-data and register flags into buf[0..7] */
  	buf[M41T62_REG_SSEC] = 0;
  	buf[M41T62_REG_SEC] =
@@ -107,6 +97,24 @@ int rtc_set(struct rtc_time *tm)
  		bin2bcd(tm->tm_mon) | (buf[M41T62_REG_MON] & ~0x1f);
  	/* assume 20YY not 19YY */
  	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
+}
+
+int rtc_get(struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+
+	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+	m41t62_update_rtc_time(tm, buf);
+
+	return 0;
+}

drivers/rtc/m41t62.c int rtc_set(struct rtc_time *tm) · line 120

Quoted 10 lines
drivers/rtc/m41t62.c +7 -0
+
+int rtc_set(struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+
+	i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE);
+	m41t62_set_rtc_buf(tm, buf);
 
  	if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf,
  		      M41T62_DATETIME_REG_SIZE)) {

I like this version better, thanks.

Thanks,
Stefan

#15 lore raw

PATCH v2 3/4 rtc: m41t62: Extract common RTC handling code to facilitate DM conversion

In reply to Lukasz Majewski
Quoted 5 lines · Lukasz Majewski

This change facilitates the conversion of m41t62 RTC driver to device model (DM).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181203/43f08e1d/attachment.sig>
#16 lore raw

PATCH v2 4/4 rtc: m41t62: Convert the RTC driver to support the driver model (DM)

In reply to Lukasz Majewski

After this change the m41t62.c can be used with RTC subsystem (i.e. date command) which uses device model (DM).

---

Changes in v2:
- Extract common RTC handling code to avoid #ifdefs for CONFIG_DM_RTC
- Provide extra patch to group DM_RTC functions together (easier to maintain)

Changes in v1:
- None

 drivers/rtc/m41t62.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)
drivers/rtc/m41t62.c +77 -0
index 94f2e0f332..2ee7e00b02 100644
@@ -1,5 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
+ * (C) Copyright 2018
+ * Lukasz Majewski, DENX Software Engineering, lukma at denx.de.
+ *
  * (C) Copyright 2008
  * Stefan Roese, DENX Software Engineering, sr at denx.de.
  *
@@ -15,6 +18,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <rtc.h>
 #include <i2c.h>
 
@@ -99,6 +103,78 @@ static void m41t62_set_rtc_buf(const struct rtc_time *tm, u8 *buf)
 	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
 }
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_get(struct udevice *dev, struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+	int ret;
+
+	ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+	if (ret)
+		return ret;
+
+	m41t62_update_rtc_time(tm, buf);
+
+	return 0;
+}
+
+static int m41t62_rtc_set(struct udevice *dev, const struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+	int ret;
+
+	ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+	if (ret)
+		return ret;
+
+	m41t62_set_rtc_buf(tm, buf);
+
+	ret = dm_i2c_write(dev, 0, buf, sizeof(buf));
+	if (ret) {
+		printf("I2C write failed in %s()\n", __func__);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int m41t62_rtc_reset(struct udevice *dev)
+{
+	u8 val;
+
+	/*
+	 * M41T82: Make sure HT (Halt Update) bit is cleared.
+	 * This bit is 0 in M41T62 so its save to clear it always.
+	 */
+
+	int ret = dm_i2c_read(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	val &= ~M41T80_ALHOUR_HT;
+	ret |= dm_i2c_write(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	return ret;
+}
+
+static const struct rtc_ops m41t62_rtc_ops = {
+	.get = m41t62_rtc_get,
+	.set = m41t62_rtc_set,
+	.reset = m41t62_rtc_reset,
+};
+
+static const struct udevice_id m41t62_rtc_ids[] = {
+	{ .compatible = "st,m41t62" },
+	{ .compatible = "microcrystal,rv4162" },
+	{ }
+};
+
+U_BOOT_DRIVER(rtc_m41t62) = {
+	.name	= "rtc-m41t62",
+	.id	= UCLASS_RTC,
+	.of_match = m41t62_rtc_ids,
+	.ops	= &m41t62_rtc_ops,
+};
+
+#else /* NON DM RTC code - will be removed */
 int rtc_get(struct rtc_time *tm)
 {
 	u8 buf[M41T62_DATETIME_REG_SIZE];
@@ -137,3 +213,4 @@ void rtc_reset(void)
 	val &= ~M41T80_ALHOUR_HT;
 	i2c_write(CONFIG_SYS_I2C_RTC_ADDR, M41T62_REG_ALARM_HOUR, 1, &val, 1);
 }
+#endif /* CONFIG_DM_RTC */
Signature · 1 line
2.11.0
#17 lore raw

PATCH v2 4/4 rtc: m41t62: Convert the RTC driver to support the driver model (DM)

Quoted 120 lines · Lukasz Majewski

After this change the m41t62.c can be used with RTC subsystem (i.e. date command) which uses device model (DM).

---

Changes in v2:
- Extract common RTC handling code to avoid #ifdefs for CONFIG_DM_RTC
- Provide extra patch to group DM_RTC functions together (easier to maintain)

Changes in v1:
- None

  drivers/rtc/m41t62.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 77 insertions(+)
drivers/rtc/m41t62.c +76 -0
index 94f2e0f332..2ee7e00b02 100644
@@ -1,5 +1,8 @@
  // SPDX-License-Identifier: GPL-2.0+
  /*
+ * (C) Copyright 2018
+ * Lukasz Majewski, DENX Software Engineering, lukma at denx.de.
+ *
   * (C) Copyright 2008
   * Stefan Roese, DENX Software Engineering, sr at denx.de.
   *
@@ -15,6 +18,7 @@
 
  #include <common.h>
  #include <command.h>
+#include <dm.h>
  #include <rtc.h>
  #include <i2c.h>
 
@@ -99,6 +103,78 @@ static void m41t62_set_rtc_buf(const struct rtc_time *tm, u8 *buf)
  	buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
  }
 
+#ifdef CONFIG_DM_RTC
+static int m41t62_rtc_get(struct udevice *dev, struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+	int ret;
+
+	ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+	if (ret)
+		return ret;
+
+	m41t62_update_rtc_time(tm, buf);
+
+	return 0;
+}
+
+static int m41t62_rtc_set(struct udevice *dev, const struct rtc_time *tm)
+{
+	u8 buf[M41T62_DATETIME_REG_SIZE];
+	int ret;
+
+	ret = dm_i2c_read(dev, 0, buf, sizeof(buf));
+	if (ret)
+		return ret;
+
+	m41t62_set_rtc_buf(tm, buf);
+
+	ret = dm_i2c_write(dev, 0, buf, sizeof(buf));
+	if (ret) {
+		printf("I2C write failed in %s()\n", __func__);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int m41t62_rtc_reset(struct udevice *dev)
+{
+	u8 val;
+
+	/*
+	 * M41T82: Make sure HT (Halt Update) bit is cleared.
+	 * This bit is 0 in M41T62 so its save to clear it always.
+	 */
+
+	int ret = dm_i2c_read(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	val &= ~M41T80_ALHOUR_HT;
+	ret |= dm_i2c_write(dev, M41T62_REG_ALARM_HOUR, &val, sizeof(val));
+
+	return ret;
+}
+
+static const struct rtc_ops m41t62_rtc_ops = {
+	.get = m41t62_rtc_get,
+	.set = m41t62_rtc_set,
+	.reset = m41t62_rtc_reset,
+};
+
+static const struct udevice_id m41t62_rtc_ids[] = {
+	{ .compatible = "st,m41t62" },
+	{ .compatible = "microcrystal,rv4162" },
+	{ }
+};
+
+U_BOOT_DRIVER(rtc_m41t62) = {
+	.name	= "rtc-m41t62",
+	.id	= UCLASS_RTC,
+	.of_match = m41t62_rtc_ids,
+	.ops	= &m41t62_rtc_ops,
+};
+
+#else /* NON DM RTC code - will be removed */
  int rtc_get(struct rtc_time *tm)
  {
  	u8 buf[M41T62_DATETIME_REG_SIZE];

drivers/rtc/m41t62.c void rtc_reset(void) · line 216

Quoted 4 lines
drivers/rtc/m41t62.c +1 -0
@@ -137,3 +213,4 @@ void rtc_reset(void)
  	val &= ~M41T80_ALHOUR_HT;
  	i2c_write(CONFIG_SYS_I2C_RTC_ADDR, M41T62_REG_ALARM_HOUR, 1, &val, 1);
  }
+#endif /* CONFIG_DM_RTC */

Thanks,
Stefan

#18 lore raw

PATCH v2 4/4 rtc: m41t62: Convert the RTC driver to support the driver model (DM)

In reply to Lukasz Majewski
Quoted 5 lines · Lukasz Majewski

After this change the m41t62.c can be used with RTC subsystem (i.e. date command) which uses device model (DM).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181203/0e25eb72/attachment.sig>