linux-automation / usbsdmux

USB-SD-Mux Project - Driver and Documentation
GNU Lesser General Public License v2.1
66 stars 19 forks source link

[Feature Request] port usb-sd-mux to macOS #84

Open danieleftodi opened 4 weeks ago

danieleftodi commented 4 weeks ago

Hi,

I recently bought a USB-SD-Mux FAST ... and I love it 😄

... though, I noticed it doesn't have macOS support.

I have done some reading through your code and and the MicroChip USB2642 documentation.

Especially the "USB82642/2642 I2C Over USB User’s Guide - Using USB Mass Storage Class Bulk-Only Transport & SCSI Pass Through"

From what I can gather, correct me if I'm wrong, but it just a matter of being able to send an I2C message over USB - to the MicroChip USB2642.

Ergo, all we would need to create, is a USB driver with DriverKit SDK for the usb-sd-mux.

And I do understand, that maybe you guy's don't have a Mac or interested to do this work. But since this an OSS project. Could you maybe assist with some technical information, when needed?

Cheers, Daniel

Screenshot 2024-10-29 at 21 57 23 Screenshot 2024-10-29 at 21 56 13 I2C_Over_USB_UserGuilde_50002283A_Page_09 Screenshot 2024-10-29 at 21 16 54

Also found these sources: Building a Simple USB Driver USBDriverKit Creating a Driver Using the DriverKit SDK Sending SCSI or ATA commands to storage devices Accessing SCSI Architecture Model Devices WWDC 2020 - Modernize PCI and SCSI drivers with DriverKit SCSIControllerDriverKit SCSIPeripheralsDriverKit VendorSpecificType00

hnez commented 4 weeks ago

Hi,

I recently bought a USB-SD-Mux FAST ... and I love it 😄

it's great to hear that, thanks!

... though, I noticed it doesn't have macOS support.

Also no Windows or BSD support. There are two reasons for that:

While our own focus is very Linux-centric we would be very happy about contributions that add support for other platforms.

I have done some reading through your code and and the MicroChip USB2642 documentation.

Especially the "USB82642/2642 I2C Over USB User’s Guide - Using USB Mass Storage Class Bulk-Only Transport & SCSI Pass Through"

From what I can gather, correct me if I'm wrong, but it just a matter of being able to send an I2C message over USB - to the MicroChip USB2642.

I2C messages over SCSI over USB but yes, there is not much more to how the USB-SD-Mux works.

On the USB-SD-Mux FAST we have a TCA6408 i²c GPIO expander that is connected to the USB2642 via i²c and that controls the muxing and the external GPIOs.

To set the mux to HOST we set output pin 0 of the GPIO expander high. To set the mux to DUT we set output pin 0 of the GPIO expander low. To set the pin high/low we set/clear the corresponding bit in the GPIO expander output register via i²c:

https://github.com/linux-automation/usbsdmux/blob/35624f2848aaae8b2e60aa3f36cbe4629d4e8d00/usbsdmux/i2c_gpio.py#L91-L109

The i²c transfer is encapsulated in a SCSI command …

https://github.com/linux-automation/usbsdmux/blob/35624f2848aaae8b2e60aa3f36cbe4629d4e8d00/usbsdmux/usb2642.py#L425-L457

… the SCSI command is sent to the Linux Kernel via the SCSI generic device using an ioctl …

https://github.com/linux-automation/usbsdmux/blob/35624f2848aaae8b2e60aa3f36cbe4629d4e8d00/usbsdmux/usb2642.py#L325-L346

and the kernel wraps it into USB transfers.

Ergo, all we would need to create, is a USB driver with DriverKit SDK for the usb-sd-mux.

I would suggest trying to implement it at the SCSI first, instead of the USB level. Talking raw USB means having to implement the SCSI layer on top and more potential for confusing the USB and SCSI state machines in the USB2642 and your OS Kernel.

And I do understand, that maybe you guy's don't have a Mac or interested to do this work. But since this an OSS project. Could you maybe assist with some technical information, when needed?

Sure! You can reach us here or in the #lxa channel on libera.chat. We are usually not too secretive about the inner workings of our devices.