Linux-Hwmon Archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Guenter Roeck <linux@roeck-us.net>,
	Patrick Rudolph <patrick.rudolph@9elements.com>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jean Delvare <jdelvare@suse.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 1/3] hwmon: (pmbus/mp2975) Replace home made version of __assign_bit()
Date: Mon, 25 Mar 2024 14:07:42 +0200	[thread overview]
Message-ID: <20240325120952.3019767-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com>

The newly introduced SWAP() macro is quite generic by naming, but
moreover it's a repetition of the existing __assign_bit().
With this applied, add a missing bits.h (via now required bitops.h).

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/hwmon/pmbus/mp2975.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c
index 953c02a2aeb5..af118087c4ee 100644
--- a/drivers/hwmon/pmbus/mp2975.c
+++ b/drivers/hwmon/pmbus/mp2975.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2020 Nvidia Technologies Ltd.
  */
 
+#include <linux/bitops.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -396,7 +397,7 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
 				  int reg, u16 word)
 {
 	u8 target, mask;
-	int ret;
+	long ret;
 
 	if (reg != PMBUS_SMBALERT_MASK)
 		return -ENODATA;
@@ -415,7 +416,6 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
  * Set/Clear 'bit' in 'ret' based on condition followed by define for each bit in SMBALERT_MASK.
  * Also bit 2 & 15 are reserved.
  */
-#define SWAP(val, mask, cond, bit) (((mask) & (cond)) ? ((val) & ~BIT(bit)) : ((val) | BIT(bit)))
 
 #define MP2973_TEMP_OT		0
 #define MP2973_VIN_UVLO		1
@@ -434,36 +434,35 @@ static int mp2973_write_word_data(struct i2c_client *client, int page,
 
 	switch (target) {
 	case PMBUS_STATUS_CML:
-		ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_DATA, MP2973_INVALID_DATA);
-		ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_COMMAND,  MP2973_INVALID_COMMAND);
-		ret = SWAP(ret, mask, PB_CML_FAULT_OTHER_COMM, MP2973_OTHER_COMM);
-		ret = SWAP(ret, mask, PB_CML_FAULT_PACKET_ERROR, MP2973_PACKET_ERROR);
+		__assign_bit(MP2973_INVALID_DATA, &ret, !(mask & PB_CML_FAULT_INVALID_DATA));
+		__assign_bit(MP2973_INVALID_COMMAND, &ret, !(mask & PB_CML_FAULT_INVALID_COMMAND));
+		__assign_bit(MP2973_OTHER_COMM, &ret, !(mask & PB_CML_FAULT_OTHER_COMM));
+		__assign_bit(MP2973_PACKET_ERROR, &ret, !(mask & PB_CML_FAULT_PACKET_ERROR));
 		break;
 	case PMBUS_STATUS_VOUT:
-		ret = SWAP(ret, mask, PB_VOLTAGE_UV_FAULT, MP2973_VOLTAGE_UV);
-		ret = SWAP(ret, mask, PB_VOLTAGE_OV_FAULT, MP2973_VOLTAGE_OV);
+		__assign_bit(MP2973_VOLTAGE_UV, &ret, !(mask & PB_VOLTAGE_UV_FAULT));
+		__assign_bit(MP2973_VOLTAGE_OV, &ret, !(mask & PB_VOLTAGE_OV_FAULT));
 		break;
 	case PMBUS_STATUS_IOUT:
-		ret = SWAP(ret, mask, PB_IOUT_OC_FAULT, MP2973_IOUT_OC);
-		ret = SWAP(ret, mask, PB_IOUT_OC_LV_FAULT, MP2973_IOUT_OC_LV);
+		__assign_bit(MP2973_IOUT_OC, &ret, !(mask & PB_IOUT_OC_FAULT));
+		__assign_bit(MP2973_IOUT_OC_LV, &ret, !(mask & PB_IOUT_OC_LV_FAULT));
 		break;
 	case PMBUS_STATUS_TEMPERATURE:
-		ret = SWAP(ret, mask, PB_TEMP_OT_FAULT, MP2973_TEMP_OT);
+		__assign_bit(MP2973_TEMP_OT, &ret, !(mask & PB_TEMP_OT_FAULT));
 		break;
 	/*
 	 * Map remaining bits to MFR specific to let the PMBUS core mask
 	 * those bits by default.
 	 */
 	case PMBUS_STATUS_MFR_SPECIFIC:
-		ret = SWAP(ret, mask, BIT(1), MP2973_VIN_UVLO);
-		ret = SWAP(ret, mask, BIT(3), MP2973_VIN_OVP);
-		ret = SWAP(ret, mask, BIT(4), MP2973_MTP_FAULT);
-		ret = SWAP(ret, mask, BIT(6), MP2973_MTP_BLK_TRIG);
+		__assign_bit(MP2973_VIN_UVLO, &ret, !(mask & BIT(1)));
+		__assign_bit(MP2973_VIN_OVP, &ret, !(mask & BIT(3)));
+		__assign_bit(MP2973_MTP_FAULT, &ret, !(mask & BIT(4)));
+		__assign_bit(MP2973_MTP_BLK_TRIG, &ret, !(mask & BIT(6)));
 		break;
 	default:
 		return 0;
 	}
-#undef SWAP
 
 	return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret);
 }
-- 
2.43.0.rc1.1.gbec44491f096


  reply	other threads:[~2024-03-25 12:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 12:07 [PATCH v1 0/3] hwmon: (pmbus/mp2975) Refactor the driver Andy Shevchenko
2024-03-25 12:07 ` Andy Shevchenko [this message]
2024-03-25 16:29   ` [PATCH v1 1/3] hwmon: (pmbus/mp2975) Replace home made version of __assign_bit() Guenter Roeck
2024-03-25 16:34     ` Andy Shevchenko
2024-03-25 12:07 ` [PATCH v1 2/3] hwmon: (pmbus/mp2975) Constify local pointers to pmbus_driver_info Andy Shevchenko
2024-03-25 16:29   ` Guenter Roeck
2024-03-25 12:07 ` [PATCH v1 3/3] hwmon: (pmbus/mp2975) Use i2c_get_match_data() Andy Shevchenko
2024-03-25 16:31   ` Guenter Roeck
2024-03-25 16:36     ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240325120952.3019767-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=patrick.rudolph@9elements.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).