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

phy-sun4i-usb: Add support for phy_set_mode

Together with some musb sunxi glue changes this allows run-time dr_mode
switching support via the "mode" musb sysfs attribute.

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
6ba43c29 5f90d31c

+30
+30
drivers/phy/phy-sun4i-usb.c
··· 427 427 return 0; 428 428 } 429 429 430 + static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode) 431 + { 432 + struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); 433 + struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); 434 + 435 + if (phy->index != 0) 436 + return -EINVAL; 437 + 438 + switch (mode) { 439 + case PHY_MODE_USB_HOST: 440 + data->dr_mode = USB_DR_MODE_HOST; 441 + break; 442 + case PHY_MODE_USB_DEVICE: 443 + data->dr_mode = USB_DR_MODE_PERIPHERAL; 444 + break; 445 + case PHY_MODE_USB_OTG: 446 + data->dr_mode = USB_DR_MODE_OTG; 447 + break; 448 + default: 449 + return -EINVAL; 450 + } 451 + 452 + dev_info(&_phy->dev, "Changing dr_mode to %d\n", (int)data->dr_mode); 453 + data->force_session_end = true; 454 + queue_delayed_work(system_wq, &data->detect, 0); 455 + 456 + return 0; 457 + } 458 + 430 459 void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled) 431 460 { 432 461 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); ··· 469 440 .exit = sun4i_usb_phy_exit, 470 441 .power_on = sun4i_usb_phy_power_on, 471 442 .power_off = sun4i_usb_phy_power_off, 443 + .set_mode = sun4i_usb_phy_set_mode, 472 444 .owner = THIS_MODULE, 473 445 }; 474 446