On Fri, 27 Sep 2019, Bastien Nocera wrote:

> Hey,
> 
> I'm trying to write a "power supply" class driver for Apple MFi
> devices, and struggling a little with the USB drivers.
> 
> To ask many Apple devices to draw more power, we need to make a call to
> the device using a vendor command. It doesn't go to an interface, but
> to the device itself.
> 
> The call done in the kernel would look something like:
> usb_control_msg(mfi->udev, usb_sndctrlpipe(mfi->udev, 0), 
>                 0x40, /* Vendor-defined USB get enabled capabilities request. 
> */
>                 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
>                 current_ma, /* wValue, current offset */
>                 current_ma, /* wIndex, current offset */
>                 NULL, 0, USB_CTRL_GET_TIMEOUT);
> 
> But I can't figure out what type of driver I'd need to just be able to
> export that power_supply interface.
> 
> Trying to use a "struct usb_device_driver" didn't work as probe
> functions were never called, and a "struct usb_driver" gets unbound
> after user-space and the ipheth drivers comes around.
> 
> This is my "struct usb_driver" attempt:
> https://github.com/hadess/apple-mfi-fastcharge
> 
> Any ideas what type of driver, or what trick I should be using here?

Is there any reason this needs to be done in a kernel driver?  Can it 
be handled from userspace instead?

You said this was for a "power supply" class driver.  It's not clear 
what that means -- the devices you want to communicate with are 
iphones, ipads, etc., not power supplies.

Under what circumstances would these messages need to get sent?  What 
piece of code is responsible for them?

If necessary, you can modify the core/generic.c driver.  However that 
might not be the right approach, considering that this is meant only 
for devices manufactured by Apple.

Alan Stern

Reply via email to