Skip to contentSkip to conversation

rtc: pcf85063: do not register a RTC device if chip is not present

PATCH Applied Mirza Krak 3 participants 4 messages Oct 17, 2016 – Nov 4, 2016 Real time clock (RTC)

lore
Share & tools
lore

Mirza Krak

author
#0 lore raw

PATCH 1/1 rtc: pcf85063: do not register a RTC device if chip is not present

From: Mirza Krak <[email protected]>

Add a sanity check to see if chip is present. If we can not communicate with the chip there is no point in registering a RTC device.

---
 drivers/rtc/rtc-pcf85063.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/rtc/rtc-pcf85063.c +7 -0
index efb0a08..a06dff9 100644
@@ -191,12 +191,19 @@ static int pcf85063_probe(struct i2c_client *client,
 				const struct i2c_device_id *id)
 {
 	struct rtc_device *rtc;
+	int err;
 
 	dev_dbg(&client->dev, "%s\n", __func__);
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -ENODEV;
 
+	err = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1);
+	if (err < 0) {
+		dev_err(&client->dev, "RTC chip is not present\n");
+		return err;
+	}
+
 	rtc = devm_rtc_device_register(&client->dev,
 				       pcf85063_driver.driver.name,
 				       &pcf85063_rtc_ops, THIS_MODULE);
Signature · 1 line
2.1.4
#1 lore raw

Hi,

Quoted 5 lines · Mirza Krak

From: Mirza Krak <[email protected]>

Add a sanity check to see if chip is present. If we can not communicate with the chip there is no point in registering a RTC device.

Does it makes sense? If the device is not present, why has it been registered in the first place?

Quoted 32 lines
---
 drivers/rtc/rtc-pcf85063.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/rtc/rtc-pcf85063.c +7 -0
index efb0a08..a06dff9 100644
@@ -191,12 +191,19 @@ static int pcf85063_probe(struct i2c_client *client,
 				const struct i2c_device_id *id)
 {
 	struct rtc_device *rtc;
+	int err;
 
 	dev_dbg(&client->dev, "%s\n", __func__);
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -ENODEV;
 
+	err = i2c_smbus_read_byte_data(client, PCF85063_REG_CTRL1);
+	if (err < 0) {
+		dev_err(&client->dev, "RTC chip is not present\n");
+		return err;
+	}
+
 	rtc = devm_rtc_device_register(&client->dev,
 				       pcf85063_driver.driver.name,
 				       &pcf85063_rtc_ops, THIS_MODULE);
Signature · 1 line
2.1.4
Signature · 13 lines
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 [email protected].
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

2016-10-17 18:23 GMT+02:00 Alexandre Belloni
<[email protected]>:

Quoted 11 lines

Hi,

Quoted 5 lines · Mirza Krak

From: Mirza Krak <[email protected]>

Add a sanity check to see if chip is present. If we can not communicate with the chip there is no point in registering a RTC device.

Does it makes sense? If the device is not present, why has it been registered in the first place?

It made sense to me, that if you can not communicated with a chip at probe time for whatever reason (chip fault, bus problem, "not present") then probe should fail.

Maybe I shouldn't have used the word "present", because obviously we expect the chip to be there, but I experienced this on a board where the chip was not mounted and the driver produces a lot of errors because it registered an RTC device for something that is not there.

Looking around in other rtc drivers, it is common to do a communication check at probe time and fail probe if the communication check does not go trough.

--=20
Med V=C3=A4nliga H=C3=A4lsningar / Best Regards

*******************************************************************
Mirza Krak
Host Mobility AB
[email protected]
Anders Personsgatan 12, 416 64 G=C3=B6teborg
Sweden
http://www.hostmobility.com
Direct: +46 31 31 32 704
Phone: +46 31 31 32 700
Fax: +46 31 80 67 51
Mobile: +46 730 28 06 22
*******************************************************************

--=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 [email protected].
For more options, visit https://groups.google.com/d/optout.

#3 lore raw
In reply to Mirza Krak
Quoted 10 lines · Mirza Krak

From: Mirza Krak <[email protected]>

Add a sanity check to see if chip is present. If we can not communicate with the chip there is no point in registering a RTC device.

---
 drivers/rtc/rtc-pcf85063.c | 7 +++++++
 1 file changed, 7 insertions(+)

Applied, thanks.

Signature · 13 lines
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 [email protected].
For more options, visit https://groups.google.com/d/optout.