mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
To: alexandre.belloni@bootlin.com, krzk+dt@kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Cc: skhan@linuxfoundation.org, linux-rtc@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	akhileshpatilvnit@gmail.com
Subject: [PATCH 5/7] rtc: m41t93: fix device connection/detection logic during probe
Date: Wed, 3 Sep 2025 19:57:21 +0530	[thread overview]
Message-ID: <c3deec9e679cd4e4a49a2cc1cba340c552faefdc.1756908788.git.akhilesh@ee.iitb.ac.in> (raw)
In-Reply-To: <cover.1756908788.git.akhilesh@ee.iitb.ac.in>

Fix the incorrect assumption about WDAY register (0x4) bits 3 to 7
being 0 after initial power-on to test response from device during probe

Do not expect these bits to be 0 after power on as datasheet does not
explicitly mention these power on defaults but recommends software to
clear these bits during operation. Refer section 3.15 for initial
power-on default bits.

Fix the random probe failures after power on by removing this condition
check. Add alternate response check logic which performs write, read,
compare check on device SRAM register to check device connection.

Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
---
 drivers/rtc/rtc-m41t93.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-m41t93.c b/drivers/rtc/rtc-m41t93.c
index 8cc179e08a4a..902797070246 100644
--- a/drivers/rtc/rtc-m41t93.c
+++ b/drivers/rtc/rtc-m41t93.c
@@ -30,6 +30,7 @@
 #define M41T93_BIT_A1IE                 BIT(7)
 #define M41T93_BIT_ABE			BIT(5)
 #define M41T93_FLAG_AF1                 BIT(6)
+#define M41T93_SRAM_BASE		0x19
 
 
 #define M41T93_REG_ALM_HOUR_HT		0xc
@@ -290,17 +291,25 @@ static int m41t93_probe(struct spi_device *spi)
 		return PTR_ERR(m41t93->regmap);
 	}
 
-	ret = regmap_read(m41t93->regmap, M41T93_REG_WDAY, &res);
-	if (ret < 0) {
+	ret = regmap_write(m41t93->regmap, M41T93_SRAM_BASE, 0xA5);
+	if (ret) {
 		dev_err(&spi->dev, "IO error\n");
 		return -EIO;
 	}
 
-	if (res < 0 || (res & 0xf8) != 0) {
-		dev_err(&spi->dev, "not found 0x%x.\n", res);
+	ret = regmap_read(m41t93->regmap, M41T93_SRAM_BASE, &res);
+	if (ret) {
+		dev_err(&spi->dev, "IO error\n");
+		return -EIO;
+	}
+
+	if (res != 0xA5) {
+		dev_err(&spi->dev, "No valid response from device 0x%x.\n", res);
 		return -ENODEV;
 	}
 
+	dev_notice(&spi->dev, "m41t93 device response success\n");
+
 	spi_set_drvdata(spi, m41t93);
 
 	m41t93->rtc = devm_rtc_device_register(&spi->dev, m41t93_driver.driver.name,
-- 
2.34.1


  parent reply	other threads:[~2025-09-03 14:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03 14:23 [PATCH 0/7] rtc: m41t93: add new features alarm, clock out, watchdog Akhilesh Patil
2025-09-03 14:25 ` [PATCH 1/7] rtc: m41t93: add device tree support Akhilesh Patil
2025-09-03 14:25 ` [PATCH 2/7] dt-bindings: rtc: add bindings for m41t93 Akhilesh Patil
2025-09-03 14:30   ` Krzysztof Kozlowski
2025-09-09 11:44     ` Akhilesh Patil
2025-09-03 20:33   ` Rob Herring (Arm)
2025-09-03 14:26 ` [PATCH 3/7] rtc: m41t93: migrate to regmap api for register access Akhilesh Patil
2025-09-03 14:26 ` [PATCH 4/7] rtc: m41t93: Add alarm support Akhilesh Patil
2025-09-04  5:07   ` kernel test robot
2025-09-03 14:27 ` Akhilesh Patil [this message]
2025-09-03 14:47   ` [PATCH 5/7] rtc: m41t93: fix device connection/detection logic during probe Alexandre Belloni
2025-09-09 12:12     ` Akhilesh Patil
2025-09-03 14:27 ` [PATCH 6/7] rtc: m41t93: Add square wave clock provider support Akhilesh Patil
2025-09-04  4:42   ` kernel test robot
2025-09-03 14:28 ` [PATCH 7/7] rtc: m41t93: Add watchdog support Akhilesh Patil
2025-09-04 23:23   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c3deec9e679cd4e4a49a2cc1cba340c552faefdc.1756908788.git.akhilesh@ee.iitb.ac.in \
    --to=akhilesh@ee.iitb.ac.in \
    --cc=akhileshpatilvnit@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®