-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: misc: Implement USB fast charge mode
Signed-off-by: engstk <[email protected]> Signed-off-by: Adithya R <[email protected]>
- Loading branch information
1 parent
d500d87
commit 7d737fa
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |