diff options
author | Michał Barnaś <mb@semihalf.com> | 2021-08-06 12:01:09 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-16 12:15:16 +0000 |
commit | 7c684a81a49c03cb5c8688c8607e883f7604dad8 (patch) | |
tree | 645ebdd3765d1dfac08c53d84101cd6e6f42fd15 /zephyr | |
parent | 8e7f105716a105173dc8af41cb76437fee62e91a (diff) | |
download | chrome-ec-7c684a81a49c03cb5c8688c8607e883f7604dad8.tar.gz |
zephyr: add support for switchcap in device tree
This commit adds support for switchcap definition in device tree.
It will allow to remove board specific files which implemented
the switchcap functionalities. This will unify the logic between
different board in zephyr.
BRANCH=main
BUG=b:194211207
TEST=Use linked TEST commits to see example of definitions for lazor
Use GPIO or LN9310 version, build and flash to lazor.
Board should be able to boot correctly.
Signed-off-by: Michał Barnaś <mb@semihalf.com>
Change-Id: Ib80a73dcb2db95e2dcf48e33f876a39246fd506a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3085670
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r-- | zephyr/Kconfig | 21 | ||||
-rw-r--r-- | zephyr/dts/bindings/switchcap/switchcap-gpio.yaml | 16 | ||||
-rw-r--r-- | zephyr/dts/bindings/switchcap/switchcap-ln9310.yaml | 27 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | zephyr/shim/src/switchcap_gpio.c | 47 | ||||
-rw-r--r-- | zephyr/shim/src/switchcap_ln9310.c | 51 |
6 files changed, 165 insertions, 1 deletions
diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 7041fd63ef..05b9d5d055 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -627,6 +627,22 @@ config PLATFORM_EC_SWITCH This also enables the "mmapinfo" console command to report the current state of all switches. +choice PLATFORM_EC_SWITCHCAP_TYPE + prompt "Enable switchcap support" + optional + help + Enable support for switchcap used to power on the AP. + If enabled, type of switchcap must be selected and node in device + tree must be added that describes the driver and pins used to control + the switchcap. + +config PLATFORM_EC_SWITCHCAP_GPIO + bool "GPIO controlled switchcap" + help + Enable support for the GPIO controlled switchcap. + Pins used for controlling the switchcap must be defined in board's + device tree. + config PLATFORM_EC_SWITCHCAP_LN9310 bool "LN9310 switchcap driver" depends on PLATFORM_EC_I2C @@ -634,7 +650,10 @@ config PLATFORM_EC_SWITCHCAP_LN9310 Enable support for the LION Semiconductor LN9310 switched capacitor converter. This will export definitions for ln9310_init, ln9310_interrupt, and ln9310_power_good, which - project-specific code should call appropriately. + project-specific code should call appropriately if there's + no switchcap node in device tree. + +endchoice config PLATFORM_EC_SYSTEM_UNLOCKED bool "System unlocked: allow dangerous commands while in development" diff --git a/zephyr/dts/bindings/switchcap/switchcap-gpio.yaml b/zephyr/dts/bindings/switchcap/switchcap-gpio.yaml new file mode 100644 index 0000000000..5d1a25bf94 --- /dev/null +++ b/zephyr/dts/bindings/switchcap/switchcap-gpio.yaml @@ -0,0 +1,16 @@ +description: SwitchCap controlled by gpios + +compatible: "switchcap-gpio" + +properties: + enable-pin: + type: phandle + required: true + description: | + GPIO used to enable the switch cap + + power-good-pin: + type: phandle + required: false + description: | + GPIO used to read if power is good diff --git a/zephyr/dts/bindings/switchcap/switchcap-ln9310.yaml b/zephyr/dts/bindings/switchcap/switchcap-ln9310.yaml new file mode 100644 index 0000000000..afd89aacc6 --- /dev/null +++ b/zephyr/dts/bindings/switchcap/switchcap-ln9310.yaml @@ -0,0 +1,27 @@ +description: SwitchCap controlled by LN9310 + +compatible: "switchcap-ln9310" + +properties: + enable-l-pin: + type: phandle + required: true + description: | + GPIO used to enable the switch cap - active low + + port: + type: phandle + required: true + description: | + I2C port used to communicate with controller + + addr-flags: + type: string + default: "LN9310_I2C_ADDR_0_FLAGS" + enum: + - "LN9310_I2C_ADDR_0_FLAGS" + - "LN9310_I2C_ADDR_1_FLAGS" + - "LN9310_I2C_ADDR_2_FLAGS" + - "LN9310_I2C_ADDR_3_FLAGS" + description: | + I2C address of controller diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index 7be2e75fb2..5fee14dfbd 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -33,6 +33,10 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PANIC panic.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PWM pwm.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_RTC rtc.c) +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCHCAP_GPIO + switchcap_gpio.c) +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCHCAP_LN9310 + switchcap_ln9310.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TEMP_SENSOR temp_sensors.c thermal.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) diff --git a/zephyr/shim/src/switchcap_gpio.c b/zephyr/shim/src/switchcap_gpio.c new file mode 100644 index 0000000000..c635978b8b --- /dev/null +++ b/zephyr/shim/src/switchcap_gpio.c @@ -0,0 +1,47 @@ +/* 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. + */ + +#include <devicetree.h> +#include "common.h" +#include "gpio.h" + +#if DT_NODE_EXISTS(DT_PATH(switchcap)) + +#if !DT_NODE_HAS_COMPAT(DT_PATH(switchcap), switchcap_gpio) +#error "Invalid /switchcap node in device tree" +#endif + +#define SC_PIN_ENABLE_PHANDLE \ + DT_PHANDLE_BY_IDX(DT_PATH(switchcap), enable_pin, 0) +#define SC_PIN_ENABLE \ + GPIO_SIGNAL(SC_PIN_ENABLE_PHANDLE) + +#define SC_PIN_POWER_GOOD_PHANDLE \ + DT_PHANDLE_BY_IDX(DT_PATH(switchcap), power_good_pin, 0) +#define SC_PIN_POWER_GOOD_EXISTS \ + DT_NODE_EXISTS(SC_PIN_POWER_GOOD_PHANDLE) +#define SC_PIN_POWER_GOOD \ + GPIO_SIGNAL(SC_PIN_POWER_GOOD_PHANDLE) + +void board_set_switchcap_power(int enable) +{ + gpio_set_level(SC_PIN_ENABLE, enable); +} + +int board_is_switchcap_enabled(void) +{ + return gpio_get_level(SC_PIN_ENABLE); +} + +int board_is_switchcap_power_good(void) +{ +#if SC_PIN_POWER_GOOD_EXISTS + return gpio_get_level(SC_PIN_POWER_GOOD); +#else + return 1; +#endif +} + +#endif diff --git a/zephyr/shim/src/switchcap_ln9310.c b/zephyr/shim/src/switchcap_ln9310.c new file mode 100644 index 0000000000..997ed8d15f --- /dev/null +++ b/zephyr/shim/src/switchcap_ln9310.c @@ -0,0 +1,51 @@ +/* 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. + */ + +#include <devicetree.h> +#include "common.h" +#include "gpio.h" +#include "ln9310.h" + +#if DT_NODE_EXISTS(DT_PATH(switchcap)) + +#if !DT_NODE_HAS_COMPAT(DT_PATH(switchcap), switchcap_ln9310) +#error "Invalid /switchcap node in device tree" +#endif + +#define SC_PIN_ENABLE_L_PHANDLE \ + DT_PHANDLE_BY_IDX(DT_PATH(switchcap), enable_l_pin, 0) +#define SC_PIN_ENABLE_L \ + GPIO_SIGNAL(SC_PIN_ENABLE_L_PHANDLE) + +#define SC_PORT_PHANDLE \ + DT_PHANDLE(DT_PATH(switchcap), port) +#define SC_PORT \ + DT_ENUM_UPPER_TOKEN(SC_PORT_PHANDLE, enum_name) + +#define SC_ADDR_FLAGS \ + DT_ENUM_UPPER_TOKEN(DT_PATH(switchcap), addr_flags) + +void board_set_switchcap_power(int enable) +{ + gpio_set_level(SC_PIN_ENABLE_L, !enable); + ln9310_software_enable(enable); +} + +int board_is_switchcap_enabled(void) +{ + return !gpio_get_level(SC_PIN_ENABLE_L); +} + +int board_is_switchcap_power_good(void) +{ + return ln9310_power_good(); +} + +const struct ln9310_config_t ln9310_config = { + .i2c_port = SC_PORT, + .i2c_addr_flags = SC_ADDR_FLAGS, +}; + +#endif |