Skip to content

Commit 0561d74

Browse files
nandojvenashif
authored andcommitted
drivers: counter: sam: Add qdec as tc special mode
The current atmel,sam-tc-qdec sensor implementation shared the timer counter node. This create issues when users wants define both modes. The current proposal changes the qdec dedinition to be a child of tc and refactor all the chain of definitions. Fixes #71312 Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent ebb75b3 commit 0561d74

File tree

10 files changed

+94
-51
lines changed

10 files changed

+94
-51
lines changed

boards/atmel/sam/sam_e70_xplained/sam_e70_xplained-common.dtsi

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,31 @@ zephyr_udc0: &usbhs {
210210
max-bitrate = <5000000>;
211211
};
212212
};
213+
214+
&tc0 {
215+
qdec0: qdec {
216+
pinctrl-0 = <&qdec0_default>;
217+
pinctrl-names = "default";
218+
};
219+
};
220+
221+
&tc1 {
222+
qdec1: qdec {
223+
pinctrl-0 = <&qdec1_default>;
224+
pinctrl-names = "default";
225+
};
226+
};
227+
228+
&tc2 {
229+
qdec2: qdec {
230+
pinctrl-0 = <&qdec2_default>;
231+
pinctrl-names = "default";
232+
};
233+
};
234+
235+
&tc3 {
236+
qdec3: qdec {
237+
pinctrl-0 = <&qdec3_default>;
238+
pinctrl-names = "default";
239+
};
240+
};

boards/atmel/sam/sam_e70_xplained/sam_e70_xplained-pinctrl.dtsi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,28 @@
7676
};
7777
};
7878

