Skip to content

Commit

Permalink
rtc: isl12022: Explicitly use __le16 type for ISL12022_REG_TEMP_L
Browse files Browse the repository at this point in the history
We are reading 10-bit value in a 16-bit register in LE format.
Make this explicit by using __le16 type for it and corresponding
conversion function.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Link: https://lore.kernel.org/r/20230110140806.87432-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
  • Loading branch information
Andy Shevchenko authored and Alexandre Belloni committed Feb 22, 2023
1 parent f525b21 commit 93219a4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/rtc/rtc-isl12022.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <linux/regmap.h>
#include <linux/hwmon.h>

#include <asm/byteorder.h>

/* ISL register offsets */
#define ISL12022_REG_SC 0x00
#define ISL12022_REG_MN 0x01
Expand Down Expand Up @@ -63,17 +65,16 @@ static umode_t isl12022_hwmon_is_visible(const void *data,
static int isl12022_hwmon_read_temp(struct device *dev, long *mC)
{
struct regmap *regmap = dev_get_drvdata(dev);
u8 temp_buf[2];
int temp, ret;
__le16 buf;

ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L,
temp_buf, sizeof(temp_buf));
ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L, &buf, sizeof(buf));
if (ret)
return ret;
/*
* Temperature is represented as a 10-bit number, unit half-Kelvins.
*/
temp = (temp_buf[1] << 8) | temp_buf[0];
temp = le16_to_cpu(buf);
temp *= 500;
temp -= 273000;

Expand Down

0 comments on commit 93219a4

Please sign in to comment.