diff options
author | Simon Glass <sjg@chromium.org> | 2023-05-02 14:50:44 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-04 21:40:07 +0000 |
commit | 04a2772c47a6f9d70a47bd7adea04cd01c2335f5 (patch) | |
tree | 6068fed6cbc6de417645be038999f99f6a5c50d0 | |
parent | 2ba94027727cd8a3a952c80d5c380cd3c7d9918c (diff) | |
download | chrome-ec-04a2772c47a6f9d70a47bd7adea04cd01c2335f5.tar.gz |
zephyr: dev-posix: Enable battery charging
One hopes this is close to the minimum Kconfig and DT additions needed
to enable this feature. It brings in charger_task() which is the subject
of this effort.
BUG=b:218332694
TEST=with other changes, see that it can be built into dev-posix
Change-Id: Ifc42bbf92f92406514414b8df6e5a2b187cbfbe8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4501285
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
Commit-Queue: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | zephyr/program/dev/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/program/dev/dev.dtsi | 129 | ||||
-rw-r--r-- | zephyr/program/dev/prj.conf | 17 | ||||
-rw-r--r-- | zephyr/program/dev/src/stubs.c | 27 |
4 files changed, 174 insertions, 1 deletions
diff --git a/zephyr/program/dev/CMakeLists.txt b/zephyr/program/dev/CMakeLists.txt index c5a94d2b14..91ccb8c30d 100644 --- a/zephyr/program/dev/CMakeLists.txt +++ b/zephyr/program/dev/CMakeLists.txt @@ -6,4 +6,6 @@ cmake_minimum_required(VERSION 3.20.5) find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}") project(ec) +target_sources(app PRIVATE src/stubs.c) + zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") diff --git a/zephyr/program/dev/dev.dtsi b/zephyr/program/dev/dev.dtsi index 253ac129c8..affe947bbe 100644 --- a/zephyr/program/dev/dev.dtsi +++ b/zephyr/program/dev/dev.dtsi @@ -6,18 +6,145 @@ #include <board-overlays/native_posix.dts> / { + named-adc-channels { + compatible = "named-adc-channels"; + + adc_charger: charger { + enum-name = "ADC_TEMP_SENSOR_CHARGER"; + io-channels = <&adc0 0>; + }; + }; + + named-gpios { + ec_batt_pres_odl { + gpios = <&gpio0 28 GPIO_INPUT>; + enum-name = "GPIO_BATT_PRES_ODL"; + }; + gpio_usb_c0_bc12_int_l: usb_c0_bc12_int_l { + gpios = <&gpio0 10 GPIO_INPUT>; + }; + gpio_usb_c0_ppc_int: usb_c0_ppc_int { + gpios = <&gpio0 14 (GPIO_INPUT | GPIO_ACTIVE_LOW)>; + }; + gpio_acok_od: acok_od { + gpios = <&gpio0 0 GPIO_INPUT>; + enum-name = "GPIO_AC_PRESENT"; + }; + }; + named-i2c-ports { compatible = "named-i2c-ports"; accel-0 { i2c-port = <&i2c0>; - enum-names = "I2C_PORT_ACCEL"; + enum-names = "I2C_PORT_ACCEL", "I2C_PORT_BATTERY"; + }; + + }; + + adc0: adc { + compatible = "zephyr,adc-emul"; + nchannels = <6>; + ref-internal-mv = <3300>; + #io-channel-cells = <1>; + status = "okay"; + }; + + batteries { + default_battery: lgc_ac17a8m { + compatible = "lgc,ac17a8m", "battery-smart"; + /** + * this has to be strictly lower than the desired + * voltage in smart battery emulator (5000mV). + */ + voltage_min = <4000>; + }; + }; + + gpio-interrupts { + compatible = "cros-ec,gpio-interrupts"; + + int_usb_c0_bc12: usb_c0_bc12 { + irq-pin = <&gpio_usb_c0_bc12_int_l>; + flags = <GPIO_INT_EDGE_FALLING>; + handler = "usb0_evt"; + }; + int_ac_present: ac_present { + irq-pin = <&gpio_acok_od>; + flags = <GPIO_INT_EDGE_BOTH>; + handler = "extpower_interrupt"; + }; + }; + + usbc { + #address-cells = <1>; + #size-cells = <0>; + + port0@0 { + compatible = "named-usbc-port"; + reg = <0>; + bc12 = <&pi3usb9201_emul0>; + chg = <&isl923x_emul>; + tcpc = <&tcpci_emul>; + ppc = <&sn5s330_emul>; + usb-mux-chain-0 { + compatible = "cros-ec,usb-mux-chain"; + usb-muxes = <&tcpci_mux_c0 + &virtual_mux_c0>; + }; + }; + port0-muxes { + tcpci_mux_c0: tcpci-mux-c0 { + compatible = "cros-ec,usbc-mux-tcpci"; + }; + virtual_mux_c0: virtual-mux-c0 { + compatible = "cros-ec,usbc-mux-virtual"; + }; }; }; }; &i2c0 { + battery: sb@b { + compatible = "zephyr,smart-battery-emul"; + reg = <0xb>; + cycle-count = <99>; + version = "BATTERY_SPEC_VER_1_1_WITH_PEC"; + /* Real battery voltages are multiples of 4.4V. */ + desired-charg-volt = <5000>; + desired-charg-cur = <1000>; + mf-name = "LGC"; + dev-name = "AC17A8M"; + }; + bmi_i2c: bmi@68 { compatible = "bosch,bmi160"; reg = <0x68>; }; + + isl923x_emul: isl923x@9 { + compatible = "cros,isl923x-emul"; + status = "okay"; + reg = <0x9>; + battery = <&battery>; + }; + + pi3usb9201_emul0: pi3usb9201@5f { + compatible = "pericom,pi3usb9201"; + reg = <0x5f>; + irq = <&int_usb_c0_bc12>; + }; + + sn5s330_emul: sn5s330@40 { + compatible = "cros,sn5s330-emul"; + reg = <0x40>; + int-pin = <&gpio_usb_c0_ppc_int>; + }; + + tcpci_emul: tcpci_emul@2 { + compatible = "cros,tcpci-generic-emul"; + status = "okay"; + reg = <0x2>; + irq-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>; + rst-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; + }; }; diff --git a/zephyr/program/dev/prj.conf b/zephyr/program/dev/prj.conf index 35bf59baea..b0fcc1f173 100644 --- a/zephyr/program/dev/prj.conf +++ b/zephyr/program/dev/prj.conf @@ -15,6 +15,23 @@ CONFIG_PLATFORM_EC_KEYBOARD=n CONFIG_PLATFORM_EC_POWER_BUTTON=n CONFIG_PLATFORM_EC_SWITCH=n CONFIG_PLATFORM_EC_VBOOT_EFS2=n +CONFIG_PLATFORM_EC_VBOOT_HASH=n + +CONFIG_PLATFORM_EC=y +CONFIG_PLATFORM_EC_HOOKS=y +CONFIG_PLATFORM_EC_HOSTCMD=y +CONFIG_PLATFORM_EC_CHARGER=y +CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y + +CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y + +CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR=10 +CONFIG_PLATFORM_EC_CHARGER_SENSE_RESISTOR_AC=10 +CONFIG_PLATFORM_EC_CHARGER_ISL9238=y +CONFIG_PLATFORM_EC_USB_PD_VBUS_MEASURE_CHARGER=y +CONFIG_PLATFORM_EC_USB_PD_DISCHARGE_PPC=y + +CONFIG_PLATFORM_EC_USB_PD_TCPM_MUX=y CONFIG_NATIVE_UART_0_ON_STDINOUT=y diff --git a/zephyr/program/dev/src/stubs.c b/zephyr/program/dev/src/stubs.c new file mode 100644 index 0000000000..488289c7e4 --- /dev/null +++ b/zephyr/program/dev/src/stubs.c @@ -0,0 +1,27 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Fakes for dev-posix which will be updated as work progresses + */ + +#include "usb_pd.h" + +int board_set_active_charge_port(int port) +{ + return 0; +} + +int pd_check_vconn_swap(int port) +{ + return 0; +} + +void pd_power_supply_reset(int port) +{ +} + +int pd_set_power_supply_ready(int port) +{ + return 0; +} |