Re: [PATCH 1/1] hwmon: (spd5118) support write protected devices

From: Guenter Roeck

Date: Mon Sep 21 2026 - 10:33:33 EST


On Sun, Sep 20, 2026 at 02:22:24PM +0800, Kean Ren wrote:
> Some systems do not allow writes to SPD devices. On the i801 SMBus
> controller family this happens when the BIOS sets SPD Write Disable, in
> which case the controller refuses writes to addresses 0x50-0x57; other
> platforms may enforce the same in firmware. There is no way for the driver
> to query this.
>
> spd5118 assumes that it can write to the device, which does not hold on
> such systems:
>
> - writes to the hwmon attributes always fail with -ENXIO
> - the temperature sensor disable in spd5118_suspend() fails silently
> - spd5118_resume() fails in regcache_sync(), and the system reports
>
> spd5118 0-0050: Failed to write b = 0: -6
> spd5118 0-0050: PM: failed to resume async: error -6
>
> Register 0xb in that message is the page selector register, which regmap
> writes back from its cache at the end of regcache_sync(). The write of the
> saved configuration register before that fails as well, but the cache code
> does not report that error.
>
> Detect write protection once at probe time by writing the page selector
> register back with the value just read from it. This is a no-op on a device
> which accepts writes, and it fails if writes are blocked.
>
> If writes are not possible, run the device read-only: drop the register
> cache so that regcache_sync() cannot attempt any write, skip the writes in
> the suspend and resume callbacks, and make the writable attributes read
> only. Alarm attributes are read only already; stop clearing a latched
> status from them, since that requires a write, and report the condition as
> the device presents it.
>
> Reading the SPD NVRAM beyond the first page requires switching pages, which
> is itself a write. Restrict the 'eeprom' attribute to the page which can be
> read in that case, instead of returning errors for the accessible part.
>

It doesn't add value to only return page 0 of NVMEM.

> The temperature sensor remains fully usable; only its configuration
> becomes read-only. Document that, and leave the shared regmap
> configuration alone by selecting a separate one without a register
> cache.
>

I had thought about implementing read-only mode, but there is no guarantee
that the BIOS doesn't select a different page during a suspend/resume
cycle. For that reason, the read-only mode can not be supported.
Sorry, I am not going to apply this patch.

Thanks,
Guenter