xref: /openbmc/linux/drivers/soc/atmel/soc.c (revision d4ac3791)
1cd9168b4SClaudiu Beznea // SPDX-License-Identifier: GPL-2.0-only
2b32de9ddSAlexandre Belloni /*
3b32de9ddSAlexandre Belloni  * Copyright (C) 2015 Atmel
4b32de9ddSAlexandre Belloni  *
5b32de9ddSAlexandre Belloni  * Alexandre Belloni <alexandre.belloni@free-electrons.com
6b32de9ddSAlexandre Belloni  * Boris Brezillon <boris.brezillon@free-electrons.com
7b32de9ddSAlexandre Belloni  */
8b32de9ddSAlexandre Belloni 
9b32de9ddSAlexandre Belloni #define pr_fmt(fmt)	"AT91: " fmt
10b32de9ddSAlexandre Belloni 
11b32de9ddSAlexandre Belloni #include <linux/io.h>
12b32de9ddSAlexandre Belloni #include <linux/of.h>
13b32de9ddSAlexandre Belloni #include <linux/of_address.h>
14b32de9ddSAlexandre Belloni #include <linux/of_platform.h>
15b32de9ddSAlexandre Belloni #include <linux/slab.h>
16b32de9ddSAlexandre Belloni #include <linux/sys_soc.h>
17b32de9ddSAlexandre Belloni 
18b32de9ddSAlexandre Belloni #include "soc.h"
19b32de9ddSAlexandre Belloni 
20b32de9ddSAlexandre Belloni #define AT91_DBGU_CIDR			0x40
21b32de9ddSAlexandre Belloni #define AT91_DBGU_EXID			0x44
22b32de9ddSAlexandre Belloni #define AT91_CHIPID_CIDR		0x00
23b32de9ddSAlexandre Belloni #define AT91_CHIPID_EXID		0x04
24af3a1051SClaudiu Beznea #define AT91_CIDR_VERSION(x, m)		((x) & (m))
25af3a1051SClaudiu Beznea #define AT91_CIDR_VERSION_MASK		GENMASK(4, 0)
26f12a29cbSClaudiu Beznea #define AT91_CIDR_VERSION_MASK_SAMA7G5	GENMASK(3, 0)
27b32de9ddSAlexandre Belloni #define AT91_CIDR_EXT			BIT(31)
288eb2f88cSClaudiu Beznea #define AT91_CIDR_MATCH_MASK		GENMASK(30, 5)
29f12a29cbSClaudiu Beznea #define AT91_CIDR_MASK_SAMA7G5		GENMASK(27, 5)
30b32de9ddSAlexandre Belloni 
3111272a37SClaudiu Beznea static const struct at91_soc socs[] __initconst = {
32b32de9ddSAlexandre Belloni #ifdef CONFIG_SOC_AT91RM9200
33af3a1051SClaudiu Beznea 	AT91_SOC(AT91RM9200_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
34af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91rm9200 BGA", "at91rm9200"),
35b32de9ddSAlexandre Belloni #endif
36b32de9ddSAlexandre Belloni #ifdef CONFIG_SOC_AT91SAM9
37af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9260_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
38af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9260", NULL),
39af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9261_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
40af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9261", NULL),
41af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9263_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
42af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9263", NULL),
43af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9G20_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
44af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9g20", NULL),
45af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9RL64_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
46af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9rl64", NULL),
47af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9G45_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
48af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9M11_EXID_MATCH,
49b32de9ddSAlexandre Belloni 		 "at91sam9m11", "at91sam9g45"),
50af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9G45_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
51af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9M10_EXID_MATCH,
52b32de9ddSAlexandre Belloni 		 "at91sam9m10", "at91sam9g45"),
53af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9G45_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
54af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9G46_EXID_MATCH,
55b32de9ddSAlexandre Belloni 		 "at91sam9g46", "at91sam9g45"),
56af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9G45_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
57af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9G45_EXID_MATCH,
58b32de9ddSAlexandre Belloni 		 "at91sam9g45", "at91sam9g45"),
59af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9X5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
60af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9G15_EXID_MATCH,
61b32de9ddSAlexandre Belloni 		 "at91sam9g15", "at91sam9x5"),
62af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9X5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
63af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9G35_EXID_MATCH,
64b32de9ddSAlexandre Belloni 		 "at91sam9g35", "at91sam9x5"),
65af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9X5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
66af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9X35_EXID_MATCH,
67b32de9ddSAlexandre Belloni 		 "at91sam9x35", "at91sam9x5"),
68af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9X5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
69af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9G25_EXID_MATCH,
70b32de9ddSAlexandre Belloni 		 "at91sam9g25", "at91sam9x5"),
71af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9X5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
72af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9X25_EXID_MATCH,
73b32de9ddSAlexandre Belloni 		 "at91sam9x25", "at91sam9x5"),
74af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9N12_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
75af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9CN12_EXID_MATCH,
76b32de9ddSAlexandre Belloni 		 "at91sam9cn12", "at91sam9n12"),
77af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9N12_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
78af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9N12_EXID_MATCH,
79b32de9ddSAlexandre Belloni 		 "at91sam9n12", "at91sam9n12"),
80af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9N12_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
81af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, AT91SAM9CN11_EXID_MATCH,
82b32de9ddSAlexandre Belloni 		 "at91sam9cn11", "at91sam9n12"),
83af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9XE128_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
84af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9xe128", "at91sam9xe128"),
85af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9XE256_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
86af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9xe256", "at91sam9xe256"),
87af3a1051SClaudiu Beznea 	AT91_SOC(AT91SAM9XE512_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
88af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, 0, "at91sam9xe512", "at91sam9xe512"),
89dccf7229SClaudiu Beznea #endif
90dccf7229SClaudiu Beznea #ifdef CONFIG_SOC_SAM9X60
91af3a1051SClaudiu Beznea 	AT91_SOC(SAM9X60_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
92af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAM9X60_EXID_MATCH,
93af3a1051SClaudiu Beznea 		 "sam9x60", "sam9x60"),
9435074df6SMihai Sain 	AT91_SOC(SAM9X60_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
9535074df6SMihai Sain 		 AT91_CIDR_VERSION_MASK, SAM9X60_D5M_EXID_MATCH,
96786c395dSKai Stuhlemmer 		 "sam9x60 64MiB DDR2 SiP", "sam9x60"),
9735074df6SMihai Sain 	AT91_SOC(SAM9X60_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
9835074df6SMihai Sain 		 AT91_CIDR_VERSION_MASK, SAM9X60_D1G_EXID_MATCH,
99786c395dSKai Stuhlemmer 		 "sam9x60 128MiB DDR2 SiP", "sam9x60"),
10035074df6SMihai Sain 	AT91_SOC(SAM9X60_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
10135074df6SMihai Sain 		 AT91_CIDR_VERSION_MASK, SAM9X60_D6K_EXID_MATCH,
102786c395dSKai Stuhlemmer 		 "sam9x60 8MiB SDRAM SiP", "sam9x60"),
103b32de9ddSAlexandre Belloni #endif
104b32de9ddSAlexandre Belloni #ifdef CONFIG_SOC_SAMA5
105af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
106af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D21CU_EXID_MATCH,
107b32de9ddSAlexandre Belloni 		 "sama5d21", "sama5d2"),
108af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
109af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D22CU_EXID_MATCH,
110b32de9ddSAlexandre Belloni 		 "sama5d22", "sama5d2"),
111af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
112af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D225C_D1M_EXID_MATCH,
113cd2e9be8SCristian Birsan 		 "sama5d225c 16MiB SiP", "sama5d2"),
114af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
115af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D23CU_EXID_MATCH,
116b32de9ddSAlexandre Belloni 		 "sama5d23", "sama5d2"),
117af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
118af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D24CX_EXID_MATCH,
119b32de9ddSAlexandre Belloni 		 "sama5d24", "sama5d2"),
120af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
121af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D24CU_EXID_MATCH,
122b32de9ddSAlexandre Belloni 		 "sama5d24", "sama5d2"),
123af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
124af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D26CU_EXID_MATCH,
125b32de9ddSAlexandre Belloni 		 "sama5d26", "sama5d2"),
126af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
127af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D27CU_EXID_MATCH,
128b32de9ddSAlexandre Belloni 		 "sama5d27", "sama5d2"),
129af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
130af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D27CN_EXID_MATCH,
131b32de9ddSAlexandre Belloni 		 "sama5d27", "sama5d2"),
132af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
133af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D27C_D1G_EXID_MATCH,
134cd2e9be8SCristian Birsan 		 "sama5d27c 128MiB SiP", "sama5d2"),
135af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
136af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D27C_D5M_EXID_MATCH,
137cd2e9be8SCristian Birsan 		 "sama5d27c 64MiB SiP", "sama5d2"),
138af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
139af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D27C_LD1G_EXID_MATCH,
14015653dc8SNicolas Ferre 		 "sama5d27c 128MiB LPDDR2 SiP", "sama5d2"),
141af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
142af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D27C_LD2G_EXID_MATCH,
14315653dc8SNicolas Ferre 		 "sama5d27c 256MiB LPDDR2 SiP", "sama5d2"),
144af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
145af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D28CU_EXID_MATCH,
146b32de9ddSAlexandre Belloni 		 "sama5d28", "sama5d2"),
147af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
148af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D28CN_EXID_MATCH,
149b32de9ddSAlexandre Belloni 		 "sama5d28", "sama5d2"),
150af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
151af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D28C_D1G_EXID_MATCH,
152cd2e9be8SCristian Birsan 		 "sama5d28c 128MiB SiP", "sama5d2"),
153af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
154af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D28C_LD1G_EXID_MATCH,
15515653dc8SNicolas Ferre 		 "sama5d28c 128MiB LPDDR2 SiP", "sama5d2"),
156af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
157af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D28C_LD2G_EXID_MATCH,
15815653dc8SNicolas Ferre 		 "sama5d28c 256MiB LPDDR2 SiP", "sama5d2"),
159def8abbbSMihai Sain 	AT91_SOC(SAMA5D2_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
160def8abbbSMihai Sain 		 AT91_CIDR_VERSION_MASK, SAMA5D29CN_EXID_MATCH,
161def8abbbSMihai Sain 		 "sama5d29", "sama5d2"),
162af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D3_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
163af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D31_EXID_MATCH,
164b32de9ddSAlexandre Belloni 		 "sama5d31", "sama5d3"),
165af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D3_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
166af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D33_EXID_MATCH,
167b32de9ddSAlexandre Belloni 		 "sama5d33", "sama5d3"),
168af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D3_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
169af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D34_EXID_MATCH,
170b32de9ddSAlexandre Belloni 		 "sama5d34", "sama5d3"),
171af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D3_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
172af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D35_EXID_MATCH,
173b32de9ddSAlexandre Belloni 		 "sama5d35", "sama5d3"),
174af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D3_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
175af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D36_EXID_MATCH,
176b32de9ddSAlexandre Belloni 		 "sama5d36", "sama5d3"),
177af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D4_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
178af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D41_EXID_MATCH,
179b32de9ddSAlexandre Belloni 		 "sama5d41", "sama5d4"),
180af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D4_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
181af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D42_EXID_MATCH,
182b32de9ddSAlexandre Belloni 		 "sama5d42", "sama5d4"),
183af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D4_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
184af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D43_EXID_MATCH,
185b32de9ddSAlexandre Belloni 		 "sama5d43", "sama5d4"),
186af3a1051SClaudiu Beznea 	AT91_SOC(SAMA5D4_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
187af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMA5D44_EXID_MATCH,
188b32de9ddSAlexandre Belloni 		 "sama5d44", "sama5d4"),
189b32de9ddSAlexandre Belloni #endif
19082208e75SSzemző András #ifdef CONFIG_SOC_SAMV7
191af3a1051SClaudiu Beznea 	AT91_SOC(SAME70Q21_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
192af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAME70Q21_EXID_MATCH,
19382208e75SSzemző András 		 "same70q21", "same7"),
194af3a1051SClaudiu Beznea 	AT91_SOC(SAME70Q20_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
195af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAME70Q20_EXID_MATCH,
19682208e75SSzemző András 		 "same70q20", "same7"),
1977deff441SArnd Bergmann 	AT91_SOC(SAME70Q19_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
198af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAME70Q19_EXID_MATCH,
19982208e75SSzemző András 		 "same70q19", "same7"),
200af3a1051SClaudiu Beznea 	AT91_SOC(SAMS70Q21_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
201af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMS70Q21_EXID_MATCH,
20282208e75SSzemző András 		 "sams70q21", "sams7"),
203af3a1051SClaudiu Beznea 	AT91_SOC(SAMS70Q20_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
204af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMS70Q20_EXID_MATCH,
20582208e75SSzemző András 		 "sams70q20", "sams7"),
206af3a1051SClaudiu Beznea 	AT91_SOC(SAMS70Q19_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
207af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMS70Q19_EXID_MATCH,
20882208e75SSzemző András 		 "sams70q19", "sams7"),
209af3a1051SClaudiu Beznea 	AT91_SOC(SAMV71Q21_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
210af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMV71Q21_EXID_MATCH,
21182208e75SSzemző András 		 "samv71q21", "samv7"),
212af3a1051SClaudiu Beznea 	AT91_SOC(SAMV71Q20_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
213af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMV71Q20_EXID_MATCH,
21482208e75SSzemző András 		 "samv71q20", "samv7"),
215af3a1051SClaudiu Beznea 	AT91_SOC(SAMV71Q19_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
216af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMV71Q19_EXID_MATCH,
21782208e75SSzemző András 		 "samv71q19", "samv7"),
218af3a1051SClaudiu Beznea 	AT91_SOC(SAMV70Q20_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
219af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMV70Q20_EXID_MATCH,
22082208e75SSzemző András 		 "samv70q20", "samv7"),
221af3a1051SClaudiu Beznea 	AT91_SOC(SAMV70Q19_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
222af3a1051SClaudiu Beznea 		 AT91_CIDR_VERSION_MASK, SAMV70Q19_EXID_MATCH,
22382208e75SSzemző András 		 "samv70q19", "samv7"),
22482208e75SSzemző András #endif
225f12a29cbSClaudiu Beznea #ifdef CONFIG_SOC_SAMA7
226f12a29cbSClaudiu Beznea 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
227f12a29cbSClaudiu Beznea 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G51_EXID_MATCH,
228f12a29cbSClaudiu Beznea 		 "sama7g51", "sama7g5"),
229f12a29cbSClaudiu Beznea 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
230f12a29cbSClaudiu Beznea 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G52_EXID_MATCH,
231f12a29cbSClaudiu Beznea 		 "sama7g52", "sama7g5"),
232f12a29cbSClaudiu Beznea 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
233f12a29cbSClaudiu Beznea 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G53_EXID_MATCH,
234f12a29cbSClaudiu Beznea 		 "sama7g53", "sama7g5"),
235f12a29cbSClaudiu Beznea 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
236f12a29cbSClaudiu Beznea 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G54_EXID_MATCH,
237f12a29cbSClaudiu Beznea 		 "sama7g54", "sama7g5"),
238*d4ac3791SMihai Sain 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
239*d4ac3791SMihai Sain 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G54_D1G_EXID_MATCH,
240*d4ac3791SMihai Sain 		 "SAMA7G54 1Gb DDR3L SiP", "sama7g5"),
241*d4ac3791SMihai Sain 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
242*d4ac3791SMihai Sain 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G54_D2G_EXID_MATCH,
243*d4ac3791SMihai Sain 		 "SAMA7G54 2Gb DDR3L SiP", "sama7g5"),
244*d4ac3791SMihai Sain 	AT91_SOC(SAMA7G5_CIDR_MATCH, AT91_CIDR_MATCH_MASK,
245*d4ac3791SMihai Sain 		 AT91_CIDR_VERSION_MASK_SAMA7G5, SAMA7G54_D4G_EXID_MATCH,
246*d4ac3791SMihai Sain 		 "SAMA7G54 4Gb DDR3L SiP", "sama7g5"),
247f12a29cbSClaudiu Beznea #endif
248b32de9ddSAlexandre Belloni 	{ /* sentinel */ },
249b32de9ddSAlexandre Belloni };
250b32de9ddSAlexandre Belloni 
at91_get_cidr_exid_from_dbgu(u32 * cidr,u32 * exid)251b32de9ddSAlexandre Belloni static int __init at91_get_cidr_exid_from_dbgu(u32 *cidr, u32 *exid)
252b32de9ddSAlexandre Belloni {
253b32de9ddSAlexandre Belloni 	struct device_node *np;
254b32de9ddSAlexandre Belloni 	void __iomem *regs;
255b32de9ddSAlexandre Belloni 
256b32de9ddSAlexandre Belloni 	np = of_find_compatible_node(NULL, NULL, "atmel,at91rm9200-dbgu");
257b32de9ddSAlexandre Belloni 	if (!np)
258b32de9ddSAlexandre Belloni 		np = of_find_compatible_node(NULL, NULL,
259b32de9ddSAlexandre Belloni 					     "atmel,at91sam9260-dbgu");
260b32de9ddSAlexandre Belloni 	if (!np)
261b32de9ddSAlexandre Belloni 		return -ENODEV;
262b32de9ddSAlexandre Belloni 
263b32de9ddSAlexandre Belloni 	regs = of_iomap(np, 0);
264b32de9ddSAlexandre Belloni 	of_node_put(np);
265b32de9ddSAlexandre Belloni 
266b32de9ddSAlexandre Belloni 	if (!regs) {
267b32de9ddSAlexandre Belloni 		pr_warn("Could not map DBGU iomem range");
268b32de9ddSAlexandre Belloni 		return -ENXIO;
269b32de9ddSAlexandre Belloni 	}
270b32de9ddSAlexandre Belloni 
271b32de9ddSAlexandre Belloni 	*cidr = readl(regs + AT91_DBGU_CIDR);
272b32de9ddSAlexandre Belloni 	*exid = readl(regs + AT91_DBGU_EXID);
273b32de9ddSAlexandre Belloni 
274b32de9ddSAlexandre Belloni 	iounmap(regs);
275b32de9ddSAlexandre Belloni 
276b32de9ddSAlexandre Belloni 	return 0;
277b32de9ddSAlexandre Belloni }
278b32de9ddSAlexandre Belloni 
at91_get_cidr_exid_from_chipid(u32 * cidr,u32 * exid)279b32de9ddSAlexandre Belloni static int __init at91_get_cidr_exid_from_chipid(u32 *cidr, u32 *exid)
280b32de9ddSAlexandre Belloni {
281b32de9ddSAlexandre Belloni 	struct device_node *np;
282b32de9ddSAlexandre Belloni 	void __iomem *regs;
283af3a1051SClaudiu Beznea 	static const struct of_device_id chipids[] = {
284af3a1051SClaudiu Beznea 		{ .compatible = "atmel,sama5d2-chipid" },
285f12a29cbSClaudiu Beznea 		{ .compatible = "microchip,sama7g5-chipid" },
286af3a1051SClaudiu Beznea 		{ },
287af3a1051SClaudiu Beznea 	};
288b32de9ddSAlexandre Belloni 
289af3a1051SClaudiu Beznea 	np = of_find_matching_node(NULL, chipids);
290b32de9ddSAlexandre Belloni 	if (!np)
291b32de9ddSAlexandre Belloni 		return -ENODEV;
292b32de9ddSAlexandre Belloni 
293b32de9ddSAlexandre Belloni 	regs = of_iomap(np, 0);
294b32de9ddSAlexandre Belloni 	of_node_put(np);
295b32de9ddSAlexandre Belloni 
296b32de9ddSAlexandre Belloni 	if (!regs) {
297b32de9ddSAlexandre Belloni 		pr_warn("Could not map DBGU iomem range");
298b32de9ddSAlexandre Belloni 		return -ENXIO;
299b32de9ddSAlexandre Belloni 	}
300b32de9ddSAlexandre Belloni 
301b32de9ddSAlexandre Belloni 	*cidr = readl(regs + AT91_CHIPID_CIDR);
302b32de9ddSAlexandre Belloni 	*exid = readl(regs + AT91_CHIPID_EXID);
303b32de9ddSAlexandre Belloni 
304b32de9ddSAlexandre Belloni 	iounmap(regs);
305b32de9ddSAlexandre Belloni 
306b32de9ddSAlexandre Belloni 	return 0;
307b32de9ddSAlexandre Belloni }
308b32de9ddSAlexandre Belloni 
at91_soc_init(const struct at91_soc * socs)309b32de9ddSAlexandre Belloni struct soc_device * __init at91_soc_init(const struct at91_soc *socs)
310b32de9ddSAlexandre Belloni {
311b32de9ddSAlexandre Belloni 	struct soc_device_attribute *soc_dev_attr;
312b32de9ddSAlexandre Belloni 	const struct at91_soc *soc;
313b32de9ddSAlexandre Belloni 	struct soc_device *soc_dev;
314b32de9ddSAlexandre Belloni 	u32 cidr, exid;
315b32de9ddSAlexandre Belloni 	int ret;
316b32de9ddSAlexandre Belloni 
317b32de9ddSAlexandre Belloni 	/*
318b32de9ddSAlexandre Belloni 	 * With SAMA5D2 and later SoCs, CIDR and EXID registers are no more
319b32de9ddSAlexandre Belloni 	 * in the dbgu device but in the chipid device whose purpose is only
320b32de9ddSAlexandre Belloni 	 * to expose these two registers.
321b32de9ddSAlexandre Belloni 	 */
322b32de9ddSAlexandre Belloni 	ret = at91_get_cidr_exid_from_dbgu(&cidr, &exid);
323b32de9ddSAlexandre Belloni 	if (ret)
324b32de9ddSAlexandre Belloni 		ret = at91_get_cidr_exid_from_chipid(&cidr, &exid);
325b32de9ddSAlexandre Belloni 	if (ret) {
326b32de9ddSAlexandre Belloni 		if (ret == -ENODEV)
327b32de9ddSAlexandre Belloni 			pr_warn("Could not find identification node");
328b32de9ddSAlexandre Belloni 		return NULL;
329b32de9ddSAlexandre Belloni 	}
330b32de9ddSAlexandre Belloni 
331b32de9ddSAlexandre Belloni 	for (soc = socs; soc->name; soc++) {
332af3a1051SClaudiu Beznea 		if (soc->cidr_match != (cidr & soc->cidr_mask))
333b32de9ddSAlexandre Belloni 			continue;
334b32de9ddSAlexandre Belloni 
335b32de9ddSAlexandre Belloni 		if (!(cidr & AT91_CIDR_EXT) || soc->exid_match == exid)
336b32de9ddSAlexandre Belloni 			break;
337b32de9ddSAlexandre Belloni 	}
338b32de9ddSAlexandre Belloni 
339b32de9ddSAlexandre Belloni 	if (!soc->name) {
340b32de9ddSAlexandre Belloni 		pr_warn("Could not find matching SoC description\n");
341b32de9ddSAlexandre Belloni 		return NULL;
342b32de9ddSAlexandre Belloni 	}
343b32de9ddSAlexandre Belloni 
344b32de9ddSAlexandre Belloni 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
345b32de9ddSAlexandre Belloni 	if (!soc_dev_attr)
346b32de9ddSAlexandre Belloni 		return NULL;
347b32de9ddSAlexandre Belloni 
348b32de9ddSAlexandre Belloni 	soc_dev_attr->family = soc->family;
349b32de9ddSAlexandre Belloni 	soc_dev_attr->soc_id = soc->name;
350b32de9ddSAlexandre Belloni 	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%X",
351af3a1051SClaudiu Beznea 					   AT91_CIDR_VERSION(cidr, soc->version_mask));
352b32de9ddSAlexandre Belloni 	soc_dev = soc_device_register(soc_dev_attr);
353b32de9ddSAlexandre Belloni 	if (IS_ERR(soc_dev)) {
354b32de9ddSAlexandre Belloni 		kfree(soc_dev_attr->revision);
355b32de9ddSAlexandre Belloni 		kfree(soc_dev_attr);
356b32de9ddSAlexandre Belloni 		pr_warn("Could not register SoC device\n");
357b32de9ddSAlexandre Belloni 		return NULL;
358b32de9ddSAlexandre Belloni 	}
359b32de9ddSAlexandre Belloni 
360b32de9ddSAlexandre Belloni 	if (soc->family)
361b32de9ddSAlexandre Belloni 		pr_info("Detected SoC family: %s\n", soc->family);
362b32de9ddSAlexandre Belloni 	pr_info("Detected SoC: %s, revision %X\n", soc->name,
363af3a1051SClaudiu Beznea 		AT91_CIDR_VERSION(cidr, soc->version_mask));
364b32de9ddSAlexandre Belloni 
365b32de9ddSAlexandre Belloni 	return soc_dev;
366b32de9ddSAlexandre Belloni }
367b32de9ddSAlexandre Belloni 
368960ddf70SSudeep Holla static const struct of_device_id at91_soc_allowed_list[] __initconst = {
369960ddf70SSudeep Holla 	{ .compatible = "atmel,at91rm9200", },
370960ddf70SSudeep Holla 	{ .compatible = "atmel,at91sam9", },
371960ddf70SSudeep Holla 	{ .compatible = "atmel,sama5", },
37297543513SClaudiu Beznea 	{ .compatible = "atmel,samv7", },
373f12a29cbSClaudiu Beznea 	{ .compatible = "microchip,sama7g5", },
37497543513SClaudiu Beznea 	{ }
375960ddf70SSudeep Holla };
376960ddf70SSudeep Holla 
atmel_soc_device_init(void)377b32de9ddSAlexandre Belloni static int __init atmel_soc_device_init(void)
378b32de9ddSAlexandre Belloni {
379960ddf70SSudeep Holla 	struct device_node *np = of_find_node_by_path("/");
380960ddf70SSudeep Holla 
381960ddf70SSudeep Holla 	if (!of_match_node(at91_soc_allowed_list, np))
382960ddf70SSudeep Holla 		return 0;
383960ddf70SSudeep Holla 
384b32de9ddSAlexandre Belloni 	at91_soc_init(socs);
385b32de9ddSAlexandre Belloni 
386b32de9ddSAlexandre Belloni 	return 0;
387b32de9ddSAlexandre Belloni }
388b32de9ddSAlexandre Belloni subsys_initcall(atmel_soc_device_init);
389