diff options
| author | motley <motley.slate@gmail.com> | 2012-12-23 09:37:36 -0500 |
|---|---|---|
| committer | audahadi <wan.audahadi@gmail.com> | 2015-07-20 04:49:08 +0800 |
| commit | 6534b5f08a17485f38b26381e490e0a6526ca7e9 (patch) | |
| tree | 12e61e2e6bcf109b62b553e79bdd8b77806d3331 | |
| parent | b207325261e26b611cb0a1c0c9be07934e27f9dc (diff) | |
USB force fast charging
-Use base from Chad Froebel <chadfroebel@gmail.com> so we continue to
use the same generic sysfs mechanism
-Referenced franco's git for drivers/usb/otg/msm_otg.c changes
https://github.com/franciscofranco/mako/commit/5a8a4c8e23c7e1df39c740b9ce1d5dda20b0ede3
Off by default
Turn on:
echo 1 > /sys/kernel/fast_charge/force_fast_charge
Turn off:
echo 0 > /sys/kernel/fast_charge/force_fast_charge
Initial Port to Cancro:
Change-Id: Id8862493cb4afeb73d200dc605f557668ec4eb5c
Signed-off-by: Jean Francis Dominique S. Mabalot <jmabalot@google.com>
| -rw-r--r-- | arch/arm/mach-msm/Kconfig | 7 | ||||
| -rw-r--r-- | arch/arm/mach-msm/Makefile | 1 | ||||
| -rw-r--r-- | arch/arm/mach-msm/fastchg.c | 95 | ||||
| -rw-r--r-- | drivers/usb/otg/msm_otg.c | 14 | ||||
| -rw-r--r-- | include/linux/fastchg.h | 23 |
5 files changed, 139 insertions, 1 deletions
diff --git a/arch/arm/mach-msm/Kconfig b/arch/arm/mach-msm/Kconfig index 50dab3c303f..5444b9cbb2c 100644 --- a/arch/arm/mach-msm/Kconfig +++ b/arch/arm/mach-msm/Kconfig @@ -3057,6 +3057,13 @@ config HAS_MACH_MEMUTILS help Faster memcpy performance for Krait +config FORCE_FAST_CHARGE + bool "Force AC charge mode at will" + default y + help + A simple sysfs interface to force adapters that + are detected as USB to charge as AC. + endif config KERNEL_TEXT_MPU_PROT diff --git a/arch/arm/mach-msm/Makefile b/arch/arm/mach-msm/Makefile index 2b6cfe4fa47..7b253e6df4c 100644 --- a/arch/arm/mach-msm/Makefile +++ b/arch/arm/mach-msm/Makefile @@ -419,3 +419,4 @@ obj-$(CONFIG_WALL_CLK_SYSFS) += wallclk_sysfs.o obj-$(CONFIG_HAS_MACH_MEMUTILS) += memutils/ obj-$(CONFIG_ARCH_RANDOM) += early_random.o obj-$(CONFIG_PERFMAP) += perfmap.o +obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o diff --git a/arch/arm/mach-msm/fastchg.c b/arch/arm/mach-msm/fastchg.c new file mode 100644 index 00000000000..9da2cabd581 --- /dev/null +++ b/arch/arm/mach-msm/fastchg.c @@ -0,0 +1,95 @@ +/* + * Author: Chad Froebel <chadfroebel@gmail.com> + * + * Simple port to Nexus 4 : motley <motley.slate@gmail.com> + * + * 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 - substitute AC to USB unconditional +*/ + +#include <linux/kobject.h> +#include <linux/sysfs.h> +#include <linux/fastchg.h> + +int force_fast_charge; + +/* sysfs interface for "force_fast_charge" */ +static ssize_t force_fast_charge_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ +return sprintf(buf, "%d\n", force_fast_charge); +} + +static ssize_t force_fast_charge_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) +{ + +int new_force_fast_charge; + +sscanf(buf, "%du", &new_force_fast_charge); + +if (new_force_fast_charge >= FAST_CHARGE_DISABLED && new_force_fast_charge <= FAST_CHARGE_FORCE_AC) { + /* update only if valid value provided */ + force_fast_charge = new_force_fast_charge; +} + +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 = FAST_CHARGE_DISABLED; /* Forced fast charge disabled by default */ + + 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/otg/msm_otg.c b/drivers/usb/otg/msm_otg.c index f4e7ea44df5..b953e8c1963 100644 --- a/drivers/usb/otg/msm_otg.c +++ b/drivers/usb/otg/msm_otg.c @@ -50,6 +50,11 @@ #include <mach/msm_bus.h> #include <mach/rpm-regulator.h> +#ifdef CONFIG_FORCE_FAST_CHARGE +#include <linux/fastchg.h> +#define USB_FASTCHG_LOAD 1000 /* uA */ +#endif + #define MSM_USB_BASE (motg->regs) #define DRIVER_NAME "msm_otg" @@ -1421,7 +1426,14 @@ 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 == 1) { + mA = USB_FASTCHG_LOAD; + pr_info("USB fast charging is ON - 1000mA.\n"); + } else { + pr_info("USB fast charging is OFF.\n"); + } +#endif dev_info(motg->phy.dev, "Avail curr from USB = %u\n", mA); /* diff --git a/include/linux/fastchg.h b/include/linux/fastchg.h new file mode 100644 index 00000000000..0570e039e22 --- /dev/null +++ b/include/linux/fastchg.h @@ -0,0 +1,23 @@ +/* + * Author: Chad Froebel <chadfroebel@gmail.com> + * + * 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; + +#define FAST_CHARGE_DISABLED 0 /* default */ +#define FAST_CHARGE_FORCE_AC 1 + +#endif |
