[PATCH 2/3] nvmem: Add read-only SpacemiT K3 eFuse support

Yao Zi me at ziyao.cc
Fri Nov 6 20:22:32 PST 2026


On Fri, Nov 06, 2026 at 02:05:24PM +0800, Jiayu Du wrote:
> Add read-only NVMEM access to bank 0 and bank 7 of the SpacemiT K3 eFuse
> controller. These banks contain temperature calibration parameters and
> other configuration data.
> 
> Snapshot the shadow registers with aligned 32-bit reads and expose the
> data in little-endian order at controller-relative offsets. Serve reads
> from the snapshot and use keepouts for the remaining register ranges.
> Keep the AES_WTM clock enabled and its shared reset deasserted while the
> provider is registered.
> 
> Signed-off-by: Jiayu Du <duge1256 at gmail.com>
> ---
>  MAINTAINERS                       |   1 +
>  drivers/nvmem/Kconfig             |  14 +++
>  drivers/nvmem/Makefile            |   1 +
>  drivers/nvmem/spacemit-k3-efuse.c | 151 ++++++++++++++++++++++++++++++
>  4 files changed, 167 insertions(+)
>  create mode 100644 drivers/nvmem/spacemit-k3-efuse.c

...

> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index d2f5bb236663..28d6c59fbd74 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -476,6 +476,20 @@ config NVMEM_SNVS_LPGPR
>  	  This driver can also be built as a module. If so, the module
>  	  will be called nvmem-snvs-lpgpr.
>  
> +config NVMEM_SPACEMIT_K3_EFUSE
> +	tristate "SpacemiT K3 eFuse support"
> +	depends on ARCH_SPACEMIT || COMPILE_TEST
> +	depends on OF && HAS_IOMEM
> +	depends on COMMON_CLK && RESET_CONTROLLER
> +	help
> +	  Say Y here to read configuration and calibration data from the
> +	  SpacemiT K3 eFuse shadow banks. The boot firmware must have loaded
> +	  the shadow registers before Linux starts. Programming and reloading
> +	  the fuses are not supported.

I didn't read K3's TRM, but is there a reason to depend on the
bootloader to do so? We should depend on the state set up by bootloaders
as less as possible, I think.

> +	  This driver can also be built as a module. If so, the module will
> +	  be called spacemit-k3-efuse.
> +

...

> diff --git a/drivers/nvmem/spacemit-k3-efuse.c b/drivers/nvmem/spacemit-k3-efuse.c
> new file mode 100644
> index 000000000000..d106053beae8
> --- /dev/null
> +++ b/drivers/nvmem/spacemit-k3-efuse.c

...

> +static int k3_efuse_probe(struct platform_device *pdev)
> +{

...

> +	for (bank = 0; bank < ARRAY_SIZE(k3_efuse_bank_offsets); bank++) {
> +		for (i = 0; i < K3_EFUSE_BANK_SIZE; i += sizeof(u32)) {
> +			u32 val = readl(base + k3_efuse_bank_offsets[bank] + i);
> +
> +			put_unaligned_le32(val, efuse->data[bank] + i);

Does memcpy_fromio() works for the device? Otherwise, you could define
efuse->data as an array of u32 instead of u8, so it keeps aligned and
you could do a simple assignment here. Reading from efuse->data is
always ok since memcpy() is used.

> +		}
> +	}

Regards,
Yao Zi



More information about the linux-riscv mailing list