13bb869c8SSebastian Andrzej Siewior #include <linux/module.h> 23bb869c8SSebastian Andrzej Siewior #include <linux/platform_device.h> 33bb869c8SSebastian Andrzej Siewior #include <linux/dma-mapping.h> 43bb869c8SSebastian Andrzej Siewior #include <linux/usb/otg.h> 53bb869c8SSebastian Andrzej Siewior #include <linux/usb/usb_phy_gen_xceiv.h> 63bb869c8SSebastian Andrzej Siewior #include <linux/slab.h> 73bb869c8SSebastian Andrzej Siewior #include <linux/clk.h> 83bb869c8SSebastian Andrzej Siewior #include <linux/regulator/consumer.h> 93bb869c8SSebastian Andrzej Siewior #include <linux/of.h> 103bb869c8SSebastian Andrzej Siewior #include <linux/of_address.h> 113bb869c8SSebastian Andrzej Siewior 123bb869c8SSebastian Andrzej Siewior #include "am35x-phy-control.h" 133bb869c8SSebastian Andrzej Siewior #include "phy-generic.h" 143bb869c8SSebastian Andrzej Siewior 153bb869c8SSebastian Andrzej Siewior struct am335x_phy { 163bb869c8SSebastian Andrzej Siewior struct usb_phy_gen_xceiv usb_phy_gen; 173bb869c8SSebastian Andrzej Siewior struct phy_control *phy_ctrl; 183bb869c8SSebastian Andrzej Siewior int id; 193bb869c8SSebastian Andrzej Siewior }; 203bb869c8SSebastian Andrzej Siewior 213bb869c8SSebastian Andrzej Siewior static int am335x_init(struct usb_phy *phy) 223bb869c8SSebastian Andrzej Siewior { 233bb869c8SSebastian Andrzej Siewior struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); 243bb869c8SSebastian Andrzej Siewior 253bb869c8SSebastian Andrzej Siewior phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 263bb869c8SSebastian Andrzej Siewior return 0; 273bb869c8SSebastian Andrzej Siewior } 283bb869c8SSebastian Andrzej Siewior 293bb869c8SSebastian Andrzej Siewior static void am335x_shutdown(struct usb_phy *phy) 303bb869c8SSebastian Andrzej Siewior { 313bb869c8SSebastian Andrzej Siewior struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); 323bb869c8SSebastian Andrzej Siewior 333bb869c8SSebastian Andrzej Siewior phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 343bb869c8SSebastian Andrzej Siewior } 353bb869c8SSebastian Andrzej Siewior 363bb869c8SSebastian Andrzej Siewior static int am335x_phy_probe(struct platform_device *pdev) 373bb869c8SSebastian Andrzej Siewior { 383bb869c8SSebastian Andrzej Siewior struct am335x_phy *am_phy; 393bb869c8SSebastian Andrzej Siewior struct device *dev = &pdev->dev; 403bb869c8SSebastian Andrzej Siewior int ret; 413bb869c8SSebastian Andrzej Siewior 423bb869c8SSebastian Andrzej Siewior am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL); 433bb869c8SSebastian Andrzej Siewior if (!am_phy) 443bb869c8SSebastian Andrzej Siewior return -ENOMEM; 453bb869c8SSebastian Andrzej Siewior 463bb869c8SSebastian Andrzej Siewior am_phy->phy_ctrl = am335x_get_phy_control(dev); 473bb869c8SSebastian Andrzej Siewior if (!am_phy->phy_ctrl) 483bb869c8SSebastian Andrzej Siewior return -EPROBE_DEFER; 493bb869c8SSebastian Andrzej Siewior am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy"); 503bb869c8SSebastian Andrzej Siewior if (am_phy->id < 0) { 513bb869c8SSebastian Andrzej Siewior dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id); 523bb869c8SSebastian Andrzej Siewior return am_phy->id; 533bb869c8SSebastian Andrzej Siewior } 543bb869c8SSebastian Andrzej Siewior 553bb869c8SSebastian Andrzej Siewior ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, 563bb869c8SSebastian Andrzej Siewior USB_PHY_TYPE_USB2, 0, false, false); 573bb869c8SSebastian Andrzej Siewior if (ret) 583bb869c8SSebastian Andrzej Siewior return ret; 593bb869c8SSebastian Andrzej Siewior 603bb869c8SSebastian Andrzej Siewior ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); 613bb869c8SSebastian Andrzej Siewior if (ret) 624d175f34SMark Brown return ret; 633bb869c8SSebastian Andrzej Siewior am_phy->usb_phy_gen.phy.init = am335x_init; 643bb869c8SSebastian Andrzej Siewior am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; 653bb869c8SSebastian Andrzej Siewior 663bb869c8SSebastian Andrzej Siewior platform_set_drvdata(pdev, am_phy); 674d175f34SMark Brown 683bb869c8SSebastian Andrzej Siewior return 0; 693bb869c8SSebastian Andrzej Siewior 703bb869c8SSebastian Andrzej Siewior return ret; 713bb869c8SSebastian Andrzej Siewior } 723bb869c8SSebastian Andrzej Siewior 733bb869c8SSebastian Andrzej Siewior static int am335x_phy_remove(struct platform_device *pdev) 743bb869c8SSebastian Andrzej Siewior { 753bb869c8SSebastian Andrzej Siewior struct am335x_phy *am_phy = platform_get_drvdata(pdev); 763bb869c8SSebastian Andrzej Siewior 773bb869c8SSebastian Andrzej Siewior usb_remove_phy(&am_phy->usb_phy_gen.phy); 783bb869c8SSebastian Andrzej Siewior return 0; 793bb869c8SSebastian Andrzej Siewior } 803bb869c8SSebastian Andrzej Siewior 81*a1222639SSebastian Andrzej Siewior #ifdef CONFIG_PM_RUNTIME 82*a1222639SSebastian Andrzej Siewior 83*a1222639SSebastian Andrzej Siewior static int am335x_phy_runtime_suspend(struct device *dev) 84*a1222639SSebastian Andrzej Siewior { 85*a1222639SSebastian Andrzej Siewior struct platform_device *pdev = to_platform_device(dev); 86*a1222639SSebastian Andrzej Siewior struct am335x_phy *am_phy = platform_get_drvdata(pdev); 87*a1222639SSebastian Andrzej Siewior 88*a1222639SSebastian Andrzej Siewior if (device_may_wakeup(dev)) 89*a1222639SSebastian Andrzej Siewior phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); 90*a1222639SSebastian Andrzej Siewior phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 91*a1222639SSebastian Andrzej Siewior return 0; 92*a1222639SSebastian Andrzej Siewior } 93*a1222639SSebastian Andrzej Siewior 94*a1222639SSebastian Andrzej Siewior static int am335x_phy_runtime_resume(struct device *dev) 95*a1222639SSebastian Andrzej Siewior { 96*a1222639SSebastian Andrzej Siewior struct platform_device *pdev = to_platform_device(dev); 97*a1222639SSebastian Andrzej Siewior struct am335x_phy *am_phy = platform_get_drvdata(pdev); 98*a1222639SSebastian Andrzej Siewior 99*a1222639SSebastian Andrzej Siewior phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 100*a1222639SSebastian Andrzej Siewior if (device_may_wakeup(dev)) 101*a1222639SSebastian Andrzej Siewior phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); 102*a1222639SSebastian Andrzej Siewior return 0; 103*a1222639SSebastian Andrzej Siewior } 104*a1222639SSebastian Andrzej Siewior 105*a1222639SSebastian Andrzej Siewior static const struct dev_pm_ops am335x_pm_ops = { 106*a1222639SSebastian Andrzej Siewior SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend, 107*a1222639SSebastian Andrzej Siewior am335x_phy_runtime_resume, NULL) 108*a1222639SSebastian Andrzej Siewior }; 109*a1222639SSebastian Andrzej Siewior 110*a1222639SSebastian Andrzej Siewior #define DEV_PM_OPS (&am335x_pm_ops) 111*a1222639SSebastian Andrzej Siewior #else 112*a1222639SSebastian Andrzej Siewior #define DEV_PM_OPS NULL 113*a1222639SSebastian Andrzej Siewior #endif 114*a1222639SSebastian Andrzej Siewior 1153bb869c8SSebastian Andrzej Siewior static const struct of_device_id am335x_phy_ids[] = { 1163bb869c8SSebastian Andrzej Siewior { .compatible = "ti,am335x-usb-phy" }, 1173bb869c8SSebastian Andrzej Siewior { } 1183bb869c8SSebastian Andrzej Siewior }; 1193bb869c8SSebastian Andrzej Siewior MODULE_DEVICE_TABLE(of, am335x_phy_ids); 1203bb869c8SSebastian Andrzej Siewior 1213bb869c8SSebastian Andrzej Siewior static struct platform_driver am335x_phy_driver = { 1223bb869c8SSebastian Andrzej Siewior .probe = am335x_phy_probe, 1233bb869c8SSebastian Andrzej Siewior .remove = am335x_phy_remove, 1243bb869c8SSebastian Andrzej Siewior .driver = { 1253bb869c8SSebastian Andrzej Siewior .name = "am335x-phy-driver", 1263bb869c8SSebastian Andrzej Siewior .owner = THIS_MODULE, 127*a1222639SSebastian Andrzej Siewior .pm = DEV_PM_OPS, 1283bb869c8SSebastian Andrzej Siewior .of_match_table = of_match_ptr(am335x_phy_ids), 1293bb869c8SSebastian Andrzej Siewior }, 1303bb869c8SSebastian Andrzej Siewior }; 1313bb869c8SSebastian Andrzej Siewior 1323bb869c8SSebastian Andrzej Siewior module_platform_driver(am335x_phy_driver); 1333bb869c8SSebastian Andrzej Siewior MODULE_LICENSE("GPL v2"); 134