From 7d737fa2865574def8213a157729c1be86e14a6e Mon Sep 17 00:00:00 2001 From: "eng.stk" Date: Sat, 13 Feb 2016 12:31:03 +0530 Subject: [PATCH] drivers: misc: Implement USB fast charge mode Signed-off-by: engstk Signed-off-by: Adithya R --- drivers/misc/Kconfig | 8 +++ drivers/misc/Makefile | 1 + drivers/misc/fastchg.c | 104 ++++++++++++++++++++++++++++++++++ drivers/usb/phy/phy-msm-usb.c | 13 +++++ include/linux/fastchg.h | 22 +++++++ 5 files changed, 148 insertions(+) create mode 100644 drivers/misc/fastchg.c create mode 100644 include/linux/fastchg.h diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index f159fff09bf..37a0663f339 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -619,12 +619,20 @@ config QCOM_LIQUID_DOCK This option enables support for the USB and Ethernet ports found on the docking station of various models of Qualcomm Technology's LiQUID Mobile Development Platforms. + config UID_CPUTIME tristate "Per-UID cpu time statistics" depends on PROFILING help Per UID based cpu time statistics exported to /proc/uid_cputime +config FORCE_FAST_CHARGE + bool "Force faster charge rate for AC/USB" + default n + help + This allows users to override default charge rate for both USB and AC + charger input current + 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 a53a897faab..ca308006717 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -68,3 +68,4 @@ obj-$(CONFIG_QPNP_MISC) += qpnp-misc.o obj-$(CONFIG_QCOM_LIQUID_DOCK) += qcom_liquid_dock.o obj-y += qcom/ obj-$(CONFIG_UID_CPUTIME) += uid_cputime.o +obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o diff --git a/drivers/misc/fastchg.c b/drivers/misc/fastchg.c new file mode 100644 index 00000000000..f419b3dd0a9 --- /dev/null +++ b/drivers/misc/fastchg.c @@ -0,0 +1,104 @@ +/* + * Author: Chad Froebel + * + * Port to Nexus 5 : flar2 + * + * Port to Osprey : engstk + * + * 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 +#include +#include +#include + +int force_fast_charge = 1; + +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) +{ + if (buf[0] >= '0' && buf[0] <= '1' && buf[1] == '\n') + if (force_fast_charge != buf[0] - '0') + force_fast_charge = buf[0] - '0'; + + return count; +} + +static struct kobj_attribute force_fast_charge_attribute = +__ATTR(force_fast_charge, 0666, 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/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c index a66e94fc4d3..6f3a5d166c0 100644 --- a/drivers/usb/phy/phy-msm-usb.c +++ b/drivers/usb/phy/phy-msm-usb.c @@ -52,6 +52,10 @@ #include +#ifdef CONFIG_FORCE_FAST_CHARGE +#include +#endif + #define MSM_USB_BASE (motg->regs) #define MSM_USB_PHY_CSR_BASE (motg->phy_csr_regs) @@ -1972,6 +1976,15 @@ static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA) if (motg->cur_power == mA) return; +#ifdef CONFIG_FORCE_FAST_CHARGE + if (force_fast_charge > 0 && mA > 0) { + mA = IDEV_ACA_CHG_MAX; + pr_info("USB fast charging is ON\n"); + } else { + pr_info("USB fast charging is OFF\n"); + } +#endif + dev_info(motg->phy.dev, "Avail curr from USB = %u\n", mA); msm_otg_dbg_log_event(&motg->phy, "AVAIL CURR FROM USB", mA, motg->chg_type); diff --git a/include/linux/fastchg.h b/include/linux/fastchg.h new file mode 100644 index 00000000000..d3bdcdaccec --- /dev/null +++ b/include/linux/fastchg.h @@ -0,0 +1,22 @@ +/* + * Author: Chad Froebel + * + * Port to Osprey : engstk + * + * 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