diff --git a/tests/drivers/pinctrl/microchip/CMakeLists.txt b/tests/drivers/pinctrl/microchip/CMakeLists.txt new file mode 100644 index 0000000000000..e1f11b2bf147f --- /dev/null +++ b/tests/drivers/pinctrl/microchip/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2025 Microchip Technology Inc. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(microchip) + +target_sources(app PRIVATE src/main.c ../common/test_device.c) diff --git a/tests/drivers/pinctrl/microchip/Kconfig b/tests/drivers/pinctrl/microchip/Kconfig new file mode 100644 index 0000000000000..058e73d422e2d --- /dev/null +++ b/tests/drivers/pinctrl/microchip/Kconfig @@ -0,0 +1,17 @@ +# Copyright (c) 2025 Microchip Technology Inc. +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "pinctrl microchip DT Test" + +source "Kconfig.zephyr" + +config PINCTRL_TEST_NON_STATIC + bool "Access to pin control configuration" + select PINCTRL_NON_STATIC + help + This option should be selected by unit tests that need to access the pin + control configuration defined in a device driver. + +config TEST_PINCTRL_MCHP_SAM + bool "Enable test for MCHP SAM drive strength" + default y if SOC_FAMILY_MICROCHIP_SAM_D5X_E5X diff --git a/tests/drivers/pinctrl/microchip/boards/sam_e54_xpro.conf b/tests/drivers/pinctrl/microchip/boards/sam_e54_xpro.conf new file mode 100644 index 0000000000000..d79e291bcecdc --- /dev/null +++ b/tests/drivers/pinctrl/microchip/boards/sam_e54_xpro.conf @@ -0,0 +1,4 @@ +# Copyright (c) 2025 Microchip Technology Inc. +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_TEST_PINCTRL_MCHP_SAM=y diff --git a/tests/drivers/pinctrl/microchip/boards/sam_e54_xpro.overlay b/tests/drivers/pinctrl/microchip/boards/sam_e54_xpro.overlay new file mode 100644 index 0000000000000..953493ee9f074 --- /dev/null +++ b/tests/drivers/pinctrl/microchip/boards/sam_e54_xpro.overlay @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Microchip Technology Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + test_device: test_device@0 { + compatible = "vnd,pinctrl-device"; + reg = <0x0 0x1>; + pinctrl-0 = <&test_device_default>; + pinctrl-names = "default"; + }; +}; + +&pinctrl { + test_device_default: test_device_default { + /* Note: the groups are just meant for testing if properties and + * pins are parsed correctly, but do not necessarily represent a + * feasible combination + */ + group1 { + pinmux = , + ; + }; + group2 { + pinmux = ; + bias-pull-up; + }; + group3 { + pinmux = ; + bias-pull-down; + }; + group4 { + pinmux = ; + input-enable; + output-enable; + }; + group5 { + pinmux = ; + drive-strength=<1>; + }; + }; +}; diff --git a/tests/drivers/pinctrl/microchip/prj.conf b/tests/drivers/pinctrl/microchip/prj.conf new file mode 100644 index 0000000000000..5e341d7d38733 --- /dev/null +++ b/tests/drivers/pinctrl/microchip/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_PINCTRL_TEST_NON_STATIC=y diff --git a/tests/drivers/pinctrl/microchip/src/main.c b/tests/drivers/pinctrl/microchip/src/main.c new file mode 100644 index 0000000000000..3ab164aaf334d --- /dev/null +++ b/tests/drivers/pinctrl/microchip/src/main.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Microchip Technology Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* Pin configuration for test device */ +#define TEST_DEVICE DT_NODELABEL(test_device) +PINCTRL_DT_DEV_CONFIG_DECLARE(TEST_DEVICE); +static const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(TEST_DEVICE); + +#define MCHP_PINCTRL_FLAG_GET(pincfg, pos) (((pincfg.pinflag) >> pos) & MCHP_PINCTRL_FLAG_MASK) + +ZTEST(pinctrl_mchp, test_pullup_pulldown_none) +{ + const struct pinctrl_state *scfg; + + scfg = &pcfg->states[0]; + + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[0], MCHP_PINCTRL_PULLUP_POS), 0); + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[0], MCHP_PINCTRL_PULLDOWN_POS), 0); + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[1], MCHP_PINCTRL_PULLUP_POS), 0); + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[1], MCHP_PINCTRL_PULLDOWN_POS), 0); +} + +ZTEST(pinctrl_mchp, test_pullup) +{ + const struct pinctrl_state *scfg; + + scfg = &pcfg->states[0]; + + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[2], MCHP_PINCTRL_PULLUP_POS), 1); +} + +ZTEST(pinctrl_mchp, test_pulldown) +{ + const struct pinctrl_state *scfg; + + scfg = &pcfg->states[0]; + + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[3], MCHP_PINCTRL_PULLDOWN_POS), 1); +} + +ZTEST(pinctrl_mchp, test_input_output_enable) +{ + const struct pinctrl_state *scfg; + + scfg = &pcfg->states[0]; + + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[4], MCHP_PINCTRL_INPUTENABLE_POS), 1); + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[4], MCHP_PINCTRL_OUTPUTENABLE_POS), 1); +} + +#if defined(CONFIG_TEST_PINCTRL_MCHP_SAM) +ZTEST(pinctrl_mchp, test_drive_strength) +{ + const struct pinctrl_state *scfg; + + scfg = &pcfg->states[0]; + + zassert_equal(MCHP_PINCTRL_FLAG_GET(scfg->pins[5], MCHP_PINCTRL_DRIVESTRENGTH_POS), 1); +} +#endif + +ZTEST(pinctrl_mchp, test_apply_state) +{ + int ret; + + ret = pinctrl_apply_state(pcfg, PINCTRL_STATE_DEFAULT); + zassert_equal(ret, 0); +} + +ZTEST_SUITE(pinctrl_mchp, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/drivers/pinctrl/microchip/testcase.yaml b/tests/drivers/pinctrl/microchip/testcase.yaml new file mode 100644 index 0000000000000..d08795f9c6da1 --- /dev/null +++ b/tests/drivers/pinctrl/microchip/testcase.yaml @@ -0,0 +1,7 @@ +tests: + drivers.pinctrl.microchip: + tags: + - drivers + - pinctrl + platform_allow: + - sam_e54_xpro