kernel: update U-Boot nvmem driver to v6.2 release version
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 873-v6.0-hwmon-tps23861-fix-byte-order-in-current-and-voltage.patch
1 From 0eabb1396656f215a5333a9444158b17b0fd3247 Mon Sep 17 00:00:00 2001
2 From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
3 Date: Wed, 20 Jul 2022 22:22:55 -0500
4 Subject: hwmon: (tps23861) fix byte order in current and voltage registers
5
6 Trying to use this driver on a big-endian machine results in garbage
7 values for voltage and current. The tps23861 registers are little-
8 endian, and regmap_read_bulk() does not do byte order conversion. Thus
9 on BE machines, the most significant bytes got modified, and were
10 trimmed by the VOLTAGE_CURRENT_MASK.
11
12 To resolve this use uint16_t values, and convert them to host byte
13 order using le16_to_cpu(). This results in correct readings on MIPS.
14
15 Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
16 Link: https://lore.kernel.org/r/20220721032255.2850647-1-mr.nuke.me@gmail.com
17 [groeck: Use __le16 instead of uint16_t]
18 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
19 ---
20 drivers/hwmon/tps23861.c | 14 +++++++++-----
21 1 file changed, 9 insertions(+), 5 deletions(-)
22
23 --- a/drivers/hwmon/tps23861.c
24 +++ b/drivers/hwmon/tps23861.c
25 @@ -140,7 +140,8 @@ static int tps23861_read_temp(struct tps
26 static int tps23861_read_voltage(struct tps23861_data *data, int channel,
27 long *val)
28 {
29 - unsigned int regval;
30 + __le16 regval;
31 + long raw_val;
32 int err;
33
34 if (channel < TPS23861_NUM_PORTS) {
35 @@ -155,7 +156,8 @@ static int tps23861_read_voltage(struct
36 if (err < 0)
37 return err;
38
39 - *val = (FIELD_GET(VOLTAGE_CURRENT_MASK, regval) * VOLTAGE_LSB) / 1000;
40 + raw_val = le16_to_cpu(regval);
41 + *val = (FIELD_GET(VOLTAGE_CURRENT_MASK, raw_val) * VOLTAGE_LSB) / 1000;
42
43 return 0;
44 }
45 @@ -163,8 +165,9 @@ static int tps23861_read_voltage(struct
46 static int tps23861_read_current(struct tps23861_data *data, int channel,
47 long *val)
48 {
49 - unsigned int current_lsb;
50 - unsigned int regval;
51 + long raw_val, current_lsb;
52 + __le16 regval;
53 +
54 int err;
55
56 if (data->shunt_resistor == SHUNT_RESISTOR_DEFAULT)
57 @@ -178,7 +181,8 @@ static int tps23861_read_current(struct
58 if (err < 0)
59 return err;
60
61 - *val = (FIELD_GET(VOLTAGE_CURRENT_MASK, regval) * current_lsb) / 1000000;
62 + raw_val = le16_to_cpu(regval);
63 + *val = (FIELD_GET(VOLTAGE_CURRENT_MASK, raw_val) * current_lsb) / 1000000;
64
65 return 0;
66 }