Skip to content

Commit

Permalink
drivers: misc: Implement USB fast charge mode
Browse files Browse the repository at this point in the history
Signed-off-by: engstk <[email protected]>
Signed-off-by: Adithya R <[email protected]>
  • Loading branch information
engstk authored and adithya2306 committed Nov 7, 2018
1 parent d500d87 commit 7d737fa
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/misc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions drivers/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
104 changes: 104 additions & 0 deletions drivers/misc/fastchg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Author: Chad Froebel <[email protected]>
*
* Port to Nexus 5 : flar2 <[email protected]>
*
* Port to Osprey : engstk <[email protected]>
*
* 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 = 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);
13 changes: 13 additions & 0 deletions drivers/usb/phy/phy-msm-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@

#include <linux/msm-bus.h>

#ifdef CONFIG_FORCE_FAST_CHARGE
#include <linux/fastchg.h>
#endif

#define MSM_USB_BASE (motg->regs)
#define MSM_USB_PHY_CSR_BASE (motg->phy_csr_regs)

Expand Down Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions include/linux/fastchg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Author: Chad Froebel <[email protected]>
*
* Port to Osprey : engstk <[email protected]>
*
* 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

0 comments on commit 7d737fa

Please sign in to comment.