Skip to content

Commit e0b94e9

Browse files
benpiccocarlescufi
authored andcommitted
usb: sam0: Add support for MCLK
On newer sam0 SoCs peripherals are enabled through the MCLK instead of the PM register. Use the MCLK register if it's availiable. Signed-off-by: Benjamin Valentin <[email protected]>
1 parent 2ff38cc commit e0b94e9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/usb/device/usb_dc_sam0.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ int usb_dc_attach(void)
180180
UsbDevice *regs = &REGS->DEVICE;
181181
struct usb_sam0_data *data = usb_sam0_get_data();
182182

183+
#ifdef MCLK
184+
/* Enable the clock in MCLK */
185+
MCLK->APBBMASK.bit.USB_ = 1;
186+
187+
/* Enable the GCLK - use 48 MHz source */
188+
GCLK->PCHCTRL[USB_GCLK_ID].reg = GCLK_PCHCTRL_GEN(2)
189+
| GCLK_PCHCTRL_CHEN;
190+
191+
while (GCLK->SYNCBUSY.reg) {
192+
}
193+
#else
183194
/* Enable the clock in PM */
184195
PM->APBBMASK.bit.USB_ = 1;
185196

@@ -189,6 +200,7 @@ int usb_dc_attach(void)
189200

190201
while (GCLK->STATUS.bit.SYNCBUSY) {
191202
}
203+
#endif /* !MCLK */
192204

193205
/* Configure */
194206
regs->CTRLA.bit.SWRST = 1;

0 commit comments

Comments
 (0)