diff --git a/soc/focaltech/CMakeLists.txt b/soc/focaltech/CMakeLists.txt new file mode 100644 index 00000000000..e06b1c03c77 --- /dev/null +++ b/soc/focaltech/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(ft9001) diff --git a/soc/focaltech/Kconfig b/soc/focaltech/Kconfig new file mode 100644 index 00000000000..6686b285bd6 --- /dev/null +++ b/soc/focaltech/Kconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +rsource "*/Kconfig" diff --git a/soc/focaltech/Kconfig.defconfig b/soc/focaltech/Kconfig.defconfig new file mode 100644 index 00000000000..cebbc042e21 --- /dev/null +++ b/soc/focaltech/Kconfig.defconfig @@ -0,0 +1,4 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +rsource "*/Kconfig.defconfig" diff --git a/soc/focaltech/Kconfig.soc b/soc/focaltech/Kconfig.soc new file mode 100644 index 00000000000..8efd3a16508 --- /dev/null +++ b/soc/focaltech/Kconfig.soc @@ -0,0 +1,4 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +rsource "*/Kconfig.soc" diff --git a/soc/focaltech/ft9001/CMakeLists.txt b/soc/focaltech/ft9001/CMakeLists.txt new file mode 100644 index 00000000000..c04a73ef4ad --- /dev/null +++ b/soc/focaltech/ft9001/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +zephyr_sources( + soc.c + xip.c +) + +zephyr_include_directories(.) + +zephyr_code_relocate(FILES xip.c LOCATION RAM) + +set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "") diff --git a/soc/focaltech/ft9001/Kconfig b/soc/focaltech/ft9001/Kconfig new file mode 100644 index 00000000000..1c8ba2b1fad --- /dev/null +++ b/soc/focaltech/ft9001/Kconfig @@ -0,0 +1,13 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FT9001 + select ARM + select CPU_CORTEX_M4 + select CPU_HAS_FPU + select CPU_HAS_ARM_MPU + select CPU_CORTEX_M_HAS_SYSTICK + select CPU_CORTEX_M_HAS_VTOR + select SOC_EARLY_INIT_HOOK + select BUILD_OUTPUT_HEX + select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE diff --git a/soc/focaltech/ft9001/Kconfig.defconfig b/soc/focaltech/ft9001/Kconfig.defconfig new file mode 100644 index 00000000000..e143323de74 --- /dev/null +++ b/soc/focaltech/ft9001/Kconfig.defconfig @@ -0,0 +1,12 @@ +# Copyright (c) 2025, FocalTech Systems CO.,Ltd +# SPDX-License-Identifier: Apache-2.0 + +if SOC_FT9001 + +config SYS_CLOCK_HW_CYCLES_PER_SEC + default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency) + +config NUM_IRQS + default 140 + +endif # SOC_FT9001 diff --git a/soc/focaltech/ft9001/Kconfig.soc b/soc/focaltech/ft9001/Kconfig.soc new file mode 100644 index 00000000000..e2701dc8e4b --- /dev/null +++ b/soc/focaltech/ft9001/Kconfig.soc @@ -0,0 +1,10 @@ +# Copyright (c) 2025, FocalTech Systems Co., Ltd. +# SPDX-License-Identifier: Apache-2.0 + +config SOC_FT9001 + bool + help + Build for the FocalTech FT9001 MCU (ARM Cortex-M4F). + +config SOC + default "ft9001" if SOC_FT9001 diff --git a/soc/focaltech/ft9001/pinctrl_soc.h b/soc/focaltech/ft9001/pinctrl_soc.h new file mode 100644 index 00000000000..1d02d80250b --- /dev/null +++ b/soc/focaltech/ft9001/pinctrl_soc.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2025, FocalTech Systems CO.,Ltd + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief FocalTech FT9001 SoC specific helpers for pinctrl driver + */ + +#ifndef ZEPHYR_SOC_ARM_FOCALTECH_FT9001_PINCTRL_SOC_H_ +#define ZEPHYR_SOC_ARM_FOCALTECH_FT9001_PINCTRL_SOC_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** @cond INTERNAL_HIDDEN */ + +/** @brief Type for FT9001 pin configuration. + * + * Bits: + * - 0-25: FT9001_PINMUX bit field. + * - 26-31: Pin configuration bit field (@ref FT9001_PINCFG). + */ +typedef uint32_t pinctrl_soc_pin_t; + +/** + * @brief Utility macro to initialize each pin. + * + * @param node_id Node identifier. + * @param prop Property name. + * @param idx Property entry index. + */ +#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ + (DT_PROP_BY_IDX(node_id, prop, idx) | \ + ((FT9001_PUPD_PULLUP * DT_PROP(node_id, bias_pull_up)) << FT9001_PUPD_POS) | \ + ((FT9001_PUPD_PULLDOWN * DT_PROP(node_id, bias_pull_down)) << FT9001_PUPD_POS) | \ + ((FT9001_OTYPE_OD * DT_PROP(node_id, drive_open_drain)) << FT9001_OTYPE_POS) | \ + (DT_ENUM_IDX(node_id, slew_rate) << FT9001_OSPEED_POS)), + +/** + * @brief Utility macro to initialize state pins contained in a given property. + * + * @param node_id Node identifier. + * @param prop Property name describing state pins. + */ +#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ + {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ + Z_PINCTRL_STATE_PIN_INIT)} + +/** @endcond */ + +/** + * @name FT9001 pull-up/down configuration + * @{ + */ +#define FT9001_PUPD_NONE 0U /**< No pull-up/down */ +#define FT9001_PUPD_PULLUP 1U /**< Pull-up */ +#define FT9001_PUPD_PULLDOWN 2U /**< Pull-down */ +/** @} */ + +/** + * @name FT9001 output type configuration + * @{ + */ +#define FT9001_OTYPE_PP 0U /**< Push-pull */ +#define FT9001_OTYPE_OD 1U /**< Open-drain */ +/** @} */ + +/** + * @name FT9001 output speed configuration + * @{ + */ +#define FT9001_OSPEED_10MHZ 0U /**< Maximum 10MHz */ +#define FT9001_OSPEED_2MHZ 1U /**< Maximum 2MHz */ +#define FT9001_OSPEED_50MHZ 2U /**< Maximum 50MHz */ +#define FT9001_OSPEED_MAX 3U /**< Maximum speed */ +/** @} */ + +/** + * @name FT9001 pin configuration bit field positions and masks + * @{ + */ +#define FT9001_PUPD_POS 29U /**< PUPD field position */ +#define FT9001_PUPD_MSK 0x3U /**< PUPD field mask */ +#define FT9001_OTYPE_POS 28U /**< OTYPE field position */ +#define FT9001_OTYPE_MSK 0x1U /**< OTYPE field mask */ +#define FT9001_OSPEED_POS 26U /**< OSPEED field position */ +#define FT9001_OSPEED_MSK 0x3U /**< OSPEED field mask */ +/** @} */ + +/** + * @brief Obtain PUPD field from pinctrl_soc_pin_t configuration. + * @param pincfg pinctrl_soc_pin_t bit field value. + */ +#define FT9001_PUPD_GET(pincfg) (((pincfg) >> FT9001_PUPD_POS) & FT9001_PUPD_MSK) + +/** + * @brief Obtain OTYPE field from pinctrl_soc_pin_t configuration. + * @param pincfg pinctrl_soc_pin_t bit field value. + */ +#define FT9001_OTYPE_GET(pincfg) (((pincfg) >> FT9001_OTYPE_POS) & FT9001_OTYPE_MSK) + +/** + * @brief Obtain OSPEED field from pinctrl_soc_pin_t configuration. + * @param pincfg pinctrl_soc_pin_t bit field value. + */ +#define FT9001_OSPEED_GET(pincfg) (((pincfg) >> FT9001_OSPEED_POS) & FT9001_OSPEED_MSK) + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_SOC_ARM_FOCALTECH_FT9001_PINCTRL_SOC_H_ */ diff --git a/soc/focaltech/ft9001/soc.c b/soc/focaltech/ft9001/soc.c new file mode 100644 index 00000000000..0248ca71f2b --- /dev/null +++ b/soc/focaltech/ft9001/soc.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025, FocalTech Systems CO.,Ltd + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#define XIP_CLKDIV_BOOT 1U + +void xip_clock_switch(uint32_t clk_div); + +void soc_early_init_hook(void) +{ +#ifdef CONFIG_XIP + xip_clock_switch(XIP_CLKDIV_BOOT); +#endif +} diff --git a/soc/focaltech/ft9001/soc.h b/soc/focaltech/ft9001/soc.h new file mode 100644 index 00000000000..fab63718f10 --- /dev/null +++ b/soc/focaltech/ft9001/soc.h @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2025, FocalTech Systems CO.,Ltd + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _SOC_ARM_FOCALTECH_FT9001_SOC_H_ +#define _SOC_ARM_FOCALTECH_FT9001_SOC_H_ + +#include + +#endif /* _SOC_ARM_FOCALTECH_FT9001_SOC_H_ */ diff --git a/soc/focaltech/ft9001/xip.c b/soc/focaltech/ft9001/xip.c new file mode 100644 index 00000000000..ea539d66e55 --- /dev/null +++ b/soc/focaltech/ft9001/xip.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025, FocalTech Systems CO.,Ltd + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* clocks (soc-specific) */ +#define FT9001_CLK_CFG_ADDR 0x40004008u +#define FT9001_CLK_UPD_ADDR 0x40004018u +#define FT9001_CLK_UPD_GO_MASK 0x02u + +__ramfunc void xip_clock_switch(uint32_t clk_div) +{ + uint32_t val = sys_read32(FT9001_CLK_CFG_ADDR); + + val = (val & 0xFFFFFFF0u) | (clk_div & 0x0Fu); + sys_write32(val, FT9001_CLK_CFG_ADDR); + sys_write32(sys_read32(FT9001_CLK_UPD_ADDR) | FT9001_CLK_UPD_GO_MASK, FT9001_CLK_UPD_ADDR); + + barrier_dsync_fence_full(); + barrier_isync_fence_full(); +} diff --git a/soc/focaltech/soc.yml b/soc/focaltech/soc.yml new file mode 100644 index 00000000000..1facbf685b2 --- /dev/null +++ b/soc/focaltech/soc.yml @@ -0,0 +1,2 @@ +socs: + - name: ft9001