diff options
author | Diana Z <dzigterman@chromium.org> | 2022-08-31 14:03:30 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-01 20:42:57 +0000 |
commit | 95e3e7de55e33293237067f2335aaef5a349fa85 (patch) | |
tree | 5e6828c0f82f49ad24eb3dbf943f19da4b2c43f5 | |
parent | d243e0376964036cda67a5f4f306d8bb615cf126 (diff) | |
download | chrome-ec-95e3e7de55e33293237067f2335aaef5a349fa85.tar.gz |
Zephyr: Add alternative charger to the device tree
Some boards may use an alternative charger chip option, so enable this
in the devicetree, similar to the alternative PPC chip.
BRANCH=None
BUG=b:231153273
TEST=zmake buildall
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: Ie95671d74b0df57fd43ded73fb548e849d269c69
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3868032
Reviewed-by: Keith Short <keithshort@chromium.org>
-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 " |