From d56fc714acc5edd06974988d6e63c900804f4e88 Mon Sep 17 00:00:00 2001 From: Rong Dian Date: Thu, 21 Jun 2012 14:26:45 +0800 Subject: [PATCH] ENGR00214367-2 imx6 usb charger: bind usb charger with power supply Bind usb charger with power supply, and print some attributes about usb charger. Signed-off-by: Rong Dian --- drivers/usb/gadget/imx_usb_charger.c | 24 ++++++++++++++++++++++++ drivers/usb/gadget/imx_usb_charger.h | 3 +-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/imx_usb_charger.c b/drivers/usb/gadget/imx_usb_charger.c index e1020421adb8..33242a7ab4d8 100644 --- a/drivers/usb/gadget/imx_usb_charger.c +++ b/drivers/usb/gadget/imx_usb_charger.c @@ -13,6 +13,29 @@ * NOTICE: Currently, it only supports i.mx6q usb charger detect */ +static void my_batt_ext_power_changed(struct power_supply *psy) +{ + int mA; + union power_supply_propval ret = {0,}; + printk(KERN_INFO "my_batt_ext_power_changed!\n"); + if (!power_supply_am_i_supplied(psy)) { + /* stop charging */ + printk(KERN_ERR "It is not usb supply!\n"); + return; + } + power_supply_get_supplier_property(psy, + POWER_SUPPLY_PROP_ONLINE, &ret); + + printk(KERN_INFO "imx6 usb charger online:%d\n", ret.intval); + + power_supply_get_supplier_property(psy, + POWER_SUPPLY_PROP_CURRENT_MAX, &ret); + /* maximum milliamps we are allowed to draw from VBUS */ + mA = ret.intval; + printk(KERN_INFO "imx6 usb charger limit mA: %d\n", mA); +} + + static int usb_charger_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -216,6 +239,7 @@ int imx_usb_create_charger(struct usb_charger *charger, psy->supplied_to = usb_charger_supplied_to; psy->num_supplicants = sizeof(usb_charger_supplied_to)/sizeof(char *); + psy->external_power_changed = my_batt_ext_power_changed; ret = power_supply_register(charger->dev, psy); if (ret) diff --git a/drivers/usb/gadget/imx_usb_charger.h b/drivers/usb/gadget/imx_usb_charger.h index 5417743a5118..b3beb0fe58d7 100644 --- a/drivers/usb/gadget/imx_usb_charger.h +++ b/drivers/usb/gadget/imx_usb_charger.h @@ -160,7 +160,6 @@ struct usb_charger { struct device *dev; /* udc supplies */ /* charger detect can be enabled/disabled by kernel config */ bool enable; - struct power_supply psy; struct work_struct work; struct mutex lock; @@ -182,7 +181,7 @@ struct usb_charger { }; static char *usb_charger_supplied_to[] = { - "main-battery", + "imx_usb_charger", }; static enum power_supply_property power_props[] = { -- 2.39.5