dwc3-google.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * dwc3-google.c - Google DWC3 Specific Glue Layer
  4. *
  5. * Copyright (c) 2025, Google LLC
  6. * Author: Roy Luo <royluo@google.com>
  7. */
  8. #include <linux/bitfield.h>
  9. #include <linux/clk.h>
  10. #include <linux/iopoll.h>
  11. #include <linux/irq.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/platform_device.h>
  17. #include <linux/pm_domain.h>
  18. #include <linux/regmap.h>
  19. #include <linux/reset.h>
  20. #include "core.h"
  21. #include "glue.h"
  22. /* HOST CFG registers */
  23. #define HC_STATUS_OFFSET 0x0
  24. #define HC_STATUS_CURRENT_POWER_STATE_U2PMU GENMASK(1, 0)
  25. #define HC_STATUS_CURRENT_POWER_STATE_U3PMU GENMASK(4, 3)
  26. #define HOST_CFG1_OFFSET 0x4
  27. #define HOST_CFG1_PME_EN BIT(3)
  28. #define HOST_CFG1_PM_POWER_STATE_REQUEST GENMASK(5, 4)
  29. #define HOST_CFG1_PM_POWER_STATE_D0 0x0
  30. #define HOST_CFG1_PM_POWER_STATE_D3 0x3
  31. /* USBINT registers */
  32. #define USBINT_CFG1_OFFSET 0x0
  33. #define USBINT_CFG1_USBDRD_PME_GEN_U2P_INTR_MSK BIT(2)
  34. #define USBINT_CFG1_USBDRD_PME_GEN_U3P_INTR_MSK BIT(3)
  35. #define USBINT_CFG1_USBDRD_PME_GEN_U2P_INTR_INT_EN BIT(8)
  36. #define USBINT_CFG1_USBDRD_PME_GEN_U3P_INTR_INT_EN BIT(9)
  37. #define USBINT_CFG1_USBDRD_PME_GEN_U2_INTR_CLR BIT(14)
  38. #define USBINT_CFG1_USBDRD_PME_GEN_U3_INTR_CLR BIT(15)
  39. #define USBINT_STATUS_OFFSET 0x4
  40. #define USBINT_STATUS_USBDRD_PME_GEN_U2P_INTR_STS_RAW BIT(2)
  41. #define USBINT_STATUS_USBDRD_PME_GEN_U3P_INTR_STS_RAW BIT(3)
  42. #define USBCS_TOP_CTRL_CFG1_OFFSET 0xc
  43. #define USBCS_TOP_CTRL_CFG1_USB2ONLY_MODE BIT(5)
  44. #define DWC3_GOOGLE_MAX_RESETS 4
  45. struct dwc3_google {
  46. struct device *dev;
  47. struct dwc3 dwc;
  48. struct clk_bulk_data *clks;
  49. int num_clks;
  50. struct reset_control_bulk_data rsts[DWC3_GOOGLE_MAX_RESETS];
  51. int num_rsts;
  52. struct reset_control *non_sticky_rst;
  53. struct device *usb_psw_pd;
  54. struct device_link *usb_psw_pd_dl;
  55. struct notifier_block usb_psw_pd_nb;
  56. struct device *usb_top_pd;
  57. struct device_link *usb_top_pd_dl;
  58. struct regmap *usb_cfg_regmap;
  59. unsigned int host_cfg_offset;
  60. unsigned int usbint_cfg_offset;
  61. int hs_pme_irq;
  62. int ss_pme_irq;
  63. bool is_usb2only;
  64. bool is_hibernation;
  65. };
  66. #define to_dwc3_google(d) container_of_const((d), struct dwc3_google, dwc)
  67. static int dwc3_google_rst_init(struct dwc3_google *google)
  68. {
  69. int ret;
  70. google->num_rsts = 4;
  71. google->rsts[0].id = "non_sticky";
  72. google->rsts[1].id = "sticky";
  73. google->rsts[2].id = "drd_bus";
  74. google->rsts[3].id = "top";
  75. ret = devm_reset_control_bulk_get_exclusive(google->dev,
  76. google->num_rsts,
  77. google->rsts);
  78. if (ret < 0)
  79. return ret;
  80. google->non_sticky_rst = google->rsts[0].rstc;
  81. return 0;
  82. }
  83. static int dwc3_google_set_pmu_state(struct dwc3_google *google, int state)
  84. {
  85. u32 reg;
  86. int ret;
  87. regmap_read(google->usb_cfg_regmap,
  88. google->host_cfg_offset + HOST_CFG1_OFFSET, &reg);
  89. reg &= ~HOST_CFG1_PM_POWER_STATE_REQUEST;
  90. reg |= (FIELD_PREP(HOST_CFG1_PM_POWER_STATE_REQUEST, state) |
  91. HOST_CFG1_PME_EN);
  92. regmap_write(google->usb_cfg_regmap,
  93. google->host_cfg_offset + HOST_CFG1_OFFSET, reg);
  94. ret = regmap_read_poll_timeout(google->usb_cfg_regmap,
  95. google->host_cfg_offset + HC_STATUS_OFFSET, reg,
  96. (FIELD_GET(HC_STATUS_CURRENT_POWER_STATE_U2PMU,
  97. reg) == state &&
  98. FIELD_GET(HC_STATUS_CURRENT_POWER_STATE_U3PMU,
  99. reg) == state),
  100. 10, 10000);
  101. if (ret)
  102. dev_err(google->dev, "failed to set PMU state %d\n", state);
  103. return ret;
  104. }
  105. /*
  106. * Clear pme interrupts and report their status.
  107. * The hardware requires write-1 then write-0 sequence to clear the interrupt bits.
  108. */
  109. static u32 dwc3_google_clear_pme_irqs(struct dwc3_google *google)
  110. {
  111. u32 irq_status, reg_set, reg_clear;
  112. regmap_read(google->usb_cfg_regmap,
  113. google->usbint_cfg_offset + USBINT_STATUS_OFFSET, &irq_status);
  114. irq_status &= (USBINT_STATUS_USBDRD_PME_GEN_U2P_INTR_STS_RAW |
  115. USBINT_STATUS_USBDRD_PME_GEN_U3P_INTR_STS_RAW);
  116. if (!irq_status)
  117. return irq_status;
  118. regmap_read(google->usb_cfg_regmap,
  119. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, &reg_set);
  120. reg_clear = reg_set;
  121. if (irq_status & USBINT_STATUS_USBDRD_PME_GEN_U2P_INTR_STS_RAW) {
  122. reg_set |= USBINT_CFG1_USBDRD_PME_GEN_U2_INTR_CLR;
  123. reg_clear &= ~USBINT_CFG1_USBDRD_PME_GEN_U2_INTR_CLR;
  124. }
  125. if (irq_status & USBINT_STATUS_USBDRD_PME_GEN_U3P_INTR_STS_RAW) {
  126. reg_set |= USBINT_CFG1_USBDRD_PME_GEN_U3_INTR_CLR;
  127. reg_clear &= ~USBINT_CFG1_USBDRD_PME_GEN_U3_INTR_CLR;
  128. }
  129. regmap_write(google->usb_cfg_regmap,
  130. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, reg_set);
  131. regmap_write(google->usb_cfg_regmap,
  132. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, reg_clear);
  133. return irq_status;
  134. }
  135. static void dwc3_google_enable_pme_irq(struct dwc3_google *google)
  136. {
  137. u32 reg;
  138. regmap_read(google->usb_cfg_regmap,
  139. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, &reg);
  140. reg &= ~(USBINT_CFG1_USBDRD_PME_GEN_U2P_INTR_MSK |
  141. USBINT_CFG1_USBDRD_PME_GEN_U3P_INTR_MSK);
  142. reg |= (USBINT_CFG1_USBDRD_PME_GEN_U2P_INTR_INT_EN |
  143. USBINT_CFG1_USBDRD_PME_GEN_U3P_INTR_INT_EN);
  144. regmap_write(google->usb_cfg_regmap,
  145. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, reg);
  146. enable_irq(google->hs_pme_irq);
  147. enable_irq(google->ss_pme_irq);
  148. enable_irq_wake(google->hs_pme_irq);
  149. enable_irq_wake(google->ss_pme_irq);
  150. }
  151. static void dwc3_google_disable_pme_irq(struct dwc3_google *google)
  152. {
  153. u32 reg;
  154. regmap_read(google->usb_cfg_regmap,
  155. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, &reg);
  156. reg &= ~(USBINT_CFG1_USBDRD_PME_GEN_U2P_INTR_INT_EN |
  157. USBINT_CFG1_USBDRD_PME_GEN_U3P_INTR_INT_EN);
  158. reg |= (USBINT_CFG1_USBDRD_PME_GEN_U2P_INTR_MSK |
  159. USBINT_CFG1_USBDRD_PME_GEN_U3P_INTR_MSK);
  160. regmap_write(google->usb_cfg_regmap,
  161. google->usbint_cfg_offset + USBINT_CFG1_OFFSET, reg);
  162. disable_irq_wake(google->hs_pme_irq);
  163. disable_irq_wake(google->ss_pme_irq);
  164. disable_irq_nosync(google->hs_pme_irq);
  165. disable_irq_nosync(google->ss_pme_irq);
  166. }
  167. static irqreturn_t dwc3_google_resume_irq(int irq, void *data)
  168. {
  169. struct dwc3_google *google = data;
  170. struct dwc3 *dwc = &google->dwc;
  171. u32 irq_status, dr_role;
  172. irq_status = dwc3_google_clear_pme_irqs(google);
  173. dr_role = dwc->current_dr_role;
  174. if (!irq_status || !google->is_hibernation ||
  175. dr_role != DWC3_GCTL_PRTCAP_HOST) {
  176. dev_dbg(google->dev, "spurious pme irq %d, hibernation %d, dr_role %u\n",
  177. irq, google->is_hibernation, dr_role);
  178. return IRQ_HANDLED;
  179. }
  180. if (dwc->xhci)
  181. pm_runtime_resume(&dwc->xhci->dev);
  182. return IRQ_HANDLED;
  183. }
  184. static int dwc3_google_request_irq(struct dwc3_google *google, struct platform_device *pdev,
  185. const char *irq_name, const char *req_name)
  186. {
  187. int ret;
  188. int irq;
  189. irq = platform_get_irq_byname(pdev, irq_name);
  190. if (irq < 0)
  191. return irq;
  192. irq_set_status_flags(irq, IRQ_NOAUTOEN);
  193. ret = devm_request_threaded_irq(google->dev, irq, NULL,
  194. dwc3_google_resume_irq,
  195. IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  196. req_name, google);
  197. if (ret < 0) {
  198. dev_err(google->dev, "failed to request irq %s\n", req_name);
  199. return ret;
  200. }
  201. return irq;
  202. }
  203. static int dwc3_google_usb_psw_pd_notifier(struct notifier_block *nb, unsigned long action, void *d)
  204. {
  205. struct dwc3_google *google = container_of(nb, struct dwc3_google, usb_psw_pd_nb);
  206. int ret;
  207. if (!google->is_hibernation)
  208. return NOTIFY_OK;
  209. if (action == GENPD_NOTIFY_OFF) {
  210. dev_dbg(google->dev, "enter D3 power state\n");
  211. dwc3_google_set_pmu_state(google, HOST_CFG1_PM_POWER_STATE_D3);
  212. ret = reset_control_assert(google->non_sticky_rst);
  213. if (ret)
  214. dev_err(google->dev, "non sticky reset assert failed: %d\n", ret);
  215. } else if (action == GENPD_NOTIFY_ON) {
  216. dev_dbg(google->dev, "enter D0 power state\n");
  217. dwc3_google_clear_pme_irqs(google);
  218. ret = reset_control_deassert(google->non_sticky_rst);
  219. if (ret)
  220. dev_err(google->dev, "non sticky reset deassert failed: %d\n", ret);
  221. dwc3_google_set_pmu_state(google, HOST_CFG1_PM_POWER_STATE_D0);
  222. }
  223. return NOTIFY_OK;
  224. }
  225. static void dwc3_google_pm_domain_deinit(struct dwc3_google *google)
  226. {
  227. if (google->usb_top_pd_dl)
  228. device_link_del(google->usb_top_pd_dl);
  229. if (!IS_ERR_OR_NULL(google->usb_top_pd)) {
  230. device_set_wakeup_capable(google->usb_top_pd, false);
  231. dev_pm_domain_detach(google->usb_top_pd, true);
  232. }
  233. if (google->usb_psw_pd_dl)
  234. device_link_del(google->usb_psw_pd_dl);
  235. if (!IS_ERR_OR_NULL(google->usb_psw_pd)) {
  236. dev_pm_genpd_remove_notifier(google->usb_psw_pd);
  237. dev_pm_domain_detach(google->usb_psw_pd, true);
  238. }
  239. }
  240. static int dwc3_google_pm_domain_init(struct dwc3_google *google)
  241. {
  242. int ret;
  243. /*
  244. * Establish PM RUNTIME link between dwc dev and its power domain usb_psw_pd,
  245. * register notifier block to handle hibernation.
  246. */
  247. google->usb_psw_pd = dev_pm_domain_attach_by_name(google->dev, "psw");
  248. if (IS_ERR_OR_NULL(google->usb_psw_pd)) {
  249. dev_err(google->dev, "failed to get psw pd");
  250. ret = google->usb_psw_pd ? PTR_ERR(google->usb_psw_pd) : -ENODATA;
  251. return ret;
  252. }
  253. google->usb_psw_pd_nb.notifier_call = dwc3_google_usb_psw_pd_notifier;
  254. ret = dev_pm_genpd_add_notifier(google->usb_psw_pd, &google->usb_psw_pd_nb);
  255. if (ret) {
  256. dev_err(google->dev, "failed to add psw pd notifier");
  257. goto err;
  258. }
  259. google->usb_psw_pd_dl = device_link_add(google->dev, google->usb_psw_pd,
  260. DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME |
  261. DL_FLAG_RPM_ACTIVE);
  262. if (!google->usb_psw_pd_dl) {
  263. dev_err(google->usb_psw_pd, "failed to add device link");
  264. ret = -ENODEV;
  265. goto err;
  266. }
  267. /*
  268. * usb_top_pd is the parent power domain of usb_psw_pd. Keeping usb_top_pd on
  269. * while usb_psw_pd is off places the controller in a power-gated state,
  270. * essential for hibernation. Acquire a handle to usb_top_pd and sets it as
  271. * wakeup-capable to allow the domain to be left on during system suspend.
  272. */
  273. google->usb_top_pd = dev_pm_domain_attach_by_name(google->dev, "top");
  274. if (IS_ERR_OR_NULL(google->usb_top_pd)) {
  275. dev_err(google->dev, "failed to get top pd");
  276. ret = google->usb_top_pd ? PTR_ERR(google->usb_top_pd) : -ENODATA;
  277. goto err;
  278. }
  279. device_set_wakeup_capable(google->usb_top_pd, true);
  280. google->usb_top_pd_dl = device_link_add(google->dev, google->usb_top_pd,
  281. DL_FLAG_STATELESS);
  282. if (!google->usb_top_pd_dl) {
  283. dev_err(google->usb_top_pd, "failed to add device link");
  284. ret = -ENODEV;
  285. goto err;
  286. }
  287. return 0;
  288. err:
  289. dwc3_google_pm_domain_deinit(google);
  290. return ret;
  291. }
  292. static void dwc3_google_program_usb2only(struct dwc3_google *google)
  293. {
  294. u32 reg;
  295. regmap_read(google->usb_cfg_regmap,
  296. google->usbint_cfg_offset + USBCS_TOP_CTRL_CFG1_OFFSET, &reg);
  297. reg |= USBCS_TOP_CTRL_CFG1_USB2ONLY_MODE;
  298. regmap_write(google->usb_cfg_regmap,
  299. google->usbint_cfg_offset + USBCS_TOP_CTRL_CFG1_OFFSET, reg);
  300. }
  301. static int dwc3_google_probe(struct platform_device *pdev)
  302. {
  303. struct dwc3_probe_data probe_data = {};
  304. struct device *dev = &pdev->dev;
  305. struct dwc3_google *google;
  306. struct resource *res;
  307. int ret;
  308. u32 args[2];
  309. google = devm_kzalloc(&pdev->dev, sizeof(*google), GFP_KERNEL);
  310. if (!google)
  311. return -ENOMEM;
  312. google->dev = &pdev->dev;
  313. ret = dwc3_google_pm_domain_init(google);
  314. if (ret < 0)
  315. return dev_err_probe(dev, ret, "failed to init pdom\n");
  316. google->usb_cfg_regmap =
  317. syscon_regmap_lookup_by_phandle_args(dev->of_node,
  318. "google,usb-cfg-csr",
  319. ARRAY_SIZE(args), args);
  320. if (IS_ERR(google->usb_cfg_regmap)) {
  321. ret = dev_err_probe(dev, PTR_ERR(google->usb_cfg_regmap),
  322. "invalid usb cfg csr\n");
  323. goto err_deinit_pdom;
  324. }
  325. google->host_cfg_offset = args[0];
  326. google->usbint_cfg_offset = args[1];
  327. if (device_property_match_string(dev, "phy-names", "usb3-phy") < 0) {
  328. google->is_usb2only = true;
  329. dwc3_google_program_usb2only(google);
  330. }
  331. ret = devm_clk_bulk_get_all_enabled(dev, &google->clks);
  332. if (ret < 0) {
  333. ret = dev_err_probe(dev, ret, "failed to get and enable clks\n");
  334. goto err_deinit_pdom;
  335. }
  336. google->num_clks = ret;
  337. ret = dwc3_google_rst_init(google);
  338. if (ret) {
  339. ret = dev_err_probe(dev, ret, "failed to get resets\n");
  340. goto err_deinit_pdom;
  341. }
  342. ret = reset_control_bulk_deassert(google->num_rsts, google->rsts);
  343. if (ret) {
  344. ret = dev_err_probe(dev, ret, "failed to deassert rsts\n");
  345. goto err_deinit_pdom;
  346. }
  347. ret = dwc3_google_request_irq(google, pdev, "hs_pme", "USB HS wakeup");
  348. if (ret < 0) {
  349. ret = dev_err_probe(dev, ret, "failed to request hs pme irq");
  350. goto err_reset_assert;
  351. }
  352. google->hs_pme_irq = ret;
  353. ret = dwc3_google_request_irq(google, pdev, "ss_pme", "USB SS wakeup");
  354. if (ret < 0) {
  355. ret = dev_err_probe(dev, ret, "failed to request ss pme irq");
  356. goto err_reset_assert;
  357. }
  358. google->ss_pme_irq = ret;
  359. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  360. if (!res) {
  361. ret = dev_err_probe(dev, -ENODEV, "invalid memory\n");
  362. goto err_reset_assert;
  363. }
  364. device_init_wakeup(dev, true);
  365. google->dwc.dev = dev;
  366. probe_data.dwc = &google->dwc;
  367. probe_data.res = res;
  368. probe_data.ignore_clocks_and_resets = true;
  369. ret = dwc3_core_probe(&probe_data);
  370. if (ret) {
  371. ret = dev_err_probe(dev, ret, "failed to register DWC3 Core\n");
  372. goto err_reset_assert;
  373. }
  374. return 0;
  375. err_reset_assert:
  376. reset_control_bulk_assert(google->num_rsts, google->rsts);
  377. err_deinit_pdom:
  378. dwc3_google_pm_domain_deinit(google);
  379. return ret;
  380. }
  381. static void dwc3_google_remove(struct platform_device *pdev)
  382. {
  383. struct dwc3 *dwc = platform_get_drvdata(pdev);
  384. struct dwc3_google *google = to_dwc3_google(dwc);
  385. dwc3_core_remove(&google->dwc);
  386. reset_control_bulk_assert(google->num_rsts, google->rsts);
  387. dwc3_google_pm_domain_deinit(google);
  388. }
  389. static int dwc3_google_suspend(struct dwc3_google *google, pm_message_t msg)
  390. {
  391. if (pm_runtime_suspended(google->dev))
  392. return 0;
  393. if (google->dwc.current_dr_role == DWC3_GCTL_PRTCAP_HOST) {
  394. /*
  395. * Follow dwc3_suspend_common() guidelines for deciding between
  396. * a full teardown and hibernation.
  397. */
  398. if (PMSG_IS_AUTO(msg) || device_may_wakeup(google->dev)) {
  399. dev_dbg(google->dev, "enter hibernation");
  400. pm_runtime_get_sync(google->usb_top_pd);
  401. device_wakeup_enable(google->usb_top_pd);
  402. dwc3_google_enable_pme_irq(google);
  403. google->is_hibernation = true;
  404. return 0;
  405. }
  406. }
  407. reset_control_bulk_assert(google->num_rsts, google->rsts);
  408. clk_bulk_disable_unprepare(google->num_clks, google->clks);
  409. return 0;
  410. }
  411. static int dwc3_google_resume(struct dwc3_google *google, pm_message_t msg)
  412. {
  413. int ret;
  414. if (google->is_hibernation) {
  415. dev_dbg(google->dev, "exit hibernation");
  416. dwc3_google_disable_pme_irq(google);
  417. device_wakeup_disable(google->usb_top_pd);
  418. pm_runtime_put_sync(google->usb_top_pd);
  419. google->is_hibernation = false;
  420. return 0;
  421. }
  422. if (google->is_usb2only)
  423. dwc3_google_program_usb2only(google);
  424. ret = clk_bulk_prepare_enable(google->num_clks, google->clks);
  425. if (ret)
  426. return ret;
  427. ret = reset_control_bulk_deassert(google->num_rsts, google->rsts);
  428. if (ret) {
  429. clk_bulk_disable_unprepare(google->num_clks, google->clks);
  430. return ret;
  431. }
  432. return 0;
  433. }
  434. static int dwc3_google_pm_suspend(struct device *dev)
  435. {
  436. struct dwc3 *dwc = dev_get_drvdata(dev);
  437. struct dwc3_google *google = to_dwc3_google(dwc);
  438. int ret;
  439. ret = dwc3_pm_suspend(&google->dwc);
  440. if (ret)
  441. return ret;
  442. return dwc3_google_suspend(google, PMSG_SUSPEND);
  443. }
  444. static int dwc3_google_pm_resume(struct device *dev)
  445. {
  446. struct dwc3 *dwc = dev_get_drvdata(dev);
  447. struct dwc3_google *google = to_dwc3_google(dwc);
  448. int ret;
  449. ret = dwc3_google_resume(google, PMSG_RESUME);
  450. if (ret)
  451. return ret;
  452. return dwc3_pm_resume(&google->dwc);
  453. }
  454. static void dwc3_google_complete(struct device *dev)
  455. {
  456. struct dwc3 *dwc = dev_get_drvdata(dev);
  457. dwc3_pm_complete(dwc);
  458. }
  459. static int dwc3_google_prepare(struct device *dev)
  460. {
  461. struct dwc3 *dwc = dev_get_drvdata(dev);
  462. return dwc3_pm_prepare(dwc);
  463. }
  464. static int dwc3_google_runtime_suspend(struct device *dev)
  465. {
  466. struct dwc3 *dwc = dev_get_drvdata(dev);
  467. struct dwc3_google *google = to_dwc3_google(dwc);
  468. int ret;
  469. ret = dwc3_runtime_suspend(&google->dwc);
  470. if (ret)
  471. return ret;
  472. return dwc3_google_suspend(google, PMSG_AUTO_SUSPEND);
  473. }
  474. static int dwc3_google_runtime_resume(struct device *dev)
  475. {
  476. struct dwc3 *dwc = dev_get_drvdata(dev);
  477. struct dwc3_google *google = to_dwc3_google(dwc);
  478. int ret;
  479. ret = dwc3_google_resume(google, PMSG_AUTO_RESUME);
  480. if (ret)
  481. return ret;
  482. return dwc3_runtime_resume(&google->dwc);
  483. }
  484. static int dwc3_google_runtime_idle(struct device *dev)
  485. {
  486. return dwc3_runtime_idle(dev_get_drvdata(dev));
  487. }
  488. static const struct dev_pm_ops dwc3_google_dev_pm_ops = {
  489. SYSTEM_SLEEP_PM_OPS(dwc3_google_pm_suspend, dwc3_google_pm_resume)
  490. RUNTIME_PM_OPS(dwc3_google_runtime_suspend, dwc3_google_runtime_resume,
  491. dwc3_google_runtime_idle)
  492. .complete = pm_sleep_ptr(dwc3_google_complete),
  493. .prepare = pm_sleep_ptr(dwc3_google_prepare),
  494. };
  495. static const struct of_device_id dwc3_google_of_match[] = {
  496. { .compatible = "google,lga-dwc3" },
  497. { }
  498. };
  499. MODULE_DEVICE_TABLE(of, dwc3_google_of_match);
  500. static struct platform_driver dwc3_google_driver = {
  501. .probe = dwc3_google_probe,
  502. .remove = dwc3_google_remove,
  503. .driver = {
  504. .name = "dwc3-google",
  505. .pm = pm_ptr(&dwc3_google_dev_pm_ops),
  506. .of_match_table = dwc3_google_of_match,
  507. },
  508. };
  509. module_platform_driver(dwc3_google_driver);
  510. MODULE_LICENSE("GPL");
  511. MODULE_DESCRIPTION("DesignWare DWC3 Google Glue Driver");