Skip to content

Commit 5522e65

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

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

drivers/usb/device/usb_dc_sam_usbhs.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define DT_DRV_COMPAT atmel_sam_usbhs
88

99
#include <zephyr/usb/usb_device.h>
10+
#include <zephyr/drivers/clock_control/atmel_sam_pmc.h>
1011
#include <zephyr/irq.h>
1112
#include <zephyr/kernel.h>
1213
#include <soc.h>
@@ -309,10 +310,12 @@ static void usb_dc_isr(void)
309310
/* Attach USB for device connection */
310311
int usb_dc_attach(void)
311312
{
313+
const struct atmel_sam_pmc_config clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0);
312314
uint32_t regval;
313315

314-
/* Start the peripheral clock */
315-
soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id));
316+
/* Enable USBHS clock in PMC */
317+
(void)clock_control_on(SAM_DT_PMC_CONTROLLER,
318+
(clock_control_subsys_t *)&clock_cfg);
316319

317320
/* Enable the USB controller in device mode with the clock frozen */
318321
USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD | USBHS_CTRL_USBE |
@@ -359,6 +362,8 @@ int usb_dc_attach(void)
359362
/* Detach the USB device */
360363
int usb_dc_detach(void)
361364
{
365+
const struct atmel_sam_pmc_config clock_cfg = SAM_DT_INST_CLOCK_PMC_CFG(0);
366+
362367
/* Detach the device */
363368
USBHS->USBHS_DEVCTRL |= USBHS_DEVCTRL_DETACH;
364369

@@ -368,8 +373,9 @@ int usb_dc_detach(void)
368373
/* Disable the USB controller and freeze the clock */
369374
USBHS->USBHS_CTRL = USBHS_CTRL_UIMOD | USBHS_CTRL_FRZCLK;
370375

371-
/* Disable the peripheral clock */
372-
soc_pmc_peripheral_enable(DT_INST_PROP(0, peripheral_id));
376+
/* Disable USBHS clock in PMC */
377+
(void)clock_control_off(SAM_DT_PMC_CONTROLLER,
378+
(clock_control_subsys_t *)&clock_cfg);
373379

374380
/* Disable interrupt */
375381
irq_disable(DT_INST_IRQN(0));

dts/arm/atmel/sam4l.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
interrupt-names = "usbc";
167167
maximum-speed = "full-speed";
168168
num-bidir-endpoints = <8>;
169-
peripheral-id = <101>;
169+
clocks = <&pmc PMC_TYPE_PERIPHERAL 101>;
170170
status = "disabled";
171171
};
172172

dts/arm/atmel/same70.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
interrupt-names = "usbhs";
315315
maximum-speed = "high-speed";
316316
num-bidir-endpoints = <10>;
317-
peripheral-id = <34>;
317+
clocks = <&pmc PMC_TYPE_PERIPHERAL 34>;
318318
status = "disabled";
319319
};
320320

dts/bindings/usb/atmel,sam-usbc.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright (c) 2018 Aurelien Jarno
2-
# Copyright (c) 2020 Gerson Fernando Budke <[email protected]>
2+
# Copyright (c) 2020*2023 Gerson Fernando Budke <[email protected]>
33
# SPDX-License-Identifier: Apache-2.0
44

55
description: |
@@ -18,7 +18,5 @@ properties:
1818
interrupts:
1919
required: true
2020

21-
peripheral-id:
22-
type: int
21+
clocks:
2322
required: true
24-
description: peripheral ID

dts/bindings/usb/atmel,sam-usbhs.yaml

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

20-
peripheral-id:
21-
type: int
20+
clocks:
2221
required: true
23-
description: peripheral ID

0 commit comments

Comments
 (0)