drivers: usb_dc_sam: get the maximum speed from DT as enum
For historical reasons, the maximum speed of the Atmel SAM USB controller is done by comparing the maximum-speed property string from the DT using strncmp at runtime. Now that the DT_ENUM_IDX macro exists, we can use it to get the maximum-speed property at build time and without string comparison. Unsupported speed can also be reported at build time. Note that the default speed in case the optional maximum-speed property isn't present in the DT is changed from full-speed to high-speed to match the property description. This is a no-op in practice as this properties is defined at the soc level. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
parent
d5c60ff2f1
commit
35adb6e2c4
1 changed files with 15 additions and 17 deletions
|
@ -47,7 +47,9 @@ LOG_MODULE_REGISTER(usb_dc_sam);
|
|||
|
||||
#define NUM_OF_EP_MAX DT_INST_PROP(0, num_bidir_endpoints)
|
||||
#if DT_INST_NODE_HAS_PROP(0, maximum_speed)
|
||||
#define USB_MAXIMUM_SPEED DT_INST_PROP(0, maximum_speed)
|
||||
#define USB_MAXIMUM_SPEED DT_ENUM_IDX(DT_DRV_INST(0), maximum_speed)
|
||||
#else
|
||||
#define USB_MAXIMUM_SPEED 2 /* Default to high-speed */
|
||||
#endif
|
||||
|
||||
struct usb_device_ep_data {
|
||||
|
@ -310,23 +312,19 @@ int usb_dc_attach(void)
|
|||
|
||||
/* Select the speed */
|
||||
regval = USBHS_DEVCTRL_DETACH;
|
||||
#ifdef USB_MAXIMUM_SPEED
|
||||
if (!strncmp(USB_MAXIMUM_SPEED, "high-speed", 10)) {
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_NORMAL;
|
||||
} else if (!strncmp(USB_MAXIMUM_SPEED, "full-speed", 10)) {
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_LOW_POWER;
|
||||
} else if (!strncmp(USB_MAXIMUM_SPEED, "low-speed", 9)) {
|
||||
regval |= USBHS_DEVCTRL_LS;
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_LOW_POWER;
|
||||
} else {
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_NORMAL;
|
||||
LOG_WRN("Unsupported maximum speed defined in device tree. "
|
||||
"USB controller will default to its maximum HW "
|
||||
"capability");
|
||||
}
|
||||
#else
|
||||
#if USB_MAXIMUM_SPEED == 0
|
||||
/* low-speed */
|
||||
regval |= USBHS_DEVCTRL_LS;
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_LOW_POWER;
|
||||
#elif USB_MAXIMUM_SPEED == 1
|
||||
/* full-speed */
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_LOW_POWER;
|
||||
#elif USB_MAXIMUM_SPEED == 2
|
||||
/* high-speed */
|
||||
regval |= USBHS_DEVCTRL_SPDCONF_NORMAL;
|
||||
#endif /* USB_MAXIMUM_SPEED */
|
||||
#else
|
||||
#error "Unsupported maximum speed defined in device tree."
|
||||
#endif
|
||||
USBHS->USBHS_DEVCTRL = regval;
|
||||
|
||||
/* Enable the USB clock */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue