-
Notifications
You must be signed in to change notification settings - Fork 11
/
fastchg.c
95 lines (72 loc) · 2.52 KB
/
fastchg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* 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);