Skip to contentSkip to conversation

soc: nuvoton: Add SoC info driver for WPCM450

PATCH RESEND Superseded Jonathan Neuschäfer 3 participants 4 messages Oct 31, 2022 – Nov 3, 2022 Arm/nuvoton WPCM450 architecture

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jonathan Neuschäfer

author maintainer
#0 lore raw

PATCH RESEND v5 1/1 soc: nuvoton: Add SoC info driver for WPCM450

Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision.

Usage example:

  # grep . /sys/devices/soc0/*
  /sys/devices/soc0/family:Nuvoton NPCM
  /sys/devices/soc0/revision:A3
  /sys/devices/soc0/soc_id:WPCM450

---
v5:
- Change Kconfig option from bool to tristate

v4:
- rebase on 5.19-rc1

v3:
- Declare revisions array as static
- Change get_revision parameter to unsigned int
- Add Paul's R-b tag
- Add usage example
- Sort includes

v2:
- https://lore.kernel.org/lkml/[email protected]/
- Add R-b tag
- rebase on 5.18-rc1

v1:
- https://lore.kernel.org/lkml/[email protected]/

---
 drivers/soc/Kconfig               |   1 +
 drivers/soc/Makefile              |   1 +
 drivers/soc/nuvoton/Kconfig       |  11 +++
 drivers/soc/nuvoton/Makefile      |   2 +
 drivers/soc/nuvoton/wpcm450-soc.c | 109 ++++++++++++++++++++++++++++++
 5 files changed, 124 insertions(+)
 create mode 100644 drivers/soc/nuvoton/Kconfig
 create mode 100644 drivers/soc/nuvoton/Makefile
 create mode 100644 drivers/soc/nuvoton/wpcm450-soc.c
drivers/soc/Kconfig +1 -0
index 86ccf5970bc1b..cca3dfa5c6aea 100644
@@ -14,6 +14,7 @@ source "drivers/soc/ixp4xx/Kconfig"
 source "drivers/soc/litex/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/microchip/Kconfig"
+source "drivers/soc/nuvoton/Kconfig"
 source "drivers/soc/pxa/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/renesas/Kconfig"
drivers/soc/Makefile +1 -0
index 919716e0e7001..b9eb3c75e551a 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_SOC_XWAY)		+= lantiq/
 obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/
 obj-y				+= mediatek/
 obj-y				+= microchip/
+obj-y				+= nuvoton/
 obj-y				+= pxa/
 obj-y				+= amlogic/
 obj-y				+= qcom/
drivers/soc/nuvoton/Kconfig new file +11 -0
new file mode 100644
index 0000000000000..df46182088ec2
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+menuconfig WPCM450_SOC
+	tristate "Nuvoton WPCM450 SoC driver"
+	default y if ARCH_WPCM450
+	select SOC_BUS
+	help
+	  Say Y here to compile the SoC information driver for Nuvoton
+	  WPCM450 SoCs.
+
+	  This driver provides information such as the SoC model and
+	  revision.
drivers/soc/nuvoton/Makefile new file +2 -0
new file mode 100644
index 0000000000000..e30317b4e8290
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_WPCM450_SOC)	+= wpcm450-soc.o
drivers/soc/nuvoton/wpcm450-soc.c new file +109 -0

109 lines not on this page · raw message

--
2.35.1

#1 lore raw
Quoted 76 lines · Jonathan Neuschäfer

Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision.

Usage example:

  # grep . /sys/devices/soc0/*
  /sys/devices/soc0/family:Nuvoton NPCM
  /sys/devices/soc0/revision:A3
  /sys/devices/soc0/soc_id:WPCM450

---
v5:
- Change Kconfig option from bool to tristate

v4:
- rebase on 5.19-rc1

v3:
- Declare revisions array as static
- Change get_revision parameter to unsigned int
- Add Paul's R-b tag
- Add usage example
- Sort includes

v2:
- https://lore.kernel.org/lkml/[email protected]/
- Add R-b tag
- rebase on 5.18-rc1

v1:
- https://lore.kernel.org/lkml/[email protected]/

