Skip to contentSkip to conversation

hwmon: Add support for SPD5118 compliant chips

PATCH In review Guenter Roeck 2 participants 9 messages Jun 10, 2024

Subsystems (5)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

v5 cover hwmon: Add support for SPD5118 compliant chips

Add support for SPD5118 (Jedec JESD300) compliant chips supporting a temperature sensor and SPD NVRAM. Such devices are typically found on DDR5 memory modules.

The first patch of the series adds SPD5118 devicetree bindings. The second patch adds support for SPD5118 temperature sensors. The third patch adds support for suspend/resume. The 4th patch adds support for reading the SPD NVRAM. The 5th patch adds support for auto-detecting SPD5118 compliant chips to i2c_register_spd() in the i2c-smbus code. The last patch of the series adds a configuration option to make the auto-detect code in the spd5118 driver configurable.

Note: The driver introduced with this patch series does not currently support accessing SPD5118 compliant chips in I3C mode.

v5: Added Tested-by: tags
Cosmetic changes
Added reference to LPDDR5 to subject and description of patch 5/6 Updated comments associated with i2c_register_spd()
to include support for (LP)DDR5
Replaced #ifdef with IS_ENABLED() and included address_list in conditional code of patch 6/6

v4: Add support for detecting SPD5118 compliant chips in i2c-smbus driver
Make auto-detect code in driver optional
Fix suspend code
Ignore failure to register with nvmem core if it is disabled Use NVMEM_DEVID_NONE instead of NVMEM_DEVID_AUTO in nvmem code, changing nvmem attribute directories from 0-005[0-7]X to 0-005[0-7]

v3: Drop explicit bindings document; add binding to trivial devices instead
Add support for reading SPD NVRAM

v2: Drop PEC support; it only applies to I3C mode.
Update documentation
Add suspend/resume support

----------------------------------------------------------------
Guenter Roeck (6):
dt-bindings: trivial-devices: Add jedec,spd5118
hwmon: Add support for SPD5118 compliant temperature sensors
hwmon: (spd5118) Add suspend/resume support
hwmon: (spd5118) Add support for reading SPD data
i2c: smbus: Support DDR5 and LPDDR5 SPD EEPROMs
hwmon: (spd5118) Add configuration option for auto-detection

 .../devicetree/bindings/trivial-devices.yaml       |   2 +
 Documentation/hwmon/index.rst                      |   1 +
 Documentation/hwmon/spd5118.rst                    |  63 ++
 drivers/hwmon/Kconfig                              |  31 +
 drivers/hwmon/Makefile                             |   1 +
 drivers/hwmon/spd5118.c                            | 658 +++++++++++++++++++++
 drivers/i2c/i2c-smbus.c                            |   6 +-
 7 files changed, 761 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/hwmon/spd5118.rst
 create mode 100644 drivers/hwmon/spd5118.c
author maintainer
#1 lore raw

PATCH v5 1/6 dt-bindings: trivial-devices: Add jedec,spd5118

