kernel: bump 5.10 to 5.10.141
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 872-v5.13-02-hwmon-tps23861-set-current-shunt-value.patch
1 From 9bca598d4a86e88afb29fdb516c68b2519bd0fb9 Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robert.marko@sartura.hr>
3 Date: Thu, 10 Jun 2021 00:07:27 +0200
4 Subject: [PATCH 3/4] hwmon: (tps23861) set current shunt value
5
6 TPS23861 has a configuration bit for setting of the
7 current shunt value used on the board.
8 Its bit 0 of the General Mask 1 register.
9
10 According to the datasheet bit values are:
11 0 for 255 mOhm (Default)
12 1 for 250 mOhm
13
14 So, configure the bit before registering the hwmon
15 device according to the value passed in the DTS or
16 default one if none is passed.
17
18 This caused potentially reading slightly skewed values
19 due to max current value being 1.02A when 250mOhm shunt
20 is used instead of 1.0A when 255mOhm is used.
21
22 Fixes: fff7b8ab2255 ("hwmon: add Texas Instruments TPS23861 driver")
23 Signed-off-by: Robert Marko <robert.marko@sartura.hr>
24 Link: https://lore.kernel.org/r/20210609220728.499879-2-robert.marko@sartura.hr
25 Signed-off-by: Guenter Roeck <linux@roeck-us.net>
26 ---
27 drivers/hwmon/tps23861.c | 12 ++++++++++++
28 1 file changed, 12 insertions(+)
29
30 --- a/drivers/hwmon/tps23861.c
31 +++ b/drivers/hwmon/tps23861.c
32 @@ -99,6 +99,9 @@
33 #define POWER_ENABLE 0x19
34 #define TPS23861_NUM_PORTS 4
35
36 +#define TPS23861_GENERAL_MASK_1 0x17
37 +#define TPS23861_CURRENT_SHUNT_MASK BIT(0)
38 +
39 #define TEMPERATURE_LSB 652 /* 0.652 degrees Celsius */
40 #define VOLTAGE_LSB 3662 /* 3.662 mV */
41 #define SHUNT_RESISTOR_DEFAULT 255000 /* 255 mOhm */
42 @@ -561,6 +564,15 @@ static int tps23861_probe(struct i2c_cli
43 else
44 data->shunt_resistor = SHUNT_RESISTOR_DEFAULT;
45
46 + if (data->shunt_resistor == SHUNT_RESISTOR_DEFAULT)
47 + regmap_clear_bits(data->regmap,
48 + TPS23861_GENERAL_MASK_1,
49 + TPS23861_CURRENT_SHUNT_MASK);
50 + else
51 + regmap_set_bits(data->regmap,
52 + TPS23861_GENERAL_MASK_1,
53 + TPS23861_CURRENT_SHUNT_MASK);
54 +
55 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name,
56 data, &tps23861_chip_info,
57 NULL);