diff options
author | Sam Hurst <shurst@google.com> | 2021-10-04 10:23:03 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-22 01:29:16 +0000 |
commit | f07b08ac2e713e7aac53ec35c2653e5d4103068b (patch) | |
tree | 08be048640cc716a46e60bc327403532fc09e09e | |
parent | 7bb51906784c97ec32248469ed6466783909a664 (diff) | |
download | chrome-ec-f07b08ac2e713e7aac53ec35c2653e5d4103068b.tar.gz |
zephyr: add support for bc1.2 in device tree
This commit adds support for bc1.2 definition in device tree.
It will allow to remove board specific files which implemented
the bc1.2 functionalities. This will unify the logic between
different board in zephyr.
BRANCH=main
BUG=b:194432779
TEST=HOST MODE: Plug non-pd device into TypeC port and verified that the
device received power and the following was printed to
the EC console: pi3usb9201[p0]: CDP_HOST mode]
CLIENT MODE: Plug an non-pd TypeC charger into the DUT and verified
that the device was charging with the "chgsup"
command. The EC console displayed the following:
port=0, type=1, cur=3000mA, vtg=5000mV, lsm=1
And the following debug output was displayed:
pi3usb9201[p0]: sts = 0x80, lim = 1500 mA, supplier = 3]
Using Suzy-Q, EC console displayed the follow:
pi3usb9201[p0]: sts = 0x40, lim = 500 mA, supplier = 5]
and "chgsup"
port=0, type=2, cur=1500mA, vtg=5000mV, lsm=1
Same results on Port 1
Signed-off-by: Sam Hurst <shurst@google.org>
Change-Id: Ia8e182997c48aa00f92c06e0fef6758473df29bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3202996
Commit-Queue: Sam Hurst <shurst@google.com>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/dts/bindings/usbc/pericom,pi3usb9201.yaml | 27 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/shim/src/bc12_pi3usb9201.c | 44 |
3 files changed, 73 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/usbc/pericom,pi3usb9201.yaml b/zephyr/dts/bindings/usbc/pericom,pi3usb9201.yaml new file mode 100644 index 0000000000..d72fa20a47 --- /dev/null +++ b/zephyr/dts/bindings/usbc/pericom,pi3usb9201.yaml @@ -0,0 +1,27 @@ +description: USBC BC1.2 + +compatible: "pericom,pi3usb9201" + +properties: + port: + type: phandle + required: true + description: | + I2C port used to communicate with controller + + irq: + type: phandles + required: true + description: | + GPIO interrupt from BC1.2 + + i2c-addr-flags: + type: string + default: "PI3USB9201_I2C_ADDR_3_FLAGS" + enum: + - "PI3USB9201_I2C_ADDR_0_FLAGS" + - "PI3USB9201_I2C_ADDR_1_FLAGS" + - "PI3USB9201_I2C_ADDR_2_FLAGS" + - "PI3USB9201_I2C_ADDR_3_FLAGS" + description: | + I2C address of controller diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index e30671c6d6..270ad10f52 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -46,3 +46,5 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C i2c.c) zephyr_library_sources_ifdef(CONFIG_SHIMMED_TASKS tasks.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_WATCHDOG watchdog.c) +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_BC12_DETECT_PI3USB9201 + bc12_pi3usb9201.c) diff --git a/zephyr/shim/src/bc12_pi3usb9201.c b/zephyr/shim/src/bc12_pi3usb9201.c new file mode 100644 index 0000000000..66fe963f5b --- /dev/null +++ b/zephyr/shim/src/bc12_pi3usb9201.c @@ -0,0 +1,44 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#define DT_DRV_COMPAT pericom_pi3usb9201 + +#include <devicetree.h> +#include "bc12/pi3usb9201_public.h" +#include "hooks.h" +#include "usb_pd.h" + + +#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) + +BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) > 0, + "No compatible BC1.2 instance found"); + +#define USBC_PORT_BC12(inst) \ + { \ + .i2c_port = I2C_PORT(DT_PHANDLE(DT_DRV_INST(inst), port)), \ + .i2c_addr_flags = DT_STRING_UPPER_TOKEN( \ + DT_DRV_INST(inst), i2c_addr_flags), \ + }, + +const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { + DT_INST_FOREACH_STATUS_OKAY(USBC_PORT_BC12) +}; + +#define BC12_GPIO_ENABLE_INTERRUPT(inst) \ + do { \ + if (DT_INST_NODE_HAS_PROP(inst, irq)) { \ + gpio_enable_interrupt( \ + GPIO_SIGNAL(DT_INST_PHANDLE(inst, irq))); \ + } \ + } while (0); + +static void bc12_enable_irqs(void) +{ + DT_INST_FOREACH_STATUS_OKAY(BC12_GPIO_ENABLE_INTERRUPT) +} +DECLARE_HOOK(HOOK_INIT, bc12_enable_irqs, HOOK_PRIO_DEFAULT); + +#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |