diff options
Diffstat (limited to 'zephyr/include')
31 files changed, 0 insertions, 4126 deletions
diff --git a/zephyr/include/cros/binman.dtsi b/zephyr/include/cros/binman.dtsi deleted file mode 100644 index 82bb801e6c..0000000000 --- a/zephyr/include/cros/binman.dtsi +++ /dev/null @@ -1,51 +0,0 @@ -/* 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. - */ - -/dts-v1/; - -/ { - #address-cells = <1>; - #size-cells = <1>; - binman { - filename = "zephyr.bin"; - pad-byte = <0x1d>; - wp-ro { - compatible = "cros-ec,flash-layout"; - type = "section"; - offset = <0x0>; - size = <0x40000>; - read-only; - ec-ro { - type = "section"; - ro-fw { - type = "blob"; - filename = "zephyr_ro.bin"; - }; - fmap { - }; - ro-frid { - type = "text"; - size = <32>; - text-label = "version"; - }; - }; - }; - ec-rw { - compatible = "cros-ec,flash-layout"; - type = "section"; - offset = <0x40000>; - size = <0x40000>; - rw-fw { - type = "blob"; - filename = "zephyr_rw.bin"; - }; - rw-fwid { - type = "text"; - size = <32>; - text-label = "version"; - }; - }; - }; -}; diff --git a/zephyr/include/cros/ite/it8xxx2.dtsi b/zephyr/include/cros/ite/it8xxx2.dtsi deleted file mode 100644 index 54ca7f63e3..0000000000 --- a/zephyr/include/cros/ite/it8xxx2.dtsi +++ /dev/null @@ -1,83 +0,0 @@ -/* 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 <cros/binman.dtsi> - -/ { - named-bbram-regions { - compatible = "named-bbram-regions"; - - scratchpad { - offset = <0x08>; - size = <0x04>; - }; - saved-reset-flags { - offset = <0x00>; - size = <0x04>; - }; - wake { - offset = <0x08>; - size = <0x04>; - }; - pd0 { - offset = <0x04>; - size = <0x01>; - }; - pd1 { - offset = <0x05>; - size = <0x01>; - }; - try_slot { - offset = <0x0e>; - size = <0x01>; - }; - pd2 { - offset = <0x06>; - size = <0x01>; - }; - }; - - soc { - bbram: bb-ram@f02200 { - #address-cells = <1>; - #size-cells = <1>; - compatible = "ite,it8xxx2-cros-bbram"; - status = "okay"; - reg = <0x00f02200 0xbf>; - reg-names = "memory"; - label = "BBRAM"; - }; - - shi: shi@f03a00 { - compatible = "ite,it8xxx2-cros-shi"; - reg = <0x00f03a00 0x30>; - label = "SHI"; - interrupts = <171 0>; - interrupt-parent = <&intc>; - pinctrl-0 = <&pinctrl_shi_mosi /* GPM0 */ - &pinctrl_shi_miso /* GPM1 */ - &pinctrl_shi_clk /* GPM4 */ - &pinctrl_shi_cs>; /* GPM5 */ - }; - - fiu0: cros-flash@80000000 { - compatible = "ite,it8xxx2-cros-flash"; - reg = <0x80000000 0x100000>; - label = "FLASH"; - }; - }; - - /* it8xxx2 has 1MB of flash. currently, we use 512KB from flash. */ - binman { - wp-ro { - offset = <0x0>; - size = <0x40000>; - }; - ec-rw { - offset = <0x40000>; - size = <0x40000>; - }; - }; -}; diff --git a/zephyr/include/cros/nuvoton/npcx.dtsi b/zephyr/include/cros/nuvoton/npcx.dtsi deleted file mode 100644 index 9c84d5712d..0000000000 --- a/zephyr/include/cros/nuvoton/npcx.dtsi +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2021 The Chromium OS Authors - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/dts-v1/; - -#include <cros/binman.dtsi> -#include <nuvoton/npcx.dtsi> - -/ { - - named-bbram-regions { - compatible = "named-bbram-regions"; - - scratchpad { - offset = <0x00>; - size = <0x04>; - }; - saved-reset-flags { - offset = <0x04>; - size = <0x04>; - }; - wake { - offset = <0x08>; - size = <0x04>; - }; - pd0 { - offset = <0x0c>; - size = <0x01>; - }; - pd1 { - offset = <0x0d>; - size = <0x01>; - }; - try_slot { - offset = <0x0e>; - size = <0x01>; - }; - pd2 { - offset = <0x0f>; - size = <0x01>; - }; - ramlog { - offset = <0x20>; - size = <0x01>; - }; - panic_flags { - offset = <0x23>; - size = <0x01>; - }; - panic_bkup { - offset = <0x24>; - size = <0x1c>; - }; - lct_time { - offset = <0x40>; - size = <0x04>; - }; - }; - - soc { - - cros_kb_raw: cros-kb-raw@400a3000 { - compatible = "nuvoton,npcx-cros-kb-raw"; - reg = <0x400a3000 0x2000>; - label = "CROS_KB_RAW_0"; - interrupts = <49 4>; - clocks = <&pcc NPCX_CLOCK_BUS_APB1 NPCX_PWDWN_CTL1 0>; - /* - * No KSO2 (It's inverted and implemented by GPIO for - * CONFIG_KEYBOARD_COL2_INVERTED.) - */ - pinctrl-0 = <&alt7_no_ksi0_sl - &alt7_no_ksi1_sl - &alt7_no_ksi2_sl - &alt7_no_ksi3_sl - &alt7_no_ksi4_sl - &alt7_no_ksi5_sl - &alt7_no_ksi6_sl - &alt7_no_ksi7_sl - &alt8_no_kso00_sl - &alt8_no_kso01_sl - &alt8_no_kso03_sl - &alt8_no_kso04_sl - &alt8_no_kso05_sl - &alt8_no_kso06_sl - &alt8_no_kso07_sl - &alt9_no_kso08_sl - &alt9_no_kso09_sl - &alt9_no_kso10_sl - &alt9_no_kso11_sl - &alt9_no_kso12_sl - &alt9_no_kso13_sl - &alt9_no_kso14_sl - &alt9_no_kso15_sl - &alta_no_kso16_sl - &alta_no_kso17_sl - >; - wui_maps = <&wui_io31 &wui_io30 &wui_io27 &wui_io26 - &wui_io25 &wui_io24 &wui_io23 &wui_io22>; - }; - - mtc: mtc@400b7000 { - compatible = "nuvoton,npcx-cros-mtc"; - reg = <0x400b7000 0x2000>; - mtc-alarm = <&wui_mtc>; - label = "MTC"; - }; - - fiu0: cros-flash@40020000 { - compatible = "nuvoton,npcx-cros-flash"; - reg = <0x40020000 0x2000>; - clocks = <&pcc NPCX_CLOCK_BUS_APB3 NPCX_PWDWN_CTL1 2>; - size = <0x80000>; - label = "FLASH_INTERFACE_UNIT0"; - pinctrl-0 = <>; - }; - - shi: shi@4000f000 { - compatible = "nuvoton,npcx-cros-shi"; - reg = <0x4000f000 0x120>; - interrupts = <18 1>; - clocks = <&pcc NPCX_CLOCK_BUS_APB3 NPCX_PWDWN_CTL5 1>; - pinctrl-0 = <&altc_shi_sl>; - shi-cs-wui =<&wui_io53>; - label = "SHI"; - }; - }; - - power-states { - suspend_to_idle_instant: suspend_to_idle_instant { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <0>; - min-residency-us = <500>; - }; - - suspend_to_idle_normal: suspend_to_idle_normal { - compatible = "zephyr,power-state"; - power-state-name = "suspend-to-idle"; - substate-id = <1>; - min-residency-us = <200100>; - }; - }; -}; - -&cpu0 { - cpu-power-states = <&suspend_to_idle_instant &suspend_to_idle_normal>; -}; - -&bbram { - status = "okay"; -}; - -&mdc { - status = "okay"; -}; diff --git a/zephyr/include/cros/nuvoton/npcx7.dtsi b/zephyr/include/cros/nuvoton/npcx7.dtsi deleted file mode 100644 index 0526341e2c..0000000000 --- a/zephyr/include/cros/nuvoton/npcx7.dtsi +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2021 The Chromium OS Authors - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/dts-v1/; - -#include <cros/nuvoton/npcx.dtsi> - -/ { - - soc { - - dbg: dbg@400c3074 { - compatible = "nuvoton,npcx-cros-dbg"; - reg = <0x400c3074 0x0C>; - pinctrl-0 = <&alt5_njen0_en>; - label = "DBG"; - status = "disabled"; - }; - }; - -}; diff --git a/zephyr/include/cros/nuvoton/npcx9.dtsi b/zephyr/include/cros/nuvoton/npcx9.dtsi deleted file mode 100644 index de492d3306..0000000000 --- a/zephyr/include/cros/nuvoton/npcx9.dtsi +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2021 The Chromium OS Authors - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/dts-v1/; - -#include <cros/nuvoton/npcx.dtsi> - -/ { - soc { - - }; -}; diff --git a/zephyr/include/cros/thermistor/thermistor.dtsi b/zephyr/include/cros/thermistor/thermistor.dtsi deleted file mode 100644 index 033d5639e2..0000000000 --- a/zephyr/include/cros/thermistor/thermistor.dtsi +++ /dev/null @@ -1,308 +0,0 @@ -/ { - thermistor_3V3_30K9_47K_4050B: thermistor-3V3-30K9-47K-4050B { - status = "disabled"; - compatible = "cros-ec,thermistor"; - scaling-factor = <11>; - num-pairs = <10>; - steinhart-reference-mv = <3300>; - steinhart-reference-res = <30900>; - - /* - * Data derived from Steinhart-Hart equation in a resistor - * divider circuit with Vdd=3300mV, R = 30.9Kohm, and thermistor - * (B = 4050, T0 = 298.15 K, nominal resistance (R0) = 47Kohm). - */ - sample-datum-0 { - milivolt = <(2753 / 11)>; - temp = <0>; - sample-index = <0>; - }; - sample-datum-1 { - milivolt = <(2487 / 11)>; - temp = <10>; - sample-index = <1>; - }; - sample-datum-2 { - milivolt = <(2165 / 11)>; - temp = <20>; - sample-index = <2>; - }; - sample-datum-3 { - milivolt = <(1813 / 11)>; - temp = <30>; - sample-index = <3>; - }; - sample-datum-4 { - milivolt = <(1145 / 11)>; - temp = <50>; - sample-index = <4>; - }; - sample-datum-5 { - milivolt = <(878 / 11)>; - temp = <60>; - sample-index = <5>; - }; - sample-datum-6 { - milivolt = <(665 / 11)>; - temp = <70>; - sample-index = <6>; - }; - sample-datum-7 { - milivolt = <(500 / 11)>; - temp = <80>; - sample-index = <7>; - }; - sample-datum-8 { - milivolt = <(375 / 11)>; - temp = <90>; - sample-index = <8>; - }; - sample-datum-9 { - milivolt = <(282 / 11)>; - temp = <100>; - sample-index = <9>; - }; - }; - - - thermistor_3V0_22K6_47K_4050B: thermistor-3V0-22K6-47K-4050B { - status = "disabled"; - compatible = "cros-ec,thermistor"; - scaling-factor = <11>; - num-pairs = <13>; - steinhart-reference-mv = <3000>; - steinhart-reference-res = <22600>; - - /* - * Data derived from Steinhart-Hart equation in a resistor - * divider circuit with Vdd=3000mV, R = 22.6Kohm, and thermistor - * (B = 4050, T0 = 298.15 K, nominal resistance (R0) = 47Kohm). - */ - sample-datum-0 { - milivolt = <( 2619 / 11)>; - temp = <0>; - sample-index = <0>; - }; - sample-datum-1 { - milivolt = <( 2421 / 11)>; - temp = <10>; - sample-index = <1>; - }; - sample-datum-2 { - milivolt = <( 2168 / 11)>; - temp = <20>; - sample-index = <2>; - }; - sample-datum-3 { - milivolt = <( 1875 / 11)>; - temp = <30>; - sample-index = <3>; - }; - sample-datum-4 { - milivolt = <( 1563 / 11)>; - temp = <40>; - sample-index = <4>; - }; - sample-datum-5 { - milivolt = <( 1262 / 11)>; - temp = <50>; - sample-index = <5>; - }; - sample-datum-6 { - milivolt = <( 994 / 11)>; - temp = <60>; - sample-index = <6>; - }; - sample-datum-7 { - milivolt = <( 769 / 11)>; - temp = <70>; - sample-index = <7>; - }; - sample-datum-8 { - milivolt = <( 588 / 11)>; - temp = <80>; - sample-index = <8>; - }; - sample-datum-9 { - milivolt = <( 513 / 11)>; - temp = <85>; - sample-index = <9>; - }; - sample-datum-10 { - milivolt = <( 448 / 11)>; - temp = <90>; - sample-index = <10>; - }; - sample-datum-11 { - milivolt = <( 390 / 11)>; - temp = <95>; - sample-index = <11>; - }; - sample-datum-12 { - milivolt = <( 340 / 11)>; - temp = <100>; - sample-index = <12>; - }; - }; - - thermistor_3V3_13K7_47K_4050B: thermistor-3V3-13K7-47K-4050B { - status = "disabled"; - compatible = "cros-ec,thermistor"; - scaling-factor = <13>; - num-pairs = <13>; - steinhart-reference-mv = <3300>; - steinhart-reference-res = <13700>; - - /* - * Data derived from Steinhart-Hart equation in a resistor - * divider circuit with Vdd=3300mV, R = 13.7Kohm, and thermistor - * (B = 4050, T0 = 298.15 K, nominal resistance (R0) = 47Kohm). - */ - sample-datum-0 { - milivolt = <(3033 / 13)>; - temp = <0>; - sample-index = <0>; - }; - sample-datum-1 { - milivolt = <(2882 / 13)>; - temp = <10>; - sample-index = <1>; - }; - sample-datum-2 { - milivolt = <(2677 / 13)>; - temp = <20>; - sample-index = <2>; - }; - sample-datum-3 { - milivolt = <(2420 / 13)>; - temp = <30>; - sample-index = <3>; - }; - sample-datum-4 { - milivolt = <(2119 / 13)>; - temp = <40>; - sample-index = <4>; - }; - sample-datum-5 { - milivolt = <(1799 / 13)>; - temp = <50>; - sample-index = <5>; - }; - sample-datum-6 { - milivolt = <(1485 / 13)>; - temp = <60>; - sample-index = <6>; - }; - sample-datum-7 { - milivolt = <(1197 / 13)>; - temp = <70>; - sample-index = <7>; - }; - sample-datum-8 { - milivolt = <( 947 / 13)>; - temp = <80>; - sample-index = <8>; - }; - sample-datum-9 { - milivolt = <( 839 / 13)>; - temp = <85>; - sample-index = <9>; - }; - sample-datum-10 { - milivolt = <( 741 / 13)>; - temp = <90>; - sample-index = <10>; - }; - sample-datum-11 { - milivolt = <( 653 / 13)>; - temp = <95>; - sample-index = <11>; - }; - sample-datum-12 { - milivolt = <( 576 / 13)>; - temp = <100>; - sample-index = <12>; - }; - }; - - - thermistor_3V3_51K1_47K_4050B: thermistor-3V3-51K1-47K-4050B { - status = "disabled"; - compatible = "cros-ec,thermistor"; - scaling-factor = <11>; - num-pairs = <13>; - steinhart-reference-mv = <3300>; - steinhart-reference-res = <51100>; - - /* - * Data derived from Steinhart-Hart equation in a resistor - * divider circuit with Vdd=3300mV, R = 51.1Kohm, and thermistor - * (B = 4050, T0 = 298.15 K, nominal resistance (R0) = 47Kohm). - */ - sample-datum-0 { - milivolt = <(2484 / 11)>; - temp = <0>; - sample-index = <0>; - }; - sample-datum-1 { - milivolt = <(2142 / 11)>; - temp = <10>; - sample-index = <1>; - }; - sample-datum-2 { - milivolt = <(1767 / 11)>; - temp = <20>; - sample-index = <2>; - }; - sample-datum-3 { - milivolt = <(1400 / 11)>; - temp = <30>; - sample-index = <3>; - }; - sample-datum-4 { - milivolt = <(1072 / 11)>; - temp = <40>; - sample-index = <4>; - }; - sample-datum-5 { - milivolt = <( 802 / 11)>; - temp = <50>; - sample-index = <5>; - }; - sample-datum-6 { - milivolt = <( 593 / 11)>; - temp = <60>; - sample-index = <6>; - }; - sample-datum-7 { - milivolt = <( 436 / 11)>; - temp = <70>; - sample-index = <7>; - }; - sample-datum-8 { - milivolt = <( 321 / 11)>; - temp = <80>; - sample-index = <8>; - }; - sample-datum-9 { - milivolt = <( 276 / 11)>; - temp = <85>; - sample-index = <9>; - }; - sample-datum-10 { - milivolt = <( 237 / 11)>; - temp = <90>; - sample-index = <10>; - }; - sample-datum-11 { - milivolt = <( 204 / 11)>; - temp = <95>; - sample-index = <11>; - }; - sample-datum-12 { - milivolt = <( 177 / 11)>; - temp = <100>; - sample-index = <12>; - }; - }; -}; diff --git a/zephyr/include/drivers/cros_cbi.h b/zephyr/include/drivers/cros_cbi.h deleted file mode 100644 index aa55e03b77..0000000000 --- a/zephyr/include/drivers/cros_cbi.h +++ /dev/null @@ -1,102 +0,0 @@ -/* 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. - */ - -/** - * @file - * @brief Chrome OS-specific API for access to Cros Board Info(CBI) - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_CBI_H_ -#define ZEPHYR_INCLUDE_DRIVERS_CROS_CBI_H_ - -#include <kernel.h> -#include <device.h> -#include <devicetree.h> - -#define CBI_SSFC_VALUE_COMPAT named_cbi_ssfc_value -#define CBI_SSFC_VALUE_ID(id) DT_CAT(CBI_SSFC_VALUE_, id) -#define CBI_SSFC_VALUE_ID_WITH_COMMA(id) CBI_SSFC_VALUE_ID(id), -#define CBI_SSFC_VALUE_INST_ENUM(inst, _) \ - CBI_SSFC_VALUE_ID_WITH_COMMA(DT_INST(inst, CBI_SSFC_VALUE_COMPAT)) -#define CROS_CBI_LABEL "cros_cbi" - -enum cbi_ssfc_value_id { - UTIL_LISTIFY(DT_NUM_INST_STATUS_OKAY(CBI_SSFC_VALUE_COMPAT), - CBI_SSFC_VALUE_INST_ENUM) - CBI_SSFC_VALUE_COUNT -}; - -/** - * @cond INTERNAL_HIDDEN - * - * cros cbi raw driver API definition and system call entry points - * - * (Internal use only.) - */ -typedef int (*cros_cbi_api_init)(const struct device *dev); -typedef int (*cros_cbi_api_ssfc_check_match)(const struct device *dev, - enum cbi_ssfc_value_id value_id); - -__subsystem struct cros_cbi_driver_api { - cros_cbi_api_init init; - cros_cbi_api_ssfc_check_match ssfc_check_match; -}; - -/** - * @endcond - */ - -/** - * @brief Initialize CBI. - * - * @param dev Pointer to the device structure for the CBI instance. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_cbi_init(const struct device *dev); - -static inline int z_impl_cros_cbi_init(const struct device *dev) -{ - const struct cros_cbi_driver_api *api = - (const struct cros_cbi_driver_api *)dev->api; - - if (!api->init) { - return -ENOTSUP; - } - - return api->init(dev); -} - -/** - * @brief Check if the CBI SSFC value matches the one in the EEPROM - * - * @param dev Pointer to the device. - * - * @return 1 If matches, 0 if not. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_cbi_ssfc_check_match(const struct device *dev, - enum cbi_ssfc_value_id value_id); - -static inline int -z_impl_cros_cbi_ssfc_check_match(const struct device *dev, - enum cbi_ssfc_value_id value_id) -{ - const struct cros_cbi_driver_api *api = - (const struct cros_cbi_driver_api *)dev->api; - - if (!api->ssfc_check_match) { - return -ENOTSUP; - } - - return api->ssfc_check_match(dev, value_id); -} - -/** - * @} - */ -#include <syscalls/cros_cbi.h> -#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_CBI_H_ */ diff --git a/zephyr/include/drivers/cros_flash.h b/zephyr/include/drivers/cros_flash.h deleted file mode 100644 index 7f48cf7285..0000000000 --- a/zephyr/include/drivers/cros_flash.h +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Chrome OS-specific API for flash memory access - * This exists only support the interface expected by the Chrome OS EC. It seems - * better to implement this so we can make use of most of the existing code in - * its keyboard_scan.c file and thus make sure we operate the same way. - * - * It provides raw access to flash memory module. - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_FLASH_H_ -#define ZEPHYR_INCLUDE_DRIVERS_CROS_FLASH_H_ - -#include <kernel.h> -#include <device.h> - -/** - * @brief CROS Flash Driver APIs - * @defgroup cros_flash_interface CROS Flash Driver APIs - * @ingroup io_interfaces - * @{ - */ - -/** - * @cond INTERNAL_HIDDEN - * - * cros keyboard raw driver API definition and system call entry points - * - * (Internal use only.) - */ -typedef int (*cros_flash_api_init)(const struct device *dev); - -typedef int (*cros_flash_api_physical_read)(const struct device *dev, - int offset, int size, char *data); - -typedef int (*cros_flash_api_physical_write)(const struct device *dev, - int offset, int size, - const char *data); - -typedef int (*cros_flash_api_physical_erase)(const struct device *dev, - int offset, int size); - -typedef int (*cros_flash_api_physical_get_protect)(const struct device *dev, - int bank); - -typedef uint32_t -(*cros_flash_api_physical_get_protect_flags)(const struct device *dev); - -typedef int (*cros_flash_api_physical_protect_at_boot)(const struct device *dev, - uint32_t new_flags); - -typedef int (*cros_flash_api_physical_protect_now)(const struct device *dev, - int all); - -__subsystem struct cros_flash_driver_api { - cros_flash_api_init init; - cros_flash_api_physical_read physical_read; - cros_flash_api_physical_write physical_write; - cros_flash_api_physical_erase physical_erase; - cros_flash_api_physical_get_protect physical_get_protect; - cros_flash_api_physical_get_protect_flags physical_get_protect_flags; - cros_flash_api_physical_protect_at_boot physical_protect_at_boot; - cros_flash_api_physical_protect_now physical_protect_now; -}; - -/** - * @endcond - */ - -/** - * @brief Initialize physical flash. - * - * @param dev Pointer to the device structure for the flash driver instance. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_init(const struct device *dev); - -static inline int z_impl_cros_flash_init(const struct device *dev) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->init) { - return -ENOTSUP; - } - - return api->init(dev); -} - -/** - * @brief Read from physical flash. - * - * @param dev Pointer to the device structure for the flash driver instance. - * @param offset Flash offset to read. - * @param size Number of bytes to read. - * @param data Destination buffer for data. Must be 32-bit aligned. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_physical_read(const struct device *dev, int offset, - int size, char *data); - -static inline int z_impl_cros_flash_physical_read(const struct device *dev, - int offset, int size, - char *data) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_read) { - return -ENOTSUP; - } - - return api->physical_read(dev, offset, size, data); -} - -/** - * @brief Write to physical flash. - * - * Offset and size must be a multiple of CONFIG_FLASH_WRITE_SIZE. - * - * @param dev Pointer to the device structure for the flash driver instance. - * @param offset Flash offset to write. - * @param size Number of bytes to write. - * @param data Destination buffer for data. Must be 32-bit aligned. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_physical_write(const struct device *dev, int offset, - int size, const char *data); - -static inline int z_impl_cros_flash_physical_write(const struct device *dev, - int offset, int size, - const char *data) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_write) { - return -ENOTSUP; - } - - return api->physical_write(dev, offset, size, data); -} - -/** - * @brief Erase physical flash. - * - * Offset and size must be a multiple of CONFIG_FLASH_ERASE_SIZE. - * - * @param dev Pointer to the device structure for the flash driver instance. - * @param offset Flash offset to erase. - * @param size Number of bytes to erase. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_physical_erase(const struct device *dev, int offset, - int size); - -static inline int z_impl_cros_flash_physical_erase(const struct device *dev, - int offset, int size) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_erase) { - return -ENOTSUP; - } - - return api->physical_erase(dev, offset, size); -} - -/** - * @brief Read physical write protect setting for a flash bank. - * - * @param dev Pointer to the device structure for the flash driver instance. - * @param bank Bank index to check. - * - * @return non-zero if bank is protected until reboot. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_physical_get_protect(const struct device *dev, - int bank); - -static inline int -z_impl_cros_flash_physical_get_protect(const struct device *dev, int bank) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_get_protect) { - return -ENOTSUP; - } - - return api->physical_get_protect(dev, bank); -} - -/** - * @brief Return flash protect state flags from the physical layer. - * - * @param dev Pointer to the device structure for the flash driver instance. - * - * @retval -ENOTSUP Not supported api function. - */ -__syscall -uint32_t cros_flash_physical_get_protect_flags(const struct device *dev); - -static inline uint32_t -z_impl_cros_flash_physical_get_protect_flags(const struct device *dev) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_get_protect_flags) { - return -ENOTSUP; - } - - return api->physical_get_protect_flags(dev); -} - -/** - * @brief Enable/disable protecting firmware/pstate at boot. - * - * @param dev Pointer to the device structure for the flash driver instance. - * @param new_flags to protect (only EC_FLASH_PROTECT_*_AT_BOOT are - * taken care of) - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_physical_protect_at_boot(const struct device *dev, - uint32_t new_flags); - -static inline int -z_impl_cros_flash_physical_protect_at_boot(const struct device *dev, - uint32_t new_flags) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_protect_at_boot) { - return -ENOTSUP; - } - - return api->physical_protect_at_boot(dev, new_flags); -} - -/** - * @brief Protect now physical flash. - * - * @param dev Pointer to the device structure for the flash driver instance. - * @param all Protect all (=1) or just read-only and pstate (=0). - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_flash_physical_protect_now(const struct device *dev, - int all); - -static inline int -z_impl_cros_flash_physical_protect_now(const struct device *dev, int all) -{ - const struct cros_flash_driver_api *api = - (const struct cros_flash_driver_api *)dev->api; - - if (!api->physical_protect_now) { - return -ENOTSUP; - } - - return api->physical_protect_now(dev, all); -} - -/** - * @} - */ -#include <syscalls/cros_flash.h> -#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_FLASH_H_ */ diff --git a/zephyr/include/drivers/cros_kb_raw.h b/zephyr/include/drivers/cros_kb_raw.h deleted file mode 100644 index 1724f59d95..0000000000 --- a/zephyr/include/drivers/cros_kb_raw.h +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Chrome OS-specific API for raw keyboard access - * This exists only support the interface expected by the Chrome OS EC. It seems - * better to implement this so we can make use of most of the existing code in - * its keyboard_scan.c file and thus make sure we operate the same way. - * - * It provides raw access to keyboard GPIOs. - * - * The keyboard matrix is read (by the caller, keyboard_scan.c in ECOS) by - * driving output signals on the column lines and reading the row lines. - * - * This API and any drivers should be removed once we can safely move to using - * the Zephyr kscan API. - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_KB_RAW_H_ -#define ZEPHYR_INCLUDE_DRIVERS_CROS_KB_RAW_H_ - -#include <kernel.h> -#include <device.h> - -/** - * @brief CROS Keyboard Raw Driver APIs - * @defgroup cros_kb_raw_interface CROS Keyboard Raw Driver APIs - * @ingroup io_interfaces - * @{ - */ - -/** - * @cond INTERNAL_HIDDEN - * - * cros keyboard raw driver API definition and system call entry points - * - * (Internal use only.) - */ -typedef int (*cros_kb_raw_api_init)(const struct device *dev); - -typedef int (*cros_kb_raw_api_drive_column)(const struct device *dev, int col); - -typedef int (*cros_kb_raw_api_read_rows)(const struct device *dev); - -typedef int (*cros_kb_raw_api_enable_interrupt)(const struct device *dev, - int enable); - -__subsystem struct cros_kb_raw_driver_api { - cros_kb_raw_api_init init; - cros_kb_raw_api_drive_column drive_colum; - cros_kb_raw_api_read_rows read_rows; - cros_kb_raw_api_enable_interrupt enable_interrupt; -}; - -/** - * @endcond - */ - -/** - * @brief Initialize the raw keyboard interface. - * - * Must be called before any other functions in this interface. - * - * @param dev Pointer to the device structure for the keyboard driver instance. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_kb_raw_init(const struct device *dev); - -static inline int z_impl_cros_kb_raw_init(const struct device *dev) -{ - const struct cros_kb_raw_driver_api *api = - (const struct cros_kb_raw_driver_api *)dev->api; - - if (!api->init) { - return -ENOTSUP; - } - - return api->init(dev); -} - -/** - * @brief Drive the specified column low. - * - * Other columns are tristated. See enum keyboard_column_index for special - * values for <col>. - * - * @param dev Pointer to the device structure for the keyboard driver instance. - * @param col Specified column is driven to low. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_kb_raw_drive_column(const struct device *dev, int col); -static inline int z_impl_cros_kb_raw_drive_column(const struct device *dev, - int col) -{ - const struct cros_kb_raw_driver_api *api = - (const struct cros_kb_raw_driver_api *)dev->api; - - if (!api->drive_colum) { - return -ENOTSUP; - } - - return api->drive_colum(dev, col); -} - -/** - * @brief Read raw row state. - * - * Bits are 1 if signal is present, 0 if not present. - * - * @param dev Pointer to the device structure for the keyboard driver instance. - * - * @return current raw row state value. - */ -__syscall int cros_kb_raw_read_rows(const struct device *dev); -static inline int z_impl_cros_kb_raw_read_rows(const struct device *dev) -{ - const struct cros_kb_raw_driver_api *api = - (const struct cros_kb_raw_driver_api *)dev->api; - - if (!api->read_rows) { - return 0; - } - - return api->read_rows(dev); -} - -/** - * @brief Enable or disable keyboard interrupts. - * - * Enabling interrupts will clear any pending interrupt bits. To avoid missing - * any interrupts that occur between the end of scanning and then, you should - * call cros_kb_raw_read_rows() after this. If it returns non-zero, disable - * interrupts and go back to polling mode instead of waiting for an interrupt. - * - * @param dev Pointer to the device structure for the keyboard driver instance. - * @param enable If 1, enable keyboard interrupt. Otherwise, disable it. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_kb_raw_enable_interrupt(const struct device *dev, - int enable); - -static inline int z_impl_cros_kb_raw_enable_interrupt(const struct device *dev, - int enable) -{ - const struct cros_kb_raw_driver_api *api = - (const struct cros_kb_raw_driver_api *)dev->api; - - if (!api->enable_interrupt) { - return -ENOTSUP; - } - - return api->enable_interrupt(dev, enable); -} - -/** - * @} - */ -#include <syscalls/cros_kb_raw.h> -#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_KB_RAW_H_ */ diff --git a/zephyr/include/drivers/cros_rtc.h b/zephyr/include/drivers/cros_rtc.h deleted file mode 100644 index 695aabef73..0000000000 --- a/zephyr/include/drivers/cros_rtc.h +++ /dev/null @@ -1,224 +0,0 @@ -/* 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. - */ - -/** - * @file - * @brief Chrome OS-specific API for real-time clock (RTC). - * This exists only support the interface expected by the Chrome OS EC. It - * provides raw access to RTC module. - * - * This API and any drivers should be removed once we can safely move to using - * the Zephyr rtc API. - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_RTC_H_ -#define ZEPHYR_INCLUDE_DRIVERS_CROS_RTC_H_ - -#include <kernel.h> -#include <device.h> - -/** - * @brief CROS Real-Time Clock (RTC) Driver APIs - * @defgroup cros_rtc_interface CROS RTC Driver APIs - * @ingroup io_interfaces - * @{ - */ - -/** - * @brief RTC alarm callback - * - * @param dev Pointer to the device structure for the RTC driver instance. - */ -typedef void (*cros_rtc_alarm_callback_t)(const struct device *dev); - -/** - * @cond INTERNAL_HIDDEN - * - * cros real-time clock driver API definition and system call entry points - * - * (Internal use only.) - */ -typedef int (*cros_rtc_api_configure)(const struct device *dev, - cros_rtc_alarm_callback_t callback); - -typedef int (*cros_rtc_api_get_value)(const struct device *dev, - uint32_t *value); - -typedef int (*cros_rtc_api_set_value)(const struct device *dev, uint32_t value); - -typedef int (*cros_rtc_api_get_alarm)(const struct device *dev, - uint32_t *seconds, - uint32_t *microseconds); - -typedef int (*cros_rtc_api_set_alarm)(const struct device *dev, - uint32_t seconds, uint32_t microseconds); - -typedef int (*cros_rtc_api_reset_alarm)(const struct device *dev); - -__subsystem struct cros_rtc_driver_api { - cros_rtc_api_configure configure; - cros_rtc_api_get_value get_value; - cros_rtc_api_set_value set_value; - cros_rtc_api_get_alarm get_alarm; - cros_rtc_api_set_alarm set_alarm; - cros_rtc_api_reset_alarm reset_alarm; -}; - -/** - * @endcond - */ - -/** - * @brief Configure real-time clock callback func. - * - * @param dev Pointer to the device structure for the RTC driver instance. - * @param callback Callback func when RTC alarm issued. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - * @retval -EINVAL Not valid callback func. - */ -__syscall int cros_rtc_configure(const struct device *dev, - cros_rtc_alarm_callback_t callback); -static inline int z_impl_cros_rtc_configure(const struct device *dev, - cros_rtc_alarm_callback_t callback) -{ - const struct cros_rtc_driver_api *api = - (const struct cros_rtc_driver_api *)dev->api; - - if (!api->configure) { - return -ENOTSUP; - } - - return api->configure(dev, callback); -} - -/** - * @brief Get the current real-time clock value. - * - * @param dev Pointer to the device structure for the RTC driver instance. - * @param value Pointer to the number of current real-time clock value. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_rtc_get_value(const struct device *dev, uint32_t *value); -static inline int z_impl_cros_rtc_get_value(const struct device *dev, - uint32_t *value) -{ - const struct cros_rtc_driver_api *api = - (const struct cros_rtc_driver_api *)dev->api; - - if (!api->get_value) { - return -ENOTSUP; - } - - return api->get_value(dev, value); -} - -/** - * @brief Set a desired value to real-time clock. - * - * @param dev Pointer to the device structure for the RTC driver instance. - * @param value Number of desired real-time clock value. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_rtc_set_value(const struct device *dev, uint32_t value); -static inline int z_impl_cros_rtc_set_value(const struct device *dev, - uint32_t value) -{ - const struct cros_rtc_driver_api *api = - (const struct cros_rtc_driver_api *)dev->api; - - if (!api->set_value) { - return -ENOTSUP; - } - - return api->set_value(dev, value); -} - -/** - * @brief Get a given time when an RTC alarm interrupt issued. - * - * @param dev Pointer to the device structure for the RTC driver instance. - * @param seconds Pointer to number of seconds before RTC alarm issued. - * @param microseconds Pointer to number of micro-secs before RTC alarm issued. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_rtc_get_alarm(const struct device *dev, uint32_t *seconds, - uint32_t *microseconds); - -static inline int z_impl_cros_rtc_get_alarm(const struct device *dev, - uint32_t *seconds, - uint32_t *microseconds) -{ - const struct cros_rtc_driver_api *api = - (const struct cros_rtc_driver_api *)dev->api; - - if (!api->get_alarm) { - return 0; - } - - return api->get_alarm(dev, seconds, microseconds); -} - -/** - * @brief Set up an RTC alarm interrupt at a given time from now - * - * @param dev Pointer to the device structure for the RTC driver instance. - * @param seconds Number of seconds before RTC alarm issued. - * @param microseconds Number of microseconds before alarm RTC issued. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_rtc_set_alarm(const struct device *dev, uint32_t seconds, - uint32_t microseconds); - -static inline int z_impl_cros_rtc_set_alarm(const struct device *dev, - uint32_t seconds, - uint32_t microseconds) -{ - const struct cros_rtc_driver_api *api = - (const struct cros_rtc_driver_api *)dev->api; - - if (!api->set_alarm) { - return 0; - } - - return api->set_alarm(dev, seconds, microseconds); -} - -/** - * @brief Disable and clear the RTC alarm interrupt. - * - * @param dev Pointer to the device structure for the RTC driver instance. - * - * @return 0 If successful. - * @retval -ENOTSUP Not supported api function. - */ -__syscall int cros_rtc_reset_alarm(const struct device *dev); - -static inline int z_impl_cros_rtc_reset_alarm(const struct device *dev) -{ - const struct cros_rtc_driver_api *api = - (const struct cros_rtc_driver_api *)dev->api; - - if (!api->reset_alarm) { - return -ENOTSUP; - } - - return api->reset_alarm(dev); -} - -/** - * @} - */ -#include <syscalls/cros_rtc.h> -#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_RTC_H_ */ diff --git a/zephyr/include/drivers/cros_shi.h b/zephyr/include/drivers/cros_shi.h deleted file mode 100644 index aab3507dd3..0000000000 --- a/zephyr/include/drivers/cros_shi.h +++ /dev/null @@ -1,89 +0,0 @@ -/* 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. - */ - -/** - * @file - * @brief Chrome OS-specific API for Serial Host Interface (SHI) - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_SHI_H_ -#define ZEPHYR_INCLUDE_DRIVERS_CROS_SHI_H_ - -/** - * @brief CROS Serial Host Interface Driver APIs - * @defgroup cros_shi_interface CROS Serial Host Interface Driver APIs - * @ingroup io_interfaces - * @{ - */ - -#include <kernel.h> -#include <device.h> - -/** - * @cond INTERNAL_HIDDEN - * - * cros Serial Host Interface driver API definition and system call entry points - * - * (Internal use only.) - */ -typedef int (*cros_shi_api_enable)(const struct device *dev); - -typedef int (*cros_shi_api_disable)(const struct device *dev); - -/** @brief Driver API structure. */ -__subsystem struct cros_shi_driver_api { - cros_shi_api_enable enable; - cros_shi_api_disable disable; -}; - -/** - * @brief Enable SHI module. - * - * @param dev Pointer to the device structure for the driver instance. - * - * @retval non-negative if successful. - * @retval Negative errno code if failure. - */ -__syscall int cros_shi_enable(const struct device *dev); - -static inline int z_impl_cros_shi_enable(const struct device *dev) -{ - const struct cros_shi_driver_api *api = - (const struct cros_shi_driver_api *)dev->api; - - if (!api->enable) { - return -ENOTSUP; - } - - return api->enable(dev); -} - -/** - * @brief Disable SHI module. - * - * @param dev Pointer to the device structure for the driver instance. - * - * @retval no return if successful. - * @retval Negative errno code if failure. - */ -__syscall int cros_shi_disable(const struct device *dev); - -static inline int z_impl_cros_shi_disable(const struct device *dev) -{ - const struct cros_shi_driver_api *api = - (const struct cros_shi_driver_api *)dev->api; - - if (!api->disable) { - return -ENOTSUP; - } - - return api->disable(dev); -} - -/** - * @} - */ -#include <syscalls/cros_shi.h> -#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_SHI_H_ */ diff --git a/zephyr/include/drivers/cros_system.h b/zephyr/include/drivers/cros_system.h deleted file mode 100644 index b0e06f1b59..0000000000 --- a/zephyr/include/drivers/cros_system.h +++ /dev/null @@ -1,302 +0,0 @@ -/* 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. - */ - -/** - * @file - * @brief Public API for cros system drivers - */ - -#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_SYSTEM_H_ -#define ZEPHYR_INCLUDE_DRIVERS_CROS_SYSTEM_H_ - -/** - * @brief cros system Interface - * @defgroup cros_system_interface cros system Interface - * @ingroup io_interfaces - * @{ - */ - -#include <kernel.h> -#include <device.h> - -/** - * @brief system_reset_cause enum - * Identify the reset cause. - */ -enum system_reset_cause { - /* the reset is triggered by VCC power-up */ - POWERUP = 0, - /* the reset is triggered by external VCC1 reset pin */ - VCC1_RST_PIN = 1, - /* the reset is triggered by ICE debug reset request */ - DEBUG_RST = 2, - /* the reset is triggered by watchdog */ - WATCHDOG_RST = 3, - /* unknown reset type */ - UNKNOWN_RST, -}; - -/** - * @brief Get a node from path '/hibernate_wakeup_pins' which has a property - * 'wakeup-pins' contains GPIO list for hibernate wake-up - * - * @return node identifier with that path. - */ -#define SYSTEM_DT_NODE_HIBERNATE_CONFIG DT_INST(0, cros_ec_hibernate_wake_pins) - -/** - * @brief Get the length of 'wakeup-pins' property - * - * @return length of 'wakeup-pins' prop which type is 'phandles' - */ -#define SYSTEM_DT_NODE_WAKEUP_PIN_LEN \ - DT_PROP_LEN(SYSTEM_DT_NODE_HIBERNATE_CONFIG, wakeup_pins) - -/** - * @brief Get a node identifier from a phandle in property 'wakeup-pins' at - * index i. - * - * @param i index of 'wakeup-pins' prop which type is 'phandles' - * @return node identifier with that path. - */ -#define SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i) \ - DT_PHANDLE_BY_IDX(SYSTEM_DT_NODE_HIBERNATE_CONFIG, wakeup_pins, i) - -/** - * @brief Get the enum using in chromium system by index i in 'wakeup-pins' - * list. - * - * @param i index of 'wakeup-pins' prop which type is 'phandles' - * @return GPIO enumeration - */ -#define SYSTEM_DT_WAKEUP_GPIO_ENUM_BY_IDX(i, _) \ - COND_CODE_1(DT_NODE_HAS_PROP(SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i), \ - enum_name), \ - (GPIO_SIGNAL(SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i)), ), ()) - -/** - * @typedef cros_system_get_reset_cause_api - * @brief Callback API for getting reset cause instance. - * See cros_system_get_reset_cause() for argument descriptions - */ -typedef int (*cros_system_get_reset_cause_api)(const struct device *dev); - -/** - * @typedef cros_system_soc_reset_api - * @brief Callback API for soc-reset instance. - * See cros_system_soc_reset() for argument descriptions - */ -typedef int (*cros_system_soc_reset_api)(const struct device *dev); - -/** - * @typedef cros_system_hibernate_api - * @brief Callback API for entering hibernate state (lowest EC power state). - * See cros_system_hibernate() for argument descriptions - */ -typedef int (*cros_system_hibernate_api)(const struct device *dev, - uint32_t seconds, - uint32_t microseconds); - -/** - * @typedef cros_system_chip_vendor_api - * @brief Callback API for getting the chip vendor. - * See cros_system_chip_vendor() for argument descriptions - */ -typedef const char *(*cros_system_chip_vendor_api)(const struct device *dev); - -/** - * @typedef cros_system_chip_name_api - * @brief Callback API for getting the chip name. - * See cros_system_chip_name() for argument descriptions - */ -typedef const char *(*cros_system_chip_name_api)(const struct device *dev); - -/** - * @typedef cros_system_chip_revision_api - * @brief Callback API for getting the chip revision. - * See cros_system_chip_revision() for argument descriptions - */ -typedef const char *(*cros_system_chip_revision_api)(const struct device *dev); - -/** - * @typedef cros_system_get_deep_sleep_ticks_api - * @brief Callback API for getting number of ticks spent in deep sleep. - * See cros_system_deep_sleep_ticks() for argument descriptions - */ -typedef uint64_t (*cros_system_deep_sleep_ticks_api)(const struct device *dev); - -/** @brief Driver API structure. */ -__subsystem struct cros_system_driver_api { - cros_system_get_reset_cause_api get_reset_cause; - cros_system_soc_reset_api soc_reset; - cros_system_hibernate_api hibernate; - cros_system_chip_vendor_api chip_vendor; - cros_system_chip_name_api chip_name; - cros_system_chip_revision_api chip_revision; - cros_system_deep_sleep_ticks_api deep_sleep_ticks; -}; - -/** - * @brief Get the chip-reset cause - * - * @param dev Pointer to the device structure for the driver instance. - * - * @retval non-negative if successful. - * @retval Negative errno code if failure. - */ -__syscall int cros_system_get_reset_cause(const struct device *dev); - -static inline int z_impl_cros_system_get_reset_cause(const struct device *dev) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->get_reset_cause) { - return -ENOTSUP; - } - - return api->get_reset_cause(dev); -} - -/** - * @brief reset the soc - * - * @param dev Pointer to the device structure for the driver instance. - * - * @retval no return if successful. - * @retval Negative errno code if failure. - */ -__syscall int cros_system_soc_reset(const struct device *dev); - -static inline int z_impl_cros_system_soc_reset(const struct device *dev) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->soc_reset) { - return -ENOTSUP; - } - - return api->soc_reset(dev); -} - -/** - * @brief put the EC in hibernate (lowest EC power state). - * - * @param dev Pointer to the device structure for the driver instance. - * @param seconds Number of seconds before EC enters hibernate state. - * @param microseconds Number of micro-secs before EC enters hibernate state. - - * @retval no return if successful. - * @retval Negative errno code if failure. - */ -__syscall int cros_system_hibernate(const struct device *dev, uint32_t seconds, - uint32_t microseconds); - -static inline int z_impl_cros_system_hibernate(const struct device *dev, - uint32_t seconds, - uint32_t microseconds) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->hibernate) { - return -ENOTSUP; - } - - return api->hibernate(dev, seconds, microseconds); -} - -/** - * @brief Get the chip vendor. - * - * @param dev Pointer to the device structure for the driver instance. - * @retval Chip vendor string if successful. - * @retval Null string if failure. - */ -__syscall const char *cros_system_chip_vendor(const struct device *dev); - -static inline const char * -z_impl_cros_system_chip_vendor(const struct device *dev) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->chip_vendor) { - return ""; - } - - return api->chip_vendor(dev); -} - -/** - * @brief Get the chip name. - * - * @param dev Pointer to the device structure for the driver instance. - * @retval Chip name string if successful. - * @retval Null string if failure. - */ -__syscall const char *cros_system_chip_name(const struct device *dev); - -static inline const char *z_impl_cros_system_chip_name(const struct device *dev) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->chip_name) { - return ""; - } - - return api->chip_name(dev); -} - -/** - * @brief Get the chip revision. - * - * @param dev Pointer to the device structure for the driver instance. - * @retval Chip revision string if successful. - * @retval Null string if failure. - */ -__syscall const char *cros_system_chip_revision(const struct device *dev); - -static inline const char * -z_impl_cros_system_chip_revision(const struct device *dev) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->chip_revision) { - return ""; - } - - return api->chip_revision(dev); -} - -/** - * @brief Get total number of ticks spent in deep sleep. - * - * @param dev Pointer to the device structure for the driver instance. - * @retval Number of ticks spent in deep sleep. - */ -__syscall uint64_t cros_system_deep_sleep_ticks(const struct device *dev); - -static inline uint64_t -z_impl_cros_system_deep_sleep_ticks(const struct device *dev) -{ - const struct cros_system_driver_api *api = - (const struct cros_system_driver_api *)dev->api; - - if (!api->deep_sleep_ticks) { - return 0; - } - - return api->deep_sleep_ticks(dev); -} - -/** - * @} - */ -#include <syscalls/cros_system.h> -#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_SYSTEM_H_ */ diff --git a/zephyr/include/dt-bindings/charger/intersil_isl9241.h b/zephyr/include/dt-bindings/charger/intersil_isl9241.h deleted file mode 100644 index 5a2742570e..0000000000 --- a/zephyr/include/dt-bindings/charger/intersil_isl9241.h +++ /dev/null @@ -1,18 +0,0 @@ -/* 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. - */ - -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CHARGER_INTERSIL_ISL9241_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_CHARGER_INTERSIL_ISL9241_H_ - -#define SWITCHING_FREQ_1420KHZ 0 -#define SWITCHING_FREQ_1180KHZ 1 -#define SWITCHING_FREQ_1020KHZ 2 -#define SWITCHING_FREQ_890KHZ 3 -#define SWITCHING_FREQ_808KHZ 4 -#define SWITCHING_FREQ_724KHZ 5 -#define SWITCHING_FREQ_656KHZ 6 -#define SWITCHING_FREQ_600KHZ 7 - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CHARGER_INTERSIL_ISL9241_H_ */ diff --git a/zephyr/include/dt-bindings/cros-kb-raw/ite_cros_kb_raw.h b/zephyr/include/dt-bindings/cros-kb-raw/ite_cros_kb_raw.h deleted file mode 100644 index f88efed949..0000000000 --- a/zephyr/include/dt-bindings/cros-kb-raw/ite_cros_kb_raw.h +++ /dev/null @@ -1,8 +0,0 @@ -/* 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. - */ -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_ITE_CROS_KB_RAW_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_ITE_CROS_KB_RAW_H_ - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_ITE_CROS_KB_RAW_H_ */ diff --git a/zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h b/zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h deleted file mode 100644 index f979ae8481..0000000000 --- a/zephyr/include/dt-bindings/cros-kb-raw/npcx_cros_kb_raw.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_NPCX_CROS_KB_RAW_H_ -#define ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_NPCX_CROS_KB_RAW_H_ - -#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CROS_KB_RAW_NPCX_CROS_KB_RAW_H_ */ diff --git a/zephyr/include/dt-bindings/gpio_defines.h b/zephyr/include/dt-bindings/gpio_defines.h deleted file mode 100644 index 37552b8d6c..0000000000 --- a/zephyr/include/dt-bindings/gpio_defines.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 Google LLC. - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef DT_BINDINGS_GPIO_DEFINES_H_ -#define DT_BINDINGS_GPIO_DEFINES_H_ - -#include <dt-bindings/gpio/gpio.h> - -/* - * The GPIO_INPUT and GPIO_OUTPUT defines are normally not available to - * the device tree. For GPIOs that are controlled by the platform/ec module, we - * allow device tree to set the initial state. - * - * Note the raw defines (e.g. GPIO_OUTPUT) in this file are copies from - * <drivers/gpio.h> - * - * The combined defined (e.g. GPIO_OUT_LOW) have been renamed to fit with - * gpio defined in platform/ec codebase. - */ - -/** Enables pin as input. */ -#define GPIO_INPUT (1U << 8) - -/** Enables pin as output, no change to the output state. */ -#define GPIO_OUTPUT (1U << 9) - -/* Initializes output to a low state. */ -#define GPIO_OUTPUT_INIT_LOW (1U << 10) - -/* Initializes output to a high state. */ -#define GPIO_OUTPUT_INIT_HIGH (1U << 11) - -/* Configures GPIO pin as output and initializes it to a low state. */ -#define GPIO_OUTPUT_LOW (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW) - -/* Configures GPIO pin as output and initializes it to a high state. */ -#define GPIO_OUTPUT_HIGH (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH) - -/* Configures GPIO pin as input with pull-up. */ -#define GPIO_INPUT_PULL_UP (GPIO_INPUT | GPIO_PULL_UP) - -/* Configures GPIO pin as input with pull-down. */ -#define GPIO_INPUT_PULL_DOWN (GPIO_INPUT | GPIO_PULL_DOWN) - -/** Configures GPIO pin as output and initializes it to a low state. */ -#define GPIO_OUT_LOW (GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW) - -/** Configures GPIO pin as output and initializes it to a high state. */ -#define GPIO_OUT_HIGH (GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH) - -/** Configures GPIO pin as ODR output and initializes it to a low state. */ -#define GPIO_ODR_LOW (GPIO_OUT_LOW | GPIO_OPEN_DRAIN) - -/** Configures GPIO pin as ODR output and initializes it to a high state. */ -#define GPIO_ODR_HIGH (GPIO_OUT_HIGH | GPIO_OPEN_DRAIN) - -#endif /* DT_BINDINGS_GPIO_DEFINES_H_ */ diff --git a/zephyr/include/dt-bindings/motionsense/utils.h b/zephyr/include/dt-bindings/motionsense/utils.h deleted file mode 100644 index 7f0e5f5fc8..0000000000 --- a/zephyr/include/dt-bindings/motionsense/utils.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef DT_BINDINGS_UTILS_H -#define DT_BINDINGS_UTILS_H - -#define BIT(x) (1U << (x)) -#define ROUND_UP_FLAG BIT(31) -#define USEC_PER_MSEC 1000 - -#endif /* DT_BINDINGS_UTILS_H */ diff --git a/zephyr/include/dt-bindings/wake_mask_event_defines.h b/zephyr/include/dt-bindings/wake_mask_event_defines.h deleted file mode 100644 index 0413fa249c..0000000000 --- a/zephyr/include/dt-bindings/wake_mask_event_defines.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2021 Google LLC. - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef DT_BINDINGS_WAKE_MASK_EVENT_DEFINES_H_ -#define DT_BINDINGS_WAKE_MASK_EVENT_DEFINES_H_ - -#ifndef BIT -#define BIT(n) (1U << n) -#endif - -/* - * NOTE: The convention in the Zephyr code is to have the public header file - * include the dt-binding header file to avoid duplicate definitions. - * However, ec_commands.h is shared with the linux kernel so we can't do that. - * - * Please consult include/ec_commands.h for explanations of the macros - * defined in this file. - */ - -#define MKBP_EVENT_KEY_MATRIX BIT(0) -#define MKBP_EVENT_HOST_EVENT BIT(1) -#define MKBP_EVENT_SENSOR_FIFO BIT(2) -#define MKBP_EVENT_BUTTON BIT(3) -#define MKBP_EVENT_SWITCH BIT(4) -#define MKBP_EVENT_FINGERPRINT BIT(5) -#define MKBP_EVENT_SYSRQ BIT(6) -#define MKBP_EVENT_HOST_EVENT64 BIT(7) -#define MKBP_EVENT_CEC_EVENT BIT(8) -#define MKBP_EVENT_CEC_MESSAGE BIT(9) -#define MKBP_EVENT_DP_ALT_MODE_ENTERED BIT(10) -#define MKBP_EVENT_ONLINE_CALIBRATION BIT(11) -#define MKBP_EVENT_PCHG BIT(12) - -#define HOST_EVENT_MASK(event) ((event) >> 1) - -#define HOST_EVENT_NONE BIT(0) -#define HOST_EVENT_LID_CLOSED BIT(1) -#define HOST_EVENT_LID_OPEN BIT(2) -#define HOST_EVENT_POWER_BUTTON BIT(3) -#define HOST_EVENT_AC_CONNECTED BIT(4) -#define HOST_EVENT_AC_DISCONNECTED BIT(5) -#define HOST_EVENT_BATTERY_LOW BIT(6) -#define HOST_EVENT_BATTERY_CRITICAL BIT(7) -#define HOST_EVENT_BATTERY BIT(8) -#define HOST_EVENT_THERMAL_THRESHOLD BIT(9) -#define HOST_EVENT_DEVICE BIT(10) -#define HOST_EVENT_THERMAL BIT(11) -#define HOST_EVENT_USB_CHARGER BIT(12) -#define HOST_EVENT_KEY_PRESSED BIT(13) -#define HOST_EVENT_INTERFACE_READY BIT(14) -#define HOST_EVENT_KEYBOARD_RECOVERY BIT(15) -#define HOST_EVENT_THERMAL_SHUTDOWN BIT(16) -#define HOST_EVENT_BATTERY_SHUTDOWN BIT(17) -#define HOST_EVENT_THROTTLE_START BIT(18) -#define HOST_EVENT_THROTTLE_STOP BIT(19) -#define HOST_EVENT_HANG_DETECT BIT(20) -#define HOST_EVENT_HANG_REBOOT BIT(21) -#define HOST_EVENT_PD_MCU BIT(22) -#define HOST_EVENT_BATTERY_STATUS BIT(23) -#define HOST_EVENT_PANIC BIT(24) -#define HOST_EVENT_KEYBOARD_FASTBOOT BIT(25) -#define HOST_EVENT_RTC BIT(26) -#define HOST_EVENT_MKBP BIT(27) -#define HOST_EVENT_USB_MUX BIT(28) -#define HOST_EVENT_MODE_CHANGE BIT(29) -#define HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT BIT(30) -#define HOST_EVENT_WOV BIT(31) -#define HOST_EVENT_INVALID BIT(32) - -#endif /* DT_BINDINGS_WAKE_MASK_EVENT_DEFINES_H_ */ - diff --git a/zephyr/include/emul/emul_bb_retimer.h b/zephyr/include/emul/emul_bb_retimer.h deleted file mode 100644 index c63cc651c0..0000000000 --- a/zephyr/include/emul/emul_bb_retimer.h +++ /dev/null @@ -1,89 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for BB retimer emulator - */ - -#ifndef __EMUL_BB_RETIMER_H -#define __EMUL_BB_RETIMER_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -/** - * @brief BB retimer emulator backend API - * @defgroup bb_emul BB retimer emulator - * @{ - * - * BB retimer emulator supports access to all its registers using I2C messages. - * It supports not four bytes writes by padding zeros (the same as real - * device), but show warning in that case. - * Application may alter emulator state: - * - * - define a Device Tree overlay file to set default vendor ID and which - * inadvisable driver behaviour should be treated as errors - * - call @ref bb_emul_set_reg and @ref bb_emul_get_reg to set and get value - * of BB retimers registers - * - call bb_emul_set_err_* to change emulator behaviour on inadvisable driver - * behaviour - * - call functions from emul_common_i2c.h to setup custom handlers for I2C - * messages - */ - -/** - * @brief Get pointer to BB retimer emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to BB retimer emulator - */ -struct i2c_emul *bb_emul_get(int ord); - -/** - * @brief Set value of given register of BB retimer - * - * @param emul Pointer to BB retimer emulator - * @param reg Register address which value will be changed - * @param val New value of the register - */ -void bb_emul_set_reg(struct i2c_emul *emul, int reg, uint32_t val); - -/** - * @brief Get value of given register of BB retimer - * - * @param emul Pointer to BB retimer emulator - * @param reg Register address - * - * @return Value of the register - */ -uint32_t bb_emul_get_reg(struct i2c_emul *emul, int reg); - -/** - * @brief Set if error should be generated when read only register is being - * written - * - * @param emul Pointer to BB retimer emulator - * @param set Check for this error - */ -void bb_emul_set_err_on_ro_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when reserved bits of register are - * not set to 0 on write I2C message - * - * @param emul Pointer to BB retimer emulator - * @param set Check for this error - */ -void bb_emul_set_err_on_rsvd_write(struct i2c_emul *emul, bool set); - -/** - * @} - */ - -#endif /* __EMUL_BB_RETIMER */ diff --git a/zephyr/include/emul/emul_bma255.h b/zephyr/include/emul/emul_bma255.h deleted file mode 100644 index b2f71df88b..0000000000 --- a/zephyr/include/emul/emul_bma255.h +++ /dev/null @@ -1,191 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for BMA255 emulator - */ - -#ifndef __EMUL_BMA255_H -#define __EMUL_BMA255_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -/** - * @brief BMA255 emulator backend API - * @defgroup bma_emul BMA255 emulator - * @{ - * - * BMA255 emulator supports responses to all write and read I2C messages. - * Accelerometer registers are obtained from internal emulator state, range - * register and offset. Only fast compensation is supported by default handler. - * Registers backed in NVM are fully supported (GP0, GP1, offset). For proper - * support for interrupts and FIFO, user needs to use custom handlers. - * Application may alter emulator state: - * - * - define a Device Tree overlay file to set default NVM content, default - * static accelerometer value and which inadvisable driver behaviour should - * be treated as errors - * - call @ref bma_emul_set_reg and @ref bma_emul_get_reg to set and get value - * of BMA255 registers - * - call @ref bma_emul_set_off and @ref bma_emul_set_off to set and get - * internal offset value - * - call @ref bma_emul_set_acc and @ref bma_emul_set_acc to set and get - * accelerometer value - * - call bma_emul_set_err_* to change emulator behaviour on inadvisable driver - * behaviour - * - call functions from emul_common_i2c.h to setup custom handlers for I2C - * messages - */ - -/** - * Axis argument used in @ref bma_emul_set_acc @ref bma_emul_get_acc - * @ref bma_emul_set_off and @ref bma_emul_get_off - */ -#define BMA_EMUL_AXIS_X 0 -#define BMA_EMUL_AXIS_Y 1 -#define BMA_EMUL_AXIS_Z 2 - -/** - * Acceleration 1g in internal emulator units. It is helpful for using - * functions @ref bma_emul_set_acc @ref bma_emul_get_acc - * @ref bma_emul_set_off and @ref bma_emul_get_off - */ -#define BMA_EMUL_1G BIT(10) - -/** - * @brief Get pointer to BMA255 emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to BMA255 emulator - */ -struct i2c_emul *bma_emul_get(int ord); - -/** - * @brief Set value of given register of BMA255 - * - * @param emul Pointer to BMA255 emulator - * @param reg Register address which value will be changed - * @param val New value of the register - */ -void bma_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val); - -/** - * @brief Get value of given register of BMA255 - * - * @param emul Pointer to BMA255 emulator - * @param reg Register address - * - * @return Value of the register - */ -uint8_t bma_emul_get_reg(struct i2c_emul *emul, int reg); - -/** - * @brief Get internal value of offset for given axis - * - * @param emul Pointer to BMA255 emulator - * @param axis Axis to access: 0 - X, 1 - Y, 2 - Z - * - * @return Offset of given axis. LSB is 0.97mg - */ -int16_t bma_emul_get_off(struct i2c_emul *emul, int axis); - -/** - * @brief Set internal value of offset for given axis - * - * @param emul Pointer to BMA255 emulator - * @param axis Axis to access: 0 - X, 1 - Y, 2 - Z - * @param val New value of offset. LSB is 0.97mg - */ -void bma_emul_set_off(struct i2c_emul *emul, int axis, int16_t val); - -/** - * @brief Get internal value of accelerometer for given axis - * - * @param emul Pointer to BMA255 emulator - * @param axis Axis to access: 0 - X, 1 - Y, 2 - Z - * - * @return Acceleration of given axis. LSB is 0.97mg - */ -int16_t bma_emul_get_acc(struct i2c_emul *emul, int axis); - -/** - * @brief Set internal value of accelerometr for given axis - * - * @param emul Pointer to BMA255 emulator - * @param axis Axis to access: 0 - X, 1 - Y, 2 - Z - * @param val New value of accelerometer axis. LSB is 0.97mg - */ -void bma_emul_set_acc(struct i2c_emul *emul, int axis, int16_t val); - -/** - * @brief Set if error should be generated when fast compensation is triggered - * when not ready flag is set - * - * @param emul Pointer to BMA255 emulator - * @param set Check for this error - */ -void bma_emul_set_err_on_cal_nrdy(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when fast compensation is triggered - * when range is not 2G - * - * @param emul Pointer to BMA255 emulator - * @param set Check for this error - */ -void bma_emul_set_err_on_cal_bad_range(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when read only register is being - * written - * - * @param emul Pointer to BMA255 emulator - * @param set Check for this error - */ -void bma_emul_set_err_on_ro_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when reserved bits of register are - * not set to 0 on write I2C message - * - * @param emul Pointer to BMA255 emulator - * @param set Check for this error - */ -void bma_emul_set_err_on_rsvd_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when MSB register is accessed before - * LSB register - * - * @param emul Pointer to BMA255 emulator - * @param set Check for this error - */ -void bma_emul_set_err_on_msb_first(struct i2c_emul *emul, bool set); - -/** - * @brief Function calculate register that should be accessed when I2C message - * started from @p reg register and now byte number @p bytes is handled. - * This function is used in I2C common emulator code and can be used in - * custom user functions. - * - * @param emul Pointer to BMA255 emulator - * @param reg Starting register - * @param bytes Number of bytes already processed in the I2C message handler - * @param read If current I2C message is read - * - * @retval Register address that should be accessed - */ -int bma_emul_access_reg(struct i2c_emul *emul, int reg, int bytes, bool read); - -/** - * @} - */ - -#endif /* __EMUL_BMA255_H */ diff --git a/zephyr/include/emul/emul_bmi.h b/zephyr/include/emul/emul_bmi.h deleted file mode 100644 index 9eac9c3f85..0000000000 --- a/zephyr/include/emul/emul_bmi.h +++ /dev/null @@ -1,431 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for BMI emulator - */ - -#ifndef __EMUL_BMI_H -#define __EMUL_BMI_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -/** - * @brief BMI emulator backend API - * @defgroup bmi_emul BMI emulator - * @{ - * - * BMI emulator supports responses to all write and read I2C messages. - * Accelerometer and gyroscope registers are obtained from internal emulator - * state, range register and offset. FIFO is fully simulated. Emulator can be - * extended to support more models of BMI. - * Application may alter emulator state: - * - * - define a Device Tree overlay file to set which inadvisable driver behaviour - * should be treated as errors and which model is emulated - * - call @ref bmi_emul_set_reg and @ref bmi_emul_get_reg to set and get value - * of BMI registers - * - call @ref bmi_emul_set_off and @ref bmi_emul_get_off to set and get - * internal offset value - * - call @ref bmi_emul_set_value and @ref bmi_emul_get_value to set and get - * accelerometer or gyroscope value - * - call bmi_emul_set_err_* to change emulator behaviour on inadvisable driver - * behaviour - * - call @ref bmi_emul_simulate_cmd_exec_time to enable or disable simulation - * of command execution time - * - call @ref bmi_emul_append_frame to add frame to FIFO - * - call @reg bmi_emul_set_skipped_frames to generate skip frame on next access - * to FIFO - * - call functions from emul_common_i2c.h to setup custom handlers for I2C - * messages - */ - -/** - * Axis argument used in @ref bmi_emul_set_value @ref bmi_emul_get_value - * @ref bmi_emul_set_off and @ref bmi_emul_get_off - */ -enum bmi_emul_axis { - BMI_EMUL_ACC_X, - BMI_EMUL_ACC_Y, - BMI_EMUL_ACC_Z, - BMI_EMUL_GYR_X, - BMI_EMUL_GYR_Y, - BMI_EMUL_GYR_Z, -}; - -/** BMI emulator models */ -#define BMI_EMUL_160 1 -#define BMI_EMUL_260 2 - -/** Last register supported by emulator */ -#define BMI_EMUL_MAX_REG 0x80 -/** Maximum number of registers that can be backed in NVM */ -#define BMI_EMUL_MAX_NVM_REGS 10 - -/** Headers used in FIFO frames */ -#define BMI_EMUL_FIFO_HEAD_SKIP 0x40 -#define BMI_EMUL_FIFO_HEAD_TIME 0x44 -#define BMI_EMUL_FIFO_HEAD_CONFIG 0x48 -#define BMI_EMUL_FIFO_HEAD_EMPTY 0x80 -#define BMI_EMUL_FIFO_HEAD_DATA 0x80 -#define BMI_EMUL_FIFO_HEAD_DATA_MAG BIT(4) -#define BMI_EMUL_FIFO_HEAD_DATA_GYR BIT(3) -#define BMI_EMUL_FIFO_HEAD_DATA_ACC BIT(2) -#define BMI_EMUL_FIFO_HEAD_DATA_TAG_MASK 0x03 - -/** - * Acceleration 1g in internal emulator units. It is helpful for using - * functions @ref bmi_emul_set_value @ref bmi_emul_get_value - * @ref bmi_emul_set_off and @ref bmi_emul_get_off - */ -#define BMI_EMUL_1G BIT(14) -/** - * Gyroscope 125°/s in internal emulator units. It is helpful for using - * functions @ref bmi_emul_set_value @ref bmi_emul_get_value - * @ref bmi_emul_set_off and @ref bmi_emul_get_off - */ -#define BMI_EMUL_125_DEG_S BIT(15) - -/** Type of frames that can be added to the emulator frames list */ -#define BMI_EMUL_FRAME_CONFIG BIT(0) -#define BMI_EMUL_FRAME_ACC BIT(1) -#define BMI_EMUL_FRAME_MAG BIT(2) -#define BMI_EMUL_FRAME_GYR BIT(3) - -/** - * Code returned by model specific handle_read and handle_write functions, when - * RO register is accessed on write or WO register is accessed on read - */ -#define BMI_EMUL_ACCESS_E 1 - -/** Structure used to describe single FIFO frame */ -struct bmi_emul_frame { - /** Type of frame */ - uint8_t type; - /** Tag added to data frame */ - uint8_t tag; - /** Value used in config frame */ - uint8_t config; - /** Accelerometer sensor values in internal emulator units */ - int32_t acc_x; - int32_t acc_y; - int32_t acc_z; - /** Gyroscope sensor values in internal emulator units */ - int32_t gyr_x; - int32_t gyr_y; - int32_t gyr_z; - /** Magnetometer/other sensor values in internal emulator units */ - int32_t mag_x; - int32_t mag_y; - int32_t mag_z; - int32_t rhall; - - /** Pointer to next frame or NULL */ - struct bmi_emul_frame *next; -}; - -/** Structure describing specific BMI model */ -struct bmi_emul_type_data { - /** Indicate if time frame should follow config frame */ - bool sensortime_follow_config_frame; - - /** - * @brief Compute register address that acctually will be accessed, when - * selected register is @p reg and there was @p byte handled in - * the current I2C message - * - * @param emul Pointer to BMI emulator - * @param reg Selected register - * @param byte Number of handled bytes in the current I2C message - * @param read If current I2C message is read - * - * @return Register address that will be accessed - */ - int (*access_reg)(struct i2c_emul *emul, int reg, int byte, bool read); - - /** - * @brief Model specific write function. It should modify state of - * emulator if required. - * - * @param regs Pointer to array of emulator's registers - * @param emul Pointer to BMI emulator - * @param reg Selected register - * @param byte Number of handled bytes in this write command - * @param val Value that is being written - * - * @return 0 on success - * @return BMI_EMUL_ACCESS_E on RO register access - * @return other on error - */ - int (*handle_write)(uint8_t *regs, struct i2c_emul *emul, int reg, - int byte, uint8_t val); - /** - * @brief Model specific read function. It should modify state of - * emulator if required. @p buf should be set to response value. - * - * @param regs Pointer to array of emulator's registers - * @param emul Pointer to BMI emulator - * @param reg Selected register - * @param byte Byte which is accessed during block read - * @param buf Pointer where read byte should be stored - * - * @return 0 on success - * @return BMI_EMUL_ACCESS_E on WO register access - * @return other on error - */ - int (*handle_read)(uint8_t *regs, struct i2c_emul *emul, int reg, - int byte, char *buf); - /** - * @brief Model specific reset function. It should modify state of - * emulator to imitate after reset conditions. - * - * @param regs Pointer to array of emulator's registers - * @param emul Pointer to BMI emulator - */ - void (*reset)(uint8_t *regs, struct i2c_emul *emul); - - /** Array of reserved bits mask for each register */ - const uint8_t *rsvd_mask; - - /** Array of registers that are backed in NVM */ - const int *nvm_reg; - /** Number of registers backed in NVM */ - int nvm_len; - - /** Gyroscope X axis register */ - int gyr_off_reg; - /** Accelerometer X axis register */ - int acc_off_reg; - /** Gyroscope 9 and 8 bits register */ - int gyr98_off_reg; -}; - -/** - * @brief Get BMI160 model specific structure. - * - * @return Pointer to BMI160 specific structure - */ -const struct bmi_emul_type_data *get_bmi160_emul_type_data(void); -/** - * @brief Get BMI260 model specific structure. - * - * @return Pointer to BMI260 specific structure - */ -const struct bmi_emul_type_data *get_bmi260_emul_type_data(void); - -/** - * @brief Get pointer to BMI emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to BMI emulator - */ -struct i2c_emul *bmi_emul_get(int ord); - -/** - * @brief Set value of given register of BMI - * - * @param emul Pointer to BMI emulator - * @param reg Register address which value will be changed - * @param val New value of the register - */ -void bmi_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val); - -/** - * @brief Get value of given register of BMI - * - * @param emul Pointer to BMI emulator - * @param reg Register address - * - * @return Value of the register - */ -uint8_t bmi_emul_get_reg(struct i2c_emul *emul, int reg); - -/** - * @brief Get internal value of offset for given axis and sensor - * - * @param emul Pointer to BMI emulator - * @param axis Axis to access - * - * @return Offset of given axis. LSB for accelerometer is 0.061mg and for - * gyroscope is 0.0037°/s. - */ -int16_t bmi_emul_get_off(struct i2c_emul *emul, enum bmi_emul_axis axis); - -/** - * @brief Set internal value of offset for given axis and sensor - * - * @param emul Pointer to BMI emulator - * @param axis Axis to access - * @param val New value of given axis. LSB for accelerometer is 0.061mg and for - * gyroscope is 0.0037°/s. - */ -void bmi_emul_set_off(struct i2c_emul *emul, enum bmi_emul_axis axis, - int16_t val); - -/** - * @brief Get internal value of sensor for given axis - * - * @param emul Pointer to BMI emulator - * @param axis Axis to access - * - * @return Sensor value of given axis. LSB for accelerometer is 0.061mg and for - * gyroscope is 0.0037°/s. - */ -int32_t bmi_emul_get_value(struct i2c_emul *emul, enum bmi_emul_axis axis); - -/** - * @brief Set internal value of sensor for given axis - * - * @param emul Pointer to BMI emulator - * @param axis Axis to access - * @param val New value of given axis. LSB for accelerometer is 0.061mg and for - * gyroscope is 0.0037°/s. - */ -void bmi_emul_set_value(struct i2c_emul *emul, enum bmi_emul_axis axis, - int32_t val); - -/** - * @brief Set if error should be generated when read only register is being - * written - * - * @param emul Pointer to BMI emulator - * @param set Check for this error - */ -void bmi_emul_set_err_on_ro_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when reserved bits of register are - * not set to 0 on write I2C message - * - * @param emul Pointer to BMI emulator - * @param set Check for this error - */ -void bmi_emul_set_err_on_rsvd_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when write only register is read - * - * @param emul Pointer to BMI emulator - * @param set Check for this error - */ -void bmi_emul_set_err_on_wo_read(struct i2c_emul *emul, bool set); - -/** - * @brief Set if effect of simulated command should take place after simulated - * time pass from issuing command. - * - * @param emul Pointer to BMI emulator - * @param set Simulate command execution time - */ -void bmi_emul_simulate_cmd_exec_time(struct i2c_emul *emul, bool set); - -/** - * @brief Set number of skipped frames. It will generate skip frame on next - * access to FIFO. After that number of skipped frames is reset to 0. - * - * @param emul Pointer to BMI emulator - * @param skip Number of skipped frames - */ -void bmi_emul_set_skipped_frames(struct i2c_emul *emul, uint8_t skip); - -/** - * @brief Clear all FIFO frames, set current frame to empty and reset fifo_skip - * counter - * - * @param emul Pointer to BMI emulator - * @param tag_time Indicate if sensor time should be included in empty frame - * @param header Indicate if header should be included in frame - */ -void bmi_emul_flush_fifo(struct i2c_emul *emul, bool tag_time, bool header); - -/** - * @brief Restore registers backed by NVM, reset sensor time and flush FIFO - * - * @param emul Pointer to BMI emulator - */ -void bmi_emul_reset_common(struct i2c_emul *emul, bool tag_time, bool header); - -/** - * @brief Set command end time to @p time ms from now - * - * @param emul Pointer to BMI emulator - * @param time After this amount of ms command should end - */ -void bmi_emul_set_cmd_end_time(struct i2c_emul *emul, int time); - -/** - * @brief Check if command should end - * - * @param emul Pointer to BMI emulator - */ -bool bmi_emul_is_cmd_end(struct i2c_emul *emul); - -/** - * @brief Append FIFO @p frame to the emulator list of frames. It can be read - * using I2C interface. - * - * @param emul Pointer to BMI emulator - * @param frame Pointer to new FIFO frame. Pointed data has to be valid while - * emulator may use this frame (until flush of FIFO or reading - * it out through I2C) - */ -void bmi_emul_append_frame(struct i2c_emul *emul, struct bmi_emul_frame *frame); - -/** - * @brief Get length of all frames that are on the emulator list of frames. - * - * @param emul Pointer to BMI emulator - * @param tag_time Indicate if sensor time should be included in empty frame - * @param header Indicate if header should be included in frame - */ -uint16_t bmi_emul_fifo_len(struct i2c_emul *emul, bool tag_time, bool header); - -/** - * @brief Get next byte that should be returned on FIFO data access. - * - * @param emul Pointer to BMI emulator - * @param byte Which byte of block read command is currently handled - * @param tag_time Indicate if sensor time should be included in empty frame - * @param header Indicate if header should be included in frame - * @param acc_shift How many bits should be right shifted from accelerometer - * data - * @param gyr_shift How many bits should be right shifted from gyroscope data - * - * @return FIFO data byte - */ -uint8_t bmi_emul_get_fifo_data(struct i2c_emul *emul, int byte, - bool tag_time, bool header, int acc_shift, - int gyr_shift); - -/** - * @brief Saves current internal state of sensors to emulator's registers. - * - * @param emul Pointer to BMI emulator - * @param acc_shift How many bits should be right shifted from accelerometer - * data - * @param gyr_shift How many bits should be right shifted from gyroscope data - * @param acc_reg Register which holds LSB of accelerometer sensor - * @param gyr_reg Register which holds LSB of gyroscope sensor - * @param sensortime_reg Register which holds LSB of sensor time - * @param acc_off_en Indicate if accelerometer offset should be included to - * sensor data value - * @param gyr_off_en Indicate if gyroscope offset should be included to - * sensor data value - */ -void bmi_emul_state_to_reg(struct i2c_emul *emul, int acc_shift, - int gyr_shift, int acc_reg, int gyr_reg, - int sensortime_reg, bool acc_off_en, - bool gyr_off_en); - -/** - * @} - */ - -#endif /* __EMUL_BMI_H */ diff --git a/zephyr/include/emul/emul_common_i2c.h b/zephyr/include/emul/emul_common_i2c.h deleted file mode 100644 index 0457842a71..0000000000 --- a/zephyr/include/emul/emul_common_i2c.h +++ /dev/null @@ -1,369 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Common code used by devices emulated on I2C bus - */ - -#ifndef __EMUL_COMMON_I2C_H -#define __EMUL_COMMON_I2C_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -/** - * @brief Common I2C API useb by emulators - * @defgroup i2c_common_emul common I2C emulator's code - * @{ - * - * I2C common emulator functionality is dispatching I2C messages. It supports - * setting custom user handler and selecting register on which access emulator - * should fail. To use common I2C handling, emulator should call or setup - * @ref i2c_common_emul_transfer as transfer callback of i2c_emul_api and - * register emulator with @ref i2c_common_emul_data structure as data. In data - * structure, emualtor should set callback called before read/write I2C message - * (start_read, start_write), for each byte of I2C message (read_byte, - * write_byte) and after I2C message (finish_read, finish_byte). If specific - * function is not needed by emulator, than it can be set to NULL. - * - * @ref i2c_common_emul_lock_data and @ref i2c_common_emul_unlock_data functions - * may be used to guard emulator data when accessed from multiple threads. - * - * User of emulator with common I2C code can use following API to define custom - * behaviour of emulator: - * - * - call @ref i2c_common_emul_set_read_func and - * @ref i2c_common_emul_set_write_func to setup custom handlers for I2C - * messages - * - call @ref i2c_common_emul_set_read_fail_reg and - * @ref i2c_common_emul_set_write_fail_reg to configure emulator to fail on - * given register read or write - */ - -/** - * Special register values used in @ref i2c_common_emul_set_read_fail_reg and - * @ref i2c_common_emul_set_write_fail_reg - */ -#define I2C_COMMON_EMUL_FAIL_ALL_REG (-1) -#define I2C_COMMON_EMUL_NO_FAIL_REG (-2) - -/** - * Describe if there is no ongoing I2C message or if there is message handled - * at the moment (last message doesn't ended with stop or write is not followed - * by read). - */ -enum i2c_common_emul_msg_state { - I2C_COMMON_EMUL_NONE_MSG, - I2C_COMMON_EMUL_IN_WRITE, - I2C_COMMON_EMUL_IN_READ -}; - -/** - * @brief Function type that is used by I2C device emulator for first byte of - * I2C write message. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by write command (first byte of I2C - * write message) - * - * @return 0 on success - * @return -EIO on error - */ -typedef int (*i2c_common_emul_start_write_func)(struct i2c_emul *emul, int reg); - -/** - * @brief Function type that is used by I2C device emulator at the end of - * I2C write message. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by write command (first byte of I2C - * write message) - * @param bytes Number of bytes received from the I2C write message - * - * @return 0 on success - * @return -EIO on error - */ -typedef int (*i2c_common_emul_finish_write_func)(struct i2c_emul *emul, int reg, - int bytes); - -/** - * @brief Function type that is used by I2C device emulator on each byte of - * I2C write message (except first byte). - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by write command (first byte of I2C - * write message) - * @param val Value of current byte - * @param bytes Number of bytes already received from the I2C write message - * (excluding current byte) - * - * @return 0 on success - * @return -EIO on error - */ -typedef int (*i2c_common_emul_write_byte_func)(struct i2c_emul *emul, int reg, - uint8_t val, int bytes); - -/** - * @brief Function type that is used by I2C device emulator before first byte of - * I2C read message. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by read command (first byte of last - * I2C write message) - * - * @return 0 on success - * @return -EIO on error - */ -typedef int (*i2c_common_emul_start_read_func)(struct i2c_emul *emul, int reg); - -/** - * @brief Function type that is used by I2C device emulator at the end of - * I2C read message. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by read command (first byte of last - * I2C write message) - * @param bytes Number of bytes responeded to the I2C read message - * - * @return 0 on success - * @return -EIO on error - */ -typedef int (*i2c_common_emul_finish_read_func)(struct i2c_emul *emul, int reg, - int bytes); - -/** - * @brief Function type that is used by I2C device emulator on each byte of - * I2C read message. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by read command (first byte of last - * I2C write message) - * @param val Pointer to buffer where current response byte should be stored - * @param bytes Number of bytes already responded to the I2C read message - * (excluding current byte) - * - * @return 0 on success - * @return -EIO on error - */ -typedef int (*i2c_common_emul_read_byte_func)(struct i2c_emul *emul, int reg, - uint8_t *val, int bytes); - -/** - * @brief Function type that is used by I2C device emulator to select register - * address that should be compared with fail register set by user using - * @ref i2c_common_emul_set_read_fail_reg and - * @ref i2c_common_emul_set_write_fail_reg - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by read/write command (first byte - * of last I2C write message) - * @param bytes Number of bytes already processed in the I2C message handler - * (excluding current byte) - * @param read If current I2C message is read - * - * @return Register address that should be compared with user-defined fail - * register - */ -typedef int (*i2c_common_emul_access_reg_func)(struct i2c_emul *emul, int reg, - int bytes, bool read); - -/** - * @brief Custom function type that is used as user-defined callback in read - * I2C messages handling. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by read command (first byte of last - * I2C write message) - * @param val Pointer to buffer where current response byte should be stored - * @param bytes Number of bytes already responded to the I2C read message - * (excluding current byte) - * @param data Pointer to custom user data - * - * @return 0 on success - * @return 1 continue with normal emulator handler - * @return negative on error - */ -typedef int (*i2c_common_emul_read_func)(struct i2c_emul *emul, int reg, - uint8_t *val, int bytes, void *data); - -/** - * @brief Custom function type that is used as user-defined callback in write - * I2C messages handling. - * - * @param emul Pointer to emulator - * @param reg Address which is now accessed by write command (first byte of I2C - * write message) - * @param val Value of current byte - * @param bytes Number of bytes already received from the I2C write message - * (excluding current byte) - * @param data Pointer to custom user data - * - * @return 0 on success - * @return 1 continue with normal emulator handler - * @return negative on error - */ -typedef int (*i2c_common_emul_write_func)(struct i2c_emul *emul, int reg, - uint8_t val, int bytes, void *data); - -/** Static configuration, common for all i2c emulators */ -struct i2c_common_emul_cfg { - /** Label of the I2C bus this emulator connects to */ - const char *i2c_label; - /** Label of the I2C device being emulated */ - const char *dev_label; - /** Pointer to run-time data */ - struct i2c_common_emul_data *data; - /** Address of emulator on i2c bus */ - uint16_t addr; -}; - -/** Run-time data used by the emulator, common for all i2c emulators */ -struct i2c_common_emul_data { - /** I2C emulator detail */ - struct i2c_emul emul; - /** Emulator device */ - const struct device *i2c; - /** Configuration information */ - const struct i2c_common_emul_cfg *cfg; - - /** Current state of I2C bus (if emulator is handling message) */ - enum i2c_common_emul_msg_state msg_state; - /** Number of already handled bytes in ongoing message */ - int msg_byte; - /** Register selected in last write command */ - uint8_t cur_reg; - - /** Custom write function called on I2C write opperation */ - i2c_common_emul_write_func write_func; - /** Data passed to custom write function */ - void *write_func_data; - /** Custom read function called on I2C read opperation */ - i2c_common_emul_read_func read_func; - /** Data passed to custom read function */ - void *read_func_data; - - /** Control if read should fail on given register */ - int read_fail_reg; - /** Control if write should fail on given register */ - int write_fail_reg; - - /** Emulator function, called for first byte of write message */ - i2c_common_emul_start_write_func start_write; - /** Emulator function, called for each byte of write message */ - i2c_common_emul_write_byte_func write_byte; - /** Emulator function, called at the end of write message */ - i2c_common_emul_finish_write_func finish_write; - - /** Emulator function, called before first byte of read message */ - i2c_common_emul_start_read_func start_read; - /** Emulator function, called for each byte of read message */ - i2c_common_emul_read_byte_func read_byte; - /** Emulator function, called at the end of read message */ - i2c_common_emul_finish_read_func finish_read; - - /** - * Emulator function, called to get register that should be checked - * if was selected by user in set_read/write_fail_reg. - */ - i2c_common_emul_access_reg_func access_reg; - - /** Mutex used to control access to emulator data */ - struct k_mutex data_mtx; -}; - -/** - * @brief Lock access to emulator properties. After acquiring lock, user - * may change emulator behaviour in multi-thread setup. - * - * @param emul Pointer to emulator - * @param timeout Timeout in getting lock - * - * @return k_mutex_lock return code - */ -int i2c_common_emul_lock_data(struct i2c_emul *emul, k_timeout_t timeout); - -/** - * @brief Unlock access to emulator properties. - * - * @param emul Pointer to emulator - * - * @return k_mutex_unlock return code - */ -int i2c_common_emul_unlock_data(struct i2c_emul *emul); - -/** - * @brief Set write handler for I2C messages. This function is called before - * generic handler. - * - * @param emul Pointer to emulator - * @param func Pointer to custom function - * @param data User data passed on call of custom function - */ -void i2c_common_emul_set_write_func(struct i2c_emul *emul, - i2c_common_emul_write_func func, - void *data); - -/** - * @brief Set read handler for I2C messages. This function is called before - * generic handler. - * - * @param emul Pointer to emulator - * @param func Pointer to custom function - * @param data User data passed on call of custom function - */ -void i2c_common_emul_set_read_func(struct i2c_emul *emul, - i2c_common_emul_read_func func, void *data); - -/** - * @brief Setup fail on read of given register of emulator - * - * @param emul Pointer to emulator - * @param reg Register address or one of special values - * (I2C_COMMON_EMUL_FAIL_ALL_REG, I2C_COMMON_EMUL_NO_FAIL_REG) - */ -void i2c_common_emul_set_read_fail_reg(struct i2c_emul *emul, int reg); - -/** - * @brief Setup fail on write of given register of emulator - * - * @param emul Pointer to emulator - * @param reg Register address or one of special values - * (I2C_COMMON_EMUL_FAIL_ALL_REG, I2C_COMMON_EMUL_NO_FAIL_REG) - */ -void i2c_common_emul_set_write_fail_reg(struct i2c_emul *emul, int reg); - -/** - * @biref Emulate an I2C transfer to an emulator - * - * This is common function used by I2C device emulators. It handles dispatching - * I2C message, calling user custom functions, failing on reading/writing - * registers selected by user and calling device specific functions. - * - * @param emul I2C emulation information - * @param msgs List of messages to process - * @param num_msgs Number of messages to process - * @param addr Address of the I2C target device - * - * @retval 0 If successful - * @retval -EIO General input / output error - */ -int i2c_common_emul_transfer(struct i2c_emul *emul, struct i2c_msg *msgs, - int num_msgs, int addr); - -/** - * @brief Initialize common emulator data structure - * - * @param data Pointer to emulator data - */ -void i2c_common_emul_init(struct i2c_common_emul_data *data); - -/** - * @} - */ - -#endif /* __EMUL_COMMON_I2C_H */ diff --git a/zephyr/include/emul/emul_lis2dw12.h b/zephyr/include/emul/emul_lis2dw12.h deleted file mode 100644 index b136e24f0a..0000000000 --- a/zephyr/include/emul/emul_lis2dw12.h +++ /dev/null @@ -1,48 +0,0 @@ -/* 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. - */ - -#ifndef ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_ -#define ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_ - -#include <emul.h> -#include <drivers/i2c_emul.h> - -/** - * @brief The the i2c emulator pointer from the top level emul. - * - * @param emul The emulator to query - * @return Pointer to the i2c emulator struct - */ -struct i2c_emul *lis2dw12_emul_to_i2c_emul(const struct emul *emul); - -/** - * @brief Reset the state of the lis2dw12 emulator. - * - * @param emul The emulator to reset. - */ -void lis2dw12_emul_reset(const struct emul *emul); - -/** - * @brief Set the who-am-i register value. - * - * By default the who-am-i register holds LIS2DW12_WHO_AM_I, this function - * enables overriding that value in order to drive testing. - * - * @param emul The emulator to modify. - * @param who_am_i The new who-am-i register value. - */ -void lis2dw12_emul_set_who_am_i(const struct emul *emul, uint8_t who_am_i); - -/** - * @brief Check the number of times the chip was soft reset. - * - * This value is reset by a call to lis2dw12_emul_reset(). - * - * @param emul The emulator to query - * @return The number of times that the chip was reset. - */ -uint32_t lis2dw12_emul_get_soft_reset_count(const struct emul *emul); - -#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_LIS2DW12_H_ */ diff --git a/zephyr/include/emul/emul_ln9310.h b/zephyr/include/emul/emul_ln9310.h deleted file mode 100644 index dfa03eaa28..0000000000 --- a/zephyr/include/emul/emul_ln9310.h +++ /dev/null @@ -1,73 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for LN9310 emulator - */ - -#ifndef ZEPHYR_INCLUDE_EMUL_EMUL_LN9310_H_ -#define ZEPHYR_INCLUDE_EMUL_EMUL_LN9310_H_ - -#include <emul.h> -#include "driver/ln9310.h" -#include <stdbool.h> - -/** - * @brief Select the current emulator to use. - * - * Currently, only a single ln9310 can be instantiated at any given instance due - * to how the driver was written. Once this restriction is removed, there's - * still an issue with the board_get_battery_cell_type() function as it doesn't - * take a device pointer. This function selects the current LN9310 context which - * will serve the data for that board function. - * - * @param emulator The LN9310 emulator to select. - */ -void ln9310_emul_set_context(const struct emul *emulator); - -/** - * @brief Clear all the emulator data. - * - * @param emulator The LN9310 emulator to clear. - */ -void ln9310_emul_reset(const struct emul *emulator); - -/** - * @brief Update the emulator's battery cell type. - * - * @param emulator The LN9310 emulator to update. - * @param type The battery type to use. - */ -void ln9310_emul_set_battery_cell_type(const struct emul *emulator, - enum battery_cell_type type); - -/** - * @brief Update the emulator's version number. - * - * @param emulator The LN9310 emulator to update. - * @param version The LN9310 chip version number. - */ -void ln9310_emul_set_version(const struct emul *emulator, int version); - -/** - * @brief Update whether or not the LN9310 is currently getting more than 10V. - * - * @param emulator The LN9310 emulator to update. - * @param is_gt_10v Whether or not the chip is currently getting more than 10V. - */ -void ln9310_emul_set_vin_gt_10v(const struct emul *emulator, bool is_gt_10v); - -/** - * @brief Get whether or not the LN9310 is initialized. - * - * @param emulator The LN9310 emulator to read. - * - * @return true if the LN9310 was correctly initialized. - */ -bool ln9310_emul_is_init(const struct emul *emulator); - -#endif /* ZEPHYR_INCLUDE_EMUL_EMUL_LN9310_H_ */ diff --git a/zephyr/include/emul/emul_pi3usb9201.h b/zephyr/include/emul/emul_pi3usb9201.h deleted file mode 100644 index b171cfefc9..0000000000 --- a/zephyr/include/emul/emul_pi3usb9201.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for pi3usb9201 emulator - */ - -#ifndef __EMUL_PI3USB9201_H -#define __EMUL_PI3USB9201_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -#define PI3USB9201_REG_CTRL_1 0x0 -#define PI3USB9201_REG_CTRL_2 0x1 -#define PI3USB9201_REG_CLIENT_STS 0x2 -#define PI3USB9201_REG_HOST_STS 0x3 - -/** - * @brief Get pointer to pi3usb9201 emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to pi3usb9201 emulator - */ -struct i2c_emul *pi3usb9201_emul_get(int ord); - -/** - * @brief Set value of given register of pi3usb9201 - * - * @param emul Pointer to pi3usb9201 emulator - * @param reg Register address - * @param val New value of the register - * - * @return 0 on success or error - */ -int pi3usb9201_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val); - -/** - * @brief Get value of given register of pi3usb9201 - * - * @param emul Pointer to pi3usb9201 emulator - * @param reg Register address - * @param val Pointer to write current value of register - * - * @return 0 on success or error - */ -int pi3usb9201_emul_get_reg(struct i2c_emul *emul, int reg, uint8_t *val); - -#endif /* __EMUL_PI3USB9201_H */ diff --git a/zephyr/include/emul/emul_smart_battery.h b/zephyr/include/emul/emul_smart_battery.h deleted file mode 100644 index b48f836d66..0000000000 --- a/zephyr/include/emul/emul_smart_battery.h +++ /dev/null @@ -1,193 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for Smart Battery emulator - */ - -#ifndef __EMUL_SMART_BATTERY_H -#define __EMUL_SMART_BATTERY_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -/** - * @brief Smart Battery emulator backend API - * @defgroup sbat_emul Smart Battery emulator - * @{ - * - * Smart Battery emulator handle static state of device. E.g. setting charging - * current will not charge battery over time. Sending periodic status messages - * and alarms to SMBus Host or charging voltage/current to Smart Battery Charger - * is not supported. Behaviour of Smart Battery emulator is application-defined. - * As-such, each application may - * - * - define a Device Tree overlay file to set the most of battery properties - * - get battery properties calling @ref sbat_emul_get_bat_data Battery - * properties can be changed through obtained pointer. In multithread - * environment access to battery can be guarded by calling - * @ref sbat_emul_lock_bat_data and @ref sbat_emul_unlock_bat_data - * - call functions from emul_common_i2c.h to setup custom handlers for SMBus - * messages - */ - -/* Value used to indicate that no command is selected */ -#define SBAT_EMUL_NO_CMD -1 -/* Maximum size of data that can be returned in SMBus block transaction */ -#define MAX_BLOCK_SIZE 32 -/* Maximum length of command to send is maximum size of data + len byte + PEC */ -#define MSG_BUF_LEN (MAX_BLOCK_SIZE + 2) - -/** @brief Emulated smart battery properties */ -struct sbat_emul_bat_data { - /** Battery mode - bit field configuring some battery behaviours */ - uint16_t mode; - /** Word returned on manufacturer access command */ - uint16_t mf_access; - /** Capacity alarm value */ - uint16_t cap_alarm; - /** Remaing time alarm value */ - uint16_t time_alarm; - /** Rate of charge used in some commands */ - int16_t at_rate; - /** - * Flag indicating if AT_RATE_TIME_TO_FULL command supports mW - * capacity mode - */ - int at_rate_full_mw_support; - /** Error code returned by last command */ - uint16_t error_code; - /** Design battery voltage in mV */ - uint16_t design_mv; - /** Battery temperature at the moment in Kelvins */ - uint16_t temp; - /** Battery voltage at the moment in mV */ - uint16_t volt; - /** Current charging (> 0) or discharging (< 0) battery in mA */ - int16_t cur; - /** Average current from 1 minute */ - int16_t avg_cur; - /** Maximum error of returned values in percent */ - uint16_t max_error; - /** Capacity of the battery at the moment in mAh */ - uint16_t cap; - /** Full capacity of the battery in mAh */ - uint16_t full_cap; - /** Design battery capacity in mAh */ - uint16_t design_cap; - /** Charging current requested by battery */ - uint16_t desired_charg_cur; - /** Charging voltage requested by battery */ - uint16_t desired_charg_volt; - /** Number of cycles */ - uint16_t cycle_count; - /** Specification of battery */ - uint16_t spec_info; - /** Status of battery */ - uint16_t status; - /** Date of manufacturing */ - uint16_t mf_date; - /** Serial number */ - uint16_t sn; - /** Manufacturer name */ - uint8_t mf_name[MAX_BLOCK_SIZE]; - /** Manufacturer name length */ - int mf_name_len; - /** Device name */ - uint8_t dev_name[MAX_BLOCK_SIZE]; - /** Device name length */ - int dev_name_len; - /** Device chemistry */ - uint8_t dev_chem[MAX_BLOCK_SIZE]; - /** Device chemistry length */ - int dev_chem_len; - /** Manufacturer data */ - uint8_t mf_data[MAX_BLOCK_SIZE]; - /** Manufacturer data length */ - int mf_data_len; -}; - -/** - * @brief Get pointer to smart battery emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to smart battery emulator - */ -struct i2c_emul *sbat_emul_get_ptr(int ord); - -/** - * @brief Function which allows to get properties of emulated smart battery - * - * @param emul Pointer to smart battery emulator - * - * @return Pointer to smart battery properties - */ -struct sbat_emul_bat_data *sbat_emul_get_bat_data(struct i2c_emul *emul); - -/** - * @brief Convert date to format used by smart battery - * - * @param day Day - * @param month Month - * @param year Year - * - * @return Converted date - */ -uint16_t sbat_emul_date_to_word(unsigned int day, unsigned int month, - unsigned int year); - -/** - * @brief Function which gets return value for read commands that returns word. - * This function may be used to obtain battery properties that are - * calculated e.g. time to empty/full. - * - * @param emul Pointer to smart battery emulator - * @param cmd Read command - * @param val Pointer to where word should be stored - * - * @return 0 on success - * @return 1 if command is unknown or return type different then word - * @return negative on error while reading value - */ -int sbat_emul_get_word_val(struct i2c_emul *emul, int cmd, uint16_t *val); - -/** - * @brief Function which gets return value for read commands that returns block - * data - * - * @param emul Pointer to smart battery emulator - * @param cmd Read command - * @param blk Pointer to where data pointer should be stored - * @param len Pointer to where data length should be stored - * - * @return 0 on success - * @return 1 if command is unknown or return type different then word - * @return negative on error while reading value - */ -int sbat_emul_get_block_data(struct i2c_emul *emul, int cmd, uint8_t **blk, - int *len); - -/** - * @brief Set next response of emulator. This function may be used in user - * custom read callback to setup response with calculated PEC. - * - * @param emul Pointer to smart battery emulator - * @param cmd Read command - * @param buf Buffer with the response - * @param len Length of the response - * @param fail If emulator should fail to send response - */ -void sbat_emul_set_response(struct i2c_emul *emul, int cmd, uint8_t *buf, - int len, bool fail); - -/** - * @} - */ - -#endif /* __EMUL_SMART_BATTERY_H */ diff --git a/zephyr/include/emul/emul_syv682x.h b/zephyr/include/emul/emul_syv682x.h deleted file mode 100644 index aa0d8840f7..0000000000 --- a/zephyr/include/emul/emul_syv682x.h +++ /dev/null @@ -1,143 +0,0 @@ -/* 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. - */ - -/** @file - * - * @brief Backend API for SYV682X emulator - */ - -#ifndef __EMUL_SYV682X_H -#define __EMUL_SYV682X_H - -#include <drivers/i2c_emul.h> -#include <stdint.h> - -/* Register info copied from syv682.h */ - -/* SYV682x register addresses */ -#define SYV682X_STATUS_REG 0x00 -#define SYV682X_CONTROL_1_REG 0x01 -#define SYV682X_CONTROL_2_REG 0x02 -#define SYV682X_CONTROL_3_REG 0x03 -#define SYV682X_CONTROL_4_REG 0x04 - -/* Status Register */ -#define SYV682X_STATUS_OC_HV BIT(7) -#define SYV682X_STATUS_RVS BIT(6) -#define SYV682X_STATUS_OC_5V BIT(5) -#define SYV682X_STATUS_OVP BIT(4) -#define SYV682X_STATUS_FRS BIT(3) -#define SYV682X_STATUS_TSD BIT(2) -#define SYV682X_STATUS_VSAFE_5V BIT(1) -#define SYV682X_STATUS_VSAFE_0V BIT(0) -#define SYV682X_STATUS_INT_MASK 0xfc - -/* Control Register 1 */ -#define SYV682X_CONTROL_1_CH_SEL BIT(1) -#define SYV682X_CONTROL_1_HV_DR BIT(2) -#define SYV682X_CONTROL_1_PWR_ENB BIT(7) - -#define SYV682X_5V_ILIM_MASK 0x18 -#define SYV682X_5V_ILIM_BIT_SHIFT 3 -#define SYV682X_5V_ILIM_1_25 0 -#define SYV682X_5V_ILIM_1_75 1 -#define SYV682X_5V_ILIM_2_25 2 -#define SYV682X_5V_ILIM_3_30 3 - -#define SYV682X_HV_ILIM_MASK 0x60 -#define SYV682X_HV_ILIM_BIT_SHIFT 5 -#define SYV682X_HV_ILIM_1_25 0 -#define SYV682X_HV_ILIM_1_75 1 -#define SYV682X_HV_ILIM_3_30 2 -#define SYV682X_HV_ILIM_5_50 3 - -/* Control Register 2 */ -#define SYV682X_OC_DELAY_MASK GENMASK(7, 6) -#define SYV682X_OC_DELAY_SHIFT 6 -#define SYV682X_OC_DELAY_1MS 0 -#define SYV682X_OC_DELAY_10MS 1 -#define SYV682X_OC_DELAY_50MS 2 -#define SYV682X_OC_DELAY_100MS 3 -#define SYV682X_DSG_TIME_MASK GENMASK(5, 4) -#define SYV682X_DSG_TIME_SHIFT 4 -#define SYV682X_DSG_TIME_50MS 0 -#define SYV682X_DSG_TIME_100MS 1 -#define SYV682X_DSG_TIME_200MS 2 -#define SYV682X_DSG_TIME_400MS 3 -#define SYV682X_DSG_RON_MASK GENMASK(3, 2) -#define SYV682X_DSG_RON_SHIFT 2 -#define SYV682X_DSG_RON_200_OHM 0 -#define SYV682X_DSG_RON_400_OHM 1 -#define SYV682X_DSG_RON_800_OHM 2 -#define SYV682X_DSG_RON_1600_OHM 3 -#define SYV682X_CONTROL_2_SDSG BIT(1) -#define SYV682X_CONTROL_2_FDSG BIT(0) - -/* Control Register 3 */ -#define SYV682X_BUSY BIT(7) -#define SYV682X_RVS_MASK BIT(3) -#define SYV682X_RST_REG BIT(0) -#define SYV682X_OVP_MASK 0x70 -#define SYV682X_OVP_BIT_SHIFT 4 -#define SYV682X_OVP_06_0 0 -#define SYV682X_OVP_08_0 1 -#define SYV682X_OVP_11_1 2 -#define SYV682X_OVP_12_1 3 -#define SYV682X_OVP_14_2 4 -#define SYV682X_OVP_17_9 5 -#define SYV682X_OVP_21_6 6 -#define SYV682X_OVP_23_7 7 - -/* Control Register 4 */ -#define SYV682X_CONTROL_4_CC1_BPS BIT(7) -#define SYV682X_CONTROL_4_CC2_BPS BIT(6) -#define SYV682X_CONTROL_4_VCONN1 BIT(5) -#define SYV682X_CONTROL_4_VCONN2 BIT(4) -#define SYV682X_CONTROL_4_VBAT_OVP BIT(3) -#define SYV682X_CONTROL_4_VCONN_OCP BIT(2) -#define SYV682X_CONTROL_4_CC_FRS BIT(1) -#define SYV682X_CONTROL_4_INT_MASK 0x0c - -/** - * @brief Get pointer to SYV682x emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to smart battery emulator - */ -struct i2c_emul *syv682x_emul_get(int ord); - -/** - * @brief Set the underlying interrupt conditions affecting the status register - * - * @param emul SYV682x emulator - * @param val A status register value corresponding to the underlying - * conditions - */ -void syv682x_emul_set_status(struct i2c_emul *emul, uint8_t val); - -/** - * @brief Set value of a register of SYV682x - * - * @param emul SYV682x emulator - * @param reg Register address - * @param val Value to write to the register - * - * @return 0 on success, error code on error - */ -int syv682x_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val); - -/** - * @brief Get value of a register of SYV682x - * - * @param emul SYV682x emulator - * @param reg Register address - * @param val Pointer at which to store current value of register - * - * @return 0 on success, error code on error - */ -int syv682x_emul_get_reg(struct i2c_emul *emul, int reg, uint8_t *val); - -#endif /* __EMUL_SYV682X_H */ diff --git a/zephyr/include/emul/emul_tcs3400.h b/zephyr/include/emul/emul_tcs3400.h deleted file mode 100644 index 49ec382a66..0000000000 --- a/zephyr/include/emul/emul_tcs3400.h +++ /dev/null @@ -1,156 +0,0 @@ -/* 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. - */ - -/** - * @file - * - * @brief Backend API for TCS3400 emulator - */ - -#ifndef __EMUL_TCS3400_H -#define __EMUL_TCS3400_H - -#include <emul.h> -#include <drivers/i2c.h> -#include <drivers/i2c_emul.h> - -/** - * @brief TCS3400 emulator backend API - * @defgroup tcs_emul TCS3400 emulator - * @{ - * - * TCS3400 emulator supports responses to all write and read I2C messages. - * Light sensor data registers are obtained from internal emulator state, gain - * and acquisition time. Application may alter emulator state: - * - * - define a devicetree overlay file to set which inadvisable driver behaviour - * should be treated as error and emulated device ID and revision - * - call @ref tcs_emul_set_reg and @ref tcs_emul_get_reg to set and get value - * of TCS3400 registers - * - call @ref tcs_emul_set_val and @ref tcs_emul_set_val to set and get - * light sensor value - * - call tcs_emul_set_err_* to change emulator behaviour on inadvisable driver - * behaviour - * - call functions from emul_common_i2c.h to setup custom handlers for I2C - * messages - */ - -/** - * Maximum number of integration cycles (when ATIME is zero). Value read from - * sensor is proportional to number of integration cycles, e.g. with constant - * light, value obtainded with 128 cycles will be two times smaller than value - * obtained with 256 cycles. - */ -#define TCS_EMUL_MAX_CYCLES 256 -/** - * Maximum gain supported by TCS3400. Value read from sensor is multiplied by - * gain selected in CONTROL register. - */ -#define TCS_EMUL_MAX_GAIN 64 - -/** - * Emulator units are value returned with gain x64 and 256 integration cycles. - * Max value is 1024 returned when gain is x1 and 1 integration cycle. Max value - * represented in emulator units is 1024 * 64 * 256 - */ -#define TCS_EMUL_MAX_VALUE (1024 * TCS_EMUL_MAX_GAIN * TCS_EMUL_MAX_CYCLES) - -/** Axis argument used in @ref tcs_emul_set_val @ref tcs_emul_get_val */ -enum tcs_emul_axis { - TCS_EMUL_R, - TCS_EMUL_G, - TCS_EMUL_B, - TCS_EMUL_C, - TCS_EMUL_IR, -}; - -/** - * Emulator saves only those registers in memory. IR select is stored sparately - * and other registers are write only. - */ -#define TCS_EMUL_FIRST_REG TCS_I2C_ENABLE -#define TCS_EMUL_LAST_REG TCS_I2C_BDATAH -#define TCS_EMUL_REG_COUNT (TCS_EMUL_LAST_REG - TCS_EMUL_FIRST_REG + 1) - -/** - * @brief Get pointer to TCS3400 emulator using device tree order number. - * - * @param ord Device tree order number obtained from DT_DEP_ORD macro - * - * @return Pointer to TCS3400 emulator - */ -struct i2c_emul *tcs_emul_get(int ord); - -/** - * @brief Set value of given register of TCS3400 - * - * @param emul Pointer to TCS3400 emulator - * @param reg Register address which value will be changed - * @param val New value of the register - */ -void tcs_emul_set_reg(struct i2c_emul *emul, int reg, uint8_t val); - -/** - * @brief Get value of given register of TCS3400 - * - * @param emul Pointer to TCS3400 emulator - * @param reg Register address - * - * @return Value of the register - */ -uint8_t tcs_emul_get_reg(struct i2c_emul *emul, int reg); - -/** - * @brief Get internal value of light sensor for given axis - * - * @param emul Pointer to TCS3400 emulator - * @param axis Axis to access - * - * @return Value of given axis with gain x64 and 256 integration cycles - */ -int tcs_emul_get_val(struct i2c_emul *emul, enum tcs_emul_axis axis); - -/** - * @brief Set internal value of light sensor for given axis - * - * @param emul Pointer to TCS3400 emulator - * @param axis Axis to access - * @param val New value of light sensor for given axis with gain x64 and - * 256 integration cycles - */ -void tcs_emul_set_val(struct i2c_emul *emul, enum tcs_emul_axis axis, int val); - -/** - * @brief Set if error should be generated when read only register is being - * written - * - * @param emul Pointer to TCS3400 emulator - * @param set Check for this error - */ -void tcs_emul_set_err_on_ro_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when reserved bits of register are - * not set to 0 on write I2C message - * - * @param emul Pointer to TCS3400 emulator - * @param set Check for this error - */ -void tcs_emul_set_err_on_rsvd_write(struct i2c_emul *emul, bool set); - -/** - * @brief Set if error should be generated when MSB register is accessed before - * LSB register - * - * @param emul Pointer to TCS3400 emulator - * @param set Check for this error - */ -void tcs_emul_set_err_on_msb_first(struct i2c_emul *emul, bool set); - -/** - * @} - */ - -#endif /* __EMUL_TCS3400_H */ diff --git a/zephyr/include/emul/i2c_mock.h b/zephyr/include/emul/i2c_mock.h deleted file mode 100644 index e9e8d97252..0000000000 --- a/zephyr/include/emul/i2c_mock.h +++ /dev/null @@ -1,35 +0,0 @@ -/* 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. - */ - -#ifndef ZEPHYR_INCLUDE_EMUL_I2C_MOCK_H_ -#define ZEPHYR_INCLUDE_EMUL_I2C_MOCK_H_ - -#include <emul.h> -#include <drivers/i2c_emul.h> - -/** - * @brief reset the I2C mock. - * - * @param emul The mock device to reset. - */ -void i2c_mock_reset(const struct emul *emul); - -/** - * @brief Get the i2c emulator pointer from the top level mock. - * - * @param emul The mock device to query - * @return Pointer to the i2c emulator struct - */ -struct i2c_emul *i2c_mock_to_i2c_emul(const struct emul *emul); - -/** - * @brief Get the I2C address of the mock - * - * @param emul The mock device to query - * @return The address on the I2C bus - */ -uint16_t i2c_mock_get_addr(const struct emul *emul); - -#endif /* ZEPHYR_INCLUDE_EMUL_I2C_MOCK_H_ */ diff --git a/zephyr/include/soc/ite_it8xxx2/reg_def_cros.h b/zephyr/include/soc/ite_it8xxx2/reg_def_cros.h deleted file mode 100644 index 8d3b56878e..0000000000 --- a/zephyr/include/soc/ite_it8xxx2/reg_def_cros.h +++ /dev/null @@ -1,97 +0,0 @@ -/* 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. - */ - -/* - * @file - * @brief ITE it8xxx2 register structure definitions used by the Chrome OS EC. - */ - -#ifndef _ITE_IT8XXX2_REG_DEF_CROS_H -#define _ITE_IT8XXX2_REG_DEF_CROS_H - -/* - * KBS (Keyboard Scan) device registers - */ -struct kbs_reg { - /* 0x000: Keyboard Scan Out */ - volatile uint8_t KBS_KSOL; - /* 0x001: Keyboard Scan Out */ - volatile uint8_t KBS_KSOH1; - /* 0x002: Keyboard Scan Out Control */ - volatile uint8_t KBS_KSOCTRL; - /* 0x003: Keyboard Scan Out */ - volatile uint8_t KBS_KSOH2; - /* 0x004: Keyboard Scan In */ - volatile uint8_t KBS_KSI; - /* 0x005: Keyboard Scan In Control */ - volatile uint8_t KBS_KSICTRL; - /* 0x006: Keyboard Scan In [7:0] GPIO Control */ - volatile uint8_t KBS_KSIGCTRL; - /* 0x007: Keyboard Scan In [7:0] GPIO Output Enable */ - volatile uint8_t KBS_KSIGOEN; - /* 0x008: Keyboard Scan In [7:0] GPIO Data */ - volatile uint8_t KBS_KSIGDAT; - /* 0x009: Keyboard Scan In [7:0] GPIO Data Mirror */ - volatile uint8_t KBS_KSIGDMRR; - /* 0x00A: Keyboard Scan Out [15:8] GPIO Control */ - volatile uint8_t KBS_KSOHGCTRL; - /* 0x00B: Keyboard Scan Out [15:8] GPIO Output Enable */ - volatile uint8_t KBS_KSOHGOEN; - /* 0x00C: Keyboard Scan Out [15:8] GPIO Data Mirror */ - volatile uint8_t KBS_KSOHGDMRR; - /* 0x00D: Keyboard Scan Out [7:0] GPIO Control */ - volatile uint8_t KBS_KSOLGCTRL; - /* 0x00E: Keyboard Scan Out [7:0] GPIO Output Enable */ - volatile uint8_t KBS_KSOLGOEN; -}; - -/* KBS register fields */ -#define IT8XXX2_KBS_KSOPU BIT(2) -#define IT8XXX2_KBS_KSOOD BIT(0) -#define IT8XXX2_KBS_KSIPU BIT(2) -#define IT8XXX2_KBS_KSO2GCTRL BIT(2) -#define IT8XXX2_KBS_KSO2GOEN BIT(2) - -/* - * ECPM (EC Clock and Power Management) device registers - */ -struct ecpm_reg { - /* 0x000: Reserved1 */ - volatile uint8_t reserved1; - /* 0x001: Clock Gating Control 1 */ - volatile uint8_t ECPM_CGCTRL1; - /* 0x002: Clock Gating Control 2 */ - volatile uint8_t ECPM_CGCTRL2; - /* 0x003: PLL Control */ - volatile uint8_t ECPM_PLLCTRL; - /* 0x004: Auto Clock Gating */ - volatile uint8_t ECPM_AUTOCG; - /* 0x005: Clock Gating Control 3 */ - volatile uint8_t ECPM_CGCTRL3; - /* 0x006: PLL Frequency */ - volatile uint8_t ECPM_PLLFREQ; - /* 0x007: Reserved2 */ - volatile uint8_t reserved2; - /* 0x008: PLL Clock Source Status */ - volatile uint8_t ECPM_PLLCSS; - /* 0x009: Clock Gating Control 4 */ - volatile uint8_t ECPM_CGCTRL4; - /* 0x00A: Reserved3 */ - volatile uint8_t reserved3; - /* 0x00B: Reserved4 */ - volatile uint8_t reserved4; - /* 0x00C: System Clock Divide Control 0 */ - volatile uint8_t ECPM_SCDCR0; - /* 0x00D: System Clock Divide Control 1 */ - volatile uint8_t ECPM_SCDCR1; - /* 0x00E: System Clock Divide Control 2 */ - volatile uint8_t ECPM_SCDCR2; - /* 0x00F: System Clock Divide Control 3 */ - volatile uint8_t ECPM_SCDCR3; - /* 0x010: System Clock Divide Control 4 */ - volatile uint8_t ECPM_SCDCR4; -}; - -#endif /* _ITE_IT8XXX2_REG_DEF_CROS_H */ diff --git a/zephyr/include/soc/nuvoton_npcx/reg_def_cros.h b/zephyr/include/soc/nuvoton_npcx/reg_def_cros.h deleted file mode 100644 index 8702502a13..0000000000 --- a/zephyr/include/soc/nuvoton_npcx/reg_def_cros.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2020 Nuvoton Technology Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* - * @file - * @brief Nuvoton NPCX register structure definitions used by the Chrome OS EC. - */ - -#ifndef _NUVOTON_NPCX_REG_DEF_CROS_H -#define _NUVOTON_NPCX_REG_DEF_CROS_H - -/* - * KBS (Keyboard Scan) device registers - */ -struct kbs_reg { - volatile uint8_t reserved1[4]; - /* 0x004: Keyboard Scan In */ - volatile uint8_t KBSIN; - /* 0x005: Keyboard Scan In Pull-Up Enable */ - volatile uint8_t KBSINPU; - /* 0x006: Keyboard Scan Out 0 */ - volatile uint16_t KBSOUT0; - /* 0x008: Keyboard Scan Out 1 */ - volatile uint16_t KBSOUT1; - /* 0x00A: Keyboard Scan Buffer Index */ - volatile uint8_t KBS_BUF_INDX; - /* 0x00B: Keyboard Scan Buffer Data */ - volatile uint8_t KBS_BUF_DATA; - /* 0x00C: Keyboard Scan Event */ - volatile uint8_t KBSEVT; - /* 0x00D: Keyboard Scan Control */ - volatile uint8_t KBSCTL; - /* 0x00E: Keyboard Scan Configuration Index */ - volatile uint8_t KBS_CFG_INDX; - /* 0x00F: Keyboard Scan Configuration Data */ - volatile uint8_t KBS_CFG_DATA; -}; - -/* KBS register fields */ -#define NPCX_KBSBUFINDX 0 -#define NPCX_KBSEVT_KBSDONE 0 -#define NPCX_KBSEVT_KBSERR 1 -#define NPCX_KBSCTL_START 0 -#define NPCX_KBSCTL_KBSMODE 1 -#define NPCX_KBSCTL_KBSIEN 2 -#define NPCX_KBSCTL_KBSINC 3 -#define NPCX_KBSCTL_KBHDRV_FIELD FIELD(6, 2) -#define NPCX_KBSCFGINDX 0 -/* Index of 'Automatic Scan' configuration register */ -#define KBS_CFG_INDX_DLY1 0 /* Keyboard Scan Delay T1 Byte */ -#define KBS_CFG_INDX_DLY2 1 /* Keyboard Scan Delay T2 Byte */ -#define KBS_CFG_INDX_RTYTO 2 /* Keyboard Scan Retry Timeout */ -#define KBS_CFG_INDX_CNUM 3 /* Keyboard Scan Columns Number */ -#define KBS_CFG_INDX_CDIV 4 /* Keyboard Scan Clock Divisor */ - -/* - * Flash Interface Unit (FIU) device registers - */ -struct fiu_reg { - /* 0x001: Burst Configuration */ - volatile uint8_t BURST_CFG; - /* 0x002: FIU Response Configuration */ - volatile uint8_t RESP_CFG; - volatile uint8_t reserved1[18]; - /* 0x014: SPI Flash Configuration */ - volatile uint8_t SPI_FL_CFG; - volatile uint8_t reserved2; - /* 0x016: UMA Code Byte */ - volatile uint8_t UMA_CODE; - /* 0x017: UMA Address Byte 0 */ - volatile uint8_t UMA_AB0; - /* 0x018: UMA Address Byte 1 */ - volatile uint8_t UMA_AB1; - /* 0x019: UMA Address Byte 2 */ - volatile uint8_t UMA_AB2; - /* 0x01A: UMA Data Byte 0 */ - volatile uint8_t UMA_DB0; - /* 0x01B: UMA Data Byte 1 */ - volatile uint8_t UMA_DB1; - /* 0x01C: UMA Data Byte 2 */ - volatile uint8_t UMA_DB2; - /* 0x01D: UMA Data Byte 3 */ - volatile uint8_t UMA_DB3; - /* 0x01E: UMA Control and Status */ - volatile uint8_t UMA_CTS; - /* 0x01F: UMA Extended Control and Status */ - volatile uint8_t UMA_ECTS; - /* 0x020: UMA Data Bytes 0-3 */ - volatile uint32_t UMA_DB0_3; - volatile uint8_t reserved3[2]; - /* 0x026: CRC Control Register */ - volatile uint8_t CRCCON; - /* 0x027: CRC Entry Register */ - volatile uint8_t CRCENT; - /* 0x028: CRC Initialization and Result Register */ - volatile uint32_t CRCRSLT; - volatile uint8_t reserved4[4]; - /* 0x030: FIU Read Command */ - volatile uint8_t FIU_RD_CMD; - volatile uint8_t reserved5; - /* 0x032: FIU Dummy Cycles */ - volatile uint8_t FIU_DMM_CYC; - /* 0x033: FIU Extended Configuration */ - volatile uint8_t FIU_EXT_CFG; -}; - -/* FIU register fields */ -#define NPCX_RESP_CFG_IAD_EN 0 -#define NPCX_RESP_CFG_DEV_SIZE_EX 2 -#define NPCX_UMA_CTS_A_SIZE 3 -#define NPCX_UMA_CTS_C_SIZE 4 -#define NPCX_UMA_CTS_RD_WR 5 -#define NPCX_UMA_CTS_DEV_NUM 6 -#define NPCX_UMA_CTS_EXEC_DONE 7 -#define NPCX_UMA_ECTS_SW_CS0 0 -#define NPCX_UMA_ECTS_SW_CS1 1 -#define NPCX_UMA_ECTS_SEC_CS 2 -#define NPCX_UMA_ECTS_UMA_LOCK 3 - -/* UMA fields selections */ -#define UMA_FLD_ADDR BIT(NPCX_UMA_CTS_A_SIZE) /* 3-bytes ADR field */ -#define UMA_FLD_NO_CMD BIT(NPCX_UMA_CTS_C_SIZE) /* No 1-Byte CMD field */ -#define UMA_FLD_WRITE BIT(NPCX_UMA_CTS_RD_WR) /* Write transaction */ -#define UMA_FLD_SHD_SL BIT(NPCX_UMA_CTS_DEV_NUM) /* Shared flash selected */ -#define UMA_FLD_EXEC BIT(NPCX_UMA_CTS_EXEC_DONE) - -#define UMA_FIELD_DATA_1 0x01 -#define UMA_FIELD_DATA_2 0x02 -#define UMA_FIELD_DATA_3 0x03 -#define UMA_FIELD_DATA_4 0x04 - -/* UMA code for transaction */ -#define UMA_CODE_CMD_ONLY (UMA_FLD_EXEC | UMA_FLD_SHD_SL) -#define UMA_CODE_CMD_ADR (UMA_FLD_EXEC | UMA_FLD_ADDR | \ - UMA_FLD_SHD_SL) -#define UMA_CODE_CMD_RD_BYTE(n) (UMA_FLD_EXEC | UMA_FIELD_DATA_##n | \ - UMA_FLD_SHD_SL) -#define UMA_CODE_RD_BYTE(n) (UMA_FLD_EXEC | UMA_FLD_NO_CMD | \ - UMA_FIELD_DATA_##n | UMA_FLD_SHD_SL) -#define UMA_CODE_CMD_WR_ONLY (UMA_FLD_EXEC | UMA_FLD_WRITE | \ - UMA_FLD_SHD_SL) -#define UMA_CODE_CMD_WR_BYTE(n) (UMA_FLD_EXEC | UMA_FLD_WRITE | \ - UMA_FIELD_DATA_##n | UMA_FLD_SHD_SL) -#define UMA_CODE_CMD_WR_ADR (UMA_FLD_EXEC | UMA_FLD_WRITE | UMA_FLD_ADDR | \ - UMA_FLD_SHD_SL) - -#define UMA_CODE_CMD_ADR_WR_BYTE(n) (UMA_FLD_EXEC | UMA_FLD_WRITE | \ - UMA_FLD_ADDR | UMA_FIELD_DATA_##n | \ - UMA_FLD_SHD_SL) - -/* - * Monotonic Counter (MTC) device registers - */ -struct mtc_reg { - /* 0x000: Timing Ticks Count Register */ - volatile uint32_t TTC; - /* 0x004: Wake-Up Ticks Count Register */ - volatile uint32_t WTC; -}; - -/* MTC register fields */ -#define NPCX_WTC_PTO 30 -#define NPCX_WTC_WIE 31 - -/* SHI (Serial Host Interface) registers */ -struct shi_reg { - volatile uint8_t reserved1; - /* 0x001: SHI Configuration 1 */ - volatile uint8_t SHICFG1; - /* 0x002: SHI Configuration 2 */ - volatile uint8_t SHICFG2; - volatile uint8_t reserved2[2]; - /* 0x005: Event Enable */ - volatile uint8_t EVENABLE; - /* 0x006: Event Status */ - volatile uint8_t EVSTAT; - /* 0x007: SHI Capabilities */ - volatile uint8_t CAPABILITY; - /* 0x008: Status */ - volatile uint8_t STATUS; - volatile uint8_t reserved3; - /* 0x00A: Input Buffer Status */ - volatile uint8_t IBUFSTAT; - /* 0x00B: Output Buffer Status */ - volatile uint8_t OBUFSTAT; - /* 0x00C: SHI Configuration 3 */ - volatile uint8_t SHICFG3; - /* 0x00D: SHI Configuration 4 */ - volatile uint8_t SHICFG4; - /* 0x00E: SHI Configuration 5 */ - volatile uint8_t SHICFG5; - /* 0x00F: Event Status 2 */ - volatile uint8_t EVSTAT2; - /* 0x010: Event Enable 2 */ - volatile uint8_t EVENABLE2; - volatile uint8_t reserved4[15]; - /* 0x20~0x9F: Output Buffer */ - volatile uint8_t OBUF[128]; - /* 0xA0~0x11F: Input Buffer */ - volatile uint8_t IBUF[128]; -}; - -/* SHI register fields */ -#define NPCX_SHICFG1_EN 0 -#define NPCX_SHICFG1_MODE 1 -#define NPCX_SHICFG1_WEN 2 -#define NPCX_SHICFG1_AUTIBF 3 -#define NPCX_SHICFG1_AUTOBE 4 -#define NPCX_SHICFG1_DAS 5 -#define NPCX_SHICFG1_CPOL 6 -#define NPCX_SHICFG1_IWRAP 7 -#define NPCX_SHICFG2_SIMUL 0 -#define NPCX_SHICFG2_BUSY 1 -#define NPCX_SHICFG2_ONESHOT 2 -#define NPCX_SHICFG2_SLWU 3 -#define NPCX_SHICFG2_REEN 4 -#define NPCX_SHICFG2_RESTART 5 -#define NPCX_SHICFG2_REEVEN 6 -#define NPCX_EVENABLE_OBEEN 0 -#define NPCX_EVENABLE_OBHEEN 1 -#define NPCX_EVENABLE_IBFEN 2 -#define NPCX_EVENABLE_IBHFEN 3 -#define NPCX_EVENABLE_EOREN 4 -#define NPCX_EVENABLE_EOWEN 5 -#define NPCX_EVENABLE_STSREN 6 -#define NPCX_EVENABLE_IBOREN 7 -#define NPCX_EVSTAT_OBE 0 -#define NPCX_EVSTAT_OBHE 1 -#define NPCX_EVSTAT_IBF 2 -#define NPCX_EVSTAT_IBHF 3 -#define NPCX_EVSTAT_EOR 4 -#define NPCX_EVSTAT_EOW 5 -#define NPCX_EVSTAT_STSR 6 -#define NPCX_EVSTAT_IBOR 7 -#define NPCX_STATUS_OBES 6 -#define NPCX_STATUS_IBFS 7 -#define NPCX_SHICFG3_OBUFLVLDIS 7 -#define NPCX_SHICFG4_IBUFLVLDIS 7 -#define NPCX_SHICFG5_IBUFLVL2 FIELD(0, 6) -#define NPCX_SHICFG5_IBUFLVL2DIS 7 -#define NPCX_EVSTAT2_IBHF2 0 -#define NPCX_EVSTAT2_CSNRE 1 -#define NPCX_EVSTAT2_CSNFE 2 -#define NPCX_EVENABLE2_IBHF2EN 0 -#define NPCX_EVENABLE2_CSNREEN 1 -#define NPCX_EVENABLE2_CSNFEEN 2 - -#endif /* _NUVOTON_NPCX_REG_DEF_CROS_H */ |