Commit | Line | Data |
---|---|---|
3bb869c8 SAS |
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_gen_xceiv.h> | |
6 | #include <linux/slab.h> | |
7 | #include <linux/clk.h> | |
8 | #include <linux/regulator/consumer.h> | |
9 | #include <linux/of.h> | |
10 | #include <linux/of_address.h> | |
11 | ||
12 | #include "am35x-phy-control.h" | |
13 | #include "phy-generic.h" | |
14 | ||
15 | struct am335x_phy { | |
16 | struct usb_phy_gen_xceiv usb_phy_gen; | |
17 | struct phy_control *phy_ctrl; | |
18 | int id; | |
19 | }; | |
20 | ||
21 | static int am335x_init(struct usb_phy *phy) | |
22 | { | |
23 | struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); | |
24 | ||
25 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); | |
26 | return 0; | |
27 | } | |
28 | ||
29 | static void am335x_shutdown(struct usb_phy *phy) | |
30 | { | |
31 | struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); | |
32 | ||
33 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); | |
34 | } | |
35 | ||
36 | static int am335x_phy_probe(struct platform_device *pdev) | |
37 | { | |
38 | struct am335x_phy *am_phy; | |
39 | struct device *dev = &pdev->dev; | |
40 | int ret; | |
41 | ||
42 | am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL); | |
43 | if (!am_phy) | |
44 | return -ENOMEM; | |
45 | ||
46 | am_phy->phy_ctrl = am335x_get_phy_control(dev); | |
47 | if (!am_phy->phy_ctrl) | |
48 | return -EPROBE_DEFER; | |
49 | am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy"); | |
50 | if (am_phy->id < 0) { | |
51 | dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id); | |
52 | return am_phy->id; | |
53 | } | |
54 | ||
55 | ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, | |
bd27fa44 | 56 | USB_PHY_TYPE_USB2, 0, false); |
3bb869c8 SAS |
57 | if (ret) |
58 | return ret; | |
59 | ||
60 | ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); | |
61 | if (ret) | |
4d175f34 | 62 | return ret; |
3bb869c8 SAS |
63 | am_phy->usb_phy_gen.phy.init = am335x_init; |
64 | am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; | |
65 | ||
66 | platform_set_drvdata(pdev, am_phy); | |
4d175f34 | 67 | |
3bb869c8 SAS |
68 | return 0; |
69 | ||
3bb869c8 SAS |
70 | return ret; |
71 | } | |
72 | ||
73 | static int am335x_phy_remove(struct platform_device *pdev) | |
74 | { | |
75 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | |
76 | ||
77 | usb_remove_phy(&am_phy->usb_phy_gen.phy); | |
78 | return 0; | |
79 | } | |
80 | ||
a1222639 SAS |
81 | #ifdef CONFIG_PM_RUNTIME |
82 | ||
83 | static int am335x_phy_runtime_suspend(struct device *dev) | |
84 | { | |
85 | struct platform_device *pdev = to_platform_device(dev); | |
86 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | |
87 | ||
88 | if (device_may_wakeup(dev)) | |
89 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); | |
90 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); | |
91 | return 0; | |
92 | } | |
93 | ||
94 | static int am335x_phy_runtime_resume(struct device *dev) | |
95 | { | |
96 | struct platform_device *pdev = to_platform_device(dev); | |
97 | struct am335x_phy *am_phy = platform_get_drvdata(pdev); | |
98 | ||
99 | phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); | |
100 | if (device_may_wakeup(dev)) | |
101 | phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false); | |
102 | return 0; | |
103 | } | |
104 | ||
105 | static const struct dev_pm_ops am335x_pm_ops = { | |
106 | SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend, | |
107 | am335x_phy_runtime_resume, NULL) | |
108 | }; | |
109 | ||
110 | #define DEV_PM_OPS (&am335x_pm_ops) | |
111 | #else | |
112 | #define DEV_PM_OPS NULL | |
113 | #endif | |
114 | ||
3bb869c8 SAS |
115 | static const struct of_device_id am335x_phy_ids[] = { |
116 | { .compatible = "ti,am335x-usb-phy" }, | |
117 | { } | |
118 | }; | |
119 | MODULE_DEVICE_TABLE(of, am335x_phy_ids); | |
120 | ||
121 | static struct platform_driver am335x_phy_driver = { | |
122 | .probe = am335x_phy_probe, | |
123 | .remove = am335x_phy_remove, | |
124 | .driver = { | |
125 | .name = "am335x-phy-driver", | |
126 | .owner = THIS_MODULE, | |
a1222639 | 127 | .pm = DEV_PM_OPS, |
b99fffca | 128 | .of_match_table = am335x_phy_ids, |
3bb869c8 SAS |
129 | }, |
130 | }; | |
131 | ||
132 | module_platform_driver(am335x_phy_driver); | |
133 | MODULE_LICENSE("GPL v2"); |