LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Jonathan Neuschäfer" <j.ne@posteo.net>
To: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Cc: "Srinivas Kandagatla" <srinivas.kandagatla@linaro.org>,
	linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org,
	"Ash Logan" <ash@heyquark.com>,
	"Jonathan Neuschäfer" <j.ne@posteo.net>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Paul Mackerras" <paulus@samba.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/4] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP
Date: Sat, 26 Jun 2021 23:24:07 +0000	[thread overview]
Message-ID: <YNe3F7DPOOKuaFIm@latitude> (raw)
In-Reply-To: <20210519095044.4109-2-linkmauve@linkmauve.fr>

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

Hi,


On Wed, May 19, 2021 at 11:50:41AM +0200, Emmanuel Gil Peyrot wrote:
> This OTP is read-only and contains various keys used by the console to
> decrypt, encrypt or verify various pieces of storage.
> 
> Its size depends on the console, it is 128 bytes on the Wii and
> 1024 bytes on the Wii U (split into eight 128 bytes banks).
> 
> It can be used directly by writing into one register and reading from
> the other one, without any additional synchronisation.
> 
> Signed-off-by: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
> ---

A link to the (third-party) documentation would be nice, either in the
commit message or in the code itself.

(https://wiiubrew.org/wiki/Hardware/OTP i guess)

[...]
> +static int nintendo_otp_reg_read(void *context,
> +				 unsigned int reg, void *_val, size_t bytes)
> +{
> +	struct nintendo_otp_priv *priv = context;
> +	u32 *val = _val;
> +	int words = bytes >> 2;
> +	u32 bank, addr;
> +
> +	while (words--) {
> +		bank = (reg << 1) & ~0xff;

This is a bit non-obvious, IMHO. As far as I understand it, the expanded
formula is:

	bank = (reg / 128) << 8;

I.e. first divide by bank size, then shift the parameter into the right
place.

> +		addr = (reg >> 2) & 0x1f;

Here, I think it's about the word size (4 bytes); I think / 4 would be
clearer.

I *think* (but haven't checked) that gcc should generate efficent shifts
for the divisions above, so using the division operator shouldn't be
problem.

> +		iowrite32be(OTP_READ | bank | addr, priv->regs + HW_OTPCMD);
> +		*val++ = ioread32be(priv->regs + HW_OTPDATA);
> +		reg += 4;
> +	}
> +
> +	return 0;
> +}
> +
[...]
> +	if (of_id->data) {
> +		const struct nintendo_otp_devtype_data *data = of_id->data;
> +		config.name = data->name;
> +		config.size = data->num_banks * 128;

Given that 128 appears a few times, perhaps a #define would be good.

> +	}
> +
> +	config.dev = dev;
> +	config.priv = priv;
> +
> +	nvmem = devm_nvmem_register(dev, &config);
> +
> +	return PTR_ERR_OR_ZERO(nvmem);
> +}
> +
> +static struct platform_driver nintendo_otp_driver = {
> +	.probe = nintendo_otp_probe,
> +	.driver = {
> +		.name = "nintendo-otp",
> +		.of_match_table = nintendo_otp_of_table,
> +	},
> +};
> +module_platform_driver(nintendo_otp_driver);
> +MODULE_AUTHOR("Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>");
> +MODULE_DESCRIPTION("Nintendo Wii and Wii U OTP driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> 2.31.1
> 

Tested-by: Jonathan Neuschäfer <j.ne@posteo.net>  # on Wii



Thanks,
Jonathan Neuschäfer

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

  reply	other threads:[~2021-06-26 23:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19  9:50 [PATCH v2 0/4] " Emmanuel Gil Peyrot
2021-05-19  9:50 ` [PATCH v2 1/4] " Emmanuel Gil Peyrot
2021-06-26 23:24   ` Jonathan Neuschäfer [this message]
2021-05-19  9:50 ` [PATCH v2 2/4] dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support Emmanuel Gil Peyrot
2021-05-21  1:37   ` Rob Herring
2021-06-26 21:27   ` Jonathan Neuschäfer
2021-05-19  9:50 ` [PATCH v2 3/4] powerpc: wii.dts: Expose the OTP on this platform Emmanuel Gil Peyrot
2021-06-26 23:34   ` Jonathan Neuschäfer
2021-07-01 19:56     ` Emmanuel Gil Peyrot
2021-07-02  8:56       ` Jonathan Neuschäfer
2021-07-03 15:53         ` Segher Boessenkool
2021-05-19  9:50 ` [PATCH v2 4/4] powerpc: wii_defconfig: Enable OTP by default Emmanuel Gil Peyrot
2021-06-26 23:38   ` Jonathan Neuschäfer
2021-07-01 22:57 ` [PATCH v3 0/5] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP Emmanuel Gil Peyrot
2021-07-01 22:57   ` [PATCH v3 1/5] " Emmanuel Gil Peyrot
2021-07-01 22:57   ` [PATCH v3 2/5] dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support Emmanuel Gil Peyrot
2021-07-14 22:51     ` Rob Herring
2021-07-01 22:57   ` [PATCH v3 3/5] powerpc: wii.dts: Reduce the size of the control area Emmanuel Gil Peyrot
2021-07-01 22:57   ` [PATCH v3 4/5] powerpc: wii.dts: Expose the OTP on this platform Emmanuel Gil Peyrot
2021-07-01 22:57   ` [PATCH v3 5/5] powerpc: wii_defconfig: Enable OTP by default Emmanuel Gil Peyrot
2021-08-01  7:38   ` [PATCH v4 0/5] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP Emmanuel Gil Peyrot
2021-08-01  7:38     ` [PATCH v4 1/5] " Emmanuel Gil Peyrot
2021-08-01  7:38     ` [PATCH v4 2/5] dt-bindings: nintendo-otp: Document the Wii and Wii U OTP support Emmanuel Gil Peyrot
2021-08-06 21:07       ` Rob Herring
2021-08-01  7:38     ` [PATCH v4 3/5] powerpc: wii.dts: Reduce the size of the control area Emmanuel Gil Peyrot
2021-08-01  7:38     ` [PATCH v4 4/5] powerpc: wii.dts: Expose the OTP on this platform Emmanuel Gil Peyrot
2021-08-01  7:38     ` [PATCH v4 5/5] powerpc: wii_defconfig: Enable OTP by default Emmanuel Gil Peyrot
2021-08-10 10:57     ` [PATCH v4 0/5] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP Srinivas Kandagatla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YNe3F7DPOOKuaFIm@latitude \
    --to=j.ne@posteo.net \
    --cc=ash@heyquark.com \
    --cc=benh@kernel.crashing.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linkmauve@linkmauve.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --subject='Re: [PATCH v2 1/4] nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox