]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/usb/phy/phy-am335x.c
Merge tag 'v4.4' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux...
[karo-tx-linux.git] / drivers / usb / phy / phy-am335x.c
1 #include <linux/module.h>
2 #include <linux/platform_device.h>
3 #include <linux/dma-mapping.h>
4 #include <linux/slab.h>
5 #include <linux/clk.h>
6 #include <linux/of.h>
7 #include <linux/of_address.h>
8 #include <linux/regulator/consumer.h>
9 #include <linux/usb/otg.h>
10 #include <linux/usb/usb_phy_generic.h>
11
12 #include "am35x-phy-control.h"
13 #include "phy-generic.h"
14
15 struct am335x_phy {
16         struct usb_phy_generic 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         usb_gen_phy_init(phy);
26         phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
27         return 0;
28 }
29
30 static void am335x_shutdown(struct usb_phy *phy)
31 {
32         struct am335x_phy *am_phy = dev_get_drvdata(phy->dev);
33
34         phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
35         usb_gen_phy_shutdown(phy);
36 }
37
38 static int am335x_phy_probe(struct platform_device *pdev)
39 {
40         struct am335x_phy *am_phy;
41         struct device *dev = &pdev->dev;
42         int ret;
43
44         am_phy = devm_kzalloc(dev, sizeof(*am_phy), GFP_KERNEL);
45         if (!am_phy)
46                 return -ENOMEM;
47
48         am_phy->phy_ctrl = am335x_get_phy_control(dev);
49         if (!am_phy->phy_ctrl)
50                 return -EPROBE_DEFER;
51         am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy");
52         if (am_phy->id < 0) {
53                 dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id);
54                 return am_phy->id;
55         }
56
57         ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL);
58         if (ret)
59                 return ret;
60
61         am_phy->usb_phy_gen.phy.init = am335x_init;
62         am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
63
64         ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
65         if (ret)
66                 return ret;
67
68         platform_set_drvdata(pdev, am_phy);
69         device_init_wakeup(dev, true);
70
71         /*
72          * If we leave PHY wakeup enabled then AM33XX wakes up
73          * immediately from DS0. To avoid this we mark dev->power.can_wakeup
74          * to false. The same is checked in suspend routine to decide
75          * on whether to enable PHY wakeup or not.
76          * PHY wakeup works fine in standby mode, there by allowing us to
77          * handle remote wakeup, wakeup on disconnect and connect.
78          */
79
80         device_set_wakeup_enable(dev, false);
81         phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
82
83         return 0;
84 }
85
86 static int am335x_phy_remove(struct platform_device *pdev)
87 {
88         struct am335x_phy *am_phy = platform_get_drvdata(pdev);
89
90         usb_remove_phy(&am_phy->usb_phy_gen.phy);
91         return 0;
92 }
93
94 #ifdef CONFIG_PM_SLEEP
95 static int am335x_phy_suspend(struct device *dev)
96 {
97         struct platform_device  *pdev = to_platform_device(dev);
98         struct am335x_phy *am_phy = platform_get_drvdata(pdev);
99
100         /*
101          * Enable phy wakeup only if dev->power.can_wakeup is true.
102          * Make sure to enable wakeup to support remote wakeup  in
103          * standby mode ( same is not supported in OFF(DS0) mode).
104          * Enable it by doing
105          * echo enabled > /sys/bus/platform/devices/<usb-phy-id>/power/wakeup
106          */
107
108         if (device_may_wakeup(dev))
109                 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
110
111         phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
112
113         return 0;
114 }
115
116 static int am335x_phy_resume(struct device *dev)
117 {
118         struct platform_device  *pdev = to_platform_device(dev);
119         struct am335x_phy       *am_phy = platform_get_drvdata(pdev);
120
121         phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
122
123         if (device_may_wakeup(dev))
124                 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
125
126         return 0;
127 }
128 #endif
129
130 static SIMPLE_DEV_PM_OPS(am335x_pm_ops, am335x_phy_suspend, am335x_phy_resume);
131
132 static const struct of_device_id am335x_phy_ids[] = {
133         { .compatible = "ti,am335x-usb-phy" },
134         { }
135 };
136 MODULE_DEVICE_TABLE(of, am335x_phy_ids);
137
138 static struct platform_driver am335x_phy_driver = {
139         .probe          = am335x_phy_probe,
140         .remove         = am335x_phy_remove,
141         .driver         = {
142                 .name   = "am335x-phy-driver",
143                 .pm = &am335x_pm_ops,
144                 .of_match_table = am335x_phy_ids,
145         },
146 };
147
148 module_platform_driver(am335x_phy_driver);
149 MODULE_LICENSE("GPL v2");