Skip to content

Commit 2f149ee

Browse files
committed
[nrf fromtree] tests: boards: nrf: qdec: Add device runtime PM configuration
Add configuration to the test which is using runtime PM on qdec. Signed-off-by: Krzysztof Chruściński <[email protected]> (cherry picked from commit 5371eff)
1 parent 21118d1 commit 2f149ee

File tree

8 files changed

+170
-19
lines changed

8 files changed

+170
-19
lines changed

tests/boards/nrf/qdec/boards/nrf52840dk_nrf52840.overlay

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,27 @@
3131
<NRF_PSEL(QDEC_B, 1, 3)>; /* Arduino D2 */
3232
};
3333
};
34+
35+
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
36+
group1 {
37+
psels = <NRF_PSEL(QDEC_A, 1, 1)>, /* Ardiuno D0 */
38+
<NRF_PSEL(QDEC_B, 1, 3)>; /* Arduino D2 */
39+
low-power-enable;
40+
};
41+
};
3442
};
3543

3644
&qdec0 {
3745
status = "okay";
3846
pinctrl-0 = <&qdec_pinctrl>;
39-
pinctrl-names = "default";
47+
pinctrl-1 = <&qdec_sleep_pinctrl>;
48+
pinctrl-names = "default", "sleep";
4049
steps = < 127 >;
4150
led-pre = < 500 >;
51+
zephyr,pm-device-runtime-auto;
52+
};
53+
54+
/* To prevent enabling console receiver. */
55+
&uart0 {
56+
disable-rx;
4257
};

tests/boards/nrf/qdec/boards/nrf5340dk_nrf5340_cpuapp.overlay

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@
3030
<NRF_PSEL(QDEC_B, 0, 6)>; /* Arduino A2 */
3131
};
3232
};
33+
34+
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
35+
group1 {
36+
psels = <NRF_PSEL(QDEC_A, 0, 4)>,
37+
<NRF_PSEL(QDEC_B, 0, 6)>;
38+
low-power-enable;
39+
};
40+
};
3341
};
3442

3543
&qdec1 {
3644
status = "okay";
3745
pinctrl-0 = <&qdec_pinctrl>;
38-
pinctrl-names = "default";
46+
pinctrl-1 = <&qdec_sleep_pinctrl>;
47+
pinctrl-names = "default", "sleep";
3948
steps = < 127 >;
4049
led-pre = < 500 >;
50+
zephyr,pm-device-runtime-auto;
51+
};
52+
53+
/* To prevent enabling console receiver. */
54+
&uart0 {
55+
disable-rx;
4156
};

tests/boards/nrf/qdec/boards/nrf54h20dk_nrf54h20_cpuapp.overlay

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
<NRF_PSEL(QDEC_B, 1, 2)>;
2929
};
3030
};
31+
32+
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
33+
group1 {
34+
psels = <NRF_PSEL(QDEC_A, 1, 0)>,
35+
<NRF_PSEL(QDEC_B, 1, 2)>;
36+
low-power-enable;
37+
};
38+
};
3139
};
3240

3341
&gpio1 {
@@ -41,7 +49,14 @@
4149
&qdec130 {
4250
status = "okay";
4351
pinctrl-0 = <&qdec_pinctrl>;
44-
pinctrl-names = "default";
52+
pinctrl-1 = <&qdec_sleep_pinctrl>;
53+
pinctrl-names = "default", "sleep";
4554
steps = <127>;
4655
led-pre = <500>;
56+
zephyr,pm-device-runtime-auto;
57+
};
58+
59+
/* To prevent enabling console receiver. */
60+
&uart136 {
61+
disable-rx;
4762
};

tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuapp.overlay

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
*/
55

66
#include "nrf54l15pdk_nrf54l15_common.dtsi"
7+
8+
/* To prevent enabling console receiver. */
9+
&uart20 {
10+
disable-rx;
11+
};

tests/boards/nrf/qdec/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
*/
55

66
#include "nrf54l15pdk_nrf54l15_common.dtsi"
7+
8+
/* To prevent enabling console receiver. */
9+
&uart30 {
10+
disable-rx;
11+
};

tests/boards/nrf/qdec/boards/nrf54l15pdk_nrf54l15_common.dtsi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
<NRF_PSEL(QDEC_B, 1, 10)>;
2929
};
3030
};
31+
32+
qdec_sleep_pinctrl: qdec_sleep_pinctrl {
33+
group1 {
34+
psels = <NRF_PSEL(QDEC_A, 1, 8)>,
35+
<NRF_PSEL(QDEC_B, 1, 10)>;
36+
low-power-enable;
37+
};
38+
};
3139
};
3240

