phy-exynos5-usbdrd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. };
  111. /**
  112. * struct exynos5_usbdrd_phy - driver data for USB 3.0 PHY
  113. * @dev: pointer to device instance of this platform device
  114. * @reg_phy: usb phy controller register memory base
  115. * @clk: phy clock for register access
  116. * @drv_data: pointer to SoC level driver data structure
  117. * @phys[]: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY
  118. * instances each with its 'phy' and 'phy_cfg'.
  119. * @extrefclk: frequency select settings when using 'separate
  120. * reference clocks' for SS and HS operations
  121. * @ref_clk: reference clock to PHY block from which PHY's
  122. * operational clocks are derived
  123. * @ref_rate: rate of above reference clock
  124. */
  125. struct exynos5_usbdrd_phy {
  126. struct device *dev;
  127. void __iomem *reg_phy;
  128. struct clk *clk;
  129. const struct exynos5_usbdrd_phy_drvdata *drv_data;
  130. struct phy_usb_instance {
  131. struct phy *phy;
  132. u32 index;
  133. struct regmap *reg_pmu;
  134. u32 pmu_offset;
  135. const struct exynos5_usbdrd_phy_config *phy_cfg;
  136. } phys[EXYNOS5_DRDPHYS_NUM];
  137. u32 extrefclk;
  138. struct clk *ref_clk;
  139. struct regulator *vbus;
  140. };
  141. static inline
  142. struct exynos5_usbdrd_phy *to_usbdrd_phy(struct phy_usb_instance *inst)
  143. {
  144. return container_of((inst), struct exynos5_usbdrd_phy,
  145. phys[(inst)->index]);
  146. }
  147. /*
  148. * exynos5_rate_to_clk() converts the supplied clock rate to the value that
  149. * can be written to the phy register.
  150. */
  151. static unsigned int exynos5_rate_to_clk(unsigned long rate, u32 *reg)
  152. {
  153. /* EXYNOS5_FSEL_MASK */
  154. switch (rate) {
  155. case 9600 * KHZ:
  156. *reg = EXYNOS5_FSEL_9MHZ6;
  157. break;
  158. case 10 * MHZ:
  159. *reg = EXYNOS5_FSEL_10MHZ;
  160. break;
  161. case 12 * MHZ:
  162. *reg = EXYNOS5_FSEL_12MHZ;
  163. break;
  164. case 19200 * KHZ:
  165. *reg = EXYNOS5_FSEL_19MHZ2;
  166. break;
  167. case 20 * MHZ:
  168. *reg = EXYNOS5_FSEL_20MHZ;
  169. break;
  170. case 24 * MHZ:
  171. *reg = EXYNOS5_FSEL_24MHZ;
  172. break;
  173. case 50 * MHZ:
  174. *reg = EXYNOS5_FSEL_50MHZ;
  175. break;
  176. default:
  177. return -EINVAL;
  178. }
  179. return 0;
  180. }
  181. static void exynos5_usbdrd_phy_isol(struct phy_usb_instance *inst,
  182. unsigned int on)
  183. {
  184. unsigned int val;
  185. if (!inst->reg_pmu)
  186. return;
  187. val = on ? 0 : EXYNOS5_PHY_ENABLE;
  188. regmap_update_bits(inst->reg_pmu, inst->pmu_offset,
  189. EXYNOS5_PHY_ENABLE, val);
  190. }
  191. /*
  192. * Sets the pipe3 phy's clk as EXTREFCLK (XXTI) which is internal clock
  193. * from clock core. Further sets multiplier values and spread spectrum
  194. * clock settings for SuperSpeed operations.
  195. */
  196. static unsigned int
  197. exynos5_usbdrd_pipe3_set_refclk(struct phy_usb_instance *inst)
  198. {
  199. static u32 reg;
  200. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  201. /* restore any previous reference clock settings */
  202. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  203. /* Use EXTREFCLK as ref clock */
  204. reg &= ~PHYCLKRST_REFCLKSEL_MASK;
  205. reg |= PHYCLKRST_REFCLKSEL_EXT_REFCLK;
  206. /* FSEL settings corresponding to reference clock */
  207. reg &= ~PHYCLKRST_FSEL_PIPE_MASK |
  208. PHYCLKRST_MPLL_MULTIPLIER_MASK |
  209. PHYCLKRST_SSC_REFCLKSEL_MASK;
  210. switch (phy_drd->extrefclk) {
  211. case EXYNOS5_FSEL_50MHZ:
  212. reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF |
  213. PHYCLKRST_SSC_REFCLKSEL(0x00));
  214. break;
  215. case EXYNOS5_FSEL_24MHZ:
  216. reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF |
  217. PHYCLKRST_SSC_REFCLKSEL(0x88));
  218. break;
  219. case EXYNOS5_FSEL_20MHZ:
  220. reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF |
  221. PHYCLKRST_SSC_REFCLKSEL(0x00));
  222. break;
  223. case EXYNOS5_FSEL_19MHZ2:
  224. reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF |
  225. PHYCLKRST_SSC_REFCLKSEL(0x88));
  226. break;
  227. default:
  228. dev_dbg(phy_drd->dev, "unsupported ref clk\n");
  229. break;
  230. }
  231. return reg;
  232. }
  233. /*
  234. * Sets the utmi phy's clk as EXTREFCLK (XXTI) which is internal clock
  235. * from clock core. Further sets the FSEL values for HighSpeed operations.
  236. */
  237. static unsigned int
  238. exynos5_usbdrd_utmi_set_refclk(struct phy_usb_instance *inst)
  239. {
  240. static u32 reg;
  241. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  242. /* restore any previous reference clock settings */
  243. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  244. reg &= ~PHYCLKRST_REFCLKSEL_MASK;
  245. reg |= PHYCLKRST_REFCLKSEL_EXT_REFCLK;
  246. reg &= ~PHYCLKRST_FSEL_UTMI_MASK |
  247. PHYCLKRST_MPLL_MULTIPLIER_MASK |
  248. PHYCLKRST_SSC_REFCLKSEL_MASK;
  249. reg |= PHYCLKRST_FSEL(phy_drd->extrefclk);
  250. return reg;
  251. }
  252. static void exynos5_usbdrd_pipe3_init(struct exynos5_usbdrd_phy *phy_drd)
  253. {
  254. u32 reg;
  255. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  256. /* Set Tx De-Emphasis level */
  257. reg &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
  258. reg |= PHYPARAM1_PCS_TXDEEMPH;
  259. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  260. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  261. reg &= ~PHYTEST_POWERDOWN_SSP;
  262. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  263. }
  264. static void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)
  265. {
  266. u32 reg;
  267. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  268. /* Set Loss-of-Signal Detector sensitivity */
  269. reg &= ~PHYPARAM0_REF_LOSLEVEL_MASK;
  270. reg |= PHYPARAM0_REF_LOSLEVEL;
  271. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  272. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  273. /* Set Tx De-Emphasis level */
  274. reg &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
  275. reg |= PHYPARAM1_PCS_TXDEEMPH;
  276. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM1);
  277. /* UTMI Power Control */
  278. writel(PHYUTMI_OTGDISABLE, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  279. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  280. reg &= ~PHYTEST_POWERDOWN_HSP;
  281. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  282. }
  283. static int exynos5_usbdrd_phy_init(struct phy *phy)
  284. {
  285. int ret;
  286. u32 reg;
  287. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  288. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  289. ret = clk_prepare_enable(phy_drd->clk);
  290. if (ret)
  291. return ret;
  292. /* Reset USB 3.0 PHY */
  293. writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYREG0);
  294. writel(0x0, phy_drd->reg_phy + EXYNOS5_DRD_PHYRESUME);
  295. /*
  296. * Setting the Frame length Adj value[6:1] to default 0x20
  297. * See xHCI 1.0 spec, 5.2.4
  298. */
  299. reg = LINKSYSTEM_XHCI_VERSION_CONTROL |
  300. LINKSYSTEM_FLADJ(0x20);
  301. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_LINKSYSTEM);
  302. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  303. /* Select PHY CLK source */
  304. reg &= ~PHYPARAM0_REF_USE_PAD;
  305. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYPARAM0);
  306. /* This bit must be set for both HS and SS operations */
  307. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
  308. reg |= PHYUTMICLKSEL_UTMI_CLKSEL;
  309. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMICLKSEL);
  310. /* UTMI or PIPE3 specific init */
  311. inst->phy_cfg->phy_init(phy_drd);
  312. /* reference clock settings */
  313. reg = inst->phy_cfg->set_refclk(inst);
  314. /* Digital power supply in normal operating mode */
  315. reg |= PHYCLKRST_RETENABLEN |
  316. /* Enable ref clock for SS function */
  317. PHYCLKRST_REF_SSP_EN |
  318. /* Enable spread spectrum */
  319. PHYCLKRST_SSC_EN |
  320. /* Power down HS Bias and PLL blocks in suspend mode */
  321. PHYCLKRST_COMMONONN |
  322. /* Reset the port */
  323. PHYCLKRST_PORTRESET;
  324. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  325. udelay(10);
  326. reg &= ~PHYCLKRST_PORTRESET;
  327. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  328. clk_disable_unprepare(phy_drd->clk);
  329. return 0;
  330. }
  331. static int exynos5_usbdrd_phy_exit(struct phy *phy)
  332. {
  333. int ret;
  334. u32 reg;
  335. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  336. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  337. ret = clk_prepare_enable(phy_drd->clk);
  338. if (ret)
  339. return ret;
  340. reg = PHYUTMI_OTGDISABLE |
  341. PHYUTMI_FORCESUSPEND |
  342. PHYUTMI_FORCESLEEP;
  343. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYUTMI);
  344. /* Resetting the PHYCLKRST enable bits to reduce leakage current */
  345. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  346. reg &= ~(PHYCLKRST_REF_SSP_EN |
  347. PHYCLKRST_SSC_EN |
  348. PHYCLKRST_COMMONONN);
  349. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYCLKRST);
  350. /* Control PHYTEST to remove leakage current */
  351. reg = readl(phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  352. reg |= PHYTEST_POWERDOWN_SSP |
  353. PHYTEST_POWERDOWN_HSP;
  354. writel(reg, phy_drd->reg_phy + EXYNOS5_DRD_PHYTEST);
  355. clk_disable_unprepare(phy_drd->clk);
  356. return 0;
  357. }
  358. static int exynos5_usbdrd_phy_power_on(struct phy *phy)
  359. {
  360. int ret;
  361. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  362. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  363. dev_dbg(phy_drd->dev, "Request to power_on usbdrd_phy phy\n");
  364. clk_prepare_enable(phy_drd->ref_clk);
  365. /* Enable VBUS supply */
  366. if (phy_drd->vbus) {
  367. ret = regulator_enable(phy_drd->vbus);
  368. if (ret) {
  369. dev_err(phy_drd->dev, "Failed to enable VBUS supply\n");
  370. goto fail_vbus;
  371. }
  372. }
  373. /* Power-on PHY*/
  374. inst->phy_cfg->phy_isol(inst, 0);
  375. return 0;
  376. fail_vbus:
  377. clk_disable_unprepare(phy_drd->ref_clk);
  378. return ret;
  379. }
  380. static int exynos5_usbdrd_phy_power_off(struct phy *phy)
  381. {
  382. struct phy_usb_instance *inst = phy_get_drvdata(phy);
  383. struct exynos5_usbdrd_phy *phy_drd = to_usbdrd_phy(inst);
  384. dev_dbg(phy_drd->dev, "Request to power_off usbdrd_phy phy\n");
  385. /* Power-off the PHY */
  386. inst->phy_cfg->phy_isol(inst, 1);
  387. /* Disable VBUS supply */
  388. if (phy_drd->vbus)
  389. regulator_disable(phy_drd->vbus);
  390. clk_disable_unprepare(phy_drd->ref_clk);
  391. return 0;
  392. }
  393. static struct phy *exynos5_usbdrd_phy_xlate(struct device *dev,
  394. struct of_phandle_args *args)
  395. {
  396. struct exynos5_usbdrd_phy *phy_drd = dev_get_drvdata(dev);
  397. if (WARN_ON(args->args[0] > EXYNOS5_DRDPHYS_NUM))
  398. return ERR_PTR(-ENODEV);
  399. return phy_drd->phys[args->args[0]].phy;
  400. }
  401. static struct phy_ops exynos5_usbdrd_phy_ops = {
  402. .init = exynos5_usbdrd_phy_init,
  403. .exit = exynos5_usbdrd_phy_exit,
  404. .power_on = exynos5_usbdrd_phy_power_on,
  405. .power_off = exynos5_usbdrd_phy_power_off,
  406. .owner = THIS_MODULE,
  407. };
  408. const struct exynos5_usbdrd_phy_config phy_cfg_exynos5[] = {
  409. {
  410. .id = EXYNOS5_DRDPHY_UTMI,
  411. .phy_isol = exynos5_usbdrd_phy_isol,
  412. .phy_init = exynos5_usbdrd_utmi_init,
  413. .set_refclk = exynos5_usbdrd_utmi_set_refclk,
  414. },
  415. {
  416. .id = EXYNOS5_DRDPHY_PIPE3,
  417. .phy_isol = exynos5_usbdrd_phy_isol,
  418. .phy_init = exynos5_usbdrd_pipe3_init,
  419. .set_refclk = exynos5_usbdrd_pipe3_set_refclk,
  420. },
  421. };
  422. const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = {
  423. .phy_cfg = phy_cfg_exynos5,
  424. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  425. .pmu_offset_usbdrd1_phy = EXYNOS5420_USBDRD1_PHY_CONTROL,
  426. };
  427. const struct exynos5_usbdrd_phy_drvdata exynos5250_usbdrd_phy = {
  428. .phy_cfg = phy_cfg_exynos5,
  429. .pmu_offset_usbdrd0_phy = EXYNOS5_USBDRD_PHY_CONTROL,
  430. };
  431. static const struct of_device_id exynos5_usbdrd_phy_of_match[] = {
  432. {
  433. .compatible = "samsung,exynos5250-usbdrd-phy",
  434. .data = &exynos5250_usbdrd_phy
  435. }, {
  436. .compatible = "samsung,exynos5420-usbdrd-phy",
  437. .data = &exynos5420_usbdrd_phy
  438. },
  439. { },
  440. };
  441. static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)
  442. {
  443. struct device *dev = &pdev->dev;
  444. struct device_node *node = dev->of_node;
  445. struct exynos5_usbdrd_phy *phy_drd;
  446. struct phy_provider *phy_provider;
  447. struct resource *res;
  448. const struct of_device_id *match;
  449. const struct exynos5_usbdrd_phy_drvdata *drv_data;
  450. struct regmap *reg_pmu;
  451. u32 pmu_offset;
  452. unsigned long ref_rate;
  453. int i, ret;
  454. int channel;
  455. phy_drd = devm_kzalloc(dev, sizeof(*phy_drd), GFP_KERNEL);
  456. if (!phy_drd)
  457. return -ENOMEM;
  458. dev_set_drvdata(dev, phy_drd);
  459. phy_drd->dev = dev;
  460. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  461. phy_drd->reg_phy = devm_ioremap_resource(dev, res);
  462. if (IS_ERR(phy_drd->reg_phy))
  463. return PTR_ERR(phy_drd->reg_phy);
  464. match = of_match_node(exynos5_usbdrd_phy_of_match, pdev->dev.of_node);
  465. drv_data = match->data;
  466. phy_drd->drv_data = drv_data;
  467. phy_drd->clk = devm_clk_get(dev, "phy");
  468. if (IS_ERR(phy_drd->clk)) {
  469. dev_err(dev, "Failed to get clock of phy controller\n");
  470. return PTR_ERR(phy_drd->clk);
  471. }
  472. phy_drd->ref_clk = devm_clk_get(dev, "ref");
  473. if (IS_ERR(phy_drd->ref_clk)) {
  474. dev_err(dev, "Failed to get reference clock of usbdrd phy\n");
  475. return PTR_ERR(phy_drd->ref_clk);
  476. }
  477. ref_rate = clk_get_rate(phy_drd->ref_clk);
  478. ret = exynos5_rate_to_clk(ref_rate, &phy_drd->extrefclk);
  479. if (ret) {
  480. dev_err(phy_drd->dev, "Clock rate (%ld) not supported\n",
  481. ref_rate);
  482. return ret;
  483. }
  484. reg_pmu = syscon_regmap_lookup_by_phandle(dev->of_node,
  485. "samsung,pmu-syscon");
  486. if (IS_ERR(reg_pmu)) {
  487. dev_err(dev, "Failed to lookup PMU regmap\n");
  488. return PTR_ERR(reg_pmu);
  489. }
  490. /*
  491. * Exynos5420 SoC has multiple channels for USB 3.0 PHY, with
  492. * each having separate power control registers.
  493. * 'channel' facilitates to set such registers.
  494. */
  495. channel = of_alias_get_id(node, "usbdrdphy");
  496. if (channel < 0)
  497. dev_dbg(dev, "Not a multi-controller usbdrd phy\n");
  498. switch (channel) {
  499. case 1:
  500. pmu_offset = phy_drd->drv_data->pmu_offset_usbdrd1_phy;
  501. break;
  502. case 0:
  503. default:
  504. pmu_offset = phy_drd->drv_data->pmu_offset_usbdrd0_phy;
  505. break;
  506. }
  507. /* Get Vbus regulator */
  508. phy_drd->vbus = devm_regulator_get(dev, "vbus");
  509. if (IS_ERR(phy_drd->vbus)) {
  510. ret = PTR_ERR(phy_drd->vbus);
  511. if (ret == -EPROBE_DEFER)
  512. return ret;
  513. dev_warn(dev, "Failed to get VBUS supply regulator\n");
  514. phy_drd->vbus = NULL;
  515. }
  516. dev_vdbg(dev, "Creating usbdrd_phy phy\n");
  517. for (i = 0; i < EXYNOS5_DRDPHYS_NUM; i++) {
  518. struct phy *phy = devm_phy_create(dev, &exynos5_usbdrd_phy_ops,
  519. NULL);
  520. if (IS_ERR(phy)) {
  521. dev_err(dev, "Failed to create usbdrd_phy phy\n");
  522. return PTR_ERR(phy);
  523. }
  524. phy_drd->phys[i].phy = phy;
  525. phy_drd->phys[i].index = i;
  526. phy_drd->phys[i].reg_pmu = reg_pmu;
  527. phy_drd->phys[i].pmu_offset = pmu_offset;
  528. phy_drd->phys[i].phy_cfg = &drv_data->phy_cfg[i];
  529. phy_set_drvdata(phy, &phy_drd->phys[i]);
  530. }
  531. phy_provider = devm_of_phy_provider_register(dev,
  532. exynos5_usbdrd_phy_xlate);
  533. if (IS_ERR(phy_provider)) {
  534. dev_err(phy_drd->dev, "Failed to register phy provider\n");
  535. return PTR_ERR(phy_provider);
  536. }
  537. return 0;
  538. }
  539. static struct platform_driver exynos5_usb3drd_phy = {
  540. .probe = exynos5_usbdrd_phy_probe,
  541. .driver = {
  542. .of_match_table = exynos5_usbdrd_phy_of_match,
  543. .name = "exynos5_usb3drd_phy",
  544. .owner = THIS_MODULE,
  545. }
  546. };
  547. module_platform_driver(exynos5_usb3drd_phy);
  548. MODULE_DESCRIPTION("Samsung EXYNOS5 SoCs USB 3.0 DRD controller PHY driver");
  549. MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
  550. MODULE_LICENSE("GPL v2");
  551. MODULE_ALIAS("platform:exynos5_usb3drd_phy");