* [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff @ 2016-10-25 9:37 ` Alexandre Belloni 0 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov Cc: Nicolas Ferre, Jean-Jacques Hiblot, linux-pm, linux-kernel, linux-arm-kernel, Alexandre Belloni Hi, This patch set improves LPDDR support on SoCs using the Atmel MPDDR controller. LPDDR memories can only handle up to 400 uncontrolled power offs in their life. The proper power off sequence has to be applied before shutting down the SoC. I'm not too happy with the code duplication but this is a design choice that has been made before because both shutdown controllers are really different apart from the shutdown itself. I guess it is still better than slowly killing the LPDDR. Changes in v3: - removed COMPILE_TEST for sama5d2_shdwc as it is now ARM specific Changes in v2: - Fix typos - Add a comment for the dummy read access of AT91_SHDW_CR - Properly set up pm_power_off in at91_poweroff_probe() Alexandre Belloni (2): ARM: at91: define LPDDR types power/reset: at91-poweroff: timely shutdown LPDDR memories drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++- include/soc/at91/at91sam9_ddrsdr.h | 3 ++ 4 files changed, 105 insertions(+), 3 deletions(-) -- 2.9.3 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff @ 2016-10-25 9:37 ` Alexandre Belloni 0 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: linux-arm-kernel Hi, This patch set improves LPDDR support on SoCs using the Atmel MPDDR controller. LPDDR memories can only handle up to 400 uncontrolled power offs in their life. The proper power off sequence has to be applied before shutting down the SoC. I'm not too happy with the code duplication but this is a design choice that has been made before because both shutdown controllers are really different apart from the shutdown itself. I guess it is still better than slowly killing the LPDDR. Changes in v3: - removed COMPILE_TEST for sama5d2_shdwc as it is now ARM specific Changes in v2: - Fix typos - Add a comment for the dummy read access of AT91_SHDW_CR - Properly set up pm_power_off in at91_poweroff_probe() Alexandre Belloni (2): ARM: at91: define LPDDR types power/reset: at91-poweroff: timely shutdown LPDDR memories drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++- include/soc/at91/at91sam9_ddrsdr.h | 3 ++ 4 files changed, 105 insertions(+), 3 deletions(-) -- 2.9.3 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff @ 2016-10-25 9:37 ` Alexandre Belloni 0 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov Cc: Jean-Jacques Hiblot, linux-pm, Nicolas Ferre, linux-kernel, Alexandre Belloni, linux-arm-kernel Hi, This patch set improves LPDDR support on SoCs using the Atmel MPDDR controller. LPDDR memories can only handle up to 400 uncontrolled power offs in their life. The proper power off sequence has to be applied before shutting down the SoC. I'm not too happy with the code duplication but this is a design choice that has been made before because both shutdown controllers are really different apart from the shutdown itself. I guess it is still better than slowly killing the LPDDR. Changes in v3: - removed COMPILE_TEST for sama5d2_shdwc as it is now ARM specific Changes in v2: - Fix typos - Add a comment for the dummy read access of AT91_SHDW_CR - Properly set up pm_power_off in at91_poweroff_probe() Alexandre Belloni (2): ARM: at91: define LPDDR types power/reset: at91-poweroff: timely shutdown LPDDR memories drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++- include/soc/at91/at91sam9_ddrsdr.h | 3 ++ 4 files changed, 105 insertions(+), 3 deletions(-) -- 2.9.3 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 1/2] ARM: at91: define LPDDR types 2016-10-25 9:37 ` Alexandre Belloni @ 2016-10-25 9:37 ` Alexandre Belloni -1 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov Cc: Nicolas Ferre, Jean-Jacques Hiblot, linux-pm, linux-kernel, linux-arm-kernel, Alexandre Belloni, # 4 . 4+ The Atmel MPDDR controller support LPDDR2 and LPDDR3 memories, add their types. Cc: <stable@vger.kernel.org> # 4.4+ Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> --- include/soc/at91/at91sam9_ddrsdr.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/soc/at91/at91sam9_ddrsdr.h b/include/soc/at91/at91sam9_ddrsdr.h index dc10c52e0e91..393362bdb860 100644 --- a/include/soc/at91/at91sam9_ddrsdr.h +++ b/include/soc/at91/at91sam9_ddrsdr.h @@ -81,6 +81,7 @@ #define AT91_DDRSDRC_LPCB_POWER_DOWN 2 #define AT91_DDRSDRC_LPCB_DEEP_POWER_DOWN 3 #define AT91_DDRSDRC_CLKFR (1 << 2) /* Clock Frozen */ +#define AT91_DDRSDRC_LPDDR2_PWOFF (1 << 3) /* LPDDR Power Off */ #define AT91_DDRSDRC_PASR (7 << 4) /* Partial Array Self Refresh */ #define AT91_DDRSDRC_TCSR (3 << 8) /* Temperature Compensated Self Refresh */ #define AT91_DDRSDRC_DS (3 << 10) /* Drive Strength */ @@ -96,7 +97,9 @@ #define AT91_DDRSDRC_MD_SDR 0 #define AT91_DDRSDRC_MD_LOW_POWER_SDR 1 #define AT91_DDRSDRC_MD_LOW_POWER_DDR 3 +#define AT91_DDRSDRC_MD_LPDDR3 5 #define AT91_DDRSDRC_MD_DDR2 6 /* [SAM9 Only] */ +#define AT91_DDRSDRC_MD_LPDDR2 7 #define AT91_DDRSDRC_DBW (1 << 4) /* Data Bus Width */ #define AT91_DDRSDRC_DBW_32BITS (0 << 4) #define AT91_DDRSDRC_DBW_16BITS (1 << 4) -- 2.9.3 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 1/2] ARM: at91: define LPDDR types @ 2016-10-25 9:37 ` Alexandre Belloni 0 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: linux-arm-kernel The Atmel MPDDR controller support LPDDR2 and LPDDR3 memories, add their types. Cc: <stable@vger.kernel.org> # 4.4+ Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> --- include/soc/at91/at91sam9_ddrsdr.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/soc/at91/at91sam9_ddrsdr.h b/include/soc/at91/at91sam9_ddrsdr.h index dc10c52e0e91..393362bdb860 100644 --- a/include/soc/at91/at91sam9_ddrsdr.h +++ b/include/soc/at91/at91sam9_ddrsdr.h @@ -81,6 +81,7 @@ #define AT91_DDRSDRC_LPCB_POWER_DOWN 2 #define AT91_DDRSDRC_LPCB_DEEP_POWER_DOWN 3 #define AT91_DDRSDRC_CLKFR (1 << 2) /* Clock Frozen */ +#define AT91_DDRSDRC_LPDDR2_PWOFF (1 << 3) /* LPDDR Power Off */ #define AT91_DDRSDRC_PASR (7 << 4) /* Partial Array Self Refresh */ #define AT91_DDRSDRC_TCSR (3 << 8) /* Temperature Compensated Self Refresh */ #define AT91_DDRSDRC_DS (3 << 10) /* Drive Strength */ @@ -96,7 +97,9 @@ #define AT91_DDRSDRC_MD_SDR 0 #define AT91_DDRSDRC_MD_LOW_POWER_SDR 1 #define AT91_DDRSDRC_MD_LOW_POWER_DDR 3 +#define AT91_DDRSDRC_MD_LPDDR3 5 #define AT91_DDRSDRC_MD_DDR2 6 /* [SAM9 Only] */ +#define AT91_DDRSDRC_MD_LPDDR2 7 #define AT91_DDRSDRC_DBW (1 << 4) /* Data Bus Width */ #define AT91_DDRSDRC_DBW_32BITS (0 << 4) #define AT91_DDRSDRC_DBW_16BITS (1 << 4) -- 2.9.3 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/2] power/reset: at91-poweroff: timely shutdown LPDDR memories 2016-10-25 9:37 ` Alexandre Belloni @ 2016-10-25 9:37 ` Alexandre Belloni -1 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: Sebastian Reichel, Dmitry Eremin-Solenikov Cc: Nicolas Ferre, Jean-Jacques Hiblot, linux-pm, linux-kernel, linux-arm-kernel, Alexandre Belloni, # 4 . 4+ LPDDR memories can only handle up to 400 uncontrolled power off. Ensure the proper power off sequence is used before shutting down the platform. Cc: <stable@vger.kernel.org> # 4.4+ Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> --- drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index c74c3f67b8da..02e46bbcf45d 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -32,7 +32,7 @@ config POWER_RESET_AT91_RESET config POWER_RESET_AT91_SAMA5D2_SHDWC tristate "Atmel AT91 SAMA5D2-Compatible shutdown controller driver" - depends on ARCH_AT91 || COMPILE_TEST + depends on ARCH_AT91 default SOC_SAMA5 help This driver supports the alternate shutdown controller for some Atmel diff --git a/drivers/power/reset/at91-poweroff.c b/drivers/power/reset/at91-poweroff.c index e9e24df35f26..2579f025b90b 100644 --- a/drivers/power/reset/at91-poweroff.c +++ b/drivers/power/reset/at91-poweroff.c @@ -14,9 +14,12 @@ #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <soc/at91/at91sam9_ddrsdr.h> + #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */ #define AT91_SHDW_SHDW BIT(0) /* Shut Down command */ #define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */ @@ -50,6 +53,7 @@ static const char *shdwc_wakeup_modes[] = { static void __iomem *at91_shdwc_base; static struct clk *sclk; +static void __iomem *mpddrc_base; static void __init at91_wakeup_status(void) { @@ -73,6 +77,29 @@ static void at91_poweroff(void) writel(AT91_SHDW_KEY | AT91_SHDW_SHDW, at91_shdwc_base + AT91_SHDW_CR); } +static void at91_lpddr_poweroff(void) +{ + asm volatile( + /* Align to cache lines */ + ".balign 32\n\t" + + /* Ensure AT91_SHDW_CR is in the TLB by reading it */ + " ldr r6, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + /* Power down SDRAM0 */ + " str %1, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t" + /* Shutdown CPU */ + " str %3, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + " b .\n\t" + : + : "r" (mpddrc_base), + "r" cpu_to_le32(AT91_DDRSDRC_LPDDR2_PWOFF), + "r" (at91_shdwc_base), + "r" cpu_to_le32(AT91_SHDW_KEY | AT91_SHDW_SHDW) + : "r0"); +} + static int at91_poweroff_get_wakeup_mode(struct device_node *np) { const char *pm; @@ -124,6 +151,8 @@ static void at91_poweroff_dt_set_wakeup_mode(struct platform_device *pdev) static int __init at91_poweroff_probe(struct platform_device *pdev) { struct resource *res; + struct device_node *np; + u32 ddr_type; int ret; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -150,12 +179,30 @@ static int __init at91_poweroff_probe(struct platform_device *pdev) pm_power_off = at91_poweroff; + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d3-ddramc"); + if (!np) + return 0; + + mpddrc_base = of_iomap(np, 0); + of_node_put(np); + + if (!mpddrc_base) + return 0; + + ddr_type = readl(mpddrc_base + AT91_DDRSDRC_MDR) & AT91_DDRSDRC_MD; + if ((ddr_type == AT91_DDRSDRC_MD_LPDDR2) || + (ddr_type == AT91_DDRSDRC_MD_LPDDR3)) + pm_power_off = at91_lpddr_poweroff; + else + iounmap(mpddrc_base); + return 0; } static int __exit at91_poweroff_remove(struct platform_device *pdev) { - if (pm_power_off == at91_poweroff) + if (pm_power_off == at91_poweroff || + pm_power_off == at91_lpddr_poweroff) pm_power_off = NULL; clk_disable_unprepare(sclk); @@ -163,6 +210,11 @@ static int __exit at91_poweroff_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id at91_ramc_of_match[] = { + { .compatible = "atmel,sama5d3-ddramc", }, + { /* sentinel */ } +}; + static const struct of_device_id at91_poweroff_of_match[] = { { .compatible = "atmel,at91sam9260-shdwc", }, { .compatible = "atmel,at91sam9rl-shdwc", }, diff --git a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c index 8a5ac9706c9c..90b0b5a70ce5 100644 --- a/drivers/power/reset/at91-sama5d2_shdwc.c +++ b/drivers/power/reset/at91-sama5d2_shdwc.c @@ -22,9 +22,12 @@ #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <soc/at91/at91sam9_ddrsdr.h> + #define SLOW_CLOCK_FREQ 32768 #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */ @@ -75,6 +78,7 @@ struct shdwc { */ static struct shdwc *at91_shdwc; static struct clk *sclk; +static void __iomem *mpddrc_base; static const unsigned long long sdwc_dbc_period[] = { 0, 3, 32, 512, 4096, 32768, @@ -108,6 +112,29 @@ static void at91_poweroff(void) at91_shdwc->at91_shdwc_base + AT91_SHDW_CR); } +static void at91_lpddr_poweroff(void) +{ + asm volatile( + /* Align to cache lines */ + ".balign 32\n\t" + + /* Ensure AT91_SHDW_CR is in the TLB by reading it */ + " ldr r6, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + /* Power down SDRAM0 */ + " str %1, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t" + /* Shutdown CPU */ + " str %3, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + " b .\n\t" + : + : "r" (mpddrc_base), + "r" cpu_to_le32(AT91_DDRSDRC_LPDDR2_PWOFF), + "r" (at91_shdwc->at91_shdwc_base), + "r" cpu_to_le32(AT91_SHDW_KEY | AT91_SHDW_SHDW) + : "r0"); +} + static u32 at91_shdwc_debouncer_value(struct platform_device *pdev, u32 in_period_us) { @@ -212,6 +239,8 @@ static int __init at91_shdwc_probe(struct platform_device *pdev) { struct resource *res; const struct of_device_id *match; + struct device_node *np; + u32 ddr_type; int ret; if (!pdev->dev.of_node) @@ -249,6 +278,23 @@ static int __init at91_shdwc_probe(struct platform_device *pdev) pm_power_off = at91_poweroff; + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d3-ddramc"); + if (!np) + return 0; + + mpddrc_base = of_iomap(np, 0); + of_node_put(np); + + if (!mpddrc_base) + return 0; + + ddr_type = readl(mpddrc_base + AT91_DDRSDRC_MDR) & AT91_DDRSDRC_MD; + if ((ddr_type == AT91_DDRSDRC_MD_LPDDR2) || + (ddr_type == AT91_DDRSDRC_MD_LPDDR3)) + pm_power_off = at91_lpddr_poweroff; + else + iounmap(mpddrc_base); + return 0; } @@ -256,7 +302,8 @@ static int __exit at91_shdwc_remove(struct platform_device *pdev) { struct shdwc *shdw = platform_get_drvdata(pdev); - if (pm_power_off == at91_poweroff) + if (pm_power_off == at91_poweroff || + pm_power_off == at91_lpddr_poweroff) pm_power_off = NULL; /* Reset values to disable wake-up features */ -- 2.9.3 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/2] power/reset: at91-poweroff: timely shutdown LPDDR memories @ 2016-10-25 9:37 ` Alexandre Belloni 0 siblings, 0 replies; 10+ messages in thread From: Alexandre Belloni @ 2016-10-25 9:37 UTC (permalink / raw) To: linux-arm-kernel LPDDR memories can only handle up to 400 uncontrolled power off. Ensure the proper power off sequence is used before shutting down the platform. Cc: <stable@vger.kernel.org> # 4.4+ Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> --- drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index c74c3f67b8da..02e46bbcf45d 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -32,7 +32,7 @@ config POWER_RESET_AT91_RESET config POWER_RESET_AT91_SAMA5D2_SHDWC tristate "Atmel AT91 SAMA5D2-Compatible shutdown controller driver" - depends on ARCH_AT91 || COMPILE_TEST + depends on ARCH_AT91 default SOC_SAMA5 help This driver supports the alternate shutdown controller for some Atmel diff --git a/drivers/power/reset/at91-poweroff.c b/drivers/power/reset/at91-poweroff.c index e9e24df35f26..2579f025b90b 100644 --- a/drivers/power/reset/at91-poweroff.c +++ b/drivers/power/reset/at91-poweroff.c @@ -14,9 +14,12 @@ #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <soc/at91/at91sam9_ddrsdr.h> + #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */ #define AT91_SHDW_SHDW BIT(0) /* Shut Down command */ #define AT91_SHDW_KEY (0xa5 << 24) /* KEY Password */ @@ -50,6 +53,7 @@ static const char *shdwc_wakeup_modes[] = { static void __iomem *at91_shdwc_base; static struct clk *sclk; +static void __iomem *mpddrc_base; static void __init at91_wakeup_status(void) { @@ -73,6 +77,29 @@ static void at91_poweroff(void) writel(AT91_SHDW_KEY | AT91_SHDW_SHDW, at91_shdwc_base + AT91_SHDW_CR); } +static void at91_lpddr_poweroff(void) +{ + asm volatile( + /* Align to cache lines */ + ".balign 32\n\t" + + /* Ensure AT91_SHDW_CR is in the TLB by reading it */ + " ldr r6, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + /* Power down SDRAM0 */ + " str %1, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t" + /* Shutdown CPU */ + " str %3, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + " b .\n\t" + : + : "r" (mpddrc_base), + "r" cpu_to_le32(AT91_DDRSDRC_LPDDR2_PWOFF), + "r" (at91_shdwc_base), + "r" cpu_to_le32(AT91_SHDW_KEY | AT91_SHDW_SHDW) + : "r0"); +} + static int at91_poweroff_get_wakeup_mode(struct device_node *np) { const char *pm; @@ -124,6 +151,8 @@ static void at91_poweroff_dt_set_wakeup_mode(struct platform_device *pdev) static int __init at91_poweroff_probe(struct platform_device *pdev) { struct resource *res; + struct device_node *np; + u32 ddr_type; int ret; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -150,12 +179,30 @@ static int __init at91_poweroff_probe(struct platform_device *pdev) pm_power_off = at91_poweroff; + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d3-ddramc"); + if (!np) + return 0; + + mpddrc_base = of_iomap(np, 0); + of_node_put(np); + + if (!mpddrc_base) + return 0; + + ddr_type = readl(mpddrc_base + AT91_DDRSDRC_MDR) & AT91_DDRSDRC_MD; + if ((ddr_type == AT91_DDRSDRC_MD_LPDDR2) || + (ddr_type == AT91_DDRSDRC_MD_LPDDR3)) + pm_power_off = at91_lpddr_poweroff; + else + iounmap(mpddrc_base); + return 0; } static int __exit at91_poweroff_remove(struct platform_device *pdev) { - if (pm_power_off == at91_poweroff) + if (pm_power_off == at91_poweroff || + pm_power_off == at91_lpddr_poweroff) pm_power_off = NULL; clk_disable_unprepare(sclk); @@ -163,6 +210,11 @@ static int __exit at91_poweroff_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id at91_ramc_of_match[] = { + { .compatible = "atmel,sama5d3-ddramc", }, + { /* sentinel */ } +}; + static const struct of_device_id at91_poweroff_of_match[] = { { .compatible = "atmel,at91sam9260-shdwc", }, { .compatible = "atmel,at91sam9rl-shdwc", }, diff --git a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c index 8a5ac9706c9c..90b0b5a70ce5 100644 --- a/drivers/power/reset/at91-sama5d2_shdwc.c +++ b/drivers/power/reset/at91-sama5d2_shdwc.c @@ -22,9 +22,12 @@ #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/printk.h> +#include <soc/at91/at91sam9_ddrsdr.h> + #define SLOW_CLOCK_FREQ 32768 #define AT91_SHDW_CR 0x00 /* Shut Down Control Register */ @@ -75,6 +78,7 @@ struct shdwc { */ static struct shdwc *at91_shdwc; static struct clk *sclk; +static void __iomem *mpddrc_base; static const unsigned long long sdwc_dbc_period[] = { 0, 3, 32, 512, 4096, 32768, @@ -108,6 +112,29 @@ static void at91_poweroff(void) at91_shdwc->at91_shdwc_base + AT91_SHDW_CR); } +static void at91_lpddr_poweroff(void) +{ + asm volatile( + /* Align to cache lines */ + ".balign 32\n\t" + + /* Ensure AT91_SHDW_CR is in the TLB by reading it */ + " ldr r6, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + /* Power down SDRAM0 */ + " str %1, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t" + /* Shutdown CPU */ + " str %3, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t" + + " b .\n\t" + : + : "r" (mpddrc_base), + "r" cpu_to_le32(AT91_DDRSDRC_LPDDR2_PWOFF), + "r" (at91_shdwc->at91_shdwc_base), + "r" cpu_to_le32(AT91_SHDW_KEY | AT91_SHDW_SHDW) + : "r0"); +} + static u32 at91_shdwc_debouncer_value(struct platform_device *pdev, u32 in_period_us) { @@ -212,6 +239,8 @@ static int __init at91_shdwc_probe(struct platform_device *pdev) { struct resource *res; const struct of_device_id *match; + struct device_node *np; + u32 ddr_type; int ret; if (!pdev->dev.of_node) @@ -249,6 +278,23 @@ static int __init at91_shdwc_probe(struct platform_device *pdev) pm_power_off = at91_poweroff; + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d3-ddramc"); + if (!np) + return 0; + + mpddrc_base = of_iomap(np, 0); + of_node_put(np); + + if (!mpddrc_base) + return 0; + + ddr_type = readl(mpddrc_base + AT91_DDRSDRC_MDR) & AT91_DDRSDRC_MD; + if ((ddr_type == AT91_DDRSDRC_MD_LPDDR2) || + (ddr_type == AT91_DDRSDRC_MD_LPDDR3)) + pm_power_off = at91_lpddr_poweroff; + else + iounmap(mpddrc_base); + return 0; } @@ -256,7 +302,8 @@ static int __exit at91_shdwc_remove(struct platform_device *pdev) { struct shdwc *shdw = platform_get_drvdata(pdev); - if (pm_power_off == at91_poweroff) + if (pm_power_off == at91_poweroff || + pm_power_off == at91_lpddr_poweroff) pm_power_off = NULL; /* Reset values to disable wake-up features */ -- 2.9.3 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff 2016-10-25 9:37 ` Alexandre Belloni (?) @ 2017-01-16 23:26 ` Sebastian Reichel -1 siblings, 0 replies; 10+ messages in thread From: Sebastian Reichel @ 2017-01-16 23:26 UTC (permalink / raw) To: Alexandre Belloni Cc: Dmitry Eremin-Solenikov, Nicolas Ferre, Jean-Jacques Hiblot, linux-pm, linux-kernel, linux-arm-kernel [-- Attachment #1: Type: text/plain, Size: 1972 bytes --] Hi Alexandre, On Tue, Oct 25, 2016 at 11:37:57AM +0200, Alexandre Belloni wrote: > This patch set improves LPDDR support on SoCs using the Atmel MPDDR controller. > > LPDDR memories can only handle up to 400 uncontrolled power offs in their > life. The proper power off sequence has to be applied before shutting down the > SoC. > > I'm not too happy with the code duplication but this is a design choice > that has been made before because both shutdown controllers are really > different apart from the shutdown itself. > > I guess it is still better than slowly killing the LPDDR. Sorry, I totally forgot about this one. I queued it into my for-next branch using an immutable topic branch, in case you need the patch against the arm include to also go through arm-soc. Feel free to use or ignore it: The following changes since commit 7ce7d89f48834cefece7804d38fc5d85382edf77: Linux 4.10-rc1 (2016-12-25 16:13:08 -0800) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git tags/ib-psy-arm-at91-4.11 for you to fetch changes up to 0b0408745e7ff24757cbfd571d69026c0ddb803c: power: reset: at91-poweroff: timely shutdown LPDDR memories (2017-01-16 23:21:33 +0100) ---------------------------------------------------------------- immutable branch between ARM at91 and power-supply for v4.11 ---------------------------------------------------------------- Alexandre Belloni (2): ARM: at91: define LPDDR types power: reset: at91-poweroff: timely shutdown LPDDR memories drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- include/soc/at91/at91sam9_ddrsdr.h | 3 +++ 4 files changed, 105 insertions(+), 3 deletions(-) -- Sebastian [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff @ 2017-01-16 23:26 ` Sebastian Reichel 0 siblings, 0 replies; 10+ messages in thread From: Sebastian Reichel @ 2017-01-16 23:26 UTC (permalink / raw) To: linux-arm-kernel Hi Alexandre, On Tue, Oct 25, 2016 at 11:37:57AM +0200, Alexandre Belloni wrote: > This patch set improves LPDDR support on SoCs using the Atmel MPDDR controller. > > LPDDR memories can only handle up to 400 uncontrolled power offs in their > life. The proper power off sequence has to be applied before shutting down the > SoC. > > I'm not too happy with the code duplication but this is a design choice > that has been made before because both shutdown controllers are really > different apart from the shutdown itself. > > I guess it is still better than slowly killing the LPDDR. Sorry, I totally forgot about this one. I queued it into my for-next branch using an immutable topic branch, in case you need the patch against the arm include to also go through arm-soc. Feel free to use or ignore it: The following changes since commit 7ce7d89f48834cefece7804d38fc5d85382edf77: Linux 4.10-rc1 (2016-12-25 16:13:08 -0800) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git tags/ib-psy-arm-at91-4.11 for you to fetch changes up to 0b0408745e7ff24757cbfd571d69026c0ddb803c: power: reset: at91-poweroff: timely shutdown LPDDR memories (2017-01-16 23:21:33 +0100) ---------------------------------------------------------------- immutable branch between ARM at91 and power-supply for v4.11 ---------------------------------------------------------------- Alexandre Belloni (2): ARM: at91: define LPDDR types power: reset: at91-poweroff: timely shutdown LPDDR memories drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- include/soc/at91/at91sam9_ddrsdr.h | 3 +++ 4 files changed, 105 insertions(+), 3 deletions(-) -- Sebastian -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170117/b06d0fb1/attachment.sig> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff @ 2017-01-16 23:26 ` Sebastian Reichel 0 siblings, 0 replies; 10+ messages in thread From: Sebastian Reichel @ 2017-01-16 23:26 UTC (permalink / raw) To: Alexandre Belloni Cc: Jean-Jacques Hiblot, linux-pm, Dmitry Eremin-Solenikov, Nicolas Ferre, linux-kernel, linux-arm-kernel [-- Attachment #1.1: Type: text/plain, Size: 1972 bytes --] Hi Alexandre, On Tue, Oct 25, 2016 at 11:37:57AM +0200, Alexandre Belloni wrote: > This patch set improves LPDDR support on SoCs using the Atmel MPDDR controller. > > LPDDR memories can only handle up to 400 uncontrolled power offs in their > life. The proper power off sequence has to be applied before shutting down the > SoC. > > I'm not too happy with the code duplication but this is a design choice > that has been made before because both shutdown controllers are really > different apart from the shutdown itself. > > I guess it is still better than slowly killing the LPDDR. Sorry, I totally forgot about this one. I queued it into my for-next branch using an immutable topic branch, in case you need the patch against the arm include to also go through arm-soc. Feel free to use or ignore it: The following changes since commit 7ce7d89f48834cefece7804d38fc5d85382edf77: Linux 4.10-rc1 (2016-12-25 16:13:08 -0800) are available in the git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git tags/ib-psy-arm-at91-4.11 for you to fetch changes up to 0b0408745e7ff24757cbfd571d69026c0ddb803c: power: reset: at91-poweroff: timely shutdown LPDDR memories (2017-01-16 23:21:33 +0100) ---------------------------------------------------------------- immutable branch between ARM at91 and power-supply for v4.11 ---------------------------------------------------------------- Alexandre Belloni (2): ARM: at91: define LPDDR types power: reset: at91-poweroff: timely shutdown LPDDR memories drivers/power/reset/Kconfig | 2 +- drivers/power/reset/at91-poweroff.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- drivers/power/reset/at91-sama5d2_shdwc.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- include/soc/at91/at91sam9_ddrsdr.h | 3 +++ 4 files changed, 105 insertions(+), 3 deletions(-) -- Sebastian [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] [-- Attachment #2: Type: text/plain, Size: 176 bytes --] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-01-16 23:27 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-10-25 9:37 [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff Alexandre Belloni 2016-10-25 9:37 ` Alexandre Belloni 2016-10-25 9:37 ` Alexandre Belloni 2016-10-25 9:37 ` [PATCH v3 1/2] ARM: at91: define LPDDR types Alexandre Belloni 2016-10-25 9:37 ` Alexandre Belloni 2016-10-25 9:37 ` [PATCH v3 2/2] power/reset: at91-poweroff: timely shutdown LPDDR memories Alexandre Belloni 2016-10-25 9:37 ` Alexandre Belloni 2017-01-16 23:26 ` [PATCH v3 0/2] ARM: at91: properly handle LPDDR poweroff Sebastian Reichel 2017-01-16 23:26 ` Sebastian Reichel 2017-01-16 23:26 ` Sebastian Reichel
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.