usb: phy: remove CONFIG_USB_OTG_UTILS
[deliverable/linux.git] / drivers / usb / phy / mxs-phy.c
CommitLineData
b3d99681
RZ
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Copyright (C) 2012 Marek Vasut <marex@denx.de>
4 * on behalf of DENX Software Engineering GmbH
5 *
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
9 *
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/platform_device.h>
17#include <linux/clk.h>
18#include <linux/usb/otg.h>
19#include <linux/stmp_device.h>
20#include <linux/delay.h>
21#include <linux/err.h>
22#include <linux/io.h>
23
24#define DRIVER_NAME "mxs_phy"
25
26#define HW_USBPHY_PWD 0x00
27#define HW_USBPHY_CTRL 0x30
28#define HW_USBPHY_CTRL_SET 0x34
29#define HW_USBPHY_CTRL_CLR 0x38
30
31#define BM_USBPHY_CTRL_SFTRST BIT(31)
32#define BM_USBPHY_CTRL_CLKGATE BIT(30)
33#define BM_USBPHY_CTRL_ENUTMILEVEL3 BIT(15)
34#define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14)
35#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
36
37struct mxs_phy {
38 struct usb_phy phy;
39 struct clk *clk;
40};
41
42#define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
43
44static void mxs_phy_hw_init(struct mxs_phy *mxs_phy)
45{
46 void __iomem *base = mxs_phy->phy.io_priv;
47
48 stmp_reset_block(base + HW_USBPHY_CTRL);
49
50 /* Power up the PHY */
b5a726b3 51 writel(0, base + HW_USBPHY_PWD);
b3d99681
RZ
52
53 /* enable FS/LS device */
b5a726b3
MKB
54 writel(BM_USBPHY_CTRL_ENUTMILEVEL2 |
55 BM_USBPHY_CTRL_ENUTMILEVEL3,
56 base + HW_USBPHY_CTRL_SET);
b3d99681
RZ
57}
58
59static int mxs_phy_init(struct usb_phy *phy)
60{
61 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
62
63 clk_prepare_enable(mxs_phy->clk);
64 mxs_phy_hw_init(mxs_phy);
65
66 return 0;
67}
68
69static void mxs_phy_shutdown(struct usb_phy *phy)
70{
71 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
72
b5a726b3
MKB
73 writel(BM_USBPHY_CTRL_CLKGATE,
74 phy->io_priv + HW_USBPHY_CTRL_SET);
b3d99681
RZ
75
76 clk_disable_unprepare(mxs_phy->clk);
77}
78
04a6221c
PC
79static int mxs_phy_suspend(struct usb_phy *x, int suspend)
80{
81 struct mxs_phy *mxs_phy = to_mxs_phy(x);
82
83 if (suspend) {
b5a726b3
MKB
84 writel(0xffffffff, x->io_priv + HW_USBPHY_PWD);
85 writel(BM_USBPHY_CTRL_CLKGATE,
86 x->io_priv + HW_USBPHY_CTRL_SET);
04a6221c
PC
87 clk_disable_unprepare(mxs_phy->clk);
88 } else {
89 clk_prepare_enable(mxs_phy->clk);
b5a726b3
MKB
90 writel(BM_USBPHY_CTRL_CLKGATE,
91 x->io_priv + HW_USBPHY_CTRL_CLR);
92 writel(0, x->io_priv + HW_USBPHY_PWD);
04a6221c
PC
93 }
94
95 return 0;
96}
97
ac96511b
PC
98static int mxs_phy_on_connect(struct usb_phy *phy,
99 enum usb_device_speed speed)
b3d99681 100{
ac96511b
PC
101 dev_dbg(phy->dev, "%s speed device has connected\n",
102 (speed == USB_SPEED_HIGH) ? "high" : "non-high");
b3d99681 103
ac96511b 104 if (speed == USB_SPEED_HIGH)
b5a726b3
MKB
105 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
106 phy->io_priv + HW_USBPHY_CTRL_SET);
b3d99681
RZ
107
108 return 0;
109}
110
ac96511b
PC
111static int mxs_phy_on_disconnect(struct usb_phy *phy,
112 enum usb_device_speed speed)
b3d99681 113{
ac96511b
PC
114 dev_dbg(phy->dev, "%s speed device has disconnected\n",
115 (speed == USB_SPEED_HIGH) ? "high" : "non-high");
b3d99681 116
ac96511b 117 if (speed == USB_SPEED_HIGH)
b5a726b3
MKB
118 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
119 phy->io_priv + HW_USBPHY_CTRL_CLR);
b3d99681
RZ
120
121 return 0;
122}
123
124static int mxs_phy_probe(struct platform_device *pdev)
125{
126 struct resource *res;
127 void __iomem *base;
128 struct clk *clk;
129 struct mxs_phy *mxs_phy;
25df6397 130 int ret;
b3d99681
RZ
131
132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
133 if (!res) {
134 dev_err(&pdev->dev, "can't get device resources\n");
135 return -ENOENT;
136 }
137
148e1134
TR
138 base = devm_ioremap_resource(&pdev->dev, res);
139 if (IS_ERR(base))
140 return PTR_ERR(base);
b3d99681
RZ
141
142 clk = devm_clk_get(&pdev->dev, NULL);
143 if (IS_ERR(clk)) {
144 dev_err(&pdev->dev,
145 "can't get the clock, err=%ld", PTR_ERR(clk));
146 return PTR_ERR(clk);
147 }
148
149 mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL);
150 if (!mxs_phy) {
151 dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
152 return -ENOMEM;
153 }
154
155 mxs_phy->phy.io_priv = base;
156 mxs_phy->phy.dev = &pdev->dev;
157 mxs_phy->phy.label = DRIVER_NAME;
158 mxs_phy->phy.init = mxs_phy_init;
159 mxs_phy->phy.shutdown = mxs_phy_shutdown;
04a6221c 160 mxs_phy->phy.set_suspend = mxs_phy_suspend;
b3d99681
RZ
161 mxs_phy->phy.notify_connect = mxs_phy_on_connect;
162 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
163
164 ATOMIC_INIT_NOTIFIER_HEAD(&mxs_phy->phy.notifier);
165
166 mxs_phy->clk = clk;
167
168 platform_set_drvdata(pdev, &mxs_phy->phy);
169
25df6397
SH
170 ret = usb_add_phy_dev(&mxs_phy->phy);
171 if (ret)
172 return ret;
173
b3d99681
RZ
174 return 0;
175}
176
fb4e98ab 177static int mxs_phy_remove(struct platform_device *pdev)
b3d99681 178{
25df6397
SH
179 struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
180
181 usb_remove_phy(&mxs_phy->phy);
182
b3d99681
RZ
183 platform_set_drvdata(pdev, NULL);
184
185 return 0;
186}
187
188static const struct of_device_id mxs_phy_dt_ids[] = {
189 { .compatible = "fsl,imx23-usbphy", },
190 { /* sentinel */ }
191};
192MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids);
193
194static struct platform_driver mxs_phy_driver = {
195 .probe = mxs_phy_probe,
7690417d 196 .remove = mxs_phy_remove,
b3d99681
RZ
197 .driver = {
198 .name = DRIVER_NAME,
199 .owner = THIS_MODULE,
200 .of_match_table = mxs_phy_dt_ids,
201 },
202};
203
204static int __init mxs_phy_module_init(void)
205{
206 return platform_driver_register(&mxs_phy_driver);
207}
208postcore_initcall(mxs_phy_module_init);
209
210static void __exit mxs_phy_module_exit(void)
211{
212 platform_driver_unregister(&mxs_phy_driver);
213}
214module_exit(mxs_phy_module_exit);
215
216MODULE_ALIAS("platform:mxs-usb-phy");
217MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
218MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
219MODULE_DESCRIPTION("Freescale MXS USB PHY driver");
220MODULE_LICENSE("GPL");
This page took 0.098831 seconds and 5 git commands to generate.