Skip to contentSkip to conversation

hwmon: (spd5118) Explicitly enable temperature sensor in probe function

PATCH In review Guenter Roeck 3 participants 5 messages Jan 31 – Feb 4 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (spd5118) Explicitly enable temperature sensor in probe function

Instantiating the driver does not make sense if the temperature sensor is disabled, so enable it unconditionally in the probe function.

If that fails, write operations to the chip are likely disabled by the I2C controller. Bail out with an error message if that happens.

Cc Armin Wolf <[email protected]>
Cc Kurt Borja <[email protected]>
Cc Tinsae Tadesse <[email protected]>
---
 drivers/hwmon/spd5118.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/hwmon/spd5118.c +14 -0
index 5da44571b6a0..d8834d4d980b 100644
@@ -552,6 +552,20 @@ static int spd5118_common_probe(struct device *dev, struct regmap *regmap,
 	if (!spd5118_vendor_valid(bank, vendor))
 		return -ENODEV;
 
+	/*
+	 * Some I2C controllers write protect the address range used by SPD5118
+	 * compliant chips. This makes the chips effectively unaccessible since
+	 * the driver needs to be able to set the page in the legacy mode
+	 * register, and it needs to be able to disable the temperature sensor
+	 * during suspend. Check if writes to the chip are possible by
+	 * explicitly enabling the temperature sensor. Bail out if that fails.
+	 */
+	err = regmap_write_bits(regmap, SPD5118_REG_TEMP_CONFIG,
+				SPD5118_TS_DISABLE, 0);
+	if (err)
+		return dev_err_probe(dev, err,
+				     "Failed to enable temperature sensor (write protected ?)\n");
+
 	data->regmap = regmap;
 	mutex_init(&data->nvmem_lock);
 	dev_set_drvdata(dev, data);
Signature · 1 line
2.45.2
#1 lore raw
Quoted 41 lines · Guenter Roeck

Instantiating the driver does not make sense if the temperature sensor is disabled, so enable it unconditionally in the probe function.

If that fails, write operations to the chip are likely disabled by the I2C controller. Bail out with an error message if that happens.

Cc Armin Wolf <[email protected]>
Cc Kurt Borja <[email protected]>
Cc Tinsae Tadesse <[email protected]>
---
 drivers/hwmon/spd5118.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/hwmon/spd5118.c +14 -1
index 5da44571b6a0..d8834d4d980b 100644
@@ -552,6 +552,20 @@ static int spd5118_common_probe(struct device *dev, struct regmap *regmap,
        if (!spd5118_vendor_valid(bank, vendor))
                return -ENODEV;
 
+       /*
+        * Some I2C controllers write protect the address range used by SPD5118
+        * compliant chips. This makes the chips effectively unaccessible since
+        * the driver needs to be able to set the page in the legacy mode
+        * register, and it needs to be able to disable the temperature sensor
+        * during suspend. Check if writes to the chip are possible by
+        * explicitly enabling the temperature sensor. Bail out if that fails.
+        */
+       err = regmap_write_bits(regmap, SPD5118_REG_TEMP_CONFIG,
+                               SPD5118_TS_DISABLE, 0);
+       if (err)
+               return dev_err_probe(dev, err,
+                                    "Failed to enable temperature sensor (write protected ?)\n");
+
        data->regmap = regmap;
        mutex_init(&data->nvmem_lock);
        dev_set_drvdata(dev, data);
--
Quoted 2 lines

2.45.2

Hi Guenter,

Tested this patch on my system, and it actually fixes the issue.

[   11.523971] i2c-core: driver [spd5118] registered
[   28.040686] i801_smbus 0000:00:1f.4: SPD Write Disable is set
[   28.041003] i801_smbus 0000:00:1f.4: SMBus using PCI interrupt
[   28.078412] i801_smbus 0000:00:1f.4: No response
[   28.078643] i801_smbus 0000:00:1f.4: No response
[   28.082927] i2c i2c-14: Creating spd5118 at 0x52
[   28.087685] spd5118 14-0052: probe
[   28.092707] i801_smbus 0000:00:1f.4: No response
[   28.092736] spd5118 14-0052: error -ENXIO: Failed to enable
temperature sensor (write protected ?)
[   28.094709] i2c i2c-14: client [spd5118] registered with bus id 14-0052
[   28.094936] i801_smbus 0000:00:1f.4: No response
[   28.095143] i801_smbus 0000:00:1f.4: No response
[   28.095351] i801_smbus 0000:00:1f.4: No response
[   28.095558] i801_smbus 0000:00:1f.4: No response
[   28.095757] i801_smbus 0000:00:1f.4: No response
[   28.095956] i801_smbus 0000:00:1f.4: No response
[   28.096153] i801_smbus 0000:00:1f.4: No response
[   28.097139] i801_smbus 0000:00:1f.4: No response
[   28.097361] i801_smbus 0000:00:1f.4: No response
[   28.097567] i801_smbus 0000:00:1f.4: No response
[   78.689689] PM: suspend entry (s2idle)
[   80.616943] ACPI: EC: interrupt blocked
[   86.510434] ACPI: EC: interrupt unblocked
[   88.175249] PM: suspend exit
#2 lore raw
In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

Instantiating the driver does not make sense if the temperature sensor is disabled, so enable it unconditionally in the probe function.

If that fails, write operations to the chip are likely disabled by the I2C controller. Bail out with an error message if that happens.

Hi Guenter,

As I mentiond in the other thread, after applying this patch the probe fails

spd5118 17-0051: error -ENXIO: Failed to enable temperature sensor (write protected ?) spd5118 17-0053: error -ENXIO: Failed to enable temperature sensor (write protected ?)

This would be a regression in my platform because, even though the register is write protected, I can still get temperature readings just fine (even after the resume error).

Signature · 2 lines
Thanks,
 ~ Kurt
author maintainer
#3 lore raw
Quoted 12 lines · Kurt Borja
Quoted 5 lines · Guenter Roeck

Instantiating the driver does not make sense if the temperature sensor is disabled, so enable it unconditionally in the probe function.

If that fails, write operations to the chip are likely disabled by the I2C controller. Bail out with an error message if that happens.

Hi Guenter,

As I mentiond in the other thread, after applying this patch the probe fails

Quoted 7 lines

spd5118 17-0051: error -ENXIO: Failed to enable temperature sensor (write protected ?) spd5118 17-0053: error -ENXIO: Failed to enable temperature sensor (write protected ?)

This would be a regression in my platform because, even though the register is write protected, I can still get temperature readings just fine (even after the resume error).

Yes, but after the next BIOS update it might not work anymore, and it is impossible to suspend the system. On top of that, it instantiates the spd eeprom which can not really be accessed because that code _does_ need to write into the chip.

There is no safe way for a spd5118 compliant chip to be accessed reliably with write protection active. There is nothing we can do about that.

Guenter

#4 lore raw
Quoted 26 lines · Guenter Roeck
Quoted 12 lines · Kurt Borja
Quoted 5 lines · Guenter Roeck

Instantiating the driver does not make sense if the temperature sensor is disabled, so enable it unconditionally in the probe function.

If that fails, write operations to the chip are likely disabled by the I2C controller. Bail out with an error message if that happens.

Hi Guenter,

As I mentiond in the other thread, after applying this patch the probe fails

Quoted 7 lines

spd5118 17-0051: error -ENXIO: Failed to enable temperature sensor (write protected ?) spd5118 17-0053: error -ENXIO: Failed to enable temperature sensor (write protected ?)

This would be a regression in my platform because, even though the register is write protected, I can still get temperature readings just fine (even after the resume error).

Yes, but after the next BIOS update it might not work anymore, and it is impossible to suspend the system. On top of that, it instantiates the spd eeprom which can not really be accessed because that code _does_ need to write into the chip.

Quoted 4 lines

There is no safe way for a spd5118 compliant chip to be accessed reliably with write protection active. There is nothing we can do about that.

Guenter

I see... I had the module blacklisted anyway :P but I can imagine future regression reports.

Thanks for the explaination!

Signature · 2 lines
Thanks,
 ~ Kurt