phy-tegra-usb.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /*
  2. * Copyright (C) 2010 Google, Inc.
  3. * Copyright (C) 2013 NVIDIA Corporation
  4. *
  5. * Author:
  6. * Erik Gilling <konkers@google.com>
  7. * Benoit Goby <benoit@android.com>
  8. * Venu Byravarasu <vbyravarasu@nvidia.com>
  9. *
  10. * This software is licensed under the terms of the GNU General Public
  11. * License version 2, as published by the Free Software Foundation, and
  12. * may be copied, distributed, and modified under those terms.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. */
  20. #include <linux/resource.h>
  21. #include <linux/delay.h>
  22. #include <linux/slab.h>
  23. #include <linux/err.h>
  24. #include <linux/export.h>
  25. #include <linux/module.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/io.h>
  28. #include <linux/gpio.h>
  29. #include <linux/of.h>
  30. #include <linux/of_device.h>
  31. #include <linux/of_gpio.h>
  32. #include <linux/usb/otg.h>
  33. #include <linux/usb/ulpi.h>
  34. #include <linux/usb/of.h>
  35. #include <linux/usb/ehci_def.h>
  36. #include <linux/usb/tegra_usb_phy.h>
  37. #include <linux/regulator/consumer.h>
  38. #define ULPI_VIEWPORT 0x170
  39. /* PORTSC PTS/PHCD bits, Tegra20 only */
  40. #define TEGRA_USB_PORTSC1 0x184
  41. #define TEGRA_USB_PORTSC1_PTS(x) (((x) & 0x3) << 30)
  42. #define TEGRA_USB_PORTSC1_PHCD (1 << 23)
  43. /* HOSTPC1 PTS/PHCD bits, Tegra30 and above */
  44. #define TEGRA_USB_HOSTPC1_DEVLC 0x1b4
  45. #define TEGRA_USB_HOSTPC1_DEVLC_PTS(x) (((x) & 0x7) << 29)
  46. #define TEGRA_USB_HOSTPC1_DEVLC_PHCD (1 << 22)
  47. /* Bits of PORTSC1, which will get cleared by writing 1 into them */
  48. #define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
  49. #define USB_SUSP_CTRL 0x400
  50. #define USB_WAKE_ON_CNNT_EN_DEV (1 << 3)
  51. #define USB_WAKE_ON_DISCON_EN_DEV (1 << 4)
  52. #define USB_SUSP_CLR (1 << 5)
  53. #define USB_PHY_CLK_VALID (1 << 7)
  54. #define UTMIP_RESET (1 << 11)
  55. #define UHSIC_RESET (1 << 11)
  56. #define UTMIP_PHY_ENABLE (1 << 12)
  57. #define ULPI_PHY_ENABLE (1 << 13)
  58. #define USB_SUSP_SET (1 << 14)
  59. #define USB_WAKEUP_DEBOUNCE_COUNT(x) (((x) & 0x7) << 16)
  60. #define USB1_LEGACY_CTRL 0x410
  61. #define USB1_NO_LEGACY_MODE (1 << 0)
  62. #define USB1_VBUS_SENSE_CTL_MASK (3 << 1)
  63. #define USB1_VBUS_SENSE_CTL_VBUS_WAKEUP (0 << 1)
  64. #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD_OR_VBUS_WAKEUP \
  65. (1 << 1)
  66. #define USB1_VBUS_SENSE_CTL_AB_SESS_VLD (2 << 1)
  67. #define USB1_VBUS_SENSE_CTL_A_SESS_VLD (3 << 1)
  68. #define ULPI_TIMING_CTRL_0 0x424
  69. #define ULPI_OUTPUT_PINMUX_BYP (1 << 10)
  70. #define ULPI_CLKOUT_PINMUX_BYP (1 << 11)
  71. #define ULPI_TIMING_CTRL_1 0x428
  72. #define ULPI_DATA_TRIMMER_LOAD (1 << 0)
  73. #define ULPI_DATA_TRIMMER_SEL(x) (((x) & 0x7) << 1)
  74. #define ULPI_STPDIRNXT_TRIMMER_LOAD (1 << 16)
  75. #define ULPI_STPDIRNXT_TRIMMER_SEL(x) (((x) & 0x7) << 17)
  76. #define ULPI_DIR_TRIMMER_LOAD (1 << 24)
  77. #define ULPI_DIR_TRIMMER_SEL(x) (((x) & 0x7) << 25)
  78. #define UTMIP_PLL_CFG1 0x804
  79. #define UTMIP_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
  80. #define UTMIP_PLLU_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
  81. #define UTMIP_XCVR_CFG0 0x808
  82. #define UTMIP_XCVR_SETUP(x) (((x) & 0xf) << 0)
  83. #define UTMIP_XCVR_SETUP_MSB(x) ((((x) & 0x70) >> 4) << 22)
  84. #define UTMIP_XCVR_LSRSLEW(x) (((x) & 0x3) << 8)
  85. #define UTMIP_XCVR_LSFSLEW(x) (((x) & 0x3) << 10)
  86. #define UTMIP_FORCE_PD_POWERDOWN (1 << 14)
  87. #define UTMIP_FORCE_PD2_POWERDOWN (1 << 16)
  88. #define UTMIP_FORCE_PDZI_POWERDOWN (1 << 18)
  89. #define UTMIP_XCVR_LSBIAS_SEL (1 << 21)
  90. #define UTMIP_XCVR_HSSLEW(x) (((x) & 0x3) << 4)
  91. #define UTMIP_XCVR_HSSLEW_MSB(x) ((((x) & 0x1fc) >> 2) << 25)
  92. #define UTMIP_BIAS_CFG0 0x80c
  93. #define UTMIP_OTGPD (1 << 11)
  94. #define UTMIP_BIASPD (1 << 10)
  95. #define UTMIP_HSSQUELCH_LEVEL(x) (((x) & 0x3) << 0)
  96. #define UTMIP_HSDISCON_LEVEL(x) (((x) & 0x3) << 2)
  97. #define UTMIP_HSDISCON_LEVEL_MSB(x) ((((x) & 0x4) >> 2) << 24)
  98. #define UTMIP_HSRX_CFG0 0x810
  99. #define UTMIP_ELASTIC_LIMIT(x) (((x) & 0x1f) << 10)
  100. #define UTMIP_IDLE_WAIT(x) (((x) & 0x1f) << 15)
  101. #define UTMIP_HSRX_CFG1 0x814
  102. #define UTMIP_HS_SYNC_START_DLY(x) (((x) & 0x1f) << 1)
  103. #define UTMIP_TX_CFG0 0x820
  104. #define UTMIP_FS_PREABMLE_J (1 << 19)
  105. #define UTMIP_HS_DISCON_DISABLE (1 << 8)
  106. #define UTMIP_MISC_CFG0 0x824
  107. #define UTMIP_DPDM_OBSERVE (1 << 26)
  108. #define UTMIP_DPDM_OBSERVE_SEL(x) (((x) & 0xf) << 27)
  109. #define UTMIP_DPDM_OBSERVE_SEL_FS_J UTMIP_DPDM_OBSERVE_SEL(0xf)
  110. #define UTMIP_DPDM_OBSERVE_SEL_FS_K UTMIP_DPDM_OBSERVE_SEL(0xe)
  111. #define UTMIP_DPDM_OBSERVE_SEL_FS_SE1 UTMIP_DPDM_OBSERVE_SEL(0xd)
  112. #define UTMIP_DPDM_OBSERVE_SEL_FS_SE0 UTMIP_DPDM_OBSERVE_SEL(0xc)
  113. #define UTMIP_SUSPEND_EXIT_ON_EDGE (1 << 22)
  114. #define UTMIP_MISC_CFG1 0x828
  115. #define UTMIP_PLL_ACTIVE_DLY_COUNT(x) (((x) & 0x1f) << 18)
  116. #define UTMIP_PLLU_STABLE_COUNT(x) (((x) & 0xfff) << 6)
  117. #define UTMIP_DEBOUNCE_CFG0 0x82c
  118. #define UTMIP_BIAS_DEBOUNCE_A(x) (((x) & 0xffff) << 0)
  119. #define UTMIP_BAT_CHRG_CFG0 0x830
  120. #define UTMIP_PD_CHRG (1 << 0)
  121. #define UTMIP_SPARE_CFG0 0x834
  122. #define FUSE_SETUP_SEL (1 << 3)
  123. #define UTMIP_XCVR_CFG1 0x838
  124. #define UTMIP_FORCE_PDDISC_POWERDOWN (1 << 0)
  125. #define UTMIP_FORCE_PDCHRP_POWERDOWN (1 << 2)
  126. #define UTMIP_FORCE_PDDR_POWERDOWN (1 << 4)
  127. #define UTMIP_XCVR_TERM_RANGE_ADJ(x) (((x) & 0xf) << 18)
  128. #define UTMIP_BIAS_CFG1 0x83c
  129. #define UTMIP_BIAS_PDTRK_COUNT(x) (((x) & 0x1f) << 3)
  130. /* For Tegra30 and above only, the address is different in Tegra20 */
  131. #define USB_USBMODE 0x1f8
  132. #define USB_USBMODE_MASK (3 << 0)
  133. #define USB_USBMODE_HOST (3 << 0)
  134. #define USB_USBMODE_DEVICE (2 << 0)
  135. static DEFINE_SPINLOCK(utmip_pad_lock);
  136. static int utmip_pad_count;
  137. struct tegra_xtal_freq {
  138. int freq;
  139. u8 enable_delay;
  140. u8 stable_count;
  141. u8 active_delay;
  142. u8 xtal_freq_count;
  143. u16 debounce;
  144. };
  145. static const struct tegra_xtal_freq tegra_freq_table[] = {
  146. {
  147. .freq = 12000000,
  148. .enable_delay = 0x02,
  149. .stable_count = 0x2F,
  150. .active_delay = 0x04,
  151. .xtal_freq_count = 0x76,
  152. .debounce = 0x7530,
  153. },
  154. {
  155. .freq = 13000000,
  156. .enable_delay = 0x02,
  157. .stable_count = 0x33,
  158. .active_delay = 0x05,
  159. .xtal_freq_count = 0x7F,
  160. .debounce = 0x7EF4,
  161. },
  162. {
  163. .freq = 19200000,
  164. .enable_delay = 0x03,
  165. .stable_count = 0x4B,
  166. .active_delay = 0x06,
  167. .xtal_freq_count = 0xBB,
  168. .debounce = 0xBB80,
  169. },
  170. {
  171. .freq = 26000000,
  172. .enable_delay = 0x04,
  173. .stable_count = 0x66,
  174. .active_delay = 0x09,
  175. .xtal_freq_count = 0xFE,
  176. .debounce = 0xFDE8,
  177. },
  178. };
  179. static void set_pts(struct tegra_usb_phy *phy, u8 pts_val)
  180. {
  181. void __iomem *base = phy->regs;
  182. unsigned long val;
  183. if (phy->soc_config->has_hostpc) {
  184. val = readl(base + TEGRA_USB_HOSTPC1_DEVLC);
  185. val &= ~TEGRA_USB_HOSTPC1_DEVLC_PTS(~0);
  186. val |= TEGRA_USB_HOSTPC1_DEVLC_PTS(pts_val);
  187. writel(val, base + TEGRA_USB_HOSTPC1_DEVLC);
  188. } else {
  189. val = readl(base + TEGRA_USB_PORTSC1) & ~TEGRA_PORTSC1_RWC_BITS;
  190. val &= ~TEGRA_USB_PORTSC1_PTS(~0);
  191. val |= TEGRA_USB_PORTSC1_PTS(pts_val);
  192. writel(val, base + TEGRA_USB_PORTSC1);
  193. }
  194. }
  195. static void set_phcd(struct tegra_usb_phy *phy, bool enable)
  196. {
  197. void __iomem *base = phy->regs;
  198. unsigned long val;
  199. if (phy->soc_config->has_hostpc) {
  200. val = readl(base + TEGRA_USB_HOSTPC1_DEVLC);
  201. if (enable)
  202. val |= TEGRA_USB_HOSTPC1_DEVLC_PHCD;
  203. else
  204. val &= ~TEGRA_USB_HOSTPC1_DEVLC_PHCD;
  205. writel(val, base + TEGRA_USB_HOSTPC1_DEVLC);
  206. } else {
  207. val = readl(base + TEGRA_USB_PORTSC1) & ~PORT_RWC_BITS;
  208. if (enable)
  209. val |= TEGRA_USB_PORTSC1_PHCD;
  210. else
  211. val &= ~TEGRA_USB_PORTSC1_PHCD;
  212. writel(val, base + TEGRA_USB_PORTSC1);
  213. }
  214. }
  215. static int utmip_pad_open(struct tegra_usb_phy *phy)
  216. {
  217. phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads");
  218. if (IS_ERR(phy->pad_clk)) {
  219. pr_err("%s: can't get utmip pad clock\n", __func__);
  220. return PTR_ERR(phy->pad_clk);
  221. }
  222. return 0;
  223. }
  224. static void utmip_pad_power_on(struct tegra_usb_phy *phy)
  225. {
  226. unsigned long val, flags;
  227. void __iomem *base = phy->pad_regs;
  228. struct tegra_utmip_config *config = phy->config;
  229. clk_prepare_enable(phy->pad_clk);
  230. spin_lock_irqsave(&utmip_pad_lock, flags);
  231. if (utmip_pad_count++ == 0) {
  232. val = readl(base + UTMIP_BIAS_CFG0);
  233. val &= ~(UTMIP_OTGPD | UTMIP_BIASPD);
  234. if (phy->soc_config->requires_extra_tuning_parameters) {
  235. val &= ~(UTMIP_HSSQUELCH_LEVEL(~0) |
  236. UTMIP_HSDISCON_LEVEL(~0) |
  237. UTMIP_HSDISCON_LEVEL_MSB(~0));
  238. val |= UTMIP_HSSQUELCH_LEVEL(config->hssquelch_level);
  239. val |= UTMIP_HSDISCON_LEVEL(config->hsdiscon_level);
  240. val |= UTMIP_HSDISCON_LEVEL_MSB(config->hsdiscon_level);
  241. }
  242. writel(val, base + UTMIP_BIAS_CFG0);
  243. }
  244. spin_unlock_irqrestore(&utmip_pad_lock, flags);
  245. clk_disable_unprepare(phy->pad_clk);
  246. }
  247. static int utmip_pad_power_off(struct tegra_usb_phy *phy)
  248. {
  249. unsigned long val, flags;
  250. void __iomem *base = phy->pad_regs;
  251. if (!utmip_pad_count) {
  252. pr_err("%s: utmip pad already powered off\n", __func__);
  253. return -EINVAL;
  254. }
  255. clk_prepare_enable(phy->pad_clk);
  256. spin_lock_irqsave(&utmip_pad_lock, flags);
  257. if (--utmip_pad_count == 0) {
  258. val = readl(base + UTMIP_BIAS_CFG0);
  259. val |= UTMIP_OTGPD | UTMIP_BIASPD;
  260. writel(val, base + UTMIP_BIAS_CFG0);
  261. }
  262. spin_unlock_irqrestore(&utmip_pad_lock, flags);
  263. clk_disable_unprepare(phy->pad_clk);
  264. return 0;
  265. }
  266. static int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
  267. {
  268. unsigned long timeout = 2000;
  269. do {
  270. if ((readl(reg) & mask) == result)
  271. return 0;
  272. udelay(1);
  273. timeout--;
  274. } while (timeout);
  275. return -1;
  276. }
  277. static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
  278. {
  279. unsigned long val;
  280. void __iomem *base = phy->regs;
  281. /*
  282. * The USB driver may have already initiated the phy clock
  283. * disable so wait to see if the clock turns off and if not
  284. * then proceed with gating the clock.
  285. */
  286. if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) == 0)
  287. return;
  288. if (phy->is_legacy_phy) {
  289. val = readl(base + USB_SUSP_CTRL);
  290. val |= USB_SUSP_SET;
  291. writel(val, base + USB_SUSP_CTRL);
  292. udelay(10);
  293. val = readl(base + USB_SUSP_CTRL);
  294. val &= ~USB_SUSP_SET;
  295. writel(val, base + USB_SUSP_CTRL);
  296. } else
  297. set_phcd(phy, true);
  298. if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
  299. pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
  300. }
  301. static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
  302. {
  303. unsigned long val;
  304. void __iomem *base = phy->regs;
  305. /*
  306. * The USB driver may have already initiated the phy clock
  307. * enable so wait to see if the clock turns on and if not
  308. * then proceed with ungating the clock.
  309. */
  310. if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
  311. USB_PHY_CLK_VALID) == 0)
  312. return;
  313. if (phy->is_legacy_phy) {
  314. val = readl(base + USB_SUSP_CTRL);
  315. val |= USB_SUSP_CLR;
  316. writel(val, base + USB_SUSP_CTRL);
  317. udelay(10);
  318. val = readl(base + USB_SUSP_CTRL);
  319. val &= ~USB_SUSP_CLR;
  320. writel(val, base + USB_SUSP_CTRL);
  321. } else
  322. set_phcd(phy, false);
  323. if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
  324. USB_PHY_CLK_VALID))
  325. pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
  326. }
  327. static int utmi_phy_power_on(struct tegra_usb_phy *phy)
  328. {
  329. unsigned long val;
  330. void __iomem *base = phy->regs;
  331. struct tegra_utmip_config *config = phy->config;
  332. val = readl(base + USB_SUSP_CTRL);
  333. val |= UTMIP_RESET;
  334. writel(val, base + USB_SUSP_CTRL);
  335. if (phy->is_legacy_phy) {
  336. val = readl(base + USB1_LEGACY_CTRL);
  337. val |= USB1_NO_LEGACY_MODE;
  338. writel(val, base + USB1_LEGACY_CTRL);
  339. }
  340. val = readl(base + UTMIP_TX_CFG0);
  341. val |= UTMIP_FS_PREABMLE_J;
  342. writel(val, base + UTMIP_TX_CFG0);
  343. val = readl(base + UTMIP_HSRX_CFG0);
  344. val &= ~(UTMIP_IDLE_WAIT(~0) | UTMIP_ELASTIC_LIMIT(~0));
  345. val |= UTMIP_IDLE_WAIT(config->idle_wait_delay);
  346. val |= UTMIP_ELASTIC_LIMIT(config->elastic_limit);
  347. writel(val, base + UTMIP_HSRX_CFG0);
  348. val = readl(base + UTMIP_HSRX_CFG1);
  349. val &= ~UTMIP_HS_SYNC_START_DLY(~0);
  350. val |= UTMIP_HS_SYNC_START_DLY(config->hssync_start_delay);
  351. writel(val, base + UTMIP_HSRX_CFG1);
  352. val = readl(base + UTMIP_DEBOUNCE_CFG0);
  353. val &= ~UTMIP_BIAS_DEBOUNCE_A(~0);
  354. val |= UTMIP_BIAS_DEBOUNCE_A(phy->freq->debounce);
  355. writel(val, base + UTMIP_DEBOUNCE_CFG0);
  356. val = readl(base + UTMIP_MISC_CFG0);
  357. val &= ~UTMIP_SUSPEND_EXIT_ON_EDGE;
  358. writel(val, base + UTMIP_MISC_CFG0);
  359. if (!phy->soc_config->utmi_pll_config_in_car_module) {
  360. val = readl(base + UTMIP_MISC_CFG1);
  361. val &= ~(UTMIP_PLL_ACTIVE_DLY_COUNT(~0) |
  362. UTMIP_PLLU_STABLE_COUNT(~0));
  363. val |= UTMIP_PLL_ACTIVE_DLY_COUNT(phy->freq->active_delay) |
  364. UTMIP_PLLU_STABLE_COUNT(phy->freq->stable_count);
  365. writel(val, base + UTMIP_MISC_CFG1);
  366. val = readl(base + UTMIP_PLL_CFG1);
  367. val &= ~(UTMIP_XTAL_FREQ_COUNT(~0) |
  368. UTMIP_PLLU_ENABLE_DLY_COUNT(~0));
  369. val |= UTMIP_XTAL_FREQ_COUNT(phy->freq->xtal_freq_count) |
  370. UTMIP_PLLU_ENABLE_DLY_COUNT(phy->freq->enable_delay);
  371. writel(val, base + UTMIP_PLL_CFG1);
  372. }
  373. if (phy->mode == USB_DR_MODE_PERIPHERAL) {
  374. val = readl(base + USB_SUSP_CTRL);
  375. val &= ~(USB_WAKE_ON_CNNT_EN_DEV | USB_WAKE_ON_DISCON_EN_DEV);
  376. writel(val, base + USB_SUSP_CTRL);
  377. val = readl(base + UTMIP_BAT_CHRG_CFG0);
  378. val &= ~UTMIP_PD_CHRG;
  379. writel(val, base + UTMIP_BAT_CHRG_CFG0);
  380. } else {
  381. val = readl(base + UTMIP_BAT_CHRG_CFG0);
  382. val |= UTMIP_PD_CHRG;
  383. writel(val, base + UTMIP_BAT_CHRG_CFG0);
  384. }
  385. utmip_pad_power_on(phy);
  386. val = readl(base + UTMIP_XCVR_CFG0);
  387. val &= ~(UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
  388. UTMIP_FORCE_PDZI_POWERDOWN | UTMIP_XCVR_LSBIAS_SEL |
  389. UTMIP_XCVR_SETUP(~0) | UTMIP_XCVR_SETUP_MSB(~0) |
  390. UTMIP_XCVR_LSFSLEW(~0) | UTMIP_XCVR_LSRSLEW(~0));
  391. if (!config->xcvr_setup_use_fuses) {
  392. val |= UTMIP_XCVR_SETUP(config->xcvr_setup);
  393. val |= UTMIP_XCVR_SETUP_MSB(config->xcvr_setup);
  394. }
  395. val |= UTMIP_XCVR_LSFSLEW(config->xcvr_lsfslew);
  396. val |= UTMIP_XCVR_LSRSLEW(config->xcvr_lsrslew);
  397. if (phy->soc_config->requires_extra_tuning_parameters) {
  398. val &= ~(UTMIP_XCVR_HSSLEW(~0) | UTMIP_XCVR_HSSLEW_MSB(~0));
  399. val |= UTMIP_XCVR_HSSLEW(config->xcvr_hsslew);
  400. val |= UTMIP_XCVR_HSSLEW_MSB(config->xcvr_hsslew);
  401. }
  402. writel(val, base + UTMIP_XCVR_CFG0);
  403. val = readl(base + UTMIP_XCVR_CFG1);
  404. val &= ~(UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
  405. UTMIP_FORCE_PDDR_POWERDOWN | UTMIP_XCVR_TERM_RANGE_ADJ(~0));
  406. val |= UTMIP_XCVR_TERM_RANGE_ADJ(config->term_range_adj);
  407. writel(val, base + UTMIP_XCVR_CFG1);
  408. val = readl(base + UTMIP_BIAS_CFG1);
  409. val &= ~UTMIP_BIAS_PDTRK_COUNT(~0);
  410. val |= UTMIP_BIAS_PDTRK_COUNT(0x5);
  411. writel(val, base + UTMIP_BIAS_CFG1);
  412. val = readl(base + UTMIP_SPARE_CFG0);
  413. if (config->xcvr_setup_use_fuses)
  414. val |= FUSE_SETUP_SEL;
  415. else
  416. val &= ~FUSE_SETUP_SEL;
  417. writel(val, base + UTMIP_SPARE_CFG0);
  418. if (!phy->is_legacy_phy) {
  419. val = readl(base + USB_SUSP_CTRL);
  420. val |= UTMIP_PHY_ENABLE;
  421. writel(val, base + USB_SUSP_CTRL);
  422. }
  423. val = readl(base + USB_SUSP_CTRL);
  424. val &= ~UTMIP_RESET;
  425. writel(val, base + USB_SUSP_CTRL);
  426. if (phy->is_legacy_phy) {
  427. val = readl(base + USB1_LEGACY_CTRL);
  428. val &= ~USB1_VBUS_SENSE_CTL_MASK;
  429. val |= USB1_VBUS_SENSE_CTL_A_SESS_VLD;
  430. writel(val, base + USB1_LEGACY_CTRL);
  431. val = readl(base + USB_SUSP_CTRL);
  432. val &= ~USB_SUSP_SET;
  433. writel(val, base + USB_SUSP_CTRL);
  434. }
  435. utmi_phy_clk_enable(phy);
  436. if (phy->soc_config->requires_usbmode_setup) {
  437. val = readl(base + USB_USBMODE);
  438. val &= ~USB_USBMODE_MASK;
  439. if (phy->mode == USB_DR_MODE_HOST)
  440. val |= USB_USBMODE_HOST;
  441. else
  442. val |= USB_USBMODE_DEVICE;
  443. writel(val, base + USB_USBMODE);
  444. }
  445. if (!phy->is_legacy_phy)
  446. set_pts(phy, 0);
  447. return 0;
  448. }
  449. static int utmi_phy_power_off(struct tegra_usb_phy *phy)
  450. {
  451. unsigned long val;
  452. void __iomem *base = phy->regs;
  453. utmi_phy_clk_disable(phy);
  454. if (phy->mode == USB_DR_MODE_PERIPHERAL) {
  455. val = readl(base + USB_SUSP_CTRL);
  456. val &= ~USB_WAKEUP_DEBOUNCE_COUNT(~0);
  457. val |= USB_WAKE_ON_CNNT_EN_DEV | USB_WAKEUP_DEBOUNCE_COUNT(5);
  458. writel(val, base + USB_SUSP_CTRL);
  459. }
  460. val = readl(base + USB_SUSP_CTRL);
  461. val |= UTMIP_RESET;
  462. writel(val, base + USB_SUSP_CTRL);
  463. val = readl(base + UTMIP_BAT_CHRG_CFG0);
  464. val |= UTMIP_PD_CHRG;
  465. writel(val, base + UTMIP_BAT_CHRG_CFG0);
  466. val = readl(base + UTMIP_XCVR_CFG0);
  467. val |= UTMIP_FORCE_PD_POWERDOWN | UTMIP_FORCE_PD2_POWERDOWN |
  468. UTMIP_FORCE_PDZI_POWERDOWN;
  469. writel(val, base + UTMIP_XCVR_CFG0);
  470. val = readl(base + UTMIP_XCVR_CFG1);
  471. val |= UTMIP_FORCE_PDDISC_POWERDOWN | UTMIP_FORCE_PDCHRP_POWERDOWN |
  472. UTMIP_FORCE_PDDR_POWERDOWN;
  473. writel(val, base + UTMIP_XCVR_CFG1);
  474. return utmip_pad_power_off(phy);
  475. }
  476. static void utmi_phy_preresume(struct tegra_usb_phy *phy)
  477. {
  478. unsigned long val;
  479. void __iomem *base = phy->regs;
  480. val = readl(base + UTMIP_TX_CFG0);
  481. val |= UTMIP_HS_DISCON_DISABLE;
  482. writel(val, base + UTMIP_TX_CFG0);
  483. }
  484. static void utmi_phy_postresume(struct tegra_usb_phy *phy)
  485. {
  486. unsigned long val;
  487. void __iomem *base = phy->regs;
  488. val = readl(base + UTMIP_TX_CFG0);
  489. val &= ~UTMIP_HS_DISCON_DISABLE;
  490. writel(val, base + UTMIP_TX_CFG0);
  491. }
  492. static void utmi_phy_restore_start(struct tegra_usb_phy *phy,
  493. enum tegra_usb_phy_port_speed port_speed)
  494. {
  495. unsigned long val;
  496. void __iomem *base = phy->regs;
  497. val = readl(base + UTMIP_MISC_CFG0);
  498. val &= ~UTMIP_DPDM_OBSERVE_SEL(~0);
  499. if (port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
  500. val |= UTMIP_DPDM_OBSERVE_SEL_FS_K;
  501. else
  502. val |= UTMIP_DPDM_OBSERVE_SEL_FS_J;
  503. writel(val, base + UTMIP_MISC_CFG0);
  504. udelay(1);
  505. val = readl(base + UTMIP_MISC_CFG0);
  506. val |= UTMIP_DPDM_OBSERVE;
  507. writel(val, base + UTMIP_MISC_CFG0);
  508. udelay(10);
  509. }
  510. static void utmi_phy_restore_end(struct tegra_usb_phy *phy)
  511. {
  512. unsigned long val;
  513. void __iomem *base = phy->regs;
  514. val = readl(base + UTMIP_MISC_CFG0);
  515. val &= ~UTMIP_DPDM_OBSERVE;
  516. writel(val, base + UTMIP_MISC_CFG0);
  517. udelay(10);
  518. }
  519. static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
  520. {
  521. int ret;
  522. unsigned long val;
  523. void __iomem *base = phy->regs;
  524. ret = gpio_direction_output(phy->reset_gpio, 0);
  525. if (ret < 0) {
  526. dev_err(phy->u_phy.dev, "gpio %d not set to 0\n",
  527. phy->reset_gpio);
  528. return ret;
  529. }
  530. msleep(5);
  531. ret = gpio_direction_output(phy->reset_gpio, 1);
  532. if (ret < 0) {
  533. dev_err(phy->u_phy.dev, "gpio %d not set to 1\n",
  534. phy->reset_gpio);
  535. return ret;
  536. }
  537. clk_prepare_enable(phy->clk);
  538. msleep(1);
  539. val = readl(base + USB_SUSP_CTRL);
  540. val |= UHSIC_RESET;
  541. writel(val, base + USB_SUSP_CTRL);
  542. val = readl(base + ULPI_TIMING_CTRL_0);
  543. val |= ULPI_OUTPUT_PINMUX_BYP | ULPI_CLKOUT_PINMUX_BYP;
  544. writel(val, base + ULPI_TIMING_CTRL_0);
  545. val = readl(base + USB_SUSP_CTRL);
  546. val |= ULPI_PHY_ENABLE;
  547. writel(val, base + USB_SUSP_CTRL);
  548. val = 0;
  549. writel(val, base + ULPI_TIMING_CTRL_1);
  550. val |= ULPI_DATA_TRIMMER_SEL(4);
  551. val |= ULPI_STPDIRNXT_TRIMMER_SEL(4);
  552. val |= ULPI_DIR_TRIMMER_SEL(4);
  553. writel(val, base + ULPI_TIMING_CTRL_1);
  554. udelay(10);
  555. val |= ULPI_DATA_TRIMMER_LOAD;
  556. val |= ULPI_STPDIRNXT_TRIMMER_LOAD;
  557. val |= ULPI_DIR_TRIMMER_LOAD;
  558. writel(val, base + ULPI_TIMING_CTRL_1);
  559. /* Fix VbusInvalid due to floating VBUS */
  560. ret = usb_phy_io_write(phy->ulpi, 0x40, 0x08);
  561. if (ret) {
  562. pr_err("%s: ulpi write failed\n", __func__);
  563. return ret;
  564. }
  565. ret = usb_phy_io_write(phy->ulpi, 0x80, 0x0B);
  566. if (ret) {
  567. pr_err("%s: ulpi write failed\n", __func__);
  568. return ret;
  569. }
  570. val = readl(base + USB_SUSP_CTRL);
  571. val |= USB_SUSP_CLR;
  572. writel(val, base + USB_SUSP_CTRL);
  573. udelay(100);
  574. val = readl(base + USB_SUSP_CTRL);
  575. val &= ~USB_SUSP_CLR;
  576. writel(val, base + USB_SUSP_CTRL);
  577. return 0;
  578. }
  579. static int ulpi_phy_power_off(struct tegra_usb_phy *phy)
  580. {
  581. clk_disable(phy->clk);
  582. return gpio_direction_output(phy->reset_gpio, 0);
  583. }
  584. static void tegra_usb_phy_close(struct tegra_usb_phy *phy)
  585. {
  586. if (!IS_ERR(phy->vbus))
  587. regulator_disable(phy->vbus);
  588. clk_disable_unprepare(phy->pll_u);
  589. }
  590. static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
  591. {
  592. if (phy->is_ulpi_phy)
  593. return ulpi_phy_power_on(phy);
  594. else
  595. return utmi_phy_power_on(phy);
  596. }
  597. static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
  598. {
  599. if (phy->is_ulpi_phy)
  600. return ulpi_phy_power_off(phy);
  601. else
  602. return utmi_phy_power_off(phy);
  603. }
  604. static int tegra_usb_phy_suspend(struct usb_phy *x, int suspend)
  605. {
  606. struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
  607. if (suspend)
  608. return tegra_usb_phy_power_off(phy);
  609. else
  610. return tegra_usb_phy_power_on(phy);
  611. }
  612. static int ulpi_open(struct tegra_usb_phy *phy)
  613. {
  614. int err;
  615. phy->clk = devm_clk_get(phy->u_phy.dev, "ulpi-link");
  616. if (IS_ERR(phy->clk)) {
  617. pr_err("%s: can't get ulpi clock\n", __func__);
  618. return PTR_ERR(phy->clk);
  619. }
  620. err = devm_gpio_request(phy->u_phy.dev, phy->reset_gpio,
  621. "ulpi_phy_reset_b");
  622. if (err < 0) {
  623. dev_err(phy->u_phy.dev, "request failed for gpio: %d\n",
  624. phy->reset_gpio);
  625. return err;
  626. }
  627. err = gpio_direction_output(phy->reset_gpio, 0);
  628. if (err < 0) {
  629. dev_err(phy->u_phy.dev, "gpio %d direction not set to output\n",
  630. phy->reset_gpio);
  631. return err;
  632. }
  633. phy->ulpi = otg_ulpi_create(&ulpi_viewport_access_ops, 0);
  634. if (!phy->ulpi) {
  635. dev_err(phy->u_phy.dev, "otg_ulpi_create returned NULL\n");
  636. err = -ENOMEM;
  637. return err;
  638. }
  639. phy->ulpi->io_priv = phy->regs + ULPI_VIEWPORT;
  640. return 0;
  641. }
  642. static int tegra_usb_phy_init(struct tegra_usb_phy *phy)
  643. {
  644. unsigned long parent_rate;
  645. int i;
  646. int err;
  647. phy->pll_u = devm_clk_get(phy->u_phy.dev, "pll_u");
  648. if (IS_ERR(phy->pll_u)) {
  649. pr_err("Can't get pll_u clock\n");
  650. return PTR_ERR(phy->pll_u);
  651. }
  652. err = clk_prepare_enable(phy->pll_u);
  653. if (err)
  654. return err;
  655. parent_rate = clk_get_rate(clk_get_parent(phy->pll_u));
  656. for (i = 0; i < ARRAY_SIZE(tegra_freq_table); i++) {
  657. if (tegra_freq_table[i].freq == parent_rate) {
  658. phy->freq = &tegra_freq_table[i];
  659. break;
  660. }
  661. }
  662. if (!phy->freq) {
  663. pr_err("invalid pll_u parent rate %ld\n", parent_rate);
  664. err = -EINVAL;
  665. goto fail;
  666. }
  667. if (!IS_ERR(phy->vbus)) {
  668. err = regulator_enable(phy->vbus);
  669. if (err) {
  670. dev_err(phy->u_phy.dev,
  671. "failed to enable usb vbus regulator: %d\n",
  672. err);
  673. goto fail;
  674. }
  675. }
  676. if (phy->is_ulpi_phy)
  677. err = ulpi_open(phy);
  678. else
  679. err = utmip_pad_open(phy);
  680. if (err < 0)
  681. goto fail;
  682. return 0;
  683. fail:
  684. clk_disable_unprepare(phy->pll_u);
  685. return err;
  686. }
  687. void tegra_usb_phy_preresume(struct usb_phy *x)
  688. {
  689. struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
  690. if (!phy->is_ulpi_phy)
  691. utmi_phy_preresume(phy);
  692. }
  693. EXPORT_SYMBOL_GPL(tegra_usb_phy_preresume);
  694. void tegra_usb_phy_postresume(struct usb_phy *x)
  695. {
  696. struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
  697. if (!phy->is_ulpi_phy)
  698. utmi_phy_postresume(phy);
  699. }
  700. EXPORT_SYMBOL_GPL(tegra_usb_phy_postresume);
  701. void tegra_ehci_phy_restore_start(struct usb_phy *x,
  702. enum tegra_usb_phy_port_speed port_speed)
  703. {
  704. struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
  705. if (!phy->is_ulpi_phy)
  706. utmi_phy_restore_start(phy, port_speed);
  707. }
  708. EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_start);
  709. void tegra_ehci_phy_restore_end(struct usb_phy *x)
  710. {
  711. struct tegra_usb_phy *phy = container_of(x, struct tegra_usb_phy, u_phy);
  712. if (!phy->is_ulpi_phy)
  713. utmi_phy_restore_end(phy);
  714. }
  715. EXPORT_SYMBOL_GPL(tegra_ehci_phy_restore_end);
  716. static int read_utmi_param(struct platform_device *pdev, const char *param,
  717. u8 *dest)
  718. {
  719. u32 value;
  720. int err = of_property_read_u32(pdev->dev.of_node, param, &value);
  721. *dest = (u8)value;
  722. if (err < 0)
  723. dev_err(&pdev->dev, "Failed to read USB UTMI parameter %s: %d\n",
  724. param, err);
  725. return err;
  726. }
  727. static int utmi_phy_probe(struct tegra_usb_phy *tegra_phy,
  728. struct platform_device *pdev)
  729. {
  730. struct resource *res;
  731. int err;
  732. struct tegra_utmip_config *config;
  733. tegra_phy->is_ulpi_phy = false;
  734. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  735. if (!res) {
  736. dev_err(&pdev->dev, "Failed to get UTMI Pad regs\n");
  737. return -ENXIO;
  738. }
  739. tegra_phy->pad_regs = devm_ioremap(&pdev->dev, res->start,
  740. resource_size(res));
  741. if (!tegra_phy->pad_regs) {
  742. dev_err(&pdev->dev, "Failed to remap UTMI Pad regs\n");
  743. return -ENOMEM;
  744. }
  745. tegra_phy->config = devm_kzalloc(&pdev->dev, sizeof(*config),
  746. GFP_KERNEL);
  747. if (!tegra_phy->config)
  748. return -ENOMEM;
  749. config = tegra_phy->config;
  750. err = read_utmi_param(pdev, "nvidia,hssync-start-delay",
  751. &config->hssync_start_delay);
  752. if (err < 0)
  753. return err;
  754. err = read_utmi_param(pdev, "nvidia,elastic-limit",
  755. &config->elastic_limit);
  756. if (err < 0)
  757. return err;
  758. err = read_utmi_param(pdev, "nvidia,idle-wait-delay",
  759. &config->idle_wait_delay);
  760. if (err < 0)
  761. return err;
  762. err = read_utmi_param(pdev, "nvidia,term-range-adj",
  763. &config->term_range_adj);
  764. if (err < 0)
  765. return err;
  766. err = read_utmi_param(pdev, "nvidia,xcvr-lsfslew",
  767. &config->xcvr_lsfslew);
  768. if (err < 0)
  769. return err;
  770. err = read_utmi_param(pdev, "nvidia,xcvr-lsrslew",
  771. &config->xcvr_lsrslew);
  772. if (err < 0)
  773. return err;
  774. if (tegra_phy->soc_config->requires_extra_tuning_parameters) {
  775. err = read_utmi_param(pdev, "nvidia,xcvr-hsslew",
  776. &config->xcvr_hsslew);
  777. if (err < 0)
  778. return err;
  779. err = read_utmi_param(pdev, "nvidia,hssquelch-level",
  780. &config->hssquelch_level);
  781. if (err < 0)
  782. return err;
  783. err = read_utmi_param(pdev, "nvidia,hsdiscon-level",
  784. &config->hsdiscon_level);
  785. if (err < 0)
  786. return err;
  787. }
  788. config->xcvr_setup_use_fuses = of_property_read_bool(
  789. pdev->dev.of_node, "nvidia,xcvr-setup-use-fuses");
  790. if (!config->xcvr_setup_use_fuses) {
  791. err = read_utmi_param(pdev, "nvidia,xcvr-setup",
  792. &config->xcvr_setup);
  793. if (err < 0)
  794. return err;
  795. }
  796. return 0;
  797. }
  798. static const struct tegra_phy_soc_config tegra20_soc_config = {
  799. .utmi_pll_config_in_car_module = false,
  800. .has_hostpc = false,
  801. .requires_usbmode_setup = false,
  802. .requires_extra_tuning_parameters = false,
  803. };
  804. static const struct tegra_phy_soc_config tegra30_soc_config = {
  805. .utmi_pll_config_in_car_module = true,
  806. .has_hostpc = true,
  807. .requires_usbmode_setup = true,
  808. .requires_extra_tuning_parameters = true,
  809. };
  810. static const struct of_device_id tegra_usb_phy_id_table[] = {
  811. { .compatible = "nvidia,tegra30-usb-phy", .data = &tegra30_soc_config },
  812. { .compatible = "nvidia,tegra20-usb-phy", .data = &tegra20_soc_config },
  813. { },
  814. };
  815. MODULE_DEVICE_TABLE(of, tegra_usb_phy_id_table);
  816. static int tegra_usb_phy_probe(struct platform_device *pdev)
  817. {
  818. const struct of_device_id *match;
  819. struct resource *res;
  820. struct tegra_usb_phy *tegra_phy = NULL;
  821. struct device_node *np = pdev->dev.of_node;
  822. enum usb_phy_interface phy_type;
  823. int err;
  824. tegra_phy = devm_kzalloc(&pdev->dev, sizeof(*tegra_phy), GFP_KERNEL);
  825. if (!tegra_phy)
  826. return -ENOMEM;
  827. match = of_match_device(tegra_usb_phy_id_table, &pdev->dev);
  828. if (!match) {
  829. dev_err(&pdev->dev, "Error: No device match found\n");
  830. return -ENODEV;
  831. }
  832. tegra_phy->soc_config = match->data;
  833. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  834. if (!res) {
  835. dev_err(&pdev->dev, "Failed to get I/O memory\n");
  836. return -ENXIO;
  837. }
  838. tegra_phy->regs = devm_ioremap(&pdev->dev, res->start,
  839. resource_size(res));
  840. if (!tegra_phy->regs) {
  841. dev_err(&pdev->dev, "Failed to remap I/O memory\n");
  842. return -ENOMEM;
  843. }
  844. tegra_phy->is_legacy_phy =
  845. of_property_read_bool(np, "nvidia,has-legacy-mode");
  846. phy_type = of_usb_get_phy_mode(np);
  847. switch (phy_type) {
  848. case USBPHY_INTERFACE_MODE_UTMI:
  849. err = utmi_phy_probe(tegra_phy, pdev);
  850. if (err < 0)
  851. return err;
  852. break;
  853. case USBPHY_INTERFACE_MODE_ULPI:
  854. tegra_phy->is_ulpi_phy = true;
  855. tegra_phy->reset_gpio =
  856. of_get_named_gpio(np, "nvidia,phy-reset-gpio", 0);
  857. if (!gpio_is_valid(tegra_phy->reset_gpio)) {
  858. dev_err(&pdev->dev, "invalid gpio: %d\n",
  859. tegra_phy->reset_gpio);
  860. return tegra_phy->reset_gpio;
  861. }
  862. tegra_phy->config = NULL;
  863. break;
  864. default:
  865. dev_err(&pdev->dev, "phy_type is invalid or unsupported\n");
  866. return -EINVAL;
  867. }
  868. if (of_find_property(np, "dr_mode", NULL))
  869. tegra_phy->mode = usb_get_dr_mode(&pdev->dev);
  870. else
  871. tegra_phy->mode = USB_DR_MODE_HOST;
  872. if (tegra_phy->mode == USB_DR_MODE_UNKNOWN) {
  873. dev_err(&pdev->dev, "dr_mode is invalid\n");
  874. return -EINVAL;
  875. }
  876. /* On some boards, the VBUS regulator doesn't need to be controlled */
  877. if (of_find_property(np, "vbus-supply", NULL)) {
  878. tegra_phy->vbus = devm_regulator_get(&pdev->dev, "vbus");
  879. if (IS_ERR(tegra_phy->vbus))
  880. return PTR_ERR(tegra_phy->vbus);
  881. } else {
  882. dev_notice(&pdev->dev, "no vbus regulator");
  883. tegra_phy->vbus = ERR_PTR(-ENODEV);
  884. }
  885. tegra_phy->u_phy.dev = &pdev->dev;
  886. err = tegra_usb_phy_init(tegra_phy);
  887. if (err < 0)
  888. return err;
  889. tegra_phy->u_phy.set_suspend = tegra_usb_phy_suspend;
  890. platform_set_drvdata(pdev, tegra_phy);
  891. err = usb_add_phy_dev(&tegra_phy->u_phy);
  892. if (err < 0) {
  893. tegra_usb_phy_close(tegra_phy);
  894. return err;
  895. }
  896. return 0;
  897. }
  898. static int tegra_usb_phy_remove(struct platform_device *pdev)
  899. {
  900. struct tegra_usb_phy *tegra_phy = platform_get_drvdata(pdev);
  901. usb_remove_phy(&tegra_phy->u_phy);
  902. tegra_usb_phy_close(tegra_phy);
  903. return 0;
  904. }
  905. static struct platform_driver tegra_usb_phy_driver = {
  906. .probe = tegra_usb_phy_probe,
  907. .remove = tegra_usb_phy_remove,
  908. .driver = {
  909. .name = "tegra-phy",
  910. .of_match_table = tegra_usb_phy_id_table,
  911. },
  912. };
  913. module_platform_driver(tegra_usb_phy_driver);
  914. MODULE_DESCRIPTION("Tegra USB PHY driver");
  915. MODULE_LICENSE("GPL v2");