Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions drivers/can/Kconfig.sam
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,3 @@ config CAN_SAM
bool "Atmel SAM CAN driver"
default $(dt_compat_enabled,$(DT_COMPAT_ATMEL_SAM_CAN))
select CAN_MCAN

if CAN_SAM

config CAN_SAM_CKDIV
int "Clock divider"
range 0 255
default 0
depends on CAN_SAM
help
Clock divider for the MCAN core clock.

endif #CAN_SAM
14 changes: 9 additions & 5 deletions drivers/can/can_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct can_sam_config {
void (*config_irq)(void);
const struct pinctrl_dev_config *pcfg;
uint8_t pmc_id;
int divider;
};

struct can_sam_data {
Expand All @@ -29,18 +30,20 @@ struct can_sam_data {

static int can_sam_get_core_clock(const struct device *dev, uint32_t *rate)
{
ARG_UNUSED(dev);
const struct can_mcan_config *mcan_cfg = dev->config;
const struct can_sam_config *sam_cfg = mcan_cfg->custom;

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

return 0;
}

static void can_sam_clock_enable(const struct can_sam_config *cfg)
static void can_sam_clock_enable(const struct can_sam_config *sam_cfg)
{
REG_PMC_PCK5 = PMC_PCK_CSS_PLLA_CLK | PMC_PCK_PRES(CONFIG_CAN_SAM_CKDIV);
REG_PMC_PCK5 = PMC_PCK_CSS_UPLL_CLK | PMC_PCK_PRES(sam_cfg->divider - 1);
PMC->PMC_SCER |= PMC_SCER_PCK5;
soc_pmc_peripheral_enable(cfg->pmc_id);

soc_pmc_peripheral_enable(sam_cfg->pmc_id);
}

static int can_sam_init(const struct device *dev)
Expand Down Expand Up @@ -129,6 +132,7 @@ static void config_can_##inst##_irq(void)
#define CAN_SAM_CFG_INST(inst) \
static const struct can_sam_config can_sam_cfg_##inst = { \
.pmc_id = DT_INST_PROP(inst, peripheral_id), \
.divider = DT_INST_PROP(inst, divider), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.config_irq = config_can_##inst##_irq, \
}; \
Expand Down
6 changes: 2 additions & 4 deletions dts/arm/atmel/same70.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,12 @@

can0: can@40030000 {
compatible = "atmel,sam-can";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40030000 0x100>;
reg-names = "m_can";
interrupts = <35 0>, <36 0>;
interrupt-names = "LINE_0", "LINE_1";
peripheral-id = <35>;
divider = <6>;
sjw = <1>;
sample-point = <875>;
sjw-data = <1>;
Expand All @@ -455,13 +454,12 @@

can1: can@40034000 {
compatible = "atmel,sam-can";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40034000 0x100>;
reg-names = "m_can";
interrupts = <37 0>, <38 0>;
interrupt-names = "LINE_0", "LINE_1";
peripheral-id = <37>;
divider = <6>;
sjw = <1>;
sample-point = <875>;
sjw-data = <1>;
Expand Down
9 changes: 9 additions & 0 deletions dts/bindings/can/atmel,sam-can.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ properties:
type: int
required: true
description: peripheral ID

divider:
type: int
required: true
enum:
- 6
- 12
- 24
description: Clock divider for the CAN core clock
8 changes: 8 additions & 0 deletions soc/arm/atmel_sam/same70/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ static ALWAYS_INLINE void clock_init(void)
;
}

/* Setup UPLL */
PMC->CKGR_UCKR = CKGR_UCKR_UPLLCOUNT(0x3Fu) | CKGR_UCKR_UPLLEN;

/* Wait for PLL lock */
while (!(PMC->PMC_SR & PMC_SR_LOCKU)) {
;
}

/*
* Final setup of the Master Clock
*/
Expand Down
3 changes: 3 additions & 0 deletions soc/arm/atmel_sam/same70/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
#define SOC_ATMEL_SAM_MCK_FREQ_HZ \
(SOC_ATMEL_SAM_HCLK_FREQ_HZ / CONFIG_SOC_ATMEL_SAME70_MDIV)

/** UTMI PLL clock (UPLLCK) Frequency */
#define SOC_ATMEL_SAM_UPLLCK_FREQ_HZ MHZ(480)

#endif /* _ASMLANGUAGE */

#endif /* _ATMEL_SAME70_SOC_H_ */
8 changes: 8 additions & 0 deletions soc/arm/atmel_sam/samv71/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ static ALWAYS_INLINE void clock_init(void)
;
}

/* Setup UPLL */
PMC->CKGR_UCKR = CKGR_UCKR_UPLLCOUNT(0x3Fu) | CKGR_UCKR_UPLLEN;

/* Wait for PLL lock */
while (!(PMC->PMC_SR & PMC_SR_LOCKU)) {
;
}

/*
* Final setup of the Master Clock
*/
Expand Down
3 changes: 3 additions & 0 deletions soc/arm/atmel_sam/samv71/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
#define SOC_ATMEL_SAM_MCK_FREQ_HZ \
(SOC_ATMEL_SAM_HCLK_FREQ_HZ / CONFIG_SOC_ATMEL_SAMV71_MDIV)

/** UTMI PLL clock (UPLLCK) Frequency */
#define SOC_ATMEL_SAM_UPLLCK_FREQ_HZ MHZ(480)

#endif /* _ASMLANGUAGE */

#include "pwm_fixup.h"
Expand Down