pm: Add power off control
Subsystems (4)
v4 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). 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(-)
Signature · 1 line
1.7.9.5
PATCH v4 1/4 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
--- Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++ drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/rtc/rtc-omap.txt +5 -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. + 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 +73 -1
118 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v4 1/4 rtc: OMAP: Add system pm_power_off to rtc driver
Quoted 12 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_offroutine can be hooked up to "pm_power_off" system call.System power off sequence:-
* Set PMICSTATUS_OFFwhenPMIC_POWER_ENis pulled low
* EnablePMIC_POWER_ENin rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt
Quoted 3 lines
Signed-off-by Colin Foe-Parker <[email protected]>[anilkumar at ti.com: move poweroff additions to rtc driver]Signed-off-by AnilKumar Ch <[email protected]>
Looks good
Quoted 160 lines
--- Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++ drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/rtc/rtc-omap.txt +5
-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. + 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 +73
-2@@ -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
PATCH v4 1/4 rtc: OMAP: Add system pm_power_off to rtc driver
Quoted 13 lines · Russ Dill
Quoted 12 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_offroutine can be hooked up to "pm_power_off" system call.System power off sequence:-
* Set PMICSTATUS_OFFwhenPMIC_POWER_ENis pulled low
* EnablePMIC_POWER_ENin rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt
Quoted 8 lines
Quoted 3 lines
Signed-off-by Colin Foe-Parker <[email protected]>[anilkumar at ti.com: move poweroff additions to rtc driver]Signed-off-by AnilKumar Ch <[email protected]>Looks good
Reviewed-by Russ Dill <[email protected]>Acked-by Russ Dill <[email protected]>
Sorry, actually, small follow up. Is there any reason this uses readl/writel in some places rather than rtc_read/rtc_write?
Quoted 160 lines
Quoted 160 lines
--- Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++ drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/rtc/rtc-omap.txt +5
-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. + 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 +73
-2@@ -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
PATCH v4 1/4 rtc: OMAP: Add system pm_power_off to rtc driver
Quoted 18 lines · Russ Dill
Quoted 17 lines · Russ Dill
Quoted 15 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_offroutine can be hooked up to "pm_power_off" system call.System power off sequence:-
* Set PMICSTATUS_OFFwhenPMIC_POWER_ENis pulled low
* EnablePMIC_POWER_ENin rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interruptSigned-off-by Colin Foe-Parker <[email protected]>[anilkumar at ti.com: move poweroff additions to rtc driver]Signed-off-by AnilKumar Ch <[email protected]>
Quoted 7 lines
Quoted 4 lines
Looks good
Reviewed-by Russ Dill <[email protected]>Acked-by Russ Dill <[email protected]>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
Quoted 162 lines
Quoted 161 lines
Quoted 161 lines
--- Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++ drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/rtc/rtc-omap.txt +5
-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. + 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 +73
-2@@ -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
PATCH v4 1/4 rtc: OMAP: Add system pm_power_off to rtc driver
In reply to Russ DillQuoted 27 lines · Chimata
Quoted 18 lines · Russ Dill
Quoted 17 lines · Russ Dill
Quoted 15 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_offroutine can be hooked up to "pm_power_off" system call.System power off sequence:-
* Set PMICSTATUS_OFFwhenPMIC_POWER_ENis pulled low
* EnablePMIC_POWER_ENin rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interruptSigned-off-by Colin Foe-Parker <[email protected]>[anilkumar at ti.com: move poweroff additions to rtc driver]Signed-off-by AnilKumar Ch <[email protected]>Quoted 7 lines
Quoted 4 lines
Looks good
Reviewed-by Russ Dill <[email protected]>Acked-by Russ Dill <[email protected]>Sorry, actually, small follow up. Is there any reason this uses readl/writel in some places rather than rtc_read/rtc_write?
Quoted 8 lines
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
Quoted 163 lines
Quoted 161 lines
Quoted 160 lines
Quoted 160 lines
--- Documentation/devicetree/bindings/rtc/rtc-omap.txt | 5 ++ drivers/rtc/rtc-omap.c | 74 +++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/rtc/rtc-omap.txt +5
-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. + 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 +73
-2@@ -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
PATCH v4 2/4 ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone
In reply to AnilKumar ChSet 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
@@ -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
PATCH v4 2/4 ARM: dts: AM33XX: Set pmic-shutdown-controller for BeagleBone
Quoted 5 lines · AnilKumar Ch
Set ti,pmic-shutdown-controller for BeagleBone in
am335x-bone.dtsfile, this flag is used by the driver to set tps65217 PMIC status to OFF whenPWR_ENtoggle.Signed-off-by AnilKumar Ch <[email protected]>
Looks good
Quoted 24 lines
--- arch/arm/boot/dts/am335x-bone.dts | 2 ++ 1 file changed, 2 insertions(+)arch/arm/boot/dts/am335x-bone.dts +2
-1@@ -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
PATCH v4 3/4 ARM: dts: AM33XX: Enable system power off control in am335x-bone
In reply to AnilKumar ChEnable 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
@@ -52,6 +52,10 @@ }; }; + + rtc at 44e3e000 { + ti,system-power-controller; + }; }; leds {
Signature · 1 line
1.7.9.5
PATCH v4 3/4 ARM: dts: AM33XX: Enable system power off control in am335x-bone
Quoted 5 lines · AnilKumar Ch
Enable system power off control for BeagleBone in
am335x-bone.dtsfile under rtc node. RTC is the incharge of controlling the system power. This flag is used by the driver to hook up thepm_power_offsystem call.Signed-off-by AnilKumar Ch <[email protected]>
Looks good
Quoted 26 lines
--- arch/arm/boot/dts/am335x-bone.dts | 4 ++++ 1 file changed, 4 insertions(+)arch/arm/boot/dts/am335x-bone.dts +4
-1@@ -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
PATCH v4 4/4 ARM: OMAP2+: omap2plus_defconfig: Enable RTC support
In reply to AnilKumar ChAM33XX 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.
--- arch/arm/configs/omap2plus_defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
@@ -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
Signature · 1 line
1.7.9.5
PATCH v4 4/4 ARM: OMAP2+: omap2plus_defconfig: Enable RTC support
Quoted 5 lines · AnilKumar Ch
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 <[email protected]>
Looks good
Quoted 23 lines
--- arch/arm/configs/omap2plus_defconfig | 1 + 1 file changed, 1 insertion(+)arch/arm/configs/omap2plus_defconfig +1
-1@@ -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
v4 cover pm: Add power off control
In reply to AnilKumar ChQuoted 11 lines · Chimata
Add PM
power_offcontrol to rtc driver and PMIC status is set toSTATUS_OFFto shutdown PMIC ifPWR_ENis toggled by RTC module.System power off sequence:-
* Set PMICSTATUS_OFFwhenPMIC_POWER_ENis pulled low
* EnablePMIC_POWER_ENin rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interruptThese 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
Quoted 34 lines
Changes from v3:
- TPS65217 mfd driver changes are accepted so dropped from this series.
- With recent changes in the kernel,reboot_mutexheldBUG()is not seen so removed while(1); fromrtc_power_off.
- Removed spinlock before while(1); which is not necessary.Changes from v2:
- Incorporated Kevin's comment on v2
* Enabled RTC inompa2plus_defconfigChanges from v1:
- Incorporated Vaibhav's comments on v1
* Changed the time rollover logic with the help of rtc-lib APIsAnilKumar 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 supportColin Foe-Parker (1):
rtc: OMAP: Add systempm_power_offto rtc driverDocumentation/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(-)Signature · 1 line
1.7.9.5
v4 cover pm: Add power off control
Quoted 10 lines · Chimata
Quoted 9 lines · Chimata
Add PM
power_offcontrol to rtc driver and PMIC status is set toSTATUS_OFFto shutdown PMIC ifPWR_ENis toggled by RTC module.System power off sequence:-
* Set PMICSTATUS_OFFwhenPMIC_POWER_ENis pulled low
* EnablePMIC_POWER_ENin rtc module
* Set rtc ALARM2 time
* Enable ALARM2 interrupt
Quoted 8 lines
Quoted 2 lines
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.
Quoted 42 lines
Thanks
AnilKumarQuoted 24 lines
Changes from v3:
- TPS65217 mfd driver changes are accepted so dropped from this series.
- With recent changes in the kernel,reboot_mutexheldBUG()is not seen so removed while(1); fromrtc_power_off.
- Removed spinlock before while(1); which is not necessary.Changes from v2:
- Incorporated Kevin's comment on v2
* Enabled RTC inompa2plus_defconfigChanges from v1:
- Incorporated Vaibhav's comments on v1
* Changed the time rollover logic with the help of rtc-lib APIsAnilKumar 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 supportColin Foe-Parker (1):
rtc: OMAP: Add systempm_power_offto rtc driverQuoted 10 lines
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
v4 cover pm: Add power off control
Hi Russ,
Quoted 4 lines · Russ Dill
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 :-)
Signature · 7 lines
Ezequiel García, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Nov 22, 2013 at 2:50 PM, Ezequiel Garcia
<[email protected]> wrote:
[...]
Quoted 4 lines
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
Quoted 15 lines · Vaibhav Bedia
On Fri, Nov 22, 2013 at 2:50 PM, Ezequiel Garcia
<[email protected]> wrote:
[...]Quoted 4 lines
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.
Quoted 5 lines
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 :-)
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com