Skip to contentSkip to conversation

pm: Add power off control

PATCH Superseded AnilKumar Ch 5 participants 29 messages Nov 5, 2012 – Nov 16, 2012

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover pm: Add power off control

Add PM power_off control to rtc driver, along with this PMIC status is set to STATUS_OFF to shutdown PMIC if PWR_EN is toggled by RTC module.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

These patches were tested on AM335x-Bone.

AnilKumar Ch (2):
ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone
ARM: dts: AM33XX: Enable system power off control in am335x-bone

Colin Foe-Parker (2):
mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle
rtc: OMAP: Add system pm_power_off to rtc driver

 .../devicetree/bindings/regulator/tps65217.txt     |    4 +
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 arch/arm/boot/dts/am335x-bone.dts                  |    6 ++
 drivers/mfd/tps65217.c                             |   12 +++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 5 files changed, 105 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

From: Colin Foe-Parker <[email protected]>

Set tps65217 PMIC status to OFF if power enable toggle is supported. Also adds platform data flag, which should be passed from board init data.

[anilkumar at ti.com: move the additions to tps65217 MFD driver]
---
 .../devicetree/bindings/regulator/tps65217.txt     |    4 ++++
 drivers/mfd/tps65217.c                             |   12 ++++++++++++
 2 files changed, 16 insertions(+)
Documentation/devicetree/bindings/regulator/tps65217.txt +4 -0
index d316fb8..4f05d20 100644
@@ -11,6 +11,9 @@ Required properties:
   using the standard binding for regulators found at
   Documentation/devicetree/bindings/regulator/regulator.txt.
 
+Optional properties:
+- ti,pmic-shutdown-controller: Telling the PMIC to shutdown on PWR_EN toggle.
+
   The valid names for regulators are:
   tps65217: dcdc1, dcdc2, dcdc3, ldo1, ldo2, ldo3 and ldo4
 
