-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfastusb.patch
More file actions
314 lines (290 loc) · 9.23 KB
/
fastusb.patch
File metadata and controls
314 lines (290 loc) · 9.23 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
*** drivers/i2c/chips/smb329.c 2011-08-19 20:19:19.396195576 -0400
--- ../Chad0989-android_kernel_common-a7c21fa/drivers/i2c/chips/smb329.c 2011-08-29 22:11:13.258040202 -0400
***************
*** 18,32 ****
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <mach/htc_battery.h>
#include <asm/mach-types.h>
static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
static int smb329_probe(struct i2c_client *client,
const struct i2c_device_id *id);
! /* static int smb329_detect(struct i2c_client *client, int kind,
! struct i2c_board_info *info); */
static int smb329_remove(struct i2c_client *client);
--- 18,41 ----
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
+ #include <linux/kobject.h>
+ #include <linux/sysfs.h>
#include <mach/htc_battery.h>
#include <asm/mach-types.h>
static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
+ int fast_charge_usb;
+
+ /**
+ * Insmod parameters
+ */
+ I2C_CLIENT_INSMOD_1(smb329);
+
static int smb329_probe(struct i2c_client *client,
const struct i2c_device_id *id);
! static int smb329_detect(struct i2c_client *client, int kind,
! struct i2c_board_info *info);
static int smb329_remove(struct i2c_client *client);
***************
*** 169,264 ****
{
int result = 0;
u8 version;
- u8 reg_00h;
- u8 reg_01h;
- u8 reg_05h;
- u8 reg_31h;
- u8 reg_33h;
- u8 reg_35h;
- u8 reg_36h;
- u8 reg_37h;
switch (ctl) {
case DISABLE:
! pr_info("batt: Switch charger OFF\n");
! smb329_i2c_read_byte(®_00h, 0x00);
! smb329_i2c_read_byte(®_01h, 0x01);
! smb329_i2c_read_byte(®_05h, 0x05);
! smb329_i2c_read_byte(®_31h, 0x31);
! smb329_i2c_read_byte(®_33h, 0x33);
! smb329_i2c_read_byte(®_35h, 0x35);
! smb329_i2c_read_byte(®_36h, 0x36);
! smb329_i2c_read_byte(®_37h, 0x37);
! pr_info("batt: Switch charger ON (SLOW):"
! " reg_05h=%x, reg_31h=%x\n", reg_05h, reg_31h);
! pr_info("batt: Switch charger ON (SLOW) DEBUG:"
! " reg_00h=%x, reg_01h=%x, reg_33h=%x\n"
! , reg_00h, reg_01h, reg_33h);
! pr_info("batt: Switch charger ON (SLOW) DEBUG:"
! " reg_35h=%x, reg_36h=%x, reg_37h=%x\n"
! , reg_35h, reg_36h, reg_37h);
break;
case ENABLE_SLOW_CHG:
! pr_info("Switch charger ON (SLOW)\n");
! smb329_i2c_write_byte(0x88, 0x31);
! smb329_i2c_read_byte(®_31h, 0x31);
! smb329_i2c_write_byte(0xD0, 0x01);
! smb329_i2c_write_byte(0x08, 0x05);
! smb329_i2c_read_byte(®_05h, 0x05);
! smb329_i2c_read_byte(®_00h, 0x00);
! smb329_i2c_read_byte(®_01h, 0x01);
! smb329_i2c_read_byte(®_35h, 0x35);
! smb329_i2c_read_byte(®_36h, 0x36);
! smb329_i2c_read_byte(®_37h, 0x37);
! pr_info("batt: Switch charger ON (SLOW):"
! " reg_05h=%x, reg_31h=%x\n", reg_05h, reg_31h);
! pr_info("batt: Switch charger ON (SLOW) DEBUG:"
! " reg_00h=%x, reg_01h=%x\n", reg_00h, reg_01h);
! pr_info("batt: Switch charger ON (SLOW) DEBUG:"
! " reg_35h=%x, reg_36h=%x, reg_37h=%x\n"
! , reg_35h, reg_36h, reg_37h);
break;
case ENABLE_FAST_CHG:
pr_info("Switch charger ON (FAST)\n");
smb329_i2c_write_byte(0x84, 0x31);
- smb329_i2c_read_byte(®_31h, 0x31);
smb329_i2c_write_byte(0xD0, 0x01);
smb329_i2c_write_byte(0x08, 0x05);
- smb329_i2c_write_byte(0xA9, 0x00);
- smb329_i2c_read_byte(®_05h, 0x05);
smb329_i2c_read_byte(&version, 0x3B);
! smb329_i2c_read_byte(®_00h, 0x00);
! smb329_i2c_read_byte(®_01h, 0x01);
! smb329_i2c_read_byte(®_35h, 0x35);
! smb329_i2c_read_byte(®_36h, 0x36);
! smb329_i2c_read_byte(®_37h, 0x37);
! pr_info("batt: Switch charger ON (FAST):"
! " reg_05h=%x, reg_31h=%x, version=%x\n"
! , reg_05h, reg_31h, version);
! pr_info("batt: Switch charger ON (FAST) DEBUG:"
! " reg_00h=%x, reg_01h=%x\n", reg_00h, reg_01h);
! pr_info("batt: Switch charger ON (FAST) DEBUG:"
! " reg_35h=%x, reg_36h=%x, reg_37h=%x\n"
! , reg_35h, reg_36h, reg_37h);
! break;
! case CHARGER_CHK:
! pr_info("batt: Switch charger CHECK\n");
! smb329_i2c_read_byte(®_00h, 0x00);
! smb329_i2c_read_byte(®_01h, 0x01);
! smb329_i2c_read_byte(®_05h, 0x05);
! smb329_i2c_read_byte(®_31h, 0x31);
! smb329_i2c_read_byte(®_33h, 0x33);
! smb329_i2c_read_byte(®_35h, 0x35);
! smb329_i2c_read_byte(®_36h, 0x36);
! smb329_i2c_read_byte(®_37h, 0x37);
! pr_info("batt: Switch charger ON (SLOW):"
! " reg_05h=%x, reg_31h=%x\n", reg_05h, reg_31h);
! pr_info("batt: Switch charger ON (SLOW) DEBUG:"
! " reg_00h=%x, reg_01h=%x, reg_33h=%x\n"
! , reg_00h, reg_01h, reg_33h);
! pr_info("batt: Switch charger ON (SLOW) DEBUG:"
! " reg_35h=%x, reg_36h=%x, reg_37h=%x\n"
! , reg_35h, reg_36h, reg_37h);
break;
default:
pr_info("%s: Not supported battery ctr called.!", __func__);
--- 178,215 ----
{
int result = 0;
u8 version;
switch (ctl) {
case DISABLE:
! pr_info("Switch charger OFF\n");
break;
case ENABLE_SLOW_CHG:
! if (fast_charge_usb == 0) {
! pr_info("Switch charger ON (SLOW)\n");
! smb329_i2c_write_byte(0x88, 0x31);
! smb329_i2c_write_byte(0x08, 0x05);
! }
! else {
! pr_info("Switch charger ON (FAST)\n");
! printk(KERN_INFO "fast charge enabled\n");
! smb329_i2c_write_byte(0x84, 0x31);
! smb329_i2c_write_byte(0xD0, 0x01);
! smb329_i2c_write_byte(0x08, 0x05);
! smb329_i2c_read_byte(&version, 0x3B);
! pr_info("Switch charger version%x\n", version);
! if ((version & 0x18) == 0x0)
! smb329_i2c_write_byte(0xA9, 0x00);
! }
break;
case ENABLE_FAST_CHG:
pr_info("Switch charger ON (FAST)\n");
smb329_i2c_write_byte(0x84, 0x31);
smb329_i2c_write_byte(0xD0, 0x01);
smb329_i2c_write_byte(0x08, 0x05);
smb329_i2c_read_byte(&version, 0x3B);
! pr_info("Switch charger version%x\n", version);
! if ((version & 0x18) == 0x0)
! smb329_i2c_write_byte(0xA9, 0x00);
break;
default:
pr_info("%s: Not supported battery ctr called.!", __func__);
***************
*** 283,289 ****
.notifier_call = cable_status_handler_func,
};
- #if 0
static int smb329_detect(struct i2c_client *client, int kind,
struct i2c_board_info *info)
{
--- 234,239 ----
***************
*** 296,314 ****
return 0;
}
- #endif
static int smb329_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct smb329_i2c_client *data = &smb329_i2c_module;
! if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
dev_dbg(&client->dev, "[SMB329]:I2C fail\n");
return -EIO;
! }
! if (machine_is_incrediblec() || (machine_is_supersonic()
! && (system_rev < 1)))
register_notifier_cable_status(&cable_status_handler);
data->address = client->addr;
--- 246,262 ----
return 0;
}
static int smb329_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct smb329_i2c_client *data = &smb329_i2c_module;
! if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
dev_dbg(&client->dev, "[SMB329]:I2C fail\n");
return -EIO;
! }
! if (machine_is_incrediblec())
register_notifier_cable_status(&cable_status_handler);
data->address = client->addr;
***************
*** 321,326 ****
--- 269,275 ----
static int smb329_remove(struct i2c_client *client)
{
struct smb329_i2c_client *data = i2c_get_clientdata(client);
+ int idx;
if (data->client && data->client != client)
i2c_unregister_device(data->client);
smb329_i2c_module.client = NULL;
***************
*** 337,346 ****
--- 286,338 ----
.remove = smb329_remove,
};
+ /* sysfs interface */
+ static ssize_t fast_charge_usb_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+ {
+ return sprintf(buf, "%d\n", fast_charge_usb);
+ }
+
+ static ssize_t fast_charge_usb_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count)
+ {
+ sscanf(buf, "%du", &fast_charge_usb);
+ return count;
+ }
+
+
+ static struct kobj_attribute fast_charge_usb_attribute =
+ __ATTR(fast_charge_usb, 0666, fast_charge_usb_show, fast_charge_usb_store);
+
+ static struct attribute *attrs[] = {
+ &fast_charge_usb_attribute.attr,
+ NULL,
+ };
+
+ static struct attribute_group attr_group = {
+ .attrs = attrs,
+ };
+
+ static struct kobject *fast_charge_usb_kobj;
+
+ int fast_charge_usb_init(void)
+ {
+ int retval;
+
+ fast_charge_usb_kobj = kobject_create_and_add("fast_charge", kernel_kobj);
+ if (!fast_charge_usb_kobj) {
+ return -ENOMEM;
+ }
+ retval = sysfs_create_group(fast_charge_usb_kobj, &attr_group);
+ if (retval)
+ kobject_put(fast_charge_usb_kobj);
+ return retval;
+ }
+
static int __init sensors_smb329_init(void)
{
int res;
+ fast_charge_usb = 0;
+
res = i2c_add_driver(&smb329_driver);
if (res) {
pr_info("[SMB329]: Driver registration failed \n");
***************
*** 351,356 ****
--- 343,349 ----
static void __exit sensors_smb329_exit(void)
{
+ kobject_put(fast_charge_usb_kobj);
i2c_del_driver(&smb329_driver);
}
***************
*** 359,362 ****
--- 352,356 ----
MODULE_LICENSE("GPL");
module_init(sensors_smb329_init);
+ module_init(fast_charge_usb_init);
module_exit(sensors_smb329_exit);