Skip to contentSkip to conversation

pm: Add power off control

PATCH Superseded AnilKumar Ch 7 participants 17 messages Nov 20, 2012 – Dec 11, 2012

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover pm: Add power off control

Add PM power_off control to rtc driver and 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 (BeagleBone). First patch is based on linux-next, second patch is based on mfd/master and rest of the patches are based on linux-omap master.

Changes from v2:
- Incorporated Kevin's comment on v2
* Enabled RTC in ompa2plus_defconfig

Changes from v1:
- Incorporated Vaibhav's comments on v1
* Changed the time rollover logic with the help of rtc-lib APIs

AnilKumar Ch (3):
ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone
ARM: dts: AM33XX: Enable system power off control in am335x-bone
ARM: OMAP2+: omap2plus_defconfig: Enable RTC support

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

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

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

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                             |   81 +++++++++++++++++++-
 2 files changed, 85 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 +80 -1

125 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

+Andrew Morton

Quoted 12 lines · Chimata

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

Quoted 3 lines

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.

Hi All,

ACK from reviewers will help this patch get in.

Andrew,

Could you please pull this patch?

Thanks
AnilKumar

Quoted 167 lines
[anilkumar at ti.com: move poweroff additions to rtc driver]
---
 Documentation/devicetree/bindings/rtc/rtc-omap.txt |    5 ++
 drivers/rtc/rtc-omap.c                             |   81 +++++++++++++++++++-
 2 files changed, 85 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 +80 -1
index 6009714..c31f93a 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,21 @@
 #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
+
 static void __iomem	*rtc_base;
 
 #define rtc_read(addr)		readb(rtc_base + (addr))
@@ -290,6 +304,63 @@ 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, time;
+
+	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);
+
+	/* Read rtc time */
+	omap_rtc_read_time(NULL, &tm);
+
+	/* Convert Gregorian date to seconds since 01-01-1970 00:00:00 */
+	rtc_tm_to_time(&tm, &time);
+
+	/* Add shutdown time to the current value */
+	time += SHUTDOWN_TIME_SEC;
+
+	/* Convert seconds since 01-01-1970 00:00:00 to Gregorian date */
+	rtc_time_to_tm(time, &tm);
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/*
+	 * pmic_pwr_enable is controlled by means of ALARM2 event. So here
+	 * programming alarm2 expiry time and enabling alarm2 interrupt
+	 */
+	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 +398,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 +460,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
 	 */
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

Quoted 19 lines · Chimata

+Andrew Morton

Quoted 15 lines · Chimata

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.

#4 lore raw

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to AnilKumar Ch
Quoted 22 lines · On Tue, 20 Nov 2012 15:18:43 +0530 AnilKumar Ch <[email protected]> wrote:

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]

...

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

Quoted 10 lines
drivers/rtc/rtc-omap.c +10 -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;

What on earth?

Quoted 35 lines
drivers/rtc/rtc-omap.c +35 -0
+	unsigned long flags, time;
+
+	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);
+
+	/* Read rtc time */
+	omap_rtc_read_time(NULL, &tm);
+
+	/* Convert Gregorian date to seconds since 01-01-1970 00:00:00 */
+	rtc_tm_to_time(&tm, &time);
+
+	/* Add shutdown time to the current value */
+	time += SHUTDOWN_TIME_SEC;
+
+	/* Convert seconds since 01-01-1970 00:00:00 to Gregorian date */
+	rtc_time_to_tm(time, &tm);
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/*
+	 * pmic_pwr_enable is controlled by means of ALARM2 event. So here
+	 * programming alarm2 expiry time and enabling alarm2 interrupt
+	 */
+	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);

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

Quoted 10 lines
drivers/rtc/rtc-omap.c +10 -0
+	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);

I suspect this doesn't do what you want it to do.

Firstly, please provide adequate code comments here so that code readers do not also need to be mind readers.

If you want to stop this CPU dead in its tracks (why?) then

	local_irq_disable();
	while (1)
		;		/* Note correct code layout */

will do it. But it means that the NMI watchdog (if present) will come along and whack the machine in the head a few seconds later. And this does nothing to stop other CPUs.

But not being a mind reader, I'm really at a loss to suggest what should be done here.

Quoted 4 lines

+}

...

#5 lore raw

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

Quoted 15 lines · Andrew Morton

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

Quoted 3 lines
drivers/rtc/rtc-omap.c +3 -0
+	/* Do not allow to execute any other task */
+	spin_lock_irqsave(&lock, flags);
+	while (1);

I suspect this doesn't do what you want it to do.

Firstly, please provide adequate code comments here so that code readers do not also need to be mind readers.

If you want to stop this CPU dead in its tracks (why?) then

	local_irq_disable();
	while (1)
		;		/* Note correct code layout */