@@ -20,6 +23,7 @@ Example:
 
 	tps: tps at 24 {
 		compatible = "ti,tps65217";
+		ti,pmic-shutdown-controller;
 
 		regulators {
 			dcdc1_reg: dcdc1 {
drivers/mfd/tps65217.c +12 -0
index 3fb32e6..c7f17d8 100644
@@ -160,6 +160,7 @@ static int __devinit tps65217_probe(struct i2c_client *client,
 	unsigned int version;
 	unsigned int chip_id = ids->driver_data;
 	const struct of_device_id *match;
+	bool status_off = false;
 	int ret;
 
 	if (client->dev.of_node) {
@@ -170,6 +171,8 @@ static int __devinit tps65217_probe(struct i2c_client *client,
 			return -EINVAL;
 		}
 		chip_id = (unsigned int)match->data;
+		status_off = of_property_read_bool(client->dev.of_node,
+					"ti,pmic-shutdown-controller");
 	}
 
 	if (!chip_id) {
@@ -207,6 +210,15 @@ static int __devinit tps65217_probe(struct i2c_client *client,
 		return ret;
 	}
 
+	/* Set the PMIC to shutdown on PWR_EN toggle */
+	if (status_off) {
+		ret = tps65217_set_bits(tps, TPS65217_REG_STATUS,
+				TPS65217_STATUS_OFF, TPS65217_STATUS_OFF,
+				TPS65217_PROTECT_NONE);
+		if (ret)
+			dev_warn(tps->dev, "unable to set the status OFF\n");
+	}
+
 	dev_info(tps->dev, "TPS65217 ID %#x version 1.%d\n",
 			(version & TPS65217_CHIPID_CHIP_MASK) >> 4,
 			version & TPS65217_CHIPID_REV_MASK);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

+ Mark

Quoted 19 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Set tps65217 PMIC status to OFF if power enable toggle is supported. Also adds platform data flag, which should be passed from board init data.

[anilkumar at ti.com: move the additions to tps65217 MFD driver]
---
 .../devicetree/bindings/regulator/tps65217.txt     |    4 ++++
 drivers/mfd/tps65217.c                             |   12 ++++++++++++
 2 files changed, 16 insertions(+)
Documentation/devicetree/bindings/regulator/tps65217.txt +0 -0
index d316fb8..4f05d20 100644

Documentation/devicetree/bindings/regulator/tps65217.txt Required properties: · line 15

Quoted 5 lines
Documentation/devicetree/bindings/regulator/tps65217.txt +2 -0
@@ -11,6 +11,9 @@ Required properties:
   using the standard binding for regulators found at
   Documentation/devicetree/bindings/regulator/regulator.txt.
 
+Optional properties:
+- ti,pmic-shutdown-controller: Telling the PMIC to shutdown on PWR_EN toggle.

That sounds like a generic functionality to me. Don't we have some more generic way to handle that?

If not, that should probably not be a TI only attribute.

It looks like a GPIO like kind of interface at PMIC level.

Regards,
Benoit

Quoted 50 lines
Documentation/devicetree/bindings/regulator/tps65217.txt +2 -0
+
   The valid names for regulators are:
   tps65217: dcdc1, dcdc2, dcdc3, ldo1, ldo2, ldo3 and ldo4
 
@@ -20,6 +23,7 @@ Example:
 
 	tps: tps at 24 {
 		compatible = "ti,tps65217";
+		ti,pmic-shutdown-controller;
 
 		regulators {
 			dcdc1_reg: dcdc1 {
drivers/mfd/tps65217.c +12 -0
index 3fb32e6..c7f17d8 100644
@@ -160,6 +160,7 @@ static int __devinit tps65217_probe(struct i2c_client *client,
 	unsigned int version;
 	unsigned int chip_id = ids->driver_data;
 	const struct of_device_id *match;
+	bool status_off = false;
 	int ret;
 
 	if (client->dev.of_node) {
@@ -170,6 +171,8 @@ static int __devinit tps65217_probe(struct i2c_client *client,
 			return -EINVAL;
 		}
 		chip_id = (unsigned int)match->data;
+		status_off = of_property_read_bool(client->dev.of_node,
+					"ti,pmic-shutdown-controller");
 	}
 
 	if (!chip_id) {
@@ -207,6 +210,15 @@ static int __devinit tps65217_probe(struct i2c_client *client,
 		return ret;
 	}
 
+	/* Set the PMIC to shutdown on PWR_EN toggle */
+	if (status_off) {
+		ret = tps65217_set_bits(tps, TPS65217_REG_STATUS,
+				TPS65217_STATUS_OFF, TPS65217_STATUS_OFF,
+				TPS65217_PROTECT_NONE);
+		if (ret)
+			dev_warn(tps->dev, "unable to set the status OFF\n");
+	}
+
 	dev_info(tps->dev, "TPS65217 ID %#x version 1.%d\n",
 			(version & TPS65217_CHIPID_CHIP_MASK) >> 4,
 			version & TPS65217_CHIPID_REV_MASK);
#3 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 25 lines · Benoit

+ Mark

Quoted 22 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Set tps65217 PMIC status to OFF if power enable toggle is supported. Also adds platform data flag, which should be passed from board init data.

[anilkumar at ti.com: move the additions to tps65217 MFD driver]
---
 .../devicetree/bindings/regulator/tps65217.txt     |    4 ++++
 drivers/mfd/tps65217.c                             |   12 ++++++++++++
 2 files changed, 16 insertions(+)
Documentation/devicetree/bindings/regulator/tps65217.txt +0 -0
index d316fb8..4f05d20 100644
@@ -11,6 +11,9 @@ Required properties:
   using the standard binding for regulators found at
   Documentation/devicetree/bindings/regulator/regulator.txt.
 
Quoted 5 lines

Documentation/devicetree/bindings/regulator/tps65217.txt Required properties: · line 15

Quoted 2 lines
Documentation/devicetree/bindings/regulator/tps65217.txt +2 -0
+Optional properties:
+- ti,pmic-shutdown-controller: Telling the PMIC to shutdown on PWR_EN toggle.

That sounds like a generic functionality to me. Don't we have some more generic way to handle that?

But STATUS_OFF should be set only if Board supports it, otherwise this change doesn't make sense.

Quoted 4 lines

If not, that should probably not be a TI only attribute.

It looks like a GPIO like kind of interface at PMIC level.

I agree this should be a generic parameter, but in some regulators this STATUS OFF control might not be available. This is in my mind while name this parameter.

Thanks
AnilKumar

#4 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

In reply to Benoit Cousson
Quoted 9 lines · Benoit Cousson
Quoted 2 lines · AnilKumar Ch

+Optional properties:
+- ti,pmic-shutdown-controller: Telling the PMIC to shutdown on PWR_EN toggle.

That sounds like a generic functionality to me. Don't we have some more generic way to handle that?

If not, that should probably not be a TI only attribute.

It's pretty unusual to have this configurable as a single thing rather
than as part of flexible power sequencing or something that's just fixed
in silicon.
-------------- 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/20121114/dbbb5772/attachment.sig>

#5 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 6 lines · Mark Brown
Quoted 4 lines · Benoit Cousson
Quoted 2 lines · AnilKumar Ch

+Optional properties:
+- ti,pmic-shutdown-controller: Telling the PMIC to shutdown on PWR_EN toggle.

Quoted 9 lines
Quoted 4 lines

That sounds like a generic functionality to me. Don't we have some more generic way to handle that?

If not, that should probably not be a TI only attribute.

It's pretty unusual to have this configurable as a single thing rather than as part of flexible power sequencing or something that's just fixed in silicon.

"[PATCH 2/4] rtc: OMAP: Add system pm_power_off to rtc driver" thread have the details of how PMIC is connected to RTC module of SoC.

As part of the power_off sequence we have
1. To write STATUS_OFF in TPS65217 PMIC. If we do so then PMIC will go to shutdown if PWR_EN is pulled-down. (This patch doing this)
2. To pull down the PWR_EN signal we have to set PMIC_PWR_EN in RTC module and trigger ALARM2 event. (This piece of code in 2/4 patch).

Thanks
AnilKumar

#6 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

In reply to Mark Brown
Quoted 10 lines · Chimata
Quoted 9 lines · Mark Brown
Quoted 7 lines · Benoit Cousson
Quoted 2 lines · AnilKumar Ch

+Optional properties:
+- ti,pmic-shutdown-controller: Telling the PMIC to shutdown on PWR_EN toggle.

That sounds like a generic functionality to me. Don't we have some more generic way to handle that?

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

If not, that should probably not be a TI only attribute.

It's pretty unusual to have this configurable as a single thing rather than as part of flexible power sequencing or something that's just fixed in silicon.

Mark,

Quoted 1 line

From these two threads we can infer that this is handled in power_off

sequence only. And this is feature of PMIC to go to shutdown mode nothing to be fixed in silicon. PWR_EN line can be connected to any of these like PRCM control or GPIO or some other instead of RTC(in this case).

Thanks
AnilKumar

Quoted 13 lines

"[PATCH 2/4] rtc: OMAP: Add system pm_power_off to rtc driver" thread have the details of how PMIC is connected to RTC module of SoC.

As part of the power_off sequence we have
1. To write STATUS_OFF in TPS65217 PMIC. If we do so then PMIC will go to shutdown if PWR_EN is pulled-down. (This patch doing this)
2. To pull down the PWR_EN signal we have to set PMIC_PWR_EN in RTC module and trigger ALARM2 event. (This piece of code in 2/4 patch).

Thanks
AnilKumar

#7 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 4 lines · Chimata

From these two threads we can infer that this is handled in power_off sequence only. And this is feature of PMIC to go to shutdown mode nothing to be fixed in silicon. PWR_EN line can be connected to any of these like PRCM control or GPIO or some other instead of RTC(in this case).

OK, but why are you telling me this? What are you looking for me to do
with this information?
-------------- 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/20121114/3d0017b1/attachment-0001.sig>

#8 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 10 lines · Mark Brown
Quoted 4 lines · Chimata

From these two threads we can infer that this is handled in power_off sequence only. And this is feature of PMIC to go to shutdown mode nothing to be fixed in silicon. PWR_EN line can be connected to any of these like PRCM control or GPIO or some other instead of RTC(in this case).

OK, but why are you telling me this? What are you looking for me to do with this information?

Mark,

Earlier you have a comment on this thread, I am adding my comments on top of it. Sorry if I am in wrong direction.

Thanks
AnilKumar

#9 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 2 lines · Chimata

Earlier you have a comment on this thread, I am adding my comments on top of it. Sorry if I am in wrong direction.

Ah, I see. I was just commenting because Benoit was asking if this
should be supported with a standard framework feature - I'm not
convinced that it should right now as there's not any clear patterns in
hardware behaviour. I've no specific interest in this system.
-------------- 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/20121114/82583125/attachment.sig>

#10 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Hi Mark,

Quoted 9 lines · Mark Brown
Quoted 2 lines · Chimata

Earlier you have a comment on this thread, I am adding my comments on top of it. Sorry if I am in wrong direction.

Ah, I see. I was just commenting because Benoit was asking if this should be supported with a standard framework feature - I'm not convinced that it should right now as there's not any clear patterns in hardware behaviour. I've no specific interest in this system.

I was wondering that, because exposing a pin to control the whole PMIC low power mode seems to be something that should be generic enough to be handled by the regulator framework.

In the current situation we do have a pwr_en pin that can be controlled by a GPIO or whatever signal from the SoC.
That's very similar, at PMIC level, to the fixedregulator that allow a GPIO binding to enable it.

Don't you think that should deserve a support in the fmwk?

Regards,
Benoit

#11 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 3 lines · Benoit Cousson

I was wondering that, because exposing a pin to control the whole PMIC low power mode seems to be something that should be generic enough to be handled by the regulator framework.

Having something that's controlled by software is really not at all generic - suspending a PMIC from a GPIO is generally tied in very closely with the CPU power sequencing which means it's typically some combination of very hard coded things that we can't control or part of much wider control of sequencing.

Quoted 6 lines

In the current situation we do have a pwr_en pin that can be controlled by a GPIO or whatever signal from the SoC.
That's very similar, at PMIC level, to the fixedregulator that allow a GPIO binding to enable it.

Don't you think that should deserve a support in the fmwk?

I'm not seeing a coherent description of a feature here - what exactly
are you proposing that we do? When and how would this GPIO be set for
example?
-------------- 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/20121114/c909c844/attachment.sig>

#12 lore raw

PATCH 1/4 mfd: tps65217: Set PMIC to shutdowm on PWR_EN toggle

Quoted 17 lines · Mark Brown
Quoted 3 lines · Benoit Cousson

I was wondering that, because exposing a pin to control the whole PMIC low power mode seems to be something that should be generic enough to be handled by the regulator framework.

Having something that's controlled by software is really not at all generic - suspending a PMIC from a GPIO is generally tied in very closely with the CPU power sequencing which means it's typically some combination of very hard coded things that we can't control or part of much wider control of sequencing.

Quoted 4 lines

In the current situation we do have a pwr_en pin that can be controlled by a GPIO or whatever signal from the SoC.
That's very similar, at PMIC level, to the fixedregulator that allow a GPIO binding to enable it.

Quoted 5 lines
Quoted 1 line

Don't you think that should deserve a support in the fmwk?

I'm not seeing a coherent description of a feature here - what exactly are you proposing that we do? When and how would this GPIO be set for example?

It would be better if these patches are going in like this till the framework exists. We can change/move this portion once the framework is defined for this kind.

Thanks
AnilKumar

#13 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +5 -0
index b47aa41..8d9f4f9 100644
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.
+
 Example:
 
 rtc at 1c23000 {
@@ -14,4 +18,5 @@ rtc at 1c23000 {
 	interrupts = <19
 		      19>;
 	interrupt-parent = <&intc>;
+	ti,system-power-controller;
 };
drivers/rtc/rtc-omap.c +78 -1

123 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#14 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

Hi Anil / Colin,

Quoted 29 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +0 -0
index b47aa41..8d9f4f9 100644

Documentation/devicetree/bindings/rtc/rtc-omap.txt Required properties: · line 11

Quoted 6 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +3 -0
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.
It does not look super generic, and I'm wondering if we should not use instead some regulator binding to reflect the connection of the RTC to a regulator.

But without the board / soc spec it is hard to tell :-(

Regards,
Benoit

Quoted 143 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +2 -0
+
 Example:
 
 rtc at 1c23000 {
@@ -14,4 +18,5 @@ rtc at 1c23000 {
 	interrupts = <19
 		      19>;
 	interrupt-parent = <&intc>;
+	ti,system-power-controller;
 };
drivers/rtc/rtc-omap.c +78 -1
index 6009714..2d90170 100644
@@ -72,6 +72,14 @@
 #define OMAP_RTC_KICK0_REG		0x6c
 #define OMAP_RTC_KICK1_REG		0x70
 
+#define OMAP_RTC_ALARM2_SECONDS_REG	0x80
+#define OMAP_RTC_ALARM2_MINUTES_REG	0x84
+#define OMAP_RTC_ALARM2_HOURS_REG	0x88
+#define OMAP_RTC_ALARM2_DAYS_REG	0x8c
+#define OMAP_RTC_ALARM2_MONTHS_REG	0x90
+#define OMAP_RTC_ALARM2_YEARS_REG	0x94
+#define OMAP_RTC_PMIC_REG		0x98
+
 /* OMAP_RTC_CTRL_REG bit fields: */
 #define OMAP_RTC_CTRL_SPLIT		(1<<7)
 #define OMAP_RTC_CTRL_DISABLE		(1<<6)
@@ -93,15 +101,24 @@
 #define OMAP_RTC_STATUS_BUSY            (1<<0)
 
 /* OMAP_RTC_INTERRUPTS_REG bit fields: */
+#define OMAP_RTC_INTERRUPTS_IT_ALARM2   (1<<4)
 #define OMAP_RTC_INTERRUPTS_IT_ALARM    (1<<3)
 #define OMAP_RTC_INTERRUPTS_IT_TIMER    (1<<2)
 
+/* OMAP_RTC_PMIC_REG bit fields: */
+#define OMAP_RTC_PMIC_POWER_EN_EN       (1<<16)
+
 /* OMAP_RTC_KICKER values */
 #define	KICK0_VALUE			0x83e70b13
 #define	KICK1_VALUE			0x95a4f1e0
 
 #define	OMAP_RTC_HAS_KICKER		0x1
 
+#define SHUTDOWN_TIME_SEC		2
+#define SECS_IN_MIN			60
+#define WAIT_AFTER			(SECS_IN_MIN - SHUTDOWN_TIME_SEC)
+#define WAIT_TIME_MS			(SHUTDOWN_TIME_SEC * 1000)
+
 static void __iomem	*rtc_base;
 
 #define rtc_read(addr)		readb(rtc_base + (addr))
@@ -290,6 +307,58 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 	return 0;
 }
 
+/*
+ * rtc_power_off: Set the pmic power off sequence. The RTC generates
+ * pmic_pwr_enable control, which can be used to control an external
+ * PMIC.
+ */
+static void rtc_power_off(void)
+{
+	u32 val;
+	struct rtc_time tm;
+	spinlock_t lock;
+	unsigned long flags;
+
+	spin_lock_init(&lock);
+
+	/* Set PMIC power enable */
+	val = readl(rtc_base + OMAP_RTC_PMIC_REG);
+	writel(val | OMAP_RTC_PMIC_POWER_EN_EN, rtc_base + OMAP_RTC_PMIC_REG);
+
+	/* Wait few seconds instead of rollover */
+	do {
+		omap_rtc_read_time(NULL, &tm);
+		if (WAIT_AFTER <= tm.tm_sec)
+			mdelay(WAIT_TIME_MS);
+	} while (WAIT_AFTER <= tm.tm_sec);
+
+	/* Add shutdown time to the current value */
+	tm.tm_sec += SHUTDOWN_TIME_SEC;
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/* Set the ALARM2 time */
+	rtc_write(tm.tm_sec, OMAP_RTC_ALARM2_SECONDS_REG);
+	rtc_write(tm.tm_min, OMAP_RTC_ALARM2_MINUTES_REG);
+	rtc_write(tm.tm_hour, OMAP_RTC_ALARM2_HOURS_REG);
+	rtc_write(tm.tm_mday, OMAP_RTC_ALARM2_DAYS_REG);
+	rtc_write(tm.tm_mon, OMAP_RTC_ALARM2_MONTHS_REG);
+	rtc_write(tm.tm_year, OMAP_RTC_ALARM2_YEARS_REG);
+
+	/* Enable alarm2 interrupt */
+	val = readl(rtc_base + OMAP_RTC_INTERRUPTS_REG);
+	writel(val | OMAP_RTC_INTERRUPTS_IT_ALARM2,
+				rtc_base + OMAP_RTC_INTERRUPTS_REG);
+
+	/* Do not allow to execute any other task */
+	spin_lock_irqsave(&lock, flags);
+	while (1);
+}
+
 static struct rtc_class_ops omap_rtc_ops = {
 	.read_time	= omap_rtc_read_time,
 	.set_time	= omap_rtc_set_time,
@@ -327,12 +396,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
 	struct resource		*res, *mem;
 	struct rtc_device	*rtc;
 	u8			reg, new_ctrl;
+	bool			pm_off = false;
 	const struct platform_device_id *id_entry;
 	const struct of_device_id *of_id;
 
 	of_id = of_match_device(omap_rtc_of_match, &pdev->dev);
-	if (of_id)
+	if (of_id) {
 		pdev->id_entry = of_id->data;
+		pm_off = of_property_read_bool(pdev->dev.of_node,
+					"ti,system-power-controller");
+	}
 
 	omap_rtc_timer = platform_get_irq(pdev, 0);
 	if (omap_rtc_timer <= 0) {
@@ -385,6 +458,10 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, rtc);
 	dev_set_drvdata(&rtc->dev, mem);
 
+	/* RTC power off */
+	if (pm_off && !pm_power_off)
+		pm_power_off = rtc_power_off;
+
 	/* clear pending irqs, and set 1/second periodic,
 	 * which we'll use instead of update irqs
 	 */
#15 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

Hi Benoit,

"I don't know how it is connected at board level, but I'm not sure the binding is the proper one."

Here is a link to the Beaglebone schematic<http://beagleboard.org/static/beaglebone/latest/Docs/Hardware/BONE_SCH.pdf>. The PMIC_PWR_EN net is the one that you should be interested in following.

In the AM335x, this net is connected to the ALARM2 event in the RTC subsystem. If the ALARM2 event is triggered, and the PMIC_PWR_EN pin is configured correctly, the pin is driven low.

In the TPS65217 series PMIC, the PWR_EN I/O can be used to put the entire chip into a low power state. This disables all the power rails in the PMIC with an exception of the rail that powers the RTC power domain.

So when the ALARM2 event occurs, the PWR_EN I/O is pulled low and the entire system into a low power "off" state.

"It does not look super generic, and I'm wondering if we should not use instead some regulator binding to reflect the connection of the RTC to a regulator.

But without the board / soc spec it is hard to tell :-("

This is a good point. I know that there are other omap SOC RTC's that do not support the ALARM2 implementation. That being said, I would argue that there is more of a RTC connection with the implementation than a regulator.

Anil will probably have greater insight into the pro's/con's of the implementation.

-Colin

Colin Foe-Parker // Software Engineer II

Logic PD /// engineering design services

5 Clock Tower Place. Suite 400

Maynard, MA 01754

T // 978.243.2045

colin.foeparker at logicpd.com

www.logicpd.com

/ / / / / / / / / / / / / / / / / / / / / / / / /

This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, you should delete this message and are hereby notified that any disclosure, copying, distribution, or other use of this message, or the taking of any action based on it, is strictly prohibited.

-----Original Message-----
From: Benoit Cousson [mailto:b-cousson at ti.com]
Sent: Monday, November 05, 2012 11:43 AM
To: AnilKumar Ch; Colin FoeParker
Cc: a.zummo at towertech.it; sameo at linux.intel.com; tony at atomide.com; grant.likely at secretlab.ca; rob.herring at calxeda.com; rtc-linux at googlegroups.com; linux-omap at vger.kernel.org; linux-arm-kernel at lists.infradead.org; devicetree-discuss at lists.ozlabs.org
Subject: Re: [PATCH 2/4] rtc: OMAP: Add system pm_power_off to rtc driver

Hi Anil / Colin,

Quoted 63 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of

controlling the BeagleBone system power. The power_off routine can be

hooked up to "pm_power_off" system call.

System power off sequence:-

* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low

* Enable PMIC_POWER_EN in rtc module

* Set rtc ALARM2 time

* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other

process acquire cpu. Otherwise we might see an unexpected behaviour

because we are shutting down all the power rails of SoC except RTC.

Signed-off-by Colin Foe-Parker <colin.foeparker at logicpd.com<mailto:[email protected]>>

[anilkumar at ti.com: move poweroff additions to rtc driver]

Signed-off-by AnilKumar Ch <anilkumar at ti.com<mailto:[email protected]>>

---

 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/rtc/rtc-omap.txt

index b47aa41..8d9f4f9 100644

--- a/Documentation/devicetree/bindings/rtc/rtc-omap.txt

+++ b/Documentation/devicetree/bindings/rtc/rtc-omap.txt

(quoted diff) +0 -0
@@ -6,6 +6,10 @@ Required properties:
 
 - interrupts: rtc timer, alarm interrupts in order
 
 - interrupt-parent: phandle for the interrupt controller

Review Required properties:

Quoted 10 lines
(quoted diff) +4 -0
 
 
 
+Optional properties:
 
+- ti,system-power-controller: Telling whether or not rtc is
 
+controlling
 
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.

It does not look super generic, and I'm wondering if we should not use instead some regulator binding to reflect the connection of the RTC to a regulator.

But without the board / soc spec it is hard to tell :-(

Regards,

Benoit

Quoted 277 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +2 -0
+
 
 Example:
 
 
 
 rtc at 1c23000 {
@@ -14,4 +18,5 @@ rtc at 1c23000 {
 
            interrupts = <19
 
                                  19>;
 
            interrupt-parent = <&intc>;
 
+          ti,system-power-controller;
 
 };
drivers/rtc/rtc-omap.c index renamed from drivers/rtc/rtc-omap.c +0 -0

6009714..2d90170 100644

--- a/drivers/rtc/rtc-omap.c

+++ b/drivers/rtc/rtc-omap.c

drivers/rtc/rtc-omap.c index renamed from drivers/rtc/rtc-omap.c +77 -1
@@ -72,6 +72,14 @@
 
 #define OMAP_RTC_KICK0_REG                         0x6c
 
 #define OMAP_RTC_KICK1_REG                         0x70
 
 
 
+#define OMAP_RTC_ALARM2_SECONDS_REG            0x80
 
+#define OMAP_RTC_ALARM2_MINUTES_REG            0x84
 
+#define OMAP_RTC_ALARM2_HOURS_REG 0x88
 
+#define OMAP_RTC_ALARM2_DAYS_REG     0x8c
 
+#define OMAP_RTC_ALARM2_MONTHS_REG             0x90
 
+#define OMAP_RTC_ALARM2_YEARS_REG   0x94
 
+#define OMAP_RTC_PMIC_REG                        0x98
 
+
 
 /* OMAP_RTC_CTRL_REG bit fields: */
 
 #define OMAP_RTC_CTRL_SPLIT                         (1<<7)
 
 #define OMAP_RTC_CTRL_DISABLE                   (1<<6)
@@ -93,15 +101,24 @@
 
 #define OMAP_RTC_STATUS_BUSY            (1<<0)
 
 
 
 /* OMAP_RTC_INTERRUPTS_REG bit fields: */
 
+#define OMAP_RTC_INTERRUPTS_IT_ALARM2   (1<<4)
 
 #define OMAP_RTC_INTERRUPTS_IT_ALARM    (1<<3)
 
 #define OMAP_RTC_INTERRUPTS_IT_TIMER    (1<<2)
 
 
 
+/* OMAP_RTC_PMIC_REG bit fields: */
 
+#define OMAP_RTC_PMIC_POWER_EN_EN       (1<<16)
 
+
 
 /* OMAP_RTC_KICKER values */
 
 #define           KICK0_VALUE                                    0x83e70b13
 
 #define           KICK1_VALUE                                    0x95a4f1e0
 
 
 
 #define           OMAP_RTC_HAS_KICKER                            0x1
 
 
 
+#define SHUTDOWN_TIME_SEC                         2
 
+#define SECS_IN_MIN                                            60
 
+#define WAIT_AFTER                                              (SECS_IN_MIN - SHUTDOWN_TIME_SEC)
 
+#define WAIT_TIME_MS                                       (SHUTDOWN_TIME_SEC * 1000)
 
+
 
 static void __iomem  *rtc_base;
 
 
 
 #define rtc_read(addr)                            readb(rtc_base + (addr))
@@ -290,6 +307,58 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 
            return 0;
 
 }
 
 
 
+/*
 
+ * rtc_power_off: Set the pmic power off sequence. The RTC generates
 
+ * pmic_pwr_enable control, which can be used to control an external
 
+ * PMIC.
 
+ */
 
+static void rtc_power_off(void)
 
+{
 
+          u32 val;
 
+          struct rtc_time tm;
 
+          spinlock_t lock;
 
+          unsigned long flags;
 
+
 
+          spin_lock_init(&lock);
 
+
 
+          /* Set PMIC power enable */
 
+          val = readl(rtc_base + OMAP_RTC_PMIC_REG);
 
+          writel(val | OMAP_RTC_PMIC_POWER_EN_EN, rtc_base +
 
+OMAP_RTC_PMIC_REG);
 
+
 
+          /* Wait few seconds instead of rollover */
 
+          do {
 
+                          omap_rtc_read_time(NULL, &tm);
 
+                          if (WAIT_AFTER <= tm.tm_sec)
 
+                                          mdelay(WAIT_TIME_MS);
 
+          } while (WAIT_AFTER <= tm.tm_sec);
 
+
 
+          /* Add shutdown time to the current value */
 
+          tm.tm_sec += SHUTDOWN_TIME_SEC;
 
+
 
+          if (tm2bcd(&tm) < 0)
 
+                          return;
 
+
 
+          pr_info("System will go to power_off state in approx. %d secs\n",
 
+                                          SHUTDOWN_TIME_SEC);
 
+
 
+          /* Set the ALARM2 time */
 
+          rtc_write(tm.tm_sec, OMAP_RTC_ALARM2_SECONDS_REG);
 
+          rtc_write(tm.tm_min, OMAP_RTC_ALARM2_MINUTES_REG);
 
+          rtc_write(tm.tm_hour, OMAP_RTC_ALARM2_HOURS_REG);
 
+          rtc_write(tm.tm_mday, OMAP_RTC_ALARM2_DAYS_REG);
 
+          rtc_write(tm.tm_mon, OMAP_RTC_ALARM2_MONTHS_REG);
 
+          rtc_write(tm.tm_year, OMAP_RTC_ALARM2_YEARS_REG);
 
+
 
+          /* Enable alarm2 interrupt */
 
+          val = readl(rtc_base + OMAP_RTC_INTERRUPTS_REG);
 
+          writel(val | OMAP_RTC_INTERRUPTS_IT_ALARM2,
 
+                                                          rtc_base + OMAP_RTC_INTERRUPTS_REG);
 
+
 
+          /* Do not allow to execute any other task */
 
+          spin_lock_irqsave(&lock, flags);
 
+          while (1);
 
+}
 
+
 
 static struct rtc_class_ops omap_rtc_ops = {
 
            .read_time         = omap_rtc_read_time,
 
            .set_time            = omap_rtc_set_time,
@@ -327,12 +396,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
 
            struct resource                 *res, *mem;
 
            struct rtc_device              *rtc;
 
            u8                                           reg, new_ctrl;
 
+          bool                                       pm_off = false;
 
            const struct platform_device_id *id_entry;
 
            const struct of_device_id *of_id;
 
 
 
            of_id = of_match_device(omap_rtc_of_match, &pdev->dev);
 
-           if (of_id)
 
+          if (of_id) {
 
                            pdev->id_entry = of_id->data;
 
+                          pm_off = of_property_read_bool(pdev->dev.of_node,
 
+                                                                          "ti,system-power-controller");
 
+          }
 
 
 
            omap_rtc_timer = platform_get_irq(pdev, 0);
 
            if (omap_rtc_timer <= 0) {
@@ -385,6 +458,10 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
 
            platform_set_drvdata(pdev, rtc);
 
            dev_set_drvdata(&rtc->dev, mem);
 
 
 
+          /* RTC power off */
 
+          if (pm_off && !pm_power_off)

drivers/rtc/rtc-omap.c index static int __init omap_rtc_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/rtc/rtc-omap.c index renamed from drivers/rtc/rtc-omap.c +2 -0
 
+                          pm_power_off = rtc_power_off;
 
+
 
            /* clear pending irqs, and set 1/second periodic,
 
             * which we'll use instead of update irqs
 
             */

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20121105/fc8fde6e/attachment-0001.html>

#16 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to Benoit Cousson
Quoted 35 lines · Benoit

Hi Anil / Colin,

Quoted 32 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +0 -0
index b47aa41..8d9f4f9 100644
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
Quoted 6 lines

Documentation/devicetree/bindings/rtc/rtc-omap.txt Required properties: · line 11

Quoted 3 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +3 -0
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.

Hi Benoit,
________________________________

|   ______          _______      |
|  |      |        |       |     |
|  |RTC   |        |       |     |
|  |PMIC  |  Line  |       |     |
|  |PWR_EN|=======>|PWR_EN |     |
|  |______|        |_______|     |
|  AM335x SoC       TPS65217     |
|                                |
|________________________________|

BeagleBone

This is how RTC PMIC_PWR_EN is connected to PWR_EN of TPS65217 PMIC. Only when RTC pull low in PMIC_PWR_EN then PMIC will go to power off state provided TPS65217 status should be changed to STATUS_OFF.

ALARM2 event should be trigger to configure PMIC_PWR_EN properly then the "Line" driven low so that PMIC will go to shutdown mode.

Thanks
AnilKumar

Quoted 155 lines

It does not look super generic, and I'm wondering if we should not use instead some regulator binding to reflect the connection of the RTC to a regulator.

But without the board / soc spec it is hard to tell :-(

Regards,
Benoit

Quoted 143 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +2 -0
+
 Example:
 
 rtc at 1c23000 {
@@ -14,4 +18,5 @@ rtc at 1c23000 {
 	interrupts = <19
 		      19>;
 	interrupt-parent = <&intc>;
+	ti,system-power-controller;
 };
drivers/rtc/rtc-omap.c +78 -1
index 6009714..2d90170 100644
@@ -72,6 +72,14 @@
 #define OMAP_RTC_KICK0_REG		0x6c
 #define OMAP_RTC_KICK1_REG		0x70
 
+#define OMAP_RTC_ALARM2_SECONDS_REG	0x80
+#define OMAP_RTC_ALARM2_MINUTES_REG	0x84
+#define OMAP_RTC_ALARM2_HOURS_REG	0x88
+#define OMAP_RTC_ALARM2_DAYS_REG	0x8c
+#define OMAP_RTC_ALARM2_MONTHS_REG	0x90
+#define OMAP_RTC_ALARM2_YEARS_REG	0x94
+#define OMAP_RTC_PMIC_REG		0x98
+
 /* OMAP_RTC_CTRL_REG bit fields: */
 #define OMAP_RTC_CTRL_SPLIT		(1<<7)
 #define OMAP_RTC_CTRL_DISABLE		(1<<6)
@@ -93,15 +101,24 @@
 #define OMAP_RTC_STATUS_BUSY            (1<<0)
 
 /* OMAP_RTC_INTERRUPTS_REG bit fields: */
+#define OMAP_RTC_INTERRUPTS_IT_ALARM2   (1<<4)
 #define OMAP_RTC_INTERRUPTS_IT_ALARM    (1<<3)
 #define OMAP_RTC_INTERRUPTS_IT_TIMER    (1<<2)
 
+/* OMAP_RTC_PMIC_REG bit fields: */
+#define OMAP_RTC_PMIC_POWER_EN_EN       (1<<16)
+
 /* OMAP_RTC_KICKER values */
 #define	KICK0_VALUE			0x83e70b13
 #define	KICK1_VALUE			0x95a4f1e0
 
 #define	OMAP_RTC_HAS_KICKER		0x1
 
+#define SHUTDOWN_TIME_SEC		2
+#define SECS_IN_MIN			60
+#define WAIT_AFTER			(SECS_IN_MIN - SHUTDOWN_TIME_SEC)
+#define WAIT_TIME_MS			(SHUTDOWN_TIME_SEC * 1000)
+
 static void __iomem	*rtc_base;
 
 #define rtc_read(addr)		readb(rtc_base + (addr))
@@ -290,6 +307,58 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 	return 0;
 }
 
+/*
+ * rtc_power_off: Set the pmic power off sequence. The RTC generates
+ * pmic_pwr_enable control, which can be used to control an external
+ * PMIC.
+ */
+static void rtc_power_off(void)
+{
+	u32 val;
+	struct rtc_time tm;
+	spinlock_t lock;
+	unsigned long flags;
+
+	spin_lock_init(&lock);
+
+	/* Set PMIC power enable */
+	val = readl(rtc_base + OMAP_RTC_PMIC_REG);
+	writel(val | OMAP_RTC_PMIC_POWER_EN_EN, rtc_base + OMAP_RTC_PMIC_REG);
+
+	/* Wait few seconds instead of rollover */
+	do {
+		omap_rtc_read_time(NULL, &tm);
+		if (WAIT_AFTER <= tm.tm_sec)
+			mdelay(WAIT_TIME_MS);
+	} while (WAIT_AFTER <= tm.tm_sec);
+
+	/* Add shutdown time to the current value */
+	tm.tm_sec += SHUTDOWN_TIME_SEC;
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/* Set the ALARM2 time */
+	rtc_write(tm.tm_sec, OMAP_RTC_ALARM2_SECONDS_REG);
+	rtc_write(tm.tm_min, OMAP_RTC_ALARM2_MINUTES_REG);
+	rtc_write(tm.tm_hour, OMAP_RTC_ALARM2_HOURS_REG);
+	rtc_write(tm.tm_mday, OMAP_RTC_ALARM2_DAYS_REG);
+	rtc_write(tm.tm_mon, OMAP_RTC_ALARM2_MONTHS_REG);
+	rtc_write(tm.tm_year, OMAP_RTC_ALARM2_YEARS_REG);
+
+	/* Enable alarm2 interrupt */
+	val = readl(rtc_base + OMAP_RTC_INTERRUPTS_REG);
+	writel(val | OMAP_RTC_INTERRUPTS_IT_ALARM2,
+				rtc_base + OMAP_RTC_INTERRUPTS_REG);
+
+	/* Do not allow to execute any other task */
+	spin_lock_irqsave(&lock, flags);
+	while (1);
+}
+
 static struct rtc_class_ops omap_rtc_ops = {
 	.read_time	= omap_rtc_read_time,
 	.set_time	= omap_rtc_set_time,
@@ -327,12 +396,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
 	struct resource		*res, *mem;
 	struct rtc_device	*rtc;
 	u8			reg, new_ctrl;
+	bool			pm_off = false;
 	const struct platform_device_id *id_entry;
 	const struct of_device_id *of_id;
 
 	of_id = of_match_device(omap_rtc_of_match, &pdev->dev);
-	if (of_id)
+	if (of_id) {
 		pdev->id_entry = of_id->data;
+		pm_off = of_property_read_bool(pdev->dev.of_node,
+					"ti,system-power-controller");
+	}
 
 	omap_rtc_timer = platform_get_irq(pdev, 0);
 	if (omap_rtc_timer <= 0) {
@@ -385,6 +458,10 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, rtc);
 	dev_set_drvdata(&rtc->dev, mem);
 
+	/* RTC power off */
+	if (pm_off && !pm_power_off)
+		pm_power_off = rtc_power_off;
+
 	/* clear pending irqs, and set 1/second periodic,
 	 * which we'll use instead of update irqs
 	 */
#17 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

Hi Anil,

Quoted 54 lines · Chimata
Quoted 35 lines · Benoit

Hi Anil / Colin,

Quoted 32 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +0 -0
index b47aa41..8d9f4f9 100644
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
Quoted 6 lines

Documentation/devicetree/bindings/rtc/rtc-omap.txt Required properties: · line 11

Quoted 3 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +3 -0
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.

Hi Benoit,
________________________________

|   ______          _______      |
|  |      |        |       |     |
|  |RTC   |        |       |     |
|  |PMIC  |  Line  |       |     |
|  |PWR_EN|=======>|PWR_EN |     |
|  |______|        |_______|     |
|  AM335x SoC       TPS65217     |
|                                |
|________________________________|
Quoted 8 lines

BeagleBone

This is how RTC PMIC_PWR_EN is connected to PWR_EN of TPS65217 PMIC. Only when RTC pull low in PMIC_PWR_EN then PMIC will go to power off state provided TPS65217 status should be changed to STATUS_OFF.

ALARM2 event should be trigger to configure PMIC_PWR_EN properly then the "Line" driven low so that PMIC will go to shutdown mode.

Thanks for the nice diagram :-)

I'm wondering if we cannot abuse the gpio binding to describe that connection instead of creating two custom attributes (PMIC + RTC).

Ideally we should do that without having to change the RTC to use the gpiolib at all.

rtc: rtc at 44e3e000 {
	compatible = "ti,da830-rtc";
	reg = <0x44e3e000 0x1000>;
	interrupts = <75, 76>;
	ti,hwmods = "rtc";

	/* expose the PWR_EN functionality of this RTC*/
	gpio-controller;
	#gpio-cells = <0>; /* assuming we can use 0 ??? */
};

...

tps: tps at 24 {

 	compatible = "ti,tps65217";
	/*
         * Enable the power enable feature from
         * the input line if that attribute is there.
         */
	gpio-power-en = <&rtc>; /* PWR_EN */

	...
}	

Any thought?

Regards,
Benoit

#18 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

Quoted 59 lines · Benoit

Hi Anil,

Quoted 56 lines · Chimata
Quoted 35 lines · Benoit

Hi Anil / Colin,

Quoted 32 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +0 -0
index b47aa41..8d9f4f9 100644
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
Quoted 6 lines

Documentation/devicetree/bindings/rtc/rtc-omap.txt Required properties: · line 11

Quoted 3 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +3 -0
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.

Hi Benoit,
________________________________

|   ______          _______      |
|  |      |        |       |     |
|  |RTC   |        |       |     |
|  |PMIC  |  Line  |       |     |
|  |PWR_EN|=======>|PWR_EN |     |
|  |______|        |_______|     |
|  AM335x SoC       TPS65217     |
|                                |
|________________________________|

BeagleBone

Quoted 8 lines
Quoted 6 lines

This is how RTC PMIC_PWR_EN is connected to PWR_EN of TPS65217 PMIC. Only when RTC pull low in PMIC_PWR_EN then PMIC will go to power off state provided TPS65217 status should be changed to STATUS_OFF.

ALARM2 event should be trigger to configure PMIC_PWR_EN properly then the "Line" driven low so that PMIC will go to shutdown mode.

Thanks for the nice diagram :-)

I missed this mail thread so delayed in response

Quoted 32 lines

I'm wondering if we cannot abuse the gpio binding to describe that connection instead of creating two custom attributes (PMIC + RTC).

Ideally we should do that without having to change the RTC to use the gpiolib at all.

rtc: rtc at 44e3e000 {
	compatible = "ti,da830-rtc";
	reg = <0x44e3e000 0x1000>;
	interrupts = <75, 76>;
	ti,hwmods = "rtc";

	/* expose the PWR_EN functionality of this RTC*/
	gpio-controller;
	#gpio-cells = <0>; /* assuming we can use 0 ??? */
};

...

tps: tps at 24 {

 	compatible = "ti,tps65217";
	/*
         * Enable the power enable feature from
         * the input line if that attribute is there.
         */
	gpio-power-en = <&rtc>; /* PWR_EN */

	...
}	
Quoted 1 line

Any thought?

No, these two are independent controllers. PMIC can go to power off mode if we pull PWR_EN to low. We can pull down that line by any means like PRCM or GPIO or some other. So these two flags should be independent from each other.

Thanks
AnilKumar

#19 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to Benoit Cousson

+Mark

Quoted 113 lines · Chimata
Quoted 59 lines · Benoit

Hi Anil,

Quoted 56 lines · Chimata
Quoted 35 lines · Benoit

Hi Anil / Colin,

Quoted 32 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +0 -0
index b47aa41..8d9f4f9 100644
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
Quoted 6 lines

Documentation/devicetree/bindings/rtc/rtc-omap.txt Required properties: · line 11

Quoted 3 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +3 -0
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.

Hi Benoit,
________________________________

|   ______          _______      |
|  |      |        |       |     |
|  |RTC   |        |       |     |
|  |PMIC  |  Line  |       |     |
|  |PWR_EN|=======>|PWR_EN |     |
|  |______|        |_______|     |
|  AM335x SoC       TPS65217     |
|                                |
|________________________________|

BeagleBone

Quoted 8 lines
Quoted 6 lines

This is how RTC PMIC_PWR_EN is connected to PWR_EN of TPS65217 PMIC. Only when RTC pull low in PMIC_PWR_EN then PMIC will go to power off state provided TPS65217 status should be changed to STATUS_OFF.

ALARM2 event should be trigger to configure PMIC_PWR_EN properly then the "Line" driven low so that PMIC will go to shutdown mode.

Thanks for the nice diagram :-)

I missed this mail thread so delayed in response

Quoted 32 lines

I'm wondering if we cannot abuse the gpio binding to describe that connection instead of creating two custom attributes (PMIC + RTC).

Ideally we should do that without having to change the RTC to use the gpiolib at all.

rtc: rtc at 44e3e000 {
	compatible = "ti,da830-rtc";
	reg = <0x44e3e000 0x1000>;
	interrupts = <75, 76>;
	ti,hwmods = "rtc";

	/* expose the PWR_EN functionality of this RTC*/
	gpio-controller;
	#gpio-cells = <0>; /* assuming we can use 0 ??? */
};

...

tps: tps at 24 {

 	compatible = "ti,tps65217";
	/*
         * Enable the power enable feature from
         * the input line if that attribute is there.
         */
	gpio-power-en = <&rtc>; /* PWR_EN */

	...
}	
Quoted 1 line

Any thought?

No, these two are independent controllers. PMIC can go to power off mode if we pull PWR_EN to low. We can pull down that line by any means like PRCM or GPIO or some other. So these two flags should be independent from each other.

Thanks
AnilKumar

#21 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to Benoit Cousson
Quoted 69 lines · Chimata

+Mark

Quoted 66 lines · Chimata
Quoted 65 lines · Benoit

Hi Anil,

Quoted 62 lines · Chimata
Quoted 35 lines · Benoit

Hi Anil / Colin,

Quoted 32 lines · AnilKumar Ch

From: Colin Foe-Parker <[email protected]>

Add system power off control to rtc driver which is the in-charge of controlling the BeagleBone system power. The power_off routine can be hooked up to "pm_power_off" system call.

System power off sequence:-
* Set PMIC STATUS_OFF when PMIC_POWER_EN is pulled low
* Enable PMIC_POWER_EN in rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt

Added while (1); after the above steps to make sure that no other process acquire cpu. Otherwise we might see an unexpected behaviour because we are shutting down all the power rails of SoC except RTC.

[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   79 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +0 -0
index b47aa41..8d9f4f9 100644
@@ -6,6 +6,10 @@ Required properties:
 - interrupts: rtc timer, alarm interrupts in order
 - interrupt-parent: phandle for the interrupt controller
 
Quoted 6 lines

Documentation/devicetree/bindings/rtc/rtc-omap.txt Required properties: · line 11

Quoted 3 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +3 -0
+Optional properties:
+- ti,system-power-controller: Telling whether or not rtc is controlling
+  the system power.

I don't know how it is connected at board level, but I'm not sure the binding is the proper one.

Hi Benoit,
________________________________

|   ______          _______      |
|  |      |        |       |     |
|  |RTC   |        |       |     |
|  |PMIC  |  Line  |       |     |
|  |PWR_EN|=======>|PWR_EN |     |
|  |______|        |_______|     |
|  AM335x SoC       TPS65217     |
|                                |
|________________________________|

BeagleBone

This is how RTC PMIC_PWR_EN is connected to PWR_EN of TPS65217 PMIC. Only when RTC pull low in PMIC_PWR_EN then PMIC will go to power off state provided TPS65217 status should be changed to STATUS_OFF.

ALARM2 event should be trigger to configure PMIC_PWR_EN properly then the "Line" driven low so that PMIC will go to shutdown mode.

Mark,

Details regarding how PMIC PWR_EN is connected to RTC module

Thanks
AnilKumar

Quoted 49 lines
Quoted 47 lines
Quoted 2 lines

Thanks for the nice diagram :-)

I missed this mail thread so delayed in response

Quoted 32 lines

I'm wondering if we cannot abuse the gpio binding to describe that connection instead of creating two custom attributes (PMIC + RTC).

Ideally we should do that without having to change the RTC to use the gpiolib at all.

rtc: rtc at 44e3e000 {
	compatible = "ti,da830-rtc";
	reg = <0x44e3e000 0x1000>;
	interrupts = <75, 76>;
	ti,hwmods = "rtc";

	/* expose the PWR_EN functionality of this RTC*/
	gpio-controller;
	#gpio-cells = <0>; /* assuming we can use 0 ??? */
};

...

tps: tps at 24 {

 	compatible = "ti,tps65217";
	/*
         * Enable the power enable feature from
         * the input line if that attribute is there.
         */
	gpio-power-en = <&rtc>; /* PWR_EN */

	...
}	
Quoted 1 line

Any thought?

No, these two are independent controllers. PMIC can go to power off mode if we pull PWR_EN to low. We can pull down that line by any means like PRCM or GPIO or some other. So these two flags should be independent from each other.

Thanks
AnilKumar

#22 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

Quoted 1 line · Chimata

On Wed, Nov 14, 2012 at 10:31:42, AnilKumar, Chimata wrote:

*Please* cut out irrelevant context from your mails.

Quoted 1 line

Details regarding how PMIC PWR_EN is connected to RTC module

OK... but what am I expected to do with this information?
-------------- 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/20121114/8a755791/attachment.sig>

#23 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to AnilKumar Ch

On Mon, Nov 05, 2012 at 15:12:27, AnilKumar, Chimata wrote:
[...]

Quoted 8 lines
drivers/rtc/rtc-omap.c +5 -0
+#define SHUTDOWN_TIME_SEC		2
+#define SECS_IN_MIN			60
+#define WAIT_AFTER			(SECS_IN_MIN - SHUTDOWN_TIME_SEC)
+#define WAIT_TIME_MS			(SHUTDOWN_TIME_SEC * 1000)
+
 static void __iomem	*rtc_base;

[...]

drivers/rtc/rtc-omap.c static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · line 333

Quoted 7 lines
drivers/rtc/rtc-omap.c +7 -0
+
+	/* Wait few seconds instead of rollover */
+	do {
+		omap_rtc_read_time(NULL, &tm);
+		if (WAIT_AFTER <= tm.tm_sec)
+			mdelay(WAIT_TIME_MS);
+	} while (WAIT_AFTER <= tm.tm_sec);

This hardcoded wait for rollover doesn't look good. I see some helper functions in rtc-lib.c which probably could be used for converting the current time to elapsed seconds, add the delay and then convert it back to the time to be programmed in RTC without worrying about rollover. Why not use that?

Quoted 13 lines
drivers/rtc/rtc-omap.c +13 -0
+
+	/* Add shutdown time to the current value */
+	tm.tm_sec += SHUTDOWN_TIME_SEC;
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/* Set the ALARM2 time */
+	rtc_write(tm.tm_sec, OMAP_RTC_ALARM2_SECONDS_REG);
+	rtc_write(tm.tm_min, OMAP_RTC_ALARM2_MINUTES_REG);

drivers/rtc/rtc-omap.c static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · line 356

Quoted 10 lines
drivers/rtc/rtc-omap.c +10 -0
+	rtc_write(tm.tm_hour, OMAP_RTC_ALARM2_HOURS_REG);
+	rtc_write(tm.tm_mday, OMAP_RTC_ALARM2_DAYS_REG);
+	rtc_write(tm.tm_mon, OMAP_RTC_ALARM2_MONTHS_REG);
+	rtc_write(tm.tm_year, OMAP_RTC_ALARM2_YEARS_REG);
+
+	/* Enable alarm2 interrupt */
+	val = readl(rtc_base + OMAP_RTC_INTERRUPTS_REG);
+	writel(val | OMAP_RTC_INTERRUPTS_IT_ALARM2,
+				rtc_base + OMAP_RTC_INTERRUPTS_REG);
+

These registers are not present in older versions of the IP so how does that get handled?

You also need to describe the connection between the ALARM2 and the power off logic in detail.

Regards,
Vaibhav

#24 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

Quoted 11 lines · Vaibhav

On Mon, Nov 05, 2012 at 15:12:27, AnilKumar, Chimata wrote:
[...]

Quoted 8 lines
drivers/rtc/rtc-omap.c +5 -0
+#define SHUTDOWN_TIME_SEC		2
+#define SECS_IN_MIN			60
+#define WAIT_AFTER			(SECS_IN_MIN - SHUTDOWN_TIME_SEC)
+#define WAIT_TIME_MS			(SHUTDOWN_TIME_SEC * 1000)
+
 static void __iomem	*rtc_base;

[...]

Quoted 13 lines

drivers/rtc/rtc-omap.c static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · line 333

Quoted 7 lines
drivers/rtc/rtc-omap.c +7 -0
+
+	/* Wait few seconds instead of rollover */
+	do {
+		omap_rtc_read_time(NULL, &tm);
+		if (WAIT_AFTER <= tm.tm_sec)
+			mdelay(WAIT_TIME_MS);
+	} while (WAIT_AFTER <= tm.tm_sec);

This hardcoded wait for rollover doesn't look good. I see some helper functions in rtc-lib.c which probably could be used for converting the current time to elapsed seconds, add the delay and then convert it back to the time to be programmed in RTC without worrying about rollover. Why not use that?

I am not aware of those APIs, can you point some?

Quoted 19 lines
Quoted 19 lines
drivers/rtc/rtc-omap.c +18 -0
+
+	/* Add shutdown time to the current value */
+	tm.tm_sec += SHUTDOWN_TIME_SEC;
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/* Set the ALARM2 time */
+	rtc_write(tm.tm_sec, OMAP_RTC_ALARM2_SECONDS_REG);
+	rtc_write(tm.tm_min, OMAP_RTC_ALARM2_MINUTES_REG);
+	rtc_write(tm.tm_hour, OMAP_RTC_ALARM2_HOURS_REG);
+	rtc_write(tm.tm_mday, OMAP_RTC_ALARM2_DAYS_REG);
+	rtc_write(tm.tm_mon, OMAP_RTC_ALARM2_MONTHS_REG);
+	rtc_write(tm.tm_year, OMAP_RTC_ALARM2_YEARS_REG);
+
Quoted 8 lines

drivers/rtc/rtc-omap.c static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · line 356

Quoted 5 lines
drivers/rtc/rtc-omap.c +5 -0
+	/* Enable alarm2 interrupt */
+	val = readl(rtc_base + OMAP_RTC_INTERRUPTS_REG);
+	writel(val | OMAP_RTC_INTERRUPTS_IT_ALARM2,
+				rtc_base + OMAP_RTC_INTERRUPTS_REG);
+

These registers are not present in older versions of the IP so how does that get handled?

I think, earlier this feature is not supported/not used.

Quoted 3 lines

You also need to describe the connection between the ALARM2 and the power off logic in detail.

Sure, I will add.

Thanks
AnilKumar

#25 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to Bedia, Vaibhav
Quoted 26 lines · Chimata
Quoted 11 lines · Vaibhav

On Mon, Nov 05, 2012 at 15:12:27, AnilKumar, Chimata wrote:
[...]

Quoted 8 lines
drivers/rtc/rtc-omap.c +5 -0
+#define SHUTDOWN_TIME_SEC		2
+#define SECS_IN_MIN			60
+#define WAIT_AFTER			(SECS_IN_MIN - SHUTDOWN_TIME_SEC)
+#define WAIT_TIME_MS			(SHUTDOWN_TIME_SEC * 1000)
+
 static void __iomem	*rtc_base;

[...]

Quoted 13 lines

drivers/rtc/rtc-omap.c static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · line 333

Quoted 7 lines
drivers/rtc/rtc-omap.c +7 -0
+
+	/* Wait few seconds instead of rollover */
+	do {
+		omap_rtc_read_time(NULL, &tm);
+		if (WAIT_AFTER <= tm.tm_sec)
+			mdelay(WAIT_TIME_MS);
+	} while (WAIT_AFTER <= tm.tm_sec);

This hardcoded wait for rollover doesn't look good. I see some helper functions in rtc-lib.c which probably could be used for converting the current time to elapsed seconds, add the delay and then convert it back to the time to be programmed in RTC without worrying about rollover. Why not use that?

Quoted 1 line

I am not aware of those APIs, can you point some?

I have gone through rtc-lib.c, these are the API's I am seeing in the library

1. rtc_time_to_tm: Convert seconds since 01-01-1970 00:00:00 to Gregorian date
2. rtc_tm_to_time: Convert Gregorian date to seconds since 01-01-1970 00:00:00

Steps I followed:-
================
1: unsigned long time;
2: omap_rtc_read_time(NULL, &tm);
3: rtc_tm_to_time(tm, &time);
4: pr_info("Time 1 %lu\n", time);
5: time += 2; /* (2sec) */
6: rtc_time_to_tm(time, tm);
7: rtc_tm_to_time(tm, &time); /* Only for printing time value */ 8: pr_info("Time 2 %lu\n", time);

With the above steps I am seeing completely two different time values at step4 and step8

Thanks
AnilKumar

#26 lore raw

PATCH 2/4 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to Bedia, Vaibhav
Quoted 48 lines · Chimata
Quoted 26 lines · Chimata
Quoted 11 lines · Vaibhav

On Mon, Nov 05, 2012 at 15:12:27, AnilKumar, Chimata wrote:
[...]

Quoted 8 lines
drivers/rtc/rtc-omap.c +5 -0
+#define SHUTDOWN_TIME_SEC		2
+#define SECS_IN_MIN			60
+#define WAIT_AFTER			(SECS_IN_MIN - SHUTDOWN_TIME_SEC)
+#define WAIT_TIME_MS			(SHUTDOWN_TIME_SEC * 1000)
+
 static void __iomem	*rtc_base;

[...]

Quoted 13 lines

drivers/rtc/rtc-omap.c static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) · line 333

Quoted 7 lines
drivers/rtc/rtc-omap.c +7 -0
+
+	/* Wait few seconds instead of rollover */
+	do {
+		omap_rtc_read_time(NULL, &tm);
+		if (WAIT_AFTER <= tm.tm_sec)
+			mdelay(WAIT_TIME_MS);
+	} while (WAIT_AFTER <= tm.tm_sec);

This hardcoded wait for rollover doesn't look good. I see some helper functions in rtc-lib.c which probably could be used for converting the current time to elapsed seconds, add the delay and then convert it back to the time to be programmed in RTC without worrying about rollover. Why not use that?

Quoted 1 line

I am not aware of those APIs, can you point some?

I have gone through rtc-lib.c, these are the API's I am seeing in the library

1. rtc_time_to_tm: Convert seconds since 01-01-1970 00:00:00 to Gregorian date
2. rtc_tm_to_time: Convert Gregorian date to seconds since 01-01-1970 00:00:00

Steps I followed:-
================
1: unsigned long time;
2: omap_rtc_read_time(NULL, &tm);
3: rtc_tm_to_time(tm, &time);
4: pr_info("Time 1 %lu\n", time);
5: time += 2; /* (2sec) */
6: rtc_time_to_tm(time, tm);
7: rtc_tm_to_time(tm, &time); /* Only for printing time value */ 8: pr_info("Time 2 %lu\n", time);

Quoted 3 lines

With the above steps I am seeing completely two different time values at step4 and step8

Nevermind it working now.

Thanks
AnilKumar

#27 lore raw

PATCH 3/4 ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone

In reply to AnilKumar Ch

Set ti,pmic-shutdown-controller for BeagleBone in am335x-bone.dts file, this flag is used by the driver to set tps65217 PMIC status to OFF when PWR_EN toggle.

---
 arch/arm/boot/dts/am335x-bone.dts |    2 ++
 1 file changed, 2 insertions(+)
arch/arm/boot/dts/am335x-bone.dts +2 -0
index 91eee97..40ea3c7 100644
@@ -44,6 +44,8 @@
 /include/ "tps65217.dtsi"
 
 &tps {
+	ti,pmic-shutdown-controller;
+
 	regulators {
 		dcdc1_reg: regulator at 0 {
 			regulator-always-on;
Signature · 1 line
1.7.9.5
#28 lore raw

PATCH 4/4 ARM: dts: AM33XX: Enable system power off control in am335x-bone

In reply to AnilKumar Ch

Enable system power off control for BeagleBone in am335x-bone.dts file under rtc node. RTC is the incharge of controlling the system power. This flag is used by the driver to hook up the pm_power_off system call.

---
 arch/arm/boot/dts/am335x-bone.dts |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/boot/dts/am335x-bone.dts +4 -0
index 40ea3c7..6f9c48e 100644
@@ -38,6 +38,10 @@
 			};
 
 		};
+
+		rtc at 44e3e000 {
+			ti,system-power-controller;
+		};
 	};
 };
 
Signature · 1 line
1.7.9.5