[PATCH v2] soc: nuvoton: Add SoC info driver for WPCM450

Jonathan Neuschäfer j.neuschaefer at gmx.net
Fri Apr 15 03:02:27 AEST 2022


On Sat, Apr 09, 2022 at 07:55:09PM +0200, Paul Menzel wrote:
> Dear Jonathan,
> 
> 
> Thank you for your patch.
> 
> Am 09.04.22 um 19:33 schrieb Jonathan Neuschäfer:
> > 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.


> 
> > Signed-off-by: Jonathan Neuschäfer <j.neuschaefer at gmx.net>
> > Reviewed-by: Joel Stanley <joel at jms.id.au>
> > ---
[...]
> > +#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 int`s

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.

> 
> > +	const char *name;
> > +};
> > +
> > +const struct revision revisions[] __initconst = {

Unrelated to your comments, I noticed that this table can and should be
declared static.

> > +	{ 0x00, "Z1" },
> > +	{ 0x03, "Z2" },
> > +	{ 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.

To avoid unexpected silent truncation that sort of makes sense.
> 
> > +
> > +	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)
> > +{
[...]
> > +
> > +	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.

> 
> > +	if (!revision) {
> > +		pr_warn("Unknown chip revision in GCR.PDID: 0x%02x\n", PDID_REV(pdid));
> > +		return -ENODEV;
> > +	}
[...]
> > 
> 
> Reviewed-by: Paul Menzel <pmenzel at molgen.mpg.de>

Thank you!

Jonathan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20220414/f1bcfd3a/attachment.sig>


More information about the openbmc mailing list