blob: 31ef59f88901b6918ab5dd202fb0cdb617240121 [file] [log] [blame]
Richard Zhaob3d99682012-07-07 22:56:47 +08001/*
Peter Chen24007802014-02-24 10:20:54 +08002 * Copyright 2012-2013 Freescale Semiconductor, Inc.
Richard Zhaob3d99682012-07-07 22:56:47 +08003 * 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>
Peter Chen24007802014-02-24 10:20:54 +080023#include <linux/of_device.h>
Peter Chen0d896532014-02-24 10:20:57 +080024#include <linux/regmap.h>
25#include <linux/mfd/syscon.h>
Richard Zhaob3d99682012-07-07 22:56:47 +080026
27#define DRIVER_NAME "mxs_phy"
28
29#define HW_USBPHY_PWD 0x00
30#define HW_USBPHY_CTRL 0x30
31#define HW_USBPHY_CTRL_SET 0x34
32#define HW_USBPHY_CTRL_CLR 0x38
33
Peter Chen3f126502014-02-24 10:21:02 +080034#define HW_USBPHY_DEBUG_SET 0x54
35#define HW_USBPHY_DEBUG_CLR 0x58
36
Peter Chen22db05e2014-02-24 10:20:59 +080037#define HW_USBPHY_IP 0x90
38#define HW_USBPHY_IP_SET 0x94
39#define HW_USBPHY_IP_CLR 0x98
40
Richard Zhaob3d99682012-07-07 22:56:47 +080041#define BM_USBPHY_CTRL_SFTRST BIT(31)
42#define BM_USBPHY_CTRL_CLKGATE BIT(30)
Peter Chen13644142014-02-24 10:20:55 +080043#define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS BIT(26)
44#define BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE BIT(25)
Peter Chen3f126502014-02-24 10:21:02 +080045#define BM_USBPHY_CTRL_ENVBUSCHG_WKUP BIT(23)
46#define BM_USBPHY_CTRL_ENIDCHG_WKUP BIT(22)
47#define BM_USBPHY_CTRL_ENDPDMCHG_WKUP BIT(21)
Peter Chen13644142014-02-24 10:20:55 +080048#define BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD BIT(20)
49#define BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE BIT(19)
50#define BM_USBPHY_CTRL_ENAUTO_PWRON_PLL BIT(18)
Richard Zhaob3d99682012-07-07 22:56:47 +080051#define BM_USBPHY_CTRL_ENUTMILEVEL3 BIT(15)
52#define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14)
53#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
54
Peter Chen22db05e2014-02-24 10:20:59 +080055#define BM_USBPHY_IP_FIX (BIT(17) | BIT(18))
56
Peter Chen3f126502014-02-24 10:21:02 +080057#define BM_USBPHY_DEBUG_CLKGATE BIT(30)
58
59/* Anatop Registers */
Peter Chenbf783432014-02-24 10:21:03 +080060#define ANADIG_ANA_MISC0 0x150
61#define ANADIG_ANA_MISC0_SET 0x154
62#define ANADIG_ANA_MISC0_CLR 0x158
63
Peter Chen3f126502014-02-24 10:21:02 +080064#define ANADIG_USB1_VBUS_DET_STAT 0x1c0
65#define ANADIG_USB2_VBUS_DET_STAT 0x220
66
67#define ANADIG_USB1_LOOPBACK_SET 0x1e4
68#define ANADIG_USB1_LOOPBACK_CLR 0x1e8
69#define ANADIG_USB2_LOOPBACK_SET 0x244
70#define ANADIG_USB2_LOOPBACK_CLR 0x248
71
Peter Chenbf783432014-02-24 10:21:03 +080072#define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG BIT(12)
73#define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL BIT(11)
74
Peter Chen3f126502014-02-24 10:21:02 +080075#define BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID BIT(3)
76#define BM_ANADIG_USB2_VBUS_DET_STAT_VBUS_VALID BIT(3)
77
78#define BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1 BIT(2)
79#define BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN BIT(5)
80#define BM_ANADIG_USB2_LOOPBACK_UTMI_DIG_TST1 BIT(2)
81#define BM_ANADIG_USB2_LOOPBACK_TSTI_TX_EN BIT(5)
82
Peter Chen24007802014-02-24 10:20:54 +080083#define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
84
85/* Do disconnection between PHY and controller without vbus */
86#define MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS BIT(0)
87
88/*
89 * The PHY will be in messy if there is a wakeup after putting
90 * bus to suspend (set portsc.suspendM) but before setting PHY to low
91 * power mode (set portsc.phcd).
92 */
93#define MXS_PHY_ABNORMAL_IN_SUSPEND BIT(1)
94
95/*
96 * The SOF sends too fast after resuming, it will cause disconnection
97 * between host and high speed device.
98 */
99#define MXS_PHY_SENDING_SOF_TOO_FAST BIT(2)
100
Peter Chen22db05e2014-02-24 10:20:59 +0800101/*
102 * IC has bug fixes logic, they include
103 * MXS_PHY_ABNORMAL_IN_SUSPEND and MXS_PHY_SENDING_SOF_TOO_FAST
104 * which are described at above flags, the RTL will handle it
105 * according to different versions.
106 */
107#define MXS_PHY_NEED_IP_FIX BIT(3)
108
Peter Chen24007802014-02-24 10:20:54 +0800109struct mxs_phy_data {
110 unsigned int flags;
111};
112
113static const struct mxs_phy_data imx23_phy_data = {
114 .flags = MXS_PHY_ABNORMAL_IN_SUSPEND | MXS_PHY_SENDING_SOF_TOO_FAST,
115};
116
117static const struct mxs_phy_data imx6q_phy_data = {
118 .flags = MXS_PHY_SENDING_SOF_TOO_FAST |
Peter Chen22db05e2014-02-24 10:20:59 +0800119 MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS |
120 MXS_PHY_NEED_IP_FIX,
Peter Chen24007802014-02-24 10:20:54 +0800121};
122
123static const struct mxs_phy_data imx6sl_phy_data = {
Peter Chen22db05e2014-02-24 10:20:59 +0800124 .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS |
125 MXS_PHY_NEED_IP_FIX,
Peter Chen24007802014-02-24 10:20:54 +0800126};
127
128static const struct of_device_id mxs_phy_dt_ids[] = {
129 { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, },
130 { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, },
131 { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, },
132 { /* sentinel */ }
133};
134MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids);
135
Richard Zhaob3d99682012-07-07 22:56:47 +0800136struct mxs_phy {
137 struct usb_phy phy;
138 struct clk *clk;
Peter Chen24007802014-02-24 10:20:54 +0800139 const struct mxs_phy_data *data;
Peter Chen0d896532014-02-24 10:20:57 +0800140 struct regmap *regmap_anatop;
Peter Chen83be1812014-02-24 10:21:00 +0800141 int port_id;
Richard Zhaob3d99682012-07-07 22:56:47 +0800142};
143
Peter Chenbf783432014-02-24 10:21:03 +0800144static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy)
145{
146 return mxs_phy->data == &imx6q_phy_data;
147}
148
149static inline bool is_imx6sl_phy(struct mxs_phy *mxs_phy)
150{
151 return mxs_phy->data == &imx6sl_phy_data;
152}
153
Fabio Estevam51e563e2013-07-03 16:34:13 -0300154static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
Richard Zhaob3d99682012-07-07 22:56:47 +0800155{
Fabio Estevam51e563e2013-07-03 16:34:13 -0300156 int ret;
Richard Zhaob3d99682012-07-07 22:56:47 +0800157 void __iomem *base = mxs_phy->phy.io_priv;
158
Fabio Estevam51e563e2013-07-03 16:34:13 -0300159 ret = stmp_reset_block(base + HW_USBPHY_CTRL);
160 if (ret)
161 return ret;
Richard Zhaob3d99682012-07-07 22:56:47 +0800162
163 /* Power up the PHY */
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100164 writel(0, base + HW_USBPHY_PWD);
Richard Zhaob3d99682012-07-07 22:56:47 +0800165
Peter Chen13644142014-02-24 10:20:55 +0800166 /*
167 * USB PHY Ctrl Setting
168 * - Auto clock/power on
169 * - Enable full/low speed support
170 */
171 writel(BM_USBPHY_CTRL_ENAUTOSET_USBCLKS |
172 BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE |
173 BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD |
174 BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE |
175 BM_USBPHY_CTRL_ENAUTO_PWRON_PLL |
176 BM_USBPHY_CTRL_ENUTMILEVEL2 |
177 BM_USBPHY_CTRL_ENUTMILEVEL3,
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100178 base + HW_USBPHY_CTRL_SET);
Fabio Estevam51e563e2013-07-03 16:34:13 -0300179
Peter Chen22db05e2014-02-24 10:20:59 +0800180 if (mxs_phy->data->flags & MXS_PHY_NEED_IP_FIX)
181 writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET);
182
Fabio Estevam51e563e2013-07-03 16:34:13 -0300183 return 0;
Richard Zhaob3d99682012-07-07 22:56:47 +0800184}
185
Peter Chen3f126502014-02-24 10:21:02 +0800186/* Return true if the vbus is there */
187static bool mxs_phy_get_vbus_status(struct mxs_phy *mxs_phy)
188{
189 unsigned int vbus_value;
190
191 if (mxs_phy->port_id == 0)
192 regmap_read(mxs_phy->regmap_anatop,
193 ANADIG_USB1_VBUS_DET_STAT,
194 &vbus_value);
195 else if (mxs_phy->port_id == 1)
196 regmap_read(mxs_phy->regmap_anatop,
197 ANADIG_USB2_VBUS_DET_STAT,
198 &vbus_value);
199
200 if (vbus_value & BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID)
201 return true;
202 else
203 return false;
204}
205
206static void __mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool disconnect)
207{
208 void __iomem *base = mxs_phy->phy.io_priv;
209 u32 reg;
210
211 if (disconnect)
212 writel_relaxed(BM_USBPHY_DEBUG_CLKGATE,
213 base + HW_USBPHY_DEBUG_CLR);
214
215 if (mxs_phy->port_id == 0) {
216 reg = disconnect ? ANADIG_USB1_LOOPBACK_SET
217 : ANADIG_USB1_LOOPBACK_CLR;
218 regmap_write(mxs_phy->regmap_anatop, reg,
219 BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1 |
220 BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN);
221 } else if (mxs_phy->port_id == 1) {
222 reg = disconnect ? ANADIG_USB2_LOOPBACK_SET
223 : ANADIG_USB2_LOOPBACK_CLR;
224 regmap_write(mxs_phy->regmap_anatop, reg,
225 BM_ANADIG_USB2_LOOPBACK_UTMI_DIG_TST1 |
226 BM_ANADIG_USB2_LOOPBACK_TSTI_TX_EN);
227 }
228
229 if (!disconnect)
230 writel_relaxed(BM_USBPHY_DEBUG_CLKGATE,
231 base + HW_USBPHY_DEBUG_SET);
232
233 /* Delay some time, and let Linestate be SE0 for controller */
234 if (disconnect)
235 usleep_range(500, 1000);
236}
237
238static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
239{
240 bool vbus_is_on = false;
241
242 /* If the SoCs don't need to disconnect line without vbus, quit */
243 if (!(mxs_phy->data->flags & MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS))
244 return;
245
246 /* If the SoCs don't have anatop, quit */
247 if (!mxs_phy->regmap_anatop)
248 return;
249
250 vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
251
252 if (on && !vbus_is_on)
253 __mxs_phy_disconnect_line(mxs_phy, true);
254 else
255 __mxs_phy_disconnect_line(mxs_phy, false);
256
257}
258
Richard Zhaob3d99682012-07-07 22:56:47 +0800259static int mxs_phy_init(struct usb_phy *phy)
260{
Fabio Estevam67c21fc2013-12-02 01:02:34 -0200261 int ret;
Richard Zhaob3d99682012-07-07 22:56:47 +0800262 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
263
Fabio Estevam67c21fc2013-12-02 01:02:34 -0200264 ret = clk_prepare_enable(mxs_phy->clk);
265 if (ret)
266 return ret;
267
Fabio Estevam51e563e2013-07-03 16:34:13 -0300268 return mxs_phy_hw_init(mxs_phy);
Richard Zhaob3d99682012-07-07 22:56:47 +0800269}
270
271static void mxs_phy_shutdown(struct usb_phy *phy)
272{
273 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
274
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100275 writel(BM_USBPHY_CTRL_CLKGATE,
276 phy->io_priv + HW_USBPHY_CTRL_SET);
Richard Zhaob3d99682012-07-07 22:56:47 +0800277
278 clk_disable_unprepare(mxs_phy->clk);
279}
280
Peter Chen04a62212013-01-10 16:35:53 +0800281static int mxs_phy_suspend(struct usb_phy *x, int suspend)
282{
Fabio Estevam67c21fc2013-12-02 01:02:34 -0200283 int ret;
Peter Chen04a62212013-01-10 16:35:53 +0800284 struct mxs_phy *mxs_phy = to_mxs_phy(x);
285
286 if (suspend) {
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100287 writel(0xffffffff, x->io_priv + HW_USBPHY_PWD);
288 writel(BM_USBPHY_CTRL_CLKGATE,
289 x->io_priv + HW_USBPHY_CTRL_SET);
Peter Chen04a62212013-01-10 16:35:53 +0800290 clk_disable_unprepare(mxs_phy->clk);
291 } else {
Fabio Estevam67c21fc2013-12-02 01:02:34 -0200292 ret = clk_prepare_enable(mxs_phy->clk);
293 if (ret)
294 return ret;
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100295 writel(BM_USBPHY_CTRL_CLKGATE,
296 x->io_priv + HW_USBPHY_CTRL_CLR);
297 writel(0, x->io_priv + HW_USBPHY_PWD);
Peter Chen04a62212013-01-10 16:35:53 +0800298 }
299
300 return 0;
301}
302
Peter Chen3f126502014-02-24 10:21:02 +0800303static int mxs_phy_set_wakeup(struct usb_phy *x, bool enabled)
304{
305 struct mxs_phy *mxs_phy = to_mxs_phy(x);
306 u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
307 BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
308 BM_USBPHY_CTRL_ENIDCHG_WKUP;
309 if (enabled) {
310 mxs_phy_disconnect_line(mxs_phy, true);
311 writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_SET);
312 } else {
313 writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_CLR);
314 mxs_phy_disconnect_line(mxs_phy, false);
315 }
316
317 return 0;
318}
319
Peter Chenac965112012-11-09 09:44:44 +0800320static int mxs_phy_on_connect(struct usb_phy *phy,
321 enum usb_device_speed speed)
Richard Zhaob3d99682012-07-07 22:56:47 +0800322{
Peter Chenf6a15822014-02-24 10:20:58 +0800323 dev_dbg(phy->dev, "%s device has connected\n",
324 (speed == USB_SPEED_HIGH) ? "HS" : "FS/LS");
Richard Zhaob3d99682012-07-07 22:56:47 +0800325
Peter Chenac965112012-11-09 09:44:44 +0800326 if (speed == USB_SPEED_HIGH)
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100327 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
328 phy->io_priv + HW_USBPHY_CTRL_SET);
Richard Zhaob3d99682012-07-07 22:56:47 +0800329
330 return 0;
331}
332
Peter Chenac965112012-11-09 09:44:44 +0800333static int mxs_phy_on_disconnect(struct usb_phy *phy,
334 enum usb_device_speed speed)
Richard Zhaob3d99682012-07-07 22:56:47 +0800335{
Peter Chenf6a15822014-02-24 10:20:58 +0800336 dev_dbg(phy->dev, "%s device has disconnected\n",
337 (speed == USB_SPEED_HIGH) ? "HS" : "FS/LS");
Richard Zhaob3d99682012-07-07 22:56:47 +0800338
Peter Chenac965112012-11-09 09:44:44 +0800339 if (speed == USB_SPEED_HIGH)
Marc Kleine-Buddeb5a726b2013-02-28 11:52:30 +0100340 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
341 phy->io_priv + HW_USBPHY_CTRL_CLR);
Richard Zhaob3d99682012-07-07 22:56:47 +0800342
343 return 0;
344}
345
346static int mxs_phy_probe(struct platform_device *pdev)
347{
348 struct resource *res;
349 void __iomem *base;
350 struct clk *clk;
351 struct mxs_phy *mxs_phy;
Sascha Hauer25df6392013-02-27 15:16:30 +0100352 int ret;
Peter Chen24007802014-02-24 10:20:54 +0800353 const struct of_device_id *of_id =
354 of_match_device(mxs_phy_dt_ids, &pdev->dev);
Peter Chen0d896532014-02-24 10:20:57 +0800355 struct device_node *np = pdev->dev.of_node;
Richard Zhaob3d99682012-07-07 22:56:47 +0800356
357 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Reding148e1132013-01-21 11:09:22 +0100358 base = devm_ioremap_resource(&pdev->dev, res);
359 if (IS_ERR(base))
360 return PTR_ERR(base);
Richard Zhaob3d99682012-07-07 22:56:47 +0800361
362 clk = devm_clk_get(&pdev->dev, NULL);
363 if (IS_ERR(clk)) {
364 dev_err(&pdev->dev,
365 "can't get the clock, err=%ld", PTR_ERR(clk));
366 return PTR_ERR(clk);
367 }
368
369 mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL);
370 if (!mxs_phy) {
371 dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
372 return -ENOMEM;
373 }
374
Peter Chen0d896532014-02-24 10:20:57 +0800375 /* Some SoCs don't have anatop registers */
376 if (of_get_property(np, "fsl,anatop", NULL)) {
377 mxs_phy->regmap_anatop = syscon_regmap_lookup_by_phandle
378 (np, "fsl,anatop");
379 if (IS_ERR(mxs_phy->regmap_anatop)) {
380 dev_dbg(&pdev->dev,
381 "failed to find regmap for anatop\n");
382 return PTR_ERR(mxs_phy->regmap_anatop);
383 }
384 }
385
Peter Chen83be1812014-02-24 10:21:00 +0800386 ret = of_alias_get_id(np, "usbphy");
387 if (ret < 0)
388 dev_dbg(&pdev->dev, "failed to get alias id, errno %d\n", ret);
389 mxs_phy->port_id = ret;
390
Richard Zhaob3d99682012-07-07 22:56:47 +0800391 mxs_phy->phy.io_priv = base;
392 mxs_phy->phy.dev = &pdev->dev;
393 mxs_phy->phy.label = DRIVER_NAME;
394 mxs_phy->phy.init = mxs_phy_init;
395 mxs_phy->phy.shutdown = mxs_phy_shutdown;
Peter Chen04a62212013-01-10 16:35:53 +0800396 mxs_phy->phy.set_suspend = mxs_phy_suspend;
Richard Zhaob3d99682012-07-07 22:56:47 +0800397 mxs_phy->phy.notify_connect = mxs_phy_on_connect;
398 mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
Michael Grzeschik4e0aa632013-05-15 15:03:14 +0200399 mxs_phy->phy.type = USB_PHY_TYPE_USB2;
Peter Chen3f126502014-02-24 10:21:02 +0800400 mxs_phy->phy.set_wakeup = mxs_phy_set_wakeup;
Richard Zhaob3d99682012-07-07 22:56:47 +0800401
Richard Zhaob3d99682012-07-07 22:56:47 +0800402 mxs_phy->clk = clk;
Peter Chen24007802014-02-24 10:20:54 +0800403 mxs_phy->data = of_id->data;
Richard Zhaob3d99682012-07-07 22:56:47 +0800404
Jisheng Zhang97a27f72013-11-07 10:55:49 +0800405 platform_set_drvdata(pdev, mxs_phy);
Richard Zhaob3d99682012-07-07 22:56:47 +0800406
Peter Chenbf783432014-02-24 10:21:03 +0800407 device_set_wakeup_capable(&pdev->dev, true);
408
Sascha Hauer25df6392013-02-27 15:16:30 +0100409 ret = usb_add_phy_dev(&mxs_phy->phy);
410 if (ret)
411 return ret;
412
Richard Zhaob3d99682012-07-07 22:56:47 +0800413 return 0;
414}
415
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500416static int mxs_phy_remove(struct platform_device *pdev)
Richard Zhaob3d99682012-07-07 22:56:47 +0800417{
Sascha Hauer25df6392013-02-27 15:16:30 +0100418 struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
419
420 usb_remove_phy(&mxs_phy->phy);
421
Richard Zhaob3d99682012-07-07 22:56:47 +0800422 return 0;
423}
424
Peter Chenbf783432014-02-24 10:21:03 +0800425#ifdef CONFIG_PM_SLEEP
426static void mxs_phy_enable_ldo_in_suspend(struct mxs_phy *mxs_phy, bool on)
427{
428 unsigned int reg = on ? ANADIG_ANA_MISC0_SET : ANADIG_ANA_MISC0_CLR;
429
430 /* If the SoCs don't have anatop, quit */
431 if (!mxs_phy->regmap_anatop)
432 return;
433
434 if (is_imx6q_phy(mxs_phy))
435 regmap_write(mxs_phy->regmap_anatop, reg,
436 BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG);
437 else if (is_imx6sl_phy(mxs_phy))
438 regmap_write(mxs_phy->regmap_anatop,
439 reg, BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL);
440}
441
442static int mxs_phy_system_suspend(struct device *dev)
443{
444 struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
445
446 if (device_may_wakeup(dev))
447 mxs_phy_enable_ldo_in_suspend(mxs_phy, true);
448
449 return 0;
450}
451
452static int mxs_phy_system_resume(struct device *dev)
453{
454 struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
455
456 if (device_may_wakeup(dev))
457 mxs_phy_enable_ldo_in_suspend(mxs_phy, false);
458
459 return 0;
460}
461#endif /* CONFIG_PM_SLEEP */
462
463static SIMPLE_DEV_PM_OPS(mxs_phy_pm, mxs_phy_system_suspend,
464 mxs_phy_system_resume);
465
Richard Zhaob3d99682012-07-07 22:56:47 +0800466static struct platform_driver mxs_phy_driver = {
467 .probe = mxs_phy_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500468 .remove = mxs_phy_remove,
Richard Zhaob3d99682012-07-07 22:56:47 +0800469 .driver = {
470 .name = DRIVER_NAME,
471 .owner = THIS_MODULE,
472 .of_match_table = mxs_phy_dt_ids,
Peter Chenbf783432014-02-24 10:21:03 +0800473 .pm = &mxs_phy_pm,
Richard Zhaob3d99682012-07-07 22:56:47 +0800474 },
475};
476
477static int __init mxs_phy_module_init(void)
478{
479 return platform_driver_register(&mxs_phy_driver);
480}
481postcore_initcall(mxs_phy_module_init);
482
483static void __exit mxs_phy_module_exit(void)
484{
485 platform_driver_unregister(&mxs_phy_driver);
486}
487module_exit(mxs_phy_module_exit);
488
489MODULE_ALIAS("platform:mxs-usb-phy");
490MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
491MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
492MODULE_DESCRIPTION("Freescale MXS USB PHY driver");
493MODULE_LICENSE("GPL");