aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorengstk <eng.stk@sapo.pt>2016-08-27 05:59:29 +0100
committerlucasponez <lucasponez@outlook.com>2021-03-22 13:51:34 -0300
commit97332b0012cad56b6311d8cbc943c8fc7287ce3c (patch)
tree3ec70d6581fbe52c435a256b3adc704d92531556
parent5f257afbf54049e67cf36eaf8ba6605c613c6276 (diff)
drivers: misc: implement usb fast charge mode
echo 0 /sys/kernel/fast_charge/force_fast_charge (disable) echo 1 /sys/kernel/fast_charge/force_fast_charge (enable) Change-Id: I29cc26e4f19e8afcd0198f245eeeb375316a928b Signed-off-by: engstk <eng.stk@sapo.pt>
-rw-r--r--drivers/misc/Kconfig6
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/fastchg.c102
-rw-r--r--drivers/power/qpnp-smbcharger.c8
-rw-r--r--include/linux/fastchg.h22
5 files changed, 139 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 6ebdf5faf673..c12ad7b54f06 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -724,6 +724,12 @@ config DTV_FC8300
help
Enable/disable FC8300 DTV module support
+config FORCE_FAST_CHARGE
+ bool "Force faster charge rate for USB"
+ default n
+ 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 3574ea05fba6..8960f7985acf 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -95,6 +95,7 @@ obj-$(CONFIG_FSUSB42_MUX) += fsusb42_mux.o
obj-$(CONFIG_SENSORS_STML0XX) += stml0xx/
obj-$(CONFIG_TPS61280) += tps61280.o
obj-$(CONFIG_DTV_FC8300) += moto-dtv-fc8300/
+obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o
# TODO: remove me b/62058353
subdir-ccflags-y += \
diff --git a/drivers/misc/fastchg.c b/drivers/misc/fastchg.c
new file mode 100644
index 000000000000..a00d425bb57d
--- /dev/null
+++ b/drivers/misc/fastchg.c
@@ -0,0 +1,102 @@
+/*
+ * Author: Chad Froebel <chadfroebel@gmail.com>
+ *
+ * Port to Thulium: 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>
+
+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/qpnp-smbcharger.c b/drivers/power/qpnp-smbcharger.c
index 3e59f25af18f..48e64349f835 100644
--- a/drivers/power/qpnp-smbcharger.c
+++ b/drivers/power/qpnp-smbcharger.c
@@ -40,6 +40,10 @@
#include <linux/ktime.h>
#include <linux/pmic-voter.h>
+#ifdef CONFIG_FORCE_FAST_CHARGE
+#include <linux/fastchg.h>
+#endif
+
/* Mask/Bit helpers */
#define _SMB_MASK(BITS, POS) \
((unsigned char)(((1 << (BITS)) - 1) << (POS)))
@@ -1784,7 +1788,11 @@ static int smbchg_set_usb_current_max(struct smbchg_chip *chip,
}
chip->usb_max_current_ma = 500;
}
+#ifdef CONFIG_FORCE_FAST_CHARGE
+ if ((force_fast_charge > 0 && current_ma == CURRENT_500_MA) || current_ma == CURRENT_900_MA) {
+#else
if (current_ma == CURRENT_900_MA) {
+#endif
rc = smbchg_sec_masked_write(chip,
chip->usb_chgpth_base + CHGPTH_CFG,
CFG_USB_2_3_SEL_BIT, CFG_USB_3);
diff --git a/include/linux/fastchg.h b/include/linux/fastchg.h
new file mode 100644
index 000000000000..9dc0adb63d75
--- /dev/null
+++ b/include/linux/fastchg.h
@@ -0,0 +1,22 @@
+/*
+ * Author: Chad Froebel <chadfroebel@gmail.com>
+ *
+ * Port to Thulium: 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