1 // SPDX-License-Identifier: GPL-2.0
3 * Nuvoton WPCM450 SoC Identification
5 * Copyright (C) 2022 Jonathan Neuschäfer
8 #include <linux/mfd/syscon.h>
10 #include <linux/regmap.h>
11 #include <linux/slab.h>
12 #include <linux/sys_soc.h>
15 #define PDID_CHIP(x) ((x) & 0x00ffffff)
16 #define CHIP_WPCM450 0x926450
17 #define PDID_REV(x) ((x) >> 24)
24 static const struct revision revisions[] __initconst = {
34 static const char * __init get_revision(unsigned int rev)
38 for (i = 0; revisions[i].name; i++)
39 if (revisions[i].number == rev)
40 return revisions[i].name;
44 static struct soc_device_attribute *wpcm450_attr;
45 static struct soc_device *wpcm450_soc;
47 static int __init wpcm450_soc_init(void)
49 struct soc_device_attribute *attr;
50 struct soc_device *soc;
56 if (!of_machine_is_compatible("nuvoton,wpcm450"))
59 gcr = syscon_regmap_lookup_by_compatible("nuvoton,wpcm450-gcr");
62 ret = regmap_read(gcr, GCR_PDID, &pdid);
66 if (PDID_CHIP(pdid) != CHIP_WPCM450) {
67 pr_warn("Unknown chip ID in GCR.PDID: 0x%06x\n", PDID_CHIP(pdid));
71 revision = get_revision(PDID_REV(pdid));
73 pr_warn("Unknown chip revision in GCR.PDID: 0x%02x\n", PDID_REV(pdid));
77 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
81 attr->family = "Nuvoton NPCM";
82 attr->soc_id = "WPCM450";
83 attr->revision = revision;
84 soc = soc_device_register(attr);
87 pr_warn("Could not register SoC device\n");
95 module_init(wpcm450_soc_init);
97 static void __exit wpcm450_soc_exit(void)
100 soc_device_unregister(wpcm450_soc);
105 module_exit(wpcm450_soc_exit);
107 MODULE_LICENSE("GPL");
108 MODULE_AUTHOR("Jonathan Neuschäfer");
109 MODULE_DESCRIPTION("Nuvoton WPCM450 SoC Identification driver");