Quoted 6 lines

will do it. But it means that the NMI watchdog (if present) will come along and whack the machine in the head a few seconds later. And this does nothing to stop other CPUs.

But not being a mind reader, I'm really at a loss to suggest what should be done here.

It's hooking into the pm_power_off hook, which is called from kernel/sys.c via arch code. We will have already stopped all other CPUs at this point.

Why there's that while (1) there I don't know; when pm_power_off is not hooked, we don't do anything like that - and what will happen in that case is we'll return all the way back to sys_reboot(), which will call do_exit(0) on us.

I don't see a problem with that, and I don't see why we need to spin (without any power saving too) waiting for some event. If we've called sys_reboot with LINUX_REBOOT_CMD_POWER_OFF, we'd better have already killed most of userspace off by that time anyway.

#6 lore raw

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

Quoted 16 lines · Russell King - ARM Linux
Quoted 15 lines · Andrew Morton

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

Quoted 3 lines
drivers/rtc/rtc-omap.c +3 -0
+	/* Do not allow to execute any other task */
+	spin_lock_irqsave(&lock, flags);
+	while (1);

I suspect this doesn't do what you want it to do.

Firstly, please provide adequate code comments here so that code readers do not also need to be mind readers.

If you want to stop this CPU dead in its tracks (why?) then

	local_irq_disable();
	while (1)
		;		/* Note correct code layout */
Quoted 6 lines
Quoted 6 lines

will do it. But it means that the NMI watchdog (if present) will come along and whack the machine in the head a few seconds later. And this does nothing to stop other CPUs.

But not being a mind reader, I'm really at a loss to suggest what should be done here.

Here intention is to disable all interrupts between rtc power_off request till system actually went to power off mode, max 2 seconds based on when the AM335x RTC alarm2 expires. The idea was that since the system is going to shutdown, it is better to not process any more interrupts.

Quoted 7 lines

It's hooking into the pm_power_off hook, which is called from kernel/sys.c via arch code. We will have already stopped all other CPUs at this point.

Why there's that while (1) there I don't know; when pm_power_off is not hooked, we don't do anything like that - and what will happen in that case is we'll return all the way back to sys_reboot(), which will call do_exit(0) on us.

When testing with v3.7-rc7, I saw the following BUG() triggered when I did not use a while(1). Logs below.

Before calling do_exit(0), there is a reboot_mutex lock that is taken in
reboot syscall. do_exit() function is , checking for any locks held by the
processor and if yes then it is printing a BUG_ON from print_held_locks_bug() function along with the locks held information. Even though the BUG triggers, the system is going to power off because
The hardware has been triggered.

==== (log)
[root at arago /]# poweroff
The system is going down NOW!
Sent SIGTERM to all processes
Sent SIGKILL to all processes
Requesting system poweroff

[   32.125900] Disabling non-boot CPUs ...
[   32.130155] Power down.
[   32.132741] System will go to power_off state in approx. 2 secs
[   32.139994]
[   32.141575] =====================================
[   32.146564] [ BUG: lock held at task exit time! ]
[   32.151522] 3.7.0-rc7-00015-g3f8bbe0 #32 Not tainted
[   32.156721] -------------------------------------
[   32.161676] init/622 is exiting with locks still held!
[   32.167085] 1 lock held by init/622:
[   32.170831]  #0:  (reboot_mutex){+.+...}, at: [<c0056fb8>] sys_reboot+0xf4/0x1e8
[   32.178679]
[   32.178679] stack backtrace:
[   32.183305] [<c001af24>] (unwind_backtrace+0x0/0xf0) from [<c0046978>] (do_exit+0x488/0x7e8)
[   32.192183] [<c0046978>] (do_exit+0x488/0x7e8) from [<c0056fc4>] (sys_reboot+0x100/0x1e8)
[   32.200797] [<c0056fc4>] (sys_reboot+0x100/0x1e8) from [<c0013320>] (ret_fast_syscall+0x0/0x3c)

=====

It is not clear to me where reboot_mutex should have been unlocked before debug_check_no_locks_held() is called in do_exit()?

Note: In latest linux-next tip I am *not* seeing this error. I have not bisected yet to see what fixed this. Since with latest linux-next I am not seeing an issue, I will remove spinlock and the while(1). Hope that will make the patch more acceptable.

Quoted 5 lines

I don't see a problem with that, and I don't see why we need to spin (without any power saving too) waiting for some event. If we've called sys_reboot with LINUX_REBOOT_CMD_POWER_OFF, we'd better have already killed most of userspace off by that time anyway.

I did a search of various power-off implementations in *arch/arm*.

