at91: add kernel support for sama7g5 soc
[openwrt/openwrt.git] / target / linux / at91 / patches-5.10 / 145-power-reset-at91-sama5d2_shdwc-add-support-for-sama7.patch
1 From f39f2312a68ec0843adba08f9c9182ffa5624190 Mon Sep 17 00:00:00 2001
2 From: Claudiu Beznea <claudiu.beznea@microchip.com>
3 Date: Wed, 16 Dec 2020 14:57:33 +0200
4 Subject: [PATCH 145/247] power: reset: at91-sama5d2_shdwc: add support for
5 sama7g5
6
7 Add support for SAMA7G5 by adding proper struct reg_config structure
8 and since SAMA7G5 is not currently on LPDDR setups the commit also
9 avoid the mapping of DDR controller.
10
11 Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
12 Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
13 ---
14 drivers/power/reset/at91-sama5d2_shdwc.c | 72 ++++++++++++++++++------
15 1 file changed, 54 insertions(+), 18 deletions(-)
16
17 diff --git a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c
18 index d9cf91e5b06d..125e592af445 100644
19 --- a/drivers/power/reset/at91-sama5d2_shdwc.c
20 +++ b/drivers/power/reset/at91-sama5d2_shdwc.c
21 @@ -78,9 +78,15 @@ struct pmc_reg_config {
22 u8 mckr;
23 };
24
25 +struct ddrc_reg_config {
26 + u32 type_offset;
27 + u32 type_mask;
28 +};
29 +
30 struct reg_config {
31 struct shdwc_reg_config shdwc;
32 struct pmc_reg_config pmc;
33 + struct ddrc_reg_config ddrc;
34 };
35
36 struct shdwc {
37 @@ -262,6 +268,10 @@ static const struct reg_config sama5d2_reg_config = {
38 .pmc = {
39 .mckr = 0x30,
40 },
41 + .ddrc = {
42 + .type_offset = AT91_DDRSDRC_MDR,
43 + .type_mask = AT91_DDRSDRC_MD
44 + },
45 };
46
47 static const struct reg_config sam9x60_reg_config = {
48 @@ -275,6 +285,23 @@ static const struct reg_config sam9x60_reg_config = {
49 .pmc = {
50 .mckr = 0x28,
51 },
52 + .ddrc = {
53 + .type_offset = AT91_DDRSDRC_MDR,
54 + .type_mask = AT91_DDRSDRC_MD
55 + },
56 +};
57 +
58 +static const struct reg_config sama7g5_reg_config = {
59 + .shdwc = {
60 + .wkup_pin_input = 0,
61 + .mr_rtcwk_shift = 17,
62 + .mr_rttwk_shift = 16,
63 + .sr_rtcwk_shift = 5,
64 + .sr_rttwk_shift = 4,
65 + },
66 + .pmc = {
67 + .mckr = 0x28,
68 + },
69 };
70
71 static const struct of_device_id at91_shdwc_of_match[] = {
72 @@ -285,6 +312,10 @@ static const struct of_device_id at91_shdwc_of_match[] = {
73 {
74 .compatible = "microchip,sam9x60-shdwc",
75 .data = &sam9x60_reg_config,
76 + },
77 + {
78 + .compatible = "microchip,sama7g5-shdwc",
79 + .data = &sama7g5_reg_config,
80 }, {
81 /*sentinel*/
82 }
83 @@ -294,6 +325,7 @@ MODULE_DEVICE_TABLE(of, at91_shdwc_of_match);
84 static const struct of_device_id at91_pmc_ids[] = {
85 { .compatible = "atmel,sama5d2-pmc" },
86 { .compatible = "microchip,sam9x60-pmc" },
87 + { .compatible = "microchip,sama7g5-pmc" },
88 { /* Sentinel. */ }
89 };
90
91 @@ -355,30 +387,34 @@ static int __init at91_shdwc_probe(struct platform_device *pdev)
92 goto clk_disable;
93 }
94
95 - np = of_find_compatible_node(NULL, NULL, "atmel,sama5d3-ddramc");
96 - if (!np) {
97 - ret = -ENODEV;
98 - goto unmap;
99 - }
100 + if (at91_shdwc->rcfg->ddrc.type_mask) {
101 + np = of_find_compatible_node(NULL, NULL,
102 + "atmel,sama5d3-ddramc");
103 + if (!np) {
104 + ret = -ENODEV;
105 + goto unmap;
106 + }
107
108 - at91_shdwc->mpddrc_base = of_iomap(np, 0);
109 - of_node_put(np);
110 + at91_shdwc->mpddrc_base = of_iomap(np, 0);
111 + of_node_put(np);
112
113 - if (!at91_shdwc->mpddrc_base) {
114 - ret = -ENOMEM;
115 - goto unmap;
116 + if (!at91_shdwc->mpddrc_base) {
117 + ret = -ENOMEM;
118 + goto unmap;
119 + }
120 +
121 + ddr_type = readl(at91_shdwc->mpddrc_base +
122 + at91_shdwc->rcfg->ddrc.type_offset) &
123 + at91_shdwc->rcfg->ddrc.type_mask;
124 + if (ddr_type != AT91_DDRSDRC_MD_LPDDR2 &&
125 + ddr_type != AT91_DDRSDRC_MD_LPDDR3) {
126 + iounmap(at91_shdwc->mpddrc_base);
127 + at91_shdwc->mpddrc_base = NULL;
128 + }
129 }
130
131 pm_power_off = at91_poweroff;
132
133 - ddr_type = readl(at91_shdwc->mpddrc_base + AT91_DDRSDRC_MDR) &
134 - AT91_DDRSDRC_MD;
135 - if (ddr_type != AT91_DDRSDRC_MD_LPDDR2 &&
136 - ddr_type != AT91_DDRSDRC_MD_LPDDR3) {
137 - iounmap(at91_shdwc->mpddrc_base);
138 - at91_shdwc->mpddrc_base = NULL;
139 - }
140 -
141 return 0;
142
143 unmap:
144 --
145 2.32.0
146