From patchwork Tue Jul 16 23:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735002 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 449592A1AA for ; Tue, 16 Jul 2024 23:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170860; cv=none; b=q16/X/uabs2//rGu8nQFC62n5M6NdnWclwSDvJnoSj5jj/vnX/bmTru8eGpdcDdbH4mw6LNY0wCAJKNg7TGWtbnZrsf1YzstoC8mkq34bpoB9sSEPaYpbR3kQkxfkcJIQALF7n1+/5mTQEaA/RxGWhMYAPIpNxPo5BGexNJH+oU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170860; c=relaxed/simple; bh=GgbN/xfi1+1UQUAQkw9MrQPh2Mrsg06rKp2yEd7dmzQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P7M6DBOvO4ixo2J0uaQpPwS6XdW4DmuppYtVFicQFL/3gDfZ9wv7eUiswPaYypuxX/FArCFTFO1eRx5OS6VSoOwH6neQZ9/u/RuNOJ28YQ4KGlnHB80T+oTENlsDdN4uGMorciTKcCJnMh8UmSXqieOAUzzBdbjqUCss9paS10E= 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=Lk5BgpMS; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lk5BgpMS" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fc49c0aaffso1715935ad.3 for ; Tue, 16 Jul 2024 16:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721170857; x=1721775657; 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=QgF4IJKfLbvm9+vR9izv5Fs0Pq+QR9XA65JgqRSU/6Y=; b=Lk5BgpMSAgBB/qTyOM6rsXlobWPYosrS4dkRSh6ebxhmw1XH+xFsuNDffmtEFxayN4 9BKuHzW5iMF7RZy7FL3W5YuQE7AidT/Z3SdvpzP4DKjNShfSYaTsfUPAm7BA08By+Emi zgap13t+RWlZYItTsC1pwMeP6sgzaLtSUNLvJ6j2pv0tSpMvV7wciiAD5q/uJuzvbsSD 55NFKhAwgCfbhcCyGzn5zX1sOmua7vuHiQ/h1s78ivF4pz7agGIbPgU4epfCNDAW7m8Y G18iBLdk8Kb0AE9DOTBuVF7HR/SrL118cFR7aTo++YoEYsdiWmxXfkZ/sA0BSClhlj+d ldqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721170857; x=1721775657; 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=QgF4IJKfLbvm9+vR9izv5Fs0Pq+QR9XA65JgqRSU/6Y=; b=bf+kwXheFiePdw3Q+Ww+6UNxhzyZQ38e4DSlhu4Z05zkojtYePXQE3k5JnYGQPzWWv MI42BXUSbJlpjB0XJzQcr1ba4fMEpnfkQ0dtldZrdISu2gV4V9oBYfZwD1YCi5tUMkOR RKIO/tWLE8IMybuuqSDDTP13AnUCnSpaBHBH4SPmMQUc4rNymEkGCc+br18lyQ2i9WWg lOr1ZOfvpL7bj5AGSYUDnnhpXkb+6WqCZwS3/dF69NjxUF9qS2BSvY9twyyOjqwfMYJq 8ucx+dIJOuAmcyon7WZbKhVlkqNOsGkZJSSHvM/QhgolDql+RFQBLBd6A5/Jd+ZsAe+l orxA== X-Gm-Message-State: AOJu0YzRd3JHqid3rGxDAI18epAljweKAvRWvvWysG1c63JxKfmr9TA8 WuiAo2eFEgsYap62eWF0En66aBeLvRT34BbV2w1EQB1WyY5UDPQPWIfweg== X-Google-Smtp-Source: AGHT+IHdCY+oHR26DA42V4gPePoh3v05rw8/lkdDNA7BZ+VNXQTutVqHiscFF1MsQecabO5nnn34RA== X-Received: by 2002:a17:902:d487:b0:1fb:cffb:cf9b with SMTP id d9443c01a7336-1fc3d92c920mr33200275ad.7.1721170856643; Tue, 16 Jul 2024 16:00: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-1fc0bc27503sm63639185ad.175.2024.07.16.16.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 16:00:55 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 1/6] hwmon: (lm95245) Use multi-byte regmap operations Date: Tue, 16 Jul 2024 16:00:45 -0700 Message-Id: <20240716230050.2049534-2-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716230050.2049534-1-linux@roeck-us.net> References: <20240716230050.2049534-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 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional change. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/lm95245.c | 110 ++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 65 deletions(-) diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c index d293b4f15dc1..3bdc30530847 100644 --- a/drivers/hwmon/lm95245.c +++ b/drivers/hwmon/lm95245.c @@ -161,18 +161,18 @@ static int lm95245_read_temp(struct device *dev, u32 attr, int channel, { struct lm95245_data *data = dev_get_drvdata(dev); struct regmap *regmap = data->regmap; - int ret, regl, regh, regvall, regvalh; + unsigned int regs[2]; + unsigned int regval; + u8 regvals[2]; + int ret; switch (attr) { case hwmon_temp_input: - regl = channel ? LM95245_REG_R_REMOTE_TEMPL_S : - LM95245_REG_R_LOCAL_TEMPL_S; - regh = channel ? LM95245_REG_R_REMOTE_TEMPH_S : - LM95245_REG_R_LOCAL_TEMPH_S; - ret = regmap_read(regmap, regl, ®vall); - if (ret < 0) - return ret; - ret = regmap_read(regmap, regh, ®valh); + regs[0] = channel ? LM95245_REG_R_REMOTE_TEMPL_S : + LM95245_REG_R_LOCAL_TEMPL_S; + regs[1] = channel ? LM95245_REG_R_REMOTE_TEMPH_S : + LM95245_REG_R_LOCAL_TEMPH_S; + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret < 0) return ret; /* @@ -181,92 +181,77 @@ static int lm95245_read_temp(struct device *dev, u32 attr, int channel, * Use signed calculation for remote if signed bit is set * or if reported temperature is below signed limit. */ - if (!channel || (regvalh & 0x80) || regvalh < 0x7f) { - *val = temp_from_reg_signed(regvalh, regvall); + if (!channel || (regvals[1] & 0x80) || regvals[1] < 0x7f) { + *val = temp_from_reg_signed(regvals[1], regvals[0]); return 0; } - ret = regmap_read(regmap, LM95245_REG_R_REMOTE_TEMPL_U, - ®vall); - if (ret < 0) + ret = regmap_bulk_read(regmap, LM95245_REG_R_REMOTE_TEMPH_U, regvals, 2); + if (ret) return ret; - ret = regmap_read(regmap, LM95245_REG_R_REMOTE_TEMPH_U, - ®valh); - if (ret < 0) - return ret; - *val = temp_from_reg_unsigned(regvalh, regvall); + *val = temp_from_reg_unsigned(regvals[0], regvals[1]); return 0; case hwmon_temp_max: ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT, - ®valh); + ®val); if (ret < 0) return ret; - *val = regvalh * 1000; + *val = regval * 1000; return 0; case hwmon_temp_crit: - regh = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT : - LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT; - ret = regmap_read(regmap, regh, ®valh); + regs[0] = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT : + LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT; + ret = regmap_read(regmap, regs[0], ®val); if (ret < 0) return ret; - *val = regvalh * 1000; + *val = regval * 1000; return 0; case hwmon_temp_max_hyst: - ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OS_LIMIT, - ®valh); + regs[0] = LM95245_REG_RW_REMOTE_OS_LIMIT; + regs[1] = LM95245_REG_RW_COMMON_HYSTERESIS; + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret < 0) return ret; - ret = regmap_read(regmap, LM95245_REG_RW_COMMON_HYSTERESIS, - ®vall); - if (ret < 0) - return ret; - *val = (regvalh - regvall) * 1000; + *val = (regvals[0] - regvals[1]) * 1000; return 0; case hwmon_temp_crit_hyst: - regh = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT : - LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT; - ret = regmap_read(regmap, regh, ®valh); + regs[0] = channel ? LM95245_REG_RW_REMOTE_TCRIT_LIMIT : + LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT; + regs[1] = LM95245_REG_RW_COMMON_HYSTERESIS; + + ret = regmap_multi_reg_read(regmap, regs, regvals, 2); if (ret < 0) return ret; - ret = regmap_read(regmap, LM95245_REG_RW_COMMON_HYSTERESIS, - ®vall); - if (ret < 0) - return ret; - *val = (regvalh - regvall) * 1000; + *val = (regvals[0] - regvals[1]) * 1000; return 0; case hwmon_temp_type: - ret = regmap_read(regmap, LM95245_REG_RW_CONFIG2, ®valh); + ret = regmap_read(regmap, LM95245_REG_RW_CONFIG2, ®val); if (ret < 0) return ret; - *val = (regvalh & CFG2_REMOTE_TT) ? 1 : 2; + *val = (regval & CFG2_REMOTE_TT) ? 1 : 2; return 0; case hwmon_temp_offset: - ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OFFL, - ®vall); + ret = regmap_bulk_read(regmap, LM95245_REG_RW_REMOTE_OFFH, regvals, 2); if (ret < 0) return ret; - ret = regmap_read(regmap, LM95245_REG_RW_REMOTE_OFFH, - ®valh); - if (ret < 0) - return ret; - *val = temp_from_reg_signed(regvalh, regvall); + *val = temp_from_reg_signed(regvals[0], regvals[1]); return 0; case hwmon_temp_max_alarm: - ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®valh); + ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®val); if (ret < 0) return ret; - *val = !!(regvalh & STATUS1_ROS); + *val = !!(regval & STATUS1_ROS); return 0; case hwmon_temp_crit_alarm: - ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®valh); + ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®val); if (ret < 0) return ret; - *val = !!(regvalh & (channel ? STATUS1_RTCRIT : STATUS1_LOC)); + *val = !!(regval & (channel ? STATUS1_RTCRIT : STATUS1_LOC)); return 0; case hwmon_temp_fault: - ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®valh); + ret = regmap_read(regmap, LM95245_REG_R_STATUS1, ®val); if (ret < 0) return ret; - *val = !!(regvalh & STATUS1_DIODE_FAULT); + *val = !!(regval & STATUS1_DIODE_FAULT); return 0; default: return -EOPNOTSUPP; @@ -279,6 +264,7 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel, struct lm95245_data *data = dev_get_drvdata(dev); struct regmap *regmap = data->regmap; unsigned int regval; + u8 regvals[2]; int ret, reg; switch (attr) { @@ -311,16 +297,10 @@ static int lm95245_write_temp(struct device *dev, u32 attr, int channel, case hwmon_temp_offset: val = clamp_val(val, -128000, 127875); val = val * 256 / 1000; - mutex_lock(&data->update_lock); - ret = regmap_write(regmap, LM95245_REG_RW_REMOTE_OFFL, - val & 0xe0); - if (ret < 0) { - mutex_unlock(&data->update_lock); - return ret; - } - ret = regmap_write(regmap, LM95245_REG_RW_REMOTE_OFFH, - (val >> 8) & 0xff); - mutex_unlock(&data->update_lock); + regvals[0] = val >> 8; + regvals[1] = val & 0xe0; + + ret = regmap_bulk_write(regmap, LM95245_REG_RW_REMOTE_OFFH, regvals, 2); return ret; case hwmon_temp_type: if (val != 1 && val != 2) From patchwork Tue Jul 16 23:00: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: 13735003 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.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 A7B6513D502 for ; Tue, 16 Jul 2024 23:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170861; cv=none; b=uw4WzKZusUOJWmPSnmpMWf1DiVYmPTK1vbwUxzHCJXgr9SPpPNirnQX+9ZNPOGQnNQD9mTkzhk18GQdUG3+PKYWwGngZkP2ROXLKBKERCetIn13I/Rmn2+Woge1mtQ662cLukgDamf5BIIIZGddy33VaJJaMgFgmzTrxSW32Brg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170861; c=relaxed/simple; bh=luq9bOH6eETrJWj0Xm8t3HuCpW+2B19gKdWieuZXsiw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q3uwkJ+1UYV3/Opmif/en8Drk4OzrkeVHh90io6MFlawdFYo00M1noJTEkTy1V3e8GFZDE5GexI+K+cpgVhm0Nmd2ua1qwuQK6TMVHfPriyADVh2Uvgm8Thj7867oNTu7Vdk27ZfXu1x7sVvJyqcWMEtVPRbmuvsnM9rvulro/o= 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=jtksCpQR; arc=none smtp.client-ip=209.85.210.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="jtksCpQR" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70af8128081so4153625b3a.1 for ; Tue, 16 Jul 2024 16:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721170858; x=1721775658; 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=G+mhWIh9rO13TbrQbGprfCh45gda11b9VrQFxkUKZFo=; b=jtksCpQRjYBlO78YV2DClxpLjPygqfaN9PZ6vlmjo9oBfBIMK9ng0GNOP9h4f1QJ3g wH+SoxTqlczeuJ8vNyYv2wXQUQR3p5Ec5rVZX5d+LfXNKGFwKEnNr0id0IQKmu2InM2h QrbMMlrUYFQOQQl8YWYKepTSrKAnH1HN/QsHkj2WrGaIKiDhgwyQpJ44/WmGT8J7OQw6 +2I4CwZYqBIFb8JQuHjOUbrmQSvBz0SvIZfj//ePlGwLHCXP7PJUafsCsj7TE1GRIKhJ zpwwD4/xqbc0fvUZ7c/bEkynIsp4V9ZqGBlyLWDTJVdi61zNM9z7svP5VSeXrHsjl17k Hhwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721170858; x=1721775658; 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=G+mhWIh9rO13TbrQbGprfCh45gda11b9VrQFxkUKZFo=; b=A9EGpTfwA9RIbYysVdGbsti9hw9HzCdiNb99AXy6eLD/Fo45HIqmbVLLkTw1o7UCW4 M8iXoa/7UQM1NeF//OVQq7xlZ97ed9WSRjyVuMCTxgo33knAgVVNXfZDzlfDRm5qf2d3 evq5d1pLEtsB9M01m7bOQBPgrrEatVS2XYVNSW8X+2+HRWxW9H3hYGsLOKcW/ef+80LQ yoO/16L/Eq2gHnIY5sh90ifgejBBWDkdJCghRGfyTsPRWh8TwGOfU6q/0C+DSnKG8B9e KhyKRlhvRT2Y/Ppx3DEnoCTwfFkOqVSaEuq/7F1NnOz2TLvdFYt39GqeZ7Jqrmurhi/X +PQA== X-Gm-Message-State: AOJu0YxEEhUpvnipxgE7TZFjNGdA+GK0r7k5zwS7tfxyi4hYm2aDf1q8 VahOyW0OeUFtRxWNWTZPG8qwiBIerKitzY5pJUrUqhHEHyz9UXugEDVziA== X-Google-Smtp-Source: AGHT+IGwzrNH+TXe8OzRoxF9hBnwgKV24W7Pu5nLZ72u18WBeVsQVOnUHAkV+aD4Y7MO61u52LCAgg== X-Received: by 2002:a05:6a21:7702:b0:1c0:ed64:e4a9 with SMTP id adf61e73a8af0-1c3fdd1838bmr39984637.34.1721170858423; Tue, 16 Jul 2024 16:00:58 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7ec7d2dasm6905823b3a.111.2024.07.16.16.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 16:00:57 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 2/6] hwmon: (nct7802) Use multi-byte regmap operations Date: Tue, 16 Jul 2024 16:00:46 -0700 Message-Id: <20240716230050.2049534-3-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716230050.2049534-1-linux@roeck-us.net> References: <20240716230050.2049534-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 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional changes. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/nct7802.c | 61 ++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c index 97e8c6424403..3d6819aebe16 100644 --- a/drivers/hwmon/nct7802.c +++ b/drivers/hwmon/nct7802.c @@ -229,41 +229,34 @@ static int nct7802_read_temp(struct nct7802_data *data, static int nct7802_read_fan(struct nct7802_data *data, u8 reg_fan) { - unsigned int f1, f2; + unsigned int regs[2] = {reg_fan, REG_FANCOUNT_LOW}; + u8 f[2]; int ret; - mutex_lock(&data->access_lock); - ret = regmap_read(data->regmap, reg_fan, &f1); - if (ret < 0) - goto abort; - ret = regmap_read(data->regmap, REG_FANCOUNT_LOW, &f2); - if (ret < 0) - goto abort; - ret = (f1 << 5) | (f2 >> 3); + ret = regmap_multi_reg_read(data->regmap, regs, f, 2); + if (ret) + return ret; + ret = (f[0] << 5) | (f[1] >> 3); /* convert fan count to rpm */ if (ret == 0x1fff) /* maximum value, assume fan is stopped */ ret = 0; else if (ret) ret = DIV_ROUND_CLOSEST(1350000U, ret); -abort: - mutex_unlock(&data->access_lock); return ret; } static int nct7802_read_fan_min(struct nct7802_data *data, u8 reg_fan_low, u8 reg_fan_high) { - unsigned int f1, f2; + unsigned int regs[2] = {reg_fan_low, reg_fan_high}; + u8 f[2]; int ret; - mutex_lock(&data->access_lock); - ret = regmap_read(data->regmap, reg_fan_low, &f1); + ret = regmap_multi_reg_read(data->regmap, regs, f, 2); if (ret < 0) - goto abort; - ret = regmap_read(data->regmap, reg_fan_high, &f2); - if (ret < 0) - goto abort; - ret = f1 | ((f2 & 0xf8) << 5); + return ret; + + ret = f[0] | ((f[1] & 0xf8) << 5); /* convert fan count to rpm */ if (ret == 0x1fff) /* maximum value, assume no limit */ ret = 0; @@ -271,8 +264,6 @@ static int nct7802_read_fan_min(struct nct7802_data *data, u8 reg_fan_low, ret = DIV_ROUND_CLOSEST(1350000U, ret); else ret = 1350000U; -abort: - mutex_unlock(&data->access_lock); return ret; } @@ -302,33 +293,27 @@ static u8 nct7802_vmul[] = { 4, 2, 2, 2, 2 }; static int nct7802_read_voltage(struct nct7802_data *data, int nr, int index) { - unsigned int v1, v2; + u8 v[2]; int ret; mutex_lock(&data->access_lock); if (index == 0) { /* voltage */ - ret = regmap_read(data->regmap, REG_VOLTAGE[nr], &v1); + unsigned int regs[2] = {REG_VOLTAGE[nr], REG_VOLTAGE_LOW}; + + ret = regmap_multi_reg_read(data->regmap, regs, v, 2); if (ret < 0) - goto abort; - ret = regmap_read(data->regmap, REG_VOLTAGE_LOW, &v2); - if (ret < 0) - goto abort; - ret = ((v1 << 2) | (v2 >> 6)) * nct7802_vmul[nr]; + return ret; + ret = ((v[0] << 2) | (v[1] >> 6)) * nct7802_vmul[nr]; } else { /* limit */ int shift = 8 - REG_VOLTAGE_LIMIT_MSB_SHIFT[index - 1][nr]; + unsigned int regs[2] = {REG_VOLTAGE_LIMIT_LSB[index - 1][nr], + REG_VOLTAGE_LIMIT_MSB[nr]}; - ret = regmap_read(data->regmap, - REG_VOLTAGE_LIMIT_LSB[index - 1][nr], &v1); + ret = regmap_multi_reg_read(data->regmap, regs, v, 2); if (ret < 0) - goto abort; - ret = regmap_read(data->regmap, REG_VOLTAGE_LIMIT_MSB[nr], - &v2); - if (ret < 0) - goto abort; - ret = (v1 | ((v2 << shift) & 0x300)) * nct7802_vmul[nr]; + return ret; + ret = (v[0] | ((v[1] << shift) & 0x300)) * nct7802_vmul[nr]; } -abort: - mutex_unlock(&data->access_lock); return ret; } From patchwork Tue Jul 16 23:00: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: 13735004 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 94A892A1AA for ; Tue, 16 Jul 2024 23:01:01 +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=1721170863; cv=none; b=ZHBzcqrmfEPX9/Aq3CVWyzGLEFwkhH+pmqzMxJy8Qv2oBiXtuVeKnpPPTYG7GReEdQSDEmE+PgeGRpDHWKplUuPO7JU4FQIsPIVRvTrzVXQTIgnhKbeWzPSPWwz5Vjmg667WCzk1WvrnyacY2ujqrC4+QyR6Ysw+RPjd6DgW98A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170863; c=relaxed/simple; bh=QuAF5jDUQY4fce8gJR0uUbraF3Vsup0Z3qPwpCk0sK4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eLrxQkyJLXkHelE8UkEX/65zPEVL8wv8lr1O61L8vyNkvqZEfPm8o0Y0U2En8u21L52F0PO2Lw9GJ3pYA9iPB+Xo9q5t/UwfmpgYhICuBgp15BUYKrvdTuZwooIaoeefSdiSZwX7DEU1gCd3aGcIOwV9i/nY4enEKrJKNK3hsTw= 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=GH0rx/xQ; 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="GH0rx/xQ" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-70b42250526so4612840b3a.1 for ; Tue, 16 Jul 2024 16:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721170860; x=1721775660; 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=uoKt1Ppg09NG9pVN3LcM+m26clGMcm38wUCw/PB5OL4=; b=GH0rx/xQEqxQZcQCt/EAC1MqEPFizuBbwsBgG5YMr+lXdQdfWClrNOK1wdtpOKqwSe p0Fq8FpUhEhUpoizXvd1iOyw27UoSsUg+onkHkJpfuTwIZLMXa68gePiFFPVlFsYQVVS z9nKFFPY9b/xoZGgOs1MZwq1gEzhzPxnpsWO+nclXoSFyM135oqvw4sgc+KtOb0e5xs4 NUEXFbFhQFWp8IE8dTWJZf/w017tmXsHrIdhxMb3ErlZgkjC0MIGwq3nLfpoug7bwiEs CbQPnkdDEm2PI2k4ILrpM2c6cmdDt2wGszn3W/fgAn/bvkR8xJbpgyg/IzggmYH3stMh bWrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721170860; x=1721775660; 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=uoKt1Ppg09NG9pVN3LcM+m26clGMcm38wUCw/PB5OL4=; b=kwxYj7dfd9h33tFxanKg/hQBuIIsVZMRUAwiazoL4pXhu6kG1A8QeleQJd6Z3v2gHs x2BWSJfDXj2AOsk9v0fSc1V1kJqyOWZ4mW3PC22d1XVfSg/gbWFO6ecbaluT84B1lBJt MNSuvcq3vVrHPAEYFGOwe5ngkiygLt5JDKZ6jyWfiWCMgxvr0dcldKSIXxzjDcuQ9BlL c6MFjYQdIiEFNaKS5rP2omOiWuWCZ+gTEPFWtgHl8Tl+/MQ1+GuGu8e2BKlnU8QI2M0M u/mmYHLgHyiYruOql+ja2tzYArTR8fWk2YQdvMFgBEXYEPNJ59l6k54qeVJFeI8knRUM 2HKw== X-Gm-Message-State: AOJu0YzTTwCrf9Bh2xmUKmQ2hNeNvzFoGUPNQ/ZhGMfLS+4DSyNUqmGe tlzwl/B7iMDqAxQX1JYMBa1N2Qfjs4YUenRJtDHnuKgkFCr01/peVUbIXw== X-Google-Smtp-Source: AGHT+IH+HuFL229bsEMyujD0NyFAdGGnwIinHWtMA0GwnsY5YieZRGEGqoSanwND8155w3wSH7rERw== X-Received: by 2002:a05:6a00:2304:b0:706:251d:d98 with SMTP id d2e1a72fcca58-70c1fb673fbmr4150721b3a.4.1721170860281; Tue, 16 Jul 2024 16:01:00 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7eb9dec9sm6855032b3a.20.2024.07.16.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 16:00:59 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 3/6] hwmon: (adt7x10) Use multi-byte regmap operations Date: Tue, 16 Jul 2024 16:00:47 -0700 Message-Id: <20240716230050.2049534-4-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716230050.2049534-1-linux@roeck-us.net> References: <20240716230050.2049534-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 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional changes. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/adt7x10.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/adt7x10.c b/drivers/hwmon/adt7x10.c index 6701920de17f..2d329391ed3f 100644 --- a/drivers/hwmon/adt7x10.c +++ b/drivers/hwmon/adt7x10.c @@ -170,21 +170,15 @@ static int adt7x10_temp_write(struct adt7x10_data *data, int index, long temp) static int adt7x10_hyst_read(struct adt7x10_data *data, int index, long *val) { - int hyst, temp, ret; + unsigned int regs[2] = {ADT7X10_T_HYST, ADT7X10_REG_TEMP[index]}; + int hyst, ret; + u16 regdata[2]; - mutex_lock(&data->update_lock); - ret = regmap_read(data->regmap, ADT7X10_T_HYST, &hyst); - if (ret) { - mutex_unlock(&data->update_lock); - return ret; - } - - ret = regmap_read(data->regmap, ADT7X10_REG_TEMP[index], &temp); - mutex_unlock(&data->update_lock); + ret = regmap_multi_reg_read(data->regmap, regs, regdata, 2); if (ret) return ret; - hyst = (hyst & ADT7X10_T_HYST_MASK) * 1000; + hyst = (regdata[0] & ADT7X10_T_HYST_MASK) * 1000; /* * hysteresis is stored as a 4 bit offset in the device, convert it @@ -194,7 +188,7 @@ static int adt7x10_hyst_read(struct adt7x10_data *data, int index, long *val) if (index == adt7x10_t_alarm_low) hyst = -hyst; - *val = ADT7X10_REG_TO_TEMP(data, temp) - hyst; + *val = ADT7X10_REG_TO_TEMP(data, regdata[1]) - hyst; return 0; } From patchwork Tue Jul 16 23:00: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: 13735005 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 3A8B86A01E for ; Tue, 16 Jul 2024 23:01:03 +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=1721170864; cv=none; b=b+1KW2AIiUPusWqtOSnn+h61MYgZjrfFWjpj8G0unciF8AXArfIBYEYxgslT5AV5Q0SC7lb9oTLAPRhiMCk7RmQ/Ij5hbhM/KtfDVD6WCa/CGgDkUx2jKkp8sA5zKSZZGqArpw3h5hQuEn2/W9hY0D01iNT9uUWaJsErCS5CLeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170864; c=relaxed/simple; bh=GOlEHnyUoF59EnIaOqz8h1goXcGRS5L4vAtiGCgCsIM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BwY8WqTxsXIa/OlMQxePpC1YPRzxbCsdbzrM84YcMq4xJ20vLfX4688x4NxYKlCk9t6y/SkkvqdmI1l7OsE6qUVlt3tbvs4zgLKpG/Q1DWxOqjAd4ZNrv2SQE1Y/tB7/WGopq78+fxUieqvMqKmAl+GTS/LJ4A41eAOeMedOgIU= 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=kv8kQdJD; 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="kv8kQdJD" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-70b5117ae06so4406737b3a.2 for ; Tue, 16 Jul 2024 16:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721170862; x=1721775662; 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=36VPYYbZzj8FPEQTnHRvuJaCAQi9X4RzJKfeP9NlBXI=; b=kv8kQdJD35UdN1K3cdIbX0n9leCQ4+q3pi4Vn4D4ImMHHbdSNQU95RddZLHF2QOS10 qgCuIBULrqv1zmJLvs3ojmSCJKDGeXDxIwRRfyqov1MBbje1k2+JyaNI9syQwubwTVji tIFRPHjBOgWYkhQ99VLPQJK0RgzQ8ptPkBTR37czSL+htkGcxeHhjB6yfVgIwTM548t5 wqJu+XmSYLhjWy2ngD7C8zSD2j4w5baLrfdJLQEe1BDNLCDYHoKP5eRzi5jkvKEZETO3 s400glkeQW9zTEE9g1KuIy4aoKannK05deb1uhFBVAaABb53HKXtXtF5JlbFQIiPPEtv Cwrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721170862; x=1721775662; 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=36VPYYbZzj8FPEQTnHRvuJaCAQi9X4RzJKfeP9NlBXI=; b=kDWhAFx9PUJPMsBFr0mBezV0WgEACavgvjToAvwNkiQo53w1OGOROACFeLBRHsHNWT Tvjblj+BcHkDmE9x6XdNbrPahMn3oZ53zQOPfChnUY1nAbRPW53HcnweTCwdZPIgI8LH XrTsydfB2QTpG9AgHiU1Rf8asgcOKmyJgb9nsAerpFzk5Qbu6rvlCxpF7dyKIMCPoapx 8f10Emdcb6x/8avYiNWdoqpgMFqWhWpIm/CwdwtTX3ybQHwcObwTh9lo6k/a1drftcP6 6/YrnrRF06tIMP2k9R5XRfgpCi8sgyFxNH7yJeaBlRqsnJPhzIhlqWaoO+/QRlTwehXW +chw== X-Gm-Message-State: AOJu0Yzm9xyYEa6tl47+0K2SIf5BWECmGCfU3CA0/FxwjsKPOxj2hM/M SvYFZqtvAr/j6qjOG41HdIjuh3u+HPA5gEzAoA8G3TWzA0TUFbrcp+Aulg== X-Google-Smtp-Source: AGHT+IF7hmuaXme0anRSsY4skxOFbtJicS6TadEfoHSsi1A4fsa90y40FZIJFgVyXlpdM0o10dzokA== X-Received: by 2002:a05:6a00:b43:b0:70a:f40e:f2c7 with SMTP id d2e1a72fcca58-70c2e9b331fmr5098353b3a.24.1721170861971; Tue, 16 Jul 2024 16:01:01 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7eca7865sm6876207b3a.158.2024.07.16.16.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 16:01:01 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 4/6] hwmon: (tmp464) Use multi-byte regmap operations Date: Tue, 16 Jul 2024 16:00:48 -0700 Message-Id: <20240716230050.2049534-5-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716230050.2049534-1-linux@roeck-us.net> References: <20240716230050.2049534-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 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional changes. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/tmp464.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/hwmon/tmp464.c b/drivers/hwmon/tmp464.c index 3ee1137533d6..0a7c0448835b 100644 --- a/drivers/hwmon/tmp464.c +++ b/drivers/hwmon/tmp464.c @@ -147,11 +147,11 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val { struct tmp464_data *data = dev_get_drvdata(dev); struct regmap *regmap = data->regmap; - unsigned int regval, regval2; + unsigned int regs[2]; + unsigned int regval; + u16 regvals[2]; int err = 0; - mutex_lock(&data->update_lock); - switch (attr) { case hwmon_temp_max_alarm: err = regmap_read(regmap, TMP464_THERM_STATUS_REG, ®val); @@ -172,26 +172,27 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val * complete. That means we have to cache the value internally * for one measurement cycle and report the cached value. */ + mutex_lock(&data->update_lock); if (!data->valid || time_after(jiffies, data->last_updated + msecs_to_jiffies(data->update_interval))) { err = regmap_read(regmap, TMP464_REMOTE_OPEN_REG, ®val); if (err < 0) - break; + goto unlock; data->open_reg = regval; data->last_updated = jiffies; data->valid = true; } *val = !!(data->open_reg & BIT(channel + 7)); +unlock: + mutex_unlock(&data->update_lock); break; case hwmon_temp_max_hyst: - err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], ®val); + regs[0] = TMP464_THERM_LIMIT[channel]; + regs[1] = TMP464_TEMP_HYST_REG; + err = regmap_multi_reg_read(regmap, regs, regvals, 2); if (err < 0) break; - err = regmap_read(regmap, TMP464_TEMP_HYST_REG, ®val2); - if (err < 0) - break; - regval -= regval2; - *val = temp_from_reg(regval); + *val = temp_from_reg(regvals[0] - regvals[1]); break; case hwmon_temp_max: err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], ®val); @@ -200,14 +201,12 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val *val = temp_from_reg(regval); break; case hwmon_temp_crit_hyst: - err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], ®val); + regs[0] = TMP464_THERM2_LIMIT[channel]; + regs[1] = TMP464_TEMP_HYST_REG; + err = regmap_multi_reg_read(regmap, regs, regvals, 2); if (err < 0) break; - err = regmap_read(regmap, TMP464_TEMP_HYST_REG, ®val2); - if (err < 0) - break; - regval -= regval2; - *val = temp_from_reg(regval); + *val = temp_from_reg(regvals[0] - regvals[1]); break; case hwmon_temp_crit: err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], ®val); @@ -239,8 +238,6 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val break; } - mutex_unlock(&data->update_lock); - return err; } From patchwork Tue Jul 16 23:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735006 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 048F013CFA3 for ; Tue, 16 Jul 2024 23:01:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170866; cv=none; b=PNjK9THOYSHwre1y6ZNag1LcJl9QXxNfMA8AU2n9PCV2OZNKGXBHOtzinNiVhajTJNx1I5N57DoK3mARsdYpxlXubrf1zNNof3bYWmhaKWmFECrXJRTzRcAZq8bRqUl9GXyfmyEdlQPdZ24+UQHA+ERpqEEy2QVtFISaRL1N1gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170866; c=relaxed/simple; bh=5KRu6nKVGaIlnN9OCR5zGlA+I97IxU9GGfRmJsf+Pyk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BLl+iayFCb59A+FUNrJdDHLPJCcIr519vRCJ3AXflUPG6N1Ad9XrgDwM7t0Fg/+NEro/q4AgRLJCADzNwfbJbuD/wGCi6LDwIglsVmlwWQ3CdYKCrJTZRkH94LuEtXARxQKSE0jeIoBWzX2XescBiw1uovP7u3PzWkFR2Vch5QQ= 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=WA5IXj5b; arc=none smtp.client-ip=209.85.210.180 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="WA5IXj5b" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-70b07bdbfbcso188031b3a.0 for ; Tue, 16 Jul 2024 16:01:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721170864; x=1721775664; 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=wBIc44ePzm+Ayf/98yNwj7sQekbnxNa9YFMUCHmbPMg=; b=WA5IXj5b+uB+elLhHCdFFoboHdVNEwN5WaPEOBBmcQVBFOqpWhxJQ85NdW9gIxfUEp S8wU7NI+y4xFUteHI8NKDKYZC45uklUmBbH+xEciht75H/gyZM2P777HiGEvYPMYWNtQ WZI9dcGh3f/AYxbR8G1r/cyzaf8ycYwVF0odIHWM8Np5dBIkNZ3BLDPfbID7uaOnyVhS XLqd57S37+jqpGSv8C9yP1hFmQ1RQmoSMSYzQufReIR5TM4iEdRU+pYvwu1PES0goV4M aYsF/g0MrA46KiVCL3ixLrq9bc5PnzgbxmLaRyD+IlWuNMIncwCCdArVINh10+3TaNnT 8y/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721170864; x=1721775664; 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=wBIc44ePzm+Ayf/98yNwj7sQekbnxNa9YFMUCHmbPMg=; b=eyFJ5czIvt4NN3X7PAV0XidLc24An/kmpQX+JMdMW7dBYES88+7BynhXGVx8Ct32wU VCsQUrF9oERVY99xJ2RBukne99ijG99H3RyG57tVUyusX3HHfuvOiJfN1bWI6wYcuTsx ZfKnWbVj5+8X16pe12ZTdhXFFF/ijDkkd5Z+ACvTphn0AgkI+00bDxs41uJm69fMgKwg yrVydyvzNtZY3AaFNn/2k72y4SrwZS6xxj38xTg9TF5jfPqsxLRBhJNcNp2wiwWhuFD7 ++hXRN22/yzZocR7pHroP7iY18Ped+8AntGaH3Mcb9/9HtsLUpbXjN//EI2s6m3WStNd CFEA== X-Gm-Message-State: AOJu0YwEYzMCcrQ+HKEwhtjJDhMUaNc4tUSAUNVVEuZZ4T6OIwbfqr2Z /u5ThNcI0eYThVyHhxOCXq5KfCwSFSpqPVziZ+J8yoZ1G8Ou67FKQoaSVw== X-Google-Smtp-Source: AGHT+IFux9RiUw7s1OfnhrlqeBpanuJqJR3d2WwCIeKkFuzEgLySHiRtUVncKdQYLWuFGOhRqQ/a/w== X-Received: by 2002:a17:90a:bf91:b0:2c9:63fb:d3ab with SMTP id 98e67ed59e1d1-2cb37e39a07mr4949078a91.22.1721170863747; Tue, 16 Jul 2024 16:01:03 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2caedbf71f1sm6956854a91.16.2024.07.16.16.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 16:01:03 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 5/6] hwmon: (max6639) Use multi-byte regmap operations Date: Tue, 16 Jul 2024 16:00:49 -0700 Message-Id: <20240716230050.2049534-6-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716230050.2049534-1-linux@roeck-us.net> References: <20240716230050.2049534-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 Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional changes. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/max6639.c | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c index f54720d3d2ce..e877a5520416 100644 --- a/drivers/hwmon/max6639.c +++ b/drivers/hwmon/max6639.c @@ -88,25 +88,16 @@ struct max6639_data { static int max6639_temp_read_input(struct device *dev, int channel, long *temp) { + u32 regs[2] = {MAX6639_REG_TEMP_EXT(channel), MAX6639_REG_TEMP(channel) }; struct max6639_data *data = dev_get_drvdata(dev); - unsigned int val; + u8 regvals[2]; int res; - /* - * Lock isn't needed as MAX6639_REG_TEMP wpnt change for at least 250ms after reading - * MAX6639_REG_TEMP_EXT - */ - res = regmap_read(data->regmap, MAX6639_REG_TEMP_EXT(channel), &val); + res = regmap_multi_reg_read(data->regmap, regs, regvals, 2); if (res < 0) return res; - *temp = val >> 5; - res = regmap_read(data->regmap, MAX6639_REG_TEMP(channel), &val); - if (res < 0) - return res; - - *temp |= val << 3; - *temp *= 125; + *temp = ((regvals[0] >> 5) | (regvals[1] << 3)) * 125; return 0; } @@ -290,8 +281,10 @@ static umode_t max6639_fan_is_visible(const void *_data, u32 attr, int channel) static int max6639_read_pwm(struct device *dev, u32 attr, int channel, long *pwm_val) { + u32 regs[2] = { MAX6639_REG_FAN_CONFIG3(channel), MAX6639_REG_GCONFIG }; struct max6639_data *data = dev_get_drvdata(dev); unsigned int val; + u8 regvals[2]; int res; u8 i; @@ -303,26 +296,13 @@ static int max6639_read_pwm(struct device *dev, u32 attr, int channel, *pwm_val = val * 255 / 120; return 0; case hwmon_pwm_freq: - mutex_lock(&data->update_lock); - res = regmap_read(data->regmap, MAX6639_REG_FAN_CONFIG3(channel), &val); - if (res < 0) { - mutex_unlock(&data->update_lock); + res = regmap_multi_reg_read(data->regmap, regs, regvals, 2); + if (res < 0) return res; - } - i = val & MAX6639_FAN_CONFIG3_FREQ_MASK; - - res = regmap_read(data->regmap, MAX6639_REG_GCONFIG, &val); - if (res < 0) { - mutex_unlock(&data->update_lock); - return res; - } - - if (val & MAX6639_GCONFIG_PWM_FREQ_HI) + i = regvals[0] & MAX6639_FAN_CONFIG3_FREQ_MASK; + if (regvals[1] & MAX6639_GCONFIG_PWM_FREQ_HI) i |= 0x4; - i &= 0x7; *pwm_val = freq_table[i]; - - mutex_unlock(&data->update_lock); return 0; default: return -EOPNOTSUPP; From patchwork Tue Jul 16 23:00:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 13735007 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 1AD6C13CFA3 for ; Tue, 16 Jul 2024 23:01:08 +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=1721170869; cv=none; b=TbUMPVhxoa5bEeQUGr3WuzeEnahIlzuTIKHDrtmWOf0sA1nKjohyA4ZP+xQ6uMoN9/p7ebf5SXETqcHx+8lksTcU6FguFDTfkIfLUf0hhpLNAls0lEt7sdJI4aQvrhgtD2j39MQAmB6KSbPkuSgL2T1FTIeGpRhmtPES9Upw5rM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721170869; c=relaxed/simple; bh=ZLjgHqYTQvU4XadmxDeUP6p9g9ffBRj7/tcMJGf1UYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=jx4TMpjWzBAS1lBlVfXebwkLlWmEKPLqBreD78UAw/k0kDRFdw+W5dGydgngeR1l1pdc8tB9bEpHQzV2RjFTYJb/eZYfIUmFL/hqKU1OmrWt3XnNpOpNS9lXBYrCOD8e1x5rU+oaK9mNhKzUg7Zddhk5vCYn2UDmrV67Tr9eMLE= 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=eD1MGVzJ; 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="eD1MGVzJ" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1fb3b7d0d3aso37914225ad.2 for ; Tue, 16 Jul 2024 16:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721170867; x=1721775667; 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=ZYUsX+qSPd3Gzit9fuaalTnUQU5YObCV4PTll9Ip+Dg=; b=eD1MGVzJghZuORnSTt90+StSP7ShiYgTT0xaC563pKhIi369zd0xrcpyhEV/kW0ezv HL7OcrbxO6yQNbkFdZIXAKzxiqXZYV7rECsIduLFqQvHtw/p76aBxKK33cfa/JfKq+j1 lCyRwsOcO/jkFaBZmLs8cbINt4F3UFYMTmQkrxtPzcSECYyHIzk7Q2My6uxBBlfgs2dL xk7zQ3yo7lk5O6wkqwPH33dP8dYy87MxdcN01GmwKynatUQGdVlsVzhLXKszqyLzxsSW sO1tZ9SzIwtoVY7Wg76S08rF+9UgaKq4B1Xb0yUYcqL1l8ieaoDSdBa5Ec6aU2ELch2w fMtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721170867; x=1721775667; 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=ZYUsX+qSPd3Gzit9fuaalTnUQU5YObCV4PTll9Ip+Dg=; b=cAuocSKx/sta8jXZFALtFpN1l9wPloCMg+Im8PViLGnHsf6oYVZfdq/gwqAFpxrzDf Ei2Cxp2Wq1p8scRbtncDzhGEtx9gpvQ4xxa+/KMnJth0A8SL0ESNvWd36gvkIqWNUC+u qcHjN8DDIzNKMaXkmPi38PCrcBpndQDml1j+HnETu4Opi4V5ikgtzO2SHPROZhBDh9Ic Oc0r9B9umfSx5e62e+NLnetxdG1ooX/Q2qiSKj9OD+9iWBcxP/9vbqjHPrlljsqmJpsV kHA81Yc8NKWhDN8nEGAR2mSCYn820YFl5uiW9qiwpKeU+nnA+z5tlMcpr25fSkEGN3SA U4lA== X-Gm-Message-State: AOJu0Yy0LSnOUFode8OfgaSlPG4zqxV4Q14kEGgeqDGAJbqFnQ3VnbeC O42mIM3UoWq7Z/J84k8FNWvT+smei17UL+KJfL/MXxGvrTdl8xQtJbnIBA== X-Google-Smtp-Source: AGHT+IHMhvSGEkyuuEfp4j1TAtEDgOM3jzyMpz2cDsBk4TshuMWkGJFMmmZPFkk4PhhY2qV7sTY2xA== X-Received: by 2002:a17:902:e945:b0:1fb:396c:7532 with SMTP id d9443c01a7336-1fc3d9f4d2bmr31465645ad.56.1721170865510; Tue, 16 Jul 2024 16:01:05 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0bb70306sm63748405ad.31.2024.07.16.16.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 16:01:04 -0700 (PDT) Sender: Guenter Roeck From: Guenter Roeck To: Hardware Monitoring Cc: Guenter Roeck Subject: [PATCH 6/6] hwmon: (amc6821) Use multi-byte regmap operations Date: Tue, 16 Jul 2024 16:00:50 -0700 Message-Id: <20240716230050.2049534-7-linux@roeck-us.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240716230050.2049534-1-linux@roeck-us.net> References: <20240716230050.2049534-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 Use multi-byte regmap operations where possible to reduce code size. No functional changes. Signed-off-by: Guenter Roeck Reviewed-by: Tzung-Bi Shih --- drivers/hwmon/amc6821.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index ec94392fcb65..ac64b407ed0e 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -136,29 +136,25 @@ struct amc6821_data { */ static int amc6821_get_auto_point_temps(struct regmap *regmap, int channel, u8 *temps) { - u32 pwm, regval; + u32 regs[] = { + AMC6821_REG_DCY_LOW_TEMP, + AMC6821_REG_PSV_TEMP, + channel ? AMC6821_REG_RTEMP_FAN_CTRL : AMC6821_REG_LTEMP_FAN_CTRL + }; + u8 regvals[3]; + int slope; int err; - err = regmap_read(regmap, AMC6821_REG_DCY_LOW_TEMP, &pwm); + err = regmap_multi_reg_read(regmap, regs, regvals, 3); if (err) return err; - - err = regmap_read(regmap, AMC6821_REG_PSV_TEMP, ®val); - if (err) - return err; - temps[0] = regval; - - err = regmap_read(regmap, - channel ? AMC6821_REG_RTEMP_FAN_CTRL : AMC6821_REG_LTEMP_FAN_CTRL, - ®val); - if (err) - return err; - temps[1] = FIELD_GET(AMC6821_TEMP_LIMIT_MASK, regval) * 4; + temps[0] = regvals[1]; + temps[1] = FIELD_GET(AMC6821_TEMP_LIMIT_MASK, regvals[2]) * 4; /* slope is 32 >> in °C */ - regval = 32 >> FIELD_GET(AMC6821_TEMP_SLOPE_MASK, regval); - if (regval) - temps[2] = temps[1] + DIV_ROUND_CLOSEST(255 - pwm, regval); + slope = 32 >> FIELD_GET(AMC6821_TEMP_SLOPE_MASK, regvals[2]); + if (slope) + temps[2] = temps[1] + DIV_ROUND_CLOSEST(255 - regvals[0], slope); else temps[2] = 255;