From 2f149ee455332891ec6e1f9272580ee96a06df30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 18 Sep 2024 15:53:28 +0200 Subject: [PATCH] [nrf fromtree] tests: boards: nrf: qdec: Add device runtime PM configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add configuration to the test which is using runtime PM on qdec. Signed-off-by: Krzysztof Chruściński (cherry picked from commit 5371effda8ff2bfc1a8e219a33c4de32ae45143d) --- .../qdec/boards/nrf52840dk_nrf52840.overlay | 17 ++++- .../boards/nrf5340dk_nrf5340_cpuapp.overlay | 17 ++++- .../boards/nrf54h20dk_nrf54h20_cpuapp.overlay | 17 ++++- .../boards/nrf54l15dk_nrf54l15_cpuapp.overlay | 5 ++ .../nrf54l15dk_nrf54l15_cpuflpr.overlay | 5 ++ .../boards/nrf54l15pdk_nrf54l15_common.dtsi | 12 ++- tests/boards/nrf/qdec/src/main.c | 76 +++++++++++++++++++ tests/boards/nrf/qdec/testcase.yaml | 40 ++++++---- 8 files changed, 170 insertions(+), 19 deletions(-) diff --git a/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay b/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay index 4f8ea8ad31b..f227fb95c38 100644 --- a/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay +++ b/tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay @@ -31,12 +31,27 @@ ; /* Arduino D2 */ }; }; + + qdec_sleep_pinctrl: qdec_sleep_pinctrl { + group1 { + psels = , /* Ardiuno D0 */ + ; /* Arduino D2 */ + low-power-enable; + }; + }; }; &qdec0 { status = "okay"; pinctrl-0 = <&qdec_pinctrl>; - pinctrl-names = "default"; + pinctrl-1 = <&qdec_sleep_pinctrl>; + pinctrl-names = "default", "sleep"; steps = < 127 >; led-pre = < 500 >; + zephyr,pm-device-runtime-auto; +}; + +/* To prevent enabling console receiver. */ +&uart0 { + disable-rx; }; diff --git a/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay b/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay index 7f4a13f3602..ed6a5587f5b 100644 --- a/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay +++ b/tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay @@ -30,12 +30,27 @@ ; /* Arduino A2 */ }; }; + + qdec_sleep_pinctrl: qdec_sleep_pinctrl { + group1 { + psels = , + ; + low-power-enable; + }; + }; }; &qdec1 { status = "okay"; pinctrl-0 = <&qdec_pinctrl>; - pinctrl-names = "default"; + pinctrl-1 = <&qdec_sleep_pinctrl>; + pinctrl-names = "default", "sleep"; steps = < 127 >; led-pre = < 500 >; + zephyr,pm-device-runtime-auto; +}; + +/* To prevent enabling console receiver. */ +&uart0 { + disable-rx; }; diff --git a/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay b/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay index 6b0db6ad6a8..0e552906a00 100644 --- a/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay +++ b/tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay @@ -28,6 +28,14 @@ ; }; }; + + qdec_sleep_pinctrl: qdec_sleep_pinctrl { + group1 { + psels = , + ; + low-power-enable; + }; + }; }; &gpio1 { @@ -41,7 +49,14 @@ &qdec130 { status = "okay"; pinctrl-0 = <&qdec_pinctrl>; - pinctrl-names = "default"; + pinctrl-1 = <&qdec_sleep_pinctrl>; + pinctrl-names = "default", "sleep"; steps = <127>; led-pre = <500>; + zephyr,pm-device-runtime-auto; +}; + +/* To prevent enabling console receiver. */ +&uart136 { + disable-rx; }; diff --git a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuapp.overlay b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuapp.overlay index 63276a93656..dc39be6deb3 100644 --- a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuapp.overlay +++ b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuapp.overlay @@ -4,3 +4,8 @@ */ #include "nrf54l15pdk_nrf54l15_common.dtsi" + +/* To prevent enabling console receiver. */ +&uart20 { + disable-rx; +}; diff --git a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay index 63276a93656..059222c801b 100644 --- a/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay +++ b/tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay @@ -4,3 +4,8 @@ */ #include "nrf54l15pdk_nrf54l15_common.dtsi" + +/* To prevent enabling console receiver. */ +&uart30 { + disable-rx; +}; diff --git a/tests/boards/nrf/qdec/boards/nrf54l15pdk_nrf54l15_common.dtsi b/tests/boards/nrf/qdec/boards/nrf54l15pdk_nrf54l15_common.dtsi index 538106b38b1..3fa426569b8 100644 --- a/tests/boards/nrf/qdec/boards/nrf54l15pdk_nrf54l15_common.dtsi +++ b/tests/boards/nrf/qdec/boards/nrf54l15pdk_nrf54l15_common.dtsi @@ -28,6 +28,14 @@ ; }; }; + + qdec_sleep_pinctrl: qdec_sleep_pinctrl { + group1 { + psels = , + ; + low-power-enable; + }; + }; }; &gpio1 { @@ -37,7 +45,9 @@ &qdec20 { status = "okay"; pinctrl-0 = <&qdec_pinctrl>; - pinctrl-names = "default"; + pinctrl-1 = <&qdec_sleep_pinctrl>; + pinctrl-names = "default", "sleep"; steps = <127>; led-pre = <500>; + zephyr,pm-device-runtime-auto; }; diff --git a/tests/boards/nrf/qdec/src/main.c b/tests/boards/nrf/qdec/src/main.c index 639e92f8510..e9c2de318f1 100644 --- a/tests/boards/nrf/qdec/src/main.c +++ b/tests/boards/nrf/qdec/src/main.c @@ -9,6 +9,7 @@ #include #include #include +#include static K_SEM_DEFINE(sem, 0, 1); static const struct gpio_dt_spec phase_a = GPIO_DT_SPEC_GET(DT_ALIAS(qenca), gpios); @@ -140,6 +141,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) { int rc; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_ALL; rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); @@ -158,10 +163,18 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) /* emulation not working, but there maybe old trigger, ignore */ rc = k_sem_take(&sem, K_MSEC(200)); + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } + /* there should be no triggers now*/ rc = k_sem_take(&sem, K_MSEC(200)); zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc); + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + /* register empty trigger - disable trigger */ rc = sensor_trigger_set(qdec_dev, &qdec_trigger, NULL); zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc); @@ -171,6 +184,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable) /* emulation working, but handler not set, thus should not be called */ rc = k_sem_take(&sem, K_MSEC(200)); zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -184,6 +201,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set) int rc; struct sensor_value val = {0}; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + qdec_trigger.type = SENSOR_TRIG_DATA_READY; qdec_trigger.chan = SENSOR_CHAN_ROTATION; rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); @@ -202,6 +223,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set) TC_PRINT("QDEC reading: %d\n", val.val1); zassert_true(val.val1 != 0, "No readings from QDEC"); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -214,6 +239,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative) { int rc; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported"); @@ -228,6 +257,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative) rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler); zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid channel"); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -238,12 +271,20 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative) */ ZTEST(qdec_sensor, test_qdec_readings) { + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + qenc_emulate_verify_reading(10, 100, true, false); qenc_emulate_verify_reading(2, 500, true, false); qenc_emulate_verify_reading(10, 200, false, false); /* may lead to overflows but currently driver does not detects that */ qenc_emulate_verify_reading(1, 1000, false, true); qenc_emulate_verify_reading(1, 1000, true, true); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -257,9 +298,16 @@ ZTEST(qdec_sensor, test_sensor_channel_get_empty) int rc; struct sensor_value val = {0}; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + rc = sensor_sample_fetch(qdec_dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); + /* wait for potential new readings */ + k_msleep(100); + /* get readings but ignore them, as they may include reading from time * when emulation was still working (i.e. during previous test) */ @@ -277,6 +325,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_empty) zassert_true(rc == 0, "Failed to get sample (%d)", rc); zassert_true(val.val1 == 0, "Expected no readings but got: %d", val.val1); zassert_true(val.val2 == 0, "Expected no readings but got: %d", val.val2); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -291,6 +343,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get) struct sensor_value val_first = {0}; struct sensor_value val_second = {0}; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + qenc_emulate_start(K_MSEC(10), true); /* wait for some readings*/ @@ -325,6 +381,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get) */ TC_PRINT("Expected the same readings: %d vs %d - ignore!\n", val_first.val2, val_second.val2); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -338,6 +398,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative) int rc; struct sensor_value val = {0}; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + qenc_emulate_start(K_MSEC(10), true); /* wait for some readings*/ @@ -350,6 +414,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative) zassert_true(rc < 0, "Should failed to get sample (%d)", rc); zassert_true(val.val1 == 0, "Some readings from QDEC: %d", val.val1); zassert_true(val.val2 == 0, "Some readings from QDEC: %d", val.val2); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } /** @@ -362,6 +430,10 @@ ZTEST(qdec_sensor, test_sensor_sample_fetch) { int rc; + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_get(qdec_dev); + } + rc = sensor_sample_fetch(qdec_dev); zassert_true(rc == 0, "Failed to fetch sample (%d)", rc); @@ -370,6 +442,10 @@ ZTEST(qdec_sensor, test_sensor_sample_fetch) rc = sensor_sample_fetch_chan(qdec_dev, SENSOR_CHAN_MAX); zassert_true(rc < 0, "Should fail to fetch sample from invalid channel (%d)", rc); + + if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) { + pm_device_runtime_put(qdec_dev); + } } static void *setup(void) diff --git a/tests/boards/nrf/qdec/testcase.yaml b/tests/boards/nrf/qdec/testcase.yaml index 4bc634412db..26cfd9901a5 100644 --- a/tests/boards/nrf/qdec/testcase.yaml +++ b/tests/boards/nrf/qdec/testcase.yaml @@ -1,21 +1,31 @@ +common: + platform_allow: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf54l15dk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuflpr + - nrf54h20dk/nrf54h20/cpuapp + integration_platforms: + - nrf52840dk/nrf52840 + - nrf5340dk/nrf5340/cpuapp + - nrf54l15dk/nrf54l15/cpuapp + - nrf54l15dk/nrf54l15/cpuflpr + - nrf54h20dk/nrf54h20/cpuapp + harness: ztest + harness_config: + fixture: gpio_loopback tests: drivers.sensor.qdec: tags: - drivers - sensors - qdec - platform_allow: - - nrf52840dk/nrf52840 - - nrf5340dk/nrf5340/cpuapp - - nrf54l15dk/nrf54l15/cpuapp - - nrf54l15dk/nrf54l15/cpuflpr - - nrf54h20dk/nrf54h20/cpuapp - integration_platforms: - - nrf52840dk/nrf52840 - - nrf5340dk/nrf5340/cpuapp - - nrf54l15dk/nrf54l15/cpuapp - - nrf54l15dk/nrf54l15/cpuflpr - - nrf54h20dk/nrf54h20/cpuapp - harness: ztest - harness_config: - fixture: gpio_loopback + drivers.sensor.qdec.pm_runtime: + tags: + - drivers + - sensors + - qdec + - pm + extra_configs: + - CONFIG_PM_DEVICE=y + - CONFIG_PM_DEVICE_RUNTIME=y