---
 drivers/soc/Kconfig               |   1 +
 drivers/soc/Makefile              |   1 +
 drivers/soc/nuvoton/Kconfig       |  11 +++
 drivers/soc/nuvoton/Makefile      |   2 +
 drivers/soc/nuvoton/wpcm450-soc.c | 109 ++++++++++++++++++++++++++++++
 5 files changed, 124 insertions(+)
 create mode 100644 drivers/soc/nuvoton/Kconfig
 create mode 100644 drivers/soc/nuvoton/Makefile
 create mode 100644 drivers/soc/nuvoton/wpcm450-soc.c
drivers/soc/Kconfig +1 -0
index 86ccf5970bc1b..cca3dfa5c6aea 100644
@@ -14,6 +14,7 @@ source "drivers/soc/ixp4xx/Kconfig"
 source "drivers/soc/litex/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/microchip/Kconfig"
+source "drivers/soc/nuvoton/Kconfig"
 source "drivers/soc/pxa/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/renesas/Kconfig"
drivers/soc/Makefile +1 -0
index 919716e0e7001..b9eb3c75e551a 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_SOC_XWAY)                += lantiq/
 obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/
 obj-y                          += mediatek/
 obj-y                          += microchip/
+obj-y                          += nuvoton/
 obj-y                          += pxa/
 obj-y                          += amlogic/
 obj-y                          += qcom/
drivers/soc/nuvoton/Kconfig new file +0 -0
new file mode 100644
index 0000000000000..df46182088ec2

drivers/soc/nuvoton/Kconfig line 5

Quoted 5 lines
drivers/soc/nuvoton/Kconfig new file +5 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+menuconfig WPCM450_SOC
+       tristate "Nuvoton WPCM450 SoC driver"
+       default y if ARCH_WPCM450
+       select SOC_BUS

Sorry for not noticing this earlier. This is a bit confusing. If we have a menu option, the soc driver should appear under it. Or we could do without the menu all together, as there's only one driver so far.

We also should select REGMAP, as you're using it, and hide the option behind ARCH_WPCM450 || COMPILE_TEST.

How about this:

if ARCH_WPCM450 || COMPILE_TEST

config WPCM450_SOCINFO
tristate "Nuvoton WPCM450 SoC driver"
default y if ARCH_WPCM450
select SOC_BUS
select REGMAP
help
Say Y here to compile the SoC information driver for Nuvoton WPCM450 SoCs.

This driver provides information such as the SoC model and revision.

endif

