power: supply: RN5T618/RC5T619
Subsystems (2)
cover power: supply: RN5T618/RC5T619
This series adds support for the RN5T618/RC5T619 charger and fuel gauge. Battery and input power status can be read.
Andreas Kemnade (2):
power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge
mfd: rn5t618: Add a power supply subdevice
drivers/mfd/rn5t618.c | 1 + drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 + drivers/power/supply/rn5t618_power.c | 565 +++++++++++++++++++++++++++ 4 files changed, 575 insertions(+) create mode 100644 drivers/power/supply/rn5t618_power.c
Signature · 1 line
2.20.1
PATCH 1/2 power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge
Both chips have charger and a fuel gauge.
This adds basic support for displaying the state of the battery and the input power, settings are not modified. There are some defaults set via OTP.
Charging also starts after plugging USB.
Known issues of the fuel gauge: There are drivers in the wild which disable the fuel gauge at shutdown. If a kernel is booted without fuel gauge support, after such a driver has been used, the fuel gauge will stay off and decalibrate.
If this driver is used after that, it might display wrong values for charge level.
--- drivers/power/supply/Kconfig | 8 + drivers/power/supply/Makefile | 1 + drivers/power/supply/rn5t618_power.c | 565 +++++++++++++++++++++++++++ 3 files changed, 574 insertions(+) create mode 100644 drivers/power/supply/rn5t618_power.c
drivers/power/supply/Kconfig +8 -0
@@ -739,4 +739,12 @@ config CHARGER_WILCO information can be found in Documentation/ABI/testing/sysfs-class-power-wilco +config RN5T618_POWER + tristate "RN5T618 charger/fuel gauge support" + depends on MFD_RN5T618 + help + Say Y here to have support for RN5T618 PMIC family fuel gauge and charger + This driver can also be built as a module. If so, the module will be + called rn5t618_power. + endif # POWER_SUPPLY
drivers/power/supply/Makefile +1 -0
@@ -95,3 +95,4 @@ obj-$(CONFIG_CHARGER_UCS1002) += ucs1002_power.o obj-$(CONFIG_CHARGER_BD70528) += bd70528-charger.o obj-$(CONFIG_CHARGER_BD99954) += bd99954-charger.o obj-$(CONFIG_CHARGER_WILCO) += wilco-charger.o +obj-$(CONFIG_RN5T618_POWER) += rn5t618_power.o
drivers/power/supply/rn5t618_power.c new file +565 -0
565 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 1/2] power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge
Hi,
Driver looks mostly good.
Quoted 8 lines · Andreas Kemnade
[...]
drivers/power/supply/rn5t618_power.c new file +7
-0+static int rn5t618_battery_current_now (struct rn5t618_power_info *info, +union power_supply_propval *val) +{ +u16 res; +int ret; + + ret =rn5t618_battery_read_doublereg (info,RN5T618_CC_AVEREG1 , &res);
drivers/power/supply/rn5t618_power.c line 194
Quoted 10 lines
drivers/power/supply/rn5t618_power.c new file +10
-0+if (ret) +return ret; + + val->intval = res; +/* 2's complement */ +if (val->intval & (1 <<13 )) + val->intval = val->intval - (1 <<14 ); + +/* negate current to be positive when discharging */ + val->intval *=-1000 ;
mh, the sign is not documented (which should be fixed). At least sbs-battery does it the other way around (negative current when discharging, positive otherwise). Some drivers do not support signed current and always report positive values (e.g. ACPI driver).
What did you use as reference for swapping the sign?
drivers/power/supply/rn5t618_power.c line 431
Quoted 7 lines
drivers/power/supply/rn5t618_power.c new file +6
-0+return 0 ; +} +static const struct power_supply_desc rn5t618_adp_desc = { + .name ="rn5t618-adp" , + .type =POWER_SUPPLY_TYPE_MAINS , + .properties = rn5t618_usb_props,
wrong property array, works by accident since usb and adp property lists are the same.
drivers/power/supply/rn5t618_power.c line 434
Quoted 4 lines
drivers/power/supply/rn5t618_power.c new file +3
-0+ .num_properties = ARRAY_SIZE(rn5t618_adp_props), + .get_property = rn5t618_adp_get_property, +};
-- Sebastian
Re: [PATCH 1/2] power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge
Quoted 29 lines · On Wed, 26 Aug 2020 19:48:17 +0200 Sebastian Reichel…
Hi,
Driver looks mostly good.
Quoted 8 lines · Andreas Kemnade
[...]
drivers/power/supply/rn5t618_power.c new file +7
-0+static int rn5t618_battery_current_now (struct rn5t618_power_info *info, +union power_supply_propval *val) +{ +u16 res; +int ret; + + ret =rn5t618_battery_read_doublereg (info,RN5T618_CC_AVEREG1 , &res);drivers/power/supply/rn5t618_power.c line 194
Quoted 10 lines
drivers/power/supply/rn5t618_power.c new file +10
-0+if (ret) +return ret; + + val->intval = res; +/* 2's complement */ +if (val->intval & (1 <<13 )) + val->intval = val->intval - (1 <<14 ); + +/* negate current to be positive when discharging */ + val->intval *=-1000 ;mh, the sign is not documented (which should be fixed). At least sbs-battery does it the other way around (negative current when discharging, positive otherwise). Some drivers do not support signed current and always report positive values (e.g. ACPI driver).
Quoted 2 lines
What did you use as reference for swapping the sign?
Well, I have searched for documentation, found nothing and used the bq27xxx driver as reference which I am used to from the GTA04/GTA02, so things behave equal. That are the devices where a was most intensively looking at those values.
I thought that there would be some unwritten rule about that.
Regards,
Andreas
Re: [PATCH 1/2] power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge
Hi,
Quoted 18 lines · Andreas Kemnade
Quoted 16 lines · On Wed, 26 Aug 2020 19:48:17 +0200 Sebastian Reichel…
Quoted 5 lines · Andreas Kemnade
[...]
drivers/power/supply/rn5t618_power.c new file +4
-0+static int rn5t618_battery_current_now (struct rn5t618_power_info *info, +union power_supply_propval *val) +{ +u16 res;drivers/power/supply/rn5t618_power.c line 191
Quoted 10 lines
drivers/power/supply/rn5t618_power.c new file +10
-0+int ret; + + ret =rn5t618_battery_read_doublereg (info,RN5T618_CC_AVEREG1 , &res); +if (ret) +return ret; + + val->intval = res; +/* 2's complement */ +if (val->intval & (1 <<13 )) + val->intval = val->intval - (1 <<14 );
Btw. I think sign_extend32() can be used here?
Quoted 8 lines
Quoted 8 lines
drivers/power/supply/rn5t618_power.c line 194
Quoted 2 lines
drivers/power/supply/rn5t618_power.c new file +2
-0+/* negate current to be positive when discharging */ + val->intval *=-1000 ;mh, the sign is not documented (which should be fixed). At least sbs-battery does it the other way around (negative current when discharging, positive otherwise). Some drivers do not support signed current and always report positive values (e.g. ACPI driver).
Quoted 7 lines
Quoted 2 lines
What did you use as reference for swapping the sign?
Well, I have searched for documentation, found nothing and used the bq27xxx driver as reference which I am used to from the GTA04/GTA02, so things behave equal. That are the devices where a was most intensively looking at those values.
I thought that there would be some unwritten rule about that.
The mess is mostly due to lacking reviewing from my side (and possibly my predecessors). I just went through a dozen of drivers and it looks like most either do not support signed current (and use negative values as error code :() or use negative current for discharge. I could not find any other driver using negative numbers for charging. I think it's best to negative = discharge as official correct value and will send an update patch for the documentation later.
-- Sebastian
Re: [PATCH 1/2] power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge
Hi,
Quoted 40 lines · On Wed, 26 Aug 2020 23:59:50 +0200 Sebastian Reichel…
Hi,
Quoted 18 lines · Andreas Kemnade
Quoted 16 lines · On Wed, 26 Aug 2020 19:48:17 +0200 Sebastian Reichel…
Quoted 5 lines · Andreas Kemnade
[...]
drivers/power/supply/rn5t618_power.c new file +4
-0+static int rn5t618_battery_current_now (struct rn5t618_power_info *info, +union power_supply_propval *val) +{ +u16 res;drivers/power/supply/rn5t618_power.c line 191
Quoted 10 lines
drivers/power/supply/rn5t618_power.c new file +10
-0+int ret; + + ret =rn5t618_battery_read_doublereg (info,RN5T618_CC_AVEREG1 , &res); +if (ret) +return ret; + + val->intval = res; +/* 2's complement */ +if (val->intval & (1 <<13 )) + val->intval = val->intval - (1 <<14 );Btw. I think
sign_extend32()can be used here?Quoted 8 lines
Quoted 8 lines
drivers/power/supply/rn5t618_power.c line 194
Quoted 2 lines
drivers/power/supply/rn5t618_power.c new file +2
-0+/* negate current to be positive when discharging */ + val->intval *=-1000 ;mh, the sign is not documented (which should be fixed). At least sbs-battery does it the other way around (negative current when discharging, positive otherwise). Some drivers do not support signed current and always report positive values (e.g. ACPI driver).
Quoted 7 lines
Quoted 2 lines
What did you use as reference for swapping the sign?
Well, I have searched for documentation, found nothing and used the bq27xxx driver as reference which I am used to from the GTA04/GTA02, so things behave equal. That are the devices where a was most intensively looking at those values.
I thought that there would be some unwritten rule about that.
Quoted 9 lines
The mess is mostly due to lacking reviewing from my side (and possibly my predecessors). I just went through a dozen of drivers and it looks like most either do not support signed current (and use negative values as error code :() or use negative current for discharge. I could not find any other driver using negative numbers for charging. I think it's best to negative = discharge as official correct value and will send an update patch for the documentation later.
ok, I will remove that sign-change and keep/update the comment so that you know that the driver does it the official way and send a v2 with the other things you mentioned.
Regards,
Andreas
PATCH 2/2 mfd: rn5t618: Add a power supply subdevice
In reply to Andreas KemnadeThe RN5T618 and RC5T619 both have a charger and a fuel gauge, so add a subdevice for it. According to drivers in the wild, things should be at least similar, but since it is not tested, add it only to the RC5T619.
--- drivers/mfd/rn5t618.c | 1 + 1 file changed, 1 insertion(+)
drivers/mfd/rn5t618.c +1 -0
@@ -25,6 +25,7 @@ static const struct mfd_cell rn5t618_cells[] = {static const struct mfd_cell rc5t619_cells[] = { { .name ="rn5t618-adc" }, + { .name ="rn5t618-power" }, { .name ="rn5t618-regulator" }, { .name ="rc5t619-rtc" }, { .name ="rn5t618-wdt" },
Signature · 1 line
2.20.1
Lee Jones
AppliedRe: [PATCH 2/2] mfd: rn5t618: Add a power supply subdevice
Quoted 9 lines · Andreas Kemnade
The RN5T618 and RC5T619 both have a charger and a fuel gauge, so add a subdevice for it. According to drivers in the wild, things should be at least similar, but since it is not tested, add it only to the RC5T619.
Signed-off-by Andreas Kemnade <[email protected]>--- drivers/mfd/rn5t618.c | 1 + 1 file changed, 1 insertion(+)
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog