From patchwork Tue Jun 18 19:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13702904 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 B79B716D4DF; Tue, 18 Jun 2024 19:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740436; cv=none; b=em/2FsuhWVLKMpyRARQlqvn/7MmgvLkhGEu6l/7eDqPxmdk0kHWfYx6wCopCE5ll5/A90BfTM1wF2y2y3TF76qo1XZXsS+mb4EWMaMQpSrUAYd1i/QOfwbYtQenSzNPvAmd+WterGqfPEGI8os1oUfhj2Y79ueyTX5nl1pKZYNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740436; c=relaxed/simple; bh=QCWiy8S2iBkH0R0SO+YmV+SSyy1AmkG+MWl4tYbfKik=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gKevoaHO1KDTlFW5IibQzUgQdyQCNG2QgldNHEJmGxwP2w+SdXTh826Tp9n3YA0CxMXsLQZ7xIqqygIOVkvDr1zS74ZyMbtD0Aww7ZLRJQxJFLTxosH1u668QPiALdku5Wh2ztcrjRkVWNi6fzW+O0uOHa31wFADk7GVZULqFCc= 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=B3YKNQAq; arc=none smtp.client-ip=209.85.216.42 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="B3YKNQAq" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2c7a6da20f2so615063a91.0; Tue, 18 Jun 2024 12:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718740433; x=1719345233; 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=TutLNJ37uRVCH3BzXMcNA2MKiY+pMX5ozT8SeedjlP8=; b=B3YKNQAqJGNvQF3t+JxG/3Uk9c2Fn4F5RNvGTzkXCNUFGYsB1nXTjJvnmDPyVZwMJ2 DcKqvf08+LWLS27SnhdNO8a1NIVp6a2EDE+l2rIUkmAsAhfnjzaQbEA8BWHeU1V+YjvW r3B4jkJUdCBko+dFeA2GbcdydguP+HvV3FaOYtToExI8iU264+rC/AGwd0owOxnL9x8/ Zvv7HLHcl/zfP7Vs34pdYbwLf+esAT8tO+ZD8KDD5i1aAKYfLDZDgGkWsD5tcW2V4Y0o pQ0hNdTqEFmrV/Hsqu1Wks5teLp5yrEdE7Nu4OWG/AQdAqzoWf121lQVroC+KJXnicqG 4S/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718740433; x=1719345233; 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=TutLNJ37uRVCH3BzXMcNA2MKiY+pMX5ozT8SeedjlP8=; b=MJlKfqIUQ9/59O8Ig2VjsS1FrPRNnu+F3d2zwmB/HXC59RJ3G4O7Cf747DObCzT5ip +fbhDUP7WCh+zHaLu35oZocQIeBuaBZcoC0wLCLbVRhy2guHD3ob9/PbQtMHggRSWeN6 HHgnTJnC3UKYzh1oxSsvxxCwu8Embgth54XuD4X0LLNEP33xt8RXruba4/FdW3QMRfqn GMaa5RsH9L0rOzo/Shzc5s5JKLD4uxK3Kkw3Z9nBOrKg6jXapsHDyvNV8xThqBrqFwMu t85qlEFLjTSuM16j/4C3CppOZyd8eNa0jsUjqyGXXgmHoZW2t0MCRHzh0HsxlRQj1+0z Q1tw== X-Gm-Message-State: AOJu0YzVynYvwpgU4GjNnJ5uv/nekHhWXbH2v7Mx65ZZ2P4RR+k0YUdy HQS7zGxcB9wCLS18uxSIHbv6nqM/GKsWicE0t8qG4n/e2SQBmgkdeKBqtA== X-Google-Smtp-Source: AGHT+IGopO9q2SH+xzHUoaChE+56XCp/6NqPcQmOwVlMrCtlRrv+f+adCZSLWpEVe4Yqqf4HqzKjcA== X-Received: by 2002:a17:90a:df06:b0:2c3:1d61:ca41 with SMTP id 98e67ed59e1d1-2c7b5b7e2c5mr733499a91.17.1718740433547; Tue, 18 Jun 2024 12:53:53 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c50c911c92sm6130224a91.49.2024.06.18.12.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 12:53:53 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, 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 , Sasha Kozachuk , John Hamrick , Chris Sarra , Guenter Roeck Subject: [RFT PATCH v2 1/3] hwmon: (spd5118) Use regmap to implement paging Date: Tue, 18 Jun 2024 12:53:46 -0700 Message-Id: <20240618195348.1670547-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240618195348.1670547-1-linux@roeck-us.net> References: <20240618195348.1670547-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 Using regmap for paging significantly improves caching since the regmap cache no longer needs to be cleared after changing the page, so let's use it. Suggested-by: Armin Wolf Signed-off-by: Guenter Roeck --- v2: Added patch drivers/hwmon/spd5118.c | 47 ++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index ac94a6779360..d405c5ef755d 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -382,45 +382,19 @@ static const struct hwmon_chip_info spd5118_chip_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 addr = (offset >> SPD5118_PAGE_SHIFT) * 0x100 + SPD5118_EEPROM_BASE; 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); + err = regmap_bulk_read(regmap, addr + offset, buf, count); if (err) return err; @@ -515,13 +489,28 @@ static bool spd5118_volatile_reg(struct device *dev, unsigned int reg) } } +static const struct regmap_range_cfg spd5118_regmap_range_cfg[] = { + { + .selector_reg = SPD5118_REG_I2C_LEGACY_MODE, + .selector_mask = SPD5118_LEGACY_PAGE_MASK, + .selector_shift = 0, + .window_start = 0, + .window_len = 0x100, + .range_min = 0, + .range_max = 0x7ff, + }, +}; + static const struct regmap_config spd5118_regmap_config = { .reg_bits = 8, .val_bits = 8, - .max_register = 0xff, + .max_register = 0x7ff, .writeable_reg = spd5118_writeable_reg, .volatile_reg = spd5118_volatile_reg, .cache_type = REGCACHE_MAPLE, + + .ranges = spd5118_regmap_range_cfg, + .num_ranges = ARRAY_SIZE(spd5118_regmap_range_cfg), }; static int spd5118_probe(struct i2c_client *client) From patchwork Tue Jun 18 19:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13702905 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 4A8D416DC1C; Tue, 18 Jun 2024 19:53:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740437; cv=none; b=c2JJzLiHqtBoC4D2az5QWd3Z5E2W466XyQUIWGyDKi9GIu2moyzgFMbWWXJ1RYUB9aGpsHAXI5kdX7MqgZNhuL+5ibYBV2XixbwRlFzDjKzf9QRgy3TnObf6uuO91qC7QqYUm0Zdv/FwfgGOFQ0R0V7BFD6gFmQcqSgJiNIlRCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740437; c=relaxed/simple; bh=82spDEIGhtFCgEtCb6qyJ82SA/FC3rJrhTS4o90L334=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gnliciz5ZNpmh49kBB6+hCQamjw21gTPtDl4Fp0olRwSq273sD0sy+4NDa5+mm14g6dTL94e7X+K4/ZT8BIeWdXG3EtBdjpUAqDzyPYVY4uu8GdITIsc+4k7xl5jvtiBUpMQ0kU2L/syDJePS+vBLXNfqXY7fAfy3eqdePQUQtQ= 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=Gvoxhnbz; arc=none smtp.client-ip=209.85.210.172 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="Gvoxhnbz" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-705c0115192so4948477b3a.1; Tue, 18 Jun 2024 12:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718740435; x=1719345235; 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=R4xI1qGGU9cjMurdZFNvmg32N3b1z8wGZUQlDVo3QRc=; b=GvoxhnbziDA3F/tXM5FZ+N2zIaMfCppnZsM6tmlD6eNefBF3cNerFbgavUUUskwnO0 vMLim7hHNK1UiGx7ziMQLBIvB4tvHNm78tSU0vxR4tnpbOARgHuIMAzLzFM53qzR9PRN 08xyFknwsRO8ugT3iGjG+Z2uWhrrU0QXpy/faUgJoBjp2zcL/ml9LVM8D9IEFo7ARuQF fofRaGoiDqvr2TrPDptgvtw7ZXOHQTlI7LPO5KdYL6q4YBQOZ1uQ/DSN05jqO/clnTzK iZbc+B5kW9VMcNQsS0QOqSV6sWifUG7nOgn7JvZLfmNesKbpQ8TSHFjCX5pR8T5hjJZ/ YHLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718740435; x=1719345235; 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=R4xI1qGGU9cjMurdZFNvmg32N3b1z8wGZUQlDVo3QRc=; b=drHZqWlKL9End8WwjWWgNlZMr3KqmqTj7i+tukrz2OMLncnz0iXC4dcJG7Zpomvt3T 5UmbZWudqss8clL2QOJS7bgAhwUwiBMILkpIQyFQlXPL0ksmxyNb+vrqcMOzCiG+8qSX yS8mA1rzZq2DSGHjHatklCbqlCya0FaAN4vVzI+YBd7U0gVLLgM/NokH5kCRR4XG7LZ4 1SyEwUm8OqXB10M0Bj9F6BmMIWjLqaV5UEV5JNWEGgqC8rtGgbZLaUwx8IbXMkx4pjje GeWKWu+CLoHxTY1hSLCf20aDKW8GqEt3k034KtGmLk7U3fX8tg+/cyV3YAWQ26WI+YEU lw6g== X-Gm-Message-State: AOJu0Yyt9yzv4lOR98AHMAS9Cdad3xZCzmDI1DQDBy0u7JC75E1PjfMi O211SqsaMzPR72LsdBdiY8GurQ7Tj1cTBkWPVZhwkrUjIafX7GPoiNI6rg== X-Google-Smtp-Source: AGHT+IHIPdCTDzuT52NsmK/SHlpshdhRoY3yFcIknwSIvMz//8KnMEs12aDaROr0kh+JKhHagxGrAQ== X-Received: by 2002:a05:6a00:bc6:b0:705:bfaa:3891 with SMTP id d2e1a72fcca58-70629c4d406mr610172b3a.17.1718740435017; Tue, 18 Jun 2024 12:53:55 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb90a33sm9349382b3a.187.2024.06.18.12.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 12:53:54 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, 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 , Sasha Kozachuk , John Hamrick , Chris Sarra , Guenter Roeck Subject: [RFT PATCH v2 2/3] hwmon: (spd5118) Use spd5118 specific read/write operations Date: Tue, 18 Jun 2024 12:53:47 -0700 Message-Id: <20240618195348.1670547-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240618195348.1670547-1-linux@roeck-us.net> References: <20240618195348.1670547-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 regmap write operations on i801 controllers were observed to fail with -ENXIO errors. It appears that the i801 controller and/or at least some spd5118 compatible chips do not support the I2C_FUNC_SMBUS_I2C_BLOCK operation used by the regmap-i2c core if I2C_FUNC_SMBUS_I2C_BLOCK is supported by the I2C/SMBus controller. Stop using the regmap-i2c core and always use basic SMBus operations instead. Reported-by: Paul Menzel Closes: https://lore.kernel.org/linux-hwmon/33f369c1-1098-458e-9398-30037bd8c5aa@molgen.mpg.de/ Signed-off-by: Guenter Roeck --- v2: Added patch drivers/hwmon/Kconfig | 2 +- drivers/hwmon/spd5118.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index d5eced417fc3..fdfa778a965d 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -2184,7 +2184,7 @@ config SENSORS_INA3221 config SENSORS_SPD5118 tristate "SPD5118 Compliant Temperature Sensors" depends on I2C - select REGMAP_I2C + select REGMAP help If you say yes here you get support for SPD5118 (JEDEC JESD300) compliant temperature sensors. Such sensors are found on DDR5 memory diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index d405c5ef755d..995c45e2a997 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -489,6 +489,31 @@ static bool spd5118_volatile_reg(struct device *dev, unsigned int reg) } } +static int spd5118_regmap_reg_read(void *context, unsigned int reg, + unsigned int *val) +{ + int ret; + + ret = i2c_smbus_read_byte_data(context, reg); + if (ret < 0) + return ret; + + *val = ret; + + return 0; +} + +static int spd5118_regmap_reg_write(void *context, unsigned int reg, + unsigned int val) +{ + return i2c_smbus_write_byte_data(context, reg, val); +} + +static const struct regmap_bus spd5118_regmap_bus = { + .reg_write = spd5118_regmap_reg_write, + .reg_read = spd5118_regmap_reg_read, +}; + static const struct regmap_range_cfg spd5118_regmap_range_cfg[] = { { .selector_reg = SPD5118_REG_I2C_LEGACY_MODE, @@ -526,7 +551,8 @@ static int spd5118_probe(struct i2c_client *client) if (!data) return -ENOMEM; - regmap = devm_regmap_init_i2c(client, &spd5118_regmap_config); + regmap = devm_regmap_init(dev, &spd5118_regmap_bus, client, + &spd5118_regmap_config); if (IS_ERR(regmap)) return dev_err_probe(dev, PTR_ERR(regmap), "regmap init failed\n"); From patchwork Tue Jun 18 19:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13702906 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 D22DE16EB58; Tue, 18 Jun 2024 19:53:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740439; cv=none; b=suVY9f/PJnajThOzZSsR/XGiD702kjMVqr9c34OQkBOVOYD6IhVYNQd0AcmBPk9Y7uwMwM/+O38YbaBZBw47lBxW8cOkCggzrQBuuWlo2InCR6WgW/cklah4tRtPoC909hfLJz2MvDPrQzsVjjhn0i0EzCYXLds59InxFQ4JWqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740439; c=relaxed/simple; bh=XkpZEMXaJWJ+1VF4LA+imV+crtqchhcJeUMjkZlQX0s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ww4SYw+qhEJkjv/P0CFdFEIgDtBditrs6of0zFvktVA4SgbtmpHvApsTTTnUzbwwYoHCt+3nRRXUreM3lamArm+Tg/LSqq2xyJHWjy1wbcofLWy5XSLXWFASLII1lAlvS4zdrFb5R6m2DLaAfjIgAgKgCfhgQxOhm8kSZhZDEXM= 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=ivmLDKNa; arc=none smtp.client-ip=209.85.214.173 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="ivmLDKNa" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f700e4cb92so50956855ad.2; Tue, 18 Jun 2024 12:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718740436; x=1719345236; 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=45FkWHWTnI7wDlZNwvZj68CZUnQTmaeCkeuNifaEhvg=; b=ivmLDKNaGXVQF6aloRFQJeIw1qAkXKD08IjYTJtSTER3+HLLFNmkRHeTcvqnnCtCir rZ0GxNW7e+kZNm8CX7X3FbP1N9ypY/l2z4t84nwW4pYOVat//9FDK4FSHuRdtpdwITgU PE0Eibup7gDNpPmsaC89tfv5FblHZVRHB6nwxC0aPnHAu7RCOt+G/HyogSfI0QzFE/ZT PpiGUZrS63y9sEIEkCWNFjwnsAPr+DiZsU/dtoZg98Ym+Y7Tg2YcNUpkPY945E6ZRIkV UNR7Jm7+Jss3okqsVtiVyTSRa7rFn2LA5+GVHPqA0zH/aBFWu4VoHwxSA8UG2Fjtk87F WbGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718740436; x=1719345236; 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=45FkWHWTnI7wDlZNwvZj68CZUnQTmaeCkeuNifaEhvg=; b=W0I10I+fDb7E/SVAV4QIENZglPCG8K2Xt37YR3jK3FKJ+mBR384m9SoI+6ZLYWePS0 VaxAqrg1Du0s7hONlMbX56xMvnFSH8lMXstIKkJJefWiGcGvxocqIBa3SauDlDu+YDJa eymgPkdsGfK17DvryjDb+HHEj/tYuadrifeBFSH9Hk7312/xGP8zT/RyUd/aVGDWFbZg YpHlqOIoz/fD7+iVsAyF/0cCAXhdL1pNfvZE5KBVIHsqL4NzKgF51vjXWNaobUVAcNpj WImpwRbYcx4otB7Zjp67VCdglNwKdO97qrUyus+YFr0I/bKhn3HrsTIM7Jyna8//RN5k 1cnQ== X-Gm-Message-State: AOJu0YxdY6NYtgasp6T+pJyBT1mI9oRJ5MK1qYlYpP+xO4Zs3wEXx/je uTeV5sduaVtGKEf5Fu0hIAcYt/NXd4JIapoHgzpy2SrPmdm+pB9Rnhio7g== X-Google-Smtp-Source: AGHT+IG9d0zHvYVBGZeQTvhIVWCsf6A6g0jCr9ScG4jPNgIfDG2/CWnu/rHcVKzBU70LkIyFPqwvCA== X-Received: by 2002:a17:902:cece:b0:1f7:167d:e289 with SMTP id d9443c01a7336-1f9aa466115mr8316035ad.55.1718740436498; Tue, 18 Jun 2024 12:53:56 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855ee80fesm101342225ad.124.2024.06.18.12.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 12:53:56 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org, 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 , Sasha Kozachuk , John Hamrick , Chris Sarra , Guenter Roeck Subject: [RFT PATCH v2 3/3] hwmon: (spd5118) Add support for Renesas/ITD SPD5118 hub controllers Date: Tue, 18 Jun 2024 12:53:48 -0700 Message-Id: <20240618195348.1670547-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240618195348.1670547-1-linux@roeck-us.net> References: <20240618195348.1670547-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 The SPD5118 specification says, in its documentation of the page bits in the MR11 register: " This register only applies to non-volatile memory (1024) Bytes) access of SPD5 Hub device. For volatile memory access, this register must be programmed to '000'. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " Renesas/ITD SPD5118 hub controllers take this literally and disable access to volatile memory if the page selected in MR11 is != 0. Since the BIOS or ROMMON will access the non-volatile memory and likely select a page != 0, this means that the driver will not instantiate since it can not identify the chip. Even if the driver instantiates, access to volatile registers is blocked after a nvram read operation which selects a page other than 0. To solve the problem, add initialization code to select page 0 during probe. Before doing that, use basic validation to ensure that this is really a SPD5118 device and not some random EEPROM. Cc: Sasha Kozachuk Cc: John Hamrick Cc: Chris Sarra Signed-off-by: Guenter Roeck --- v2: Simplified to use mechanisms introduced in the first two patches of the series. drivers/hwmon/spd5118.c | 56 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/hwmon/spd5118.c b/drivers/hwmon/spd5118.c index 995c45e2a997..80a02dba2ccc 100644 --- a/drivers/hwmon/spd5118.c +++ b/drivers/hwmon/spd5118.c @@ -538,6 +538,58 @@ static const struct regmap_config spd5118_regmap_config = { .num_ranges = ARRAY_SIZE(spd5118_regmap_range_cfg), }; +static int spd5118_init(struct i2c_client *client) +{ + struct i2c_adapter *adapter = client->adapter; + int err, regval, mode; + + 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 < 0 || (regval && regval != 0x5118)) + return -ENODEV; + + /* + * If the device type registers return 0, it is possible that the chip + * has a non-zero page selected and takes the specification literally, + * i.e. disables access to volatile registers besides the page register + * if the page is not 0. Try to identify such chips. + */ + if (!regval) { + /* Vendor ID registers must also be 0 */ + regval = i2c_smbus_read_word_data(client, SPD5118_REG_VENDOR); + if (regval) + return -ENODEV; + + /* The selected page in MR11 must not be 0 */ + mode = i2c_smbus_read_byte_data(client, SPD5118_REG_I2C_LEGACY_MODE); + if (mode < 0 || (mode & ~SPD5118_LEGACY_MODE_MASK) || + !(mode & SPD5118_LEGACY_PAGE_MASK)) + return -ENODEV; + + err = i2c_smbus_write_byte_data(client, SPD5118_REG_I2C_LEGACY_MODE, + mode & SPD5118_LEGACY_MODE_ADDR); + if (err) + return -ENODEV; + + /* + * If the device type registers are still bad after selecting + * page 0, this is not a SPD5118 device. Restore original + * legacy mode register value and abort. + */ + regval = i2c_smbus_read_word_swapped(client, SPD5118_REG_TYPE); + if (regval != 0x5118) { + i2c_smbus_write_byte_data(client, SPD5118_REG_I2C_LEGACY_MODE, mode); + return -ENODEV; + } + } + + /* We are reasonably sure that this is really a SPD5118 hub controller */ + return 0; +} + static int spd5118_probe(struct i2c_client *client) { struct device *dev = &client->dev; @@ -547,6 +599,10 @@ static int spd5118_probe(struct i2c_client *client) struct regmap *regmap; int err; + err = spd5118_init(client); + if (err) + return err; + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM;