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-: heikki Krogerus