Skip to content

Conversation

@VynDragon
Copy link
Contributor

@VynDragon VynDragon commented Oct 16, 2025

It does device at high-speed speeds.

Caveat: controller does host, this does not do host.

@VynDragon VynDragon changed the title Bl61x usb usb: usdc: BL61x Device HS USB Oct 17, 2025
@VynDragon VynDragon force-pushed the bl61x_usb branch 4 times, most recently from 662579f to f771808 Compare October 17, 2025 21:46
@josuah josuah self-requested a review October 17, 2025 23:33
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish to do another round of review when I get back home, also run USB3CV compliance tool which will be good at spotting bugs.

Though it sounds like ready for review to me.
Thank you!

@josuah
Copy link
Contributor

josuah commented Oct 18, 2025

Zephyr host not ready yet either... (>_<')
The host driver API seems a bit simpler.

@VynDragon
Copy link
Contributor Author

Thanks for the review.

Zephyr host not ready yet either... (>_<') The host driver API seems a bit simpler.

What would be the proper naming scheme? should I name this driver 'udc' instead of usb and the host one 'uhc'?

@josuah
Copy link
Contributor

josuah commented Oct 18, 2025

I think you are right, to follow the UDC (USB Device Controller) acronym, BL61x USB controller device driver could eventually become BL61x USB device controller driver.

@VynDragon VynDragon force-pushed the bl61x_usb branch 2 times, most recently from da3285c to e7f5f3b Compare October 18, 2025 02:37
@VynDragon
Copy link
Contributor Author

And one other caveat before this is ready, this will need to add a new board, because the current bl61x board ai-m62-12f has NO usb at all going out the module so it cant support USB. Liekly this will be sipeed m0s, but it could also be added to qcc744_evk if it's merged very fast

@VynDragon
Copy link
Contributor Author

Ah no wait it does have them...

josuah
josuah previously approved these changes Oct 18, 2025
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you I did not find anything missing!
I added a few extra notes if wanting to anticipate the review of USB maintainers, not 100% sure this is going to be requested.

Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it's going to be enforced to have all of them marked as const (not part of Zephyr coding style, just the style in USB), but in case you wanted a TODO list here we go.

@josuah
Copy link
Contributor

josuah commented Oct 19, 2025

I think the next step is basically wait that the maintainers' review queue clears out.

If it takes long and "ping" don't help, the workaround is west patch gh-fetch --pull-request 97750 to maintain this PR as a local patch until it's merged.

@VynDragon
Copy link
Contributor Author

west patch gh-fetch --pull-request 97750

i didnt know about that and manually git fetched and cherry picked PR

@VynDragon
Copy link
Contributor Author

ok did all the ones that worked i think and a few more

josuah
josuah previously approved these changes Oct 19, 2025
Comment on lines 27 to 29
#define USB_BL61X_CAP_ISO 1
#define USB_BL61X_CAP_BULK 2
#define USB_BL61X_CAP_INT 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these values? They are used by bitwise ORing the values, but USB_BL61X_CAP_ISO | USB_BL61X_CAP_BULK == USB_BL61X_CAP_INT. Is this intentional or oversight?

Copy link
Contributor Author

@VynDragon VynDragon Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/cherry-embedded/CherryUSB/blob/master/port/bouffalolab/usb_dc_bl.c

Do not use it for any references, or copy any code or logic from there. This project is absolutely unreliable regarding code source and licensing.

Copy link
Contributor Author

@VynDragon VynDragon Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same code as from the bouffalolab SDK, the author of cherryUSB worked for bouffalolab for quite a while (like 4 years at least, until fairly recently).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway, fixed that issue by removing that function entirely, it was usign the wrong thing anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it looks good, there are usual style and code structure issues that needs to be fixed, but...

Looking at the next commit I was curious about "It is similar to FOTG210". I started to look at the BL61X manual, and there does not seem to be one, the same appears to be for FOTG210 IP. I see some rumors that the BL61X SoC uses FOTG210 IP. Comparing fotg210-udc.[c,h] from the Linux kernel with your code and usb_v2_reg.h from the bouffalolab HAL, it seems to be FOTG210 USB controller IP. In that case, the right way is to implement platform/vendor independent driver for FOTG210 based controllers and use vendor specific quirks for platform specific parts like clock configuration or pin configuration.

Please use drivers/usb/common/usb_dwc2_hw.h, drivers/usb/udc/udc_dwc2.[c,h], and drivers/usb/udc/udc_dwc2_vendor_quirks.h as the reference.
Rename udc_bflb_bl61x.c to udc_fotg210.c and use udc_fotg210/fotg210 as namespace. Add common header file drivers/usb/common/usb_fotg210_hw.h. Use definition from usb_fotg210_hw.h in udc_fotg210.c. Move BL61X specific platform code to drivers/usb/udc/udc_fotg210_vendor_quirks.h.

The problem is where to get register names for drivers/usb/common/usb_fotg210_hw.h, ideally they should have similar names as in the official FOTG210 manual/databook. I have no idea where to get them. Faraday Technology seems to be the original author of the Linux driver but these files are GPL-2.0+ only and definitions there can not be copied. So this need to be solved first.

I am also curious where did you get all the info to write this driver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is similar to fotg210, there are some significant differences on what interrupts work and dont work, and it uses an entirely different DMA system, if you look at the linux driver for fotg210 it has some significant differences mostly around the control logic due to what is and what isnt available (or doesnt work as it should, i tried to apply the advantages of the version in the linux kernel in many places) in the bflb version. So i dont think it's possible to make a generic fotg210 driver from this, as it's pretty much guaranteed to be inadapted for whatever else could use it.

I am also curious where did you get all the info to write this driver?

apache-2 bouffalo SDK, author of cherryUSB did work for them, so code is available both in cherryUSB and the bouffalosdk, and you can also observe the same code under proprietary license in the QCC744 SDK. The bouffalolab port also has a line to talk to bouffalolab but this driver predates it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is similar to fotg210, there are some significant differences on what interrupts work and dont work, and it uses an entirely different DMA system, if you look at the linux driver for fotg210 it has some significant differences mostly around the control logic due to what is and what isnt available

That is not a reason to give up. There are more similarities than differences. Some parts can be handled by vendor quirks. VDMA in the driver with a comment until there will be another platform that could use this driver.

apache-2 bouffalo SDK, author of cherryUSB did work for them

That makes it unacceptable for me. You need to write the code from scratch.

Copy link
Contributor Author

@VynDragon VynDragon Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes it unacceptable for me. You need to write the code from scratch.

The reference code. I should have quoted 'I am also curious where did you get all the info to write this driver?' instead. Obviously i've written the entire thing submitted here... If you're going to complain about the register writes being the same, there isn't 5 different way to do the same operations with the same hardware.

That is not a reason to give up. There are more similarities than differences. Some parts can be handled by vendor quirks. VDMA in the driver with a comment until there will be another platform that could use this driver.

Yes it is until I get docs for the IP, and even then this is re-scoping the PR in a huge way.

@VynDragon VynDragon force-pushed the bl61x_usb branch 3 times, most recently from 013b081 to a84cca4 Compare October 24, 2025 12:47
Adds a device mode driver for BL61x

Signed-off-by: Camille BAUD <[email protected]>
Adds the binding to enable the USB controller

Signed-off-by: Camille BAUD <[email protected]>
This is necessary to have a board testing the USB driver,
however the board doesn't have a USB plug for it,
but the pins are available

Signed-off-by: Camille BAUD <[email protected]>
@sonarqubecloud
Copy link

@VynDragon VynDragon marked this pull request as draft October 24, 2025 22:00
@VynDragon
Copy link
Contributor Author

Converting back to draft because some major bugs have been found and we're struggling to fix them (what with not having docs...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants