Skip to contentSkip to conversation

rtc: pch-rtc: add Intel Series PCH built-in read-only RTC

PATCH In review Ivan Mikhaylov 5 participants 12 messages Aug 10, 2021 – Sep 25, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover rtc: pch-rtc: add Intel Series PCH built-in read-only RTC

Add RTC driver with dt binding tree document. Also this driver adds one sysfs attribute for host power control which I think is odd for RTC driver. Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not good way too from my point of view. Is there any better approach?

Ivan Mikhaylov (2):
rtc: pch-rtc: add RTC driver for Intel Series PCH
dt-bindings: rtc: provide RTC PCH device tree binding doc

 .../bindings/rtc/intel,pch-rtc.yaml           |  39 +++++
 drivers/rtc/Kconfig                           |  10 ++
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-pch.c                         | 148 ++++++++++++++++++
 4 files changed, 198 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/intel,pch-rtc.yaml
 create mode 100644 drivers/rtc/rtc-pch.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 rtc: pch-rtc: add RTC driver for Intel Series PCH

Add the Intel Series PCH built-in read-only RTC. This driver is not for in-system use on x86 but rather is for external access over I2C from a BMC.

---
 drivers/rtc/Kconfig   |  10 +++
 drivers/rtc/Makefile  |   1 +
 drivers/rtc/rtc-pch.c | 148 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 drivers/rtc/rtc-pch.c
drivers/rtc/Kconfig +10 -0
index 12153d5801ce..4f31bcbf0736 100644
@@ -555,6 +555,16 @@ config RTC_DRV_PALMAS
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-palma.
 
+config RTC_DRV_PCH
+	tristate "PCH RTC driver"
+	help
+	  If you say yes here you get support for the Intel Series PCH
+	  built-in read-only RTC. This driver is not for in-system use on x86,
+	  but rather is for external access over I2C from a BMC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-pch.
+
 config RTC_DRV_TPS6586X
 	tristate "TI TPS6586X RTC driver"
 	depends on MFD_TPS6586X
drivers/rtc/Makefile +1 -0
index 2dd0dd956b0e..cb2804433d87 100644
@@ -121,6 +121,7 @@ obj-$(CONFIG_RTC_DRV_PCF8523)	+= rtc-pcf8523.o
 obj-$(CONFIG_RTC_DRV_PCF85363)	+= rtc-pcf85363.o
 obj-$(CONFIG_RTC_DRV_PCF8563)	+= rtc-pcf8563.o
 obj-$(CONFIG_RTC_DRV_PCF8583)	+= rtc-pcf8583.o
+obj-$(CONFIG_RTC_DRV_PCH)	+= rtc-pch.o
 obj-$(CONFIG_RTC_DRV_PIC32)	+= rtc-pic32.o
 obj-$(CONFIG_RTC_DRV_PL030)	+= rtc-pl030.o
 obj-$(CONFIG_RTC_DRV_PL031)	+= rtc-pl031.o
drivers/rtc/rtc-pch.c new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 1/2] rtc: pch-rtc: add RTC driver for Intel Series PCH

drivers/rtc/Kconfig config RTC_DRV_PALMAS · line 561

Quoted 4 lines · Ivan Mikhaylov
drivers/rtc/Kconfig +4 -0
+config RTC_DRV_PCH
+	tristate "PCH RTC driver"
+	help
+	  If you say yes here you get support for the Intel Series PCH

I'm afraid this is really lacking some specification of devices that are supported. Is it really everything that Intel currently calls PCH?

drivers/rtc/rtc-pch.c line 43

Quoted 12 lines
drivers/rtc/rtc-pch.c new file +12 -0
+static int pch_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct pch *pch = i2c_get_clientdata(client);
+	unsigned char rtc_data[NUM_TIME_REGS] = {0};
+	int rc;
+
+	rc = regmap_bulk_read(pch->regmap, PCH_REG_SC, rtc_data, NUM_TIME_REGS);
+	if (rc < 0) {
+		dev_err(dev, "fail to read time reg(%d)\n", rc);
+		return rc;
+	}

Citing 26.7.2.3 from C620 (Lewisburg/Purley) datasheet:

"The PCH SMBus slave interface only supports Byte Read operation. The external SMBus master will read the RTC time bytes one after another. It is software’s responsibility to check and manage the possible time rollover when subsequent time bytes are read.

