2f8dcf62174e09478255f62ce61c4790ad60f582
[openwrt/staging/jow.git] / target / linux / at91 / patches-5.10 / 235-clk-at91-pmc-execute-suspend-resume-only-for-backup-.patch
1 From 63a0c32028148e91ea91cfbf95841c4ecd69d21b Mon Sep 17 00:00:00 2001
2 From: Claudiu Beznea <claudiu.beznea@microchip.com>
3 Date: Mon, 11 Oct 2021 14:27:06 +0300
4 Subject: [PATCH 235/247] clk: at91: pmc: execute suspend/resume only for
5 backup mode
6
7 Before going to backup mode architecture specific PM code sets the first
8 word in securam (file arch/arm/mach-at91/pm.c, function at91_pm_begin()).
9 Thus take this into account when suspending/resuming clocks. This will
10 avoid executing unnecessary instructions when suspending to non backup
11 modes.
12
13 Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
14 Link: https://lore.kernel.org/r/20211011112719.3951784-3-claudiu.beznea@microchip.com
15 Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
16 Signed-off-by: Stephen Boyd <sboyd@kernel.org>
17 ---
18 drivers/clk/at91/pmc.c | 39 +++++++++++++++++++++++++++++++++++++++
19 1 file changed, 39 insertions(+)
20
21 diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c
22 index b2806946a77a..517973062719 100644
23 --- a/drivers/clk/at91/pmc.c
24 +++ b/drivers/clk/at91/pmc.c
25 @@ -8,6 +8,7 @@
26 #include <linux/clkdev.h>
27 #include <linux/clk/at91_pmc.h>
28 #include <linux/of.h>
29 +#include <linux/of_address.h>
30 #include <linux/mfd/syscon.h>
31 #include <linux/platform_device.h>
32 #include <linux/regmap.h>
33 @@ -110,13 +111,35 @@ struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
34 }
35
36 #ifdef CONFIG_PM
37 +
38 +/* Address in SECURAM that say if we suspend to backup mode. */
39 +static void __iomem *at91_pmc_backup_suspend;
40 +
41 static int at91_pmc_suspend(void)
42 {
43 + unsigned int backup;
44 +
45 + if (!at91_pmc_backup_suspend)
46 + return 0;
47 +
48 + backup = readl_relaxed(at91_pmc_backup_suspend);
49 + if (!backup)
50 + return 0;
51 +
52 return clk_save_context();
53 }
54
55 static void at91_pmc_resume(void)
56 {
57 + unsigned int backup;
58 +
59 + if (!at91_pmc_backup_suspend)
60 + return;
61 +
62 + backup = readl_relaxed(at91_pmc_backup_suspend);
63 + if (!backup)
64 + return;
65 +
66 clk_restore_context();
67 }
68
69 @@ -144,6 +167,22 @@ static int __init pmc_register_ops(void)
70 }
71 of_node_put(np);
72
73 + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
74 + if (!np)
75 + return -ENODEV;
76 +
77 + if (!of_device_is_available(np)) {
78 + of_node_put(np);
79 + return -ENODEV;
80 + }
81 + of_node_put(np);
82 +
83 + at91_pmc_backup_suspend = of_iomap(np, 0);
84 + if (!at91_pmc_backup_suspend) {
85 + pr_warn("%s(): unable to map securam\n", __func__);
86 + return -ENOMEM;
87 + }
88 +
89 register_syscore_ops(&pmc_syscore_ops);
90
91 return 0;
92 --
93 2.32.0
94