3341
&gpio1 {
@@ -37,7 +45,9 @@
3745
&qdec20 {
3846
status = "okay";
3947
pinctrl-0 = <&qdec_pinctrl>;
40-
pinctrl-names = "default";
48+
pinctrl-1 = <&qdec_sleep_pinctrl>;
49+
pinctrl-names = "default", "sleep";
4150
steps = <127>;
4251
led-pre = <500>;
52+
zephyr,pm-device-runtime-auto;
4353
};

tests/boards/nrf/qdec/src/main.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/device.h>
1010
#include <zephyr/drivers/sensor.h>
1111
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/pm/device_runtime.h>
1213

1314
static K_SEM_DEFINE(sem, 0, 1);
1415
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)
140141
{
141142
int rc;
142143

144+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
145+
pm_device_runtime_get(qdec_dev);
146+
}
147+
143148
qdec_trigger.type = SENSOR_TRIG_DATA_READY;
144149
qdec_trigger.chan = SENSOR_CHAN_ALL;
145150
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
@@ -158,10 +163,18 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable)
158163
/* emulation not working, but there maybe old trigger, ignore */
159164
rc = k_sem_take(&sem, K_MSEC(200));
160165

166+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
167+
pm_device_runtime_put(qdec_dev);
168+
}
169+
161170
/* there should be no triggers now*/
162171
rc = k_sem_take(&sem, K_MSEC(200));
163172
zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc);
164173

174+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
175+
pm_device_runtime_get(qdec_dev);
176+
}
177+
165178
/* register empty trigger - disable trigger */
166179
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, NULL);
167180
zassert_true(rc == 0, "sensor_trigger_set failed: %d", rc);
@@ -171,6 +184,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_and_disable)
171184
/* emulation working, but handler not set, thus should not be called */
172185
rc = k_sem_take(&sem, K_MSEC(200));
173186
zassert_true(rc == -EAGAIN, "qdec handler should not be triggered (%d)", rc);
187+
188+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
189+
pm_device_runtime_put(qdec_dev);
190+
}
174191
}
175192

176193
/**
@@ -184,6 +201,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
184201
int rc;
185202
struct sensor_value val = {0};
186203

204+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
205+
pm_device_runtime_get(qdec_dev);
206+
}
207+
187208
qdec_trigger.type = SENSOR_TRIG_DATA_READY;
188209
qdec_trigger.chan = SENSOR_CHAN_ROTATION;
189210
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
@@ -202,6 +223,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
202223

203224
TC_PRINT("QDEC reading: %d\n", val.val1);
204225
zassert_true(val.val1 != 0, "No readings from QDEC");
226+
227+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
228+
pm_device_runtime_put(qdec_dev);
229+
}
205230
}
206231

207232
/**
@@ -214,6 +239,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative)
214239
{
215240
int rc;
216241

242+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
243+
pm_device_runtime_get(qdec_dev);
244+
}
245+
217246
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
218247
zassume_true(rc != -ENOSYS, "sensor_trigger_set not supported");
219248

@@ -228,6 +257,10 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative)
228257

229258
rc = sensor_trigger_set(qdec_dev, &qdec_trigger, qdec_trigger_handler);
230259
zassume_true(rc < 0, "sensor_trigger_set should fail due to invalid channel");
260+
261+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
262+
pm_device_runtime_put(qdec_dev);
263+
}
231264
}
232265

233266
/**
@@ -238,12 +271,20 @@ ZTEST(qdec_sensor, test_sensor_trigger_set_negative)
238271
*/
239272
ZTEST(qdec_sensor, test_qdec_readings)
240273
{
274+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
275+
pm_device_runtime_get(qdec_dev);
276+
}
277+
241278
qenc_emulate_verify_reading(10, 100, true, false);
242279
qenc_emulate_verify_reading(2, 500, true, false);
243280
qenc_emulate_verify_reading(10, 200, false, false);
244281
/* may lead to overflows but currently driver does not detects that */
245282
qenc_emulate_verify_reading(1, 1000, false, true);
246283
qenc_emulate_verify_reading(1, 1000, true, true);
284+
285+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
286+
pm_device_runtime_put(qdec_dev);
287+
}
247288
}
248289

249290
/**
@@ -257,9 +298,16 @@ ZTEST(qdec_sensor, test_sensor_channel_get_empty)
257298
int rc;
258299
struct sensor_value val = {0};
259300

301+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
302+
pm_device_runtime_get(qdec_dev);
303+
}
304+
260305
rc = sensor_sample_fetch(qdec_dev);
261306
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
262307

308+
/* wait for potential new readings */
309+
k_msleep(100);
310+
263311
/* get readings but ignore them, as they may include reading from time
264312
* when emulation was still working (i.e. during previous test)
265313
*/
@@ -277,6 +325,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_empty)
277325
zassert_true(rc == 0, "Failed to get sample (%d)", rc);
278326
zassert_true(val.val1 == 0, "Expected no readings but got: %d", val.val1);
279327
zassert_true(val.val2 == 0, "Expected no readings but got: %d", val.val2);
328+
329+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
330+
pm_device_runtime_put(qdec_dev);
331+
}
280332
}
281333

