Save HSMMC registers if core is powered off
RFC 1/1 Save HSMMC registers if core is powered off
I've noticed that if the core power domain gets powered off during suspend, the MMC registers get reset. Which, among other things causes the MMC host controller code to turn on VMMC1 even if no MMC card is present.
I'm not sure if this is the right place to put this code. It also doesn't work. If any of the __raw_readl commands execute, the board will hang on a suspend attempt (assuming the core domain will be powered off.) Strangely, the __raw_writel commands don't cause problems (other than writing 0s to all the MMC registers.)
My platform is an OMAP3430 on a rev B7 Beagleboard. The patch is against omap/pm.
--- arch/arm/mach-omap2/Makefile | 1 + arch/arm/mach-omap2/hsmmc.c | 73 +++++++++++++++++++++++++++++++ arch/arm/mach-omap2/pm34xx.c | 5 ++ arch/arm/plat-omap/include/mach/hsmmc.h | 15 ++++++ 4 files changed, 94 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/hsmmc.c create mode 100644 arch/arm/plat-omap/include/mach/hsmmc.h
arch/arm/mach-omap2/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-y += pm.o obj-$(CONFIG_ARCH_OMAP2) += pm24xx.o obj-$(CONFIG_ARCH_OMAP24XX) += sleep24xx.o obj-$(CONFIG_ARCH_OMAP3) += pm34xx.o sleep34xx.o cpuidle34xx.o +obj-$(CONFIG_ARCH_OMAP3) += hsmmc.o obj-$(CONFIG_PM_DEBUG) += pm-debug.o endif
arch/arm/mach-omap2/hsmmc.c new file +73 -0
73 lines not on this page · raw message
arch/arm/mach-omap2/pm34xx.c +5 -0
@@ -41,6 +41,7 @@#include <mach/sdrc.h> #include <mach/dma.h> #include <mach/gpmc.h> +#include <mach/hsmmc.h> #include <mach/dma.h> #include <asm/tlbflush.h>
@@ -148,6 +149,8 @@ static void omap3_core_save_context(void)omap3_intc_save_context ();/* Save the GPMC context */ omap3_gpmc_save_context (); +/* Save the HSMMC context */ +omap3_hsmmc_save_context ();/* Save the system control module context, padconf already save above*/ omap3_control_save_context ();omap_dma_global_context_save ();
@@ -159,6 +162,8 @@ static void omap3_core_restore_context(void)omap3_control_restore_context ();/* Restore the GPMC context */ omap3_gpmc_restore_context (); +/* Restore the HSMMC context */ +omap3_hsmmc_restore_context ();/* Restore the interrupt controller context */ omap3_intc_restore_context ();omap_dma_global_context_restore ();
arch/arm/plat-omap/include/mach/hsmmc.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* HSMMC save/restore logic for OMAP3 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __OMAP3_HSMMC_H +#define __OMAP3_HSMMC_H + +extern void omap3_hsmmc_save_context (void ); +extern void omap3_hsmmc_restore_context (void ); + +#endif
Signature · 1 line
1.6.0.4
Quoted 10 lines · Russ Dill
I've noticed that if the core power domain gets powered off during suspend, the MMC registers get reset. Which, among other things causes the MMC host controller code to turn on VMMC1 even if no MMC card is present.
I'm not sure if this is the right place to put this code. It also doesn't work. If any of the
__raw_readlcommands execute, the board will hang on a suspend attempt (assuming the core domain will be powered off.) Strangely, the__raw_writelcommands don't cause problems (other than writing 0s to all the MMC registers.)
That would be because omap_mmc_suspend disables the interface clock. The suspend method is a more logical place to save these registers, but I'm not sure how to tell from the suspend method if the domain is going to be turned off or not.
Quoted 154 lines
My platform is an OMAP3430 on a rev B7 Beagleboard. The patch is against omap/pm.
---arch/arm/mach-omap2/Makefile | 1 + arch/arm/mach-omap2/hsmmc.c | 73 +++++++++++++++++++++++++++++++ arch/arm/mach-omap2/pm34xx.c | 5 ++ arch/arm/plat-omap/include/mach/hsmmc.h | 15 ++++++ 4 files changed, 94 insertions(+), 0 deletions(-)create mode 100644
arch/arm/mach-omap2/hsmmc.ccreate mode 100644arch/arm/plat-omap/include/mach/hsmmc.harch/arm/mach-omap2/Makefile +0
-0@@ -24,6 +24,7 @@ obj-y += pm.oobj-$(CONFIG_ARCH_OMAP2) += pm24xx.o obj-$(CONFIG_ARCH_OMAP24XX) += sleep24xx.o obj-$(CONFIG_ARCH_OMAP3) += pm34xx.o sleep34xx.o cpuidle34xx.o +obj-$(CONFIG_ARCH_OMAP3) += hsmmc.o obj-$(CONFIG_PM_DEBUG) += pm-debug.o
endifarch/arm/mach-omap2/hsmmc.c new file +73
-0@@ -0,0 +1,73 @@ +/* +* HSMMC context save/restore functions +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/kernel.h> + +#include <asm/io.h> + +#include <mach/mmc.h> + +#define HSMMC_SYSCONFIG 0x0010 +#define HSMMC_CON 0x002c +#define HSMMC_HCTL 0x0128 +#define HSMMC_SYSCTL 0x012c +#define HSMMC_IE 0x0134 +#define HSMMC_ISE 0x0138 + +static const void __iomem *instances[] = { + OMAP2_IO_ADDRESS(OMAP2_MMC1_BASE), + OMAP2_IO_ADDRESS(OMAP2_MMC2_BASE), + OMAP2_IO_ADDRESS(OMAP3_MMC3_BASE), +}; + +struct omap3_hsmmc_regs { + u32 sysconfig; + u32 con; + u32 hctl; + u32 sysctl; + u32 ie; + u32 ise; +}; + +static struct omap3_hsmmc_regs hsmmc_context[ARRAY_SIZE (instances)]; + +static void hsmmc_write_reg (int id,int idx,u32 val) +{ + __raw_writel(val, instances[id] + idx); +} + +static u32 hsmmc_read_reg (int id,int idx) +{ + return 0;//__raw_readl(instances[id] + idx); +} + +void omap3_hsmmc_save_context (void ) +{ + int i; + for (i = 0; i < ARRAY_SIZE(instances); i++) { + hsmmc_context[i].sysconfig = hsmmc_read_reg(i, HSMMC_SYSCONFIG); + hsmmc_context[i].con = hsmmc_read_reg(i, HSMMC_CON); + hsmmc_context[i].hctl = hsmmc_read_reg(i, HSMMC_HCTL); + hsmmc_context[i].sysctl = hsmmc_read_reg(i, HSMMC_SYSCTL); + hsmmc_context[i].ie = hsmmc_read_reg(i, HSMMC_IE); + hsmmc_context[i].ise = hsmmc_read_reg(i, HSMMC_ISE); + } +} + +void omap3_hsmmc_restore_context (void ) +{ + int i; + for (i = 0; i < ARRAY_SIZE(instances); i++) { + hsmmc_write_reg(i, HSMMC_SYSCONFIG, hsmmc_context[i].sysconfig); + hsmmc_write_reg(i, HSMMC_CON, hsmmc_context[i].con); + hsmmc_write_reg(i, HSMMC_HCTL, hsmmc_context[i].hctl); + hsmmc_write_reg(i, HSMMC_SYSCTL, hsmmc_context[i].sysctl); + hsmmc_write_reg(i, HSMMC_IE, hsmmc_context[i].ie); + hsmmc_write_reg(i, HSMMC_ISE, hsmmc_context[i].ise); + } +}arch/arm/mach-omap2/pm34xx.c +5
-0@@ -41,6 +41,7 @@ #include <mach/sdrc.h> #include <mach/dma.h> #include <mach/gpmc.h> +#include <mach/hsmmc.h> #include <mach/dma.h> #include <asm/tlbflush.h>@@ -148,6 +149,8 @@ static void omap3_core_save_context(void) omap3_intc_save_context(); /* Save the GPMC context */ omap3_gpmc_save_context(); + /* Save the HSMMC context */ + omap3_hsmmc_save_context(); /* Save the system control module context, padconf already save above*/ omap3_control_save_context(); omap_dma_global_context_save();@@ -159,6 +162,8 @@ static void omap3_core_restore_context(void) omap3_control_restore_context(); /* Restore the GPMC context */ omap3_gpmc_restore_context(); + /* Restore the HSMMC context */ + omap3_hsmmc_restore_context(); /* Restore the interrupt controller context */ omap3_intc_restore_context(); omap_dma_global_context_restore();arch/arm/plat-omap/include/mach/hsmmc.h new file +15
-1@@ -0,0 +1,15 @@ +/* +* HSMMC save/restore logic for OMAP3 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __OMAP3_HSMMC_H +#define __OMAP3_HSMMC_H + +extern void omap3_hsmmc_save_context (void ); +extern void omap3_hsmmc_restore_context (void ); + +#endif --
Quoted 3 lines
1.6.0.4
--
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
Hello Russ,
Quoted 12 lines · Russ Dill
Quoted 10 lines · Russ Dill
I've noticed that if the core power domain gets powered off during suspend, the MMC registers get reset. Which, among other things causes the MMC host controller code to turn on VMMC1 even if no MMC card is present.
I'm not sure if this is the right place to put this code. It also doesn't work. If any of the
__raw_readlcommands execute, the board will hang on a suspend attempt (assuming the core domain will be powered off.) Strangely, the__raw_writelcommands don't cause problems (other than writing 0s to all the MMC registers.)
Quoted 4 lines
That would be because
omap_mmc_suspenddisables the interface clock. The suspend method is a more logical place to save these registers, but I'm not sure how to tell from the suspend method if the domain is going to be turned off or not.
Generally speaking, the device driver doesn't know this. The powerdomain target state decision may change after the device goes idle. So the best thing to do is to save context unconditionally before disabling clocks.
Another approach to saving device context that should work for most registers is to save the register contents when the device registers are written -- the "shadow register" approach. That approach avoids unnecessary latency in the device idle path and avoids some register reads.
One other possible optimization. In the event that the device context is not lost, an unnecessary context restore can be avoided by using the omap_pm_get_dev_context_loss_count() function. (This is documented in plat-omap/include/mach/omap-pm.h) This function should be used by passing a function pointer to the driver code in struct omap_mmc_platform_data, called 'get_dev_context_loss_count' -- this should look something like the example at the end of this E-mail.
Hope this helps,
- Paul
... In driver idle path, before clk_disable() ...
int loss_count;
if (pdata->get_dev_context_loss_count)
loss_count = pdata->get_dev_context_loss_count();
... In driver resume path, after clk_enable() ...
int restore_needed = 1;
if (pdata->get_dev_context_loss_count)
if (pdata->get_dev_context_loss_count() == loss_count) restore_needed = 0;
if (restore_needed)
/* restore device registers here */