phy-rockchip-inno-usb2.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * Rockchip USB2.0 PHY with Innosilicon IP block driver
  3. *
  4. * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/clk-provider.h>
  18. #include <linux/delay.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/io.h>
  21. #include <linux/gpio/consumer.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/mutex.h>
  26. #include <linux/of.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_irq.h>
  29. #include <linux/of_platform.h>
  30. #include <linux/phy/phy.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/regmap.h>
  33. #include <linux/mfd/syscon.h>
  34. #define BIT_WRITEABLE_SHIFT 16
  35. #define SCHEDULE_DELAY (60 * HZ)
  36. enum rockchip_usb2phy_port_id {
  37. USB2PHY_PORT_OTG,
  38. USB2PHY_PORT_HOST,
  39. USB2PHY_NUM_PORTS,
  40. };
  41. enum rockchip_usb2phy_host_state {
  42. PHY_STATE_HS_ONLINE = 0,
  43. PHY_STATE_DISCONNECT = 1,
  44. PHY_STATE_CONNECT = 2,
  45. PHY_STATE_FS_LS_ONLINE = 4,
  46. };
  47. struct usb2phy_reg {
  48. unsigned int offset;
  49. unsigned int bitend;
  50. unsigned int bitstart;
  51. unsigned int disable;
  52. unsigned int enable;
  53. };
  54. /**
  55. * struct rockchip_usb2phy_port_cfg: usb-phy port configuration.
  56. * @phy_sus: phy suspend register.
  57. * @ls_det_en: linestate detection enable register.
  58. * @ls_det_st: linestate detection state register.
  59. * @ls_det_clr: linestate detection clear register.
  60. * @utmi_ls: utmi linestate state register.
  61. * @utmi_hstdet: utmi host disconnect register.
  62. */
  63. struct rockchip_usb2phy_port_cfg {
  64. struct usb2phy_reg phy_sus;
  65. struct usb2phy_reg ls_det_en;
  66. struct usb2phy_reg ls_det_st;
  67. struct usb2phy_reg ls_det_clr;
  68. struct usb2phy_reg utmi_ls;
  69. struct usb2phy_reg utmi_hstdet;
  70. };
  71. /**
  72. * struct rockchip_usb2phy_cfg: usb-phy configuration.
  73. * @reg: the address offset of grf for usb-phy config.
  74. * @num_ports: specify how many ports that the phy has.
  75. * @clkout_ctl: keep on/turn off output clk of phy.
  76. */
  77. struct rockchip_usb2phy_cfg {
  78. unsigned int reg;
  79. unsigned int num_ports;
  80. struct usb2phy_reg clkout_ctl;
  81. const struct rockchip_usb2phy_port_cfg port_cfgs[USB2PHY_NUM_PORTS];
  82. };
  83. /**
  84. * struct rockchip_usb2phy_port: usb-phy port data.
  85. * @port_id: flag for otg port or host port.
  86. * @suspended: phy suspended flag.
  87. * @ls_irq: IRQ number assigned for linestate detection.
  88. * @mutex: for register updating in sm_work.
  89. * @sm_work: OTG state machine work.
  90. * @phy_cfg: port register configuration, assigned by driver data.
  91. */
  92. struct rockchip_usb2phy_port {
  93. struct phy *phy;
  94. unsigned int port_id;
  95. bool suspended;
  96. int ls_irq;
  97. struct mutex mutex;
  98. struct delayed_work sm_work;
  99. const struct rockchip_usb2phy_port_cfg *port_cfg;
  100. };
  101. /**
  102. * struct rockchip_usb2phy: usb2.0 phy driver data.
  103. * @grf: General Register Files regmap.
  104. * @clk: clock struct of phy input clk.
  105. * @clk480m: clock struct of phy output clk.
  106. * @clk_hw: clock struct of phy output clk management.
  107. * @phy_cfg: phy register configuration, assigned by driver data.
  108. * @ports: phy port instance.
  109. */
  110. struct rockchip_usb2phy {
  111. struct device *dev;
  112. struct regmap *grf;
  113. struct clk *clk;
  114. struct clk *clk480m;
  115. struct clk_hw clk480m_hw;
  116. const struct rockchip_usb2phy_cfg *phy_cfg;
  117. struct rockchip_usb2phy_port ports[USB2PHY_NUM_PORTS];
  118. };
  119. static inline int property_enable(struct rockchip_usb2phy *rphy,
  120. const struct usb2phy_reg *reg, bool en)
  121. {
  122. unsigned int val, mask, tmp;
  123. tmp = en ? reg->enable : reg->disable;
  124. mask = GENMASK(reg->bitend, reg->bitstart);
  125. val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT);
  126. return regmap_write(rphy->grf, reg->offset, val);
  127. }
  128. static inline bool property_enabled(struct rockchip_usb2phy *rphy,
  129. const struct usb2phy_reg *reg)
  130. {
  131. int ret;
  132. unsigned int tmp, orig;
  133. unsigned int mask = GENMASK(reg->bitend, reg->bitstart);
  134. ret = regmap_read(rphy->grf, reg->offset, &orig);
  135. if (ret)
  136. return false;
  137. tmp = (orig & mask) >> reg->bitstart;
  138. return tmp == reg->enable;
  139. }
  140. static int rockchip_usb2phy_clk480m_enable(struct clk_hw *hw)
  141. {
  142. struct rockchip_usb2phy *rphy =
  143. container_of(hw, struct rockchip_usb2phy, clk480m_hw);
  144. int ret;
  145. /* turn on 480m clk output if it is off */
  146. if (!property_enabled(rphy, &rphy->phy_cfg->clkout_ctl)) {
  147. ret = property_enable(rphy, &rphy->phy_cfg->clkout_ctl, true);
  148. if (ret)
  149. return ret;
  150. /* waitting for the clk become stable */
  151. mdelay(1);
  152. }
  153. return 0;
  154. }
  155. static void rockchip_usb2phy_clk480m_disable(struct clk_hw *hw)
  156. {
  157. struct rockchip_usb2phy *rphy =
  158. container_of(hw, struct rockchip_usb2phy, clk480m_hw);
  159. /* turn off 480m clk output */
  160. property_enable(rphy, &rphy->phy_cfg->clkout_ctl, false);
  161. }
  162. static int rockchip_usb2phy_clk480m_enabled(struct clk_hw *hw)
  163. {
  164. struct rockchip_usb2phy *rphy =
  165. container_of(hw, struct rockchip_usb2phy, clk480m_hw);
  166. return property_enabled(rphy, &rphy->phy_cfg->clkout_ctl);
  167. }
  168. static unsigned long
  169. rockchip_usb2phy_clk480m_recalc_rate(struct clk_hw *hw,
  170. unsigned long parent_rate)
  171. {
  172. return 480000000;
  173. }
  174. static const struct clk_ops rockchip_usb2phy_clkout_ops = {
  175. .enable = rockchip_usb2phy_clk480m_enable,
  176. .disable = rockchip_usb2phy_clk480m_disable,
  177. .is_enabled = rockchip_usb2phy_clk480m_enabled,
  178. .recalc_rate = rockchip_usb2phy_clk480m_recalc_rate,
  179. };
  180. static void rockchip_usb2phy_clk480m_unregister(void *data)
  181. {
  182. struct rockchip_usb2phy *rphy = data;
  183. of_clk_del_provider(rphy->dev->of_node);
  184. clk_unregister(rphy->clk480m);
  185. }
  186. static int
  187. rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy)
  188. {
  189. struct device_node *node = rphy->dev->of_node;
  190. struct clk_init_data init;
  191. const char *clk_name;
  192. int ret;
  193. init.flags = 0;
  194. init.name = "clk_usbphy_480m";
  195. init.ops = &rockchip_usb2phy_clkout_ops;
  196. /* optional override of the clockname */
  197. of_property_read_string(node, "clock-output-names", &init.name);
  198. if (rphy->clk) {
  199. clk_name = __clk_get_name(rphy->clk);
  200. init.parent_names = &clk_name;
  201. init.num_parents = 1;
  202. } else {
  203. init.parent_names = NULL;
  204. init.num_parents = 0;
  205. }
  206. rphy->clk480m_hw.init = &init;
  207. /* register the clock */
  208. rphy->clk480m = clk_register(rphy->dev, &rphy->clk480m_hw);
  209. if (IS_ERR(rphy->clk480m)) {
  210. ret = PTR_ERR(rphy->clk480m);
  211. goto err_ret;
  212. }
  213. ret = of_clk_add_provider(node, of_clk_src_simple_get, rphy->clk480m);
  214. if (ret < 0)
  215. goto err_clk_provider;
  216. ret = devm_add_action(rphy->dev, rockchip_usb2phy_clk480m_unregister,
  217. rphy);
  218. if (ret < 0)
  219. goto err_unreg_action;
  220. return 0;
  221. err_unreg_action:
  222. of_clk_del_provider(node);
  223. err_clk_provider:
  224. clk_unregister(rphy->clk480m);
  225. err_ret:
  226. return ret;
  227. }
  228. static int rockchip_usb2phy_init(struct phy *phy)
  229. {
  230. struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
  231. struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
  232. int ret;
  233. if (rport->port_id == USB2PHY_PORT_HOST) {
  234. /* clear linestate and enable linestate detect irq */
  235. mutex_lock(&rport->mutex);
  236. ret = property_enable(rphy, &rport->port_cfg->ls_det_clr, true);
  237. if (ret) {
  238. mutex_unlock(&rport->mutex);
  239. return ret;
  240. }
  241. ret = property_enable(rphy, &rport->port_cfg->ls_det_en, true);
  242. if (ret) {
  243. mutex_unlock(&rport->mutex);
  244. return ret;
  245. }
  246. mutex_unlock(&rport->mutex);
  247. schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY);
  248. }
  249. return 0;
  250. }
  251. static int rockchip_usb2phy_power_on(struct phy *phy)
  252. {
  253. struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
  254. struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
  255. int ret;
  256. dev_dbg(&rport->phy->dev, "port power on\n");
  257. if (!rport->suspended)
  258. return 0;
  259. ret = clk_prepare_enable(rphy->clk480m);
  260. if (ret)
  261. return ret;
  262. ret = property_enable(rphy, &rport->port_cfg->phy_sus, false);
  263. if (ret)
  264. return ret;
  265. rport->suspended = false;
  266. return 0;
  267. }
  268. static int rockchip_usb2phy_power_off(struct phy *phy)
  269. {
  270. struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
  271. struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent);
  272. int ret;
  273. dev_dbg(&rport->phy->dev, "port power off\n");
  274. if (rport->suspended)
  275. return 0;
  276. ret = property_enable(rphy, &rport->port_cfg->phy_sus, true);
  277. if (ret)
  278. return ret;
  279. rport->suspended = true;
  280. clk_disable_unprepare(rphy->clk480m);
  281. return 0;
  282. }
  283. static int rockchip_usb2phy_exit(struct phy *phy)
  284. {
  285. struct rockchip_usb2phy_port *rport = phy_get_drvdata(phy);
  286. if (rport->port_id == USB2PHY_PORT_HOST)
  287. cancel_delayed_work_sync(&rport->sm_work);
  288. return 0;
  289. }
  290. static const struct phy_ops rockchip_usb2phy_ops = {
  291. .init = rockchip_usb2phy_init,
  292. .exit = rockchip_usb2phy_exit,
  293. .power_on = rockchip_usb2phy_power_on,
  294. .power_off = rockchip_usb2phy_power_off,
  295. .owner = THIS_MODULE,
  296. };
  297. /*
  298. * The function manage host-phy port state and suspend/resume phy port
  299. * to save power.
  300. *
  301. * we rely on utmi_linestate and utmi_hostdisconnect to identify whether
  302. * devices is disconnect or not. Besides, we do not need care it is FS/LS
  303. * disconnected or HS disconnected, actually, we just only need get the
  304. * device is disconnected at last through rearm the delayed work,
  305. * to suspend the phy port in _PHY_STATE_DISCONNECT_ case.
  306. *
  307. * NOTE: It may invoke *phy_powr_off or *phy_power_on which will invoke
  308. * some clk related APIs, so do not invoke it from interrupt context directly.
  309. */
  310. static void rockchip_usb2phy_sm_work(struct work_struct *work)
  311. {
  312. struct rockchip_usb2phy_port *rport =
  313. container_of(work, struct rockchip_usb2phy_port, sm_work.work);
  314. struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
  315. unsigned int sh = rport->port_cfg->utmi_hstdet.bitend -
  316. rport->port_cfg->utmi_hstdet.bitstart + 1;
  317. unsigned int ul, uhd, state;
  318. unsigned int ul_mask, uhd_mask;
  319. int ret;
  320. mutex_lock(&rport->mutex);
  321. ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul);
  322. if (ret < 0)
  323. goto next_schedule;
  324. ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset,
  325. &uhd);
  326. if (ret < 0)
  327. goto next_schedule;
  328. uhd_mask = GENMASK(rport->port_cfg->utmi_hstdet.bitend,
  329. rport->port_cfg->utmi_hstdet.bitstart);
  330. ul_mask = GENMASK(rport->port_cfg->utmi_ls.bitend,
  331. rport->port_cfg->utmi_ls.bitstart);
  332. /* stitch on utmi_ls and utmi_hstdet as phy state */
  333. state = ((uhd & uhd_mask) >> rport->port_cfg->utmi_hstdet.bitstart) |
  334. (((ul & ul_mask) >> rport->port_cfg->utmi_ls.bitstart) << sh);
  335. switch (state) {
  336. case PHY_STATE_HS_ONLINE:
  337. dev_dbg(&rport->phy->dev, "HS online\n");
  338. break;
  339. case PHY_STATE_FS_LS_ONLINE:
  340. /*
  341. * For FS/LS device, the online state share with connect state
  342. * from utmi_ls and utmi_hstdet register, so we distinguish
  343. * them via suspended flag.
  344. *
  345. * Plus, there are two cases, one is D- Line pull-up, and D+
  346. * line pull-down, the state is 4; another is D+ line pull-up,
  347. * and D- line pull-down, the state is 2.
  348. */
  349. if (!rport->suspended) {
  350. /* D- line pull-up, D+ line pull-down */
  351. dev_dbg(&rport->phy->dev, "FS/LS online\n");
  352. break;
  353. }
  354. /* fall through */
  355. case PHY_STATE_CONNECT:
  356. if (rport->suspended) {
  357. dev_dbg(&rport->phy->dev, "Connected\n");
  358. rockchip_usb2phy_power_on(rport->phy);
  359. rport->suspended = false;
  360. } else {
  361. /* D+ line pull-up, D- line pull-down */
  362. dev_dbg(&rport->phy->dev, "FS/LS online\n");
  363. }
  364. break;
  365. case PHY_STATE_DISCONNECT:
  366. if (!rport->suspended) {
  367. dev_dbg(&rport->phy->dev, "Disconnected\n");
  368. rockchip_usb2phy_power_off(rport->phy);
  369. rport->suspended = true;
  370. }
  371. /*
  372. * activate the linestate detection to get the next device
  373. * plug-in irq.
  374. */
  375. property_enable(rphy, &rport->port_cfg->ls_det_clr, true);
  376. property_enable(rphy, &rport->port_cfg->ls_det_en, true);
  377. /*
  378. * we don't need to rearm the delayed work when the phy port
  379. * is suspended.
  380. */
  381. mutex_unlock(&rport->mutex);
  382. return;
  383. default:
  384. dev_dbg(&rport->phy->dev, "unknown phy state\n");
  385. break;
  386. }
  387. next_schedule:
  388. mutex_unlock(&rport->mutex);
  389. schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY);
  390. }
  391. static irqreturn_t rockchip_usb2phy_linestate_irq(int irq, void *data)
  392. {
  393. struct rockchip_usb2phy_port *rport = data;
  394. struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent);
  395. if (!property_enabled(rphy, &rport->port_cfg->ls_det_st))
  396. return IRQ_NONE;
  397. mutex_lock(&rport->mutex);
  398. /* disable linestate detect irq and clear its status */
  399. property_enable(rphy, &rport->port_cfg->ls_det_en, false);
  400. property_enable(rphy, &rport->port_cfg->ls_det_clr, true);
  401. mutex_unlock(&rport->mutex);
  402. /*
  403. * In this case for host phy port, a new device is plugged in,
  404. * meanwhile, if the phy port is suspended, we need rearm the work to
  405. * resume it and mange its states; otherwise, we do nothing about that.
  406. */
  407. if (rport->suspended && rport->port_id == USB2PHY_PORT_HOST)
  408. rockchip_usb2phy_sm_work(&rport->sm_work.work);
  409. return IRQ_HANDLED;
  410. }
  411. static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy,
  412. struct rockchip_usb2phy_port *rport,
  413. struct device_node *child_np)
  414. {
  415. int ret;
  416. rport->port_id = USB2PHY_PORT_HOST;
  417. rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST];
  418. rport->suspended = true;
  419. mutex_init(&rport->mutex);
  420. INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work);
  421. rport->ls_irq = of_irq_get_byname(child_np, "linestate");
  422. if (rport->ls_irq < 0) {
  423. dev_err(rphy->dev, "no linestate irq provided\n");
  424. return rport->ls_irq;
  425. }
  426. ret = devm_request_threaded_irq(rphy->dev, rport->ls_irq, NULL,
  427. rockchip_usb2phy_linestate_irq,
  428. IRQF_ONESHOT,
  429. "rockchip_usb2phy", rport);
  430. if (ret) {
  431. dev_err(rphy->dev, "failed to request irq handle\n");
  432. return ret;
  433. }
  434. return 0;
  435. }
  436. static int rockchip_usb2phy_probe(struct platform_device *pdev)
  437. {
  438. struct device *dev = &pdev->dev;
  439. struct device_node *np = dev->of_node;
  440. struct device_node *child_np;
  441. struct phy_provider *provider;
  442. struct rockchip_usb2phy *rphy;
  443. const struct rockchip_usb2phy_cfg *phy_cfgs;
  444. const struct of_device_id *match;
  445. unsigned int reg;
  446. int index, ret;
  447. rphy = devm_kzalloc(dev, sizeof(*rphy), GFP_KERNEL);
  448. if (!rphy)
  449. return -ENOMEM;
  450. match = of_match_device(dev->driver->of_match_table, dev);
  451. if (!match || !match->data) {
  452. dev_err(dev, "phy configs are not assigned!\n");
  453. return -EINVAL;
  454. }
  455. if (!dev->parent || !dev->parent->of_node)
  456. return -EINVAL;
  457. rphy->grf = syscon_node_to_regmap(dev->parent->of_node);
  458. if (IS_ERR(rphy->grf))
  459. return PTR_ERR(rphy->grf);
  460. if (of_property_read_u32(np, "reg", &reg)) {
  461. dev_err(dev, "the reg property is not assigned in %s node\n",
  462. np->name);
  463. return -EINVAL;
  464. }
  465. rphy->dev = dev;
  466. phy_cfgs = match->data;
  467. platform_set_drvdata(pdev, rphy);
  468. /* find out a proper config which can be matched with dt. */
  469. index = 0;
  470. while (phy_cfgs[index].reg) {
  471. if (phy_cfgs[index].reg == reg) {
  472. rphy->phy_cfg = &phy_cfgs[index];
  473. break;
  474. }
  475. ++index;
  476. }
  477. if (!rphy->phy_cfg) {
  478. dev_err(dev, "no phy-config can be matched with %s node\n",
  479. np->name);
  480. return -EINVAL;
  481. }
  482. rphy->clk = of_clk_get_by_name(np, "phyclk");
  483. if (!IS_ERR(rphy->clk)) {
  484. clk_prepare_enable(rphy->clk);
  485. } else {
  486. dev_info(&pdev->dev, "no phyclk specified\n");
  487. rphy->clk = NULL;
  488. }
  489. ret = rockchip_usb2phy_clk480m_register(rphy);
  490. if (ret) {
  491. dev_err(dev, "failed to register 480m output clock\n");
  492. goto disable_clks;
  493. }
  494. index = 0;
  495. for_each_available_child_of_node(np, child_np) {
  496. struct rockchip_usb2phy_port *rport = &rphy->ports[index];
  497. struct phy *phy;
  498. /*
  499. * This driver aim to support both otg-port and host-port,
  500. * but unfortunately, the otg part is not ready in current,
  501. * so this comments and below codes are interim, which should
  502. * be changed after otg-port is supplied soon.
  503. */
  504. if (of_node_cmp(child_np->name, "host-port"))
  505. goto next_child;
  506. phy = devm_phy_create(dev, child_np, &rockchip_usb2phy_ops);
  507. if (IS_ERR(phy)) {
  508. dev_err(dev, "failed to create phy\n");
  509. ret = PTR_ERR(phy);
  510. goto put_child;
  511. }
  512. rport->phy = phy;
  513. phy_set_drvdata(rport->phy, rport);
  514. ret = rockchip_usb2phy_host_port_init(rphy, rport, child_np);
  515. if (ret)
  516. goto put_child;
  517. next_child:
  518. /* to prevent out of boundary */
  519. if (++index >= rphy->phy_cfg->num_ports)
  520. break;
  521. }
  522. provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  523. return PTR_ERR_OR_ZERO(provider);
  524. put_child:
  525. of_node_put(child_np);
  526. disable_clks:
  527. if (rphy->clk) {
  528. clk_disable_unprepare(rphy->clk);
  529. clk_put(rphy->clk);
  530. }
  531. return ret;
  532. }
  533. static const struct rockchip_usb2phy_cfg rk3366_phy_cfgs[] = {
  534. {
  535. .reg = 0x700,
  536. .num_ports = 2,
  537. .clkout_ctl = { 0x0724, 15, 15, 1, 0 },
  538. .port_cfgs = {
  539. [USB2PHY_PORT_HOST] = {
  540. .phy_sus = { 0x0728, 15, 0, 0, 0x1d1 },
  541. .ls_det_en = { 0x0680, 4, 4, 0, 1 },
  542. .ls_det_st = { 0x0690, 4, 4, 0, 1 },
  543. .ls_det_clr = { 0x06a0, 4, 4, 0, 1 },
  544. .utmi_ls = { 0x049c, 14, 13, 0, 1 },
  545. .utmi_hstdet = { 0x049c, 12, 12, 0, 1 }
  546. }
  547. },
  548. },
  549. { /* sentinel */ }
  550. };
  551. static const struct rockchip_usb2phy_cfg rk3399_phy_cfgs[] = {
  552. {
  553. .reg = 0xe450,
  554. .num_ports = 2,
  555. .clkout_ctl = { 0xe450, 4, 4, 1, 0 },
  556. .port_cfgs = {
  557. [USB2PHY_PORT_HOST] = {
  558. .phy_sus = { 0xe458, 1, 0, 0x2, 0x1 },
  559. .ls_det_en = { 0xe3c0, 6, 6, 0, 1 },
  560. .ls_det_st = { 0xe3e0, 6, 6, 0, 1 },
  561. .ls_det_clr = { 0xe3d0, 6, 6, 0, 1 },
  562. .utmi_ls = { 0xe2ac, 22, 21, 0, 1 },
  563. .utmi_hstdet = { 0xe2ac, 23, 23, 0, 1 }
  564. }
  565. },
  566. },
  567. {
  568. .reg = 0xe460,
  569. .num_ports = 2,
  570. .clkout_ctl = { 0xe460, 4, 4, 1, 0 },
  571. .port_cfgs = {
  572. [USB2PHY_PORT_HOST] = {
  573. .phy_sus = { 0xe468, 1, 0, 0x2, 0x1 },
  574. .ls_det_en = { 0xe3c0, 11, 11, 0, 1 },
  575. .ls_det_st = { 0xe3e0, 11, 11, 0, 1 },
  576. .ls_det_clr = { 0xe3d0, 11, 11, 0, 1 },
  577. .utmi_ls = { 0xe2ac, 26, 25, 0, 1 },
  578. .utmi_hstdet = { 0xe2ac, 27, 27, 0, 1 }
  579. }
  580. },
  581. },
  582. { /* sentinel */ }
  583. };
  584. static const struct of_device_id rockchip_usb2phy_dt_match[] = {
  585. { .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs },
  586. { .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs },
  587. {}
  588. };
  589. MODULE_DEVICE_TABLE(of, rockchip_usb2phy_dt_match);
  590. static struct platform_driver rockchip_usb2phy_driver = {
  591. .probe = rockchip_usb2phy_probe,
  592. .driver = {
  593. .name = "rockchip-usb2phy",
  594. .of_match_table = rockchip_usb2phy_dt_match,
  595. },
  596. };
  597. module_platform_driver(rockchip_usb2phy_driver);
  598. MODULE_AUTHOR("Frank Wang <frank.wang@rock-chips.com>");
  599. MODULE_DESCRIPTION("Rockchip USB2.0 PHY driver");
  600. MODULE_LICENSE("GPL v2");