Quoted 132 lines
drivers/soc/nuvoton/Kconfig new file +6 -0
+       help
+         Say Y here to compile the SoC information driver for Nuvoton
+         WPCM450 SoCs.
+
+         This driver provides information such as the SoC model and
+         revision.
drivers/soc/nuvoton/Makefile new file +2 -0
new file mode 100644
index 0000000000000..e30317b4e8290
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_WPCM450_SOC)      += wpcm450-soc.o
drivers/soc/nuvoton/wpcm450-soc.c new file +109 -1
new file mode 100644
index 0000000000000..c5e0d11c383b1
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Nuvoton WPCM450 SoC Identification
+ *
+ * Copyright (C) 2022 Jonathan Neuschäfer
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+#define GCR_PDID       0
+#define PDID_CHIP(x)   ((x) & 0x00ffffff)
+#define CHIP_WPCM450   0x926450
+#define PDID_REV(x)    ((x) >> 24)
+
+struct revision {
+       u8 number;
+       const char *name;
+};
+
+static const struct revision revisions[] __initconst = {
+       { 0x00, "Z1" },
+       { 0x03, "Z2" },
+       { 0x04, "Z21" },
+       { 0x08, "A1" },
+       { 0x09, "A2" },
+       { 0x0a, "A3" },
+       {}
+};
+
+static const char * __init get_revision(unsigned int rev)
+{
+       int i;
+
+       for (i = 0; revisions[i].name; i++)
+               if (revisions[i].number == rev)
+                       return revisions[i].name;
+       return NULL;
+}
+
+static struct soc_device_attribute *wpcm450_attr;
+static struct soc_device *wpcm450_soc;
+
+static int __init wpcm450_soc_init(void)
+{
+       struct soc_device_attribute *attr;
+       struct soc_device *soc;
+       const char *revision;
+       struct regmap *gcr;
+       u32 pdid;
+       int ret;
+
+       if (!of_machine_is_compatible("nuvoton,wpcm450"))
+               return 0;
+
+       gcr = syscon_regmap_lookup_by_compatible("nuvoton,wpcm450-gcr");
+       if (IS_ERR(gcr))
+               return PTR_ERR(gcr);
+       ret = regmap_read(gcr, GCR_PDID, &pdid);
+       if (ret)
+               return ret;
+
+       if (PDID_CHIP(pdid) != CHIP_WPCM450) {
+               pr_warn("Unknown chip ID in GCR.PDID: 0x%06x\n", PDID_CHIP(pdid));
+               return -ENODEV;
+       }
+
+       revision = get_revision(PDID_REV(pdid));
+       if (!revision) {
+               pr_warn("Unknown chip revision in GCR.PDID: 0x%02x\n", PDID_REV(pdid));
+               return -ENODEV;
+       }
+
+       attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+       if (!attr)
+               return -ENOMEM;
+
+       attr->family = "Nuvoton NPCM";
+       attr->soc_id = "WPCM450";
+       attr->revision = revision;
+       soc = soc_device_register(attr);
+       if (IS_ERR(soc)) {
+               kfree(attr);
+               pr_warn("Could not register SoC device\n");
+               return PTR_ERR(soc);
+       }
+
+       wpcm450_soc = soc;
+       wpcm450_attr = attr;
+       return 0;
+}
+module_init(wpcm450_soc_init);
+
+static void __exit wpcm450_soc_exit(void)
+{
+       if (wpcm450_soc) {
+               soc_device_unregister(wpcm450_soc);
+               wpcm450_soc = NULL;
+               kfree(wpcm450_attr);
+       }
+}
+module_exit(wpcm450_soc_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jonathan Neuschäfer");
+MODULE_DESCRIPTION("Nuvoton WPCM450 SoC Identification driver");
--

2.35.1

#2 lore raw

Hi Jonathan,

Thanks for your patch.

Quoted 88 lines · Joel Stanley
Quoted 76 lines · Jonathan Neuschäfer

Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision.

Usage example:

  # grep . /sys/devices/soc0/*
  /sys/devices/soc0/family:Nuvoton NPCM
  /sys/devices/soc0/revision:A3
  /sys/devices/soc0/soc_id:WPCM450

---
v5:
- Change Kconfig option from bool to tristate

v4:
- rebase on 5.19-rc1

v3:
- Declare revisions array as static
- Change get_revision parameter to unsigned int
- Add Paul's R-b tag
- Add usage example
- Sort includes

v2:
- https://lore.kernel.org/lkml/[email protected]/
- Add R-b tag
- rebase on 5.18-rc1

v1:
- https://lore.kernel.org/lkml/[email protected]/

---
 drivers/soc/Kconfig               |   1 +
 drivers/soc/Makefile              |   1 +
 drivers/soc/nuvoton/Kconfig       |  11 +++
 drivers/soc/nuvoton/Makefile      |   2 +
 drivers/soc/nuvoton/wpcm450-soc.c | 109 ++++++++++++++++++++++++++++++
 5 files changed, 124 insertions(+)
 create mode 100644 drivers/soc/nuvoton/Kconfig
 create mode 100644 drivers/soc/nuvoton/Makefile
 create mode 100644 drivers/soc/nuvoton/wpcm450-soc.c
drivers/soc/Kconfig +1 -0
index 86ccf5970bc1b..cca3dfa5c6aea 100644
@@ -14,6 +14,7 @@ source "drivers/soc/ixp4xx/Kconfig"
 source "drivers/soc/litex/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/microchip/Kconfig"
+source "drivers/soc/nuvoton/Kconfig"
 source "drivers/soc/pxa/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/renesas/Kconfig"
drivers/soc/Makefile +1 -0
index 919716e0e7001..b9eb3c75e551a 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_SOC_XWAY)                += lantiq/
 obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/
 obj-y                          += mediatek/
 obj-y                          += microchip/
