Skip to content

Commit eb2c6d7

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: timer: sam: Update to use clock control
This update Atmel SAM timer driver to use clock control drivers. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 3c7988c commit eb2c6d7

File tree

7 files changed

+45
-20
lines changed

7 files changed

+45
-20
lines changed

drivers/counter/counter_sam_tc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2021, Piotr Mienkowski
3+
* Copyright (c) 2023, Gerson Fernando Budke
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -31,6 +32,7 @@
3132
#include <soc.h>
3233
#include <zephyr/drivers/counter.h>
3334
#include <zephyr/drivers/pinctrl.h>
35+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
3436

3537
#include <zephyr/logging/log.h>
3638
#include <zephyr/irq.h>
@@ -51,11 +53,11 @@ struct counter_sam_dev_cfg {
5153
uint32_t reg_cmr;
5254
uint32_t reg_rc;
5355
void (*irq_config_func)(const struct device *dev);
56+
const struct atmel_sam_pmc_config clock_cfg[TCCHANNEL_NUMBER];
5457
const struct pinctrl_dev_config *pcfg;
5558
uint8_t clk_sel;
5659
bool nodivclk;
5760
uint8_t tc_chan_num;
58-
uint8_t periph_id[TCCHANNEL_NUMBER];
5961
};
6062

6163
struct counter_sam_alarm_data {
@@ -322,7 +324,8 @@ static int counter_sam_initialize(const struct device *dev)
322324
}
323325

324326
/* Enable channel's clock */
325-
soc_pmc_peripheral_enable(dev_cfg->periph_id[dev_cfg->tc_chan_num]);
327+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
328+
(clock_control_subsys_t *)&dev_cfg->clock_cfg[dev_cfg->tc_chan_num]);
326329

327330
/* Clock and Mode Selection */
328331
tc_ch->TC_CMR = dev_cfg->reg_cmr;
@@ -384,7 +387,7 @@ static const struct counter_sam_dev_cfg counter_##n##_sam_config = { \
384387
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
385388
.nodivclk = DT_INST_PROP(n, nodivclk), \
386389
.tc_chan_num = DT_INST_PROP_OR(n, channel, 0), \
387-
.periph_id = DT_INST_PROP(n, peripheral_id), \
390+
.clock_cfg = SAM_DT_INST_CLOCKS_PMC_CFG(n), \
388391
}; \
389392
\
390393
static struct counter_sam_dev_data counter_##n##_sam_data; \

dts/arm/atmel/sam3x.dtsi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@
199199
interrupts = <27 0
200200
28 0
201201
29 0>;
202-
peripheral-id = <27 28 29>;
202+
clocks = <&pmc PMC_TYPE_PERIPHERAL 27>,
203+
<&pmc PMC_TYPE_PERIPHERAL 28>,
204+
<&pmc PMC_TYPE_PERIPHERAL 29>;
203205
status = "disabled";
204206
};
205207

@@ -209,7 +211,9 @@
209211
interrupts = <30 0
210212
31 0
211213
32 0>;
212-
peripheral-id = <30 31 32>;
214+
clocks = <&pmc PMC_TYPE_PERIPHERAL 30>,
215+
<&pmc PMC_TYPE_PERIPHERAL 31>,
216+
<&pmc PMC_TYPE_PERIPHERAL 32>;
213217
status = "disabled";
214218
};
215219

@@ -219,7 +223,9 @@
219223
interrupts = <33 0
220224
34 0
221225
35 0>;
222-
peripheral-id = <33 34 35>;
226+
clocks = <&pmc PMC_TYPE_PERIPHERAL 33>,
227+
<&pmc PMC_TYPE_PERIPHERAL 34>,
228+
<&pmc PMC_TYPE_PERIPHERAL 35>;
223229
status = "disabled";
224230
};
225231
};

dts/arm/atmel/sam4e.dtsi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@
218218
interrupts = <21 0
219219
22 0
220220
23 0>;
221-
peripheral-id = <21 22 23>;
221+
clocks = <&pmc PMC_TYPE_PERIPHERAL 21>,
222+
<&pmc PMC_TYPE_PERIPHERAL 22>,
223+
<&pmc PMC_TYPE_PERIPHERAL 23>;
222224
status = "disabled";
223225
};
224226

