linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450
@ 2022-11-03 21:34 Jonathan Neuschäfer
  2023-02-10 10:26 ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Neuschäfer @ 2022-11-03 21:34 UTC (permalink / raw)
  To: openbmc, Joel Stanley, Tomer Maimon
  Cc: Jonathan Neuschäfer, Paul Menzel, Arnd Bergmann,
	Hitomi Hasegawa, Linus Walleij, Conor Dooley, Hector Martin,
	Robert Jarzmik, Nicolas Ferre, Brian Norris, Sven Peter,
	linux-kernel

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

Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
v6:
- Select REGMAP
- Rearrange Kconfig structure a bit

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/20220409173319.2491196-1-j.neuschaefer@gmx.net/
- Add R-b tag
- rebase on 5.18-rc1

v1:
- https://lore.kernel.org/lkml/20220129143316.2321460-1-j.neuschaefer@gmx.net/
---
 drivers/soc/Kconfig               |   1 +
 drivers/soc/Makefile              |   1 +
 drivers/soc/nuvoton/Kconfig       |  17 +++++
 drivers/soc/nuvoton/Makefile      |   2 +
 drivers/soc/nuvoton/wpcm450-soc.c | 109 ++++++++++++++++++++++++++++++
 5 files changed, 130 insertions(+)
 create mode 100644 drivers/soc/nuvoton/Kconfig
 create mode 100644 drivers/soc/nuvoton/Makefile
 create mode 100644 drivers/soc/nuvoton/wpcm450-soc.c

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e461c071189b4..f17764a7e5884 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -15,6 +15,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"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 69ba6508cf2c1..9f92506854852 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -20,6 +20,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/
diff --git a/drivers/soc/nuvoton/Kconfig b/drivers/soc/nuvoton/Kconfig
new file mode 100644
index 0000000000000..2167d3d739d84
--- /dev/null
+++ b/drivers/soc/nuvoton/Kconfig
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+menu "Nuvoton SoC drivers"
+	depends on ARCH_NPCM || COMPILE_TEST
+
+config WPCM450_SOC
+	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.
+
+endmenu
diff --git a/drivers/soc/nuvoton/Makefile b/drivers/soc/nuvoton/Makefile
new file mode 100644
index 0000000000000..e30317b4e8290
--- /dev/null
+++ b/drivers/soc/nuvoton/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_WPCM450_SOC)	+= wpcm450-soc.o
diff --git a/drivers/soc/nuvoton/wpcm450-soc.c b/drivers/soc/nuvoton/wpcm450-soc.c
new file mode 100644
index 0000000000000..c5e0d11c383b1
--- /dev/null
+++ b/drivers/soc/nuvoton/wpcm450-soc.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450
  2022-11-03 21:34 [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450 Jonathan Neuschäfer
@ 2023-02-10 10:26 ` Geert Uytterhoeven
  2023-02-11  1:02   ` Jonathan Neuschäfer
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2023-02-10 10:26 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: openbmc, Joel Stanley, Tomer Maimon, Paul Menzel, Arnd Bergmann,
	Hitomi Hasegawa, Linus Walleij, Conor Dooley, Hector Martin,
	Robert Jarzmik, Nicolas Ferre, Brian Norris, Sven Peter,
	linux-kernel

Hi Jonathan,

On Thu, Nov 3, 2022 at 10:37 PM Jonathan Neuschäfer
<j.neuschaefer@gmx.net> wrote:
> 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
>
> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> Reviewed-by: Joel Stanley <joel@jms.id.au>
> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
> ---
> v6:
> - Select REGMAP
> - Rearrange Kconfig structure a bit

Thanks for your patch!

Unfortunately Joel seems to have sent v5 to Arnd instead of v6?
https://lore.kernel.org/all/20230201051717.1005938-1-joel@jms.id.au

Which is now commit 7dbb4a38bff34493 ("soc:
nuvoton: Add SoC info driver for WPCM450") in soc/for-next...

> --- /dev/null
> +++ b/drivers/soc/nuvoton/Kconfig
> @@ -0,0 +1,17 @@
> +# SPDX-License-Identifier: GPL-2.0
> +menu "Nuvoton SoC drivers"
> +       depends on ARCH_NPCM || COMPILE_TEST

... and lacks the above dependency, hence appearing on my radar.

> +
> +config WPCM450_SOC
> +       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.
> +
> +endmenu

Do you plan to send a follow-up patch?
Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450
  2023-02-10 10:26 ` Geert Uytterhoeven
@ 2023-02-11  1:02   ` Jonathan Neuschäfer
  2023-02-11  9:33     ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Neuschäfer @ 2023-02-11  1:02 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jonathan Neuschäfer, openbmc, Joel Stanley, Tomer Maimon,
	Paul Menzel, Arnd Bergmann, Hitomi Hasegawa, Linus Walleij,
	Conor Dooley, Hector Martin, Robert Jarzmik, Nicolas Ferre,
	Brian Norris, Sven Peter, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2346 bytes --]

On Fri, Feb 10, 2023 at 11:26:28AM +0100, Geert Uytterhoeven wrote:
> Hi Jonathan,
> 
> On Thu, Nov 3, 2022 at 10:37 PM Jonathan Neuschäfer
> <j.neuschaefer@gmx.net> wrote:
> > 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
> >
> > Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> > Reviewed-by: Joel Stanley <joel@jms.id.au>
> > Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
> > ---
> > v6:
> > - Select REGMAP
> > - Rearrange Kconfig structure a bit
> 
> Thanks for your patch!
> 
> Unfortunately Joel seems to have sent v5 to Arnd instead of v6?
> https://lore.kernel.org/all/20230201051717.1005938-1-joel@jms.id.au
> 
> Which is now commit 7dbb4a38bff34493 ("soc:
> nuvoton: Add SoC info driver for WPCM450") in soc/for-next...
> 
> > --- /dev/null
> > +++ b/drivers/soc/nuvoton/Kconfig
> > @@ -0,0 +1,17 @@
> > +# SPDX-License-Identifier: GPL-2.0
> > +menu "Nuvoton SoC drivers"
> > +       depends on ARCH_NPCM || COMPILE_TEST
> 
> ... and lacks the above dependency, hence appearing on my radar.
> 
> > +
> > +config WPCM450_SOC
> > +       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.
> > +
> > +endmenu
> 
> Do you plan to send a follow-up patch?

Yes, hopefully I'll get around to it a few days after rc1, when the dust
of the (upcoming) merge window has settled a bit.

Or should I rather send it earlier?

Jonathan

> Thanks!
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450
  2023-02-11  1:02   ` Jonathan Neuschäfer
@ 2023-02-11  9:33     ` Geert Uytterhoeven
  2023-02-11 20:13       ` Jonathan Neuschäfer
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2023-02-11  9:33 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: openbmc, Joel Stanley, Tomer Maimon, Paul Menzel, Arnd Bergmann,
	Hitomi Hasegawa, Linus Walleij, Conor Dooley, Hector Martin,
	Robert Jarzmik, Nicolas Ferre, Brian Norris, Sven Peter,
	linux-kernel

Hi Jonathan,

On Sat, Feb 11, 2023 at 2:03 AM Jonathan Neuschäfer
<j.neuschaefer@gmx.net> wrote:
> On Fri, Feb 10, 2023 at 11:26:28AM +0100, Geert Uytterhoeven wrote:
> > On Thu, Nov 3, 2022 at 10:37 PM Jonathan Neuschäfer
> > <j.neuschaefer@gmx.net> wrote:
> > > 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
> > >
> > > Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> > > Reviewed-by: Joel Stanley <joel@jms.id.au>
> > > Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
> > > ---
> > > v6:
> > > - Select REGMAP
> > > - Rearrange Kconfig structure a bit
> >
> > Thanks for your patch!
> >
> > Unfortunately Joel seems to have sent v5 to Arnd instead of v6?
> > https://lore.kernel.org/all/20230201051717.1005938-1-joel@jms.id.au
> >
> > Which is now commit 7dbb4a38bff34493 ("soc:
> > nuvoton: Add SoC info driver for WPCM450") in soc/for-next...
> >
> > > --- /dev/null
> > > +++ b/drivers/soc/nuvoton/Kconfig
> > > @@ -0,0 +1,17 @@
> > > +# SPDX-License-Identifier: GPL-2.0
> > > +menu "Nuvoton SoC drivers"
> > > +       depends on ARCH_NPCM || COMPILE_TEST
> >
> > ... and lacks the above dependency, hence appearing on my radar.
> >
> > > +
> > > +config WPCM450_SOC
> > > +       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.
> > > +
> > > +endmenu
> >
> > Do you plan to send a follow-up patch?
>
> Yes, hopefully I'll get around to it a few days after rc1, when the dust
> of the (upcoming) merge window has settled a bit.
>
> Or should I rather send it earlier?

I'd say sooner rather than later.
If I hadn't found your v6, I would have sent a patch myself to add the
dependency.

Does the "select REGMAP" fix a build issue? If yes, that's a very good
reason to send it now...

Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450
  2023-02-11  9:33     ` Geert Uytterhoeven
@ 2023-02-11 20:13       ` Jonathan Neuschäfer
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Neuschäfer @ 2023-02-11 20:13 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jonathan Neuschäfer, openbmc, Joel Stanley, Tomer Maimon,
	Paul Menzel, Arnd Bergmann, Hitomi Hasegawa, Linus Walleij,
	Conor Dooley, Hector Martin, Robert Jarzmik, Nicolas Ferre,
	Brian Norris, Sven Peter, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1531 bytes --]

On Sat, Feb 11, 2023 at 10:33:05AM +0100, Geert Uytterhoeven wrote:
> Hi Jonathan,
> 
> On Sat, Feb 11, 2023 at 2:03 AM Jonathan Neuschäfer
> <j.neuschaefer@gmx.net> wrote:
> > On Fri, Feb 10, 2023 at 11:26:28AM +0100, Geert Uytterhoeven wrote:
> > > On Thu, Nov 3, 2022 at 10:37 PM Jonathan Neuschäfer
> > > <j.neuschaefer@gmx.net> wrote:
> > > > Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides
> > > > information such as the SoC revision.
[...]
> > > > +config WPCM450_SOC
> > > > +       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.
> > > > +
> > > > +endmenu
> > >
> > > Do you plan to send a follow-up patch?
> >
> > Yes, hopefully I'll get around to it a few days after rc1, when the dust
> > of the (upcoming) merge window has settled a bit.
> >
> > Or should I rather send it earlier?
> 
> I'd say sooner rather than later.
> If I hadn't found your v6, I would have sent a patch myself to add the
> dependency.

Ok, I'll send it today.

> 
> Does the "select REGMAP" fix a build issue? If yes, that's a very good
> reason to send it now...

Unfortunately I wasn't able to find the build issue report.


Jonathan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-02-11 20:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 21:34 [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450 Jonathan Neuschäfer
2023-02-10 10:26 ` Geert Uytterhoeven
2023-02-11  1:02   ` Jonathan Neuschäfer
2023-02-11  9:33     ` Geert Uytterhoeven
2023-02-11 20:13       ` Jonathan Neuschäfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).