# SPDX-License-Identifier: GPL-2.0
%YAML 1.2
---
$id: http://devicetree.org/schemas/power/supply/charger-manager.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Charger Manager

maintainers:
  - Sebastian Reichel <sre@kernel.org>

description: |
  Binding for the legacy charger manager driver.
  Please do not use for new products.

properties:
  compatible:
    const: charger-manager

  cm-chargers:
    description: name of chargers
    $ref: /schemas/types.yaml#/definitions/string-array

  cm-num-chargers:
    $ref: /schemas/types.yaml#/definitions/uint32
    deprecated: true

  cm-fuel-gauge:
    description: name of battery fuel gauge
    $ref: /schemas/types.yaml#/definitions/string

  cm-name:
    description: name of the charger manager
    default: battery
    $ref: /schemas/types.yaml#/definitions/string

  cm-poll-mode:
    description: polling mode
    $ref: /schemas/types.yaml#/definitions/uint32
    default: 0
    enum:
      - 0 # disabled
      - 1 # always
      - 2 # when external power is connected
      - 3 # when charging

  cm-poll-interval:
    description: polling interval (in ms)
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-battery-stat:
    description: battery status
    $ref: /schemas/types.yaml#/definitions/uint32
    enum:
      - 0 # battery always present
      - 1 # no battery
      - 2 # check presence via fuel gauge
      - 3 # check presence via charger

  cm-fullbatt-vchkdrop-volt:
    description: voltage drop before restarting charging in uV
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-fullbatt-vchkdrop-ms:
    deprecated: true

  cm-fullbatt-voltage:
    description: voltage of full battery in uV
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-fullbatt-soc:
    description: state of charge to consider as full battery in %
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-fullbatt-capacity:
    description: capcity to consider as full battery in uAh
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-thermal-zone:
    description: name of external thermometer's thermal zone
    $ref: /schemas/types.yaml#/definitions/string

  cm-discharging-max:
    description: limits of discharging duration in ms
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-charging-max:
    description: limits of charging duration in ms
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-battery-cold:
    description: critical cold temperature of battery for charging in deci-degree celsius
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-battery-cold-in-minus:
    description: if set cm-battery-cold temperature is in minus degrees
    type: boolean

  cm-battery-hot:
    description: critical hot temperature of battery for charging in deci-degree celsius
    $ref: /schemas/types.yaml#/definitions/uint32

  cm-battery-temp-diff:
    description: temperature difference to allow recharging in deci-degree celsius
    $ref: /schemas/types.yaml#/definitions/uint32

patternProperties:
  "-supply$":
    description: regulator consumer, named according to cm-regulator-name
    $ref: /schemas/types.yaml#/definitions/phandle

  "^regulator[@-][0-9]$":
    type: object
    properties:
      cm-regulator-name:
        description: name of charger regulator
        $ref: /schemas/types.yaml#/definitions/string

    required:
      - cm-regulator-name

    additionalProperties: false

    patternProperties:
      "^cable[@-][0-9]$":
        type: object
        properties:
          cm-cable-name:
            description: name of charger cable
            enum:
              - USB
              - USB-HOST
              - SDP
              - DCP
              - CDP
              - ACA
              - FAST-CHARGER
              - SLOW-CHARGER
              - WPT
              - PD
              - DOCK
              - JIG
              - MECHANICAL

          cm-cable-extcon:
            description: name of extcon dev
            $ref: /schemas/types.yaml#/definitions/string

          cm-cable-min:
            description: minimum current of cable in uA
            $ref: /schemas/types.yaml#/definitions/uint32

          cm-cable-max:
            description: maximum current of cable in uA
            $ref: /schemas/types.yaml#/definitions/uint32

        required:
          - cm-cable-name
          - cm-cable-extcon

        additionalProperties: false

required:
  - compatible
  - cm-chargers
  - cm-fuel-gauge

additionalProperties: false

examples:
  - |
    charger-manager {
        compatible = "charger-manager";
        chg-reg-supply = <&charger_regulator>;

        cm-name = "battery";
        /* Always polling ON : 30s */
        cm-poll-mode = <1>;
        cm-poll-interval = <30000>;

        cm-fullbatt-vchkdrop-volt = <150000>;
        cm-fullbatt-soc = <100>;

        cm-battery-stat = <3>;

        cm-chargers = "charger0", "charger1", "charger2";

        cm-fuel-gauge = "fuelgauge0";

        cm-thermal-zone = "thermal_zone.1";
        /* in deci centigrade */
        cm-battery-cold = <50>;
        cm-battery-cold-in-minus;
        cm-battery-hot = <800>;
        cm-battery-temp-diff = <100>;

        /* Allow charging for 5hr */
        cm-charging-max = <18000000>;
        /* Allow discharging for 2hr */
        cm-discharging-max = <7200000>;

        regulator-0 {
            cm-regulator-name = "chg-reg";
            cable-0 {
                cm-cable-name = "USB";
                cm-cable-extcon = "extcon-dev.0";
                cm-cable-min = <475000>;
                cm-cable-max = <500000>;
            };
            cable-1 {
                cm-cable-name = "SDP";
                cm-cable-extcon = "extcon-dev.0";
                cm-cable-min = <650000>;
                cm-cable-max = <675000>;
            };
        };
    };