diff options
| author | engstk <eng.stk@sapo.pt> | 2017-07-31 18:28:24 +0100 |
|---|---|---|
| committer | Semavi Ulusoy <doc.divxm@gmail.com> | 2023-05-25 01:48:28 +0300 |
| commit | f2357465a39723366faac4a9fb77489fd5c08739 (patch) | |
| tree | 2e02a4474e18cc87673e9d0b7e864195dda8bd98 | |
| parent | b870015c90676065016aaa65244a159f8e8c35dc (diff) | |
echo 0 /sys/kernel/fast_charge/force_fast_charge (disable)
echo 1 /sys/kernel/fast_charge/force_fast_charge (enable)
Enables force charging up to 900mA in usb2 mode
Signed-off-by: engstk <eng.stk@sapo.pt>
Signed-off-by: AnierinB <anierin@evolution-x.org>
| -rw-r--r-- | drivers/misc/Kconfig | 6 | ||||
| -rw-r--r-- | drivers/misc/Makefile | 2 | ||||
| -rw-r--r-- | drivers/misc/fastchg.c | 103 | ||||
| -rw-r--r-- | drivers/power/oplus/oplus_charger.c | 18 | ||||
| -rw-r--r-- | include/linux/fastchg.h | 22 |
5 files changed, 151 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 0660da335bc2..ef577cb44835 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -668,6 +668,12 @@ config OEM_QMI Say Y here to enable oem qmi support #endif /* OPLUS_FEATURE_SIM_DETECT */ +config FORCE_FAST_CHARGE + bool "Force faster charge rate for USB" + default y + help + This allows users to override default charge rate for USB + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 442e24b0b20d..616e4555728b 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -106,3 +106,5 @@ obj-$(CONFIG_OEM_QMI) += oem_qmi_client.o #endif obj-y += qrc/ obj-$(CONFIG_KINECTICS_XR_NORDIC) += kxrctrl/ + +obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o diff --git a/drivers/misc/fastchg.c b/drivers/misc/fastchg.c new file mode 100644 index 000000000000..3b8ac5f1af37 --- /dev/null +++ b/drivers/misc/fastchg.c @@ -0,0 +1,103 @@ +/* + * Author (legacy sysfs): Chad Froebel <chadfroebel@gmail.com> + * + * Port to instantnoodle/kebab and powers supply hooks: engstk <eng.stk@sapo.pt> + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +/* + * Possible values for "force_fast_charge" are : + * + * 0 - Disabled (default) + * 1 - Force faster charge +*/ + +#include <linux/kobject.h> +#include <linux/sysfs.h> +#include <linux/fastchg.h> +#include <linux/string.h> +#include <linux/module.h> + +int force_fast_charge = 0; + +static int __init get_fastcharge_opt(char *ffc) +{ + if (strcmp(ffc, "0") == 0) { + force_fast_charge = 0; + } else if (strcmp(ffc, "1") == 0) { + force_fast_charge = 1; + } else { + force_fast_charge = 0; + } + return 1; +} + +__setup("ffc=", get_fastcharge_opt); + +static ssize_t force_fast_charge_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + size_t count = 0; + count += sprintf(buf, "%d\n", force_fast_charge); + return count; +} + +static ssize_t force_fast_charge_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) +{ + sscanf(buf, "%d ", &force_fast_charge); + if (force_fast_charge < 0 || force_fast_charge > 1) + force_fast_charge = 0; + + return count; +} + +static struct kobj_attribute force_fast_charge_attribute = +__ATTR(force_fast_charge, 0664, force_fast_charge_show, force_fast_charge_store); + +static struct attribute *force_fast_charge_attrs[] = { +&force_fast_charge_attribute.attr, +NULL, +}; + +static struct attribute_group force_fast_charge_attr_group = { +.attrs = force_fast_charge_attrs, +}; + +/* Initialize fast charge sysfs folder */ +static struct kobject *force_fast_charge_kobj; + +int force_fast_charge_init(void) +{ + int force_fast_charge_retval; + + force_fast_charge_kobj = kobject_create_and_add("fast_charge", kernel_kobj); + if (!force_fast_charge_kobj) { + return -ENOMEM; + } + + force_fast_charge_retval = sysfs_create_group(force_fast_charge_kobj, &force_fast_charge_attr_group); + + if (force_fast_charge_retval) + kobject_put(force_fast_charge_kobj); + + if (force_fast_charge_retval) + kobject_put(force_fast_charge_kobj); + + return (force_fast_charge_retval); +} + +void force_fast_charge_exit(void) +{ + kobject_put(force_fast_charge_kobj); +} + +module_init(force_fast_charge_init); +module_exit(force_fast_charge_exit); diff --git a/drivers/power/oplus/oplus_charger.c b/drivers/power/oplus/oplus_charger.c index 5e4f00674475..6366f575eb27 100644 --- a/drivers/power/oplus/oplus_charger.c +++ b/drivers/power/oplus/oplus_charger.c @@ -90,6 +90,13 @@ static struct oplus_chg_chip *g_charger_chip = NULL; +#ifdef CONFIG_FORCE_FAST_CHARGE +#include <linux/moduleparam.h> +#include <linux/fastchg.h> +static int ffc_val = 900; +module_param(ffc_val, int, 0644); +#endif + #define FLASH_SCREEN_CTRL_OTA 0X01 #define FLASH_SCREEN_CTRL_DTSI 0X02 @@ -5621,7 +5628,18 @@ void oplus_chg_set_input_current_limit(struct oplus_chg_chip *chip) case POWER_SUPPLY_TYPE_UNKNOWN: return; case POWER_SUPPLY_TYPE_USB: +#ifdef CONFIG_FORCE_FAST_CHARGE + if (force_fast_charge > 0) + { + current_limit = ffc_val; + } + else + { + current_limit = chip->limits.input_current_usb_ma; + } +#else current_limit = chip->limits.input_current_usb_ma; +#endif break; case POWER_SUPPLY_TYPE_USB_DCP: current_limit = chip->limits.input_current_charger_ma; diff --git a/include/linux/fastchg.h b/include/linux/fastchg.h new file mode 100644 index 000000000000..7ab4c91e0388 --- /dev/null +++ b/include/linux/fastchg.h @@ -0,0 +1,22 @@ +/* + * Author (legacy sysfs): Chad Froebel <chadfroebel@gmail.com> + * + * Port to lemonadep/kebab and powers supply hooks: engstk <eng.stk@sapo.pt> + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef _LINUX_FASTCHG_H +#define _LINUX_FASTCHG_H + +extern int force_fast_charge; + +#endif |
