Skip to content

Commit ebbb4b6

Browse files
henrikbrixandersencarlescufi
authored andcommitted
drivers: can: sam: use UPLL clock instead of PLLA clock
Use the UPLLCK clock for the CAN controller as recommended by the Atmel SAM E70 data sheet. Move the configuration of the clock prescaler from Kconfig to devicetree and limit it to the values recommended by the SAM E70 datasheet. Fixes: #45012 Signed-off-by: Henrik Brix Andersen <[email protected]>
1 parent 03bece0 commit ebbb4b6

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

drivers/can/Kconfig.sam

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,3 @@ config CAN_SAM
88
bool "Atmel SAM CAN driver"
99
default $(dt_compat_enabled,$(DT_COMPAT_ATMEL_SAM_CAN))
1010
select CAN_MCAN
11-
12-
if CAN_SAM
13-
14-
config CAN_SAM_CKDIV
15-
int "Clock divider"
16-
range 0 255
17-
default 0
18-
depends on CAN_SAM
19-
help
20-
Clock divider for the MCAN core clock.
21-
22-
endif #CAN_SAM

drivers/can/can_sam.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct can_sam_config {
2121
void (*config_irq)(void);
2222
const struct pinctrl_dev_config *pcfg;
2323
uint8_t pmc_id;
24+
int divider;
2425
};
2526

2627
struct can_sam_data {
@@ -29,18 +30,20 @@ struct can_sam_data {
2930

3031
static int can_sam_get_core_clock(const struct device *dev, uint32_t *rate)
3132
{
32-
ARG_UNUSED(dev);
33+
const struct can_mcan_config *mcan_cfg = dev->config;
34+
const struct can_sam_config *sam_cfg = mcan_cfg->custom;
3335

34-
*rate = SOC_ATMEL_SAM_MCK_FREQ_HZ / (CONFIG_CAN_SAM_CKDIV + 1);
36+
*rate = SOC_ATMEL_SAM_UPLLCK_FREQ_HZ / (sam_cfg->divider);
3537

3638
return 0;
3739
}
3840

39-
static void can_sam_clock_enable(const struct can_sam_config *cfg)
41+
static void can_sam_clock_enable(const struct can_sam_config *sam_cfg)
4042
{
41-
REG_PMC_PCK5 = PMC_PCK_CSS_PLLA_CLK | PMC_PCK_PRES(CONFIG_CAN_SAM_CKDIV);
43+
REG_PMC_PCK5 = PMC_PCK_CSS_UPLL_CLK | PMC_PCK_PRES(sam_cfg->divider - 1);
4244
PMC->PMC_SCER |= PMC_SCER_PCK5;
43-
soc_pmc_peripheral_enable(cfg->pmc_id);
45+
46+
soc_pmc_peripheral_enable(sam_cfg->pmc_id);
4447
}
4548

4649
static int can_sam_init(const struct device *dev)
@@ -129,6 +132,7 @@ static void config_can_##inst##_irq(void)
129132
#define CAN_SAM_CFG_INST(inst) \
130133
static const struct can_sam_config can_sam_cfg_##inst = { \
131134
.pmc_id = DT_INST_PROP(inst, peripheral_id), \
135+
.divider = DT_INST_PROP(inst, divider), \
132136
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
133137
.config_irq = config_can_##inst##_irq, \
134138
}; \

dts/arm/atmel/same70.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445
interrupts = <35 0>, <36 0>;
446446
interrupt-names = "LINE_0", "LINE_1";
447447
peripheral-id = <35>;
448+
divider = <6>;
448449
sjw = <1>;
449450
sample-point = <875>;
450451
sjw-data = <1>;
@@ -462,6 +463,7 @@
462463
interrupts = <37 0>, <38 0>;
463464
interrupt-names = "LINE_0", "LINE_1";
464465
peripheral-id = <37>;
466+
divider = <6>;
465467
sjw = <1>;
466468
sample-point = <875>;
467469
sjw-data = <1>;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ properties:
1717
type: int
1818
required: true
1919
description: peripheral ID
20+
21+
divider:
22+
type: int
23+
required: true
24+
enum:
25+
- 6
26+
- 12
27+
- 24
28+
description: Clock divider for the CAN core clock

0 commit comments

Comments
 (0)