@@ -228,7 +230,9 @@
228230
interrupts = <24 0
229231
25 0
230232
26 0>;
231-
peripheral-id = <24 25 26>;
233+
clocks = <&pmc PMC_TYPE_PERIPHERAL 24>,
234+
<&pmc PMC_TYPE_PERIPHERAL 25>,
235+
<&pmc PMC_TYPE_PERIPHERAL 26>;
232236
status = "disabled";
233237
};
234238

@@ -238,7 +242,9 @@
238242
interrupts = <27 0
239243
28 0
240244
29 0>;
241-
peripheral-id = <27 28 29>;
245+
clocks = <&pmc PMC_TYPE_PERIPHERAL 27>,
246+
<&pmc PMC_TYPE_PERIPHERAL 28>,
247+
<&pmc PMC_TYPE_PERIPHERAL 29>;
242248
status = "disabled";
243249
};
244250

dts/arm/atmel/sam4l.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
interrupts = <55 0
212212
56 0
213213
57 0>;
214-
peripheral-id = <2>;
214+
clocks = <&pmc PMC_TYPE_PERIPHERAL 2>;
215215
status = "disabled";
216216
};
217217

@@ -221,7 +221,7 @@
221221
interrupts = <58 0
222222
59 0
223223
60 0>;
224-
peripheral-id = <3>;
224+
clocks = <&pmc PMC_TYPE_PERIPHERAL 3>;
225225
status = "disabled";
226226
};
227227

dts/arm/atmel/sam4s.dtsi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@
195195
interrupts = <23 0
196196
24 0
197197
25 0>;
198-
peripheral-id = <23 24 25>;
198+
clocks = <&pmc PMC_TYPE_PERIPHERAL 23>,
199+
<&pmc PMC_TYPE_PERIPHERAL 24>,
200+
<&pmc PMC_TYPE_PERIPHERAL 25>;
199201
status = "disabled";
200202
};
201203

@@ -205,7 +207,9 @@
205207
interrupts = <26 0
206208
27 0
207209
28 0>;
208-
peripheral-id = <26 27 28>;
210+
clocks = <&pmc PMC_TYPE_PERIPHERAL 26>,
211+
<&pmc PMC_TYPE_PERIPHERAL 27>,
212+
<&pmc PMC_TYPE_PERIPHERAL 28>;
209213
status = "disabled";
210214
};
211215

dts/arm/atmel/same70.dtsi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@
340340
interrupts = <23 0
341341
24 0
342342
25 0>;
343-
peripheral-id = <23 24 25>;
343+
clocks = <&pmc PMC_TYPE_PERIPHERAL 23>,
344+
<&pmc PMC_TYPE_PERIPHERAL 24>,
345+
<&pmc PMC_TYPE_PERIPHERAL 25>;
344346
status = "disabled";
345347
};
346348

@@ -350,7 +352,9 @@
350352
interrupts = <26 0
351353
27 0
352354
28 0>;
353-
peripheral-id = <26 27 28>;
355+
clocks = <&pmc PMC_TYPE_PERIPHERAL 26>,
356+
<&pmc PMC_TYPE_PERIPHERAL 27>,
357+
<&pmc PMC_TYPE_PERIPHERAL 28>;
354358
status = "disabled";
355359
};
356360

@@ -360,7 +364,9 @@
360364
interrupts = <47 0
361365
48 0
362366
49 0>;
363-
peripheral-id = <47 48 49>;
367+
clocks = <&pmc PMC_TYPE_PERIPHERAL 47>,
368+
<&pmc PMC_TYPE_PERIPHERAL 48>,
369+
<&pmc PMC_TYPE_PERIPHERAL 49>;
364370
status = "disabled";
365371
};
366372

@@ -370,7 +376,9 @@
370376
interrupts = <50 0
371377
51 0
372378
52 0>;
373-
peripheral-id = <50 51 52>;
379+
clocks = <&pmc PMC_TYPE_PERIPHERAL 50>,
380+
<&pmc PMC_TYPE_PERIPHERAL 51>,
381+
<&pmc PMC_TYPE_PERIPHERAL 52>;
374382
status = "disabled";
375383
};
376384

dts/bindings/timer/atmel,sam-tc.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ properties:
1515
interrupts:
1616
required: true
1717

18-
peripheral-id:
19-
type: array
20-
description: peripheral ID
18+
clocks:
2119
required: true
2220

2321
channel:

0 commit comments

Comments
 (0)