Add bindings for the SPD hub present in DDR5 modules.
(https://www.jedec.org/standards-documents/docs/jesd300-5b01).

---
v5: Unchanged

v4: Add Krzysztof's Acked-by:

v3: Drop explicit bindings file; add binding to trivial devices
instead

 Documentation/devicetree/bindings/trivial-devices.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/trivial-devices.yaml +2 -0
index 0a419453d183..1d19e67de2a1 100644
@@ -168,6 +168,8 @@ properties:
           - isil,isl69269
             # Intersil ISL76682 Ambient Light Sensor
           - isil,isl76682
+            # JEDEC JESD300 (SPD5118) Hub and Serial Presence Detect
+          - jedec,spd5118
             # Linear Technology LTC2488
           - lineartechnology,ltc2488
             # 5 Bit Programmable, Pulse-Width Modulator
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH v5 2/6 hwmon: Add support for SPD5118 compliant temperature sensors

In reply to Guenter Roeck

Add support for SPD5118 (Jedec JESD300) compliant temperature sensors. Such sensors are typically found on DDR5 memory modules.

---
v5: Added Tested-by: tags

v4: No change

v3: Shorten JESD300-5B.01 to JESD300; 5B.01 refers to the version
of the standard
Drop unnecessary 'attr' parameter from spd5118_{read,write}_enable()

v2: Drop PEC property documentation
Add note indicating that alarm attributes are sticky until read to documentation
Fix detect function
Fix misspelling in Makefile (CONFIG_SENSORS_SPD5118->CONFIG_SENSORS_SPD5118)

 Documentation/hwmon/index.rst   |   1 +
 Documentation/hwmon/spd5118.rst |  55 ++++
 drivers/hwmon/Kconfig           |  12 +
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/spd5118.c         | 481 ++++++++++++++++++++++++++++++++
 5 files changed, 550 insertions(+)
 create mode 100644 Documentation/hwmon/spd5118.rst
 create mode 100644 drivers/hwmon/spd5118.c
Documentation/hwmon/index.rst +1 -0
index 03d313af469a..6e7b8726b60c 100644
@@ -215,6 +215,7 @@ Hardware Monitoring Kernel Drivers
    smsc47m192
    smsc47m1
    sparx5-temp
+   spd5118
    stpddc60
    surface_fan
    sy7636a-hwmon
Documentation/hwmon/spd5118.rst new file +55 -0

55 lines not on this page · raw message

drivers/hwmon/Kconfig +12 -0
index e14ae18a973b..7a84e7637b51 100644
@@ -2181,6 +2181,18 @@ config SENSORS_INA3221
 	  This driver can also be built as a module. If so, the module
 	  will be called ina3221.
 
+config SENSORS_SPD5118
+	tristate "SPD5118 Compliant Temperature Sensors"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  If you say yes here you get support for SPD5118 (JEDEC JESD300)
+	  compliant temperature sensors. Such sensors are found on DDR5 memory
+	  modules.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called spd5118.
+
 config SENSORS_TC74
 	tristate "Microchip TC74"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index e3f25475d1f0..6574ca67d761 100644
@@ -207,6 +207,7 @@ obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
 obj-$(CONFIG_SENSORS_SMSC47M1)	+= smsc47m1.o
 obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
 obj-$(CONFIG_SENSORS_SPARX5)	+= sparx5-temp.o
+obj-$(CONFIG_SENSORS_SPD5118)	+= spd5118.o
 obj-$(CONFIG_SENSORS_STTS751)	+= stts751.o
 obj-$(CONFIG_SENSORS_SURFACE_FAN)+= surface_fan.o
 obj-$(CONFIG_SENSORS_SY7636A)	+= sy7636a-hwmon.o
drivers/hwmon/spd5118.c new file +481 -0

481 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH v5 3/6 hwmon: (spd5118) Add suspend/resume support

In reply to Guenter Roeck

Add suspend/resume support to ensure that limit and configuration registers are updated and synchronized after a suspend/resume cycle.

---
v5: Added Tested-by: tags

v4: Fix bug seen if the enable attribute was never read prior
to a suspend/resume cycle.

v3: No change

v2: New patch

 drivers/hwmon/spd5118.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/hwmon/spd5118.c +39 -0
index d3fc0ae17743..d55c073ff5fd 100644
@@ -20,6 +20,7 @@
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/units.h>
 
@@ -432,6 +433,8 @@ static int spd5118_probe(struct i2c_client *client)
 	if (!spd5118_vendor_valid(bank, vendor))
 		return -ENODEV;
 
+	dev_set_drvdata(dev, regmap);
+
 	hwmon_dev = devm_hwmon_device_register_with_info(dev, "spd5118",
 							 regmap, &spd5118_chip_info,
 							 NULL);
@@ -449,6 +452,41 @@ static int spd5118_probe(struct i2c_client *client)
 	return 0;
 }
 
