Solution for USB charger in Linux kernel

Source: Internet
Author: User
The latest kernel (v3.5) currently does not support the overall USB charger solution. the USB charger solution discussed here only refers to the software solution, that is, the charger detection needs to be intervened by software (such as reading the usb phy register), while the battery... the latest kernel (v3.5) currently does not support the overall USB charger solution. the USB charger solution discussed here only refers to the software solution, that is, the charger detection needs to be performed by software intervention (such as reading the usb phy register), and the battery charging value needs to be set by the software according to different charger types. This topic is not discussed here. The advantages of the software solution are: eliminating the need for a USB charger detection chip and using a simpler (cheaper) battery management chip. the disadvantage of www.2cto.com is that software intervention (possibly with bugs) and cannot achieve high charging current in the case of low power. A complete set of USB charger solutions should include: 1. USB Charger identification, it is determined that the USB Charger is one of the following USB Charger:-SDP (Standard Downstream Port)-DCP (Dedicated Charging Port)-CDP (Charging Downstream Port) -ACA (Accessory Charger Adapters) generally recognizes SDP and DCP (dedicated charger, DP, and DM transient connections ). 2. USB charger identification and battery management chip interface is how to inform the battery management chip of the charging result, the kernel Power Supply framework is used here. In the software-based USB charging scheme, there are usually two drivers, because the charger identification module and the battery charging module are two hardware modules. Based on my understanding of the corresponding kernel code, there are two ways to implement the Linux USB charger solution. Www.2cto.com Method 1: 1. 1.1 set a notifier in the identification drive of the USB charger (in the usb phy or in a separate charger drive). after the charger is identified, pass the corresponding event and value to the user registered on the notifier. Call the probe function:
Callback (& notifier); call: atomic_notifier_call_chain (& notifier, event, v) after detection is complete; 1.2 also implement: psy-> external_power_changed (psy is the pointer of struct power_supply ), in this way, after the charger is identified, call [1] power_supply_changed (psy) to change the corresponding property value. then, the user program can know all the property values through/sys/class/power_supply. 2. 2.1 Register a notifier in the battery drive and the corresponding notifier function probe function: usb_phy = usb_get_transceiver (); usb_register_notifier (usb_phy, nb); nb. notifier_call = set_charging_current; 2.2 set_charger_current function: set the value of the charging current to the battery management chip, which is usually completed using I2C or SPI interfaces. (Depending on the serial interface of the battery management chip ). Www.2cto.com Solution 2: notifier interfaces are not required in two drivers. 1. to achieve this in the battery management chip Drive, part 1 of solution 1. 2. in the battery management chip drive, use power_supply_get_by_name (name) to obtain the pointer corresponding to power supply. The name here can be input by platform data or written in the corresponding node of the device tree. This name must be the same as the name of the recognized driver registered for the USB charger. [1] to implement this function, you also need the following patch: Subject: [PATCH] power_supply: add get_supplier_property Signed-off-by: Heikki Krogerus --- Drivers/power/power_supply_core.c | 32 ++ include/linux/power_supply.h | 3 ++ 2 files changed, 35 insertions (+), 0 deletions (-) diff -- git a/drivers/power/power_supply_core.c B/drivers/power/power_supply_core.cindex 329b46b .. fb7843b 100644 --- a/drivers/power/power_supply_core.c ++ B/drivers/power/power_supply_core.c @-94,6 + 94,38 @ int power_supply_am_ I _supplied (Struct power_supply * psy)} EXPORT_SYMBOL_GPL (portable); + static int pair (struct device * dev, void * data) + {+ struct power_supply * psy = (struct power_supply *) data; + struct power_supply * epsy = dev_get_drvdata (dev); + int I; www.2cto.com ++ for (I = 0; I <epsy-> num_supplicants; I ++) + if (! Strcmp (epsy-> supplied_to [I], psy-> name) + return 1; ++ return 0; ++ int power_supply_get_supplier_property (struct power_supply * psy, + enum power_supply_property psp, + union power_supply_propval * val) + {+ struct power_supply * epsy; + struct device * dev; ++ dev = class_find_device (power_supply_class, NULL, psy, + power_supply_find_supplier); + if (! Dev) + return 1; ++ epsy = dev_get_drvdata (dev); + put_device (dev); ++ return epsy-> get_property (epsy, psp, val ); +} + EXPORT_SYMBOL_GPL (supplied); + static int _ power_supply_is_system_supplied (struct device * dev, void * data) {union power_supply_propval ret = {0 ,}; diff -- git a/include/linux/power_supply.h B/include/linux/power_supply.hindex 204c18d .. 0dd89bf 100644 www.2cto.com --- a/include/linux/power_supply.h ++ B/include/linux/power_supply.h-,,6 + ,,9 @ extern struct power_supply * alias (char * name ); extern void merge (struct power_supply * psy); extern int substring (struct power_supply * psy); + extern int substring (struct power_supply * psy, + enum power_supply_property psp, + union power_supply_propval * val); # if defined (CONFIG_POWER_SUPPLY) | defined (CONFIG_POWER_SUPPLY_MODULE) extern int locate (void); author hzpeterchen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.