Skip to contentSkip to conversation

rtc: Add support for Intersil ISL12057 I2C RTC chip

PATCH RESEND Superseded Arnaud Ebalard 2 participants 3 messages Dec 17, 2013 – Dec 18, 2013

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v5 1/1 rtc: Add support for Intersil ISL12057 I2C RTC chip

Intersil ISL12057 is an I2C RTC chip also supporting two alarms. This patch only adds support for basic RTC functionalities (i.e. getting and setting time). Tests have been performed on NETGEAR ReadyNAS 102 w/ startup/shutdown scripts, hwclock, ntpdate and openntpd.

---
Hi Andrew,

Sorry to bother you with that but I wonder if you could take care of this patch in order to get it queued for v3.14 (i.e. -next); like others [1], I came to the conclusion that it was unlikely the patch would find its way via Alessandro. *Do not hesitate* to correct me if I missed something.

Some context below regarding that work; changes on various versions are listed after that:

In order to get at least some initial support for the chip available in mainline kernel (v3.14 will have three users waiting for it: ReadyNAS 102, 104 and 2120), I decided to temporarily remove the alarm and IRQ related code I pushed earlier (see [2] below). If possible, I'd like to iterate on this before Christmas in order not to miss ARM submission cutoff (around -rc5) to push the .dts changes (once the driver is queued for 3.14).

I will submit a patch later to add back Alarm/IRQ support once I get some feedback from RTC community on how to correctly handle the specificities of the hardware (Alarm1 interrupt line connected to a power component and not to the SoC).

Comments welcome!

Cheers,

a+

[1]: http://www.spinics.net/lists/arm-kernel/msg292187.html
[2]: http://thread.gmane.org/gmane.linux.drivers.devicetree/46581

Changes since previous v4 (comments from Guenter Roeck):
- M-x tabified the whole driver and manually handled tab before comments (after defines). In the long run, I will try and find a way to make emacs wiser on that last point.
- Removed checkpatch false positive by cleaning header
- remove useless forward declaration of isl12057_driver
- added missing comment about lack of mutex protection
- typo (s/enable/unable/)
- removed forgotten data->rtc and associated field in 'data'

NOTE: I kept definitions of bits (Alarms, etc) to avoid sparse info in the file. Additionally, those will be reused soon.

Changes since previous v3 (comments from Guenter Roeck):
- use BIT() instead of (1<<X)
- use dev_set_drvdata()/dev_get_drvdata() to simplify access to 'data'
- removed two (now) useless fields in private 'data' structure
- now use dev instead of &client->dev

Changes since previous v2 (Comments from Mark Brown):
- converted to regmap

Changes since previous v1 (Comments from Mark Rutland):
- fixed return values for isl12057_i2c_{read,set}_regs()
- checked associated return paths

Changes since previous v0:
- removed alarm and IRQ related code
- Switched to isl for intersil (no existing driver has any reference to isil, even though this would be the recommended choice)
- Added intersil info in vendor-prefixes.txt file
- Added entry for ISL 12057 in I2C trivial-devices.txt file
- Added mutex protection for non atomic read/write

 .../devicetree/bindings/i2c/trivial-devices.txt    |   1 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 drivers/rtc/Kconfig                                |  11 +
 drivers/rtc/Makefile                               |   1 +
 drivers/rtc/rtc-isl12057.c                         | 351 +++++++++++++++++++++
 5 files changed, 365 insertions(+)
 create mode 100644 drivers/rtc/rtc-isl12057.c
Documentation/devicetree/bindings/i2c/trivial-devices.txt +1 -0
index b1cb341..cdf1430 100644
@@ -39,6 +39,7 @@ fsl,sgtl5000		SGTL5000: Ultra Low-Power Audio Codec
 gmt,g751		G751: Digital Temperature Sensor and Thermal Watchdog with Two-Wire Interface
 infineon,slb9635tt	Infineon SLB9635 (Soft-) I2C TPM (old protocol, max 100khz)
 infineon,slb9645tt	Infineon SLB9645 I2C TPM (new protocol, max 400khz)