+static int spd5118_suspend(struct device *dev)
+{
+	struct regmap *regmap = dev_get_drvdata(dev);
+	u32 regval;
+	int err;
+
+	/*
+	 * Make sure the configuration register in the regmap cache is current
+	 * before bypassing it.
+	 */
+	err = regmap_read(regmap, SPD5118_REG_TEMP_CONFIG, &regval);
+	if (err < 0)
+		return err;
+
+	regcache_cache_bypass(regmap, true);
+	regmap_update_bits(regmap, SPD5118_REG_TEMP_CONFIG, SPD5118_TS_DISABLE,
+			   SPD5118_TS_DISABLE);
+	regcache_cache_bypass(regmap, false);
+
+	regcache_cache_only(regmap, true);
+	regcache_mark_dirty(regmap);
+
+	return 0;
+}
+
+static int spd5118_resume(struct device *dev)
+{
+	struct regmap *regmap = dev_get_drvdata(dev);
+
+	regcache_cache_only(regmap, false);
+	return regcache_sync(regmap);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(spd5118_pm_ops, spd5118_suspend, spd5118_resume);
+
 static const struct i2c_device_id spd5118_id[] = {
 	{ "spd5118", 0 },
 	{ }
@@ -466,6 +504,7 @@ static struct i2c_driver spd5118_driver = {
 	.driver = {
 		.name	= "spd5118",
 		.of_match_table = spd5118_of_ids,
+		.pm = pm_sleep_ptr(&spd5118_pm_ops),
 	},
 	.probe		= spd5118_probe,
 	.id_table	= spd5118_id,
Signature · 1 line
2.39.2
author maintainer
#4 lore raw

PATCH v5 4/6 hwmon: (spd5118) Add support for reading SPD data

In reply to Guenter Roeck

Add support for reading SPD NVMEM data from SPD5118 (Jedec JESD300) compliant memory modules. NVMEM write operation is not supported.

NVMEM support is optional. If CONFIG_NVMEM is disabled, the driver will still instantiate but not provide NVMEM attribute files.

---
v5: Added Tested-by: tag
Dropped stray double empty line

v4: Use NVMEM_DEVID_NONE instead of NVMEM_DEVID_AUTO
Ignore nvmem registration failure if nvmem support is disabled

v3: New patch

 Documentation/hwmon/spd5118.rst |   8 ++
 drivers/hwmon/spd5118.c         | 146 +++++++++++++++++++++++++++++++-
 2 files changed, 150 insertions(+), 4 deletions(-)
Documentation/hwmon/spd5118.rst +8 -0
index a15d75aa2066..ef7338f46575 100644
@@ -53,3 +53,11 @@ temp1_crit_alarm	Temperature critical alarm
 
 Alarm attributes are sticky until read and will be cleared afterwards
 unless the alarm condition still applies.
+
+
+SPD (Serial Presence Detect) support
+------------------------------------
+
+The driver also supports reading the SPD NVRAM on SPD5118 compatible chips.
+SPD data is available from the 'eeprom' binary attribute file attached to the
+chip's I2C device.
drivers/hwmon/spd5118.c +142 -4

207 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH v5 5/6 i2c: smbus: Support DDR5 and LPDDR5 SPD EEPROMs

In reply to Guenter Roeck

Detect (LP)DDR5 memory and instantiate the SPD5118 driver automatically.

---
v5: Added reference to LPDDR5 to subject and description
Updated comments associated with i2c_register_spd() to include support for (LP)DDR5

v4: New patch

 drivers/i2c/i2c-smbus.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/i2c/i2c-smbus.c +5 -1
index 97f338b123b1..f809f0ef2004 100644
@@ -308,7 +308,7 @@ EXPORT_SYMBOL_GPL(i2c_free_slave_host_notify_device);
  * target systems are the same.
  * Restrictions to automatic SPD instantiation:
  *  - Only works if all filled slots have the same memory type
- *  - Only works for DDR, DDR2, DDR3 and DDR4 for now
+ *  - Only works for (LP)DDR memory types up to DDR5
  *  - Only works on systems with 1 to 8 memory slots
  */
 #if IS_ENABLED(CONFIG_DMI)
@@ -382,6 +382,10 @@ void i2c_register_spd(struct i2c_adapter *adap)
 	case 0x1E:	/* LPDDR4 */
 		name = "ee1004";
 		break;
+	case 0x22:	/* DDR5 */
+	case 0x23:	/* LPDDR5 */
+		name = "spd5118";
+		break;
 	default:
 		dev_info(&adap->dev,
 			 "Memory type 0x%02x not supported yet, not instantiating SPD\n",
Signature · 1 line
2.39.2
author maintainer
#6 lore raw

PATCH v5 6/6 hwmon: (spd5118) Add configuration option for auto-detection

In reply to Guenter Roeck

With SPD5118 chip detection for the most part handled by the i2c-smbus core using DMI information, the spd5118 driver no longer needs to auto-detect spd5118 compliant chips.

Auto-detection by the driver is still needed on systems with no DMI support or on systems with more than eight DIMMs and can not be removed entirely. However, it affects boot time and introduces the risk of mis-identifying chips. Add configuration option to be able to disable it on systems where chip detection is handled outside the driver.

---
v5: Added Tested-by: tag
Replaced #ifdef with IS_ENABLED() and included address_list in conditional code

v4a:
Do not auto-select SENSORS_SPD5118_DETECT if DMI is disabled Modify help text of SENSORS_SPD5118_DETECT
Default SENSORS_SPD5118_DETECT to y if (!DMI || !X86)

v4: New patch

 drivers/hwmon/Kconfig   | 19 +++++++++++++++++++
 drivers/hwmon/spd5118.c |  4 ++--
 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/hwmon/Kconfig +19 -0
index 7a84e7637b51..d5eced417fc3 100644
@@ -2193,6 +2193,25 @@ config SENSORS_SPD5118
 	  This driver can also be built as a module. If so, the module
 	  will be called spd5118.
 
+config SENSORS_SPD5118_DETECT
+	bool "Enable detect function"
+	depends on SENSORS_SPD5118
+	default (!DMI || !X86)
+	help
+	  If enabled, the driver auto-detects if a chip in the SPD address
+	  range is compliant to the SPD51888 standard and auto-instantiates
+	  if that is the case. If disabled, SPD5118 compliant devices have
+	  to be instantiated by other means. On X86 systems with DMI support
+	  this will typically be done from DMI DDR detection code in the
+	  I2C SMBus subsystem. Devicetree based systems will instantiate
+	  attached devices if the DIMMs are listed in the devicetree file.
+
+	  Disabling the detect function will speed up boot time and reduce
+	  the risk of mis-detecting SPD5118 compliant devices. However, it
+	  may result in missed DIMMs under some circumstances.
+
+	  If unsure, say Y.
+
 config SENSORS_TC74
 	tristate "Microchip TC74"
 	depends on I2C
drivers/hwmon/spd5118.c +2 -2
index de6cf07f3007..ac94a6779360 100644
@@ -646,8 +646,8 @@ static struct i2c_driver spd5118_driver = {
 	},
 	.probe		= spd5118_probe,
 	.id_table	= spd5118_id,
-	.detect		= spd5118_detect,
-	.address_list	= normal_i2c,
+	.detect		= IS_ENABLED(CONFIG_SENSORS_SPD5118_DETECT) ? spd5118_detect : NULL,
+	.address_list	= IS_ENABLED(CONFIG_SENSORS_SPD5118_DETECT) ? normal_i2c : NULL,
 };
 
 module_i2c_driver(spd5118_driver);
Signature · 1 line
2.39.2
Reviewed-by on the v5 series
#7 lore raw
In reply to Guenter Roeck
Quoted 3 lines · Guenter Roeck

Add support for SPD5118 (Jedec JESD300) compliant chips supporting a temperature sensor and SPD NVRAM. Such devices are typically found on DDR5 memory modules.

<snip>

Quoted 9 lines

----------------------------------------------------------------
Guenter Roeck (6):
dt-bindings: trivial-devices: Add jedec,spd5118
hwmon: Add support for SPD5118 compliant temperature sensors
hwmon: (spd5118) Add suspend/resume support
hwmon: (spd5118) Add support for reading SPD data
i2c: smbus: Support DDR5 and LPDDR5 SPD EEPROMs
hwmon: (spd5118) Add configuration option for auto-detection

Quoted 10 lines
 .../devicetree/bindings/trivial-devices.yaml       |   2 +
 Documentation/hwmon/index.rst                      |   1 +
 Documentation/hwmon/spd5118.rst                    |  63 ++
 drivers/hwmon/Kconfig                              |  31 +
 drivers/hwmon/Makefile                             |   1 +
 drivers/hwmon/spd5118.c                            | 658 +++++++++++++++++++++
 drivers/i2c/i2c-smbus.c                            |   6 +-
 7 files changed, 761 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/hwmon/spd5118.rst
 create mode 100644 drivers/hwmon/spd5118.c
author maintainer
#8 lore raw
Quoted 27 lines · Thomas Weißschuh
Quoted 3 lines · Guenter Roeck

Add support for SPD5118 (Jedec JESD300) compliant chips supporting a temperature sensor and SPD NVRAM. Such devices are typically found on DDR5 memory modules.

<snip>

Quoted 17 lines

----------------------------------------------------------------
Guenter Roeck (6):
dt-bindings: trivial-devices: Add jedec,spd5118
hwmon: Add support for SPD5118 compliant temperature sensors
hwmon: (spd5118) Add suspend/resume support
hwmon: (spd5118) Add support for reading SPD data
i2c: smbus: Support DDR5 and LPDDR5 SPD EEPROMs
hwmon: (spd5118) Add configuration option for auto-detection

  .../devicetree/bindings/trivial-devices.yaml       |   2 +
  Documentation/hwmon/index.rst                      |   1 +
  Documentation/hwmon/spd5118.rst                    |  63 ++
  drivers/hwmon/Kconfig                              |  31 +
  drivers/hwmon/Makefile                             |   1 +
  drivers/hwmon/spd5118.c                            | 658 +++++++++++++++++++++
  drivers/i2c/i2c-smbus.c                            |   6 +-
  7 files changed, 761 insertions(+), 1 deletion(-)
Quoted 2 lines

create mode 100644 Documentation/hwmon/spd5118.rst create mode 100644 drivers/hwmon/spd5118.c

Quoted 1 line

Thanks!

Guenter