Skip to content

Commit

Permalink
Force AC (Fast) Charging
Browse files Browse the repository at this point in the history
Change-Id: I9096f16895b54906e591f6b6eb80629a94370e72
  • Loading branch information
ekerazha committed Sep 22, 2014
1 parent 737c1a9 commit efa79e8
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 30 deletions.
8 changes: 8 additions & 0 deletions arch/arm/mach-s5pv210/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,12 @@ config WIFI_CONTROL_FUNC
bool "Enable WiFi control function abstraction"
help
Enables Power/Reset/Carddetect function abstraction

config FORCE_FAST_CHARGE
bool "Force AC charge mode at will"
default y
help
A simple sysfs interface to force adapters that
are detected as USB to charge as AC.

endif
2 changes: 2 additions & 0 deletions arch/arm/mach-s5pv210/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ obj-$(CONFIG_MACH_HERRING) += herring-touchkey-led.o

obj-$(CONFIG_MACH_HERRING) += dev-herring-phone.o

obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o

# device support

obj-y += dev-audio.o
Expand Down
70 changes: 70 additions & 0 deletions arch/arm/mach-s5pv210/fastchg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Author: Chad Froebel <[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.
*
*/

#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/fastchg.h>

int force_fast_charge;

/* sysfs interface */
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)
{
sscanf(buf, "%du", &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 *attrs[] = {
&force_fast_charge_attribute.attr,
NULL,
};

static struct attribute_group attr_group = {
.attrs = attrs,
};

static struct kobject *force_fast_charge_kobj;

int force_fast_charge_init(void)
{
int retval;

force_fast_charge = 0;

force_fast_charge_kobj = kobject_create_and_add("fast_charge", kernel_kobj);
if (!force_fast_charge_kobj) {
return -ENOMEM;
}
retval = sysfs_create_group(force_fast_charge_kobj, &attr_group);
if (retval)
kobject_put(force_fast_charge_kobj);
return retval;
}
/* end sysfs interface */

void force_fast_charge_exit(void)
{
kobject_put(force_fast_charge_kobj);
}

module_init(force_fast_charge_init);
module_exit(force_fast_charge_exit);
80 changes: 50 additions & 30 deletions arch/arm/mach-s5pv210/mach-herring.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <linux/skbuff.h>
#include <linux/console.h>
#include <linux/earlysuspend.h>
#ifdef CONFIG_FORCE_FAST_CHARGE
#include <linux/fastchg.h>
#endif

#include <asm/mach/arch.h>
#include <asm/mach/map.h>
Expand Down Expand Up @@ -2946,27 +2949,36 @@ static void k3g_irq_init(void)
}


static void fsa9480_usb_cb(bool attached)
static void fsa9480_charger_cb(bool attached)
{
struct usb_gadget *gadget = platform_get_drvdata(&s3c_device_usbgadget);

if (gadget) {
if (attached)
usb_gadget_vbus_connect(gadget);
else
usb_gadget_vbus_disconnect(gadget);
}

set_cable_status = attached ? CABLE_TYPE_USB : CABLE_TYPE_NONE;
if (callbacks && callbacks->set_cable)
callbacks->set_cable(callbacks, set_cable_status);
set_cable_status = attached ? CABLE_TYPE_AC : CABLE_TYPE_NONE;
if (callbacks && callbacks->set_cable)
callbacks->set_cable(callbacks, set_cable_status);
}

static void fsa9480_charger_cb(bool attached)

static void fsa9480_usb_cb(bool attached)
{
set_cable_status = attached ? CABLE_TYPE_AC : CABLE_TYPE_NONE;
if (callbacks && callbacks->set_cable)
callbacks->set_cable(callbacks, set_cable_status);
#ifdef CONFIG_FORCE_FAST_CHARGE
if (force_fast_charge != 0) {
fsa9480_charger_cb(attached);
} else {
#endif
struct usb_gadget *gadget = platform_get_drvdata(&s3c_device_usbgadget);

if (gadget) {
if (attached)
usb_gadget_vbus_connect(gadget);
else
usb_gadget_vbus_disconnect(gadget);
}

set_cable_status = attached ? CABLE_TYPE_USB : CABLE_TYPE_NONE;
if (callbacks && callbacks->set_cable)
callbacks->set_cable(callbacks, set_cable_status);
#ifdef CONFIG_FORCE_FAST_CHARGE
}
#endif
}

static struct switch_dev switch_dock = {
Expand All @@ -2975,23 +2987,31 @@ static struct switch_dev switch_dock = {

static void fsa9480_deskdock_cb(bool attached)
{
struct usb_gadget *gadget = platform_get_drvdata(&s3c_device_usbgadget);

if (attached)
switch_set_state(&switch_dock, 1);
else
switch_set_state(&switch_dock, 0);
#ifdef CONFIG_FORCE_FAST_CHARGE
if (force_fast_charge != 0) {
fsa9480_charger_cb(attached);
} else {
#endif
struct usb_gadget *gadget = platform_get_drvdata(&s3c_device_usbgadget);

if (gadget) {
if (attached)
usb_gadget_vbus_connect(gadget);
switch_set_state(&switch_dock, 1);
else
usb_gadget_vbus_disconnect(gadget);
}
switch_set_state(&switch_dock, 0);

set_cable_status = attached ? CABLE_TYPE_USB : CABLE_TYPE_NONE;
if (callbacks && callbacks->set_cable)
callbacks->set_cable(callbacks, set_cable_status);
if (gadget) {
if (attached)
usb_gadget_vbus_connect(gadget);
else
usb_gadget_vbus_disconnect(gadget);
}

set_cable_status = attached ? CABLE_TYPE_USB : CABLE_TYPE_NONE;
if (callbacks && callbacks->set_cable)
callbacks->set_cable(callbacks, set_cable_status);
#ifdef CONFIG_FORCE_FAST_CHARGE
}
#endif
}

static void fsa9480_cardock_cb(bool attached)
Expand Down
21 changes: 21 additions & 0 deletions include/linux/fastchg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Author: Chad Froebel <[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 efa79e8

Please sign in to comment.