BC1.2 Devices (Experimental)

The Battery Charging specification, currently at revision 1.2, is commonly referred to as just BC1.2. BC1.2 defines limits and detection mechanisms for USB devices to draw current exceeding the USB 2.0 specification limit of 0.5A, 2.5W.

The BC1.2 specification uses the term Charging Port for the device that supplies VBUS on the USB connection and the term Portable Device for the device that sinks current from the USB connection.

Note that the BC1.2 Specification uses the acronym PD for Portable Device. This should not be confused with the USB-C Power Delivery, which also uses the acronym PD.

On many devices, BC1.2 is the fallback mechanism to determine the connected charger capability on USB type C ports when the attached type-C partner does not support Power Delivery.

Key parameters from the BC1.2 Specification include:

Parameter

Symbol

Range

Allowed PD (portable device) Current Draw from Charging Port

IDEV_CHG

1.5 A

Charging Downstream Port Rated Current

ICDP

1.5 - 5.0 A

Maximum Configured Current when connected to a SDP

ICFG_MAX

500 mA

Dedicated Charging Port Rated Current

IDCP

1.5 - 5.0 A

Suspend current

ISUSP

2.5 mA

Unit load current

IUNIT

100 mA

While the ICDP and IDCP rated currents go up to 5.0 A, the BC1.2 current is limited by the IDEV_CHG parameter. So the BC1.2 support is capped at 1.5 A in the Zephyr implementation when using portable-device mode.

Basic Operation

The BC1.2 device driver provides only two APIs, bc12_set_role() and bc12_set_result_cb().

The application calls bc12_set_role() to transition the BC1.2 device to either a disconnected, portable-device, or charging port mode.

For the disconnected state, the BC1.2 driver powers down the detection chip. The power down operation is vendor specific.

The application calls bc12_set_role() with the type set to BC12_PORTABLE_DEVICE when both the following conditions are true:

  • The application configured the port as an upstream facing port, i.e. a USB device port.

  • The application detects VBUS on the USB connection.

For portable-device mode, the BC1.2 driver powers up the detection chip and starts charger detection. At completion of the charger detection, the BC1.2 driver notifies the callback registered with bc12_set_result_cb(). By default, the BC1.2 driver clamps the current to 1.5A to comply with the BC1.2 specification.

To comply with the USB 2.0 specification, when the driver detects a SDP (Standard Downstream Port) charging partner or if BC1.2 detection fails, the driver reports the available current as ISUSP (2.5 mA). The application may increase the current draw to IUNIT (100 mA) when the connected USB host resumes the USB bus and may increase the current draw to ICFG_MAX (500 mA) when the USB host configures the USB device.

Charging port mode is used by the application when the USB port is configured as a downstream facing port, i.e. a USB host port. For charging port mode, the BC1.2 driver powers up the detection chip and configures the charger type specified by a devicetree property. If the driver supports detection of plug and unplug events, the BC1.2 driver notifies the callback registered with bc12_set_result_cb() to indicate the current connection state of the portable device partner.

Configuration Options

Related configuration options:

API Reference

group b12_interface

BC1.2 driver APIs.

BC1.2 constants

BC12_CHARGER_VOLTAGE_UV

BC1.2 USB charger voltage.

BC12_CHARGER_MIN_CURR_UA

BC1.2 USB charger minimum current.

Set to match the Isusp of 2.5 mA parameter. This is returned by the driver when either BC1.2 detection fails, or the attached partner is a SDP (standard downstream port).

The application may increase the current draw after determining the USB device state of suspended/unconfigured/configured. Suspended: 2.5 mA Unconfigured: 100 mA Configured: 500 mA (USB 2.0)

BC12_CHARGER_MAX_CURR_UA

BC1.2 USB charger maximum current.

Typedefs

typedef void (*bc12_callback_t)(const struct device *dev, struct bc12_partner_state *state, void *user_data)

BC1.2 callback for charger configuration.

Param dev:

BC1.2 device which is notifying of the new charger state.

Param state:

Current state of the BC1.2 client, including BC1.2 type detected, voltage, and current limits. If NULL, then the partner charger is disconnected or the BC1.2 device is operating in host mode.

Param user_data:

Requester supplied data which is passed along to the callback.

Enums

enum bc12_role

BC1.2 device role.

Values:

enumerator BC12_DISCONNECTED
enumerator BC12_PORTABLE_DEVICE
enumerator BC12_CHARGING_PORT
enum bc12_type

BC1.2 charging partner type.

Values:

enumerator BC12_TYPE_NONE

No partner connected.

enumerator BC12_TYPE_SDP

Standard Downstream Port.

enumerator BC12_TYPE_DCP

Dedicated Charging Port.

enumerator BC12_TYPE_CDP

Charging Downstream Port.

enumerator BC12_TYPE_PROPRIETARY

Proprietary charging port.

enumerator BC12_TYPE_UNKNOWN

Unknown charging port, BC1.2 detection failed.

enumerator BC12_TYPE_COUNT

Count of valid BC12 types.

Functions

int bc12_set_role(const struct device *dev, enum bc12_role role)

Set the BC1.2 role.

Parameters:
  • dev – Pointer to the device structure for the BC1.2 driver instance.

  • role – New role for the BC1.2 device.

Return values:
  • 0 – If successful.

  • -EIO – general input/output error.

int bc12_set_result_cb(const struct device *dev, bc12_callback_t cb, void *user_data)

Register a callback for BC1.2 results.

Parameters:
  • dev – Pointer to the device structure for the BC1.2 driver instance.

  • cb – Function pointer for the result callback.

  • user_data – Requester supplied data which is passed along to the callback.

Return values:
  • 0 – If successful.

  • -EIO – general input/output error.

struct bc12_partner_state
#include <usb_bc12.h>

BC1.2 detected partner state.

Param bc12_role:

Current role of the BC1.2 device.

Param type:

Charging partner type. Valid when bc12_role is BC12_PORTABLE_DEVICE.

Param current_ma:

Current, in uA, that the charging partner provides. Valid when bc12_role is BC12_PORTABLE_DEVICE.

Param voltage_mv:

Voltage, in uV, that the charging partner provides. Valid when bc12_role is BC12_PORTABLE_DEVICE.

Param pd_partner_connected:

True if a PD partner is currently connected. Valid when bc12_role is BC12_CHARGING_PORT.

group b12_emulator_backend

BC1.2 backend emulator APIs.

Functions

static inline int bc12_emul_set_charging_partner(const struct emul *target, enum bc12_type partner_type)

Set the charging partner type connected to the BC1.2 device.

The corresponding BC1.2 emulator updates the vendor specific registers to simulate connection of the specified charging partner type. The emulator also generates an interrupt for processing by the real driver, if supported.

Parameters:
  • target – Pointer to the emulator structure for the BC1.2 emulator instance.

  • partner_type – The simulated partner type. Set to BC12_TYPE_NONE to disconnect the charging partner.

Return values:
  • 0 – If successful.

  • -EINVAL – if the partner type is not supported.

static inline int bc12_emul_set_pd_partner(const struct emul *target, bool connected)

Set the portable device partner state.

The corresponding BC1.2 emulator updates the vendor specific registers to simulate connection or disconnection of a portable device partner. The emulator also generates an interrupt for processing by the real driver, if supported.

Parameters:
  • target – Pointer to the emulator structure for the BC1.2 emulator instance.

  • connected – If true, emulate a connection of a portable device partner. If false, emulate a disconnect event.

Return values:
  • 0 – If successful.

  • -EINVAL – if the connection/disconnection of PD partner is not supported.