Skip to content

Commit

Permalink
ACPI: PMIC: Replace open coded be16_to_cpu()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
andy-shev authored and rafaeljw committed Jun 13, 2024
1 parent 1dd804a commit f42cfd5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/acpi/pmic/intel_pmic_chtdc_ti.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 = {
Expand Down

0 comments on commit f42cfd5

Please sign in to comment.