0001
0002 #include <linux/module.h>
0003 #include <linux/platform_device.h>
0004 #include <linux/dma-mapping.h>
0005 #include <linux/usb/otg.h>
0006 #include <linux/usb/usb_phy_generic.h>
0007 #include <linux/slab.h>
0008 #include <linux/clk.h>
0009 #include <linux/of.h>
0010 #include <linux/of_address.h>
0011 #include <linux/usb/of.h>
0012
0013 #include "phy-am335x-control.h"
0014 #include "phy-generic.h"
0015
0016 struct am335x_phy {
0017 struct usb_phy_generic usb_phy_gen;
0018 struct phy_control *phy_ctrl;
0019 int id;
0020 enum usb_dr_mode dr_mode;
0021 };
0022
0023 static int am335x_init(struct usb_phy *phy)
0024 {
0025 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
0026
0027 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true);
0028 return 0;
0029 }
0030
0031 static void am335x_shutdown(struct usb_phy *phy)
0032 {
0033 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
0034
0035 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
0036 }
0037
0038 static int am335x_phy_probe(struct platform_device *pdev)
0039 {
0040 struct am335x_phy *am_phy;
0041 struct device *dev = &pdev->dev;
0042 int ret;
0043
0044 am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
0045 if (!am_phy)
0046 return -ENOMEM;
0047
0048 am_phy->phy_ctrl = am335x_get_phy_control(dev);
0049 if (!am_phy->phy_ctrl)
0050 return -EPROBE_DEFER;
0051
0052 am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
0053 if (am_phy->id < 0) {
0054 dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
0055 return am_phy->id;
0056 }
0057
0058 am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node, -1);
0059
0060 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen);
0061 if (ret)
0062 return ret;
0063
0064 am_phy->usb_phy_gen.phy.init = am335x_init;
0065 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
0066
0067 platform_set_drvdata(pdev, am_phy);
0068 device_init_wakeup(dev, true);
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079 device_set_wakeup_enable(dev, false);
0080 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
0081
0082 return usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
0083 }
0084
0085 static int am335x_phy_remove(struct platform_device *pdev)
0086 {
0087 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
0088
0089 usb_remove_phy(&am_phy->usb_phy_gen.phy);
0090 return 0;
0091 }
0092
0093 #ifdef CONFIG_PM_SLEEP
0094 static int am335x_phy_suspend(struct device *dev)
0095 {
0096 struct am335x_phy *am_phy = dev_get_drvdata(dev);
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 if (device_may_wakeup(dev))
0107 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
0108
0109 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false);
0110
0111 return 0;
0112 }
0113
0114 static int am335x_phy_resume(struct device *dev)
0115 {
0116 struct am335x_phy *am_phy = dev_get_drvdata(dev);
0117
0118 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true);
0119
0120 if (device_may_wakeup(dev))
0121 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
0122
0123 return 0;
0124 }
0125 #endif
0126
0127 static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume);
0128
0129 static const struct of_device_id am335x_phy_ids[] = {
0130 { .compatible = "ti,am335x-usb-phy" },
0131 { }
0132 };
0133 MODULE_DEVICE_TABLE(of, am335x_phy_ids);
0134
0135 static struct platform_driver am335x_phy_driver = {
0136 .probe = am335x_phy_probe,
0137 .remove = am335x_phy_remove,
0138 .driver = {
0139 .name = "am335x-phy-driver",
0140 .pm = &am335x_pm_ops,
0141 .of_match_table = am335x_phy_ids,
0142 },
0143 };
0144
0145 module_platform_driver(am335x_phy_driver);
0146 MODULE_LICENSE("GPL v2");