1 #include <linux/module.h>
2 #include <linux/platform_device.h>
3 #include <linux/dma-mapping.h>
4 #include <linux/usb/otg.h>
5 #include <linux/usb/usb_phy_generic.h>
6 #include <linux/slab.h>
8 #include <linux/regulator/consumer.h>
10 #include <linux/of_address.h>
12 #include "am35x-phy-control.h"
13 #include "phy-generic.h"
16 struct usb_phy_generic usb_phy_gen;
17 struct phy_control *phy_ctrl;
21 static int am335x_init(struct usb_phy *phy)
23 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
25 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
29 static void am335x_shutdown(struct usb_phy *phy)
31 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
33 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
36 static int am335x_phy_probe(struct platform_device *pdev)
38 struct am335x_phy *am_phy;
39 struct device *dev = &pdev->dev;
42 am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
46 am_phy->phy_ctrl = am335x_get_phy_control(dev);
47 if (!am_phy->phy_ctrl)
49 am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
51 dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL);
59 am_phy->usb_phy_gen.phy.init = am335x_init;
60 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
62 platform_set_drvdata(pdev, am_phy);
63 device_init_wakeup(dev, true);
66 * If we leave PHY wakeup enabled then AM33XX wakes up
67 * immediately from DS0. To avoid this we mark dev->power.can_wakeup
68 * to false. The same is checked in suspend routine to decide
69 * on whether to enable PHY wakeup or not.
70 * PHY wakeup works fine in standby mode, there by allowing us to
71 * handle remote wakeup, wakeup on disconnect and connect.
74 device_set_wakeup_enable(dev, false);
75 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
77 return usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
80 static int am335x_phy_remove(struct platform_device *pdev)
82 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
84 usb_remove_phy(&am_phy->usb_phy_gen.phy);
88 #ifdef CONFIG_PM_SLEEP
89 static int am335x_phy_suspend(struct device *dev)
91 struct platform_device *pdev = to_platform_device(dev);
92 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
95 * Enable phy wakeup only if dev->power.can_wakeup is true.
96 * Make sure to enable wakeup to support remote wakeup in
97 * standby mode ( same is not supported in OFF(DS0) mode).
99 * echo enabled > /sys/bus/platform/devices/<usb-phy-id>/power/wakeup
102 if (device_may_wakeup(dev))
103 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
105 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
110 static int am335x_phy_resume(struct device *dev)
112 struct platform_device *pdev = to_platform_device(dev);
113 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
115 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
117 if (device_may_wakeup(dev))
118 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
124 static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume);
126 static const struct of_device_id am335x_phy_ids[] = {
127 { .compatible = "ti,am335x-usb-phy" },
130 MODULE_DEVICE_TABLE(of, am335x_phy_ids);
132 static struct platform_driver am335x_phy_driver = {
133 .probe = am335x_phy_probe,
134 .remove = am335x_phy_remove,
136 .name = "am335x-phy-driver",
137 .pm = &am335x_pm_ops,
138 .of_match_table = am335x_phy_ids,
142 module_platform_driver(am335x_phy_driver);
143 MODULE_LICENSE("GPL v2");