Skip to content

Commit dc45d7a

Browse files
nandojvembolivar-nordic
authored andcommitted
drivers: sensors: qdec_sam: Update to use clock control
This update Atmel SAM QDEC driver to use clock control driver. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent f1b68be commit dc45d7a

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

boards/arm/sam_e70_xplained/sam_e70_xplained.dts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (c) 2017 Piotr Mienkowski
33
* Copyright (c) 2017 Justin Watson
4-
* Copyright (c) 2020 Gerson Fernando Budke <[email protected]>
4+
* Copyright (c) 2020-2023 Gerson Fernando Budke <[email protected]>
55
*
66
* SPDX-License-Identifier: Apache-2.0
77
*/
@@ -15,3 +15,11 @@
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+
};

drivers/sensor/qdec_sam/qdec_sam.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818
#include <soc.h>
1919
#include <zephyr/drivers/sensor.h>
2020
#include <zephyr/drivers/pinctrl.h>
21+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
2122

2223
#include <zephyr/logging/log.h>
2324
LOG_MODULE_REGISTER(qdec_sam, CONFIG_SENSOR_LOG_LEVEL);
2425

2526
/* Device constant configuration parameters */
2627
struct qdec_sam_dev_cfg {
2728
Tc *regs;
29+
const struct atmel_sam_pmc_config clock_cfg[TCCHANNEL_NUMBER];
2830
const struct pinctrl_dev_config *pcfg;
29-
uint8_t periph_id[TCCHANNEL_NUMBER];
3031
};
3132

3233
/* Device run time data */
@@ -103,9 +104,10 @@ static int qdec_sam_initialize(const struct device *dev)
103104
return retval;
104105
}
105106

106-
for (int i = 0; i < ARRAY_SIZE(dev_cfg->periph_id); i++) {
107-
/* Enable module's clock */
108-
soc_pmc_peripheral_enable(dev_cfg->periph_id[i]);
107+
for (int i = 0; i < ARRAY_SIZE(dev_cfg->clock_cfg); i++) {
108+
/* Enable TC clock in PMC */
109+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
110+
(clock_control_subsys_t *)&dev_cfg->clock_cfg[i]);
109111
}
110112

111113
qdec_sam_configure(dev);
@@ -125,7 +127,7 @@ static const struct sensor_driver_api qdec_sam_driver_api = {
125127
static const struct qdec_sam_dev_cfg qdec##n##_sam_config = { \
126128
.regs = (Tc *)DT_INST_REG_ADDR(n), \
127129
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
128-
.periph_id = DT_INST_PROP(n, peripheral_id), \
130+
.clock_cfg = SAM_DT_INST_CLOCKS_PMC_CFG(n), \
129131
}; \
130132
\
131133
static struct qdec_sam_dev_data qdec##n##_sam_data; \

dts/bindings/sensor/atmel,sam-tc-qdec.yaml

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

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

0 commit comments

Comments
 (0)