diff options
-rw-r--r-- | zephyr/dts/bindings/usbc/named-usbc-port.yaml | 5 | ||||
-rw-r--r-- | zephyr/shim/include/charger_chips.h | 32 | ||||
-rw-r--r-- | zephyr/shim/src/charger.c | 9 |
3 files changed, 46 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/usbc/named-usbc-port.yaml b/zephyr/dts/bindings/usbc/named-usbc-port.yaml index 074d2e972d..7717a2e4d3 100644 --- a/zephyr/dts/bindings/usbc/named-usbc-port.yaml +++ b/zephyr/dts/bindings/usbc/named-usbc-port.yaml @@ -24,6 +24,11 @@ properties: required: false description: | Charger chip for the USB-C port. + chg_alt: + type: phandle + required: false + description: | + Alternative charger for the USB-C port. ppc: type: phandle required: false diff --git a/zephyr/shim/include/charger_chips.h b/zephyr/shim/include/charger_chips.h new file mode 100644 index 0000000000..2d4bee923f --- /dev/null +++ b/zephyr/shim/include/charger_chips.h @@ -0,0 +1,32 @@ +/* Copyright 2022 The ChromiumOS Authors. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_CHARGER_CHIPS_H +#define __CROS_EC_CHARGER_CHIPS_H + +#include "charger.h" +#include <zephyr/devicetree.h> + +extern const struct charger_config_t chg_chips_alt[]; + +#define ALT_CHG_CHIP_CHK(usbc_id, usb_port_num) \ + COND_CODE_1(DT_REG_HAS_IDX(usbc_id, usb_port_num), \ + (COND_CODE_1(DT_NODE_HAS_PROP(usbc_id, chg_alt), (|| 1), \ + (|| 0))), \ + (|| 0)) + +#define CHG_ENABLE_ALTERNATE(usb_port_num) \ + do { \ + BUILD_ASSERT( \ + (0 DT_FOREACH_STATUS_OKAY_VARGS(named_usbc_port, \ + ALT_CHG_CHIP_CHK, \ + usb_port_num)), \ + "Selected USB node does not exist or does not specify" \ + "a charger alternate chip"); \ + memcpy(&chg_chips[usb_port_num], &chg_chips_alt[usb_port_num], \ + sizeof(struct charger_config_t)); \ + } while (0) + +#endif /* __CROS_EC_CHARGER_CHIPS_H */ diff --git a/zephyr/shim/src/charger.c b/zephyr/shim/src/charger.c index d4afc85218..be8c7615f6 100644 --- a/zephyr/shim/src/charger.c +++ b/zephyr/shim/src/charger.c @@ -31,6 +31,11 @@ COND_CODE_1(DT_NODE_HAS_PROP(usbc_id, chg), \ (CHG_CHIP_FIND(usbc_id, DT_PHANDLE(usbc_id, chg))), ()) +#define CHG_CHIP_ALT(usbc_id) \ + COND_CODE_1(DT_NODE_HAS_PROP(usbc_id, chg_alt), \ + (CHG_CHIP_FIND(usbc_id, DT_PHANDLE(usbc_id, chg_alt))), \ + ()) + #define MAYBE_CONST \ COND_CODE_1(CONFIG_PLATFORM_EC_CHARGER_RUNTIME_CONFIG, (), (const)) @@ -38,6 +43,10 @@ MAYBE_CONST struct charger_config_t chg_chips[] = { DT_FOREACH_STATUS_OKAY( named_usbc_port, CHG_CHIP) }; +/* Alternate options */ +const struct charger_config_t chg_chips_alt[] = { DT_FOREACH_STATUS_OKAY( + named_usbc_port, CHG_CHIP_ALT) }; + #ifdef CONFIG_PLATFORM_EC_CHARGER_SINGLE_CHIP BUILD_ASSERT(ARRAY_SIZE(chg_chips) == 1, "For the CHARGER_SINGLE_CHIP config, the number of defined charger " |