Hello Amelie,
sorry for the late reply
On Wed, Jul 8, 2020 at 6:00 PM Amelie DELAUNAY <amelie.delaunay@xxxxxx> wrote:
[...]
Could you please test with:this one is looking good - the previous kernel warnings are now gone!
static int dwc2_drd_role_sw_set(struct device *dev, enum usb_role role)
{
ÂÂÂÂÂÂÂÂ struct dwc2_hsotg *hsotg = dev_get_drvdata(dev);
ÂÂÂÂÂÂÂÂ unsigned long flags;
ÂÂÂÂÂÂÂÂ int already = 0;
ÂÂÂÂÂÂÂÂ /* Skip session not in line with dr_mode */
ÂÂÂÂÂÂÂÂ if ((role == USB_ROLE_DEVICE && hsotg->dr_mode == USB_DR_MODE_HOST) ||
ÂÂÂÂÂÂÂÂÂÂÂÂ (role == USB_ROLE_HOST && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
ÂÂÂÂÂÂÂÂ /* Skip session if core is in test mode */
ÂÂÂÂÂÂÂÂ if (role == USB_ROLE_NONE && hsotg->test_mode) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_dbg(hsotg->dev, "Core is in test mode\n");
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return -EBUSY;
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ spin_lock_irqsave(&hsotg->lock, flags);
ÂÂÂÂÂÂÂÂ if (role == USB_ROLE_HOST) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ already = dwc2_ovr_avalid(hsotg, true);
ÂÂÂÂÂÂÂÂ } else if (role == USB_ROLE_DEVICE) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ already = dwc2_ovr_bvalid(hsotg, true);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /* This clear DCTL.SFTDISCON bit */
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dwc2_hsotg_core_connect(hsotg);
ÂÂÂÂÂÂÂÂ } else {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (dwc2_is_device_mode(hsotg)) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!dwc2_ovr_bvalid(hsotg, false))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /* This set DCTL.SFTDISCON bit */
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dwc2_hsotg_core_disconnect(hsotg);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ } else {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dwc2_ovr_avalid(hsotg, false);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ spin_unlock_irqrestore(&hsotg->lock, flags);
ÂÂÂÂÂÂÂÂ if (!already &&
ÂÂÂÂÂÂÂÂÂÂÂÂ role != USB_ROLE_NONE && hsotg->dr_mode == USB_DR_MODE_OTG)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /* This will raise a Connector ID Status Change Interrupt */
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dwc2_force_mode(hsotg, role == USB_ROLE_HOST);
ÂÂÂÂÂÂÂÂ dev_dbg(hsotg->dev, "%s-session valid\n",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ role == USB_ROLE_NONE ? "No" :
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ role == USB_ROLE_HOST ? "A" : "B");
ÂÂÂÂÂÂÂÂ return 0;
}
dwc2_force_mode is called outside the spin_lock_irqsave so the kernel
should not complain. I've tested on my setup and the behavior seems the
same.
thank you very much
Best regards,
Martin