Skip to content

Commit d2e9b46

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

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

drivers/pwm/pwm_sam.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <errno.h>
1111
#include <zephyr/drivers/pwm.h>
1212
#include <zephyr/drivers/pinctrl.h>
13+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
1314
#include <soc.h>
1415

1516
#include <zephyr/logging/log.h>
@@ -23,8 +24,8 @@ LOG_MODULE_REGISTER(pwm_sam, CONFIG_PWM_LOG_LEVEL);
2324

2425
struct sam_pwm_config {
2526
Pwm *regs;
27+
const struct atmel_sam_pmc_config clock_cfg;
2628
const struct pinctrl_dev_config *pcfg;
27-
uint32_t id;
2829
uint8_t prescaler;
2930
uint8_t divider;
3031
};
@@ -96,15 +97,15 @@ static int sam_pwm_init(const struct device *dev)
9697
const struct sam_pwm_config *config = dev->config;
9798

9899
Pwm * const pwm = config->regs;
99-
uint32_t id = config->id;
100100
uint8_t prescaler = config->prescaler;
101101
uint8_t divider = config->divider;
102102
int retval;
103103

104104
/* FIXME: way to validate prescaler & divider */
105105

106-
/* Enable the PWM peripheral */
107-
soc_pmc_peripheral_enable(id);
106+
/* Enable PWM clock in PMC */
107+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
108+
(clock_control_subsys_t *)&config->clock_cfg);
108109

109110
retval = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
110111
if (retval < 0) {
@@ -127,7 +128,7 @@ static const struct pwm_driver_api sam_pwm_driver_api = {
127128
static const struct sam_pwm_config sam_pwm_config_##inst = { \
128129
.regs = (Pwm *)DT_INST_REG_ADDR(inst), \
129130
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
130-
.id = DT_INST_PROP(inst, peripheral_id), \
131+
.clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(inst), \
131132
.prescaler = DT_INST_PROP(inst, prescaler), \
132133
.divider = DT_INST_PROP(inst, divider), \
133134
}; \

dts/arm/atmel/sam4s.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
compatible = "atmel,sam-pwm";
129129
reg = <0x40020000 0x4000>;
130130
interrupts = <31 1>;
131-
peripheral-id = <31>;
131+
clocks = <&pmc PMC_TYPE_PERIPHERAL 31>;
132132
prescaler = <10>;
133133
divider = <1>;
134134
#pwm-cells = <3>;

dts/arm/atmel/same70.dtsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
compatible = "atmel,sam-pwm";
288288
reg = <0x40020000 0x4000>;
289289
interrupts = <31 0>;
290-
peripheral-id = <31>;
290+
clocks = <&pmc PMC_TYPE_PERIPHERAL 31>;
291291
status = "disabled";
292292
prescaler = <10>;
293293
divider = <1>;
@@ -298,7 +298,7 @@
298298
compatible = "atmel,sam-pwm";
299299
reg = <0x4005c000 0x4000>;
300300
interrupts = <60 0>;
301-
peripheral-id = <60>;
301+
clocks = <&pmc PMC_TYPE_PERIPHERAL 60>;
302302
status = "disabled";
303303
prescaler = <10>;
304304
divider = <1>;

dts/bindings/pwm/atmel,sam-pwm.yaml

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

20-
peripheral-id:
21-
type: int
22-
description: peripheral ID
20+
clocks:
2321
required: true
2422

2523
prescaler:

0 commit comments

Comments
 (0)