+isl,isl12057		Intersil ISL12057 I2C RTC Chip
 maxim,ds1050		5 Bit Programmable, Pulse-Width Modulator
 maxim,max1237		Low-Power, 4-/12-Channel, 2-Wire Serial, 12-Bit ADCs
 maxim,max6625		9-Bit/12-Bit Temperature Sensors with I?C-Compatible Serial Interface
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index edbb8d8..ed0f63f 100644
@@ -39,6 +39,7 @@ ibm	International Business Machines (IBM)
 idt	Integrated Device Technologies, Inc.
 img	Imagination Technologies Ltd.
 intercontrol	Inter Control Group
+isl	Intersil
 lg	LG Corporation
 linux	Linux-specific binding
 lsi	LSI Corp. (LSI Logic)
drivers/rtc/Kconfig +11 -0
index 0077302..9608210 100644
@@ -304,6 +304,17 @@ config RTC_DRV_ISL12022
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-isl12022.
 
+config RTC_DRV_ISL12057
+       depends on I2C
+       select REGMAP_I2C
+       tristate "Intersil ISL12057"
+       help
+	  If you say yes here you get support for the Intersil ISL12057
+	  I2C RTC chip.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-isl12057.
+
 config RTC_DRV_X1205
 	tristate "Xicor/Intersil X1205"
 	help
drivers/rtc/Makefile +1 -0
index 27b4bd8..d4089c0 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
 obj-$(CONFIG_RTC_DRV_IMXDI)	+= rtc-imxdi.o
 obj-$(CONFIG_RTC_DRV_ISL1208)	+= rtc-isl1208.o
 obj-$(CONFIG_RTC_DRV_ISL12022)	+= rtc-isl12022.o
+obj-$(CONFIG_RTC_DRV_ISL12057)	+= rtc-isl12057.o
 obj-$(CONFIG_RTC_DRV_JZ4740)	+= rtc-jz4740.o
 obj-$(CONFIG_RTC_DRV_LP8788)	+= rtc-lp8788.o
 obj-$(CONFIG_RTC_DRV_LPC32XX)	+= rtc-lpc32xx.o
drivers/rtc/rtc-isl12057.c new file +351 -0

351 lines not on this page · raw message

Signature · 1 line
1.8.4.4
#1 lore raw

PATCH RESEND v5 1/1 rtc: Add support for Intersil ISL12057 I2C RTC chip

Quoted 5 lines · Arnaud Ebalard

Intersil ISL12057 is an I2C RTC chip also supporting two alarms. This patch only adds support for basic RTC functionalities (i.e. getting and setting time). Tests have been performed on NETGEAR ReadyNAS 102 w/ startup/shutdown scripts, hwclock, ntpdate and openntpd.

but

