renesas-soc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Renesas SoC Identification
  4. *
  5. * Copyright (C) 2014-2016 Glider bvba
  6. */
  7. #include <linux/io.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/slab.h>
  11. #include <linux/string.h>
  12. #include <linux/sys_soc.h>
  13. struct renesas_family {
  14. const char name[16];
  15. u32 reg; /* CCCR or PRR, if not in DT */
  16. };
  17. static const struct renesas_family fam_rcar_gen1 __initconst __maybe_unused = {
  18. .name = "R-Car Gen1",
  19. .reg = 0xff000044, /* PRR (Product Register) */
  20. };
  21. static const struct renesas_family fam_rcar_gen2 __initconst __maybe_unused = {
  22. .name = "R-Car Gen2",
  23. .reg = 0xff000044, /* PRR (Product Register) */
  24. };
  25. static const struct renesas_family fam_rcar_gen3 __initconst __maybe_unused = {
  26. .name = "R-Car Gen3",
  27. .reg = 0xfff00044, /* PRR (Product Register) */
  28. };
  29. static const struct renesas_family fam_rcar_gen4 __initconst __maybe_unused = {
  30. .name = "R-Car Gen4",
  31. };
  32. static const struct renesas_family fam_rmobile __initconst __maybe_unused = {
  33. .name = "R-Mobile",
  34. .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
  35. };
  36. static const struct renesas_family fam_rza1 __initconst __maybe_unused = {
  37. .name = "RZ/A1",
  38. };
  39. static const struct renesas_family fam_rza2 __initconst __maybe_unused = {
  40. .name = "RZ/A2",
  41. };
  42. static const struct renesas_family fam_rzfive __initconst __maybe_unused = {
  43. .name = "RZ/Five",
  44. };
  45. static const struct renesas_family fam_rzg1 __initconst __maybe_unused = {
  46. .name = "RZ/G1",
  47. .reg = 0xff000044, /* PRR (Product Register) */
  48. };
  49. static const struct renesas_family fam_rzg2 __initconst __maybe_unused = {
  50. .name = "RZ/G2",
  51. .reg = 0xfff00044, /* PRR (Product Register) */
  52. };
  53. static const struct renesas_family fam_rzg2l __initconst __maybe_unused = {
  54. .name = "RZ/G2L",
  55. };
  56. static const struct renesas_family fam_rzg2ul __initconst __maybe_unused = {
  57. .name = "RZ/G2UL",
  58. };
  59. static const struct renesas_family fam_rzv2l __initconst __maybe_unused = {
  60. .name = "RZ/V2L",
  61. };
  62. static const struct renesas_family fam_shmobile __initconst __maybe_unused = {
  63. .name = "SH-Mobile",
  64. .reg = 0xe600101c, /* CCCR (Common Chip Code Register) */
  65. };
  66. struct renesas_soc {
  67. const struct renesas_family *family;
  68. u32 id;
  69. };
  70. static const struct renesas_soc soc_rz_a1h __initconst __maybe_unused = {
  71. .family = &fam_rza1,
  72. };
  73. static const struct renesas_soc soc_rz_a2m __initconst __maybe_unused = {
  74. .family = &fam_rza2,
  75. .id = 0x3b,
  76. };
  77. static const struct renesas_soc soc_rmobile_ape6 __initconst __maybe_unused = {
  78. .family = &fam_rmobile,
  79. .id = 0x3f,
  80. };
  81. static const struct renesas_soc soc_rmobile_a1 __initconst __maybe_unused = {
  82. .family = &fam_rmobile,
  83. .id = 0x40,
  84. };
  85. static const struct renesas_soc soc_rz_five __initconst __maybe_unused = {
  86. .family = &fam_rzfive,
  87. .id = 0x847c447,
  88. };
  89. static const struct renesas_soc soc_rz_g1h __initconst __maybe_unused = {
  90. .family = &fam_rzg1,
  91. .id = 0x45,
  92. };
  93. static const struct renesas_soc soc_rz_g1m __initconst __maybe_unused = {
  94. .family = &fam_rzg1,
  95. .id = 0x47,
  96. };
  97. static const struct renesas_soc soc_rz_g1n __initconst __maybe_unused = {
  98. .family = &fam_rzg1,
  99. .id = 0x4b,
  100. };
  101. static const struct renesas_soc soc_rz_g1e __initconst __maybe_unused = {
  102. .family = &fam_rzg1,
  103. .id = 0x4c,
  104. };
  105. static const struct renesas_soc soc_rz_g1c __initconst __maybe_unused = {
  106. .family = &fam_rzg1,
  107. .id = 0x53,
  108. };
  109. static const struct renesas_soc soc_rz_g2m __initconst __maybe_unused = {
  110. .family = &fam_rzg2,
  111. .id = 0x52,
  112. };
  113. static const struct renesas_soc soc_rz_g2n __initconst __maybe_unused = {
  114. .family = &fam_rzg2,
  115. .id = 0x55,
  116. };
  117. static const struct renesas_soc soc_rz_g2e __initconst __maybe_unused = {
  118. .family = &fam_rzg2,
  119. .id = 0x57,
  120. };
  121. static const struct renesas_soc soc_rz_g2h __initconst __maybe_unused = {
  122. .family = &fam_rzg2,
  123. .id = 0x4f,
  124. };
  125. static const struct renesas_soc soc_rz_g2l __initconst __maybe_unused = {
  126. .family = &fam_rzg2l,
  127. .id = 0x841c447,
  128. };
  129. static const struct renesas_soc soc_rz_g2ul __initconst __maybe_unused = {
  130. .family = &fam_rzg2ul,
  131. .id = 0x8450447,
  132. };
  133. static const struct renesas_soc soc_rz_v2l __initconst __maybe_unused = {
  134. .family = &fam_rzv2l,
  135. .id = 0x8447447,
  136. };
  137. static const struct renesas_soc soc_rcar_m1a __initconst __maybe_unused = {
  138. .family = &fam_rcar_gen1,
  139. };
  140. static const struct renesas_soc soc_rcar_h1 __initconst __maybe_unused = {
  141. .family = &fam_rcar_gen1,
  142. .id = 0x3b,
  143. };
  144. static const struct renesas_soc soc_rcar_h2 __initconst __maybe_unused = {
  145. .family = &fam_rcar_gen2,
  146. .id = 0x45,
  147. };
  148. static const struct renesas_soc soc_rcar_m2_w __initconst __maybe_unused = {
  149. .family = &fam_rcar_gen2,
  150. .id = 0x47,
  151. };
  152. static const struct renesas_soc soc_rcar_v2h __initconst __maybe_unused = {
  153. .family = &fam_rcar_gen2,
  154. .id = 0x4a,
  155. };
  156. static const struct renesas_soc soc_rcar_m2_n __initconst __maybe_unused = {
  157. .family = &fam_rcar_gen2,
  158. .id = 0x4b,
  159. };
  160. static const struct renesas_soc soc_rcar_e2 __initconst __maybe_unused = {
  161. .family = &fam_rcar_gen2,
  162. .id = 0x4c,
  163. };
  164. static const struct renesas_soc soc_rcar_h3 __initconst __maybe_unused = {
  165. .family = &fam_rcar_gen3,
  166. .id = 0x4f,
  167. };
  168. static const struct renesas_soc soc_rcar_m3_w __initconst __maybe_unused = {
  169. .family = &fam_rcar_gen3,
  170. .id = 0x52,
  171. };
  172. static const struct renesas_soc soc_rcar_m3_n __initconst __maybe_unused = {
  173. .family = &fam_rcar_gen3,
  174. .id = 0x55,
  175. };
  176. static const struct renesas_soc soc_rcar_v3m __initconst __maybe_unused = {
  177. .family = &fam_rcar_gen3,
  178. .id = 0x54,
  179. };
  180. static const struct renesas_soc soc_rcar_v3h __initconst __maybe_unused = {
  181. .family = &fam_rcar_gen3,
  182. .id = 0x56,
  183. };
  184. static const struct renesas_soc soc_rcar_e3 __initconst __maybe_unused = {
  185. .family = &fam_rcar_gen3,
  186. .id = 0x57,
  187. };
  188. static const struct renesas_soc soc_rcar_d3 __initconst __maybe_unused = {
  189. .family = &fam_rcar_gen3,
  190. .id = 0x58,
  191. };
  192. static const struct renesas_soc soc_rcar_v3u __initconst __maybe_unused = {
  193. .family = &fam_rcar_gen4,
  194. .id = 0x59,
  195. };
  196. static const struct renesas_soc soc_rcar_s4 __initconst __maybe_unused = {
  197. .family = &fam_rcar_gen4,
  198. .id = 0x5a,
  199. };
  200. static const struct renesas_soc soc_rcar_v4h __initconst __maybe_unused = {
  201. .family = &fam_rcar_gen4,
  202. .id = 0x5c,
  203. };
  204. static const struct renesas_soc soc_shmobile_ag5 __initconst __maybe_unused = {
  205. .family = &fam_shmobile,
  206. .id = 0x37,
  207. };
  208. static const struct of_device_id renesas_socs[] __initconst = {
  209. #ifdef CONFIG_ARCH_R7S72100
  210. { .compatible = "renesas,r7s72100", .data = &soc_rz_a1h },
  211. #endif
  212. #ifdef CONFIG_ARCH_R7S9210
  213. { .compatible = "renesas,r7s9210", .data = &soc_rz_a2m },
  214. #endif
  215. #ifdef CONFIG_ARCH_R8A73A4
  216. { .compatible = "renesas,r8a73a4", .data = &soc_rmobile_ape6 },
  217. #endif
  218. #ifdef CONFIG_ARCH_R8A7740
  219. { .compatible = "renesas,r8a7740", .data = &soc_rmobile_a1 },
  220. #endif
  221. #ifdef CONFIG_ARCH_R8A7742
  222. { .compatible = "renesas,r8a7742", .data = &soc_rz_g1h },
  223. #endif
  224. #ifdef CONFIG_ARCH_R8A7743
  225. { .compatible = "renesas,r8a7743", .data = &soc_rz_g1m },
  226. #endif
  227. #ifdef CONFIG_ARCH_R8A7744
  228. { .compatible = "renesas,r8a7744", .data = &soc_rz_g1n },
  229. #endif
  230. #ifdef CONFIG_ARCH_R8A7745
  231. { .compatible = "renesas,r8a7745", .data = &soc_rz_g1e },
  232. #endif
  233. #ifdef CONFIG_ARCH_R8A77470
  234. { .compatible = "renesas,r8a77470", .data = &soc_rz_g1c },
  235. #endif
  236. #ifdef CONFIG_ARCH_R8A774A1
  237. { .compatible = "renesas,r8a774a1", .data = &soc_rz_g2m },
  238. #endif
  239. #ifdef CONFIG_ARCH_R8A774B1
  240. { .compatible = "renesas,r8a774b1", .data = &soc_rz_g2n },
  241. #endif
  242. #ifdef CONFIG_ARCH_R8A774C0
  243. { .compatible = "renesas,r8a774c0", .data = &soc_rz_g2e },
  244. #endif
  245. #ifdef CONFIG_ARCH_R8A774E1
  246. { .compatible = "renesas,r8a774e1", .data = &soc_rz_g2h },
  247. #endif
  248. #ifdef CONFIG_ARCH_R8A7778
  249. { .compatible = "renesas,r8a7778", .data = &soc_rcar_m1a },
  250. #endif
  251. #ifdef CONFIG_ARCH_R8A7779
  252. { .compatible = "renesas,r8a7779", .data = &soc_rcar_h1 },
  253. #endif
  254. #ifdef CONFIG_ARCH_R8A7790
  255. { .compatible = "renesas,r8a7790", .data = &soc_rcar_h2 },
  256. #endif
  257. #ifdef CONFIG_ARCH_R8A7791
  258. { .compatible = "renesas,r8a7791", .data = &soc_rcar_m2_w },
  259. #endif
  260. #ifdef CONFIG_ARCH_R8A7792
  261. { .compatible = "renesas,r8a7792", .data = &soc_rcar_v2h },
  262. #endif
  263. #ifdef CONFIG_ARCH_R8A7793
  264. { .compatible = "renesas,r8a7793", .data = &soc_rcar_m2_n },
  265. #endif
  266. #ifdef CONFIG_ARCH_R8A7794
  267. { .compatible = "renesas,r8a7794", .data = &soc_rcar_e2 },
  268. #endif
  269. #if defined(CONFIG_ARCH_R8A77950) || defined(CONFIG_ARCH_R8A77951)
  270. { .compatible = "renesas,r8a7795", .data = &soc_rcar_h3 },
  271. #endif
  272. #ifdef CONFIG_ARCH_R8A77951
  273. { .compatible = "renesas,r8a779m0", .data = &soc_rcar_h3 },
  274. { .compatible = "renesas,r8a779m1", .data = &soc_rcar_h3 },
  275. { .compatible = "renesas,r8a779m8", .data = &soc_rcar_h3 },
  276. { .compatible = "renesas,r8a779mb", .data = &soc_rcar_h3 },
  277. #endif
  278. #ifdef CONFIG_ARCH_R8A77960
  279. { .compatible = "renesas,r8a7796", .data = &soc_rcar_m3_w },
  280. #endif
  281. #ifdef CONFIG_ARCH_R8A77961
  282. { .compatible = "renesas,r8a77961", .data = &soc_rcar_m3_w },
  283. { .compatible = "renesas,r8a779m2", .data = &soc_rcar_m3_w },
  284. { .compatible = "renesas,r8a779m3", .data = &soc_rcar_m3_w },
  285. #endif
  286. #ifdef CONFIG_ARCH_R8A77965
  287. { .compatible = "renesas,r8a77965", .data = &soc_rcar_m3_n },
  288. { .compatible = "renesas,r8a779m4", .data = &soc_rcar_m3_n },
  289. { .compatible = "renesas,r8a779m5", .data = &soc_rcar_m3_n },
  290. #endif
  291. #ifdef CONFIG_ARCH_R8A77970
  292. { .compatible = "renesas,r8a77970", .data = &soc_rcar_v3m },
  293. #endif
  294. #ifdef CONFIG_ARCH_R8A77980
  295. { .compatible = "renesas,r8a77980", .data = &soc_rcar_v3h },
  296. #endif
  297. #ifdef CONFIG_ARCH_R8A77990
  298. { .compatible = "renesas,r8a77990", .data = &soc_rcar_e3 },
  299. { .compatible = "renesas,r8a779m6", .data = &soc_rcar_e3 },
  300. #endif
  301. #ifdef CONFIG_ARCH_R8A77995
  302. { .compatible = "renesas,r8a77995", .data = &soc_rcar_d3 },
  303. { .compatible = "renesas,r8a779m7", .data = &soc_rcar_d3 },
  304. #endif
  305. #ifdef CONFIG_ARCH_R8A779A0
  306. { .compatible = "renesas,r8a779a0", .data = &soc_rcar_v3u },
  307. #endif
  308. #ifdef CONFIG_ARCH_R8A779F0
  309. { .compatible = "renesas,r8a779f0", .data = &soc_rcar_s4 },
  310. #endif
  311. #ifdef CONFIG_ARCH_R8A779G0
  312. { .compatible = "renesas,r8a779g0", .data = &soc_rcar_v4h },
  313. #endif
  314. #if defined(CONFIG_ARCH_R9A07G043)
  315. #ifdef CONFIG_RISCV
  316. { .compatible = "renesas,r9a07g043", .data = &soc_rz_five },
  317. #else
  318. { .compatible = "renesas,r9a07g043", .data = &soc_rz_g2ul },
  319. #endif
  320. #endif
  321. #if defined(CONFIG_ARCH_R9A07G044)
  322. { .compatible = "renesas,r9a07g044", .data = &soc_rz_g2l },
  323. #endif
  324. #if defined(CONFIG_ARCH_R9A07G054)
  325. { .compatible = "renesas,r9a07g054", .data = &soc_rz_v2l },
  326. #endif
  327. #ifdef CONFIG_ARCH_SH73A0
  328. { .compatible = "renesas,sh73a0", .data = &soc_shmobile_ag5 },
  329. #endif
  330. { /* sentinel */ }
  331. };
  332. struct renesas_id {
  333. unsigned int offset;
  334. u32 mask;
  335. };
  336. static const struct renesas_id id_bsid __initconst = {
  337. .offset = 0,
  338. .mask = 0xff0000,
  339. /*
  340. * TODO: Upper 4 bits of BSID are for chip version, but the format is
  341. * not known at this time so we don't know how to specify eshi and eslo
  342. */
  343. };
  344. static const struct renesas_id id_rzg2l __initconst = {
  345. .offset = 0xa04,
  346. .mask = 0xfffffff,
  347. };
  348. static const struct renesas_id id_prr __initconst = {
  349. .offset = 0,
  350. .mask = 0xff00,
  351. };
  352. static const struct of_device_id renesas_ids[] __initconst = {
  353. { .compatible = "renesas,bsid", .data = &id_bsid },
  354. { .compatible = "renesas,r9a07g043-sysc", .data = &id_rzg2l },
  355. { .compatible = "renesas,r9a07g044-sysc", .data = &id_rzg2l },
  356. { .compatible = "renesas,r9a07g054-sysc", .data = &id_rzg2l },
  357. { .compatible = "renesas,prr", .data = &id_prr },
  358. { /* sentinel */ }
  359. };
  360. static int __init renesas_soc_init(void)
  361. {
  362. struct soc_device_attribute *soc_dev_attr;
  363. unsigned int product, eshi = 0, eslo;
  364. const struct renesas_family *family;
  365. const struct of_device_id *match;
  366. const struct renesas_soc *soc;
  367. const struct renesas_id *id;
  368. void __iomem *chipid = NULL;
  369. const char *rev_prefix = "";
  370. struct soc_device *soc_dev;
  371. struct device_node *np;
  372. const char *soc_id;
  373. int ret;
  374. match = of_match_node(renesas_socs, of_root);
  375. if (!match)
  376. return -ENODEV;
  377. soc_id = strchr(match->compatible, ',') + 1;
  378. soc = match->data;
  379. family = soc->family;
  380. np = of_find_matching_node_and_match(NULL, renesas_ids, &match);
  381. if (np) {
  382. id = match->data;
  383. chipid = of_iomap(np, 0);
  384. of_node_put(np);
  385. } else if (soc->id && family->reg) {
  386. /* Try hardcoded CCCR/PRR fallback */
  387. id = &id_prr;
  388. chipid = ioremap(family->reg, 4);
  389. }
  390. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  391. if (!soc_dev_attr) {
  392. if (chipid)
  393. iounmap(chipid);
  394. return -ENOMEM;
  395. }
  396. np = of_find_node_by_path("/");
  397. of_property_read_string(np, "model", &soc_dev_attr->machine);
  398. of_node_put(np);
  399. soc_dev_attr->family = kstrdup_const(family->name, GFP_KERNEL);
  400. soc_dev_attr->soc_id = kstrdup_const(soc_id, GFP_KERNEL);
  401. if (chipid) {
  402. product = readl(chipid + id->offset);
  403. iounmap(chipid);
  404. if (id == &id_prr) {
  405. /* R-Car M3-W ES1.1 incorrectly identifies as ES2.0 */
  406. if ((product & 0x7fff) == 0x5210)
  407. product ^= 0x11;
  408. /* R-Car M3-W ES1.3 incorrectly identifies as ES2.1 */
  409. if ((product & 0x7fff) == 0x5211)
  410. product ^= 0x12;
  411. eshi = ((product >> 4) & 0x0f) + 1;
  412. eslo = product & 0xf;
  413. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "ES%u.%u",
  414. eshi, eslo);
  415. } else if (id == &id_rzg2l) {
  416. eshi = ((product >> 28) & 0x0f);
  417. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%u",
  418. eshi);
  419. rev_prefix = "Rev ";
  420. }
  421. if (soc->id &&
  422. ((product & id->mask) >> __ffs(id->mask)) != soc->id) {
  423. pr_warn("SoC mismatch (product = 0x%x)\n", product);
  424. ret = -ENODEV;
  425. goto free_soc_dev_attr;
  426. }
  427. }
  428. pr_info("Detected Renesas %s %s %s%s\n", soc_dev_attr->family,
  429. soc_dev_attr->soc_id, rev_prefix, soc_dev_attr->revision ?: "");
  430. soc_dev = soc_device_register(soc_dev_attr);
  431. if (IS_ERR(soc_dev)) {
  432. ret = PTR_ERR(soc_dev);
  433. goto free_soc_dev_attr;
  434. }
  435. return 0;
  436. free_soc_dev_attr:
  437. kfree(soc_dev_attr->revision);
  438. kfree_const(soc_dev_attr->soc_id);
  439. kfree_const(soc_dev_attr->family);
  440. kfree(soc_dev_attr);
  441. return ret;
  442. }
  443. early_initcall(renesas_soc_init);