-
Notifications
You must be signed in to change notification settings - Fork 8.3k
USB STM32: Improve usb clock code #87061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7556439 to
54f099e
Compare
25be4dc to
70cf204
Compare
drivers/usb/device/usb_dc_stm32.c
Outdated
|
|
||
| #if USB_OTG_HS_ULPI_PHY || \ | ||
| DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) || \ | ||
| USB_OTG_HS_EMB_PHYC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually here also #if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC should be enough.
| #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) | ||
|
|
||
| static const struct stm32_pclken phy_pclken[] = STM32_DT_CLOCKS(DT_INST_PHANDLE(0, phys)); | ||
| #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking: remove the extra empty line above.
drivers/usb/device/usb_dc_stm32.c
Outdated
| LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_USBPHY); | ||
| /* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */ | ||
| clock_control_on(clk, (clock_control_subsys_t)&phy_pclken[0]); | ||
| /* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
| clocks = <&rcc STM32_CLOCK(AHB1, 26U)>; | ||
| reset-gpios = < &gpioj 4 GPIO_ACTIVE_LOW >; | ||
| #phy-cells = <0>; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 26U)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can discard this change (no change)
boards/arduino/nicla_vision/arduino_nicla_vision_stm32h747xx_m7.dts
Outdated
Show resolved
Hide resolved
8216b18 to
e8bd04d
Compare
drivers/usb/device/usb_dc_stm32.c
Outdated
| #else | ||
| LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_OTGHSULPI); | ||
| #endif | ||
| clock_control_on(clk, (clock_control_subsys_t)&phy_pclken[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the duplication of this call all over the place confusing to read.
Is there anything preventing this clock_control_on call from being placed in a single spot, gated behind the same #if USB_OTG_HS_ULPI_PHY || DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) || \ USB_OTG_HS_EMB_PHYC as the phy_pclken definition?
(If this is possible, having a top-level #define HAS_PHY_CLK 1 gated behind the existing #if test with all series/IP, and testing for HAS_PHY_CLK everywhere else, could be cleaner)
drivers/usb/udc/udc_stm32.c
Outdated
| #if USB_OTG_HS_ULPI_PHY | ||
| #if defined(CONFIG_SOC_SERIES_STM32H7X) | ||
| clock_control_on(clk, (clock_control_subsys_t)&phy_pclken[0]); | ||
| LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_USB1OTGHSULPI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line 1151 (duplicates the clock_control_on() call above)
| clock_control_on(clk, (clock_control_subsys_t)&phy_pclken[0]); | ||
| /* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */ | ||
| LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS || | ||
| LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is a fix. It deserves a dedicated commit IMHO.
| clock_control_on(clk, (clock_control_subsys_t)&phy_pclken[0]); | ||
| /* Both OTG HS and USBPHY sleep clock MUST be disabled here at the same time */ | ||
| LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS || | ||
| LL_AHB2_GRP1_DisableClockStopSleep(LL_AHB2_GRP1_PERIPH_OTG_HS | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixup change, deserves a dedicated commit.
etienne-lms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3 last commits changing DTS/DTSI files should be placed before the 2 commits modifying the drivers implementation.
drivers/usb/device/usb_dc_stm32.c
Outdated
| static const struct stm32_pclken phy_pclken[] = STM32_DT_CLOCKS(DT_INST_PHANDLE(0, phys)); | ||
| #endif | ||
|
|
||
| #if USB_OTG_HS_ULPI_PHY || DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) || USB_OTG_HS_EMB_PHYC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/st_stm32_otghs/st_stm32u5_otghs_phy/?
If so, can define HAS_PHY_CLK in the above #ifdef/#endif close.
drivers/usb/device/usb_dc_stm32.c
Outdated
| LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_USB1OTGHSULPI); | ||
| #else | ||
| LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_OTGHSULPI); | ||
| #if HAS_PHY_CLK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking again, I'm not sure HAS_PHY_CLK can be used here.
In previous implementaion, line 416 is embedded when both compats st_stm32u5_otghs_phy AND st_stm32_otghs are enabled, that is when USB_OTG_HS_EMB_PHY is true.
So I think here it should be:
#if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY
At line 105 (new implementation), you still need to define phy_pclken upon
#if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC || DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy)
since it's required by usb_dc_stm32u5_phy_clock_select() and usb_dc_stm32u5_phy_clock_enable().
Could you cross-check that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it's required for u5.
drivers/usb/udc/udc_stm32.c
Outdated
| #define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \ | ||
| DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)) | ||
|
|
||
| #if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|| USB_OTG_HS_EMB_PHY
(to cover case at line 1135 in previous implementation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And USB_OTG_HS_EMB_PHY should be defined:
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))(edited: fixed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry my previous comment was inaccurate and confusing.
For consistency with device/usb_dc_stm32.c implementation, I think we should add commit to rename macro USB_OTG_HS_EMB_PHY to USB_OTG_HS_EMB_PHYC in this udc/udc_stm32.c and then introduce USB_OTG_HS_EMB_PHY related to STM32U5 OTGHS PHY, as done in usb_dc_stm32.c:
#define USB_OTG_HS_EMB_PHYC (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
+#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) && \
+ DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
+
#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))Based on that, your can factorize PHY clock management upon USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC || USB_OTG_HS_EMB_PHY.
Renaming USB_OTG_HS_EMB_PHY to USB_OTG_HS_EMB_PHYC could be controversial. @erwango, what do you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'd minimize the changes to the minimum considered the pain experienced in previous PR.
But the long term direction sounds fine though, but we should not forget that device/usb_dc_stm32.c should disappear in 1 or 2 releases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I understand renaming is not the preferred way.
However I think current proposal won't match: USB_OTG_HS_EMB_PHYC is not defined (..._PHY not ..._PHYC) and U5 case is not considered (at line 1135 in previous implementation).
That would be something like:
#define USB_OTG_HS_EMB_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usbphyc) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
#define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \
DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
+#define USB_OTG_HS_EMB_U5_PHY (DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) && \
+ DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs))
+
-#if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC
+#if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHY || USB_OTG_HS_EMB_U5_PHY
#define HAS_PHY_CLKThat said, you proposal implemented in the next commit of these series could apply here, no?
-#if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC
+#if DT_NODE_HAS_PROP(DT_PHANDLE(DT_INST(0, DT_DRV_COMPAT), phys), clocks)
#define HAS_PHY_CLKThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced with: #if DT_NODE_HAS_PROP(DT_PHANDLE(DT_INST(0, DT_DRV_COMPAT), phys), clocks)
drivers/usb/udc/udc_stm32.c
Outdated
| LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_USB1OTGHSULPI); | ||
| #else | ||
| LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_OTGHSULPI); | ||
| #if HAS_PHY_CLK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef
| } | ||
| #endif | ||
| #elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) /* USB_OTG_HS_ULPI_PHY */ | ||
| #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) /* USB_OTG_HS_ULPI_PHY */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, I think an empty line above would be welcome.
| otghs_ulpi_phy: otghs_ulpis_phy { | ||
| compatible = "usb-ulpi-phy"; | ||
| reset-gpios = <&gpiod 7 (GPIO_ACTIVE_LOW)>; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 30)>; | ||
| #phy-cells = <0>; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd propose to move node declaration with status = <disabled>; along with not configurable properties (clock, compatible, phy-cells) to .dtsi files.
Then board description should enable node and populate board specific properties like reset-gpios.
In any case, since it has impact on out of tree boards, this should be documented in migration guide (doc/releases/migration-guide-4.2.rst)
drivers/usb/device/usb_dc_stm32.c
Outdated
| #define USB_DC_STM32_FULL_SPEED USB_OTG_SPEED_FULL | ||
| #endif | ||
|
|
||
| #if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC || DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_otghs_phy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to use DT_NODE_HAS_PROP ?
Something like:
#if DT_NODE_HAS_PROP(DT_PHANDLE(DT_INST(0, DT_DRV_COMPAT), phys), clocks)
drivers/usb/udc/udc_stm32.c
Outdated
| #define USB_OTG_HS_ULPI_PHY (DT_HAS_COMPAT_STATUS_OKAY(usb_ulpi_phy) && \ | ||
| DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)) | ||
|
|
||
| #if USB_OTG_HS_ULPI_PHY || USB_OTG_HS_EMB_PHYC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'd minimize the changes to the minimum considered the pain experienced in previous PR.
But the long term direction sounds fine though, but we should not forget that device/usb_dc_stm32.c should disappear in 1 or 2 releases.
6b538ac to
4e1d494
Compare
| } | ||
| #endif | ||
| #elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) /* USB_OTG_HS_ULPI_PHY */ | ||
| #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also I think an empty line above would be welcome.
bd5f229 to
81fe5a0
Compare
| compatible = "usb-nop-xceiv"; | ||
| #phy-cells = <0>; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 30)>; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be verified, but probably all these nodes should get a status = "disabled";
(When no status is provided, default is "okay").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for stm32f723 and stm32f769 status = "okay"
dts/arm/st/h7/stm32h747Xi_m7.dtsi
Outdated
|
|
||
| otghs_ulpi_phy: otghs_ulpis_phy { | ||
| compatible = "usb-ulpi-phy"; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 26)>; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be possible to use this on M4 side, so to be put in stm32h747.dtsi file.
dts/arm/st/h7/stm32h757Xi_m7.dtsi
Outdated
|
|
||
| otghs_ulpi_phy: otghs_ulpis_phy { | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 26)>; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be removed as this will come by stm32h747 file inclusion
dts/arm/st/h7/stm32h747Xi_m7.dtsi
Outdated
|
|
||
| otghs_ulpi_phy: otghs_ulpis_phy { | ||
| compatible = "usb-ulpi-phy"; | ||
| #phy-cells = <0>; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 26)>; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be moved to stm32h747.dtsi, or to be checked if it wouldn't be obtained by the already available inlcusion of stm32h745.dtsi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to stm32h747 dtsi file.
| compatible = "usb-ulpi-phy"; | ||
| reset-gpios = < &gpioj 4 GPIO_ACTIVE_LOW >; | ||
| #phy-cells = <0>; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 26)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of phy descriptions that are not board specifics should be moved to soc files
|
|
||
| otghs_ulpi_phy: otghs_ulpis_phy { | ||
| compatible = "usb-ulpi-phy"; | ||
| clocks = <&rcc STM32_CLOCK(AHB1, 26)>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
81fe5a0 to
67e120e
Compare
add phy clocks to dtsi files. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
07f922d to
884526e
Compare
add phy clocks to dtsi files. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
Replace the direct call to LL_AHBx_GRP1_EnableClock with the clock control API. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
Replace the direct call to LL_AHBx_GRP1_EnableClock with the clock control API. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
corrected the logical OR (||) to bitwise OR (|) in the LL_AHB2_GRP1_DisableClockStopSleep function call. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
corrected the logical OR (||) to bitwise OR (|) in the LL_AHB2_GRP1_DisableClockStopSleep function call. Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
884526e to
b5ccd7c
Compare
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
This PR includes several improvements to the USB code for STM32 devices. The changes aim to enhance code maintainability and add necessary configurations for PHY clocks.