Quoted 26 lines
drivers/rtc/rtc-isl12057.c new file +26 -0
+static int isl12057_rtc_proc(struct device *dev, struct seq_file *seq)
+{
+	struct isl12057_rtc_data *data = dev_get_drvdata(dev);
+	int reg, ret;
+
+	mutex_lock(&data->lock);
+
+	/* Status register */
+	ret = regmap_read(data->regmap, ISL12057_REG_SR, &reg);
+	if (ret) {
+		dev_err(dev, "%s: reading SR failed\n", __func__);
+		goto out;
+	}
+
+	seq_printf(seq, "status_reg\t:%s%s%s (0x%.2x)\n",
+		   (reg & ISL12057_REG_SR_OSF) ? " OSF" : "",
+		   (reg & ISL12057_REG_SR_A1F) ? " A1F" : "",
+		   (reg & ISL12057_REG_SR_A2F) ? " A2F" : "", reg);
+
+	/* Control register */
+	ret = regmap_read(data->regmap, ISL12057_REG_INT, &reg);
+	if (ret) {
+		dev_err(dev, "%s: reading INT failed\n", __func__);
+		goto out;
+	}
+

drivers/rtc/rtc-isl12057.c line 229

Quoted 10 lines
drivers/rtc/rtc-isl12057.c new file +10 -0
+	seq_printf(seq, "control_reg\t:%s%s%s%s%s%s (0x%.2x)\n",
+		   (reg & ISL12057_REG_INT_A1IE) ?  " A1IE"  : "",
+		   (reg & ISL12057_REG_INT_A2IE) ?  " A2IE"  : "",
+		   (reg & ISL12057_REG_INT_INTCN) ? " INTCN" : "",
+		   (reg & ISL12057_REG_INT_RS1) ?   " RS1"   : "",
+		   (reg & ISL12057_REG_INT_RS2) ?   " RS2"   : "",
+		   (reg & ISL12057_REG_INT_EOSC) ?  " EOSC"  : "", reg);
+
+ out:
+	mutex_unlock(&data->lock);

I'm not sure the lock is achieving anything any more - the only time it
actualy protects more than one operation is the above but since the
status register is volatile anyway it might change between it being read
and the control register being read.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131218/74207624/attachment-0001.sig>

#2 lore raw

PATCH RESEND v5 1/1 rtc: Add support for Intersil ISL12057 I2C RTC chip

Hi,

Quoted 8 lines · Mark Brown
Quoted 5 lines · Arnaud Ebalard

Intersil ISL12057 is an I2C RTC chip also supporting two alarms. This patch only adds support for basic RTC functionalities (i.e. getting and setting time). Tests have been performed on NETGEAR ReadyNAS 102 w/ startup/shutdown scripts, hwclock, ntpdate and openntpd.

Thanks, Mark!

Quoted 33 lines
Quoted 33 lines
drivers/rtc/rtc-isl12057.c new file +33 -0
+static int isl12057_rtc_proc(struct device *dev, struct seq_file *seq)
+{
+	struct isl12057_rtc_data *data = dev_get_drvdata(dev);
+	int reg, ret;
+
+	mutex_lock(&data->lock);
+
+	/* Status register */
+	ret = regmap_read(data->regmap, ISL12057_REG_SR, &reg);
+	if (ret) {
+		dev_err(dev, "%s: reading SR failed\n", __func__);
+		goto out;
+	}
+
+	seq_printf(seq, "status_reg\t:%s%s%s (0x%.2x)\n",
+		   (reg & ISL12057_REG_SR_OSF) ? " OSF" : "",
+		   (reg & ISL12057_REG_SR_A1F) ? " A1F" : "",
+		   (reg & ISL12057_REG_SR_A2F) ? " A2F" : "", reg);
+
+	/* Control register */
+	ret = regmap_read(data->regmap, ISL12057_REG_INT, &reg);
+	if (ret) {
+		dev_err(dev, "%s: reading INT failed\n", __func__);
+		goto out;
+	}
+
+	seq_printf(seq, "control_reg\t:%s%s%s%s%s%s (0x%.2x)\n",
+		   (reg & ISL12057_REG_INT_A1IE) ?  " A1IE"  : "",
+		   (reg & ISL12057_REG_INT_A2IE) ?  " A2IE"  : "",
+		   (reg & ISL12057_REG_INT_INTCN) ? " INTCN" : "",
+		   (reg & ISL12057_REG_INT_RS1) ?   " RS1"   : "",
+		   (reg & ISL12057_REG_INT_RS2) ?   " RS2"   : "",
+		   (reg & ISL12057_REG_INT_EOSC) ?  " EOSC"  : "", reg);
Quoted 8 lines

drivers/rtc/rtc-isl12057.c line 229

Quoted 3 lines
drivers/rtc/rtc-isl12057.c new file +3 -0
+
+ out:
+	mutex_unlock(&data->lock);

I'm not sure the lock is achieving anything any more - the only time it actualy protects more than one operation is the above but since the status register is volatile anyway it might change between it being read and the control register being read.

Well, I guess the lock will be more useful when alarm code will be added back, even if it does not hurt above. Now, regarding protection of regmap_bulk_write/read() calls in set/read time helpers, I also protected those because I thought it was good practice in general to serialize concurrent accesses to both the regmap structure and the device *in the driver*. But looking at the internals of regmap functions in more details, I guess I could have relied on those (they acquire an internal lock before action).

Cheers,

a+