soc: nuvoton: Add SoC info driver for WPCM450
Jonathan Neuschäfer
maintainerPATCH v2 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.
---
v2:
- 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 | 90 +++++++++++++++++++++++++++++++ 5 files changed, 105 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
@@ -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/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -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 += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/nuvoton/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +menuconfig WPCM450_SOC + bool "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
@@ -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 +90 -0
90 lines not on this page · raw message
--
2.35.1
Dear Jonathan,
Thank you for your patch.
Am 09.04.22 um 19:33 schrieb Jonathan Neuschäfer:
Quoted 2 lines
Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision.
Maybe add an example command, how to read the model and revision.
Quoted 86 lines
Signed-off-by Jonathan Neuschäfer <[email protected]>Reviewed-by Joel Stanley <[email protected]>---
v2:
- Add R-b tag
- rebase on 5.18-rc1v1:
- 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 | 90 +++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+)create mode 100644
drivers/soc/nuvoton/Kconfigcreate mode 100644drivers/soc/nuvoton/Makefilecreate mode 100644drivers/soc/nuvoton/wpcm450-soc.cdrivers/soc/Kconfig +1
-0@@ -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/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"drivers/soc/Makefile +1
-0@@ -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 += amlogic/ obj-y += qcom/ obj-y += renesas/drivers/soc/nuvoton/Kconfig new file +11
-0@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +menuconfig WPCM450_SOC + bool "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@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_WPCM450_SOC) += wpcm450-soc.odrivers/soc/nuvoton/wpcm450-soc.c new file +10
-0@@ -0,0 +1,90 @@ +// 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>
drivers/soc/nuvoton/wpcm450-soc.c line 20
Quoted 10 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +10
-0+#include <linux/sys_soc.h> +#include <linux/slab.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;
Can this be just be unsigned ints
Quoted 6 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +6
-0+const char *name; +}; + +const struct revision revisions[]__initconst = { + {0x00 ,"Z1" }, + {0x03 ,"Z2" },
drivers/soc/nuvoton/wpcm450-soc.c line 36
Quoted 10 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +10
-0+ { 0x04, "Z21" }, + { 0x08, "A1" }, + { 0x09, "A2" }, + { 0x0a, "A3" }, + {} +}; + +static const char *__init get_revision (u8 rev) +{ +int i;
I’d do unsigned int, though it does not make a difference in the end result.
Quoted 22 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +22
-0+ +for (i =0 ; revisions[i].name; i++) +if (revisions[i].number == rev) +return revisions[i].name; +return NULL ; +} + +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);
drivers/soc/nuvoton/wpcm450-soc.c line 68
Quoted 10 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +10
-0+ 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));
The signature of get_revision() is u8, but you pass u32, if I am not mistaken.
Quoted 23 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +22
-1+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); + } + +return 0 ; +} +device_initcall (wpcm450_soc_init); --
Quoted 2 lines
2.35.1
Kind regards,
Paul
Jonathan Neuschäfer
maintainerQuoted 10 lines · Paul Menzel
Dear Jonathan,
Thank you for your patch.
Am 09.04.22 um 19:33 schrieb Jonathan Neuschäfer:
Quoted 2 lines
Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision.
Maybe add an example command, how to read the model and revision.
Will do.
Quoted 4 lines
Quoted 4 lines
Signed-off-by Jonathan Neuschäfer <[email protected]>Reviewed-by Joel Stanley <[email protected]>---
[...]
Quoted 9 lines
drivers/soc/nuvoton/wpcm450-soc.c line 20
Quoted 7 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +7
-0+#define GCR_PDID 0 +#define PDID_CHIP (x) ((x) & 0x00ffffff) +#define CHIP_WPCM450 0x926450 +#define PDID_REV (x) ((x) >> 24) + +struct revision { +u8 number;Can this be just be
unsigned ints
It could be, but it's unnecessary because I'm dealing with a 8-bit value here.
The same amount of space is used in the struct whether I declare the value as unsigned int or as u8, but with u8 it's clearer that it's really (always) just an 8-bit value.
Quoted 5 lines
drivers/soc/nuvoton/wpcm450-soc.c line 24
Quoted 5 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +4
-0+const char *name; +}; + +const struct revision revisions[]__initconst = {
Unrelated to your comments, I noticed that this table can and should be declared static.
Quoted 7 lines
Quoted 7 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +7
-0+ { 0x00, "Z1" }, + { 0x03, "Z2" }, + { 0x04, "Z21" }, + { 0x08, "A1" }, + { 0x09, "A2" }, + { 0x0a, "A3" }, + {}
Quoted 8 lines
drivers/soc/nuvoton/wpcm450-soc.c line 36
Quoted 5 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +5
-0+}; + +static const char *__init get_revision (u8 rev) +{ +int i;I’d do
unsigned int, though it does not make a difference in the end result.
To avoid unexpected silent truncation that sort of makes sense.
Quoted 10 lines
Quoted 10 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +9
-0+ +for (i =0 ; revisions[i].name; i++) +if (revisions[i].number == rev) +return revisions[i].name; +return NULL ; +} + +static int __init wpcm450_soc_init (void ) +{
[...]
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + revision = get_revision(PDID_REV(pdid));The signature of
get_revision()is u8, but you pass u32, if I am not mistaken.
The truncation to u8 is fine in this case, because PDID_REV extracts an 8 bit value and the upper 24 bits of the result of PDID_REV are thus always already zero.
Quoted 5 lines
Quoted 5 lines
drivers/soc/nuvoton/wpcm450-soc.c new file +4
-0+if (!revision) { +pr_warn ("Unknown chip revision in GCR.PDID: 0x%02x\n" ,PDID_REV (pdid)); +return -ENODEV ; + }
[...]
Quoted 3 lines
Quoted 1 line
Reviewed-by Paul Menzel <[email protected]>
Thank you!
Jonathan