From patchwork Thu May 30 22:39:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13680889 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 677FC1802B1; Thu, 30 May 2024 22:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717108785; cv=none; b=pUgmO/QjtcVUxi+QPAz9vCEUbFoEkb7lzQ0vKGiREogxPMljjeI/BBhNGu1G+bto0lCnI4J6vKQ4ICPTi3ZjyglJFooi9J79zKsIM+mWeq8zLXgBR5u6iame5ZjDPEmTx6yf2MNh9liTspFlRR+jpEe++wjXDK6yFPKmXKsDobY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717108785; c=relaxed/simple; bh=ofGw7/Ge7WBz5qMYrDYoKIYc/M2oPcchQzIyC4hEIyA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QqKn0rZRASvNszsfc7BEApVfnqmwYyNTLKWGwh5XZnwAKfx7Sdyynk932RBz8y0KWoBtbc3ewUW4yhNdLlQCHd2FmfEepPHWcWVkZ6NxHeX5wWHZnEfYBQ2fozOpmHLvueYyAvCV065GJKUMK97hpcs3ydMJby5bpA1gldU8eTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mIFzCHa4; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mIFzCHa4" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7023b6d810bso677145b3a.3; Thu, 30 May 2024 15:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717108783; x=1717713583; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=AsuGUamW29699gCC/95HWoSSeAKd2RQxA8flwqqR5aw=; b=mIFzCHa4K0odrtrwxPZfofYTIAbYsMaXwFtsFVbgAZm3ahuY+b6+0ruy9gZJXPsKjV eME1fSXbwQSKEMsxUfSreWgR7aP+RevWpBUOtUn8LcRZL5Q3S9EXiW/13O5tD8Jka32e EIg7linulN5XtUmaNZqZjXN6tlJBESEUYeHZf6kgEyCgcDvNcZffSQycS7KUuqcwLpoV 8e2PqP0pSvW6hgYEUDo0fZu4c1dctMqTAookjVvCHrC0ElraBKX3Hn5JURyy/SnCgxAh CdMxtimqZo4or8GjdsKkG2ysSu563EJcciAAcXe1rridRdKbmu/dKmFHoeLdIkVxVcG7 AO9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717108783; x=1717713583; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AsuGUamW29699gCC/95HWoSSeAKd2RQxA8flwqqR5aw=; b=G+ftxdHy3WOUbNUJxg5bO1nw8CRiWKJ7Z7yuRu90AOG3yw+h/WDhAJqxESapvIIcGV jphIo4X+PPWfL8MweVmXLmo9Zr51f7tsJvvDWxGT9bS1JwWDgO0Fe5uOjSWlFgADlWbM yVAU2EQsHYsGK0JQAaq0gnhLazuaAO2tFNIlzKJWg1tDZ62/j00L56gatP15vSmAuAdW /bn3jmanBmxFK97b1GFQbXWQZMjh+1LFf4y2snLyHTTGKP88XdpvKYxqmgMVXynGm9/2 7uV35f0qJTFOt8T7pKztuorIet4i6n3Ip/RJYsdIccO2FjbzyoC3CKgA4cOdBLOwUM3R Oqjg== X-Forwarded-Encrypted: i=1; AJvYcCWcXYGX85BbX6YNpMjJqnpD/dclxUXtrg+t9XqQOrmb+T2h+hd0tWWDT6rseIYzDLeHM3ygpGHLVrIWueRz6SA4koRZ/QbhlkkiUIqo X-Gm-Message-State: AOJu0YxdffZO9e1MZApBkPslMfKk0JmsHUuPmSdaKH5kd4QGd5CN37dQ AaeUsk/WMEMbVNSGS1TTPSbkiZ7iAUk60VDimBjmZNQHgLMXnJSw4anNMA== X-Google-Smtp-Source: AGHT+IHLkX6hrU59wyxmdEs1l16B3BWOYf1k4sF/C3RAMNiNqq5kc6iUwEevdIXBg8ucEPVmTJJUMw== X-Received: by 2002:a05:6a00:3cc4:b0:6ed:4a97:5dec with SMTP id d2e1a72fcca58-70247830606mr190592b3a.20.1717108783095; Thu, 30 May 2024 15:39:43 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6c35937a4c5sm173576a12.68.2024.05.30.15.39.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:39:42 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, Armin Wolf , =?utf-8?q?Thomas?= =?utf-8?q?_Wei=C3=9Fschuh?= , =?utf-8?q?Ren=C3=A9_Reb?= =?utf-8?q?e?= , Guenter Roeck Subject: [PATCH v2 1/3] dt-bindings: hwmon: jedec,spd5118: Add bindings Date: Thu, 30 May 2024 15:39:37 -0700 Message-Id: <20240530223939.1027659-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530223939.1027659-1-linux@roeck-us.net> References: <20240530223939.1027659-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add device tree bindings for the SPD hub present in DDR5 modules. Signed-off-by: Guenter Roeck --- v2: Drop pec-enable property .../bindings/hwmon/jedec,spd5118.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/jedec,spd5118.yaml diff --git a/Documentation/devicetree/bindings/hwmon/jedec,spd5118.yaml b/Documentation/devicetree/bindings/hwmon/jedec,spd5118.yaml new file mode 100644 index 000000000000..05c39f7083db --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/jedec,spd5118.yaml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hwmon/jedec,spd5118.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: JEDEC JESD300-5B (SPD5118) compatible DDR5 SPD hub + +maintainers: + - Guenter Roeck + +description: | + JEDEC JESD300-5B.01 SPD5118 Hub and Serial Presence Detect + https://www.jedec.org/standards-documents/docs/jesd300-5b01 + +select: + properties: + compatible: + const: jedec,spd5118 + + required: + - compatible + - reg + +properties: + compatible: + const: jedec,spd5118 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + temp-sensor@51 { + compatible = "jedec,spd5118"; + reg = <0x51>; + }; + }; From patchwork Thu May 30 22:39:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13680890 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BF48183994; Thu, 30 May 2024 22:39:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717108788; cv=none; b=qyARl6H5EWsxftmOBZjHonslRm6PYdPMFyeR4PlzBmgS3UZdK2ha60cdIdE80S0FFay/dL7xc6rvJ6zmIIjvjF7L9yG7NReX9E/7ZMDbArIxyRFlsGrxj/jxNU0ftzH0gieFIzEhFEkg1zJ59Zd1iBLXZrYSqE+6vvOFrKxXXUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717108788; c=relaxed/simple; bh=K2edpfdzOXhrPtiPiaEHLwmW3SKzSzTMM4wiQNJyxn8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=KGhj51xzCE4mmmoINwpHMHhNfQ+3Mq+rsA9VNxD/+7yT/5rmqAY3JUw+OMKDcxodq2szwG30urm1cU5mi2BGqfXcZnjIvlfeaeW8UDjX7PJF937PwvvcLajoISOA4mUNIShEeJfzYVZ7yqxy9Y1CwlwTMsYhRjbRPz7sM6EUS4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=isDJu4Oq; arc=none smtp.client-ip=209.85.161.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="isDJu4Oq" Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5b9f9e7176eso486641eaf.2; Thu, 30 May 2024 15:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717108785; x=1717713585; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=z1ze40S3ifbif7/5OPCC64s+2eO9dK2PK2fHfhX5h7Y=; b=isDJu4OqKBT/fNb2NTnDCxwv41r4Lv5eFMDxw3staOC7tq/5BvI1T6OdYadRIFW4QK Sj7LhK6/3oKe8E3Bfvtb873MSDgXMQ0uAd/n61gx5kGOzRXDr8pxv1KkoBdRK6sqcvMg xLclkem3mNb8Gv5uKtL8kwQAc5DXmRz924nYo/MrjhTgLQydJ/pjxBzgCXARLQQC4FwT gupi7gfENh/ONMfkAuOIPmHC6hXiq+fYdA2RnP6sW53N7TqRmmp+z3/n/eIozn0wRMky 13b8uq4KtO9JfiVhhSlk+oKniR4Z50mnAzWQU4iUuNi+8RpkL0gkw1T1fa7g561DBO1u TkGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717108785; x=1717713585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=z1ze40S3ifbif7/5OPCC64s+2eO9dK2PK2fHfhX5h7Y=; b=BwV7guVMSQXnMHEZSVe0ex1LOfvhTVjA/9hlhO8d8Pc2an/x4IizD3FvAkVRwv4+IG 8DFoYSZQEJekltqTxbA+0qtX0SjmVWGN9P/doPd6rz+WR2F3QhXEOm48G/UjhoCBRJ0P 9tZvPOAEQpg2z23ZesjDv6NArpIWuQqWNs4G3cie2xoRdnyC1s+lnkJOAomFLEy+I7Dj t97zIlec41Hsunfs3zYUhAJMSSX9y1xcAPF4XcQVcCj78n0RoHhKb3gQ4CRWE+ovV2Sq +J5E/ykp81CasdD0QgmGq25XQXdr77yhkjUoCfThb7wCKh9PDTZzKbbyA3QnPsQ8rCf5 vclw== X-Forwarded-Encrypted: i=1; AJvYcCXEcBrq9bo7z7vz263bK7MLwEUbgs6Qw7bljcipHMvJbU5801JkL9j6pFc1elRTpVrQwjaefMiPkdiDumnoPIwqMlWMmX6UTt1ClKqK X-Gm-Message-State: AOJu0YxLnacR5PQK96qgmwqf5T8k0y7lp9M9MAGtTmEyBYK5k3/pS49n Ck8wt1M25JAqjyHEiEmRQTmoYu41GUwi9skG+eXFcLoPYV4lkp/0Nzuk5Q== X-Google-Smtp-Source: AGHT+IG0dqMLDbfm49sTKvsW3/XkvlTSbn+/PYHqdaDtLYleok/Fo1al18S+/cqV05qjYQUkiwgl4g== X-Received: by 2002:a05:6359:c30:b0:196:e76f:a06d with SMTP id e5c5f4694b2df-19b490d9720mr30351455d.22.1717108784754; Thu, 30 May 2024 15:39:44 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6c35a6a36a7sm228102a12.89.2024.05.30.15.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:39:44 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, Armin Wolf , =?utf-8?q?Thomas?= =?utf-8?q?_Wei=C3=9Fschuh?= , =?utf-8?q?Ren=C3=A9_Reb?= =?utf-8?q?e?= , Guenter Roeck Subject: [PATCH v2 2/3] hwmon: Add support for SPD5118 compliant temperature sensors Date: Thu, 30 May 2024 15:39:38 -0700 Message-Id: <20240530223939.1027659-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530223939.1027659-1-linux@roeck-us.net> References: <20240530223939.1027659-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for SPD5118 (Jedec JESD300-5B.01) compliant temperature sensors. Such sensors are typically found on DDR5 memory modules. Cc: René Rebe Cc: Thomas Weißschuh Reviewed-by: Thomas Weißschuh Tested-by: Thomas Weißschuh Signed-off-by: Guenter Roeck --- 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 | 56 ++++ drivers/hwmon/Kconfig | 12 + drivers/hwmon/Makefile | 1 + drivers/hwmon/spd5118.c | 481 ++++++++++++++++++++++++++++++++ 5 files changed, 551 insertions(+) create mode 100644 Documentation/hwmon/spd5118.rst create mode 100644 drivers/hwmon/spd5118.c diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index 03d313af469a..6e7b8726b60c 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -215,6 +215,7 @@ Hardware Monitoring Kernel Drivers smsc47m192 smsc47m1 sparx5-temp + spd5118 stpddc60 surface_fan sy7636a-hwmon diff --git a/Documentation/hwmon/spd5118.rst b/Documentation/hwmon/spd5118.rst new file mode 100644 index 000000000000..5bf7b7e7ca67 --- /dev/null +++ b/Documentation/hwmon/spd5118.rst @@ -0,0 +1,56 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver spd5118 +===================== + +Supported chips: + + * SPD5118 (JEDEC JESD300-5B.01) compliant temperature sensor chips + + JEDEC standard download: + https://www.jedec.org/standards-documents/docs/jesd300-5b01 + (account required) + + + Prefix: 'spd5118' + + Addresses scanned: I2C 0x50 - 0x57 + +Author: + Guenter Roeck + + +Description +----------- + +This driver implements support for SPD5118 (JEDEC JESD300-5B.01) compliant +temperature sensors, which are used on many DDR5 memory modules. Some systems +use the sensor to prevent memory overheating by automatically throttling +the memory controller. + +The driver auto-detects SPD5118 compliant chips, but can also be instantiated +using devicetree/firmware nodes. + +A SPD5118 compliant chip supports a single temperature sensor. Critical minimum, +minimum, maximum, and critical temperature can be configured. There are alarms +for low critical, low, high, and critical thresholds. + + +Hardware monitoring sysfs entries +--------------------------------- + +======================= ================================== +temp1_input Temperature (RO) +temp1_lcrit Low critical high temperature (RW) +temp1_min Minimum temperature (RW) +temp1_max Maximum temperature (RW) +temp1_crit Critical high temperature (RW) + +temp1_lcrit_alarm Temperature low critical alarm +temp1_min_alarm Temperature low alarm +temp1_max_alarm Temperature high alarm +temp1_crit_alarm Temperature critical alarm +======================= ================================== + +Alarm attributes are sticky until read and will be cleared afterwards +unless the alarm condition still applies. diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e14ae18a973b..d0fb5fe1b2ac 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -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-5B) + 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 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index e3f25475d1f0..6574ca67d761 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -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 diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c new file mode 100644 index 000000000000..3c75964a0fba --- /dev/null +++ b/drivers/hwmon/spd5118.c @@ -0,0 +1,481 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Jedec 5118 compliant temperature sensors + * + * Derived from https://github.com/Steve-Tech/SPD5118-DKMS + * Originally from T/2 driver at https://t2sde.org/packages/linux + * Copyright (c) 2023 René Rebe, ExactCODE GmbH; Germany. + * + * Copyright (c) 2024 Guenter Roeck + * + * Inspired by ee1004.c and jc42.c. + * + * SPD5118 compliant temperature sensors are typically used on DDR5 + * memory modules. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, I2C_CLIENT_END }; + +/* SPD5118 registers. */ +#define SPD5118_REG_TYPE 0x00 /* MR0:MR1 */ +#define SPD5118_REG_REVISION 0x02 /* MR2 */ +#define SPD5118_REG_VENDOR 0x03 /* MR3:MR4 */ +#define SPD5118_REG_CAPABILITY 0x05 /* MR5 */ +#define SPD5118_REG_I2C_LEGACY_MODE 0x0B /* MR11 */ +#define SPD5118_REG_TEMP_CLR 0x13 /* MR19 */ +#define SPD5118_REG_ERROR_CLR 0x14 /* MR20 */ +#define SPD5118_REG_TEMP_CONFIG 0x1A /* MR26 */ +#define SPD5118_REG_TEMP_MAX 0x1c /* MR28:MR29 */ +#define SPD5118_REG_TEMP_MIN 0x1e /* MR30:MR31 */ +#define SPD5118_REG_TEMP_CRIT 0x20 /* MR32:MR33 */ +#define SPD5118_REG_TEMP_LCRIT 0x22 /* MR34:MR35 */ +#define SPD5118_REG_TEMP 0x31 /* MR49:MR50 */ +#define SPD5118_REG_TEMP_STATUS 0x33 /* MR51 */ + +#define SPD5118_TEMP_STATUS_HIGH BIT(0) +#define SPD5118_TEMP_STATUS_LOW BIT(1) +#define SPD5118_TEMP_STATUS_CRIT BIT(2) +#define SPD5118_TEMP_STATUS_LCRIT BIT(3) + +#define SPD5118_CAP_TS_SUPPORT BIT(1) /* temperature sensor support */ + +#define SPD5118_TS_DISABLE BIT(0) /* temperature sensor disable */ + +/* Temperature unit in millicelsius */ +#define SPD5118_TEMP_UNIT (MILLIDEGREE_PER_DEGREE / 4) +/* Representable temperature range in millicelsius */ +#define SPD5118_TEMP_RANGE_MIN -256000 +#define SPD5118_TEMP_RANGE_MAX 255750 + +static int spd5118_temp_from_reg(u16 reg) +{ + int temp = sign_extend32(reg >> 2, 10); + + return temp * SPD5118_TEMP_UNIT; +} + +static u16 spd5118_temp_to_reg(long temp) +{ + temp = clamp_val(temp, SPD5118_TEMP_RANGE_MIN, SPD5118_TEMP_RANGE_MAX); + return (DIV_ROUND_CLOSEST(temp, SPD5118_TEMP_UNIT) & 0x7ff) << 2; +} + +static int spd5118_read_temp(struct regmap *regmap, u32 attr, long *val) +{ + int reg, err; + u8 regval[2]; + u16 temp; + + switch (attr) { + case hwmon_temp_input: + reg = SPD5118_REG_TEMP; + break; + case hwmon_temp_max: + reg = SPD5118_REG_TEMP_MAX; + break; + case hwmon_temp_min: + reg = SPD5118_REG_TEMP_MIN; + break; + case hwmon_temp_crit: + reg = SPD5118_REG_TEMP_CRIT; + break; + case hwmon_temp_lcrit: + reg = SPD5118_REG_TEMP_LCRIT; + break; + default: + return -EOPNOTSUPP; + } + + err = regmap_bulk_read(regmap, reg, regval, 2); + if (err) + return err; + + temp = (regval[1] << 8) | regval[0]; + + *val = spd5118_temp_from_reg(temp); + return 0; +} + +static int spd5118_read_alarm(struct regmap *regmap, u32 attr, long *val) +{ + unsigned int mask, regval; + int err; + + switch (attr) { + case hwmon_temp_max_alarm: + mask = SPD5118_TEMP_STATUS_HIGH; + break; + case hwmon_temp_min_alarm: + mask = SPD5118_TEMP_STATUS_LOW; + break; + case hwmon_temp_crit_alarm: + mask = SPD5118_TEMP_STATUS_CRIT; + break; + case hwmon_temp_lcrit_alarm: + mask = SPD5118_TEMP_STATUS_LCRIT; + break; + default: + return -EOPNOTSUPP; + } + + err = regmap_read(regmap, SPD5118_REG_TEMP_STATUS, ®val); + if (err < 0) + return err; + *val = !!(regval & mask); + if (*val) + return regmap_write(regmap, SPD5118_REG_TEMP_CLR, mask); + return 0; +} + +static int spd5118_read_enable(struct regmap *regmap, u32 attr, long *val) +{ + u32 regval; + int err; + + err = regmap_read(regmap, SPD5118_REG_TEMP_CONFIG, ®val); + if (err < 0) + return err; + *val = !(regval & SPD5118_TS_DISABLE); + return 0; +} + +static int spd5118_read(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct regmap *regmap = dev_get_drvdata(dev); + + if (type != hwmon_temp) + return -EOPNOTSUPP; + + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_max: + case hwmon_temp_min: + case hwmon_temp_crit: + case hwmon_temp_lcrit: + return spd5118_read_temp(regmap, attr, val); + case hwmon_temp_max_alarm: + case hwmon_temp_min_alarm: + case hwmon_temp_crit_alarm: + case hwmon_temp_lcrit_alarm: + return spd5118_read_alarm(regmap, attr, val); + case hwmon_temp_enable: + return spd5118_read_enable(regmap, attr, val); + default: + return -EOPNOTSUPP; + } +} + +static int spd5118_write_temp(struct regmap *regmap, u32 attr, long val) +{ + u8 regval[2]; + u16 temp; + int reg; + + switch (attr) { + case hwmon_temp_max: + reg = SPD5118_REG_TEMP_MAX; + break; + case hwmon_temp_min: + reg = SPD5118_REG_TEMP_MIN; + break; + case hwmon_temp_crit: + reg = SPD5118_REG_TEMP_CRIT; + break; + case hwmon_temp_lcrit: + reg = SPD5118_REG_TEMP_LCRIT; + break; + default: + return -EOPNOTSUPP; + } + + temp = spd5118_temp_to_reg(val); + regval[0] = temp & 0xff; + regval[1] = temp >> 8; + + return regmap_bulk_write(regmap, reg, regval, 2); +} + +static int spd5118_write_enable(struct regmap *regmap, u32 attr, long val) +{ + if (val && val != 1) + return -EINVAL; + + return regmap_update_bits(regmap, SPD5118_REG_TEMP_CONFIG, + SPD5118_TS_DISABLE, + val ? 0 : SPD5118_TS_DISABLE); +} + +static int spd5118_temp_write(struct regmap *regmap, u32 attr, long val) +{ + switch (attr) { + case hwmon_temp_max: + case hwmon_temp_min: + case hwmon_temp_crit: + case hwmon_temp_lcrit: + return spd5118_write_temp(regmap, attr, val); + case hwmon_temp_enable: + return spd5118_write_enable(regmap, attr, val); + default: + return -EOPNOTSUPP; + } +} + +static int spd5118_write(struct device *dev, enum hwmon_sensor_types type, + u32 attr, int channel, long val) +{ + struct regmap *regmap = dev_get_drvdata(dev); + + switch (type) { + case hwmon_temp: + return spd5118_temp_write(regmap, attr, val); + default: + return -EOPNOTSUPP; + } +} + +static umode_t spd5118_is_visible(const void *_data, enum hwmon_sensor_types type, + u32 attr, int channel) +{ + if (type != hwmon_temp) + return 0; + + switch (attr) { + case hwmon_temp_input: + return 0444; + case hwmon_temp_min: + case hwmon_temp_max: + case hwmon_temp_lcrit: + case hwmon_temp_crit: + case hwmon_temp_enable: + return 0644; + case hwmon_temp_min_alarm: + case hwmon_temp_max_alarm: + case hwmon_temp_crit_alarm: + case hwmon_temp_lcrit_alarm: + return 0444; + default: + return 0; + } +} + +static inline bool spd5118_parity8(u8 w) +{ + w ^= w >> 4; + return (0x6996 >> (w & 0xf)) & 1; +} + +/* + * Bank and vendor id are 8-bit fields with seven data bits and odd parity. + * Vendor IDs 0 and 0x7f are invalid. + * See Jedec standard JEP106BJ for details and a list of assigned vendor IDs. + */ +static bool spd5118_vendor_valid(u8 bank, u8 id) +{ + if (!spd5118_parity8(bank) || !spd5118_parity8(id)) + return false; + + id &= 0x7f; + return id && id != 0x7f; +} + +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int spd5118_detect(struct i2c_client *client, struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + int regval; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) + return -ENODEV; + + regval = i2c_smbus_read_word_swapped(client, SPD5118_REG_TYPE); + if (regval != 0x5118) + return -ENODEV; + + regval = i2c_smbus_read_word_data(client, SPD5118_REG_VENDOR); + if (regval < 0 || !spd5118_vendor_valid(regval & 0xff, regval >> 8)) + return -ENODEV; + + regval = i2c_smbus_read_byte_data(client, SPD5118_REG_CAPABILITY); + if (regval < 0) + return -ENODEV; + if (!(regval & SPD5118_CAP_TS_SUPPORT) || (regval & 0xfc)) + return -ENODEV; + + regval = i2c_smbus_read_byte_data(client, SPD5118_REG_TEMP_CLR); + if (regval) + return -ENODEV; + regval = i2c_smbus_read_byte_data(client, SPD5118_REG_ERROR_CLR); + if (regval) + return -ENODEV; + + regval = i2c_smbus_read_byte_data(client, SPD5118_REG_REVISION); + if (regval < 0 || (regval & 0xc1)) + return -ENODEV; + + regval = i2c_smbus_read_byte_data(client, SPD5118_REG_TEMP_CONFIG); + if (regval < 0) + return -ENODEV; + if (regval & ~SPD5118_TS_DISABLE) + return -ENODEV; + + strscpy(info->type, "spd5118", I2C_NAME_SIZE); + return 0; +} + +static const struct hwmon_channel_info *spd5118_info[] = { + HWMON_CHANNEL_INFO(chip, + HWMON_C_REGISTER_TZ), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | + HWMON_T_LCRIT | HWMON_T_LCRIT_ALARM | + HWMON_T_MIN | HWMON_T_MIN_ALARM | + HWMON_T_MAX | HWMON_T_MAX_ALARM | + HWMON_T_CRIT | HWMON_T_CRIT_ALARM | + HWMON_T_ENABLE), + NULL +}; + +static const struct hwmon_ops spd5118_hwmon_ops = { + .is_visible = spd5118_is_visible, + .read = spd5118_read, + .write = spd5118_write, +}; + +static const struct hwmon_chip_info spd5118_chip_info = { + .ops = &spd5118_hwmon_ops, + .info = spd5118_info, +}; + +static bool spd5118_writeable_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case SPD5118_REG_TEMP_CLR: + case SPD5118_REG_TEMP_CONFIG: + case SPD5118_REG_TEMP_MAX: + case SPD5118_REG_TEMP_MAX + 1: + case SPD5118_REG_TEMP_MIN: + case SPD5118_REG_TEMP_MIN + 1: + case SPD5118_REG_TEMP_CRIT: + case SPD5118_REG_TEMP_CRIT + 1: + case SPD5118_REG_TEMP_LCRIT: + case SPD5118_REG_TEMP_LCRIT + 1: + return true; + default: + return false; + } +} + +static bool spd5118_volatile_reg(struct device *dev, unsigned int reg) +{ + switch (reg) { + case SPD5118_REG_TEMP_CLR: + case SPD5118_REG_ERROR_CLR: + case SPD5118_REG_TEMP: + case SPD5118_REG_TEMP + 1: + case SPD5118_REG_TEMP_STATUS: + return true; + default: + return false; + } +} + +static const struct regmap_config spd5118_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = SPD5118_REG_TEMP_STATUS, + .writeable_reg = spd5118_writeable_reg, + .volatile_reg = spd5118_volatile_reg, + .cache_type = REGCACHE_MAPLE, +}; + +static int spd5118_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + unsigned int regval, revision, vendor, bank; + struct device *hwmon_dev; + struct regmap *regmap; + int err; + + regmap = devm_regmap_init_i2c(client, &spd5118_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), "regmap init failed\n"); + + err = regmap_read(regmap, SPD5118_REG_CAPABILITY, ®val); + if (err) + return err; + if (!(regval & SPD5118_CAP_TS_SUPPORT)) + return -ENODEV; + + err = regmap_read(regmap, SPD5118_REG_REVISION, &revision); + if (err) + return err; + + err = regmap_read(regmap, SPD5118_REG_VENDOR, &bank); + if (err) + return err; + err = regmap_read(regmap, SPD5118_REG_VENDOR + 1, &vendor); + if (err) + return err; + if (!spd5118_vendor_valid(bank, vendor)) + return -ENODEV; + + hwmon_dev = devm_hwmon_device_register_with_info(dev, "spd5118", + regmap, &spd5118_chip_info, + NULL); + if (IS_ERR(hwmon_dev)) + return PTR_ERR(hwmon_dev); + + /* + * From JESD300-5B + * MR2 bits [5:4]: Major revision, 1..4 + * MR2 bits [3:1]: Minor revision, 0..8? Probably a typo, assume 1..8 + */ + dev_info(dev, "DDR5 temperature sensor: vendor 0x%02x:0x%02x revision %d.%d\n", + bank & 0x7f, vendor, ((revision >> 4) & 0x03) + 1, ((revision >> 1) & 0x07) + 1); + + return 0; +} + +static const struct i2c_device_id spd5118_id[] = { + { "spd5118", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, spd5118_id); + +static const struct of_device_id spd5118_of_ids[] = { + { .compatible = "jedec,spd5118", }, + { } +}; +MODULE_DEVICE_TABLE(of, spd5118_of_ids); + +static struct i2c_driver spd5118_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "spd5118", + .of_match_table = spd5118_of_ids, + }, + .probe = spd5118_probe, + .id_table = spd5118_id, + .detect = spd5118_detect, + .address_list = normal_i2c, +}; + +module_i2c_driver(spd5118_driver); + +MODULE_AUTHOR("René Rebe "); +MODULE_AUTHOR("Guenter Roeck "); +MODULE_DESCRIPTION("SPD 5118 driver"); +MODULE_LICENSE("GPL"); From patchwork Thu May 30 22:39:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13680891 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60EAD184135; Thu, 30 May 2024 22:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717108788; cv=none; b=aqQn0MNKcsP7Hd8AF0fFITpxYDNYTnaridjuBlrW3A/jXF9jcqOKC3R1MTCadCftk8uhdrV4Ini2y80SLuZAGmPu6W6WXAW2AjQCrt7FUVGv8eSUkLK1wtP5XC8Ixxc79Br9gsJ0HM25Pm2q6bWauxu+kbwpYQ2f5PAZ7Lb4Bho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717108788; c=relaxed/simple; bh=ObfyRu7oiPBL1J7xJbM/pHFssCtum2gBV4H+0RGWvNw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JhFDSzKfK0DODNPtL7yTWX90PyVez/jXjQyFkk5G8AZZVt+J9RYI96a4ANvXZQPcsufyIfDFZckHj92U5vkfSlG4TQbi+BoquyxzfoblyVrEwgfVjRe2AISNF82le1LTemScHAmYT/CeEsYniyZsCKvLfWPeT8UmUjJ7TFlQhAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nGr8rYHP; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nGr8rYHP" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7024426c75dso206594b3a.1; Thu, 30 May 2024 15:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717108786; x=1717713586; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=RATLX8vwG5qFLWJv5e+WyDP7UKBpMbaga/mz8MYejto=; b=nGr8rYHPAGJeG5NFK3wWdsisEj9FFzmssIwUu6rCHXot9GW+0tSbSytwGnELjbC8Wq pEgZA63/muyMoQ0+4Al2pFX2+fXRiuz5A3J95+xR8TLBI3EwbNz6rT/cBZ0tlS4LIduN dlHnNzFCHfASEEKkpDsNF4VUPoetxYerAFX7n7M0sSzkvcx4SZD4xyFQwg0osEUC58Fd +upRhrTTUDwodXnTFxrwOeCbpg0NRWts/7w06t/6ya6ChVGQSUMJ6cJgES30MckrnJPS rP4L3tV1Bp+o0buEK+CmBDcoaxB6zHOrwbWhr5FZHYbKd7ngYYsKbue77IhnuO9/ohIX agEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717108786; x=1717713586; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RATLX8vwG5qFLWJv5e+WyDP7UKBpMbaga/mz8MYejto=; b=DpGKaBdVohRu1+NnnHca+RWQ1P9g5F8Cyal2tUJpIlJRfCaSgvSnHX4c9qteHkwyE2 E64MXCYYVz+2OA3Fd89Grn+5AwXc0zzhE70uCeYwxMf+ImgBymv3EFEULT07GBsQJsi6 4DJ/Tv9KR87Y1vOIMle8pcyHJCRy3XgMGc/4tGIiZIyMci4uSZMoVRzw7UnaC3kvfOu9 giq5p4F45QAby75kESwGcNTOWGsdkPLHM9EedxT1cSMMMVaZD3b+9uZCDxOJnipfCNUZ b4+ED42D6wedGHc5Dh/HNfBHkeB7pFeYo6y8UgOqa/4c+cxvyTBHfQJaWR+kuNUHPwgA i1ww== X-Forwarded-Encrypted: i=1; AJvYcCUIeFaHhZDQAB6qOW1+gXCE+PWE9DPbenmBf87TlX3X/eqQbk8xeDIbmkoLc8/GynaHTGFBeP9HpTHACdQMQjABRHnHHPLBO+TV9gKr X-Gm-Message-State: AOJu0YzTYcACUfYrdkpqG8/XeM+9vvTdyP/dFRs3WFbxvi7mCeVFJ9Rl llsIOXAPJAR3gRWv12o3P+/g28bCWty+bg2iDE3/jcmbZ09yzfAu9Cw/dg== X-Google-Smtp-Source: AGHT+IHQl1iqObMs93tbh8ZmfFVhjQn1Q3y0D9ccbNyXE3ce9knFzqcgyPscYR3hQ4UIiXhKiCMP9g== X-Received: by 2002:a05:6a00:18a9:b0:6ea:b48a:f971 with SMTP id d2e1a72fcca58-702477bd92fmr255317b3a.2.1717108786156; Thu, 30 May 2024 15:39:46 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702423cce7asm227776b3a.40.2024.05.30.15.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:39:45 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: devicetree@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-kernel@vger.kernel.org, Armin Wolf , =?utf-8?q?Thomas?= =?utf-8?q?_Wei=C3=9Fschuh?= , =?utf-8?q?Ren=C3=A9_Reb?= =?utf-8?q?e?= , Guenter Roeck Subject: [PATCH v2 3/3] hwmon: (spd5118) Add suspend/resume support Date: Thu, 30 May 2024 15:39:39 -0700 Message-Id: <20240530223939.1027659-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530223939.1027659-1-linux@roeck-us.net> References: <20240530223939.1027659-1-linux@roeck-us.net> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add suspend/resume support to ensure that limit and configuration registers are updated and synchronized after a suspend/resume cycle. Cc: Armin Wolf Signed-off-by: Guenter Roeck --- v2: New patch RFT: I tested the patch through a suspend/resume cycle, and it seems to work, but I am not sure if that had any effect because, after all, the memory is still active during suspend/resume. I was unable to test a hibernation cycle with my system. drivers/hwmon/spd5118.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index 3c75964a0fba..ea807a77a4ee 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -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,31 @@ static int spd5118_probe(struct i2c_client *client) return 0; } +static int spd5118_suspend(struct device *dev) +{ + struct regmap *regmap = dev_get_drvdata(dev); + + 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 +494,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,