From ee89b6cb24f35447616425a04a202b75fdac244a Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Mon, 15 Mar 2021 15:13:45 -0700 Subject: [PATCH] linux-purism-librem5: add bq25890 patch for ship mode on poweroff (MR 2032) Submitted to purism here: https://source.puri.sm/Librem5/linux-next/-/merge_requests/333 --- ...charger-enter-ship-mode-on-power-off.patch | 108 ++++++++++++++++++ .../community/linux-purism-librem5/APKBUILD | 4 +- 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 device/community/linux-purism-librem5/0002-bq25890_charger-enter-ship-mode-on-power-off.patch diff --git a/device/community/linux-purism-librem5/0002-bq25890_charger-enter-ship-mode-on-power-off.patch b/device/community/linux-purism-librem5/0002-bq25890_charger-enter-ship-mode-on-power-off.patch new file mode 100644 index 000000000..7da74ba82 --- /dev/null +++ b/device/community/linux-purism-librem5/0002-bq25890_charger-enter-ship-mode-on-power-off.patch @@ -0,0 +1,108 @@ +From 5fe6169f02e92cf0220b58bba45dc16173876627 Mon Sep 17 00:00:00 2001 +From: Clayton Craft +Date: Fri, 5 Mar 2021 18:55:28 -0800 +Subject: [PATCH] bq25890_charger: enter ship mode on power off + +This sets the charger device into 'ship mode' when powering off by +hooking onto pm_power_off. 'Ship mode' is skipped if the device is +actively charging. This feature is disabled by default, and can be +enabled by setting 'ship_mode=1' when loading this module. + +Since the poweroff can be aborted (i.e. when charging), any previous +value for pm_power_off is saved and run in the cases where the +bq25890 is *not* used to power off system. +--- + drivers/power/supply/bq25890_charger.c | 56 ++++++++++++++++++++++++++ + 1 file changed, 56 insertions(+) + +diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c +index c33885e4f48c..7360bc51ef64 100644 +--- a/drivers/power/supply/bq25890_charger.c ++++ b/drivers/power/supply/bq25890_charger.c +@@ -40,6 +40,10 @@ static const char *const bq25890_chip_name[] = { + "BQ25896", + }; + ++static bool ship_mode; ++module_param(ship_mode, bool, 0644); ++MODULE_PARM_DESC(ship_mode, "Put device into 'ship mode' when powering off the computer"); ++ + enum bq25890_fields { + F_EN_HIZ, F_EN_ILIM, F_IILIM, /* Reg00 */ + F_BHOT, F_BCOLD, F_VINDPM_OFS, /* Reg01 */ +@@ -837,6 +841,43 @@ static int bq25890_power_supply_init(struct bq25890_device *bq) + return PTR_ERR_OR_ZERO(bq->charger); + } + ++static struct bq25890_device *bq25890_dev; ++void (*previous_pm_power_off)(void) = NULL; ++static void bq25890_power_off(void) ++{ ++ int ret; ++ ++ /* Don't enable ship mode if charging */ ++ if (bq25890_dev->state.online) { ++ dev_info(bq25890_dev->dev, "Charging, not entering ship mode"); ++ goto end; ++ } ++ ++ dev_info(bq25890_dev->dev, "Entering ship mode!"); ++ ++ /* Enable HIZ */ ++ dev_info(bq25890_dev->dev, "Enabling HIZ"); ++ ret = bq25890_field_write(bq25890_dev, F_EN_HIZ, 1); ++ if (ret < 0) ++ goto error; ++ ++ /* Enable ship mode with no delay */ ++ dev_info(bq25890_dev->dev, "Ship mode w/ no delay"); ++ ret = bq25890_field_write(bq25890_dev, F_BATFET_DLY, 0); ++ if (ret < 0) ++ goto error; ++ ret = bq25890_field_write(bq25890_dev, F_BATFET_DIS, 1); ++ if (ret < 0) ++ goto error; ++ ++error: ++ dev_err(bq25890_dev->dev, "Error entering ship mode.\n"); ++ ++end: ++ if (previous_pm_power_off) ++ previous_pm_power_off(); ++} ++ + static void bq25890_usb_work(struct work_struct *data) + { + int ret; +@@ -1141,6 +1182,17 @@ static int bq25890_probe(struct i2c_client *client, + goto battery_fail; + } + ++ if (ship_mode) { ++ if (pm_power_off) ++ previous_pm_power_off = pm_power_off; ++ dev_info(bq->dev, "ship mode will be enabled"); ++ bq25890_dev = bq; ++ pm_power_off = &bq25890_power_off; ++ } else { ++ dev_info(bq->dev, "ship mode not enabled"); ++ } ++ ++ + return 0; + + battery_fail: +@@ -1164,6 +1216,10 @@ static int bq25890_remove(struct i2c_client *client) + /* reset all registers to default values */ + bq25890_chip_reset(bq); + ++ if (pm_power_off == &bq25890_power_off) ++ /* restore previous pm_power_off */ ++ pm_power_off = previous_pm_power_off; ++ + return 0; + } + +-- +2.30.2 + diff --git a/device/community/linux-purism-librem5/APKBUILD b/device/community/linux-purism-librem5/APKBUILD index dfb5a986c..151ddf1fc 100644 --- a/device/community/linux-purism-librem5/APKBUILD +++ b/device/community/linux-purism-librem5/APKBUILD @@ -2,7 +2,7 @@ # Maintainer: Clayton Craft pkgname=linux-purism-librem5 pkgver=5.11.4 -pkgrel=0 +pkgrel=1 _purismrel=1 # . _purismver=${pkgver}pureos$_purismrel @@ -34,6 +34,7 @@ source=" $pkgname-$_purismver.tar.gz::https://source.puri.sm/Librem5/$_repository/-/archive/pureos/$_purismver/$_repository-pureos-$_purismver.tar.gz 8f11380ec32912370b8ae9134a0387a6f18862f7.patch 0001-Revert-arm64-dts-librem5-Drop-separte-DP-device-tree.patch + 0002-bq25890_charger-enter-ship-mode-on-power-off.patch $_config " builddir="$srcdir/$_repository-pureos-$_purismver" @@ -75,4 +76,5 @@ dev() { sha512sums="d2e0f49403413f581aee6e47e021cb04fc003fbf821349c188a0c6a57561ba702c327badf9b181c6f8fdc6952ebc7f061482d6508ae48dc336842eb94c5ed558 linux-purism-librem5-5.11.4pureos1.tar.gz 9870bff4b187188b519b23264c2634ee4232011fed6d2f66a7b4971db354ac3dffa0e1552bd0dc953c66ec622e18ce8899fdbcfba94f60867fc5004d6da96753 8f11380ec32912370b8ae9134a0387a6f18862f7.patch 5baae99010bde62e253fdd56f21ba096c217ba2ab9c367c80b34bc0f445a79a8fb8b5d14682f71ad6061d73c81fc16a608f4be037d792978dbbaf74267844260 0001-Revert-arm64-dts-librem5-Drop-separte-DP-device-tree.patch +1a12f74895b0fc710792e3881f23754a8eb92d25b11a2751db007a1b08f72729043d1e824096c97dc795b8e33300274887b428997ddaacf4b61f52ef3bd78ce5 0002-bq25890_charger-enter-ship-mode-on-power-off.patch d27cc078f49563fa935d104846017c9ba28e859d5231d202c68b6438e25f381747206fe0be86d323bd50dc457e67b02a52eb60a845c35bd33d7f2367893781d2 config-purism-librem5.aarch64"