7
7
8
8
/*
9
9
* SPDX-FileCopyrightText: Copyright (c) 2024 Carl Zeiss Meditec AG
10
+ * SPDX-FileCopyrightText: Copyright (c) 2025 Prevas A/S
10
11
*
11
12
* SPDX-License-Identifier: Apache-2.0
12
13
*/
@@ -49,16 +50,28 @@ extern "C" {
49
50
#define TMC_RAMP_VSTOP_MIN 1
50
51
#define TMC_RAMP_TZEROWAIT_MAX (GENMASK(15, 0) - 512)
51
52
#define TMC_RAMP_TZEROWAIT_MIN 0
52
- #define TMC_RAMP_VCOOLTHRS_MAX GENMASK(22, 0)
53
- #define TMC_RAMP_VCOOLTHRS_MIN 0
54
- #define TMC_RAMP_VHIGH_MAX GENMASK(22, 0)
55
- #define TMC_RAMP_VHIGH_MIN 0
56
53
#define TMC_RAMP_IHOLD_IRUN_MAX GENMASK(4, 0)
57
54
#define TMC_RAMP_IHOLD_IRUN_MIN 0
58
55
#define TMC_RAMP_IHOLDDELAY_MAX GENMASK(3, 0)
59
56
#define TMC_RAMP_IHOLDDELAY_MIN 0
60
57
#define TMC_RAMP_VACTUAL_SHIFT 22
61
58
59
+ /* TMC50XX specific */
60
+ #define TMC_RAMP_VCOOLTHRS_MAX GENMASK(22, 0)
61
+ #define TMC_RAMP_VCOOLTHRS_MIN 0
62
+ #define TMC_RAMP_VHIGH_MAX GENMASK(22, 0)
63
+ #define TMC_RAMP_VHIGH_MIN 0
64
+
65
+ /* TMC51XX specific */
66
+ #define TMC_RAMP_TPOWERDOWN_MAX GENMASK(7, 0)
67
+ #define TMC_RAMP_TPOWERDOWN_MIN 0
68
+ #define TMC_RAMP_TPWMTHRS_MAX GENMASK(19, 0)
69
+ #define TMC_RAMP_TPWMTHRS_MIN 0
70
+ #define TMC_RAMP_TCOOLTHRS_MAX GENMASK(19, 0)
71
+ #define TMC_RAMP_TCOOLTHRS_MIN 0
72
+ #define TMC_RAMP_THIGH_MAX GENMASK(19, 0)
73
+ #define TMC_RAMP_THIGH_MIN 0
74
+
62
75
/**
63
76
* @brief Trinamic Stepper Ramp Generator data
64
77
*/
@@ -72,9 +85,21 @@ struct tmc_ramp_generator_data {
72
85
uint16_t dmax ;
73
86
uint32_t vstop ;
74
87
uint16_t tzerowait ;
75
- uint32_t vcoolthrs ;
76
- uint32_t vhigh ;
77
88
uint32_t iholdrun ;
89
+ union {
90
+ /* TMC50XX specific */
91
+ struct {
92
+ uint32_t vcoolthrs ;
93
+ uint32_t vhigh ;
94
+ };
95
+ /* TMC51XX specific */
96
+ struct {
97
+ uint32_t tpowerdown ;
98
+ uint32_t tpwmthrs ;
99
+ uint32_t tcoolthrs ;
100
+ uint32_t thigh ;
101
+ };
102
+ };
78
103
};
79
104
80
105
/**
@@ -108,12 +133,6 @@ struct tmc_ramp_generator_data {
108
133
COND_CODE_1(DT_PROP_EXISTS(node, tzerowait), \
109
134
BUILD_ASSERT(IN_RANGE(DT_PROP(node, tzerowait), TMC_RAMP_TZEROWAIT_MIN, \
110
135
TMC_RAMP_TZEROWAIT_MAX), "tzerowait out of range"), ()); \
111
- COND_CODE_1(DT_PROP_EXISTS(node, vcoolthrs), \
112
- BUILD_ASSERT(IN_RANGE(DT_PROP(node, vcoolthrs), TMC_RAMP_VCOOLTHRS_MIN, \
113
- TMC_RAMP_VCOOLTHRS_MAX), "vcoolthrs out of range"), ()); \
114
- COND_CODE_1(DT_PROP_EXISTS(node, vhigh), \
115
- BUILD_ASSERT(IN_RANGE(DT_PROP(node, vhigh), TMC_RAMP_VHIGH_MIN, \
116
- TMC_RAMP_VHIGH_MAX), "vhigh out of range"), ()); \
117
136
COND_CODE_1(DT_PROP_EXISTS(node, ihold), \
118
137
BUILD_ASSERT(IN_RANGE(DT_PROP(node, ihold), TMC_RAMP_IHOLD_IRUN_MIN, \
119
138
TMC_RAMP_IHOLD_IRUN_MAX), "ihold out of range"), ()); \
@@ -122,7 +141,27 @@ struct tmc_ramp_generator_data {
122
141
TMC_RAMP_IHOLD_IRUN_MAX), "irun out of range"), ()); \
123
142
COND_CODE_1(DT_PROP_EXISTS(node, iholddelay), \
124
143
BUILD_ASSERT(IN_RANGE(DT_PROP(node, iholddelay), TMC_RAMP_IHOLDDELAY_MIN, \
125
- TMC_RAMP_IHOLDDELAY_MAX), "iholddelay out of range"), ());
144
+ TMC_RAMP_IHOLDDELAY_MAX), "iholddelay out of range"), ());\
145
+ /* TMC50XX specific */ \
146
+ COND_CODE_1 (DT_PROP_EXISTS (node , vcoolthrs ), \
147
+ BUILD_ASSERT (IN_RANGE (DT_PROP (node , vcoolthrs ), TMC_RAMP_VCOOLTHRS_MIN , \
148
+ TMC_RAMP_VCOOLTHRS_MAX ), "vcoolthrs out of range" ), ( )); \
149
+ COND_CODE_1 (DT_PROP_EXISTS (node , vhigh ), \
150
+ BUILD_ASSERT (IN_RANGE (DT_PROP (node , vhigh ), TMC_RAMP_VHIGH_MIN , \
151
+ TMC_RAMP_VHIGH_MAX ), "vhigh out of range" ), ( )); \
152
+ /* TMC51XX specific */ \
153
+ COND_CODE_1 (DT_PROP_EXISTS (node , tpowerdown ), \
154
+ BUILD_ASSERT (IN_RANGE (DT_PROP (node , tpowerdown ), TMC_RAMP_TPOWERDOWN_MIN , \
155
+ TMC_RAMP_TPOWERDOWN_MAX ), "tpowerdown out of range" ), ( ));\
156
+ COND_CODE_1 (DT_PROP_EXISTS (node , tpwmthrs ), \
157
+ BUILD_ASSERT (IN_RANGE (DT_PROP (node , tpwmthrs ), TMC_RAMP_TPWMTHRS_MIN , \
158
+ TMC_RAMP_TPWMTHRS_MAX ), "tpwmthrs out of range" ), ( )); \
159
+ COND_CODE_1 (DT_PROP_EXISTS (node , tcoolthrs ), \
160
+ BUILD_ASSERT (IN_RANGE (DT_PROP (node , tcoolthrs ), TMC_RAMP_TCOOLTHRS_MIN , \
161
+ TMC_RAMP_TCOOLTHRS_MAX ), "tcoolthrs out of range" ), ( )); \
162
+ COND_CODE_1 (DT_PROP_EXISTS (node , thigh ), \
163
+ BUILD_ASSERT (IN_RANGE (DT_PROP (node , thigh ), TMC_RAMP_THIGH_MIN , \
164
+ TMC_RAMP_THIGH_MAX ), "thigh out of range" ), ( ));
126
165
127
166
/**
128
167
* @brief Get Trinamic Stepper Ramp Generator data from DT
@@ -131,8 +170,7 @@ struct tmc_ramp_generator_data {
131
170
*
132
171
* @return struct tmc_ramp_generator_data
133
172
*/
134
- #define TMC_RAMP_DT_SPEC_GET (node ) \
135
- { \
173
+ #define TMC_RAMP_DT_SPEC_GET_COMMON (node ) \
136
174
.vstart = DT_PROP(node, vstart), \
137
175
.v1 = DT_PROP(node, v1), \
138
176
.vmax = DT_PROP(node, vmax), \
@@ -142,11 +180,24 @@ struct tmc_ramp_generator_data {
142
180
.dmax = DT_PROP(node, dmax), \
143
181
.vstop = DT_PROP(node, vstop), \
144
182
.tzerowait = DT_PROP(node, tzerowait), \
145
- .vcoolthrs = DT_PROP(node, vcoolthrs), \
146
- .vhigh = DT_PROP(node, vhigh), \
147
183
.iholdrun = (TMC5XXX_IRUN(DT_PROP(node, irun)) | \
148
184
TMC5XXX_IHOLD(DT_PROP(node, ihold)) | \
149
- TMC5XXX_IHOLDDELAY(DT_PROP(node, iholddelay))), \
185
+ TMC5XXX_IHOLDDELAY(DT_PROP(node, iholddelay))),
186
+
187
+ #define TMC_RAMP_DT_SPEC_GET_TMC50XX (node ) \
188
+ { \
189
+ TMC_RAMP_DT_SPEC_GET_COMMON(node) \
190
+ .vhigh = DT_PROP(node, vhigh), \
191
+ .vcoolthrs = DT_PROP(node, vcoolthrs), \
192
+ }
193
+
194
+ #define TMC_RAMP_DT_SPEC_GET_TMC51XX (node ) \
195
+ { \
196
+ TMC_RAMP_DT_SPEC_GET_COMMON(DT_DRV_INST(node)) \
197
+ .tpowerdown = DT_INST_PROP(node, tpowerdown), \
198
+ .tpwmthrs = DT_INST_PROP(node, tpwmthrs), \
199
+ .tcoolthrs = DT_INST_PROP(node, tcoolthrs), \
200
+ .thigh = DT_INST_PROP(node, thigh), \
150
201
}
151
202
152
203
/**
0 commit comments