phy-mxs-usb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * Copyright 2012-2014 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. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <linux/usb/otg.h>
  18. #include <linux/stmp_device.h>
  19. #include <linux/delay.h>
  20. #include <linux/err.h>
  21. #include <linux/io.h>
  22. #include <linux/of_device.h>
  23. #include <linux/regmap.h>
  24. #include <linux/mfd/syscon.h>
  25. #define DRIVER_NAME "mxs_phy"
  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. #define HW_USBPHY_DEBUG_SET 0x54
  31. #define HW_USBPHY_DEBUG_CLR 0x58
  32. #define HW_USBPHY_IP 0x90
  33. #define HW_USBPHY_IP_SET 0x94
  34. #define HW_USBPHY_IP_CLR 0x98
  35. #define BM_USBPHY_CTRL_SFTRST BIT(31)
  36. #define BM_USBPHY_CTRL_CLKGATE BIT(30)
  37. #define BM_USBPHY_CTRL_OTG_ID_VALUE BIT(27)
  38. #define BM_USBPHY_CTRL_ENAUTOSET_USBCLKS BIT(26)
  39. #define BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE BIT(25)
  40. #define BM_USBPHY_CTRL_ENVBUSCHG_WKUP BIT(23)
  41. #define BM_USBPHY_CTRL_ENIDCHG_WKUP BIT(22)
  42. #define BM_USBPHY_CTRL_ENDPDMCHG_WKUP BIT(21)
  43. #define BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD BIT(20)
  44. #define BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE BIT(19)
  45. #define BM_USBPHY_CTRL_ENAUTO_PWRON_PLL BIT(18)
  46. #define BM_USBPHY_CTRL_ENUTMILEVEL3 BIT(15)
  47. #define BM_USBPHY_CTRL_ENUTMILEVEL2 BIT(14)
  48. #define BM_USBPHY_CTRL_ENHOSTDISCONDETECT BIT(1)
  49. #define BM_USBPHY_IP_FIX (BIT(17) | BIT(18))
  50. #define BM_USBPHY_DEBUG_CLKGATE BIT(30)
  51. /* Anatop Registers */
  52. #define ANADIG_ANA_MISC0 0x150
  53. #define ANADIG_ANA_MISC0_SET 0x154
  54. #define ANADIG_ANA_MISC0_CLR 0x158
  55. #define ANADIG_USB1_VBUS_DET_STAT 0x1c0
  56. #define ANADIG_USB2_VBUS_DET_STAT 0x220
  57. #define ANADIG_USB1_LOOPBACK_SET 0x1e4
  58. #define ANADIG_USB1_LOOPBACK_CLR 0x1e8
  59. #define ANADIG_USB2_LOOPBACK_SET 0x244
  60. #define ANADIG_USB2_LOOPBACK_CLR 0x248
  61. #define ANADIG_USB1_MISC 0x1f0
  62. #define ANADIG_USB2_MISC 0x250
  63. #define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG BIT(12)
  64. #define BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL BIT(11)
  65. #define BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID BIT(3)
  66. #define BM_ANADIG_USB2_VBUS_DET_STAT_VBUS_VALID BIT(3)
  67. #define BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1 BIT(2)
  68. #define BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN BIT(5)
  69. #define BM_ANADIG_USB2_LOOPBACK_UTMI_DIG_TST1 BIT(2)
  70. #define BM_ANADIG_USB2_LOOPBACK_TSTI_TX_EN BIT(5)
  71. #define BM_ANADIG_USB1_MISC_RX_VPIN_FS BIT(29)
  72. #define BM_ANADIG_USB1_MISC_RX_VMIN_FS BIT(28)
  73. #define BM_ANADIG_USB2_MISC_RX_VPIN_FS BIT(29)
  74. #define BM_ANADIG_USB2_MISC_RX_VMIN_FS BIT(28)
  75. #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy)
  76. /* Do disconnection between PHY and controller without vbus */
  77. #define MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS BIT(0)
  78. /*
  79. * The PHY will be in messy if there is a wakeup after putting
  80. * bus to suspend (set portsc.suspendM) but before setting PHY to low
  81. * power mode (set portsc.phcd).
  82. */
  83. #define MXS_PHY_ABNORMAL_IN_SUSPEND BIT(1)
  84. /*
  85. * The SOF sends too fast after resuming, it will cause disconnection
  86. * between host and high speed device.
  87. */
  88. #define MXS_PHY_SENDING_SOF_TOO_FAST BIT(2)
  89. /*
  90. * IC has bug fixes logic, they include
  91. * MXS_PHY_ABNORMAL_IN_SUSPEND and MXS_PHY_SENDING_SOF_TOO_FAST
  92. * which are described at above flags, the RTL will handle it
  93. * according to different versions.
  94. */
  95. #define MXS_PHY_NEED_IP_FIX BIT(3)
  96. struct mxs_phy_data {
  97. unsigned int flags;
  98. };
  99. static const struct mxs_phy_data imx23_phy_data = {
  100. .flags = MXS_PHY_ABNORMAL_IN_SUSPEND | MXS_PHY_SENDING_SOF_TOO_FAST,
  101. };
  102. static const struct mxs_phy_data imx6q_phy_data = {
  103. .flags = MXS_PHY_SENDING_SOF_TOO_FAST |
  104. MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS |
  105. MXS_PHY_NEED_IP_FIX,
  106. };
  107. static const struct mxs_phy_data imx6sl_phy_data = {
  108. .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS |
  109. MXS_PHY_NEED_IP_FIX,
  110. };
  111. static const struct mxs_phy_data vf610_phy_data = {
  112. .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS |
  113. MXS_PHY_NEED_IP_FIX,
  114. };
  115. static const struct mxs_phy_data imx6sx_phy_data = {
  116. .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS,
  117. };
  118. static const struct mxs_phy_data imx6ul_phy_data = {
  119. .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS,
  120. };
  121. static const struct of_device_id mxs_phy_dt_ids[] = {
  122. { .compatible = "fsl,imx6sx-usbphy", .data = &imx6sx_phy_data, },
  123. { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, },
  124. { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, },
  125. { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, },
  126. { .compatible = "fsl,vf610-usbphy", .data = &vf610_phy_data, },
  127. { .compatible = "fsl,imx6ul-usbphy", .data = &imx6ul_phy_data, },
  128. { /* sentinel */ }
  129. };
  130. MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids);
  131. struct mxs_phy {
  132. struct usb_phy phy;
  133. struct clk *clk;
  134. const struct mxs_phy_data *data;
  135. struct regmap *regmap_anatop;
  136. int port_id;
  137. };
  138. static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy)
  139. {
  140. return mxs_phy->data == &imx6q_phy_data;
  141. }
  142. static inline bool is_imx6sl_phy(struct mxs_phy *mxs_phy)
  143. {
  144. return mxs_phy->data == &imx6sl_phy_data;
  145. }
  146. /*
  147. * PHY needs some 32K cycles to switch from 32K clock to
  148. * bus (such as AHB/AXI, etc) clock.
  149. */
  150. static void mxs_phy_clock_switch_delay(void)
  151. {
  152. usleep_range(300, 400);
  153. }
  154. static int mxs_phy_hw_init(struct mxs_phy *mxs_phy)
  155. {
  156. int ret;
  157. void __iomem *base = mxs_phy->phy.io_priv;
  158. ret = stmp_reset_block(base + HW_USBPHY_CTRL);
  159. if (ret)
  160. return ret;
  161. /* Power up the PHY */
  162. writel(0, base + HW_USBPHY_PWD);
  163. /*
  164. * USB PHY Ctrl Setting
  165. * - Auto clock/power on
  166. * - Enable full/low speed support
  167. */
  168. writel(BM_USBPHY_CTRL_ENAUTOSET_USBCLKS |
  169. BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE |
  170. BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD |
  171. BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE |
  172. BM_USBPHY_CTRL_ENAUTO_PWRON_PLL |
  173. BM_USBPHY_CTRL_ENUTMILEVEL2 |
  174. BM_USBPHY_CTRL_ENUTMILEVEL3,
  175. base + HW_USBPHY_CTRL_SET);
  176. if (mxs_phy->data->flags & MXS_PHY_NEED_IP_FIX)
  177. writel(BM_USBPHY_IP_FIX, base + HW_USBPHY_IP_SET);
  178. return 0;
  179. }
  180. /* Return true if the vbus is there */
  181. static bool mxs_phy_get_vbus_status(struct mxs_phy *mxs_phy)
  182. {
  183. unsigned int vbus_value;
  184. if (!mxs_phy->regmap_anatop)
  185. return false;
  186. if (mxs_phy->port_id == 0)
  187. regmap_read(mxs_phy->regmap_anatop,
  188. ANADIG_USB1_VBUS_DET_STAT,
  189. &vbus_value);
  190. else if (mxs_phy->port_id == 1)
  191. regmap_read(mxs_phy->regmap_anatop,
  192. ANADIG_USB2_VBUS_DET_STAT,
  193. &vbus_value);
  194. if (vbus_value & BM_ANADIG_USB1_VBUS_DET_STAT_VBUS_VALID)
  195. return true;
  196. else
  197. return false;
  198. }
  199. static void __mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool disconnect)
  200. {
  201. void __iomem *base = mxs_phy->phy.io_priv;
  202. u32 reg;
  203. if (disconnect)
  204. writel_relaxed(BM_USBPHY_DEBUG_CLKGATE,
  205. base + HW_USBPHY_DEBUG_CLR);
  206. if (mxs_phy->port_id == 0) {
  207. reg = disconnect ? ANADIG_USB1_LOOPBACK_SET
  208. : ANADIG_USB1_LOOPBACK_CLR;
  209. regmap_write(mxs_phy->regmap_anatop, reg,
  210. BM_ANADIG_USB1_LOOPBACK_UTMI_DIG_TST1 |
  211. BM_ANADIG_USB1_LOOPBACK_TSTI_TX_EN);
  212. } else if (mxs_phy->port_id == 1) {
  213. reg = disconnect ? ANADIG_USB2_LOOPBACK_SET
  214. : ANADIG_USB2_LOOPBACK_CLR;
  215. regmap_write(mxs_phy->regmap_anatop, reg,
  216. BM_ANADIG_USB2_LOOPBACK_UTMI_DIG_TST1 |
  217. BM_ANADIG_USB2_LOOPBACK_TSTI_TX_EN);
  218. }
  219. if (!disconnect)
  220. writel_relaxed(BM_USBPHY_DEBUG_CLKGATE,
  221. base + HW_USBPHY_DEBUG_SET);
  222. /* Delay some time, and let Linestate be SE0 for controller */
  223. if (disconnect)
  224. usleep_range(500, 1000);
  225. }
  226. static bool mxs_phy_is_otg_host(struct mxs_phy *mxs_phy)
  227. {
  228. void __iomem *base = mxs_phy->phy.io_priv;
  229. u32 phyctrl = readl(base + HW_USBPHY_CTRL);
  230. if (IS_ENABLED(CONFIG_USB_OTG) &&
  231. !(phyctrl & BM_USBPHY_CTRL_OTG_ID_VALUE))
  232. return true;
  233. return false;
  234. }
  235. static void mxs_phy_disconnect_line(struct mxs_phy *mxs_phy, bool on)
  236. {
  237. bool vbus_is_on = false;
  238. /* If the SoCs don't need to disconnect line without vbus, quit */
  239. if (!(mxs_phy->data->flags & MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS))
  240. return;
  241. /* If the SoCs don't have anatop, quit */
  242. if (!mxs_phy->regmap_anatop)
  243. return;
  244. vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
  245. if (on && !vbus_is_on && !mxs_phy_is_otg_host(mxs_phy))
  246. __mxs_phy_disconnect_line(mxs_phy, true);
  247. else
  248. __mxs_phy_disconnect_line(mxs_phy, false);
  249. }
  250. static int mxs_phy_init(struct usb_phy *phy)
  251. {
  252. int ret;
  253. struct mxs_phy *mxs_phy = to_mxs_phy(phy);
  254. mxs_phy_clock_switch_delay();
  255. ret = clk_prepare_enable(mxs_phy->clk);
  256. if (ret)
  257. return ret;
  258. return mxs_phy_hw_init(mxs_phy);
  259. }
  260. static void mxs_phy_shutdown(struct usb_phy *phy)
  261. {
  262. struct mxs_phy *mxs_phy = to_mxs_phy(phy);
  263. u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
  264. BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
  265. BM_USBPHY_CTRL_ENIDCHG_WKUP |
  266. BM_USBPHY_CTRL_ENAUTOSET_USBCLKS |
  267. BM_USBPHY_CTRL_ENAUTOCLR_USBCLKGATE |
  268. BM_USBPHY_CTRL_ENAUTOCLR_PHY_PWD |
  269. BM_USBPHY_CTRL_ENAUTOCLR_CLKGATE |
  270. BM_USBPHY_CTRL_ENAUTO_PWRON_PLL;
  271. writel(value, phy->io_priv + HW_USBPHY_CTRL_CLR);
  272. writel(0xffffffff, phy->io_priv + HW_USBPHY_PWD);
  273. writel(BM_USBPHY_CTRL_CLKGATE,
  274. phy->io_priv + HW_USBPHY_CTRL_SET);
  275. clk_disable_unprepare(mxs_phy->clk);
  276. }
  277. static bool mxs_phy_is_low_speed_connection(struct mxs_phy *mxs_phy)
  278. {
  279. unsigned int line_state;
  280. /* bit definition is the same for all controllers */
  281. unsigned int dp_bit = BM_ANADIG_USB1_MISC_RX_VPIN_FS,
  282. dm_bit = BM_ANADIG_USB1_MISC_RX_VMIN_FS;
  283. unsigned int reg = ANADIG_USB1_MISC;
  284. /* If the SoCs don't have anatop, quit */
  285. if (!mxs_phy->regmap_anatop)
  286. return false;
  287. if (mxs_phy->port_id == 0)
  288. reg = ANADIG_USB1_MISC;
  289. else if (mxs_phy->port_id == 1)
  290. reg = ANADIG_USB2_MISC;
  291. regmap_read(mxs_phy->regmap_anatop, reg, &line_state);
  292. if ((line_state & (dp_bit | dm_bit)) == dm_bit)
  293. return true;
  294. else
  295. return false;
  296. }
  297. static int mxs_phy_suspend(struct usb_phy *x, int suspend)
  298. {
  299. int ret;
  300. struct mxs_phy *mxs_phy = to_mxs_phy(x);
  301. bool low_speed_connection, vbus_is_on;
  302. low_speed_connection = mxs_phy_is_low_speed_connection(mxs_phy);
  303. vbus_is_on = mxs_phy_get_vbus_status(mxs_phy);
  304. if (suspend) {
  305. /*
  306. * FIXME: Do not power down RXPWD1PT1 bit for low speed
  307. * connect. The low speed connection will have problem at
  308. * very rare cases during usb suspend and resume process.
  309. */
  310. if (low_speed_connection & vbus_is_on) {
  311. /*
  312. * If value to be set as pwd value is not 0xffffffff,
  313. * several 32Khz cycles are needed.
  314. */
  315. mxs_phy_clock_switch_delay();
  316. writel(0xffbfffff, x->io_priv + HW_USBPHY_PWD);
  317. } else {
  318. writel(0xffffffff, x->io_priv + HW_USBPHY_PWD);
  319. }
  320. writel(BM_USBPHY_CTRL_CLKGATE,
  321. x->io_priv + HW_USBPHY_CTRL_SET);
  322. clk_disable_unprepare(mxs_phy->clk);
  323. } else {
  324. mxs_phy_clock_switch_delay();
  325. ret = clk_prepare_enable(mxs_phy->clk);
  326. if (ret)
  327. return ret;
  328. writel(BM_USBPHY_CTRL_CLKGATE,
  329. x->io_priv + HW_USBPHY_CTRL_CLR);
  330. writel(0, x->io_priv + HW_USBPHY_PWD);
  331. }
  332. return 0;
  333. }
  334. static int mxs_phy_set_wakeup(struct usb_phy *x, bool enabled)
  335. {
  336. struct mxs_phy *mxs_phy = to_mxs_phy(x);
  337. u32 value = BM_USBPHY_CTRL_ENVBUSCHG_WKUP |
  338. BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
  339. BM_USBPHY_CTRL_ENIDCHG_WKUP;
  340. if (enabled) {
  341. mxs_phy_disconnect_line(mxs_phy, true);
  342. writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_SET);
  343. } else {
  344. writel_relaxed(value, x->io_priv + HW_USBPHY_CTRL_CLR);
  345. mxs_phy_disconnect_line(mxs_phy, false);
  346. }
  347. return 0;
  348. }
  349. static int mxs_phy_on_connect(struct usb_phy *phy,
  350. enum usb_device_speed speed)
  351. {
  352. dev_dbg(phy->dev, "%s device has connected\n",
  353. (speed == USB_SPEED_HIGH) ? "HS" : "FS/LS");
  354. if (speed == USB_SPEED_HIGH)
  355. writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
  356. phy->io_priv + HW_USBPHY_CTRL_SET);
  357. return 0;
  358. }
  359. static int mxs_phy_on_disconnect(struct usb_phy *phy,
  360. enum usb_device_speed speed)
  361. {
  362. dev_dbg(phy->dev, "%s device has disconnected\n",
  363. (speed == USB_SPEED_HIGH) ? "HS" : "FS/LS");
  364. /* Sometimes, the speed is not high speed when the error occurs */
  365. if (readl(phy->io_priv + HW_USBPHY_CTRL) &
  366. BM_USBPHY_CTRL_ENHOSTDISCONDETECT)
  367. writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
  368. phy->io_priv + HW_USBPHY_CTRL_CLR);
  369. return 0;
  370. }
  371. static int mxs_phy_probe(struct platform_device *pdev)
  372. {
  373. struct resource *res;
  374. void __iomem *base;
  375. struct clk *clk;
  376. struct mxs_phy *mxs_phy;
  377. int ret;
  378. const struct of_device_id *of_id;
  379. struct device_node *np = pdev->dev.of_node;
  380. of_id = of_match_device(mxs_phy_dt_ids, &pdev->dev);
  381. if (!of_id)
  382. return -ENODEV;
  383. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  384. base = devm_ioremap_resource(&pdev->dev, res);
  385. if (IS_ERR(base))
  386. return PTR_ERR(base);
  387. clk = devm_clk_get(&pdev->dev, NULL);
  388. if (IS_ERR(clk)) {
  389. dev_err(&pdev->dev,
  390. "can't get the clock, err=%ld", PTR_ERR(clk));
  391. return PTR_ERR(clk);
  392. }
  393. mxs_phy = devm_kzalloc(&pdev->dev, sizeof(*mxs_phy), GFP_KERNEL);
  394. if (!mxs_phy)
  395. return -ENOMEM;
  396. /* Some SoCs don't have anatop registers */
  397. if (of_get_property(np, "fsl,anatop", NULL)) {
  398. mxs_phy->regmap_anatop = syscon_regmap_lookup_by_phandle
  399. (np, "fsl,anatop");
  400. if (IS_ERR(mxs_phy->regmap_anatop)) {
  401. dev_dbg(&pdev->dev,
  402. "failed to find regmap for anatop\n");
  403. return PTR_ERR(mxs_phy->regmap_anatop);
  404. }
  405. }
  406. ret = of_alias_get_id(np, "usbphy");
  407. if (ret < 0)
  408. dev_dbg(&pdev->dev, "failed to get alias id, errno %d\n", ret);
  409. mxs_phy->port_id = ret;
  410. mxs_phy->phy.io_priv = base;
  411. mxs_phy->phy.dev = &pdev->dev;
  412. mxs_phy->phy.label = DRIVER_NAME;
  413. mxs_phy->phy.init = mxs_phy_init;
  414. mxs_phy->phy.shutdown = mxs_phy_shutdown;
  415. mxs_phy->phy.set_suspend = mxs_phy_suspend;
  416. mxs_phy->phy.notify_connect = mxs_phy_on_connect;
  417. mxs_phy->phy.notify_disconnect = mxs_phy_on_disconnect;
  418. mxs_phy->phy.type = USB_PHY_TYPE_USB2;
  419. mxs_phy->phy.set_wakeup = mxs_phy_set_wakeup;
  420. mxs_phy->clk = clk;
  421. mxs_phy->data = of_id->data;
  422. platform_set_drvdata(pdev, mxs_phy);
  423. device_set_wakeup_capable(&pdev->dev, true);
  424. return usb_add_phy_dev(&mxs_phy->phy);
  425. }
  426. static int mxs_phy_remove(struct platform_device *pdev)
  427. {
  428. struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
  429. usb_remove_phy(&mxs_phy->phy);
  430. return 0;
  431. }
  432. #ifdef CONFIG_PM_SLEEP
  433. static void mxs_phy_enable_ldo_in_suspend(struct mxs_phy *mxs_phy, bool on)
  434. {
  435. unsigned int reg = on ? ANADIG_ANA_MISC0_SET : ANADIG_ANA_MISC0_CLR;
  436. /* If the SoCs don't have anatop, quit */
  437. if (!mxs_phy->regmap_anatop)
  438. return;
  439. if (is_imx6q_phy(mxs_phy))
  440. regmap_write(mxs_phy->regmap_anatop, reg,
  441. BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG);
  442. else if (is_imx6sl_phy(mxs_phy))
  443. regmap_write(mxs_phy->regmap_anatop,
  444. reg, BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL);
  445. }
  446. static int mxs_phy_system_suspend(struct device *dev)
  447. {
  448. struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
  449. if (device_may_wakeup(dev))
  450. mxs_phy_enable_ldo_in_suspend(mxs_phy, true);
  451. return 0;
  452. }
  453. static int mxs_phy_system_resume(struct device *dev)
  454. {
  455. struct mxs_phy *mxs_phy = dev_get_drvdata(dev);
  456. if (device_may_wakeup(dev))
  457. mxs_phy_enable_ldo_in_suspend(mxs_phy, false);
  458. return 0;
  459. }
  460. #endif /* CONFIG_PM_SLEEP */
  461. static SIMPLE_DEV_PM_OPS(mxs_phy_pm, mxs_phy_system_suspend,
  462. mxs_phy_system_resume);
  463. static struct platform_driver mxs_phy_driver = {
  464. .probe = mxs_phy_probe,
  465. .remove = mxs_phy_remove,
  466. .driver = {
  467. .name = DRIVER_NAME,
  468. .of_match_table = mxs_phy_dt_ids,
  469. .pm = &mxs_phy_pm,
  470. },
  471. };
  472. static int __init mxs_phy_module_init(void)
  473. {
  474. return platform_driver_register(&mxs_phy_driver);
  475. }
  476. postcore_initcall(mxs_phy_module_init);
  477. static void __exit mxs_phy_module_exit(void)
  478. {
  479. platform_driver_unregister(&mxs_phy_driver);
  480. }
  481. module_exit(mxs_phy_module_exit);
  482. MODULE_ALIAS("platform:mxs-usb-phy");
  483. MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
  484. MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
  485. MODULE_DESCRIPTION("Freescale MXS USB PHY driver");
  486. MODULE_LICENSE("GPL");