From patchwork Mon Jun 10 14:40:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13692149 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 CD4A213774A; Mon, 10 Jun 2024 14:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030473; cv=none; b=rFLIXBO57ZLkQRaOZzPX6leyDqteZWyScfmPapM+fpOXYH2leiC37dmE8rODWRQlip8mUktS6re97E0HPJiwfd34E+zOJPMKEDtH7GtLPtbvzrxF4XTmhc1SEKsO9m6GDBztl9UWPltcroACWSkkQBVyr2DFlywOUK90RP7odA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030473; c=relaxed/simple; bh=zjeFdMfEWi9lRnjxPzFnJQqsm0kXpfPxDwStso/WHBw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J8AnZom15pUDCW7xdNECtDrRj/Tv4FsnPksUhAt4yHrQWpXSHTDi0UQU43Vx9ACsvsPxIlP1k9bQ490SGYuqbKC8WqDNGETG8ASjJKW0ylS5xLAhK6LBO01sefztukgS6e43hn8/24OvxATWuw3jHQnmd2p5xgohquP34bcIKn8= 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=WlBp9qKB; arc=none smtp.client-ip=209.85.210.176 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="WlBp9qKB" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7041f4553ccso2345544b3a.1; Mon, 10 Jun 2024 07:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718030470; x=1718635270; 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=xiQRZCJ4lRKdCOsidmp5fsupiblBLEugjBHIkO/u9wM=; b=WlBp9qKBukPxhnriymvYtGsEKujc+XRo5/OeeAcrw6p2HZi/aU7y25Pk0kobYFxpYR GbHPAmbb7HJnT5THwqReJj3OMkg58+jt169UBql8/hsvCINqSbzTKdmMBkB+LgldOyTK bqeSbVhEG6lV1gruRuDe1vnix9Wb8UbfxteFkjOufq49mTT8p7+9MVyUli/U9vHzfXtd dqJZ67LdNC+P02D2K2wG3ABkEIFTgCbEj38h4lArmR8m1cjPqABmRDvHTN+Fy38wZ4zG YqMDe3fpcc3v1RRBXffaAjZTLUMDoWbzP0LRRYUxLE00NB8GWBfsh0v6vM7yUOUCgrHS cBpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718030470; x=1718635270; 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=xiQRZCJ4lRKdCOsidmp5fsupiblBLEugjBHIkO/u9wM=; b=V85AgZgylsEiTk0r2zPmC21eqFhGnS6bZk4lXyDnJ24j/Bgj20zzjcE3H+O2pgYD4e xpbYu0PjvUlsa0LuAWVfkwz6SE2TAwsij5xmYLCdZoLfpjSnmi/BRmZWB83LqfQ0daPW i8CZ2mcMEXKMtISujJ5GLbpTNCfUuDR8dJvTzRECPaJAIUuUJoSvNvRaYB/LpjzDL6NP 7Q4zUj55CWYmBeTKrbTw9Z9ZxMWGgOSpTHJZrt60aQmPf5lZNJzpRH2vKOYz8JQaPnKq pGQnoFD6Yi+W7NLlPGRPOxCTlDtbpQpptWKIQ8LcBeYoIG1wiZz+iHo7+3aHrv15pRh0 HrgA== X-Forwarded-Encrypted: i=1; AJvYcCX1XG7umfJDijPOiUMahB6u7wBrXVWfqJ0e1lfkA8qoJGHRMP7htbWR2a3gE2jMS1dP/NcbKIkD51U34OqMaDscZ9HTHJx7W8CRKbhoGXzTp00molaqDv0OW0VaqZXQTQJwNq9Hmdy2yw== X-Gm-Message-State: AOJu0Yy7131l7Wd7QkAFJIHGRaDBesuPh0CMS2H6NsGGoJ102Ve5h6dy r1pBSTdWhWkDYIz6uegErvtEOJ0oLriiFiTcctfo3OHpsv6e6A/4LgWpUw== X-Google-Smtp-Source: AGHT+IG7jn0w4AwOM1WM0D3Y4KA1sYQNLSEjiwsIH3RfZa9Awd4mWYUvTSmeQUMQ8vDE7C2yIvQwVQ== X-Received: by 2002:a05:6a20:1592:b0:1b6:cd8e:4a5 with SMTP id adf61e73a8af0-1b6cd8e0845mr4653885637.19.1718030470580; Mon, 10 Jun 2024 07:41:10 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7042eba77e2sm3311157b3a.104.2024.06.10.07.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:41:09 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang , =?utf-8?q?Ren=C3=A9_Rebe?= , =?utf-8?q?Thomas_Wei=C3=9Fs?= =?utf-8?q?chuh?= , Armin Wolf , Stephen Horvath , Paul Menzel , Guenter Roeck , Krzysztof Kozlowski Subject: [PATCH v5 1/6] dt-bindings: trivial-devices: Add jedec,spd5118 Date: Mon, 10 Jun 2024 07:40:58 -0700 Message-Id: <20240610144103.1970359-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610144103.1970359-1-linux@roeck-us.net> References: <20240610144103.1970359-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 bindings for the SPD hub present in DDR5 modules. (https://www.jedec.org/standards-documents/docs/jesd300-5b01). Acked-by: Krzysztof Kozlowski Signed-off-by: Guenter Roeck --- 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(+) diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 0a419453d183..1d19e67de2a1 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -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 From patchwork Mon Jun 10 14:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13692151 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 AFC0913D2A2; Mon, 10 Jun 2024 14:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030477; cv=none; b=UbUoDRJO1nMgZjpZXRBh+ICkKHQP3qEwcUn1u7vBQqV0epGe6wF3WjZg1tTUoAs3Q+ZrR6ooGS/o3wo0wDO0OU5s2B9s4vaWbJgLGvXcrxAfXHp0Z+lQctANB2ceXClzPqooX5//moPHlq9tB6n/X6ejccQ8X7HFeFCu6sitGK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030477; c=relaxed/simple; bh=8emzTkhgf0ZPTygN4gGZdG9XrXut69g8uLZCehS7lfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=LHc4PXXy3FFK0ipYqIkNtF8djFVMmGx7yY2Wi0NEedbnPY5rAUnFqBgSjKJPp80SUNl/sE2359iIyn4EbKg3pM9e9L2fFXSUywK0FEI59DOEFdzfCP1LItQhrhX7f2JSPK9zrekmU8S4dW3e9pgZvErRU7Lz0EwSyxJhHysbEpc= 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=Xpb5u5FO; arc=none smtp.client-ip=209.85.214.178 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="Xpb5u5FO" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1f44b5b9de6so35693305ad.3; Mon, 10 Jun 2024 07:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718030472; x=1718635272; 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=Y8NtE8PbT8iMjMYzZ6twWuMhlfdpii7y+48aqCOsPtQ=; b=Xpb5u5FOIc3h5m8e0XeO6jwSrX1/2BqJdPYVvHcDEeD+3eoS3EPEoR7q43D31suMce woOLvMBpFDW19rop3uWQXWNE/TNjMSrVRdHrfn0Fh9DwgDt+NXlWYlPYaxecNr+HAKLi uJmmFcPcjWR6CyS3H5ee7apkQ9BR+Sr7pbG4RsFiGUNnzmB/c6lsGz2KAZ/488ywEdcS gKatHbvflnm0QmnmlHU/8Ff+lRlPku2BKTXj1jg4ltnBiGqCNv4gxFgnZ1dtRVsLF/qt JB7bo8lVk3I5J3TJAVzWriQ65pE3JJJcZSgn03an/5iQMNoa83Myue4Vl+1I9VVpT0AF 4dDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718030472; x=1718635272; 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=Y8NtE8PbT8iMjMYzZ6twWuMhlfdpii7y+48aqCOsPtQ=; b=nPhGG5LBG2eRD/zCgRprDHZbvH/n6cJuJQ/VV8racObDNtLUpD4GPXBq1A6x/quWIF Jt2/Wlv8EzasCN13qsyH+yQAHHnpEZN+/V5/xH5qqD3BBrlkxaH62X/BE2PgK1xVUdCK /NUUHeId0MxEkf8obscNXU1i33RZP0rk2VfqoV70vHyvunopI9kv0OPHf7KDpWojPSBd Kyli3thzu2EDumjhs89pdrVpmVytGtJeCpu0hzpG9RO6bO471L5o7d9q8TdvVNtoKi2m xT6CNQciQ7rBUnBUbRPgdE66X2les/u8dM2xd64kjj9c53ue4NmQdDs7hKvXRUe/BVi3 pA3A== X-Forwarded-Encrypted: i=1; AJvYcCVFbJz8E6QlHO2raLXdJT3TLNeEdoqWMDvMo8R1trIS+7JoYaVEMx1pYarzptytqbc/2qpI1zoj/9vliXZCIhjis7pbWGzmCnCXHQIiXbGiCaHwwrkOb3k/kMxRRKfqh/3rU3kyXGfyNQ== X-Gm-Message-State: AOJu0YycSfdgseLoZOM/xOnQpE9+6xIbbRAPV5ASFPn2Fc9PgYBwigRz Vy4O8Luknken+cPdqgsAvRtJ1Ju0gyXspUwriKWL1VYHMsJGaqlCTPn6rw== X-Google-Smtp-Source: AGHT+IFgFh5Hh1ubxuHT7ziZ8TjintovE/lRVTnRffrJSOeSpeUDX4YVtTDp2df2SGfHL/+zMzW1mA== X-Received: by 2002:a17:902:f690:b0:1f4:5617:c9bb with SMTP id d9443c01a7336-1f6d03e56c6mr122512895ad.59.1718030472275; Mon, 10 Jun 2024 07:41:12 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6fc06a5d2sm37464495ad.306.2024.06.10.07.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:41:11 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang , =?utf-8?q?Ren=C3=A9_Rebe?= , =?utf-8?q?Thomas_Wei=C3=9Fs?= =?utf-8?q?chuh?= , Armin Wolf , Stephen Horvath , Paul Menzel , Guenter Roeck Subject: [PATCH v5 2/6] hwmon: Add support for SPD5118 compliant temperature sensors Date: Mon, 10 Jun 2024 07:40:59 -0700 Message-Id: <20240610144103.1970359-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610144103.1970359-1-linux@roeck-us.net> References: <20240610144103.1970359-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) 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 Tested-by: Stephen Horvath Tested-by: Armin Wolf Signed-off-by: Guenter Roeck --- 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 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..a15d75aa2066 --- /dev/null +++ b/Documentation/hwmon/spd5118.rst @@ -0,0 +1,55 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Kernel driver spd5118 +===================== + +Supported chips: + + * SPD5118 (JEDEC JESD300) 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) 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..7a84e7637b51 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) + 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..d3fc0ae17743 --- /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, 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, 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, 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, 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 Mon Jun 10 14:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13692150 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 622B5136E23; Mon, 10 Jun 2024 14:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030476; cv=none; b=WFlkFGQvm7EiRDV0dzKJ/ONwY8XnlIaodNEy7zhHQvRtabtKr9jdrNXDDqvcMQaBtZ/iOb24lNshPUG4n4vWFJ/nYjYIU+sPoDLlZkDUX+9vV7eIRn1i4sQuGSEpjNoqb3pIDXLdRbZKO6p8k0JmNJLZJ8tGXiArnSGAxDaKzhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030476; c=relaxed/simple; bh=pNPGcLWrzfEk2//0QY8jfo45JRYZJyr8R8GsKD107Q4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DNCumdnKutd6rloFsFnB18fcX3BX+vc0qHrm1+V4tQJS//MMHFpHe9I+rKKyGC0ErooDW2xgDmPEPQApo+j1CH3FmDWGSqoTSU4HMUg2TcY82E/YFMfcr6a+nm3ROUDIeHS5ritSH3Vw5Bcze12R3ohALaX4oO1tQONZ7uLEO9A= 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=TWAbXAUw; arc=none smtp.client-ip=209.85.210.174 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="TWAbXAUw" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-704313fa830so1087704b3a.3; Mon, 10 Jun 2024 07:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718030474; x=1718635274; 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=GtmJnksmoCsc2IBlomAMwsiJXhl0n2lw9y2HgeNnN3c=; b=TWAbXAUwh9sr2PsjLf/IEaO0d4S2rvqwcUhAAC4hnvGqILUXae/MPQf6ivVxcCUNmf t/jZfMgPm5U8h+XslCB2MTVJsdmg+lUfQz2R917OpAcGCfyXZw8jffyjlBBf48KP131h HWtJW3TV1MERSlWQS2FyxM2RmNIJXDudg5vxejAyU+MnzVmIsNbKcZaxTabSZuDQRvHB 1ml1/I7OE/cE9soHYpd6zPA+XuPKASVCJ5w9qr2S9t7whgyYZ871B2lKyd5VFO5Krq7K vWtrzNNq682ceCVxkzH9R6RPlduyXBUw0AeAXa1fS9uSLrUwnCGAQQMJ0J841zK9E3ow 01dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718030474; x=1718635274; 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=GtmJnksmoCsc2IBlomAMwsiJXhl0n2lw9y2HgeNnN3c=; b=ixbw8dq+21Z2kfoVFVLfQaIKeRN11+7X9K9VAyZG5Np4UzNngokB9QwAl5/4n/lUui E2eA4XCrpKnRMBMdsht7jwjlQ26HgdpB7xzX6bnZEXOmaTvkBhWq/PjIqHjqnREAO6gg 6Qrxo5/kGCIb8KuvIrCJvQPMNOE1M9Hq3CAoA9Cjo6A/8Yzu32sM9vJDqB//KpYVFljJ +LmgMFULPPphUgn10GLQT/xhowHbyrYg9Q+fTRL4hat8GtyL6gY4DlxAc8Zvrq0DuG4+ 0wY8Jiz5NsTKLF55CTF5NJF1WiT85aShLQu0gAa1BeuK349jMs38buCHKB+tdH3NQhAc jUJg== X-Forwarded-Encrypted: i=1; AJvYcCU+IAw5PfJIy9Dzd6kvOBMRqcyDG1lD4oRpUNoO0ODSdggoe9Tqn7s6H/SNHH+708WHEL9vywv7GjpUOT+njM+NpB3qS/On9+uPQnaOTVwv22oJ6nKEPqgB71rhwXlTcOADUFYRJHzl0g== X-Gm-Message-State: AOJu0YwnqxxNwDtl9FYdp2GZQzEW/IHSD0wMMEFNWrWgoRnCvOzUpkZm JIBGBPdQJQCIuqpMjbkRxHdTYAPIPEEnQ3dGjlUeTNhL0998MvlNMjp1+g== X-Google-Smtp-Source: AGHT+IEMN6LJ09VCFt9Do1cTmBEsRrCZL8Jp4MBZ1jlvUb81j6fRu2O297bvB51M9ADgvo0NthzAjw== X-Received: by 2002:a05:6a20:a114:b0:1af:59b9:e3ed with SMTP id adf61e73a8af0-1b2f96de772mr10918230637.5.1718030474101; Mon, 10 Jun 2024 07:41:14 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f728492b13sm71685ad.130.2024.06.10.07.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:41:13 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang , =?utf-8?q?Ren=C3=A9_Rebe?= , =?utf-8?q?Thomas_Wei=C3=9Fs?= =?utf-8?q?chuh?= , Armin Wolf , Stephen Horvath , Paul Menzel , Guenter Roeck Subject: [PATCH v5 3/6] hwmon: (spd5118) Add suspend/resume support Date: Mon, 10 Jun 2024 07:41:00 -0700 Message-Id: <20240610144103.1970359-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610144103.1970359-1-linux@roeck-us.net> References: <20240610144103.1970359-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 Cc: Stephen Horvath Tested-by: Stephen Horvath Tested-by: Armin Wolf Signed-off-by: Guenter Roeck --- 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(+) diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index d3fc0ae17743..d55c073ff5fd 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,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, ®val); + 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, From patchwork Mon Jun 10 14:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13692152 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 6354C13F450; Mon, 10 Jun 2024 14:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030479; cv=none; b=IFJp9Gg0KyIIo/taACYFJhdMRnk+IWRmQaWb4pZ1e/UjmaeTkaNBha4Nc5UKdT21pDB8ohvqbOuyHaxUxWEtYZIjMh/iBjH55/xPKy0d42VJyXyyLfnRuj0e723axLlvleWFJtuw/heApm3SFOd1JoydvZ/zUGnflIDh93gpx8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030479; c=relaxed/simple; bh=shikEARW8XTIQRtRy1i1PIfoqQb7U5jybyeOLhdBtvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oyBxFDsBD6PzvcFWwAq4Yh8KIyplL7ohWUNppUw4JKKvNRL0hZQgUb4j2Dq0JJx7jlGVEOA/VhowQhaJKlXnqSFp2AgGJTs0oBX8ql9RaredCxZfakkJ6CkePIdQ2/ACOa37njCVYP4Nm4iyYavk86QP/XpIBAIEW6n7LM2/Chw= 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=PU2gOiS1; arc=none smtp.client-ip=209.85.216.54 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="PU2gOiS1" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2c1ab9e17f6so3899686a91.1; Mon, 10 Jun 2024 07:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718030476; x=1718635276; 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=vSu3eodO6ltFeaNZljPFVoyOWCNP3NwVHj1cKcH7eTE=; b=PU2gOiS17c6AcG8cdbuA5VWJLH/TfidUv1Wvs3fkzuEdLkexHWcqZJ5ShH/b/Z0spY XcvY3YzEDS/j7Zokq9WngDBrLZA9qAItqPmP1t3FD5opzczPzqaeLwmRww27MLFqGwtP rxJjCcWHz8tNmjzNJ2l51nyibt5OsP59PeznwYsf7GMuDiLJXSXCA49dC7JvR3LCYIho KqHU+C9cHHI4jE2oMckHECOtuepouCp8uKB/sLYQ2u9/bZ4deFMg9gAy4BdDa0WXOUNy eGUMZ2htPZ744GdA7A69h9rA2XYk5Nrj45u4rYfhExk/X2AWAg/4MT4NnEJYOmIGF1Ta ELaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718030476; x=1718635276; 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=vSu3eodO6ltFeaNZljPFVoyOWCNP3NwVHj1cKcH7eTE=; b=osWEmsveHoHaSLRFNZqufN+f/BP6OaESuO3Id4cTPnbnxGMdxd0pk15vVEVTmU2z3l +1IZyGKKpE5XuteSqRNZRYX6+fJL/SKbLcwKj0U6IeH/SlrEmXU4QtE1iTkYB+demOiD 9WTSDUtvO8ozaRzkVT7fQVznfdWuII4sys7dq+A42jXIIxERBzGkXZ4uxd0IPr90zsOm ngHc5hGN+Qq/tkg6R7NS6DHrnzFcsCD71UXeUwI2968E9IeGmaowsIbzLfhoJw58gOy/ b0Thv7UXvvohPgGc1OupzJt3AaoFVcv8D8jh0hSjzIhFI6tihT4ZNHwhgFqUpv7J47u7 SrYw== X-Forwarded-Encrypted: i=1; AJvYcCUf2xLkEL/O3K9+0BVantQgFgOvcjblFsefgnnGb/zgJDieLGYk2M18KXJZZBBpua1CqV1jpdNyNLrBWUrJcywSkHtikphxupaobnUH6C7yRFelLHbLUJjHDssTUf4LyRegC+XBE02UhA== X-Gm-Message-State: AOJu0Yw6F5V0HO9rjlEOfb5DYpSGc0a9Pu0C70Z+CA/BRWLpUpwPfJp8 l94Zj8loSC6WCtUnKLcVTVKnouBtEIGPF3A7ipvVlIETc+tUXoBDmz1e3w== X-Google-Smtp-Source: AGHT+IGqPWvezuj9P6fxKhUmtxw8Lk+RScjVt0blWadPgwssBVjvY8Emlkeseq3P6fG8BVjwL0YkaA== X-Received: by 2002:a17:90b:b0f:b0:2c2:d250:2813 with SMTP id 98e67ed59e1d1-2c2d2502b82mr6455469a91.1.1718030475968; Mon, 10 Jun 2024 07:41:15 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c28066d573sm10648230a91.17.2024.06.10.07.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:41:15 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang , =?utf-8?q?Ren=C3=A9_Rebe?= , =?utf-8?q?Thomas_Wei=C3=9Fs?= =?utf-8?q?chuh?= , Armin Wolf , Stephen Horvath , Paul Menzel , Guenter Roeck Subject: [PATCH v5 4/6] hwmon: (spd5118) Add support for reading SPD data Date: Mon, 10 Jun 2024 07:41:01 -0700 Message-Id: <20240610144103.1970359-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610144103.1970359-1-linux@roeck-us.net> References: <20240610144103.1970359-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 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. Tested-by: Armin Wolf Signed-off-by: Guenter Roeck --- 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(-) diff --git a/Documentation/hwmon/spd5118.rst b/Documentation/hwmon/spd5118.rst index a15d75aa2066..ef7338f46575 100644 --- a/Documentation/hwmon/spd5118.rst +++ b/Documentation/hwmon/spd5118.rst @@ -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. diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index d55c073ff5fd..de6cf07f3007 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -53,12 +55,30 @@ static const unsigned short normal_i2c[] = { #define SPD5118_TS_DISABLE BIT(0) /* temperature sensor disable */ +#define SPD5118_LEGACY_MODE_ADDR BIT(3) +#define SPD5118_LEGACY_PAGE_MASK GENMASK(2, 0) +#define SPD5118_LEGACY_MODE_MASK (SPD5118_LEGACY_MODE_ADDR | SPD5118_LEGACY_PAGE_MASK) + +#define SPD5118_NUM_PAGES 8 +#define SPD5118_PAGE_SIZE 128 +#define SPD5118_PAGE_SHIFT 7 +#define SPD5118_PAGE_MASK GENMASK(6, 0) +#define SPD5118_EEPROM_BASE 0x80 +#define SPD5118_EEPROM_SIZE (SPD5118_PAGE_SIZE * SPD5118_NUM_PAGES) + /* 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 +struct spd5118_data { + struct regmap *regmap; + struct mutex nvmem_lock; +}; + +/* hwmon */ + static int spd5118_temp_from_reg(u16 reg) { int temp = sign_extend32(reg >> 2, 10); @@ -360,9 +380,111 @@ static const struct hwmon_chip_info spd5118_chip_info = { .info = spd5118_info, }; +/* nvmem */ + +static int spd5118_nvmem_set_page(struct regmap *regmap, int page) +{ + unsigned int old_page; + int err; + + err = regmap_read(regmap, SPD5118_REG_I2C_LEGACY_MODE, &old_page); + if (err) + return err; + + if (page != (old_page & SPD5118_LEGACY_MODE_MASK)) { + /* Update page and explicitly select 1-byte addressing */ + err = regmap_update_bits(regmap, SPD5118_REG_I2C_LEGACY_MODE, + SPD5118_LEGACY_MODE_MASK, page); + if (err) + return err; + + /* Selected new NVMEM page, drop cached data */ + regcache_drop_region(regmap, SPD5118_EEPROM_BASE, 0xff); + } + + return 0; +} + +static ssize_t spd5118_nvmem_read_page(struct regmap *regmap, char *buf, + unsigned int offset, size_t count) +{ + int err; + + err = spd5118_nvmem_set_page(regmap, offset >> SPD5118_PAGE_SHIFT); + if (err) + return err; + + offset &= SPD5118_PAGE_MASK; + + /* Can't cross page boundaries */ + if (offset + count > SPD5118_PAGE_SIZE) + count = SPD5118_PAGE_SIZE - offset; + + err = regmap_bulk_read(regmap, SPD5118_EEPROM_BASE + offset, buf, count); + if (err) + return err; + + return count; +} + +static int spd5118_nvmem_read(void *priv, unsigned int off, void *val, size_t count) +{ + struct spd5118_data *data = priv; + char *buf = val; + int ret; + + if (unlikely(!count)) + return count; + + if (off + count > SPD5118_EEPROM_SIZE) + return -EINVAL; + + mutex_lock(&data->nvmem_lock); + + while (count) { + ret = spd5118_nvmem_read_page(data->regmap, buf, off, count); + if (ret < 0) { + mutex_unlock(&data->nvmem_lock); + return ret; + } + buf += ret; + off += ret; + count -= ret; + } + mutex_unlock(&data->nvmem_lock); + return 0; +} + +static int spd5118_nvmem_init(struct device *dev, struct spd5118_data *data) +{ + struct nvmem_config nvmem_config = { + .type = NVMEM_TYPE_EEPROM, + .name = dev_name(dev), + .id = NVMEM_DEVID_NONE, + .dev = dev, + .base_dev = dev, + .read_only = true, + .root_only = false, + .owner = THIS_MODULE, + .compat = true, + .reg_read = spd5118_nvmem_read, + .priv = data, + .stride = 1, + .word_size = 1, + .size = SPD5118_EEPROM_SIZE, + }; + struct nvmem_device *nvmem; + + nvmem = devm_nvmem_register(dev, &nvmem_config); + return PTR_ERR_OR_ZERO(nvmem); +} + +/* regmap */ + static bool spd5118_writeable_reg(struct device *dev, unsigned int reg) { switch (reg) { + case SPD5118_REG_I2C_LEGACY_MODE: case SPD5118_REG_TEMP_CLR: case SPD5118_REG_TEMP_CONFIG: case SPD5118_REG_TEMP_MAX: @@ -396,7 +518,7 @@ static bool spd5118_volatile_reg(struct device *dev, unsigned int reg) static const struct regmap_config spd5118_regmap_config = { .reg_bits = 8, .val_bits = 8, - .max_register = SPD5118_REG_TEMP_STATUS, + .max_register = 0xff, .writeable_reg = spd5118_writeable_reg, .volatile_reg = spd5118_volatile_reg, .cache_type = REGCACHE_MAPLE, @@ -406,10 +528,15 @@ static int spd5118_probe(struct i2c_client *client) { struct device *dev = &client->dev; unsigned int regval, revision, vendor, bank; + struct spd5118_data *data; struct device *hwmon_dev; struct regmap *regmap; int err; + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + 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"); @@ -433,7 +560,16 @@ static int spd5118_probe(struct i2c_client *client) if (!spd5118_vendor_valid(bank, vendor)) return -ENODEV; - dev_set_drvdata(dev, regmap); + data->regmap = regmap; + mutex_init(&data->nvmem_lock); + dev_set_drvdata(dev, data); + + err = spd5118_nvmem_init(dev, data); + /* Ignore if NVMEM support is disabled */ + if (err && err != -EOPNOTSUPP) { + dev_err_probe(dev, err, "failed to register nvmem\n"); + return err; + } hwmon_dev = devm_hwmon_device_register_with_info(dev, "spd5118", regmap, &spd5118_chip_info, @@ -454,7 +590,8 @@ static int spd5118_probe(struct i2c_client *client) static int spd5118_suspend(struct device *dev) { - struct regmap *regmap = dev_get_drvdata(dev); + struct spd5118_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; u32 regval; int err; @@ -479,7 +616,8 @@ static int spd5118_suspend(struct device *dev) static int spd5118_resume(struct device *dev) { - struct regmap *regmap = dev_get_drvdata(dev); + struct spd5118_data *data = dev_get_drvdata(dev); + struct regmap *regmap = data->regmap; regcache_cache_only(regmap, false); return regcache_sync(regmap); From patchwork Mon Jun 10 14:41:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13692153 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 E3877135A6E; Mon, 10 Jun 2024 14:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030480; cv=none; b=CAKsklFfaUjC1bd2AHZ+rV55YlV51TyOlaYIcB5zZLuHcIQlzieRfsdWuRgFvoz/Gxoqd9L2lKW4JE9Y6oFL5QnNVuhV6wtFjT7ZU+k0dfndcDDmMpEtRLDEQF6bpe6gLhs82YCG5S2nDRcgHRm/1MYSuXU9aO59/4b4E4inslA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030480; c=relaxed/simple; bh=mdCr1zf8B7Ll/Iil5q/KFUOYdJ9yYqfw+FAXpSBZsps=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=gjgrkxaaM0nCBw/ERLUPq4eyVYQBH9dejfXsHIzP7JE1Pyq6GIwDmO4VUimKBFgSoxD6P7D7icpdqX6ys5Dk545dTP0dGf6ln9/Zr1/0C8xd1FVdLuMVIFVWAtq+eVP92yBapMb92e18wVkDWWMpdrnGNmgbrq5Htb6GT/fBnxE= 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=FEUn+buu; arc=none smtp.client-ip=209.85.216.52 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="FEUn+buu" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2c3051aee3fso933417a91.3; Mon, 10 Jun 2024 07:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718030478; x=1718635278; 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=4+PkgdXXou89sVVpBiLAp6lG13UU9DXBepbNyS0RY/Y=; b=FEUn+buuiXORtCh28hb98/EYcrNAZVCnhqKdunKb8E356KgjY9+AVhlPLD4aIGGIDX D1JEbi4M0vekvSprLD1hxfz2XkzRhLDXCiLo4VA34e9VxlDLDRpJeFjBmeFI+mtk6HjU w3RphND9X4qUJvAmQei2+lunw9NFe2Y3I/2vF6GtDAJNclmyOz1PZujQnQ7+JO0BsnhO coj/Uih0Ln+BCB2F78BuJ9ECSezuNA0ouXagy8AHzb37K7LgVArpC3tMVS8k0vGhHzVm bx90lp+5GNmS+1Oz2bdws1ZpVNpFGY4By34lDJTL9kW2cIlDcBxnhfFEGMO0Kdx0qRKf tqwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718030478; x=1718635278; 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=4+PkgdXXou89sVVpBiLAp6lG13UU9DXBepbNyS0RY/Y=; b=XLJ91F6TwGmZt4HxEuMnKgBuJKTMu0JNMairoj5h8yEwAsEv9H7aC3Gb3yS0lz/+QL DRdyZ9zgeFu8nWfAhfM65VJvRek9kzTKeqg6lMmcEGaxup3ggrLukXQvzgslXGCiwuS9 TT02S+3LugYwR50o81hd5nAqONvMwYsquXupWGvxpA8J7SHRWaFeairhksZ+02kUiyyC l3/x5RCf8ehVlr2XMV8FOuWAP6Kr/0DoiVD2GPthTi1GOd28SFJEKe9SR4EntalQXtKh ZZMIo9XM4hmGtiCnTh0vilIYfUSmOijbIfZSbsNQZI672IO/r6pgCRhF09fNl6GLnDc9 7Bdg== X-Forwarded-Encrypted: i=1; AJvYcCVfm7oCUNaTsE9JZbzpbj89Xv49bdXsHX/bPiWfzYvEcdyIe0w3mBW97aHwiDzsElh6bdjg9+mxzYniHcSveY9EdhgyHItVID0njR2xClIh7BhK2AvoymlD8W5tFkVm5/njxa0ayZcc3w== X-Gm-Message-State: AOJu0YzDNYdVwA9JiNrNwButvNDAZvYaskjor3/26haF/CFCITP+lO4o Q1Qs1riXKyqDuufTIrSd8HrgCPxlh4aZyiuvTr6knRfvt9T+OJyV5xVLGw== X-Google-Smtp-Source: AGHT+IEGHyGgx8eoYjZQOIoTylQHokUeZXRI3h1OVpag1CSxhFFMIg9ikpFiBCJNpDgpFi20vteGiA== X-Received: by 2002:a17:90a:2ec2:b0:2bd:d42a:e071 with SMTP id 98e67ed59e1d1-2c2bcc6b2b7mr8645226a91.30.1718030477777; Mon, 10 Jun 2024 07:41:17 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c31f22a9d9sm726864a91.40.2024.06.10.07.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:41:17 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang , =?utf-8?q?Ren=C3=A9_Rebe?= , =?utf-8?q?Thomas_Wei=C3=9Fs?= =?utf-8?q?chuh?= , Armin Wolf , Stephen Horvath , Paul Menzel , Guenter Roeck Subject: [PATCH v5 5/6] i2c: smbus: Support DDR5 and LPDDR5 SPD EEPROMs Date: Mon, 10 Jun 2024 07:41:02 -0700 Message-Id: <20240610144103.1970359-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610144103.1970359-1-linux@roeck-us.net> References: <20240610144103.1970359-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 Detect (LP)DDR5 memory and instantiate the SPD5118 driver automatically. Suggested-by: Thomas Weißschuh Cc: Wolfram Sang Acked-by: Wolfram Sang Reviewed-by: Armin Wolf Signed-off-by: Guenter Roeck --- 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(-) diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index 97f338b123b1..f809f0ef2004 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -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", From patchwork Mon Jun 10 14:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13692154 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 A587614263B; Mon, 10 Jun 2024 14:41:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030482; cv=none; b=ENDDC78mOwTMgheXOd0R95QBKfSaCzf2GepRycBPw6KxVm/YsOxPGT+DJS0F1u22h7+FW11fZJMuSaqJuRmhv+mYwJr341OLYgMwvqFM+OpY9QW+f2BmzR2ukwQjecyBaDxIpbYwD248HbWCE3Txz/FzNL+6HOUH5I+8BJbpxkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718030482; c=relaxed/simple; bh=eqaMSv5Aa4/kBy5g0iKnICdAo6+fypqw8AFbKQnuxkw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a7HNfKF780ENGb8952PGtSGE++x2FCR8pNIM9wn4paeNLmaymY6yiV9IQSZeM7213c8oS63/avpPy66HfO1GFaYCNASlpxqzTq65a+aUoE2vCO4ArnDTlaNrwNT5CoQS/Q4/nhbbeIF9zLjM8jG3MA7ZsV6bogGveWc9xAfB1Xo= 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=YG6FDjzJ; arc=none smtp.client-ip=209.85.210.177 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="YG6FDjzJ" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7023b6d810bso3545051b3a.3; Mon, 10 Jun 2024 07:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718030479; x=1718635279; 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=BKkziaSKSr/muOq1HRAFyB+WD5eSBI8YIdJmSO2EbMk=; b=YG6FDjzJsOxT2GbicoQBxzx2W+NiI0ywx6nSe7kX5n6OB9CS81eDIq3GOioYuipo/C ga2uG8Kn3HWw2ZuIIyzuNFLfYZpLxdOaHh648iL5BWfWsnRrL2IqT8QGXHRA1PYnp4hs Dv6P6TmLybgCfaxJGO/46ZuA1SuFqAAEniPvhJCKrhvPrBb+SLHSzVQ0LYFnBWvJ1vmN X5Zz/yQvi9XmElOuDo6GgWzmr9UBkEdaOvvNQtOrGqVaUIpNQU9cpMOxS1JAeAZiWuKs Y4NsBfwKD+tJGqGMfBUOHSzaXNxPvb6fWKhVYiHysIZ8UtT8kuHXMzJ4rfKf6da/iAOq XomQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718030479; x=1718635279; 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=BKkziaSKSr/muOq1HRAFyB+WD5eSBI8YIdJmSO2EbMk=; b=iRaL39HMk1CgysRHT0IuOCq89yEnAGGhbIuJwLU/lpE/g6H6sZw15eW0666olJfLdO 6GgrqqqV2DFs5ViJlfrGMwLn29/bQCnmN3DDUEWP65qgpqg4mv7mKSAyEorlDdtHW3JZ Rs3cwLPl4ysB/7FfWYB97vTUnNMI4b8niqE0CFP5wUiBmfVDsaE4tcS+yBmdJibCKDNW DQI21lU7jGM/pgxMfPCKwFaWiOGTUy1F5Q7/uwjzSWtQMO2sMI+ytpaCJbXx9lyht803 tBTnE1LQvi0D5eESHGaTUyfQP29NSy229m84MWCx+eu/oQOUYoRGxT6PVcZHKyzmCIC2 pvPw== X-Forwarded-Encrypted: i=1; AJvYcCV8FIgx6OQFwtRZK0Ztcs+yXOfjY8M8H8eJd97RHsBcNfBuAM++Xk9+e3DI5soPYRWe/vdv8he2PzeubDKdFkboKXf8BSc47XbuFWbZZosSzsf+5Qe++SM87I6VNcXweR4ihRNRwtkVDg== X-Gm-Message-State: AOJu0YwY9iUOgyWrjC4jAujCMi/oZKMnYaR2i/IB3BlCc3GtjtPVOXXg gThudZv75m3ogyGvnkHm8R8SLvVD/DgAUaAEy+GyDcBoQjLPa+GuY79ndg== X-Google-Smtp-Source: AGHT+IEGygyaEEzNJcvfGUiBscSz6qRFlJq4IfwsDQFQ9QBMcu4Vuk/Vz3+vZUX2LI4nK8RxdU3dFQ== X-Received: by 2002:a05:6a00:4790:b0:704:13d0:a7cb with SMTP id d2e1a72fcca58-70413d0aeccmr6270995b3a.13.1718030479556; Mon, 10 Jun 2024 07:41:19 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705382784b9sm2146318b3a.48.2024.06.10.07.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 07:41:18 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang , =?utf-8?q?Ren=C3=A9_Rebe?= , =?utf-8?q?Thomas_Wei=C3=9Fs?= =?utf-8?q?chuh?= , Armin Wolf , Stephen Horvath , Paul Menzel , Guenter Roeck Subject: [PATCH v5 6/6] hwmon: (spd5118) Add configuration option for auto-detection Date: Mon, 10 Jun 2024 07:41:03 -0700 Message-Id: <20240610144103.1970359-7-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240610144103.1970359-1-linux@roeck-us.net> References: <20240610144103.1970359-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 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. Cc: Wolfram Sang Tested-by: Armin Wolf Signed-off-by: Guenter Roeck --- 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(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 7a84e7637b51..d5eced417fc3 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -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 diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index de6cf07f3007..ac94a6779360 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -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);