+obj-y                          += nuvoton/
 obj-y                          += pxa/
 obj-y                          += amlogic/
 obj-y                          += qcom/
drivers/soc/nuvoton/Kconfig new file +0 -0
new file mode 100644
index 0000000000000..df46182088ec2

drivers/soc/nuvoton/Kconfig line 5

Quoted 5 lines
drivers/soc/nuvoton/Kconfig new file +5 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+menuconfig WPCM450_SOC
+       tristate "Nuvoton WPCM450 SoC driver"
+       default y if ARCH_WPCM450
+       select SOC_BUS

Sorry for not noticing this earlier. This is a bit confusing. If we have a menu option, the soc driver should appear under it. Or we could do without the menu all together, as there's only one driver so far.

Quoted 6 lines

We also should select REGMAP, as you're using it, and hide the option behind ARCH_WPCM450 || COMPILE_TEST.

How about this:

if ARCH_WPCM450 || COMPILE_TEST

These days we working on LPC BPC driver for NPCM7xx and NPCM8xx that will be placed in nuvoton soc folder.
we will use:

if ARCH_NPCM || COMPILE_TEST

menu "NPCM SoC drivers"

Maybe you should remove
if ARCH_WPCM450 || COMPILE_TEST

and add ARCH_WPCM450 dependency in the WPCM450_SOCINFO driver configuration.

Quoted 142 lines

config WPCM450_SOCINFO
tristate "Nuvoton WPCM450 SoC driver"
default y if ARCH_WPCM450
select SOC_BUS
select REGMAP
help
Say Y here to compile the SoC information driver for Nuvoton WPCM450 SoCs.

This driver provides information such as the SoC model and revision.

endif

