phy-hi3670-usb3.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Phy provider for USB 3.1 controller on HiSilicon Kirin970 platform
  4. *
  5. * Copyright (C) 2017-2020 Hilisicon Electronics Co., Ltd.
  6. * http://www.huawei.com
  7. *
  8. * Authors: Yu Chen <chenyu56@huawei.com>
  9. */
  10. #include <linux/bitfield.h>
  11. #include <linux/clk.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/phy/phy.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regmap.h>
  19. #define SCTRL_SCDEEPSLEEPED (0x0)
  20. #define USB_CLK_SELECTED BIT(20)
  21. #define PERI_CRG_PEREN0 (0x00)
  22. #define PERI_CRG_PERDIS0 (0x04)
  23. #define PERI_CRG_PEREN4 (0x40)
  24. #define PERI_CRG_PERDIS4 (0x44)
  25. #define PERI_CRG_PERRSTEN4 (0x90)
  26. #define PERI_CRG_PERRSTDIS4 (0x94)
  27. #define PERI_CRG_ISODIS (0x148)
  28. #define PERI_CRG_PEREN6 (0x410)
  29. #define PERI_CRG_PERDIS6 (0x414)
  30. #define USB_REFCLK_ISO_EN BIT(25)
  31. #define GT_CLK_USB2PHY_REF BIT(19)
  32. #define PCTRL_PERI_CTRL3 (0x10)
  33. #define PCTRL_PERI_CTRL3_MSK_START (16)
  34. #define USB_TCXO_EN BIT(1)
  35. #define PCTRL_PERI_CTRL24 (0x64)
  36. #define SC_CLK_USB3PHY_3MUX1_SEL BIT(25)
  37. #define USB3OTG_CTRL0 (0x00)
  38. #define USB3OTG_CTRL3 (0x0c)
  39. #define USB3OTG_CTRL4 (0x10)
  40. #define USB3OTG_CTRL5 (0x14)
  41. #define USB3OTG_CTRL7 (0x1c)
  42. #define USB_MISC_CFG50 (0x50)
  43. #define USB_MISC_CFG54 (0x54)
  44. #define USB_MISC_CFG58 (0x58)
  45. #define USB_MISC_CFG5C (0x5c)
  46. #define USB_MISC_CFGA0 (0xa0)
  47. #define TCA_CLK_RST (0x200)
  48. #define TCA_INTR_EN (0x204)
  49. #define TCA_INTR_STS (0x208)
  50. #define TCA_GCFG (0x210)
  51. #define TCA_TCPC (0x214)
  52. #define TCA_SYSMODE_CFG (0x218)
  53. #define TCA_VBUS_CTRL (0x240)
  54. #define CTRL0_USB3_VBUSVLD BIT(7)
  55. #define CTRL0_USB3_VBUSVLD_SEL BIT(6)
  56. #define CTRL3_USB2_VBUSVLDEXT0 BIT(6)
  57. #define CTRL3_USB2_VBUSVLDEXTSEL0 BIT(5)
  58. #define CTRL5_USB2_SIDDQ BIT(0)
  59. #define CTRL7_USB2_REFCLKSEL_MASK GENMASK(4, 3)
  60. #define CTRL7_USB2_REFCLKSEL_ABB (BIT(4) | BIT(3))
  61. #define CTRL7_USB2_REFCLKSEL_PAD BIT(4)
  62. #define CFG50_USB3_PHY_TEST_POWERDOWN BIT(23)
  63. #define CFG54_USB31PHY_CR_ADDR_MASK GENMASK(31, 16)
  64. #define CFG54_USB3PHY_REF_USE_PAD BIT(12)
  65. #define CFG54_PHY0_PMA_PWR_STABLE BIT(11)
  66. #define CFG54_PHY0_PCS_PWR_STABLE BIT(9)
  67. #define CFG54_USB31PHY_CR_ACK BIT(7)
  68. #define CFG54_USB31PHY_CR_WR_EN BIT(5)
  69. #define CFG54_USB31PHY_CR_SEL BIT(4)
  70. #define CFG54_USB31PHY_CR_RD_EN BIT(3)
  71. #define CFG54_USB31PHY_CR_CLK BIT(2)
  72. #define CFG54_USB3_PHY0_ANA_PWR_EN BIT(1)
  73. #define CFG58_USB31PHY_CR_DATA_MASK GENMASK(31, 16)
  74. #define CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN BIT(1)
  75. #define CFGA0_VAUX_RESET BIT(9)
  76. #define CFGA0_USB31C_RESET BIT(8)
  77. #define CFGA0_USB2PHY_REFCLK_SELECT BIT(4)
  78. #define CFGA0_USB3PHY_RESET BIT(1)
  79. #define CFGA0_USB2PHY_POR BIT(0)
  80. #define INTR_EN_XA_TIMEOUT_EVT_EN BIT(1)
  81. #define INTR_EN_XA_ACK_EVT_EN BIT(0)
  82. #define CLK_RST_TCA_REF_CLK_EN BIT(1)
  83. #define CLK_RST_SUSPEND_CLK_EN BIT(0)
  84. #define GCFG_ROLE_HSTDEV BIT(4)
  85. #define GCFG_OP_MODE GENMASK(1, 0)
  86. #define GCFG_OP_MODE_CTRL_SYNC_MODE BIT(0)
  87. #define TCPC_VALID BIT(4)
  88. #define TCPC_LOW_POWER_EN BIT(3)
  89. #define TCPC_MUX_CONTROL_MASK GENMASK(1, 0)
  90. #define TCPC_MUX_CONTROL_USB31 BIT(0)
  91. #define SYSMODE_CFG_TYPEC_DISABLE BIT(3)
  92. #define VBUS_CTRL_POWERPRESENT_OVERRD GENMASK(3, 2)
  93. #define VBUS_CTRL_VBUSVALID_OVERRD GENMASK(1, 0)
  94. #define KIRIN970_USB_DEFAULT_PHY_PARAM (0xfdfee4)
  95. #define KIRIN970_USB_DEFAULT_PHY_VBOOST (0x5)
  96. #define TX_VBOOST_LVL_REG (0xf)
  97. #define TX_VBOOST_LVL_START (6)
  98. #define TX_VBOOST_LVL_ENABLE BIT(9)
  99. struct hi3670_priv {
  100. struct device *dev;
  101. struct regmap *peri_crg;
  102. struct regmap *pctrl;
  103. struct regmap *sctrl;
  104. struct regmap *usb31misc;
  105. u32 eye_diagram_param;
  106. u32 tx_vboost_lvl;
  107. u32 peri_crg_offset;
  108. u32 pctrl_offset;
  109. u32 usb31misc_offset;
  110. };
  111. static int hi3670_phy_cr_clk(struct regmap *usb31misc)
  112. {
  113. int ret;
  114. /* Clock up */
  115. ret = regmap_update_bits(usb31misc, USB_MISC_CFG54,
  116. CFG54_USB31PHY_CR_CLK, CFG54_USB31PHY_CR_CLK);
  117. if (ret)
  118. return ret;
  119. /* Clock down */
  120. return regmap_update_bits(usb31misc, USB_MISC_CFG54,
  121. CFG54_USB31PHY_CR_CLK, 0);
  122. }
  123. static int hi3670_phy_cr_set_sel(struct regmap *usb31misc)
  124. {
  125. return regmap_update_bits(usb31misc, USB_MISC_CFG54,
  126. CFG54_USB31PHY_CR_SEL, CFG54_USB31PHY_CR_SEL);
  127. }
  128. static int hi3670_phy_cr_start(struct regmap *usb31misc, int direction)
  129. {
  130. int ret, reg;
  131. if (direction)
  132. reg = CFG54_USB31PHY_CR_WR_EN;
  133. else
  134. reg = CFG54_USB31PHY_CR_RD_EN;
  135. ret = regmap_update_bits(usb31misc, USB_MISC_CFG54, reg, reg);
  136. if (ret)
  137. return ret;
  138. ret = hi3670_phy_cr_clk(usb31misc);
  139. if (ret)
  140. return ret;
  141. return regmap_update_bits(usb31misc, USB_MISC_CFG54,
  142. CFG54_USB31PHY_CR_RD_EN | CFG54_USB31PHY_CR_WR_EN, 0);
  143. }
  144. static int hi3670_phy_cr_wait_ack(struct regmap *usb31misc)
  145. {
  146. u32 reg;
  147. int retry = 10;
  148. int ret;
  149. while (retry-- > 0) {
  150. ret = regmap_read(usb31misc, USB_MISC_CFG54, &reg);
  151. if (ret)
  152. return ret;
  153. if ((reg & CFG54_USB31PHY_CR_ACK) == CFG54_USB31PHY_CR_ACK)
  154. return 0;
  155. ret = hi3670_phy_cr_clk(usb31misc);
  156. if (ret)
  157. return ret;
  158. usleep_range(10, 20);
  159. }
  160. return -ETIMEDOUT;
  161. }
  162. static int hi3670_phy_cr_set_addr(struct regmap *usb31misc, u32 addr)
  163. {
  164. u32 reg;
  165. int ret;
  166. ret = regmap_read(usb31misc, USB_MISC_CFG54, &reg);
  167. if (ret)
  168. return ret;
  169. reg = FIELD_PREP(CFG54_USB31PHY_CR_ADDR_MASK, addr);
  170. return regmap_update_bits(usb31misc, USB_MISC_CFG54,
  171. CFG54_USB31PHY_CR_ADDR_MASK, reg);
  172. }
  173. static int hi3670_phy_cr_read(struct regmap *usb31misc, u32 addr, u32 *val)
  174. {
  175. int reg, i, ret;
  176. for (i = 0; i < 100; i++) {
  177. ret = hi3670_phy_cr_clk(usb31misc);
  178. if (ret)
  179. return ret;
  180. }
  181. ret = hi3670_phy_cr_set_sel(usb31misc);
  182. if (ret)
  183. return ret;
  184. ret = hi3670_phy_cr_set_addr(usb31misc, addr);
  185. if (ret)
  186. return ret;
  187. ret = hi3670_phy_cr_start(usb31misc, 0);
  188. if (ret)
  189. return ret;
  190. ret = hi3670_phy_cr_wait_ack(usb31misc);
  191. if (ret)
  192. return ret;
  193. ret = regmap_read(usb31misc, USB_MISC_CFG58, &reg);
  194. if (ret)
  195. return ret;
  196. *val = FIELD_GET(CFG58_USB31PHY_CR_DATA_MASK, reg);
  197. return 0;
  198. }
  199. static int hi3670_phy_cr_write(struct regmap *usb31misc, u32 addr, u32 val)
  200. {
  201. int i;
  202. int ret;
  203. for (i = 0; i < 100; i++) {
  204. ret = hi3670_phy_cr_clk(usb31misc);
  205. if (ret)
  206. return ret;
  207. }
  208. ret = hi3670_phy_cr_set_sel(usb31misc);
  209. if (ret)
  210. return ret;
  211. ret = hi3670_phy_cr_set_addr(usb31misc, addr);
  212. if (ret)
  213. return ret;
  214. ret = regmap_write(usb31misc, USB_MISC_CFG58,
  215. FIELD_PREP(CFG58_USB31PHY_CR_DATA_MASK, val));
  216. if (ret)
  217. return ret;
  218. ret = hi3670_phy_cr_start(usb31misc, 1);
  219. if (ret)
  220. return ret;
  221. return hi3670_phy_cr_wait_ack(usb31misc);
  222. }
  223. static int hi3670_phy_set_params(struct hi3670_priv *priv)
  224. {
  225. u32 reg;
  226. int ret;
  227. int retry = 3;
  228. ret = regmap_write(priv->usb31misc, USB3OTG_CTRL4,
  229. priv->eye_diagram_param);
  230. if (ret) {
  231. dev_err(priv->dev, "set USB3OTG_CTRL4 failed\n");
  232. return ret;
  233. }
  234. while (retry-- > 0) {
  235. ret = hi3670_phy_cr_read(priv->usb31misc,
  236. TX_VBOOST_LVL_REG, &reg);
  237. if (!ret)
  238. break;
  239. if (ret != -ETIMEDOUT) {
  240. dev_err(priv->dev, "read TX_VBOOST_LVL_REG failed\n");
  241. return ret;
  242. }
  243. }
  244. if (ret)
  245. return ret;
  246. reg |= (TX_VBOOST_LVL_ENABLE | (priv->tx_vboost_lvl << TX_VBOOST_LVL_START));
  247. ret = hi3670_phy_cr_write(priv->usb31misc, TX_VBOOST_LVL_REG, reg);
  248. if (ret)
  249. dev_err(priv->dev, "write TX_VBOOST_LVL_REG failed\n");
  250. return ret;
  251. }
  252. static bool hi3670_is_abbclk_selected(struct hi3670_priv *priv)
  253. {
  254. u32 reg;
  255. if (!priv->sctrl) {
  256. dev_err(priv->dev, "priv->sctrl is null!\n");
  257. return false;
  258. }
  259. if (regmap_read(priv->sctrl, SCTRL_SCDEEPSLEEPED, &reg)) {
  260. dev_err(priv->dev, "SCTRL_SCDEEPSLEEPED read failed!\n");
  261. return false;
  262. }
  263. if ((reg & USB_CLK_SELECTED) == 0)
  264. return false;
  265. return true;
  266. }
  267. static int hi3670_config_phy_clock(struct hi3670_priv *priv)
  268. {
  269. u32 val, mask;
  270. int ret;
  271. if (!hi3670_is_abbclk_selected(priv)) {
  272. /* usb refclk iso disable */
  273. ret = regmap_write(priv->peri_crg, PERI_CRG_ISODIS,
  274. USB_REFCLK_ISO_EN);
  275. if (ret)
  276. goto out;
  277. /* enable usb_tcxo_en */
  278. ret = regmap_write(priv->pctrl, PCTRL_PERI_CTRL3,
  279. USB_TCXO_EN |
  280. (USB_TCXO_EN << PCTRL_PERI_CTRL3_MSK_START));
  281. /* select usbphy clk from abb */
  282. mask = SC_CLK_USB3PHY_3MUX1_SEL;
  283. ret = regmap_update_bits(priv->pctrl,
  284. PCTRL_PERI_CTRL24, mask, 0);
  285. if (ret)
  286. goto out;
  287. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0,
  288. CFGA0_USB2PHY_REFCLK_SELECT, 0);
  289. if (ret)
  290. goto out;
  291. ret = regmap_read(priv->usb31misc, USB3OTG_CTRL7, &val);
  292. if (ret)
  293. goto out;
  294. val &= ~CTRL7_USB2_REFCLKSEL_MASK;
  295. val |= CTRL7_USB2_REFCLKSEL_ABB;
  296. ret = regmap_write(priv->usb31misc, USB3OTG_CTRL7, val);
  297. if (ret)
  298. goto out;
  299. return 0;
  300. }
  301. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG54,
  302. CFG54_USB3PHY_REF_USE_PAD,
  303. CFG54_USB3PHY_REF_USE_PAD);
  304. if (ret)
  305. goto out;
  306. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0,
  307. CFGA0_USB2PHY_REFCLK_SELECT,
  308. CFGA0_USB2PHY_REFCLK_SELECT);
  309. if (ret)
  310. goto out;
  311. ret = regmap_read(priv->usb31misc, USB3OTG_CTRL7, &val);
  312. if (ret)
  313. goto out;
  314. val &= ~CTRL7_USB2_REFCLKSEL_MASK;
  315. val |= CTRL7_USB2_REFCLKSEL_PAD;
  316. ret = regmap_write(priv->usb31misc, USB3OTG_CTRL7, val);
  317. if (ret)
  318. goto out;
  319. ret = regmap_write(priv->peri_crg,
  320. PERI_CRG_PEREN6, GT_CLK_USB2PHY_REF);
  321. if (ret)
  322. goto out;
  323. return 0;
  324. out:
  325. dev_err(priv->dev, "failed to config phy clock ret: %d\n", ret);
  326. return ret;
  327. }
  328. static int hi3670_config_tca(struct hi3670_priv *priv)
  329. {
  330. u32 val, mask;
  331. int ret;
  332. ret = regmap_write(priv->usb31misc, TCA_INTR_STS, 0xffff);
  333. if (ret)
  334. goto out;
  335. ret = regmap_write(priv->usb31misc, TCA_INTR_EN,
  336. INTR_EN_XA_TIMEOUT_EVT_EN | INTR_EN_XA_ACK_EVT_EN);
  337. if (ret)
  338. goto out;
  339. mask = CLK_RST_TCA_REF_CLK_EN | CLK_RST_SUSPEND_CLK_EN;
  340. ret = regmap_update_bits(priv->usb31misc, TCA_CLK_RST, mask, 0);
  341. if (ret)
  342. goto out;
  343. ret = regmap_update_bits(priv->usb31misc, TCA_GCFG,
  344. GCFG_ROLE_HSTDEV | GCFG_OP_MODE,
  345. GCFG_ROLE_HSTDEV | GCFG_OP_MODE_CTRL_SYNC_MODE);
  346. if (ret)
  347. goto out;
  348. ret = regmap_update_bits(priv->usb31misc, TCA_SYSMODE_CFG,
  349. SYSMODE_CFG_TYPEC_DISABLE, 0);
  350. if (ret)
  351. goto out;
  352. ret = regmap_read(priv->usb31misc, TCA_TCPC, &val);
  353. if (ret)
  354. goto out;
  355. val &= ~(TCPC_VALID | TCPC_LOW_POWER_EN | TCPC_MUX_CONTROL_MASK);
  356. val |= (TCPC_VALID | TCPC_MUX_CONTROL_USB31);
  357. ret = regmap_write(priv->usb31misc, TCA_TCPC, val);
  358. if (ret)
  359. goto out;
  360. ret = regmap_write(priv->usb31misc, TCA_VBUS_CTRL,
  361. VBUS_CTRL_POWERPRESENT_OVERRD | VBUS_CTRL_VBUSVALID_OVERRD);
  362. if (ret)
  363. goto out;
  364. return 0;
  365. out:
  366. dev_err(priv->dev, "failed to config phy clock ret: %d\n", ret);
  367. return ret;
  368. }
  369. static int hi3670_phy_init(struct phy *phy)
  370. {
  371. struct hi3670_priv *priv = phy_get_drvdata(phy);
  372. u32 val;
  373. int ret;
  374. /* assert controller */
  375. val = CFGA0_VAUX_RESET | CFGA0_USB31C_RESET |
  376. CFGA0_USB3PHY_RESET | CFGA0_USB2PHY_POR;
  377. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, val, 0);
  378. if (ret)
  379. goto out;
  380. ret = hi3670_config_phy_clock(priv);
  381. if (ret)
  382. goto out;
  383. /* Exit from IDDQ mode */
  384. ret = regmap_update_bits(priv->usb31misc, USB3OTG_CTRL5,
  385. CTRL5_USB2_SIDDQ, 0);
  386. if (ret)
  387. goto out;
  388. /* Release USB31 PHY out of TestPowerDown mode */
  389. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG50,
  390. CFG50_USB3_PHY_TEST_POWERDOWN, 0);
  391. if (ret)
  392. goto out;
  393. /* Deassert phy */
  394. val = CFGA0_USB3PHY_RESET | CFGA0_USB2PHY_POR;
  395. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, val, val);
  396. if (ret)
  397. goto out;
  398. usleep_range(100, 120);
  399. /* Tell the PHY power is stable */
  400. val = CFG54_USB3_PHY0_ANA_PWR_EN | CFG54_PHY0_PCS_PWR_STABLE |
  401. CFG54_PHY0_PMA_PWR_STABLE;
  402. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG54,
  403. val, val);
  404. if (ret)
  405. goto out;
  406. ret = hi3670_config_tca(priv);
  407. if (ret)
  408. goto out;
  409. /* Enable SSC */
  410. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFG5C,
  411. CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN,
  412. CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN);
  413. if (ret)
  414. goto out;
  415. /* Deassert controller */
  416. val = CFGA0_VAUX_RESET | CFGA0_USB31C_RESET;
  417. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, val, val);
  418. if (ret)
  419. goto out;
  420. usleep_range(100, 120);
  421. /* Set fake vbus valid signal */
  422. val = CTRL0_USB3_VBUSVLD | CTRL0_USB3_VBUSVLD_SEL;
  423. ret = regmap_update_bits(priv->usb31misc, USB3OTG_CTRL0, val, val);
  424. if (ret)
  425. goto out;
  426. val = CTRL3_USB2_VBUSVLDEXT0 | CTRL3_USB2_VBUSVLDEXTSEL0;
  427. ret = regmap_update_bits(priv->usb31misc, USB3OTG_CTRL3, val, val);
  428. if (ret)
  429. goto out;
  430. usleep_range(100, 120);
  431. ret = hi3670_phy_set_params(priv);
  432. if (ret)
  433. goto out;
  434. return 0;
  435. out:
  436. dev_err(priv->dev, "failed to init phy ret: %d\n", ret);
  437. return ret;
  438. }
  439. static int hi3670_phy_exit(struct phy *phy)
  440. {
  441. struct hi3670_priv *priv = phy_get_drvdata(phy);
  442. u32 mask;
  443. int ret;
  444. /* Assert phy */
  445. mask = CFGA0_USB3PHY_RESET | CFGA0_USB2PHY_POR;
  446. ret = regmap_update_bits(priv->usb31misc, USB_MISC_CFGA0, mask, 0);
  447. if (ret)
  448. goto out;
  449. if (!hi3670_is_abbclk_selected(priv)) {
  450. /* disable usb_tcxo_en */
  451. ret = regmap_write(priv->pctrl, PCTRL_PERI_CTRL3,
  452. USB_TCXO_EN << PCTRL_PERI_CTRL3_MSK_START);
  453. } else {
  454. ret = regmap_write(priv->peri_crg, PERI_CRG_PERDIS6,
  455. GT_CLK_USB2PHY_REF);
  456. if (ret)
  457. goto out;
  458. }
  459. return 0;
  460. out:
  461. dev_err(priv->dev, "failed to exit phy ret: %d\n", ret);
  462. return ret;
  463. }
  464. static const struct phy_ops hi3670_phy_ops = {
  465. .init = hi3670_phy_init,
  466. .exit = hi3670_phy_exit,
  467. .owner = THIS_MODULE,
  468. };
  469. static int hi3670_phy_probe(struct platform_device *pdev)
  470. {
  471. struct phy_provider *phy_provider;
  472. struct device *dev = &pdev->dev;
  473. struct phy *phy;
  474. struct hi3670_priv *priv;
  475. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  476. if (!priv)
  477. return -ENOMEM;
  478. priv->dev = dev;
  479. priv->peri_crg = syscon_regmap_lookup_by_phandle(dev->of_node,
  480. "hisilicon,pericrg-syscon");
  481. if (IS_ERR(priv->peri_crg)) {
  482. dev_err(dev, "no hisilicon,pericrg-syscon\n");
  483. return PTR_ERR(priv->peri_crg);
  484. }
  485. priv->pctrl = syscon_regmap_lookup_by_phandle(dev->of_node,
  486. "hisilicon,pctrl-syscon");
  487. if (IS_ERR(priv->pctrl)) {
  488. dev_err(dev, "no hisilicon,pctrl-syscon\n");
  489. return PTR_ERR(priv->pctrl);
  490. }
  491. priv->sctrl = syscon_regmap_lookup_by_phandle(dev->of_node,
  492. "hisilicon,sctrl-syscon");
  493. if (IS_ERR(priv->sctrl)) {
  494. dev_err(dev, "no hisilicon,sctrl-syscon\n");
  495. return PTR_ERR(priv->sctrl);
  496. }
  497. /* node of hi3670 phy is a sub-node of usb3_otg_bc */
  498. priv->usb31misc = syscon_node_to_regmap(dev->parent->of_node);
  499. if (IS_ERR(priv->usb31misc)) {
  500. dev_err(dev, "no hisilicon,usb3-otg-bc-syscon\n");
  501. return PTR_ERR(priv->usb31misc);
  502. }
  503. if (of_property_read_u32(dev->of_node, "hisilicon,eye-diagram-param",
  504. &priv->eye_diagram_param))
  505. priv->eye_diagram_param = KIRIN970_USB_DEFAULT_PHY_PARAM;
  506. if (of_property_read_u32(dev->of_node, "hisilicon,tx-vboost-lvl",
  507. &priv->tx_vboost_lvl))
  508. priv->tx_vboost_lvl = KIRIN970_USB_DEFAULT_PHY_VBOOST;
  509. phy = devm_phy_create(dev, NULL, &hi3670_phy_ops);
  510. if (IS_ERR(phy))
  511. return PTR_ERR(phy);
  512. phy_set_drvdata(phy, priv);
  513. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  514. return PTR_ERR_OR_ZERO(phy_provider);
  515. }
  516. static const struct of_device_id hi3670_phy_of_match[] = {
  517. { .compatible = "hisilicon,hi3670-usb-phy" },
  518. { },
  519. };
  520. MODULE_DEVICE_TABLE(of, hi3670_phy_of_match);
  521. static struct platform_driver hi3670_phy_driver = {
  522. .probe = hi3670_phy_probe,
  523. .driver = {
  524. .name = "hi3670-usb-phy",
  525. .of_match_table = hi3670_phy_of_match,
  526. }
  527. };
  528. module_platform_driver(hi3670_phy_driver);
  529. MODULE_AUTHOR("Yu Chen <chenyu56@huawei.com>");
  530. MODULE_LICENSE("GPL v2");
  531. MODULE_DESCRIPTION("Hilisicon Kirin970 USB31 PHY Driver");