phy-exynos5-usbdrd.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * Samsung EXYNOS5 SoC series USB DRD PHY driver
  3. *
  4. * Phy provider for USB 3.0 DRD controller on Exynos5 SoC series
  5. *
  6. * Copyright (C) 2014 Samsung Electronics Co., Ltd.
  7. * Author: Vivek Gautam <gautam.vivek@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/delay.h>
  15. #include <linux/io.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/phy/phy.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/mutex.h>
  23. #include <linux/mfd/syscon.h>
  24. #include <linux/mfd/syscon/exynos5-pmu.h>
  25. #include <linux/regmap.h>
  26. #include <linux/regulator/consumer.h>
  27. /* Exynos USB PHY registers */
  28. #define EXYNOS5_FSEL_9MHZ6 0x0
  29. #define EXYNOS5_FSEL_10MHZ 0x1
  30. #define EXYNOS5_FSEL_12MHZ 0x2
  31. #define EXYNOS5_FSEL_19MHZ2 0x3
  32. #define EXYNOS5_FSEL_20MHZ 0x4
  33. #define EXYNOS5_FSEL_24MHZ 0x5
  34. #define EXYNOS5_FSEL_50MHZ 0x7
  35. /* EXYNOS5: USB 3.0 DRD PHY registers */
  36. #define EXYNOS5_DRD_LINKSYSTEM 0x04
  37. #define LINKSYSTEM_FLADJ_MASK (0x3f << 1)
  38. #define LINKSYSTEM_FLADJ(_x) ((_x) << 1)
  39. #define LINKSYSTEM_XHCI_VERSION_CONTROL BIT(27)
  40. #define EXYNOS5_DRD_PHYUTMI 0x08
  41. #define PHYUTMI_OTGDISABLE BIT(6)
  42. #define PHYUTMI_FORCESUSPEND BIT(1)
  43. #define PHYUTMI_FORCESLEEP BIT(0)
  44. #define EXYNOS5_DRD_PHYPIPE 0x0c
  45. #define EXYNOS5_DRD_PHYCLKRST 0x10
  46. #define PHYCLKRST_EN_UTMISUSPEND BIT(31)
  47. #define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23)
  48. #define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23)
  49. #define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21)
  50. #define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21)
  51. #define PHYCLKRST_SSC_EN BIT(20)
  52. #define PHYCLKRST_REF_SSP_EN BIT(19)
  53. #define PHYCLKRST_REF_CLKDIV2 BIT(18)
  54. #define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11)
  55. #define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11)
  56. #define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x32 << 11)
  57. #define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11)
  58. #define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11)
  59. #define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11)
  60. #define PHYCLKRST_FSEL_UTMI_MASK (0x7 << 5)
  61. #define PHYCLKRST_FSEL_PIPE_MASK (0x7 << 8)
  62. #define PHYCLKRST_FSEL(_x) ((_x) << 5)
  63. #define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5)
  64. #define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5)
  65. #define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5)
  66. #define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5)
  67. #define PHYCLKRST_RETENABLEN BIT(4)
  68. #define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2)
  69. #define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2)
  70. #define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2)
  71. #define PHYCLKRST_PORTRESET BIT(1)
  72. #define PHYCLKRST_COMMONONN BIT(0)
  73. #define EXYNOS5_DRD_PHYREG0 0x14
  74. #define EXYNOS5_DRD_PHYREG1 0x18
  75. #define EXYNOS5_DRD_PHYPARAM0 0x1c
  76. #define PHYPARAM0_REF_USE_PAD BIT(31)
  77. #define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26)
  78. #define PHYPARAM0_REF_LOSLEVEL (0x9 << 26)
  79. #define EXYNOS5_DRD_PHYPARAM1 0x20
  80. #define PHYPARAM1_PCS_TXDEEMPH_MASK (0x1f << 0)
  81. #define PHYPARAM1_PCS_TXDEEMPH (0x1c)
  82. #define EXYNOS5_DRD_PHYTERM 0x24
  83. #define EXYNOS5_DRD_PHYTEST 0x28
  84. #define PHYTEST_POWERDOWN_SSP BIT(3)
  85. #define PHYTEST_POWERDOWN_HSP BIT(2)
  86. #define EXYNOS5_DRD_PHYADP 0x2c
  87. #define EXYNOS5_DRD_PHYUTMICLKSEL 0x30
  88. #define PHYUTMICLKSEL_UTMI_CLKSEL BIT(2)
  89. #define EXYNOS5_DRD_PHYRESUME 0x34
  90. #define EXYNOS5_DRD_LINKPORT 0x44
  91. #define KHZ 1000
  92. #define MHZ (KHZ * KHZ)
  93. enum exynos5_usbdrd_phy_id {
  94. EXYNOS5_DRDPHY_UTMI,
  95. EXYNOS5_DRDPHY_PIPE3,
  96. EXYNOS5_DRDPHYS_NUM,
  97. };
  98. struct phy_usb_instance;
  99. struct exynos5_usbdrd_phy;
  100. struct exynos5_usbdrd_phy_config {
  101. u32 id;
  102. void (*phy_isol)(struct phy_usb_instance *inst, u32 on);
  103. void (*phy_init)(struct exynos5_usbdrd_phy *phy_drd);
  104. unsigned int (*set_refclk)(struct phy_usb_instance *inst);
  105. };
  106. struct exynos5_usbdrd_phy_drvdata {
  107. const struct exynos5_usbdrd_phy_config *phy_cfg;
  108. u32 pmu_offset_usbdrd0_phy;
  109. u32 pmu_offset_usbdrd1_phy;
  110. bool has_common_clk_gate;
  111. };
  112. /**
  113. * struct exynos5_usbdrd_phy - driver data for USB 3.0 PHY
  114. * @dev: pointer to device instance of this platform device
  115. * @reg_phy: usb phy controller register memory base
  116. * @clk: phy clock for register access
  117. * @pipeclk: clock for pipe3 phy
  118. * @utmiclk: clock for utmi+ phy
  119. * @itpclk: clock for ITP generation
  120. * @drv_data: pointer to SoC level driver data structure
  121. * @phys[]: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY
  122. * instances each with its 'phy' and 'phy_cfg'.
  123. * @extrefclk: frequency select settings when using 'separate
  124. * reference clocks' for SS and HS operations
  125. * @ref_clk: reference clock to PHY block from which PHY's
  126. * operational clocks are derived
  127. * vbus: VBUS regulator for phy
  128. * vbus_boost: Boost regulator for VBUS present on few Exynos boards
  129. */
  130. struct exynos5_usbdrd_phy {
  131. struct device *dev;
  132. void __iomem *reg_phy;
  133. struct clk *clk;
  134. struct clk *pipeclk;
  135. struct clk *utmiclk;
  136. struct clk *itpclk;
  137. const struct exynos5_usbdrd_phy_drvdata *drv_data;
  138. struct phy_usb_instance {
  139. struct phy *phy;
  140. u32 index;
  141. struct regmap *reg_pmu;
  142. u32 pmu_offset;
  143. const struct exynos5_usbdrd_phy_config *phy_cfg;
  144. } phys[EXYNOS5_DRDPHYS_NUM];
  145. u32 extrefclk;
  146. struct clk *ref_clk;
  147. struct regulator *vbus;
  148. struct regulator *vbus_boost;
  149. };
  150. static inline
  151. struct exynos5_usbdrd_phy *to_usbdrd_phy(struct phy_usb_instance *inst)
  152. {
  153. return container_of((inst), struct exynos5_usbdrd_phy,
  154. phys[(inst)->index]);
  155. }
  156. /*
  157. * exynos5_rate_to_clk() converts the supplied clock rate to the value that
  158. * can be written to the phy register.
  159. */
  160. static unsigned int exynos5_rate_to_clk(unsigned long rate, u32 *reg)
  161. {
  162. /* EXYNOS5_FSEL_MASK */
  163. switch (rate) {
  164. case 9600 * KHZ:
  165. *reg = EXYNOS5_FSEL_9MHZ6;
  166. break;
  167. case 10 * MHZ:
  168. *reg = EXYNOS5_FSEL_10MHZ;
  169. break;
  170. case 12 * MHZ:
  171. *reg = EXYNOS5_FSEL_12MHZ;
  172. break;
  173. case 19200 * KHZ:
  174. *reg = EXYNOS5_FSEL_19MHZ2;
  175. break;
  176. case 20 * MHZ:
  177. *reg = EXYNOS5_FSEL_20MHZ;
  178. break;
  179. case 24 * MHZ:
  180. *reg = EXYNOS5_FSEL_24MHZ;
  181. break;
  182. case 50 * MHZ:
  183. *reg = EXYNOS5_FSEL_50MHZ;
  184. break;
  185. default:
  186. return -EINVAL;
  187. }
  188. return 0;
  189. }
  190. static void exynos5_usbdrd_phy_isol(struct phy_usb_instance *inst,
  191. unsigned int on)
  192. {
  193. unsigned int val;
  194. if (!inst->reg_pmu)
  195. return;
  196. val = on ? 0 : EXYNOS5_PHY_ENABLE;
  197. regmap_update_bits(inst->reg_pmu, inst->pmu_offset,
  198. EXYNOS5_PHY_ENABLE, val);
  199. }
  200. /*
  201. * Sets the pipe3 phy's clk as EXTREFCLK (XXTI) which is internal clock
  202. * from clock core. Further sets multiplier values and spread spectrum
  203. * clock settings for SuperSpeed operations.
  204. */
  205. static unsigned int
  206. exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst)
  207. {
  208. static u32 reg;
  209. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  210. /* restore any previous reference clock settings */
  211. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  212. /* Use EXTREFCLK as ref clock */
  213. reg &= ~PHYCLKRST_REFCLKSEL_MASK;
  214. reg |= PHYCLKRST_REFCLKSEL_EXT_REFCLK;
  215. /* FSEL settings corresponding to reference clock */
  216. reg &= ~PHYCLKRST_FSEL_PIPE_MASK |
  217. PHYCLKRST_MPLL_MULTIPLIER_MASK |
  218. PHYCLKRST_SSC_REFCLKSEL_MASK;
  219. switch (phy_drd->extrefclk) {
  220. case EXYNOS5_FSEL_50MHZ:
  221. reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF |
  222. PHYCLKRST_SSC_REFCLKSEL(0x00));
  223. break;
  224. case EXYNOS5_FSEL_24MHZ:
  225. reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF |
  226. PHYCLKRST_SSC_REFCLKSEL(0x88));
  227. break;
  228. case EXYNOS5_FSEL_20MHZ:
  229. reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF |
  230. PHYCLKRST_SSC_REFCLKSEL(0x00));
  231. break;
  232. case EXYNOS5_FSEL_19MHZ2:
  233. reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF |
  234. PHYCLKRST_SSC_REFCLKSEL(0x88));
  235. break;
  236. default:
  237. dev_dbg(phy_drd->dev, "unsupported ref clk\n");
  238. break;
  239. }
  240. return reg;
  241. }
  242. /*
  243. * Sets the utmi phy's clk as EXTREFCLK (XXTI) which is internal clock
  244. * from clock core. Further sets the FSEL values for HighSpeed operations.
  245. */
  246. static unsigned int
  247. exynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance *inst)
  248. {
  249. static u32 reg;
  250. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  251. /* restore any previous reference clock settings */
  252. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  253. reg &= ~PHYCLKRST_REFCLKSEL_MASK;
  254. reg |= PHYCLKRST_REFCLKSEL_EXT_REFCLK;
  255. reg &= ~PHYCLKRST_FSEL_UTMI_MASK |
  256. PHYCLKRST_MPLL_MULTIPLIER_MASK |
  257. PHYCLKRST_SSC_REFCLKSEL_MASK;
  258. reg |= PHYCLKRST_FSEL(phy_drd->extrefclk);
  259. return reg;
  260. }
  261. static void exynos5_usbdrd_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
  262. {
  263. u32 reg;
  264. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  265. /* Set Tx De-Emphasis level */
  266. reg &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
  267. reg |= PHYPARAM1_PCS_TXDEEMPH;
  268. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  269. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  270. reg &= ~PHYTEST_POWERDOWN_SSP;
  271. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  272. }
  273. static void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  274. {
  275. u32 reg;
  276. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  277. /* Set Loss-of-Signal Detector sensitivity */
  278. reg &= ~PHYPARAM0_REF_LOSLEVEL_MASK;
  279. reg |= PHYPARAM0_REF_LOSLEVEL;
  280. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  281. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  282. /* Set Tx De-Emphasis level */
  283. reg &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
  284. reg |= PHYPARAM1_PCS_TXDEEMPH;
  285. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  286. /* UTMI Power Control */
  287. writel(PHYUTMI_OTGDISABLE, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  288. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  289. reg &= ~PHYTEST_POWERDOWN_HSP;
  290. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  291. }
  292. static int exynos5_usbdrd_phy_init(struct phy *phy)
  293. {
  294. int ret;
  295. u32 reg;
  296. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  297. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  298. ret = clk_prepare_enable(phy_drd->clk);
  299. if (ret)
  300. return ret;
  301. /* Reset USB 3.0 PHY */
  302. writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  303. writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYRESUME);
  304. /*
  305. * Setting the Frame length Adj value[6:1] to default 0x20
  306. * See xHCI 1.0 spec, 5.2.4
  307. */
  308. reg = LINKSYSTEM_XHCI_VERSION_CONTROL |
  309. LINKSYSTEM_FLADJ(0x20);
  310. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  311. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  312. /* Select PHY CLK source */
  313. reg &= ~PHYPARAM0_REF_USE_PAD;
  314. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  315. /* This bit must be set for both HS and SS operations */
  316. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
  317. reg |= PHYUTMICLKSEL_UTMI_CLKSEL;
  318. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
  319. /* UTMI or PIPE3 specific init */
  320. inst->phy_cfg->phy_init(phy_drd);
  321. /* reference clock settings */
  322. reg = inst->phy_cfg->set_refclk(inst);
  323. /* Digital power supply in normal operating mode */
  324. reg |= PHYCLKRST_RETENABLEN |
  325. /* Enable ref clock for SS function */
  326. PHYCLKRST_REF_SSP_EN |
  327. /* Enable spread spectrum */
  328. PHYCLKRST_SSC_EN |
  329. /* Power down HS Bias and PLL blocks in suspend mode */
  330. PHYCLKRST_COMMONONN |
  331. /* Reset the port */
  332. PHYCLKRST_PORTRESET;
  333. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  334. udelay(10);
  335. reg &= ~PHYCLKRST_PORTRESET;
  336. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  337. clk_disable_unprepare(phy_drd->clk);
  338. return 0;
  339. }
  340. static int exynos5_usbdrd_phy_exit(struct phy *phy)
  341. {
  342. int ret;
  343. u32 reg;
  344. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  345. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  346. ret = clk_prepare_enable(phy_drd->clk);
  347. if (ret)
  348. return ret;
  349. reg = PHYUTMI_OTGDISABLE |
  350. PHYUTMI_FORCESUSPEND |
  351. PHYUTMI_FORCESLEEP;
  352. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  353. /* Resetting the PHYCLKRST enable bits to reduce leakage current */
  354. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  355. reg &= ~(PHYCLKRST_REF_SSP_EN |
  356. PHYCLKRST_SSC_EN |
  357. PHYCLKRST_COMMONONN);
  358. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  359. /* Control PHYTEST to remove leakage current */
  360. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  361. reg |= PHYTEST_POWERDOWN_SSP |
  362. PHYTEST_POWERDOWN_HSP;
  363. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  364. clk_disable_unprepare(phy_drd->clk);
  365. return 0;
  366. }
  367. static int exynos5_usbdrd_phy_power_on(struct phy *phy)
  368. {
  369. int ret;
  370. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  371. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  372. dev_dbg(phy_drd->dev, "Request to power_on usbdrd_phy phy\n");
  373. clk_prepare_enable(phy_drd->ref_clk);
  374. if (!phy_drd->drv_data->has_common_clk_gate) {
  375. clk_prepare_enable(phy_drd->pipeclk);
  376. clk_prepare_enable(phy_drd->utmiclk);
  377. clk_prepare_enable(phy_drd->itpclk);
  378. }
  379. /* Enable VBUS supply */
  380. if (phy_drd->vbus_boost) {
  381. ret = regulator_enable(phy_drd->vbus_boost);
  382. if (ret) {
  383. dev_err(phy_drd->dev,
  384. "Failed to enable VBUS boost supply\n");
  385. goto fail_vbus;
  386. }
  387. }
  388. if (phy_drd->vbus) {
  389. ret = regulator_enable(phy_drd->vbus);
  390. if (ret) {
  391. dev_err(phy_drd->dev, "Failed to enable VBUS supply\n");
  392. goto fail_vbus_boost;
  393. }
  394. }
  395. /* Power-on PHY*/
  396. inst->phy_cfg->phy_isol(inst, 0);
  397. return 0;
  398. fail_vbus_boost:
  399. if (phy_drd->vbus_boost)
  400. regulator_disable(phy_drd->vbus_boost);
  401. fail_vbus:
  402. clk_disable_unprepare(phy_drd->ref_clk);
  403. if (!phy_drd->drv_data->has_common_clk_gate) {
  404. clk_disable_unprepare(phy_drd->itpclk);
  405. clk_disable_unprepare(phy_drd->utmiclk);
  406. clk_disable_unprepare(phy_drd->pipeclk);
  407. }
  408. return ret;
  409. }
  410. static int exynos5_usbdrd_phy_power_off(struct phy *phy)
  411. {
  412. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  413. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  414. dev_dbg(phy_drd->dev, "Request to power_off usbdrd_phy phy\n");
  415. /* Power-off the PHY */
  416. inst->phy_cfg->phy_isol(inst, 1);
  417. /* Disable VBUS supply */
  418. if (phy_drd->vbus)
  419. regulator_disable(phy_drd->vbus);
  420. if (phy_drd->vbus_boost)
  421. regulator_disable(phy_drd->vbus_boost);
  422. clk_disable_unprepare(phy_drd->ref_clk);
  423. if (!phy_drd->drv_data->has_common_clk_gate) {
  424. clk_disable_unprepare(phy_drd->itpclk);
  425. clk_disable_unprepare(phy_drd->pipeclk);
  426. clk_disable_unprepare(phy_drd->utmiclk);
  427. }
  428. return 0;
  429. }
  430. static struct phy *exynos5_usbdrd_phy_xlate(struct device *dev,
  431. struct of_phandle_args *args)
  432. {
  433. struct exynos5_usbdrd_phy *phy_drd = dev_get_drvdata(dev);
  434. if (WARN_ON(args->args[0] >= EXYNOS5_DRDPHYS_NUM))
  435. return ERR_PTR(-ENODEV);
  436. return phy_drd->phys[args->args[0]].phy;
  437. }
  438. static const struct phy_ops exynos5_usbdrd_phy_ops = {
  439. .init = exynos5_usbdrd_phy_init,
  440. .exit = exynos5_usbdrd_phy_exit,
  441. .power_on = exynos5_usbdrd_phy_power_on,
  442. .power_off = exynos5_usbdrd_phy_power_off,
  443. .owner = THIS_MODULE,
  444. };
  445. static int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy *phy_drd)
  446. {
  447. unsigned long ref_rate;
  448. int ret;
  449. phy_drd->clk = devm_clk_get(phy_drd->dev, "phy");
  450. if (IS_ERR(phy_drd->clk)) {
  451. dev_err(phy_drd->dev, "Failed to get phy clock\n");
  452. return PTR_ERR(phy_drd->clk);
  453. }
  454. phy_drd->ref_clk = devm_clk_get(phy_drd->dev, "ref");
  455. if (IS_ERR(phy_drd->ref_clk)) {
  456. dev_err(phy_drd->dev, "Failed to get phy reference clock\n");
  457. return PTR_ERR(phy_drd->ref_clk);
  458. }
  459. ref_rate = clk_get_rate(phy_drd->ref_clk);
  460. ret = exynos5_rate_to_clk(ref_rate, &phy_drd->extrefclk);
  461. if (ret) {
  462. dev_err(phy_drd->dev, "Clock rate (%ld) not supported\n",
  463. ref_rate);
  464. return ret;
  465. }
  466. if (!phy_drd->drv_data->has_common_clk_gate) {
  467. phy_drd->pipeclk = devm_clk_get(phy_drd->dev, "phy_pipe");
  468. if (IS_ERR(phy_drd->pipeclk)) {
  469. dev_info(phy_drd->dev,
  470. "PIPE3 phy operational clock not specified\n");
  471. phy_drd->pipeclk = NULL;
  472. }
  473. phy_drd->utmiclk = devm_clk_get(phy_drd->dev, "phy_utmi");
  474. if (IS_ERR(phy_drd->utmiclk)) {
  475. dev_info(phy_drd->dev,
  476. "UTMI phy operational clock not specified\n");
  477. phy_drd->utmiclk = NULL;
  478. }
  479. phy_drd->itpclk = devm_clk_get(phy_drd->dev, "itp");
  480. if (IS_ERR(phy_drd->itpclk)) {
  481. dev_info(phy_drd->dev,
  482. "ITP clock from main OSC not specified\n");
  483. phy_drd->itpclk = NULL;
  484. }
  485. }
  486. return 0;
  487. }
  488. static const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = {
  489. {
  490. .id = EXYNOS5_DRDPHY_UTMI,
  491. .phy_isol = exynos5_usbdrd_phy_isol,
  492. .phy_init = exynos5_usbdrd_utmi_init,
  493. .set_refclk = exynos5_usbdrd_utmi_set_refclk,
  494. },
  495. {
  496. .id = EXYNOS5_DRDPHY_PIPE3,
  497. .phy_isol = exynos5_usbdrd_phy_isol,
  498. .phy_init = exynos5_usbdrd_pipe3_init,
  499. .set_refclk = exynos5_usbdrd_pipe3_set_refclk,
  500. },
  501. };
  502. static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
  503. .phy_cfg = phy_cfg_exynos5,
  504. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  505. .pmu_offset_usbdrd1_phy = EXYNOS5420_USBDRD1_PHY_CONTROL,
  506. .has_common_clk_gate = true,
  507. };
  508. static const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
  509. .phy_cfg = phy_cfg_exynos5,
  510. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  511. .has_common_clk_gate = true,
  512. };
  513. static const struct exynos5_usbdrd_phy_drvdata exynos5433_usbdrd_phy = {
  514. .phy_cfg = phy_cfg_exynos5,
  515. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  516. .pmu_offset_usbdrd1_phy = EXYNOS5433_USBHOST30_PHY_CONTROL,
  517. .has_common_clk_gate = false,
  518. };
  519. static const struct exynos5_usbdrd_phy_drvdata exynos7_usbdrd_phy = {
  520. .phy_cfg = phy_cfg_exynos5,
  521. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  522. .has_common_clk_gate = false,
  523. };
  524. static const struct of_device_id exynos5_usbdrd_phy_of_match[] = {
  525. {
  526. .compatible = "samsung,exynos5250-usbdrd-phy",
  527. .data = &exynos5250_usbdrd_phy
  528. }, {
  529. .compatible = "samsung,exynos5420-usbdrd-phy",
  530. .data = &exynos5420_usbdrd_phy
  531. }, {
  532. .compatible = "samsung,exynos5433-usbdrd-phy",
  533. .data = &exynos5433_usbdrd_phy
  534. }, {
  535. .compatible = "samsung,exynos7-usbdrd-phy",
  536. .data = &exynos7_usbdrd_phy
  537. },
  538. { },
  539. };
  540. MODULE_DEVICE_TABLE(of, exynos5_usbdrd_phy_of_match);
  541. static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
  542. {
  543. struct device *dev = &pdev->dev;
  544. struct device_node *node = dev->of_node;
  545. struct exynos5_usbdrd_phy *phy_drd;
  546. struct phy_provider *phy_provider;
  547. struct resource *res;
  548. const struct of_device_id *match;
  549. const struct exynos5_usbdrd_phy_drvdata *drv_data;
  550. struct regmap *reg_pmu;
  551. u32 pmu_offset;
  552. int i, ret;
  553. int channel;
  554. phy_drd = devm_kzalloc(dev, sizeof(*phy_drd), GFP_KERNEL);
  555. if (!phy_drd)
  556. return -ENOMEM;
  557. dev_set_drvdata(dev, phy_drd);
  558. phy_drd->dev = dev;
  559. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  560. phy_drd->reg_phy = devm_ioremap_resource(dev, res);
  561. if (IS_ERR(phy_drd->reg_phy))
  562. return PTR_ERR(phy_drd->reg_phy);
  563. match = of_match_node(exynos5_usbdrd_phy_of_match, pdev->dev.of_node);
  564. drv_data = match->data;
  565. phy_drd->drv_data = drv_data;
  566. ret = exynos5_usbdrd_phy_clk_handle(phy_drd);
  567. if (ret) {
  568. dev_err(dev, "Failed to initialize clocks\n");
  569. return ret;
  570. }
  571. reg_pmu = syscon_regmap_lookup_by_phandle(dev->of_node,
  572. "samsung,pmu-syscon");
  573. if (IS_ERR(reg_pmu)) {
  574. dev_err(dev, "Failed to lookup PMU regmap\n");
  575. return PTR_ERR(reg_pmu);
  576. }
  577. /*
  578. * Exynos5420 SoC has multiple channels for USB 3.0 PHY, with
  579. * each having separate power control registers.
  580. * 'channel' facilitates to set such registers.
  581. */
  582. channel = of_alias_get_id(node, "usbdrdphy");
  583. if (channel < 0)
  584. dev_dbg(dev, "Not a multi-controller usbdrd phy\n");
  585. switch (channel) {
  586. case 1:
  587. pmu_offset = phy_drd->drv_data->pmu_offset_usbdrd1_phy;
  588. break;
  589. case 0:
  590. default:
  591. pmu_offset = phy_drd->drv_data->pmu_offset_usbdrd0_phy;
  592. break;
  593. }
  594. /* Get Vbus regulators */
  595. phy_drd->vbus = devm_regulator_get(dev, "vbus");
  596. if (IS_ERR(phy_drd->vbus)) {
  597. ret = PTR_ERR(phy_drd->vbus);
  598. if (ret == -EPROBE_DEFER)
  599. return ret;
  600. dev_warn(dev, "Failed to get VBUS supply regulator\n");
  601. phy_drd->vbus = NULL;
  602. }
  603. phy_drd->vbus_boost = devm_regulator_get(dev, "vbus-boost");
  604. if (IS_ERR(phy_drd->vbus_boost)) {
  605. ret = PTR_ERR(phy_drd->vbus_boost);
  606. if (ret == -EPROBE_DEFER)
  607. return ret;
  608. dev_warn(dev, "Failed to get VBUS boost supply regulator\n");
  609. phy_drd->vbus_boost = NULL;
  610. }
  611. dev_vdbg(dev, "Creating usbdrd_phy phy\n");
  612. for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) {
  613. struct phy *phy = devm_phy_create(dev, NULL,
  614. &exynos5_usbdrd_phy_ops);
  615. if (IS_ERR(phy)) {
  616. dev_err(dev, "Failed to create usbdrd_phy phy\n");
  617. return PTR_ERR(phy);
  618. }
  619. phy_drd->phys[i].phy = phy;
  620. phy_drd->phys[i].index = i;
  621. phy_drd->phys[i].reg_pmu = reg_pmu;
  622. phy_drd->phys[i].pmu_offset = pmu_offset;
  623. phy_drd->phys[i].phy_cfg = &drv_data->phy_cfg[i];
  624. phy_set_drvdata(phy, &phy_drd->phys[i]);
  625. }
  626. phy_provider = devm_of_phy_provider_register(dev,
  627. exynos5_usbdrd_phy_xlate);
  628. if (IS_ERR(phy_provider)) {
  629. dev_err(phy_drd->dev, "Failed to register phy provider\n");
  630. return PTR_ERR(phy_provider);
  631. }
  632. return 0;
  633. }
  634. static struct platform_driver exynos5_usb3drd_phy = {
  635. .probe = exynos5_usbdrd_phy_probe,
  636. .driver = {
  637. .of_match_table = exynos5_usbdrd_phy_of_match,
  638. .name = "exynos5_usb3drd_phy",
  639. }
  640. };
  641. module_platform_driver(exynos5_usb3drd_phy);
  642. MODULE_DESCRIPTION("Samsung EXYNOS5 SoCs USB 3.0 DRD controller PHY driver");
  643. MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
  644. MODULE_LICENSE("GPL v2");
  645. MODULE_ALIAS("platform:exynos5_usb3drd_phy");