Quoted 124 lines
drivers/soc/nuvoton/Kconfig new file +6 -0
+       help
+         Say Y here to compile the SoC information driver for Nuvoton
+         WPCM450 SoCs.
+
+         This driver provides information such as the SoC model and
+         revision.
drivers/soc/nuvoton/Makefile new file +2 -0
new file mode 100644
index 0000000000000..e30317b4e8290
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_WPCM450_SOC)      += wpcm450-soc.o
drivers/soc/nuvoton/wpcm450-soc.c new file +104 -0
new file mode 100644
index 0000000000000..c5e0d11c383b1
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Nuvoton WPCM450 SoC Identification
+ *
+ * Copyright (C) 2022 Jonathan Neuschäfer
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/of.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+#define GCR_PDID       0
+#define PDID_CHIP(x)   ((x) & 0x00ffffff)
+#define CHIP_WPCM450   0x926450
+#define PDID_REV(x)    ((x) >> 24)
+
+struct revision {
+       u8 number;
+       const char *name;
+};
+
+static const struct revision revisions[] __initconst = {
+       { 0x00, "Z1" },
+       { 0x03, "Z2" },
+       { 0x04, "Z21" },
+       { 0x08, "A1" },
+       { 0x09, "A2" },
+       { 0x0a, "A3" },
+       {}
+};
+
+static const char * __init get_revision(unsigned int rev)
+{
+       int i;
+
+       for (i = 0; revisions[i].name; i++)
+               if (revisions[i].number == rev)
+                       return revisions[i].name;
+       return NULL;
+}
+
+static struct soc_device_attribute *wpcm450_attr;
+static struct soc_device *wpcm450_soc;
+
+static int __init wpcm450_soc_init(void)
+{
+       struct soc_device_attribute *attr;
+       struct soc_device *soc;
+       const char *revision;
+       struct regmap *gcr;
+       u32 pdid;
+       int ret;
+
+       if (!of_machine_is_compatible("nuvoton,wpcm450"))
+               return 0;
+
+       gcr = syscon_regmap_lookup_by_compatible("nuvoton,wpcm450-gcr");
+       if (IS_ERR(gcr))
+               return PTR_ERR(gcr);
+       ret = regmap_read(gcr, GCR_PDID, &pdid);
+       if (ret)
+               return ret;
+
+       if (PDID_CHIP(pdid) != CHIP_WPCM450) {
+               pr_warn("Unknown chip ID in GCR.PDID: 0x%06x\n", PDID_CHIP(pdid));
+               return -ENODEV;
+       }
+
+       revision = get_revision(PDID_REV(pdid));
+       if (!revision) {
+               pr_warn("Unknown chip revision in GCR.PDID: 0x%02x\n", PDID_REV(pdid));
+               return -ENODEV;
+       }
+
+       attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+       if (!attr)
+               return -ENOMEM;
+
+       attr->family = "Nuvoton NPCM";
+       attr->soc_id = "WPCM450";
+       attr->revision = revision;
+       soc = soc_device_register(attr);
+       if (IS_ERR(soc)) {
+               kfree(attr);
+               pr_warn("Could not register SoC device\n");
+               return PTR_ERR(soc);
+       }
+
+       wpcm450_soc = soc;
+       wpcm450_attr = attr;
+       return 0;
+}
+module_init(wpcm450_soc_init);
+
+static void __exit wpcm450_soc_exit(void)
+{
+       if (wpcm450_soc) {
+               soc_device_unregister(wpcm450_soc);
+               wpcm450_soc = NULL;
+               kfree(wpcm450_attr);
+       }
+}
Quoted 8 lines
Quoted 8 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +5 -1
+module_exit(wpcm450_soc_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jonathan Neuschäfer");
+MODULE_DESCRIPTION("Nuvoton WPCM450 SoC Identification driver");
--

2.35.1

Thanks,

Tomer

author maintainer
#3 lore raw
Quoted 10 lines · Tomer Maimon

Hi Jonathan,

Thanks for your patch.

Quoted 5 lines · Joel Stanley
Quoted 3 lines · Jonathan Neuschäfer

Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision.

[...]

Quoted 11 lines
Quoted 11 lines

drivers/soc/nuvoton/Kconfig line 5

Quoted 7 lines

+++ b/drivers/soc/nuvoton/Kconfig

drivers/soc/nuvoton/Kconfig new file +5 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+menuconfig WPCM450_SOC
+       tristate "Nuvoton WPCM450 SoC driver"
+       default y if ARCH_WPCM450
+       select SOC_BUS

Sorry for not noticing this earlier. This is a bit confusing. If we have a menu option, the soc driver should appear under it. Or we could do without the menu all together, as there's only one driver so far.

Good point.

Quoted 2 lines
Quoted 2 lines

We also should select REGMAP, as you're using it,

I'll add it.

Quoted 4 lines
Quoted 4 lines

and hide the option behind ARCH_WPCM450 || COMPILE_TEST.

How about this:

Quoted 8 lines
Quoted 1 line

if ARCH_WPCM450 || COMPILE_TEST

These days we working on LPC BPC driver for NPCM7xx and NPCM8xx that will be placed in nuvoton soc folder.
we will use:

if ARCH_NPCM || COMPILE_TEST

menu "NPCM SoC drivers"

That sounds reasonable, I'll do something similar.

Quoted 4 lines

Maybe you should remove
if ARCH_WPCM450 || COMPILE_TEST

and add ARCH_WPCM450 dependency in the WPCM450_SOCINFO driver configuration.

The WPCM450_SOCINFO driver would build fine on other NPCM SoC, it just wouldn't be very useful, so I think the current "default y if ARCH_WPCM450" solution is sufficient.

Quoted 11 lines
Quoted 11 lines

config WPCM450_SOCINFO
tristate "Nuvoton WPCM450 SoC driver"
default y if ARCH_WPCM450
select SOC_BUS
select REGMAP
help
Say Y here to compile the SoC information driver for Nuvoton WPCM450 SoCs.

Quoted 4 lines
Quoted 4 lines

This driver provides information such as the SoC model and revision.

endif

Thank you both,
Jonathan