Skip to content
Browse files

Simple interface to allow and enable fast charging when phone

is detected as connected to USB.
  • Loading branch information...
1 parent d75940d commit a7c21fa0391c225900f93960362535179c0cecc9 @Chad0989 committed
Showing with 65 additions and 3 deletions.
  1. +65 −3 arch/arm/mach-msm/smb329.c
View
68 arch/arm/mach-msm/smb329.c
@@ -18,11 +18,15 @@
#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
*/
@@ -180,9 +184,22 @@ int set_charger_ctrl(u32 ctl)
pr_info("Switch charger OFF\n");
break;
case ENABLE_SLOW_CHG:
- pr_info("Switch charger ON (SLOW)\n");
- smb329_i2c_write_byte(0x88, 0x31);
- smb329_i2c_write_byte(0x08, 0x05);
+ 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");
@@ -269,10 +286,53 @@ static struct i2c_driver smb329_driver = {
.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");
@@ -283,6 +343,7 @@ static int __init sensors_smb329_init(void)
static void __exit sensors_smb329_exit(void)
{
+ kobject_put(fast_charge_usb_kobj);
i2c_del_driver(&smb329_driver);
}
@@ -291,4 +352,5 @@ MODULE_DESCRIPTION("smb329 driver");
MODULE_LICENSE("GPL");
module_init(sensors_smb329_init);
+module_init(fast_charge_usb_init);
module_exit(sensors_smb329_exit);

0 comments on commit a7c21fa

Please sign in to comment.
Something went wrong with that request. Please try again.