Those that use a while(1):
=========================
arch/arm/mach-at91/board-gsia18s.c arch/arm/mach-at91/setup.c doesn't arch/arm/mach-cns3xxx/cns3420vb.c arch/arm/mach-iop32x/glantank.c arch/arm/mach-iop32x/iq31244.c arch/arm/mach-iop32x/n2100.c local_irq_disable() and then a while(1) arch/arm/mach-kirkwood/board-lsxl.c

arch/arm/mach-highbank/highbank.c does while(1) cpu_do_idle()

Those that don't have a while(1):
================================
arch/arm/mach-imx/mach-mx31moboard.c
arch/arm/mach-iop32x/em7210.c

Doesn't have a while(1) but setting a gpio so presumably kills the system immediately:
===========
arch/arm/mach-ixp4xx/dsmg600-setup.c arch/arm/mach-ixp4xx/nas100d-setup.c
arch/arm/mach-ixp4xx/nslu2-setup.c
arch/arm/mach-kirkwood/board-dnskw.c arch/arm/mach-kirkwood/board-ib62x0.c arch/arm/mach-kirkwood/board-dnskw.c arch/arm/mach-kirkwood/board-ib62x0.c arch/arm/mach-kirkwood/d2net_v2-setup.c arch/arm/mach-kirkwood/netspace_v2-setup.c arch/arm/mach-kirkwood/netxbig_v2-setup.c arch/arm/mach-kirkwood/t5325-setup.c arch/arm/mach-orion5x/dns323-setup.c

arch/arm/mach-vexpress/v2m.c take a spinlock, not sure when it will shut down

arch/arm/mach-kirkwood/board-ts219.c sends a character to PIC and potentially returns... arch/arm/mach-kirkwood/ts219-setup.c

So it seems there is a plethora of variations of how this is implemented (probably driven also by hardware differences). Since what I mentioned above works for me (in linux-next), I will go ahead and submit at v4. Let me know if there are objections.

Thanks
AnilKumar

#7 lore raw

PATCH v3 1/5 rtc: OMAP: Add system pm_power_off to rtc driver

In reply to AnilKumar Ch
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                             |   81 +++++++++++++++++++-
 2 files changed, 85 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 12

Quoted 7 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +4 -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.
+
Quoted 146 lines
Documentation/devicetree/bindings/rtc/rtc-omap.txt +1 -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 +80 -1
index 6009714..c31f93a 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,21 @@
 #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
+
 static void __iomem	*rtc_base;
 
 #define rtc_read(addr)		readb(rtc_base + (addr))
@@ -290,6 +304,63 @@ 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, time;
+
+	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);
+
+	/* Read rtc time */
+	omap_rtc_read_time(NULL, &tm);
+
+	/* Convert Gregorian date to seconds since 01-01-1970 00:00:00 */
+	rtc_tm_to_time(&tm, &time);
+
+	/* Add shutdown time to the current value */
+	time += SHUTDOWN_TIME_SEC;
+
+	/* Convert seconds since 01-01-1970 00:00:00 to Gregorian date */
+	rtc_time_to_tm(time, &tm);
+
+	if (tm2bcd(&tm) < 0)
+		return;
+
+	pr_info("System will go to power_off state in approx. %d secs\n",
+			SHUTDOWN_TIME_SEC);
+
+	/*
+	 * pmic_pwr_enable is controlled by means of ALARM2 event. So here
+	 * programming alarm2 expiry time and enabling alarm2 interrupt
+	 */
+	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 +398,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 +460,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
 	 */
Signature · 1 line
1.7.9.5
Signature · 2 lines
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
#8 lore raw

PATCH v3 2/5 mfd: tps65217: Set PMIC to shutdown on PWR_EN toggle

In reply to AnilKumar Ch

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

Set tps65217 PMIC status to OFF if power enable toggle is supported. By setting this bit to 1 to enter PMIC to OFF state when PWR_EN pin is pulled low. Also adds a DT flag to specify that device pmic supports shutdown control or not.

