]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ACPI: PMIC: Replace open coded be16_to_cpu()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 6 Jun 2024 20:54:16 +0000 (23:54 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 13 Jun 2024 19:23:05 +0000 (21:23 +0200)
It's easier to understand the nature of a data type when
it's written explicitly. With that, replace open coded
endianess conversion.

As a side effect it fixes the returned value of
intel_crc_pmic_update_aux() since ACPI PMIC core code
expects negative or zero and never uses positive one.

While at it, use macros from bits.h to reduce a room for mistake.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/pmic/intel_pmic_chtdc_ti.c

index 35744a0307aa466758f9994463cc762d63e3be44..79f9df552524be9b2da50d630c376a59f020e164 100644 (file)
@@ -8,12 +8,16 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/bits.h>
 #include <linux/init.h>
 #include <linux/mfd/intel_soc_pmic.h>
 #include <linux/platform_device.h>
+#include <asm/byteorder.h>
 #include "intel_pmic.h"
 
 /* registers stored in 16bit BE (high:low, total 10bit) */
+#define PMIC_REG_MASK          GENMASK(9, 0)
+
 #define CHTDC_TI_VBAT          0x54
 #define CHTDC_TI_DIETEMP       0x56
 #define CHTDC_TI_BPTHERM       0x58
@@ -73,7 +77,7 @@ static int chtdc_ti_pmic_get_power(struct regmap *regmap, int reg, int bit,
        if (regmap_read(regmap, reg, &data))
                return -EIO;
 
-       *value = data & 1;
+       *value = data & BIT(0);
        return 0;
 }
 
@@ -85,13 +89,12 @@ static int chtdc_ti_pmic_update_power(struct regmap *regmap, int reg, int bit,
 
 static int chtdc_ti_pmic_get_raw_temp(struct regmap *regmap, int reg)
 {
-       u8 buf[2];
+       __be16 buf;
 
-       if (regmap_bulk_read(regmap, reg, buf, sizeof(buf)))
+       if (regmap_bulk_read(regmap, reg, &buf, sizeof(buf)))
                return -EIO;
 
-       /* stored in big-endian */
-       return ((buf[0] & 0x03) << 8) | buf[1];
+       return be16_to_cpu(buf) & PMIC_REG_MASK;
 }
 
 static const struct intel_pmic_opregion_data chtdc_ti_pmic_opregion_data = {