79-
tc0_qdec_default: tc0_qdec_default {
79+
qdec0_default: qdec0_default {
8080
group1 {
8181
pinmux = <PA0B_TC0_TIOA0>,
8282
<PA1B_TC0_TIOB0>;
8383
};
8484
};
8585

86-
tc1_qdec_default: tc1_qdec_default {
86+
qdec1_default: qdec1_default {
8787
group1 {
8888
pinmux = <PC23B_TC1_TIOA3>,
8989
<PC24B_TC1_TIOB3>;
9090
};
9191
};
9292

93-
tc2_qdec_default: tc2_qdec_default {
93+
qdec2_default: qdec2_default {
9494
group1 {
9595
pinmux = <PC5B_TC2_TIOA6>,
9696
<PC6B_TC2_TIOB6>;
9797
};
9898
};
9999

100-
tc3_qdec_default: tc3_qdec_default {
100+
qdec3_default: qdec3_default {
101101
group1 {
102102
pinmux = <PE0B_TC3_TIOA9>,
103103
<PE1B_TC3_TIOB9>;

boards/atmel/sam/sam_e70_xplained/sam_e70_xplained_same70q21.dts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,3 @@
1515
model = "Atmel SAM E70 Xplained board";
1616
compatible = "atmel,sam_e70_xplained", "atmel,same70q21", "atmel,same70";
1717
};
18-
19-
&tc0 {
20-
status = "okay";
21-
compatible = "atmel,sam-tc-qdec";
22-
23-
pinctrl-0 = <&tc0_qdec_default>;
24-
pinctrl-names = "default";
25-
};
26-
27-
&tc1 {
28-
status = "disabled";
29-
compatible = "atmel,sam-tc-qdec";
30-
31-
pinctrl-0 = <&tc1_qdec_default>;
32-
pinctrl-names = "default";
33-
};
34-
35-
&tc2 {
36-
status = "disabled";
37-
compatible = "atmel,sam-tc-qdec";
38-
39-
pinctrl-0 = <&tc2_qdec_default>;
40-
pinctrl-names = "default";
41-
};
42-
43-
&tc3 {
44-
status = "disabled";
45-
compatible = "atmel,sam-tc-qdec";
46-
47-
pinctrl-0 = <&tc3_qdec_default>;
48-
pinctrl-names = "default";
49-
};

drivers/sensor/qdec_sam/qdec_sam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ static const struct sensor_driver_api qdec_sam_driver_api = {
125125
#define QDEC_SAM_INIT(n) \
126126
PINCTRL_DT_INST_DEFINE(n); \
127127
static const struct qdec_sam_dev_cfg qdec##n##_sam_config = { \
128-
.regs = (Tc *)DT_INST_REG_ADDR(n), \
128+
.regs = (Tc *)DT_REG_ADDR(DT_INST_PARENT(n)), \
129129
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
130-
.clock_cfg = SAM_DT_INST_CLOCKS_PMC_CFG(n), \
130+
.clock_cfg = SAM_DT_CLOCKS_PMC_CFG(DT_INST_PARENT(n)), \
131131
}; \
132132
\
133133
static struct qdec_sam_dev_data qdec##n##_sam_data; \

dts/arm/atmel/same70.dtsi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@
354354
<&pmc PMC_TYPE_PERIPHERAL 24>,
355355
<&pmc PMC_TYPE_PERIPHERAL 25>;
356356
status = "disabled";
357+
358+
qdec {
359+
compatible = "atmel,sam-tc-qdec";
360+
status = "disabled";
361+
};
357362
};
358363

359364
tc1: tc@40010000 {
@@ -366,6 +371,11 @@
366371
<&pmc PMC_TYPE_PERIPHERAL 27>,
367372
<&pmc PMC_TYPE_PERIPHERAL 28>;
368373
status = "disabled";
374+
375+
qdec {
376+
compatible = "atmel,sam-tc-qdec";
377+
status = "disabled";
378+
};
369379
};
370380

371381
tc2: tc@40014000 {
@@ -378,6 +388,11 @@
378388
<&pmc PMC_TYPE_PERIPHERAL 48>,
379389
<&pmc PMC_TYPE_PERIPHERAL 49>;
380390
status = "disabled";
391+
392+
qdec {
393+
compatible = "atmel,sam-tc-qdec";
394+
status = "disabled";
395+
};
381396
};
382397

383398
tc3: tc@40054000 {
@@ -390,6 +405,11 @@
390405
<&pmc PMC_TYPE_PERIPHERAL 51>,
391406
<&pmc PMC_TYPE_PERIPHERAL 52>;
392407
status = "disabled";
408+
409+
qdec {
410+
compatible = "atmel,sam-tc-qdec";
411+
status = "disabled";
412+
};
393413
};
394414

395415
trng: random@40070000 {
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
description: Atmel SAM Timer Counter (TC) QDEC node
3+
description: Atmel SAM Timer Counter (TC) QDEC mode
44

55
compatible: "atmel,sam-tc-qdec"
66

77
include:
88
- name: sensor-device.yaml
99
- name: pinctrl-device.yaml
10-
11-
properties:
12-
reg:
13-
required: true
14-
15-
interrupts:
16-
required: true
17-
18-
clocks:
19-
required: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2024 Gerson Fernando Budke <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
qdec0 = &qdec0;
10+
};
11+
};
12+
13+
&qdec0 {
14+
status = "okay";
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2024 Gerson Fernando Budke <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
qdec0 = &qdec0;
10+
};
11+
};
12+
13+
&qdec0 {
14+
status = "okay";
15+
};

samples/sensor/qdec/sample.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ sample:
44
common:
55
tags: sensors
66
timeout: 5
7-
harness: console
87

98
tests:
109
sample.sensor.qdec_sensor:
10+
filter: dt_alias_exists("qdec0")
11+
12+
sample.sensor.sam_qdec_sensor:
13+
platform_allow:
14+
- sam_e70_xplained/same70q21
15+
- sam_e70_xplained/same70q21b
16+
17+
sample.sensor.st_qdec_sensor:
1118
platform_allow: nucleo_f401re
1219
harness_config:
1320
fixture: fixture_mech_encoder

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ manifest:
152152
groups:
153153
- hal
154154
- name: hal_atmel
155-
revision: d6221e73d76a4a31d802e0657342fcbda77e21ae
155+
revision: 56d60ebc909ad065bf6554cee73487969857614b
156156
path: modules/hal/atmel
157157
groups:
158158
- hal

0 commit comments

Comments
 (0)