[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
Applied
#9 lore raw

PATCH v3 2/5 mfd: tps65217: Set PMIC to shutdown on PWR_EN toggle

Hi Anilkumar,

Quoted 7 lines · AnilKumar Ch

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

Set tps65217 PMIC status to OFF if power enable toggle is supported. By setting this bit to 1 to enter PMIC to OFF state when PWR_EN pin is pulled low. Also adds a DT flag to specify that device pmic supports shutdown control or not.

Quoted 7 lines
[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(+)

Applied, thanks.
I suppose you're not expecting the whole patchset to go through one tree ?

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#10 lore raw

PATCH v3 2/5 mfd: tps65217: Set PMIC to shutdown on PWR_EN toggle

Quoted 17 lines · Samuel Ortiz

Hi Anilkumar,

Quoted 7 lines · AnilKumar Ch

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

Set tps65217 PMIC status to OFF if power enable toggle is supported. By setting this bit to 1 to enter PMIC to OFF state when PWR_EN pin is pulled low. Also adds a DT flag to specify that device pmic supports shutdown control or not.

Quoted 7 lines
[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(+)
Quoted 3 lines

Applied, thanks.
I suppose you're not expecting the whole patchset to go through one tree ?

Hi Samuel,

Thanks much. Yes, I will request the corresponding owners to pick rest of the patches.

Thanks
AnilKumar

#11 lore raw

PATCH v3 3/5 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 2c33888..1d55190 100644
@@ -88,6 +88,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
#12 lore raw

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

Quoted 3 lines · Chimata

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.

Hi Tony,

Could you please pull these 3 patches? (3/5, 4/5 and 5/5)

Thanks
AnilKumar

Quoted 22 lines
---
 arch/arm/boot/dts/am335x-bone.dts |    2 ++
 1 file changed, 2 insertions(+)
arch/arm/boot/dts/am335x-bone.dts +2 -0
index 2c33888..1d55190 100644
@@ -88,6 +88,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
#13 lore raw

PATCH v3 4/5 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 in-charge 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 1d55190..206c3eb 100644
@@ -52,6 +52,10 @@
 			};
 
 		};
+
+		rtc at 44e3e000 {
+			ti,system-power-controller;
+		};
 	};
 
 	leds {
Signature · 1 line
1.7.9.5
#14 lore raw

PATCH v3 5/5 ARM: OMAP2+: omap2plus_defconfig: Enable RTC support

In reply to AnilKumar Ch

AM33XX family of devices uses RTC module, one has to manually enable this support to use RTC features. So this patch enable RTC driver in omap2plus_defconfig.

---
 arch/arm/configs/omap2plus_defconfig |    1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
index a4b330e..8839ac9 100644
@@ -194,6 +194,7 @@ CONFIG_SDIO_UART=y
 CONFIG_MMC_OMAP=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_OMAP=y
 CONFIG_RTC_DRV_TWL92330=y
 CONFIG_RTC_DRV_TWL4030=y
 CONFIG_DMADEVICES=y
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH v3 5/5 ARM: OMAP2+: omap2plus_defconfig: Enable RTC support

Quoted 14 lines · AnilKumar Ch

AM33XX family of devices uses RTC module, one has to manually enable this support to use RTC features. So this patch enable RTC driver in omap2plus_defconfig.

---
 arch/arm/configs/omap2plus_defconfig |    1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +0 -0
index a4b330e..8839ac9 100644

arch/arm/configs/omap2plus_defconfig CONFIG_SDIO_UART=y · line 200

Quoted 7 lines
arch/arm/configs/omap2plus_defconfig +1 -0
@@ -194,6 +194,7 @@ CONFIG_SDIO_UART=y
 CONFIG_MMC_OMAP=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_OMAP=y
 CONFIG_RTC_DRV_TWL92330=y
 CONFIG_RTC_DRV_TWL4030=y
 CONFIG_DMADEVICES=y

Hello,

But this is not enough, we need to change drivers/rtc/Kconfig too. This change was offered in this thread

http://marc.info/?l=linux-arm-kernel&m=135057569913027&w=2

But, may be all this previous rtc-related changes accounted already in some development branch. I just doesn't see it in the current master. In this case, when could we get RTC support in the current kernel?

Regards,
Igor.

#16 lore raw

PATCH v3 5/5 ARM: OMAP2+: omap2plus_defconfig: Enable RTC support

Quoted 25 lines · Igor Mazanov
Quoted 14 lines · AnilKumar Ch

AM33XX family of devices uses RTC module, one has to manually enable this support to use RTC features. So this patch enable RTC driver in omap2plus_defconfig.

---
 arch/arm/configs/omap2plus_defconfig |    1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +0 -0
index a4b330e..8839ac9 100644

arch/arm/configs/omap2plus_defconfig CONFIG_SDIO_UART=y · line 200

Quoted 7 lines
arch/arm/configs/omap2plus_defconfig +1 -0
@@ -194,6 +194,7 @@ CONFIG_SDIO_UART=y
 CONFIG_MMC_OMAP=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_OMAP=y
 CONFIG_RTC_DRV_TWL92330=y
 CONFIG_RTC_DRV_TWL4030=y
 CONFIG_DMADEVICES=y

Hello,

Quoted 8 lines

But this is not enough, we need to change drivers/rtc/Kconfig too. This change was offered in this thread

http://marc.info/?l=linux-arm-kernel&m=135057569913027&w=2

But, may be all this previous rtc-related changes accounted already in some development branch. I just doesn't see it in the current master. In this case, when could we get RTC support in the current kernel?

The Kconfig modification already present in mainline (linux-next/master)

Thanks
AnilKumar