282334
/**
@@ -291,6 +343,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
291343
struct sensor_value val_first = {0};
292344
struct sensor_value val_second = {0};
293345

346+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
347+
pm_device_runtime_get(qdec_dev);
348+
}
349+
294350
qenc_emulate_start(K_MSEC(10), true);
295351

296352
/* wait for some readings*/
@@ -325,6 +381,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
325381
*/
326382
TC_PRINT("Expected the same readings: %d vs %d - ignore!\n", val_first.val2,
327383
val_second.val2);
384+
385+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
386+
pm_device_runtime_put(qdec_dev);
387+
}
328388
}
329389

330390
/**
@@ -338,6 +398,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative)
338398
int rc;
339399
struct sensor_value val = {0};
340400

401+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
402+
pm_device_runtime_get(qdec_dev);
403+
}
404+
341405
qenc_emulate_start(K_MSEC(10), true);
342406

343407
/* wait for some readings*/
@@ -350,6 +414,10 @@ ZTEST(qdec_sensor, test_sensor_channel_get_negative)
350414
zassert_true(rc < 0, "Should failed to get sample (%d)", rc);
351415
zassert_true(val.val1 == 0, "Some readings from QDEC: %d", val.val1);
352416
zassert_true(val.val2 == 0, "Some readings from QDEC: %d", val.val2);
417+
418+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
419+
pm_device_runtime_put(qdec_dev);
420+
}
353421
}
354422

355423
/**
@@ -362,6 +430,10 @@ ZTEST(qdec_sensor, test_sensor_sample_fetch)
362430
{
363431
int rc;
364432

433+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
434+
pm_device_runtime_get(qdec_dev);
435+
}
436+
365437
rc = sensor_sample_fetch(qdec_dev);
366438
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
367439

@@ -370,6 +442,10 @@ ZTEST(qdec_sensor, test_sensor_sample_fetch)
370442

371443
rc = sensor_sample_fetch_chan(qdec_dev, SENSOR_CHAN_MAX);
372444
zassert_true(rc < 0, "Should fail to fetch sample from invalid channel (%d)", rc);
445+
446+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME)) {
447+
pm_device_runtime_put(qdec_dev);
448+
}
373449
}
374450

375451
static void *setup(void)
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
common:
2+
platform_allow:
3+
- nrf52840dk/nrf52840
4+
- nrf5340dk/nrf5340/cpuapp
5+
- nrf54l15dk/nrf54l15/cpuapp
6+
- nrf54l15dk/nrf54l15/cpuflpr
7+
- nrf54h20dk/nrf54h20/cpuapp
8+
integration_platforms:
9+
- nrf52840dk/nrf52840
10+
- nrf5340dk/nrf5340/cpuapp
11+
- nrf54l15dk/nrf54l15/cpuapp
12+
- nrf54l15dk/nrf54l15/cpuflpr
13+
- nrf54h20dk/nrf54h20/cpuapp
14+
harness: ztest
15+
harness_config:
16+
fixture: gpio_loopback
117
tests:
218
drivers.sensor.qdec:
319
tags:
420
- drivers
521
- sensors
622
- qdec
7-
platform_allow:
8-
- nrf52840dk/nrf52840
9-
- nrf5340dk/nrf5340/cpuapp
10-
- nrf54l15dk/nrf54l15/cpuapp
11-
- nrf54l15dk/nrf54l15/cpuflpr
12-
- nrf54h20dk/nrf54h20/cpuapp
13-
integration_platforms:
14-
- nrf52840dk/nrf52840
15-
- nrf5340dk/nrf5340/cpuapp
16-
- nrf54l15dk/nrf54l15/cpuapp
17-
- nrf54l15dk/nrf54l15/cpuflpr
18-
- nrf54h20dk/nrf54h20/cpuapp
19-
harness: ztest
20-
harness_config:
21-
fixture: gpio_loopback
23+
drivers.sensor.qdec.pm_runtime:
24+
tags:
25+
- drivers
26+
- sensors
27+
- qdec
28+
- pm
29+
extra_configs:
30+
- CONFIG_PM_DEVICE=y
31+
- CONFIG_PM_DEVICE_RUNTIME=y

0 commit comments

Comments
 (0)