kernel/at91: Restore kernel files for v5.15
[openwrt/openwrt.git] / target / linux / at91 / patches-5.15 / 101-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 --- a/drivers/clk/at91/pmc.c
22 +++ b/drivers/clk/at91/pmc.c
23 @@ -8,6 +8,7 @@
24 #include <linux/clkdev.h>
25 #include <linux/clk/at91_pmc.h>
26 #include <linux/of.h>
27 +#include <linux/of_address.h>
28 #include <linux/mfd/syscon.h>
29 #include <linux/platform_device.h>
30 #include <linux/regmap.h>
31 @@ -110,13 +111,35 @@ struct pmc_data *pmc_data_allocate(unsig
32 }
33
34 #ifdef CONFIG_PM
35 +
36 +/* Address in SECURAM that say if we suspend to backup mode. */
37 +static void __iomem *at91_pmc_backup_suspend;
38 +
39 static int at91_pmc_suspend(void)
40 {
41 + unsigned int backup;
42 +
43 + if (!at91_pmc_backup_suspend)
44 + return 0;
45 +
46 + backup = readl_relaxed(at91_pmc_backup_suspend);
47 + if (!backup)
48 + return 0;
49 +
50 return clk_save_context();
51 }
52
53 static void at91_pmc_resume(void)
54 {
55 + unsigned int backup;
56 +
57 + if (!at91_pmc_backup_suspend)
58 + return;
59 +
60 + backup = readl_relaxed(at91_pmc_backup_suspend);
61 + if (!backup)
62 + return;
63 +
64 clk_restore_context();
65 }
66
67 @@ -144,6 +167,22 @@ static int __init pmc_register_ops(void)
68 }
69 of_node_put(np);
70
71 + np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-securam");
72 + if (!np)
73 + return -ENODEV;
74 +
75 + if (!of_device_is_available(np)) {
76 + of_node_put(np);
77 + return -ENODEV;
78 + }
79 + of_node_put(np);
80 +
81 + at91_pmc_backup_suspend = of_iomap(np, 0);
82 + if (!at91_pmc_backup_suspend) {
83 + pr_warn("%s(): unable to map securam\n", __func__);
84 + return -ENOMEM;
85 + }
86 +
87 register_syscore_ops(&pmc_syscore_ops);
88
89 return 0;