From patchwork Thu Apr 24 03:35:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yo-Jung \(Leo\) Lin" X-Patchwork-Id: 884098 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A7921B0411; Thu, 24 Apr 2025 03:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745466306; cv=none; b=BnPGOPAgx5EmHM18F6XIskFIhUnesq6AfvWVkGPXIBa2lNf3kAkj01ZAIbGej38EP8JZehnlPehrbViwPQA/c5Z/6zY1pzwtzuHQkp0XTQrqId/c5N6JBZW/Cb+QMK06HJw5iz+FHwE2usX67m2phHO21AE3ZLiHbeCSWJdU3OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745466306; c=relaxed/simple; bh=VhkHoUdxKl4O9TthbMASF0VVm4EmFSje5xdRL9hofKs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J5g9LJQ742Q5sUQ9ry6p72+U2Afjn+Y3vM+5ujRkXV6GlwxZU2I3ZxOYAyTEyTeM02QtvVbJie8pA+cEd2CaDvTS2ah2yYq7YgcJ2GfvJ40QRBr8nYIFNrD9R4YKU8yNPhP1Mb6MBndyer1BxOkjEP/9vzbDfUg2M7YOkpMjazc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=iQDVqaoD; arc=none smtp.client-ip=185.125.188.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="iQDVqaoD" Received: from [10.102.98.142] (unknown [10.101.200.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 295D23FFEB; Thu, 24 Apr 2025 03:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1745465797; bh=0jZ8ricmTcuy3cC7y+FRlhMCNHHbkhvvP/2DbcyHPQ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iQDVqaoDYX3VLscrqLbu+Cvr8DVa2vJ1umbKQSyV3dBK5qTX/tj2G2jySfCM6kQr9 OnqEolA3bp16LqpiRwwsCAg3JnuFYXsCbtEqYapbztrErt09DdJoMAUxJyBPO1OIbB geiDdHwCiMwOqY0XAWsC9C/Qk9YsA0j+pkki5jSdbPnT+ugbQ4f11MDX3rsiLi9mtf yEhjTGwlIdIWuun+Z2HroKglfuTUsJiW0W1Cje/OKv6muP4Gwppoz8HsvnjlFPuXEy E/oLQYgxqiQpTDyKMUdlF3ELoo4PvmHqxDCk2WUbyksSS+bOiuW7UP670y+jIE03r3 agi3YO15R69Xg== From: "Yo-Jung (Leo) Lin" Date: Thu, 24 Apr 2025 11:35:43 +0800 Subject: [PATCH 1/2] i2c: smbus: pass write disabling bit to spd instantiating function Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250424-for-upstream-i801-spd5118-no-instantiate-v1-1-627398268a1f@canonical.com> References: <20250424-for-upstream-i801-spd5118-no-instantiate-v1-0-627398268a1f@canonical.com> In-Reply-To: <20250424-for-upstream-i801-spd5118-no-instantiate-v1-0-627398268a1f@canonical.com> To: Jean Delvare , Andi Shyti , Wolfram Sang Cc: Guenter Roeck , "Chia-Lin Kao (AceLan)" , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, "Yo-Jung Lin (Leo)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3110; i=leo.lin@canonical.com; h=from:subject:message-id; bh=VhkHoUdxKl4O9TthbMASF0VVm4EmFSje5xdRL9hofKs=; b=owEBbQKS/ZANAwAKAV8XsZZKKe6GAcsmYgBoCbG8J/5XjP98f47h12j9AMFRG7jbXLs9BJV2d to26hHr14+JAjMEAAEKAB0WIQQzqV4kW+yguuqHrw5fF7GWSinuhgUCaAmxvAAKCRBfF7GWSinu hiOgEACtmfl1Pi2lo6FGwrRpOP7K81E4x78ypPmnzP6Vnbw0ar3RXehWA1VnB5j1yDmvYoHoasz XL303HB741gnmmrsgkQM7AjNY0cyNDEdgpL6iHIP3nG/x8Er9ayoq6uiDTrh3tlGOl60gXRgMm1 RFhg2aViBfDy6/9aT0nHE9u/qPT1Y5+PKlDX6oqwE4mFsOlrO96tlhraugTdQSqJ+esySnZiyQ6 2Vm5lFafNE+oQKYP6TiTEvEGP2jcgDgtF/gRlUCl6g6rQPsfFIY1wEZ0EmGm4In6ubK8NcuAG7W YX04TfZpshd2qAzfLDjKHvv2p3FjWqdDFAnonw1GKFcPIBzT5fmaGziiyDxRm8UjHu7RMoWbV2W rwvyfW9d3jL6zC1FbuNdOqvH5ja+gUMRhwde7uViExb9TXZ9oFbpIb8KZkHM+19rUzgbe4HxFyX KhAxL2LR5GlrsaNOrwymMQQYFI7FLS2vrqixIdciA4s9Y7ammhPWz5HUrYCIoA0ReIe90FprUb1 ATYZQPTM5fG/bmQTTCf+74yStEZg5Va2zOK3GvpMFIuIhvBnd/I83PZ5O8ptZCmRha5I1Txn9+W B+3WA9RQozFqiDBf73v4pHP/fh0TcyqwVEVfRKgtlkdgylWBiZyXZEbvneAN/zp0xwRopdWxt0I CJmlwCsHDrDZvyA== X-Developer-Key: i=leo.lin@canonical.com; a=openpgp; fpr=33A95E245BECA0BAEA87AF0E5F17B1964A29EE86 Some SMBus controllers may restrict writes to addresses where SPD sensors may reside. This may lead to some SPD sensors not functioning correctly, and might need extra handling. Pass this extra context to i2c_register_spd() so that it could be handled accordingly. Signed-off-by: Yo-Jung (Leo) Lin --- drivers/i2c/busses/i2c-i801.c | 6 ++++-- drivers/i2c/busses/i2c-piix4.c | 2 +- drivers/i2c/i2c-smbus.c | 2 +- include/linux/i2c-smbus.h | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index 48e1af544b75..95619eb5e798 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -1180,7 +1180,8 @@ static void i801_probe_optional_targets(struct i801_priv *priv) #ifdef CONFIG_I2C_I801_MUX if (!priv->mux_pdev) #endif - i2c_register_spd(&priv->adapter); + i2c_register_spd(&priv->adapter, + !!(priv->original_hstcfg & SMBHSTCFG_SPD_WD)); } #else static void __init input_apanel_init(void) {} @@ -1283,7 +1284,8 @@ static int i801_notifier_call(struct notifier_block *nb, unsigned long action, return NOTIFY_DONE; /* Call i2c_register_spd for muxed child segments */ - i2c_register_spd(to_i2c_adapter(dev)); + i2c_register_spd(to_i2c_adapter(dev), + !!(priv->original_hstcfg & SMBHSTCFG_SPD_WD)); return NOTIFY_OK; } diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c index dd75916157f0..085d121a88f6 100644 --- a/drivers/i2c/busses/i2c-piix4.c +++ b/drivers/i2c/busses/i2c-piix4.c @@ -971,7 +971,7 @@ static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba, * This would allow the ee1004 to be probed incorrectly. */ if (port == 0) - i2c_register_spd(adap); + i2c_register_spd(adap, false); *padap = adap; return 0; diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index 7d40e7aa3799..97e833895dd7 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -372,7 +372,7 @@ EXPORT_SYMBOL_GPL(i2c_free_slave_host_notify_device); * - Only works on systems with 1 to 8 memory slots */ #if IS_ENABLED(CONFIG_DMI) -void i2c_register_spd(struct i2c_adapter *adap) +void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled) { int n, slot_count = 0, dimm_count = 0; u16 handle; diff --git a/include/linux/i2c-smbus.h b/include/linux/i2c-smbus.h index ced1c6ead52a..57bb3154eb47 100644 --- a/include/linux/i2c-smbus.h +++ b/include/linux/i2c-smbus.h @@ -44,9 +44,9 @@ static inline void i2c_free_slave_host_notify_device(struct i2c_client *client) #endif #if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_DMI) -void i2c_register_spd(struct i2c_adapter *adap); +void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled); #else -static inline void i2c_register_spd(struct i2c_adapter *adap) { } +static inline void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled) { } #endif #endif /* _LINUX_I2C_SMBUS_H */ From patchwork Thu Apr 24 03:35:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yo-Jung \(Leo\) Lin" X-Patchwork-Id: 885155 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 335D11A8F8A; Thu, 24 Apr 2025 03:45:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745466306; cv=none; b=UOfVWkL+Dezea9Vf0ieDvoaUVApQIi6vv3kglpxbAdLlU1g+/TvqtGXoTUVUvG6D+oBa2+FHMgeRMgYavuZl105qnAqJpFITnIwpRoo4PGW7OwDOJ7cQNLViIPnFBlpqpZmB3xAZrLJAUsJ42LIMrOldrv68nJ7BA7Oo2xCsu38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745466306; c=relaxed/simple; bh=NnqERpE7eR8g8r0iLIpxS2uNkqlSpGP9aGgq+2djYg4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pENzuJXNFqpz+azhLPUThtnqztKuK2+t4gSHm3SeAb0jxXa+0niclR29I0gRE2ZQ28kGOMv4sBnFUObJsiG1vLSLBKUrVvCU2r169HdyJ53kckh+K7cFq3gMcTumFZfz9pglqZQNUYofN7hkIZObIMwe3ilz8F2cnXBLrNXHD/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=Tt5LiOcQ; arc=none smtp.client-ip=185.125.188.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="Tt5LiOcQ" Received: from [10.102.98.142] (unknown [10.101.200.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id B5C913FFEC; Thu, 24 Apr 2025 03:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1745465800; bh=9TuPK+Tu+4yd7SCrzNeveB7vgYe62My2LDqUfykqOFc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tt5LiOcQKE1L/PtyBiv/DnoXVkcXZKjrW8gvZ2XrCSHD+yKSqup/MpCDyWq0hL/9q i92PECtVLm8IkhcEtnWFLipqraRLHFR9amxKgOQIOTc18R0M8TlmlhcRhCd+Dp2nuY CJ42FF4S3UfV6uzW/D6W+LoRzu2ZjMICNlJuCo6N92k4rTvNmXsFbJNdoaFvPTWCrO HhFcni9PEzl1ayXzDUdmOho8ZCIUriIF1OAl1SwnNPe6h8vT9Vgm2TjGApVUhef9Tg /pVFs2g1/YJPVfI9mLpG52aYEz9U5iCw4vXAk+njdTWlcnOxvy1XdjgMW0v27myxmZ m+Nnm2X73Ra6A== From: "Yo-Jung (Leo) Lin" Date: Thu, 24 Apr 2025 11:35:44 +0800 Subject: [PATCH 2/2] i2c: i801: don't instantiate spd5118 if SPD Write Disable is set Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250424-for-upstream-i801-spd5118-no-instantiate-v1-2-627398268a1f@canonical.com> References: <20250424-for-upstream-i801-spd5118-no-instantiate-v1-0-627398268a1f@canonical.com> In-Reply-To: <20250424-for-upstream-i801-spd5118-no-instantiate-v1-0-627398268a1f@canonical.com> To: Jean Delvare , Andi Shyti , Wolfram Sang Cc: Guenter Roeck , "Chia-Lin Kao (AceLan)" , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, "Yo-Jung Lin (Leo)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2192; i=leo.lin@canonical.com; h=from:subject:message-id; bh=NnqERpE7eR8g8r0iLIpxS2uNkqlSpGP9aGgq+2djYg4=; b=owEBbQKS/ZANAwAKAV8XsZZKKe6GAcsmYgBoCbG9Stdu01Wp2ar44hPp3CIGHsuW4dvAyyq/X fD466cwV2qJAjMEAAEKAB0WIQQzqV4kW+yguuqHrw5fF7GWSinuhgUCaAmxvQAKCRBfF7GWSinu hgl+D/988uFs6hJ3+3qTA3IDg7pYKd2cw3W2eJUAJben9yBdu6Mxu70241Xih3tY5bgwq9aZGv1 SxGOskARCwOZaAWe//d9LrOZxebnOOAMndiEwHSm4RiOUnf/Nli6DZGzvq5J67ZTz+Jq8IpjDDv 9fhLx1jSlTDNnATLcRqyj/amCxrWvHE/CD3tEquuQky6sl5IE26D8A0QheVh2y+kcG5BG+1XS9d qAnSZONUVEeCnQf/Q0UTCk/pcUJDIFRq5ENNF4y9AgpmGfwW2XHTWA+wjfeUfH0jdHqmU1UFGrg hI7DOofls/mi9IiY4yma4JMumUNta7Cm6WcQyGsatQa0nStkNzLf9eJ28zRyoTvl3tLdsUMfBoF LTY0YFgZMTls71t44hiAHBVrNZMfbbAfGiXpw5G6/5cmI8vz70V6KDZ/UtkV+NGA/2DogvTldSo fSPFNzx1PS+ecYoCOaKBrGWO8UyQiCufYCwzopy8F927SvHro44//0CjdqCfWJxxDpmWcKGfHjK 3j2LpZzr0NscROZmpkpdO3TEE44I4e0FrOZt1rFhFFqGE3dZZn3m6GDVzoueyFAGskb+x0PLDPy s+/HAGclTAdsMR+gse6njr2SlpaFsiMiUcOc3KYgGw5thO7WvQG8Y9Sp0cVe45rGIfVfnLSbYEI vkdowSPIRlDVhGw== X-Developer-Key: i=leo.lin@canonical.com; a=openpgp; fpr=33A95E245BECA0BAEA87AF0E5F17B1964A29EE86 If SPD Write Disable bit in the SMBus is enabled, writing data to addresses from 0x50 to 0x57 is forbidden. This may lead to the following issues for spd5118 device: 1) Writes to the sensor hwmon sysfs attributes will always result in ENXIO. 2) System-wide resume, errors may occur during regcache sync, resulting in the following error messages: kernel: spd5118 1-0050: Failed to write b = 0: -6 kernel: spd5118 1-0050: PM: dpm_run_callback(): spd5118_resume [spd5118] returns -6 kernel: spd5118 1-0050: PM: failed to resume async: error -6 3) nvmem won't be usable, because writing to the page selector becomes impossible. Also, spd5118 from some manufacturers may set the page to a value != 0 after a sensor reset. This will make the sensor not functional unless its MR11 register can be changed, which is impossible due to writes being disabled. To address these issues, don't instantiate it at all if SPD Write Disable bit is set. Signed-off-by: Yo-Jung (Leo) Lin --- drivers/i2c/i2c-smbus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index 97e833895dd7..cb7ef6a7a174 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -378,6 +378,7 @@ void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled) u16 handle; u8 common_mem_type = 0x0, mem_type; u64 mem_size; + bool scan_needed = true; const char *name; while ((handle = dmi_memdev_handle(slot_count)) != 0xffff) { @@ -438,6 +439,7 @@ void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled) case 0x22: /* DDR5 */ case 0x23: /* LPDDR5 */ name = "spd5118"; + scan_needed = !write_disabled; break; default: dev_info(&adap->dev, @@ -461,6 +463,9 @@ void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled) addr_list[0] = 0x50 + n; addr_list[1] = I2C_CLIENT_END; + if (!scan_needed) + continue; + if (!IS_ERR(i2c_new_scanned_device(adap, &info, addr_list, NULL))) { dev_info(&adap->dev, "Successfully instantiated SPD at 0x%hx\n",