For example, assuming the RTC time is 11 hours: 59 minutes: 59 seconds. When the external SMBus master reads the hour as 11, then proceeds to read the minute, it is possible that the rollover happens between the reads and the minute is read as 0. This results in 11
hours: 0 minutes instead of the correct time of 12 hours: 0 minutes. Unless it is certain that rollover will not occur, software is required to detect the possible time rollover by reading multiple times such that the read time bytes can be adjusted accordingly if needed."

Should this be taken additional care of somehow?

Quoted 4 lines
drivers/rtc/rtc-pch.c new file +4 -0
+static ssize_t force_off_store(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{

drivers/rtc/rtc-pch.c line 69

Quoted 10 lines
drivers/rtc/rtc-pch.c new file +10 -0
+	struct i2c_client *client = to_i2c_client(dev);
+	struct pch *pch = i2c_get_clientdata(client);
+	unsigned long val;
+	int rc;
+
+	if (kstrtoul(buf, 10, &val))
+		return -EINVAL;
+
+	if (val) {
+		/* 0x02 host force off */

I wonder why you write "host force off" while the C620 datasheet calls it "Unconditional Power Down", does your PCH manual use different naming?

In any case this doesn't belong to an RTC driver, as previously noted.

Signature · 2 lines
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:[email protected]
#3 lore raw

Re: [PATCH 1/2] rtc: pch-rtc: add RTC driver for Intel Series PCH

Quoted 8 lines · Paul Fertser

drivers/rtc/Kconfig config RTC_DRV_PALMAS · line 561

Quoted 4 lines · Ivan Mikhaylov
drivers/rtc/Kconfig +4 -0
+config RTC_DRV_PCH
+	tristate "PCH RTC driver"
+	help
+	  If you say yes here you get support for the Intel Series PCH

I'm afraid this is really lacking some specification of devices that are supported. Is it really everything that Intel currently calls PCH?

Yes, from infromation that I know.

Quoted 30 lines

drivers/rtc/rtc-pch.c line 43

Quoted 12 lines
drivers/rtc/rtc-pch.c new file +12 -0
+static int pch_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct pch *pch = i2c_get_clientdata(client);
+	unsigned char rtc_data[NUM_TIME_REGS] = {0};
+	int rc;
+
+	rc = regmap_bulk_read(pch->regmap, PCH_REG_SC, rtc_data, NUM_TIME_REGS);
+	if (rc < 0) {
+		dev_err(dev, "fail to read time reg(%d)\n", rc);
+		return rc;
+	}

Citing 26.7.2.3 from C620 (Lewisburg/Purley) datasheet:

"The PCH SMBus slave interface only supports Byte Read operation. The external SMBus master will read the RTC time bytes one after another. It is software’s responsibility to check and manage the possible time rollover when subsequent time bytes are read.

For example, assuming the RTC time is 11 hours: 59 minutes: 59 seconds. When the external SMBus master reads the hour as 11, then proceeds to read the minute, it is possible that the rollover happens between the reads and the minute is read as 0. This results in 11
hours: 0 minutes instead of the correct time of 12 hours: 0 minutes. Unless it is certain that rollover will not occur, software is required to detect the possible time rollover by reading multiple times such that the read time bytes can be adjusted accordingly if needed."

Quoted 1 line

Should this be taken additional care of somehow?

1. .use_single_read in regmap_config.
2. Maybe that is the right place for rollover check.

Quoted 10 lines
Quoted 10 lines
drivers/rtc/rtc-pch.c new file +10 -0
+static ssize_t force_off_store(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct pch *pch = i2c_get_clientdata(client);
+	unsigned long val;
+	int rc;
+
+	if (kstrtoul(buf, 10, &val))
Quoted 8 lines

drivers/rtc/rtc-pch.c line 69

Quoted 4 lines
drivers/rtc/rtc-pch.c new file +4 -0
+		return -EINVAL;
+
+	if (val) {
+		/* 0x02 host force off */

I wonder why you write "host force off" while the C620 datasheet calls it "Unconditional Power Down", does your PCH manual use different naming?

It just a synonym, does the same. I can change it but first it's need to be decided if attribute would go or not.

Thanks.

#4 lore raw

Re: [PATCH 1/2] rtc: pch-rtc: add RTC driver for Intel Series PCH

Quoted 66 lines · Ivan Mikhaylov
Quoted 8 lines · Paul Fertser

drivers/rtc/Kconfig config RTC_DRV_PALMAS · line 561

Quoted 4 lines · Ivan Mikhaylov
drivers/rtc/Kconfig +4 -0
+config RTC_DRV_PCH
+	tristate "PCH RTC driver"
+	help
+	  If you say yes here you get support for the Intel Series PCH

I'm afraid this is really lacking some specification of devices that are supported. Is it really everything that Intel currently calls PCH?

Yes, from infromation that I know.

Quoted 30 lines

drivers/rtc/rtc-pch.c line 43

Quoted 12 lines
drivers/rtc/rtc-pch.c new file +12 -0
+static int pch_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct pch *pch = i2c_get_clientdata(client);
+	unsigned char rtc_data[NUM_TIME_REGS] = {0};
+	int rc;
+
+	rc = regmap_bulk_read(pch->regmap, PCH_REG_SC, rtc_data, NUM_TIME_REGS);
+	if (rc < 0) {
+		dev_err(dev, "fail to read time reg(%d)\n", rc);
+		return rc;
+	}

Citing 26.7.2.3 from C620 (Lewisburg/Purley) datasheet:

"The PCH SMBus slave interface only supports Byte Read operation. The external SMBus master will read the RTC time bytes one after another. It is software’s responsibility to check and manage the possible time rollover when subsequent time bytes are read.

For example, assuming the RTC time is 11 hours: 59 minutes: 59 seconds. When the external SMBus master reads the hour as 11, then proceeds to read the minute, it is possible that the rollover happens between the reads and the minute is read as 0. This results in 11
hours: 0 minutes instead of the correct time of 12 hours: 0 minutes. Unless it is certain that rollover will not occur, software is required to detect the possible time rollover by reading multiple times such that the read time bytes can be adjusted accordingly if needed."

Quoted 1 line

Should this be taken additional care of somehow?

1. .use_single_read in regmap_config.
2. Maybe that is the right place for rollover check.

Quoted 10 lines
Quoted 10 lines
drivers/rtc/rtc-pch.c new file +10 -0
+static ssize_t force_off_store(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct pch *pch = i2c_get_clientdata(client);
+	unsigned long val;
+	int rc;
+
+	if (kstrtoul(buf, 10, &val))
Quoted 8 lines

drivers/rtc/rtc-pch.c line 69

Quoted 4 lines
drivers/rtc/rtc-pch.c new file +4 -0
+		return -EINVAL;
+
+	if (val) {
+		/* 0x02 host force off */

I wonder why you write "host force off" while the C620 datasheet calls it "Unconditional Power Down", does your PCH manual use different naming?

Quoted 3 lines

It just a synonym, does the same. I can change it but first it's need to be decided if attribute would go or not.

I would prefer if this was added later on in a later patch, with the proper ABI documentation so that the ABI can be discussed.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH 2/2 dt-bindings: rtc: provide RTC PCH device tree binding doc

In reply to Ivan Mikhaylov

Add I2C Intel Series PCH built-in read-only RTC driver documentation.

---
 .../bindings/rtc/intel,pch-rtc.yaml           | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rtc/intel,pch-rtc.yaml
Documentation/devicetree/bindings/rtc/intel,pch-rtc.yaml new file +39 -0
new file mode 100644
index 000000000000..f49867257f93
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rtc/intel,pch-rtc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Intel Series PCH built-in read-only RTC
+
+maintainers:
+  - Ivan Mikhaylov <[email protected]>
+
+allOf:
+  - $ref: rtc.yaml#
+
+properties:
+  compatible:
+    enum:
+      - intel,pch-rtc
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        rtc@0 {
+            compatible = "intel,pch-rtc";
+            reg = <0x44>;
+        };
+    };
Signature · 1 line
2.31.1
#6 lore raw
In reply to Ivan Mikhaylov
Quoted 4 lines · Ivan Mikhaylov

Add RTC driver with dt binding tree document. Also this driver adds one sysfs attribute for host power control which I think is odd for RTC driver. Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not good way too from my point of view. Is there any better approach?

Reading the C620 datasheet I see this interface also allows other commands (wake up, watchdog feeding, reboot etc.) and reading statuses (e.g Intruder Detect, POWER_OK_BAD).

I think if there's any plan to use anything other but RTC via this interface then the driver should be registered as an MFD.

Signature · 2 lines
Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software!
mailto:[email protected]
#7 lore raw
Quoted 6 lines · Paul Fertser
Quoted 4 lines · Ivan Mikhaylov

Add RTC driver with dt binding tree document. Also this driver adds one sysfs attribute for host power control which I think is odd for RTC driver. Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not good way too from my point of view. Is there any better approach?

Quoted 7 lines

Reading the C620 datasheet I see this interface also allows other commands (wake up, watchdog feeding, reboot etc.) and reading statuses (e.g Intruder Detect, POWER_OK_BAD).

I think if there's any plan to use anything other but RTC via this interface then the driver should be registered as an MFD.

This is not the current thinking, if everything is integrated, then there is no issue registering a watchdog from the RTC driver. I'll let you check with Lee...

However, I'm not sure what is the correct interface for poweroff/reboot control.

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#8 lore raw
Quoted 15 lines · Alexandre Belloni
Quoted 2 lines · Paul Fertser
Quoted 1 line · Ivan Mikhaylov

Add RTC driver with dt binding tree document. Also this driver

adds one sysfs

Quoted 1 line
Quoted 1 line

attribute for host power control which I think is odd for RTC

driver.

Quoted 1 line
Quoted 1 line

Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not

good

Quoted 4 lines
Quoted 1 line

way too from my point of view. Is there any better approach?

Reading the C620 datasheet I see this interface also allows other commands (wake up, watchdog feeding, reboot etc.) and reading

statuses

Quoted 2 lines

(e.g Intruder Detect, POWER_OK_BAD).

Quoted 8 lines
Quoted 3 lines

I think if there's any plan to use anything other but RTC via this interface then the driver should be registered as an MFD.

This is not the current thinking, if everything is integrated, then there is no issue registering a watchdog from the RTC driver. I'll let
you check with Lee...

I think the current statement is "if they are truly disjoint hardware controls" then an MFD might suffice, but if they require software cordination the new auxillary bus seems to be desired.

Quoted 3 lines
Quoted 1 line

However, I'm not sure what is the correct interface for

poweroff/reboot
control.

While there is a gpio interface to a simple regulator switch, the project to date has been asserting direct or indirect
gpios etc to control the host. If these are events to
trigger a change in state and not a direct state change that some controller trys to follow, maybe a message delivery
model? (this is not to reboot or cycle the bmc).

milton

#9 lore raw
Quoted 21 lines · Milton Miller II
Quoted 19 lines · Alexandre Belloni
Quoted 2 lines · Paul Fertser
Quoted 1 line · Ivan Mikhaylov

Add RTC driver with dt binding tree document. Also this driver

adds one sysfs

Quoted 1 line
Quoted 1 line

attribute for host power control which I think is odd for RTC

driver.

Quoted 1 line
Quoted 1 line

Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not

good

Quoted 4 lines
Quoted 1 line

way too from my point of view. Is there any better approach?

Reading the C620 datasheet I see this interface also allows other commands (wake up, watchdog feeding, reboot etc.) and reading

statuses

Quoted 5 lines

(e.g Intruder Detect, POWER_OK_BAD).

I think if there's any plan to use anything other but RTC via this interface then the driver should be registered as an MFD.

Quoted 9 lines
Quoted 4 lines

This is not the current thinking, if everything is integrated, then there is no issue registering a watchdog from the RTC driver. I'll let
you check with Lee...

I think the current statement is "if they are truly disjoint hardware controls" then an MFD might suffice, but if they require software cordination the new auxillary bus seems to be desired.

Honestly, the auxiliary bus doesn't provide anything that you can't do by registering a device in multiple subsystem from a single driver. (Lee Jones, Mark Brown and I did complain at the time that this was yet another back channel for misuses).

Quoted 12 lines
Quoted 3 lines
Quoted 1 line

However, I'm not sure what is the correct interface for

poweroff/reboot
control.

While there is a gpio interface to a simple regulator switch, the project to date has been asserting direct or indirect
gpios etc to control the host. If these are events to
trigger a change in state and not a direct state change that some controller trys to follow, maybe a message delivery
model? (this is not to reboot or cycle the bmc).

milton

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#10 lore raw
Quoted 32 lines · Alexandre Belloni
Quoted 21 lines · Milton Miller II
Quoted 19 lines · Alexandre Belloni
Quoted 2 lines · Paul Fertser
Quoted 1 line · Ivan Mikhaylov

Add RTC driver with dt binding tree document. Also this driver

adds one sysfs

Quoted 1 line
Quoted 1 line

attribute for host power control which I think is odd for RTC

driver.

Quoted 1 line
Quoted 1 line

Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not

good

Quoted 4 lines
Quoted 1 line

way too from my point of view. Is there any better approach?

Reading the C620 datasheet I see this interface also allows other commands (wake up, watchdog feeding, reboot etc.) and reading

statuses

Quoted 5 lines

(e.g Intruder Detect, POWER_OK_BAD).

I think if there's any plan to use anything other but RTC via this interface then the driver should be registered as an MFD.

Quoted 9 lines
Quoted 4 lines

This is not the current thinking, if everything is integrated, then there is no issue registering a watchdog from the RTC driver. I'll let
you check with Lee...

I think the current statement is "if they are truly disjoint hardware controls" then an MFD might suffice, but if they require software cordination the new auxillary bus seems to be desired.

Quoted 18 lines

Honestly, the auxiliary bus doesn't provide anything that you can't do by registering a device in multiple subsystem from a single driver. (Lee Jones, Mark Brown and I did complain at the time that this was yet another back channel for misuses).

Quoted 12 lines
Quoted 3 lines
Quoted 1 line

However, I'm not sure what is the correct interface for

poweroff/reboot
control.

While there is a gpio interface to a simple regulator switch, the project to date has been asserting direct or indirect gpios etc to control the host.   If these are events to trigger a change in state and not a direct state change that some controller trys to follow, maybe a message delivery model?   (this is not to reboot or cycle the bmc).

milton

Alexandre, gentle reminder about this one series. I can get rid off from sysfs attribute and put it like RO rtc without any additional things for now as starter.

Thanks.

#11 lore raw
Quoted 49 lines · Ivan Mikhaylov
Quoted 48 lines · Alexandre Belloni
Quoted 21 lines · Milton Miller II
Quoted 19 lines · Alexandre Belloni
Quoted 2 lines · Paul Fertser
Quoted 1 line · Ivan Mikhaylov

Add RTC driver with dt binding tree document. Also this driver

adds one sysfs

Quoted 1 line
Quoted 1 line

attribute for host power control which I think is odd for RTC

driver.

Quoted 1 line
Quoted 1 line

Need I cut it off and use I2C_SLAVE_FORCE? I2C_SLAVE_FORCE is not

good

Quoted 4 lines
Quoted 1 line

way too from my point of view. Is there any better approach?

Reading the C620 datasheet I see this interface also allows other commands (wake up, watchdog feeding, reboot etc.) and reading

statuses

Quoted 5 lines

(e.g Intruder Detect, POWER_OK_BAD).

I think if there's any plan to use anything other but RTC via this interface then the driver should be registered as an MFD.

Quoted 9 lines
Quoted 4 lines

This is not the current thinking, if everything is integrated, then there is no issue registering a watchdog from the RTC driver. I'll let
you check with Lee...

I think the current statement is "if they are truly disjoint hardware controls" then an MFD might suffice, but if they require software cordination the new auxillary bus seems to be desired.

Honestly, the auxiliary bus doesn't provide anything that you can't do by registering a device in multiple subsystem from a single driver. (Lee Jones, Mark Brown and I did complain at the time that this was yet another back channel for misuses).

Quoted 11 lines
Quoted 3 lines
Quoted 1 line

However, I'm not sure what is the correct interface for

poweroff/reboot
control.

While there is a gpio interface to a simple regulator switch, the project to date has been asserting direct or indirect gpios etc to control the host.   If these are events to trigger a change in state and not a direct state change that some controller trys to follow, maybe a message delivery model?   (this is not to reboot or cycle the bmc).

Quoted 9 lines
Quoted 2 lines
Quoted 1 line

milton

Alexandre, gentle reminder about this one series. I can get rid off from sysfs attribute and put it like RO rtc without any additional things for now as starter.

Thanks.

ping

Thanks.