Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy_sun4i_usb: set_mode: Allow using set_mode to force end the current session

The sunxi musb has a bug where sometimes it will generate a babble
error on device disconnect instead of a disconnect irq. When this
happens the musb-controller switches from host mode to device mode
(it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
gets stuck in this state.

Clearing this requires reporting Vbus low for 200 or more ms, but
on some devices Vbus is simply always high (host-only mode, no Vbus
control).

This commit modifies sun4i_usb_phy_set_mode so that it will force
end the current session when called with the current mode, before this
commit calling set_mode with the current mode was a nop since id_det
would stay the same resulting in the detect_work not doing anything.

This allows the sunxi-musb glue to use sun4i_usb_phy_set_mode to force
end the current session without changing the mode, to fixup the stuck
state after a babble error.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

authored by

Hans de Goede and committed by
Kishon Vijay Abraham I
5d04c883 e4d5973f

+10 -4
+10 -4
drivers/phy/phy-sun4i-usb.c
··· 436 436 { 437 437 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); 438 438 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); 439 + int new_mode; 439 440 440 441 if (phy->index != 0) 441 442 return -EINVAL; 442 443 443 444 switch (mode) { 444 445 case PHY_MODE_USB_HOST: 445 - data->dr_mode = USB_DR_MODE_HOST; 446 + new_mode = USB_DR_MODE_HOST; 446 447 break; 447 448 case PHY_MODE_USB_DEVICE: 448 - data->dr_mode = USB_DR_MODE_PERIPHERAL; 449 + new_mode = USB_DR_MODE_PERIPHERAL; 449 450 break; 450 451 case PHY_MODE_USB_OTG: 451 - data->dr_mode = USB_DR_MODE_OTG; 452 + new_mode = USB_DR_MODE_OTG; 452 453 break; 453 454 default: 454 455 return -EINVAL; 455 456 } 456 457 457 - dev_info(&_phy->dev, "Changing dr_mode to %d\n", (int)data->dr_mode); 458 + if (new_mode != data->dr_mode) { 459 + dev_info(&_phy->dev, "Changing dr_mode to %d\n", new_mode); 460 + data->dr_mode = new_mode; 461 + } 462 + 463 + data->id_det = -1; /* Force reprocessing of id */ 458 464 data->force_session_end = true; 459 465 queue_delayed_work(system_wq, &data->detect, 0); 460 466