* [PATCH v4 0/4] pm: Add power off control
@ 2012-12-14 6:03 AnilKumar Ch
2012-12-14 6:03 ` [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver AnilKumar Ch
` (4 more replies)
0 siblings, 5 replies; 17+ messages in thread
From: AnilKumar Ch @ 2012-12-14 6:03 UTC (permalink / raw)
To: linux-arm-kernel
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). These patchs
are based on linux-next.
Changes from v3:
- TPS65217 mfd driver changes are accepted so dropped
from this series.
- With recent changes in the kernel, reboot_mutex held BUG()
is not seen so removed while(1); from rtc_power_off.
- Removed spinlock before while(1); which is not necessary.
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 (1):
rtc: OMAP: Add system pm_power_off to rtc driver
Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
arch/arm/boot/dts/am335x-bone.dts | 6 ++
arch/arm/configs/omap2plus_defconfig | 1 +
drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
4 files changed, 85 insertions(+), 1 deletion(-)
--
1.7.9.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver
2012-12-14 6:03 [PATCH v4 0/4] pm: Add power off control AnilKumar Ch
@ 2012-12-14 6:03 ` AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2012-12-14 6:03 ` [PATCH v4 2/4] ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone AnilKumar Ch
` (3 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: AnilKumar Ch @ 2012-12-14 6:03 UTC (permalink / raw)
To: linux-arm-kernel
From: Colin Foe-Parker <colin.foeparker@logicpd.com>
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
Signed-off-by: Colin Foe-Parker <colin.foeparker@logicpd.com>
[anilkumar at ti.com: move poweroff additions to rtc driver]
Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
---
Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
2 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt 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
@@ -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;
};
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 6009714..e6d4878 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -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,56 @@ 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;
+ unsigned long time;
+
+ /* 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);
+}
+
static struct rtc_class_ops omap_rtc_ops = {
.read_time = omap_rtc_read_time,
.set_time = omap_rtc_set_time,
@@ -327,12 +391,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 +453,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
*/
--
1.7.9.5
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 2/4] ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone
2012-12-14 6:03 [PATCH v4 0/4] pm: Add power off control AnilKumar Ch
2012-12-14 6:03 ` [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver AnilKumar Ch
@ 2012-12-14 6:03 ` AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2012-12-14 6:03 ` [PATCH v4 3/4] ARM: dts: AM33XX: Enable system power off control in am335x-bone AnilKumar Ch
` (2 subsequent siblings)
4 siblings, 1 reply; 17+ messages in thread
From: AnilKumar Ch @ 2012-12-14 6:03 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
---
arch/arm/boot/dts/am335x-bone.dts | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm/boot/dts/am335x-bone.dts b/arch/arm/boot/dts/am335x-bone.dts
index 5302f79..e7dff9d 100644
--- a/arch/arm/boot/dts/am335x-bone.dts
+++ b/arch/arm/boot/dts/am335x-bone.dts
@@ -88,6 +88,8 @@
/include/ "tps65217.dtsi"
&tps {
+ ti,pmic-shutdown-controller;
+
regulators {
dcdc1_reg: regulator at 0 {
regulator-always-on;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 3/4] ARM: dts: AM33XX: Enable system power off control in am335x-bone
2012-12-14 6:03 [PATCH v4 0/4] pm: Add power off control AnilKumar Ch
2012-12-14 6:03 ` [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver AnilKumar Ch
2012-12-14 6:03 ` [PATCH v4 2/4] ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone AnilKumar Ch
@ 2012-12-14 6:03 ` AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2012-12-14 6:03 ` [PATCH v4 4/4] ARM: OMAP2+: omap2plus_defconfig: Enable RTC support AnilKumar Ch
2013-01-02 10:15 ` [PATCH v4 0/4] pm: Add power off control AnilKumar, Chimata
4 siblings, 1 reply; 17+ messages in thread
From: AnilKumar Ch @ 2012-12-14 6:03 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
---
arch/arm/boot/dts/am335x-bone.dts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/boot/dts/am335x-bone.dts b/arch/arm/boot/dts/am335x-bone.dts
index e7dff9d..febbe2f 100644
--- a/arch/arm/boot/dts/am335x-bone.dts
+++ b/arch/arm/boot/dts/am335x-bone.dts
@@ -52,6 +52,10 @@
};
};
+
+ rtc at 44e3e000 {
+ ti,system-power-controller;
+ };
};
leds {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 4/4] ARM: OMAP2+: omap2plus_defconfig: Enable RTC support
2012-12-14 6:03 [PATCH v4 0/4] pm: Add power off control AnilKumar Ch
` (2 preceding siblings ...)
2012-12-14 6:03 ` [PATCH v4 3/4] ARM: dts: AM33XX: Enable system power off control in am335x-bone AnilKumar Ch
@ 2012-12-14 6:03 ` AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2013-01-02 10:15 ` [PATCH v4 0/4] pm: Add power off control AnilKumar, Chimata
4 siblings, 1 reply; 17+ messages in thread
From: AnilKumar Ch @ 2012-12-14 6:03 UTC (permalink / raw)
To: linux-arm-kernel
AM33XX family of devices use RTC module, one has to manually enable
this support to use RTC features. So this patch enable RTC driver in
omap2plus_defconfig.
Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
---
arch/arm/configs/omap2plus_defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 0ce6771..e58afc5 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -216,6 +216,7 @@ CONFIG_LEDS_TRIGGER_CPU=y
CONFIG_LEDS_TRIGGER_GPIO=y
CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
CONFIG_RTC_CLASS=y
+CONFIG_RTC_DRV_OMAP=y
CONFIG_RTC_DRV_TWL92330=y
CONFIG_RTC_DRV_TWL4030=y
CONFIG_DMADEVICES=y
--
1.7.9.5
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 0/4] pm: Add power off control
2012-12-14 6:03 [PATCH v4 0/4] pm: Add power off control AnilKumar Ch
` (3 preceding siblings ...)
2012-12-14 6:03 ` [PATCH v4 4/4] ARM: OMAP2+: omap2plus_defconfig: Enable RTC support AnilKumar Ch
@ 2013-01-02 10:15 ` AnilKumar, Chimata
2013-01-11 8:09 ` Russ Dill
4 siblings, 1 reply; 17+ messages in thread
From: AnilKumar, Chimata @ 2013-01-02 10:15 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Dec 14, 2012 at 11:33:13, AnilKumar, Chimata wrote:
> 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). These patchs
> are based on linux-next.
Hi All,
Happy New Year
Gentle ping to this series
Thanks
AnilKumar
> Changes from v3:
> - TPS65217 mfd driver changes are accepted so dropped
> from this series.
> - With recent changes in the kernel, reboot_mutex held BUG()
> is not seen so removed while(1); from rtc_power_off.
> - Removed spinlock before while(1); which is not necessary.
>
> 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 (1):
> rtc: OMAP: Add system pm_power_off to rtc driver
>
> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
> arch/arm/boot/dts/am335x-bone.dts | 6 ++
> arch/arm/configs/omap2plus_defconfig | 1 +
> drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
> 4 files changed, 85 insertions(+), 1 deletion(-)
>
> --
> 1.7.9.5
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 2/4] ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone
2012-12-14 6:03 ` [PATCH v4 2/4] ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone AnilKumar Ch
@ 2013-01-11 8:08 ` Russ Dill
0 siblings, 0 replies; 17+ messages in thread
From: Russ Dill @ 2013-01-11 8:08 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
> 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.
>
> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Looks good
Reviewed-by: Russ Dill <russ.dill@ti.com>
Acked-by: Russ Dill <russ.dill@ti.com>
> ---
> arch/arm/boot/dts/am335x-bone.dts | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/arm/boot/dts/am335x-bone.dts b/arch/arm/boot/dts/am335x-bone.dts
> index 5302f79..e7dff9d 100644
> --- a/arch/arm/boot/dts/am335x-bone.dts
> +++ b/arch/arm/boot/dts/am335x-bone.dts
> @@ -88,6 +88,8 @@
> /include/ "tps65217.dtsi"
>
> &tps {
> + ti,pmic-shutdown-controller;
> +
> regulators {
> dcdc1_reg: regulator at 0 {
> regulator-always-on;
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 4/4] ARM: OMAP2+: omap2plus_defconfig: Enable RTC support
2012-12-14 6:03 ` [PATCH v4 4/4] ARM: OMAP2+: omap2plus_defconfig: Enable RTC support AnilKumar Ch
@ 2013-01-11 8:08 ` Russ Dill
0 siblings, 0 replies; 17+ messages in thread
From: Russ Dill @ 2013-01-11 8:08 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
> AM33XX family of devices use RTC module, one has to manually enable
> this support to use RTC features. So this patch enable RTC driver in
> omap2plus_defconfig.
>
> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Looks good
Reviewed-by: Russ Dill <russ.dill@ti.com>
Acked-by: Russ Dill <russ.dill@ti.com>
> ---
> arch/arm/configs/omap2plus_defconfig | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
> index 0ce6771..e58afc5 100644
> --- a/arch/arm/configs/omap2plus_defconfig
> +++ b/arch/arm/configs/omap2plus_defconfig
> @@ -216,6 +216,7 @@ CONFIG_LEDS_TRIGGER_CPU=y
> CONFIG_LEDS_TRIGGER_GPIO=y
> CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
> CONFIG_RTC_CLASS=y
> +CONFIG_RTC_DRV_OMAP=y
> CONFIG_RTC_DRV_TWL92330=y
> CONFIG_RTC_DRV_TWL4030=y
> CONFIG_DMADEVICES=y
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 3/4] ARM: dts: AM33XX: Enable system power off control in am335x-bone
2012-12-14 6:03 ` [PATCH v4 3/4] ARM: dts: AM33XX: Enable system power off control in am335x-bone AnilKumar Ch
@ 2013-01-11 8:08 ` Russ Dill
0 siblings, 0 replies; 17+ messages in thread
From: Russ Dill @ 2013-01-11 8:08 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
> 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.
>
> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Looks good
Reviewed-by: Russ Dill <russ.dill@ti.com>
Acked-by: Russ Dill <russ.dill@ti.com>
> ---
> arch/arm/boot/dts/am335x-bone.dts | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/arm/boot/dts/am335x-bone.dts b/arch/arm/boot/dts/am335x-bone.dts
> index e7dff9d..febbe2f 100644
> --- a/arch/arm/boot/dts/am335x-bone.dts
> +++ b/arch/arm/boot/dts/am335x-bone.dts
> @@ -52,6 +52,10 @@
> };
>
> };
> +
> + rtc at 44e3e000 {
> + ti,system-power-controller;
> + };
> };
>
> leds {
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver
2012-12-14 6:03 ` [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver AnilKumar Ch
@ 2013-01-11 8:08 ` Russ Dill
2013-01-11 8:54 ` Russ Dill
0 siblings, 1 reply; 17+ messages in thread
From: Russ Dill @ 2013-01-11 8:08 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
> From: Colin Foe-Parker <colin.foeparker@logicpd.com>
>
> 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
>
> Signed-off-by: Colin Foe-Parker <colin.foeparker@logicpd.com>
> [anilkumar at ti.com: move poweroff additions to rtc driver]
> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Looks good
Reviewed-by: Russ Dill <russ.dill@ti.com>
Acked-by: Russ Dill <russ.dill@ti.com>
> ---
> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
> drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
> 2 files changed, 78 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt 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
> @@ -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;
> };
> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> index 6009714..e6d4878 100644
> --- a/drivers/rtc/rtc-omap.c
> +++ b/drivers/rtc/rtc-omap.c
> @@ -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,56 @@ 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;
> + unsigned long time;
> +
> + /* 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);
> +}
> +
> static struct rtc_class_ops omap_rtc_ops = {
> .read_time = omap_rtc_read_time,
> .set_time = omap_rtc_set_time,
> @@ -327,12 +391,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 +453,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
> */
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 0/4] pm: Add power off control
2013-01-02 10:15 ` [PATCH v4 0/4] pm: Add power off control AnilKumar, Chimata
@ 2013-01-11 8:09 ` Russ Dill
2013-11-22 19:50 ` Ezequiel Garcia
0 siblings, 1 reply; 17+ messages in thread
From: Russ Dill @ 2013-01-11 8:09 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Jan 2, 2013 at 2:15 AM, AnilKumar, Chimata <anilkumar@ti.com> wrote:
> On Fri, Dec 14, 2012 at 11:33:13, AnilKumar, Chimata wrote:
>> 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). These patchs
>> are based on linux-next.
>
> Hi All,
>
> Happy New Year
>
> Gentle ping to this series
I personally like the series, it certainly adds needed functionality.
I just wish there was a way to get it without a possible 4 second
delay.
> Thanks
> AnilKumar
>
>> Changes from v3:
>> - TPS65217 mfd driver changes are accepted so dropped
>> from this series.
>> - With recent changes in the kernel, reboot_mutex held BUG()
>> is not seen so removed while(1); from rtc_power_off.
>> - Removed spinlock before while(1); which is not necessary.
>>
>> 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 (1):
>> rtc: OMAP: Add system pm_power_off to rtc driver
>>
>> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
>> arch/arm/boot/dts/am335x-bone.dts | 6 ++
>> arch/arm/configs/omap2plus_defconfig | 1 +
>> drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
>> 4 files changed, 85 insertions(+), 1 deletion(-)
>>
>> --
>> 1.7.9.5
>>
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver
2013-01-11 8:08 ` Russ Dill
@ 2013-01-11 8:54 ` Russ Dill
2013-01-11 9:30 ` AnilKumar, Chimata
2013-01-11 9:55 ` AnilKumar, Chimata
0 siblings, 2 replies; 17+ messages in thread
From: Russ Dill @ 2013-01-11 8:54 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 11, 2013 at 12:08 AM, Russ Dill <russ.dill@gmail.com> wrote:
> On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
>> From: Colin Foe-Parker <colin.foeparker@logicpd.com>
>>
>> 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
>>
>> Signed-off-by: Colin Foe-Parker <colin.foeparker@logicpd.com>
>> [anilkumar at ti.com: move poweroff additions to rtc driver]
>> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
>
> Looks good
>
> Reviewed-by: Russ Dill <russ.dill@ti.com>
> Acked-by: Russ Dill <russ.dill@ti.com>
Sorry, actually, small follow up. Is there any reason this uses
readl/writel in some places rather than rtc_read/rtc_write?
>> ---
>> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
>> drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
>> 2 files changed, 78 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt 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
>> @@ -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;
>> };
>> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
>> index 6009714..e6d4878 100644
>> --- a/drivers/rtc/rtc-omap.c
>> +++ b/drivers/rtc/rtc-omap.c
>> @@ -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,56 @@ 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;
>> + unsigned long time;
>> +
>> + /* 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);
>> +}
>> +
>> static struct rtc_class_ops omap_rtc_ops = {
>> .read_time = omap_rtc_read_time,
>> .set_time = omap_rtc_set_time,
>> @@ -327,12 +391,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 +453,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
>> */
>> --
>> 1.7.9.5
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
>> the body of a message to majordomo at vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver
2013-01-11 8:54 ` Russ Dill
@ 2013-01-11 9:30 ` AnilKumar, Chimata
2013-01-11 9:55 ` AnilKumar, Chimata
1 sibling, 0 replies; 17+ messages in thread
From: AnilKumar, Chimata @ 2013-01-11 9:30 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 11, 2013 at 14:24:46, Russ Dill wrote:
> On Fri, Jan 11, 2013 at 12:08 AM, Russ Dill <russ.dill@gmail.com> wrote:
> > On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
> >> From: Colin Foe-Parker <colin.foeparker@logicpd.com>
> >>
> >> 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
> >>
> >> Signed-off-by: Colin Foe-Parker <colin.foeparker@logicpd.com>
> >> [anilkumar at ti.com: move poweroff additions to rtc driver]
> >> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
> >
> > Looks good
> >
> > Reviewed-by: Russ Dill <russ.dill@ti.com>
> > Acked-by: Russ Dill <russ.dill@ti.com>
>
> Sorry, actually, small follow up. Is there any reason this uses
> readl/writel in some places rather than rtc_read/rtc_write?
Hi Russ Dill,
Thanks for the review
At OMAP_RTC_PMIC_POWER_EN_EN, 32-bit value needs to modified so
readl/writel are used. While enabling the INTERRUPTS we can change
it to rtc_read/rtc_write but I am not seeing any advantage if we
do that apart from consistency.
Thanks
AnilKumar
>
> >> ---
> >> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
> >> drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
> >> 2 files changed, 78 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt 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
> >> @@ -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;
> >> };
> >> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> >> index 6009714..e6d4878 100644
> >> --- a/drivers/rtc/rtc-omap.c
> >> +++ b/drivers/rtc/rtc-omap.c
> >> @@ -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,56 @@ 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;
> >> + unsigned long time;
> >> +
> >> + /* 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);
> >> +}
> >> +
> >> static struct rtc_class_ops omap_rtc_ops = {
> >> .read_time = omap_rtc_read_time,
> >> .set_time = omap_rtc_set_time,
> >> @@ -327,12 +391,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 +453,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
> >> */
> >> --
> >> 1.7.9.5
> >>
> >> --
> >> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> >> the body of a message to majordomo at vger.kernel.org
> >> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver
2013-01-11 8:54 ` Russ Dill
2013-01-11 9:30 ` AnilKumar, Chimata
@ 2013-01-11 9:55 ` AnilKumar, Chimata
1 sibling, 0 replies; 17+ messages in thread
From: AnilKumar, Chimata @ 2013-01-11 9:55 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Jan 11, 2013 at 15:00:03, AnilKumar, Chimata wrote:
> On Fri, Jan 11, 2013 at 14:24:46, Russ Dill wrote:
> > On Fri, Jan 11, 2013 at 12:08 AM, Russ Dill <russ.dill@gmail.com> wrote:
> > > On Thu, Dec 13, 2012 at 10:03 PM, AnilKumar Ch <anilkumar@ti.com> wrote:
> > >> From: Colin Foe-Parker <colin.foeparker@logicpd.com>
> > >>
> > >> 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
> > >>
> > >> Signed-off-by: Colin Foe-Parker <colin.foeparker@logicpd.com>
> > >> [anilkumar at ti.com: move poweroff additions to rtc driver]
> > >> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
> > >
> > > Looks good
> > >
> > > Reviewed-by: Russ Dill <russ.dill@ti.com>
> > > Acked-by: Russ Dill <russ.dill@ti.com>
> >
> > Sorry, actually, small follow up. Is there any reason this uses
> > readl/writel in some places rather than rtc_read/rtc_write?
>
> Hi Russ Dill,
>
> Thanks for the review
>
> At OMAP_RTC_PMIC_POWER_EN_EN, 32-bit value needs to modified so
> readl/writel are used. While enabling the INTERRUPTS we can change
> it to rtc_read/rtc_write but I am not seeing any advantage if we
> do that apart from consistency.
And driver has to clean-up properly to make use of rtc_read/write
APIs with proper read/write's based on the memory type. Ideally
rtc_readb/w/l and rtc_writeb/w/l should go way from the driver.
This clean-up can be done while converting the driver with platform
specific rtc_read/write.
Thanks
AnilKumar
> > >> ---
> > >> Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++
> > >> drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++-
> > >> 2 files changed, 78 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/Documentation/devicetree/bindings/rtc/rtc-omap.txt 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
> > >> @@ -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;
> > >> };
> > >> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> > >> index 6009714..e6d4878 100644
> > >> --- a/drivers/rtc/rtc-omap.c
> > >> +++ b/drivers/rtc/rtc-omap.c
> > >> @@ -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,56 @@ 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;
> > >> + unsigned long time;
> > >> +
> > >> + /* 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);
> > >> +}
> > >> +
> > >> static struct rtc_class_ops omap_rtc_ops = {
> > >> .read_time = omap_rtc_read_time,
> > >> .set_time = omap_rtc_set_time,
> > >> @@ -327,12 +391,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 +453,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
> > >> */
> > >> --
> > >> 1.7.9.5
> > >>
> > >> --
> > >> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> > >> the body of a message to majordomo at vger.kernel.org
> > >> More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 0/4] pm: Add power off control
2013-01-11 8:09 ` Russ Dill
@ 2013-11-22 19:50 ` Ezequiel Garcia
2013-11-23 17:23 ` [rtc-linux] " Vaibhav Bedia
0 siblings, 1 reply; 17+ messages in thread
From: Ezequiel Garcia @ 2013-11-22 19:50 UTC (permalink / raw)
To: linux-arm-kernel
Hi Russ,
On Fri, Jan 11, 2013 at 12:09:56AM -0800, Russ Dill wrote:
> I personally like the series, it certainly adds needed functionality.
> I just wish there was a way to get it without a possible 4 second
> delay.
>
I was just going through this patches and got confused by the same
thing, could you explain me *why* are those waitings requried?
And why specifically *2* seconds, instead of *1* or *33* ?
Sounds a bit like voodoo magic on this side :-)
--
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* [rtc-linux] Re: [PATCH v4 0/4] pm: Add power off control
2013-11-22 19:50 ` Ezequiel Garcia
@ 2013-11-23 17:23 ` Vaibhav Bedia
2013-11-26 13:22 ` Ezequiel Garcia
0 siblings, 1 reply; 17+ messages in thread
From: Vaibhav Bedia @ 2013-11-23 17:23 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Nov 22, 2013 at 2:50 PM, Ezequiel Garcia
<ezequiel.garcia@free-electrons.com> wrote:
[...]
>
> And why specifically *2* seconds, instead of *1* or *33* ?
>
> Sounds a bit like voodoo magic on this side :-)
Consider the scenario where the actual time is 00:00:01.95 secs.
Due to the 1 second resolution of the RTC, reading the registers
would return 00:00:01. By the time we get to updating the
RTC register for the shutdown by adding 1 sec (theoretically the
smallest delta) we could end up programming the time that's already
passed and in such cases the system will never shut down.
2 secs is the smallest delay that we can use to get the system
to shutdown reliably.
So it's not voodoo magic after all ;)
Regards,
Vaibhav
^ permalink raw reply [flat|nested] 17+ messages in thread
* [rtc-linux] Re: [PATCH v4 0/4] pm: Add power off control
2013-11-23 17:23 ` [rtc-linux] " Vaibhav Bedia
@ 2013-11-26 13:22 ` Ezequiel Garcia
0 siblings, 0 replies; 17+ messages in thread
From: Ezequiel Garcia @ 2013-11-26 13:22 UTC (permalink / raw)
To: linux-arm-kernel
On Sat, Nov 23, 2013 at 12:23:35PM -0500, Vaibhav Bedia wrote:
> On Fri, Nov 22, 2013 at 2:50 PM, Ezequiel Garcia
> <ezequiel.garcia@free-electrons.com> wrote:
> [...]
> >
> > And why specifically *2* seconds, instead of *1* or *33* ?
> >
> > Sounds a bit like voodoo magic on this side :-)
>
> Consider the scenario where the actual time is 00:00:01.95 secs.
> Due to the 1 second resolution of the RTC, reading the registers
> would return 00:00:01. By the time we get to updating the
> RTC register for the shutdown by adding 1 sec (theoretically the
> smallest delta) we could end up programming the time that's already
> passed and in such cases the system will never shut down.
>
> 2 secs is the smallest delay that we can use to get the system
> to shutdown reliably.
>
> So it's not voodoo magic after all ;)
>
Right, thanks for the details.
Care to add the above explanation to a comment inside the driver?
That way, people won't ask this same question again :-)
--
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2013-11-26 13:22 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-14 6:03 [PATCH v4 0/4] pm: Add power off control AnilKumar Ch
2012-12-14 6:03 ` [PATCH v4 1/4] rtc: OMAP: Add system pm_power_off to rtc driver AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2013-01-11 8:54 ` Russ Dill
2013-01-11 9:30 ` AnilKumar, Chimata
2013-01-11 9:55 ` AnilKumar, Chimata
2012-12-14 6:03 ` [PATCH v4 2/4] ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2012-12-14 6:03 ` [PATCH v4 3/4] ARM: dts: AM33XX: Enable system power off control in am335x-bone AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2012-12-14 6:03 ` [PATCH v4 4/4] ARM: OMAP2+: omap2plus_defconfig: Enable RTC support AnilKumar Ch
2013-01-11 8:08 ` Russ Dill
2013-01-02 10:15 ` [PATCH v4 0/4] pm: Add power off control AnilKumar, Chimata
2013-01-11 8:09 ` Russ Dill
2013-11-22 19:50 ` Ezequiel Garcia
2013-11-23 17:23 ` [rtc-linux] " Vaibhav Bedia
2013-11-26 13:22 ` Ezequiel Garcia
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).