1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 * Inspired by dwc3-of-simple.c
7 #include <linux/acpi.h>
10 #include <linux/clk.h>
11 #include <linux/irq.h>
12 #include <linux/of_clk.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/extcon.h>
16 #include <linux/interconnect.h>
17 #include <linux/of_platform.h>
18 #include <linux/platform_device.h>
19 #include <linux/phy/phy.h>
20 #include <linux/usb/of.h>
21 #include <linux/reset.h>
22 #include <linux/iopoll.h>
26 /* USB QSCRATCH Hardware registers */
27 #define QSCRATCH_HS_PHY_CTRL 0x10
28 #define UTMI_OTG_VBUS_VALID BIT(20)
29 #define SW_SESSVLD_SEL BIT(28)
31 #define QSCRATCH_SS_PHY_CTRL 0x30
32 #define LANE0_PWR_PRESENT BIT(24)
34 #define QSCRATCH_GENERAL_CFG 0x08
35 #define PIPE_UTMI_CLK_SEL BIT(0)
36 #define PIPE3_PHYSTATUS_SW BIT(3)
37 #define PIPE_UTMI_CLK_DIS BIT(8)
39 #define PWR_EVNT_IRQ_STAT_REG 0x58
40 #define PWR_EVNT_LPM_IN_L2_MASK BIT(4)
41 #define PWR_EVNT_LPM_OUT_L2_MASK BIT(5)
43 #define SDM845_QSCRATCH_BASE_OFFSET 0xf8800
44 #define SDM845_QSCRATCH_SIZE 0x400
45 #define SDM845_DWC3_CORE_SIZE 0xcd00
47 /* Interconnect path bandwidths in MBps */
48 #define USB_MEMORY_AVG_HS_BW MBps_to_icc(240)
49 #define USB_MEMORY_PEAK_HS_BW MBps_to_icc(700)
50 #define USB_MEMORY_AVG_SS_BW MBps_to_icc(1000)
51 #define USB_MEMORY_PEAK_SS_BW MBps_to_icc(2500)
52 #define APPS_USB_AVG_BW 0
53 #define APPS_USB_PEAK_BW MBps_to_icc(40)
55 struct dwc3_acpi_pdata {
56 u32 qscratch_base_offset;
57 u32 qscratch_base_size;
58 u32 dwc3_core_base_size;
60 int dp_hs_phy_irq_index;
61 int dm_hs_phy_irq_index;
68 void __iomem *qscratch_base;
69 struct platform_device *dwc3;
70 struct platform_device *urs_usb;
73 struct reset_control *resets;
80 struct extcon_dev *edev;
81 struct extcon_dev *host_edev;
82 struct notifier_block vbus_nb;
83 struct notifier_block host_nb;
85 const struct dwc3_acpi_pdata *acpi_pdata;
87 enum usb_dr_mode mode;
90 struct icc_path *icc_path_ddr;
91 struct icc_path *icc_path_apps;
94 static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
98 reg = readl(base + offset);
100 writel(reg, base + offset);
102 /* ensure that above write is through */
103 readl(base + offset);
106 static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val)
110 reg = readl(base + offset);
112 writel(reg, base + offset);
114 /* ensure that above write is through */
115 readl(base + offset);
118 static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable)
121 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL,
123 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL,
124 UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL);
126 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL,
128 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL,
129 UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL);
133 static int dwc3_qcom_vbus_notifier(struct notifier_block *nb,
134 unsigned long event, void *ptr)
136 struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb);
138 /* enable vbus override for device mode */
139 dwc3_qcom_vbus_override_enable(qcom, event);
140 qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST;
145 static int dwc3_qcom_host_notifier(struct notifier_block *nb,
146 unsigned long event, void *ptr)
148 struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb);
150 /* disable vbus override in host mode */
151 dwc3_qcom_vbus_override_enable(qcom, !event);
152 qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL;
157 static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom)
159 struct device *dev = qcom->dev;
160 struct extcon_dev *host_edev;
163 if (!of_property_read_bool(dev->of_node, "extcon"))
166 qcom->edev = extcon_get_edev_by_phandle(dev, 0);
167 if (IS_ERR(qcom->edev))
168 return PTR_ERR(qcom->edev);
170 qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier;
172 qcom->host_edev = extcon_get_edev_by_phandle(dev, 1);
173 if (IS_ERR(qcom->host_edev))
174 qcom->host_edev = NULL;
176 ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB,
179 dev_err(dev, "VBUS notifier register failed\n");
184 host_edev = qcom->host_edev;
186 host_edev = qcom->edev;
188 qcom->host_nb.notifier_call = dwc3_qcom_host_notifier;
189 ret = devm_extcon_register_notifier(dev, host_edev, EXTCON_USB_HOST,
192 dev_err(dev, "Host notifier register failed\n");
196 /* Update initial VBUS override based on extcon state */
197 if (extcon_get_state(qcom->edev, EXTCON_USB) ||
198 !extcon_get_state(host_edev, EXTCON_USB_HOST))
199 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev);
201 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev);
206 static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom)
210 ret = icc_enable(qcom->icc_path_ddr);
214 ret = icc_enable(qcom->icc_path_apps);
216 icc_disable(qcom->icc_path_ddr);
221 static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom)
225 ret = icc_disable(qcom->icc_path_ddr);
229 ret = icc_disable(qcom->icc_path_apps);
231 icc_enable(qcom->icc_path_ddr);
237 * dwc3_qcom_interconnect_init() - Get interconnect path handles
238 * and set bandwidhth.
239 * @qcom: Pointer to the concerned usb core.
242 static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
244 struct device *dev = qcom->dev;
247 if (has_acpi_companion(dev))
250 qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr");
251 if (IS_ERR(qcom->icc_path_ddr)) {
252 dev_err(dev, "failed to get usb-ddr path: %ld\n",
253 PTR_ERR(qcom->icc_path_ddr));
254 return PTR_ERR(qcom->icc_path_ddr);
257 qcom->icc_path_apps = of_icc_get(dev, "apps-usb");
258 if (IS_ERR(qcom->icc_path_apps)) {
259 dev_err(dev, "failed to get apps-usb path: %ld\n",
260 PTR_ERR(qcom->icc_path_apps));
261 ret = PTR_ERR(qcom->icc_path_apps);
265 if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER ||
266 usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN)
267 ret = icc_set_bw(qcom->icc_path_ddr,
268 USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW);
270 ret = icc_set_bw(qcom->icc_path_ddr,
271 USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW);
274 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret);
278 ret = icc_set_bw(qcom->icc_path_apps,
279 APPS_USB_AVG_BW, APPS_USB_PEAK_BW);
281 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret);
288 icc_put(qcom->icc_path_apps);
290 icc_put(qcom->icc_path_ddr);
295 * dwc3_qcom_interconnect_exit() - Release interconnect path handles
296 * @qcom: Pointer to the concerned usb core.
298 * This function is used to release interconnect path handle.
300 static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
302 icc_put(qcom->icc_path_ddr);
303 icc_put(qcom->icc_path_apps);
306 /* Only usable in contexts where the role can not change. */
307 static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom)
312 * FIXME: Fix this layering violation.
314 dwc = platform_get_drvdata(qcom->dwc3);
316 /* Core driver may not have probed yet. */
323 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
325 if (qcom->hs_phy_irq) {
326 disable_irq_wake(qcom->hs_phy_irq);
327 disable_irq_nosync(qcom->hs_phy_irq);
330 if (qcom->dp_hs_phy_irq) {
331 disable_irq_wake(qcom->dp_hs_phy_irq);
332 disable_irq_nosync(qcom->dp_hs_phy_irq);
335 if (qcom->dm_hs_phy_irq) {
336 disable_irq_wake(qcom->dm_hs_phy_irq);
337 disable_irq_nosync(qcom->dm_hs_phy_irq);
340 if (qcom->ss_phy_irq) {
341 disable_irq_wake(qcom->ss_phy_irq);
342 disable_irq_nosync(qcom->ss_phy_irq);
346 static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
348 if (qcom->hs_phy_irq) {
349 enable_irq(qcom->hs_phy_irq);
350 enable_irq_wake(qcom->hs_phy_irq);
353 if (qcom->dp_hs_phy_irq) {
354 enable_irq(qcom->dp_hs_phy_irq);
355 enable_irq_wake(qcom->dp_hs_phy_irq);
358 if (qcom->dm_hs_phy_irq) {
359 enable_irq(qcom->dm_hs_phy_irq);
360 enable_irq_wake(qcom->dm_hs_phy_irq);
363 if (qcom->ss_phy_irq) {
364 enable_irq(qcom->ss_phy_irq);
365 enable_irq_wake(qcom->ss_phy_irq);
369 static int dwc3_qcom_suspend(struct dwc3_qcom *qcom)
374 if (qcom->is_suspended)
377 val = readl(qcom->qscratch_base + PWR_EVNT_IRQ_STAT_REG);
378 if (!(val & PWR_EVNT_LPM_IN_L2_MASK))
379 dev_err(qcom->dev, "HS-PHY not in L2\n");
381 for (i = qcom->num_clocks - 1; i >= 0; i--)
382 clk_disable_unprepare(qcom->clks[i]);
384 ret = dwc3_qcom_interconnect_disable(qcom);
386 dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
388 if (device_may_wakeup(qcom->dev))
389 dwc3_qcom_enable_interrupts(qcom);
391 qcom->is_suspended = true;
396 static int dwc3_qcom_resume(struct dwc3_qcom *qcom)
401 if (!qcom->is_suspended)
404 if (device_may_wakeup(qcom->dev))
405 dwc3_qcom_disable_interrupts(qcom);
407 for (i = 0; i < qcom->num_clocks; i++) {
408 ret = clk_prepare_enable(qcom->clks[i]);
411 clk_disable_unprepare(qcom->clks[i]);
416 ret = dwc3_qcom_interconnect_enable(qcom);
418 dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
420 /* Clear existing events from PHY related to L2 in/out */
421 dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG,
422 PWR_EVNT_LPM_IN_L2_MASK | PWR_EVNT_LPM_OUT_L2_MASK);
424 qcom->is_suspended = false;
429 static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data)
431 struct dwc3_qcom *qcom = data;
432 struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
434 /* If pm_suspended then let pm_resume take care of resuming h/w */
435 if (qcom->pm_suspended)
439 * This is safe as role switching is done from a freezable workqueue
440 * and the wakeup interrupts are disabled as part of resume.
442 if (dwc3_qcom_is_host(qcom))
443 pm_runtime_resume(&dwc->xhci->dev);
448 static void dwc3_qcom_select_utmi_clk(struct dwc3_qcom *qcom)
450 /* Configure dwc3 to use UTMI clock as PIPE clock not present */
451 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
454 usleep_range(100, 1000);
456 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
457 PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW);
459 usleep_range(100, 1000);
461 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG,
465 static int dwc3_qcom_get_irq(struct platform_device *pdev,
466 const char *name, int num)
468 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
469 struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev;
470 struct device_node *np = pdev->dev.of_node;
474 ret = platform_get_irq_byname_optional(pdev_irq, name);
476 ret = platform_get_irq_optional(pdev_irq, num);
481 static int dwc3_qcom_setup_irq(struct platform_device *pdev)
483 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
484 const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata;
488 irq = dwc3_qcom_get_irq(pdev, "hs_phy_irq",
489 pdata ? pdata->hs_phy_irq_index : -1);
491 /* Keep wakeup interrupts disabled until suspend */
492 irq_set_status_flags(irq, IRQ_NOAUTOEN);
493 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
494 qcom_dwc3_resume_irq,
496 "qcom_dwc3 HS", qcom);
498 dev_err(qcom->dev, "hs_phy_irq failed: %d\n", ret);
501 qcom->hs_phy_irq = irq;
504 irq = dwc3_qcom_get_irq(pdev, "dp_hs_phy_irq",
505 pdata ? pdata->dp_hs_phy_irq_index : -1);
507 irq_set_status_flags(irq, IRQ_NOAUTOEN);
508 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
509 qcom_dwc3_resume_irq,
511 "qcom_dwc3 DP_HS", qcom);
513 dev_err(qcom->dev, "dp_hs_phy_irq failed: %d\n", ret);
516 qcom->dp_hs_phy_irq = irq;
519 irq = dwc3_qcom_get_irq(pdev, "dm_hs_phy_irq",
520 pdata ? pdata->dm_hs_phy_irq_index : -1);
522 irq_set_status_flags(irq, IRQ_NOAUTOEN);
523 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
524 qcom_dwc3_resume_irq,
526 "qcom_dwc3 DM_HS", qcom);
528 dev_err(qcom->dev, "dm_hs_phy_irq failed: %d\n", ret);
531 qcom->dm_hs_phy_irq = irq;
534 irq = dwc3_qcom_get_irq(pdev, "ss_phy_irq",
535 pdata ? pdata->ss_phy_irq_index : -1);
537 irq_set_status_flags(irq, IRQ_NOAUTOEN);
538 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
539 qcom_dwc3_resume_irq,
541 "qcom_dwc3 SS", qcom);
543 dev_err(qcom->dev, "ss_phy_irq failed: %d\n", ret);
546 qcom->ss_phy_irq = irq;
552 static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count)
554 struct device *dev = qcom->dev;
555 struct device_node *np = dev->of_node;
564 qcom->num_clocks = count;
566 qcom->clks = devm_kcalloc(dev, qcom->num_clocks,
567 sizeof(struct clk *), GFP_KERNEL);
571 for (i = 0; i < qcom->num_clocks; i++) {
575 clk = of_clk_get(np, i);
578 clk_put(qcom->clks[i]);
582 ret = clk_prepare_enable(clk);
585 clk_disable_unprepare(qcom->clks[i]);
586 clk_put(qcom->clks[i]);
599 static const struct property_entry dwc3_qcom_acpi_properties[] = {
600 PROPERTY_ENTRY_STRING("dr_mode", "host"),
604 static int dwc3_qcom_acpi_register_core(struct platform_device *pdev)
606 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
607 struct device *dev = &pdev->dev;
608 struct resource *res, *child_res = NULL;
609 struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb :
614 qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
618 qcom->dwc3->dev.parent = dev;
619 qcom->dwc3->dev.type = dev->type;
620 qcom->dwc3->dev.dma_mask = dev->dma_mask;
621 qcom->dwc3->dev.dma_parms = dev->dma_parms;
622 qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask;
624 child_res = kcalloc(2, sizeof(*child_res), GFP_KERNEL);
628 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
630 dev_err(&pdev->dev, "failed to get memory resource\n");
635 child_res[0].flags = res->flags;
636 child_res[0].start = res->start;
637 child_res[0].end = child_res[0].start +
638 qcom->acpi_pdata->dwc3_core_base_size;
640 irq = platform_get_irq(pdev_irq, 0);
645 child_res[1].flags = IORESOURCE_IRQ;
646 child_res[1].start = child_res[1].end = irq;
648 ret = platform_device_add_resources(qcom->dwc3, child_res, 2);
650 dev_err(&pdev->dev, "failed to add resources\n");
654 ret = platform_device_add_properties(qcom->dwc3,
655 dwc3_qcom_acpi_properties);
657 dev_err(&pdev->dev, "failed to add properties\n");
661 ret = platform_device_add(qcom->dwc3);
663 dev_err(&pdev->dev, "failed to add device\n");
670 static int dwc3_qcom_of_register_core(struct platform_device *pdev)
672 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
673 struct device_node *np = pdev->dev.of_node, *dwc3_np;
674 struct device *dev = &pdev->dev;
677 dwc3_np = of_get_child_by_name(np, "dwc3");
679 dev_err(dev, "failed to find dwc3 core child\n");
683 ret = of_platform_populate(np, NULL, NULL, dev);
685 dev_err(dev, "failed to register dwc3 core - %d\n", ret);
689 qcom->dwc3 = of_find_device_by_node(dwc3_np);
692 dev_err(dev, "failed to get dwc3 platform device\n");
693 of_platform_depopulate(dev);
697 of_node_put(dwc3_np);
702 static struct platform_device *dwc3_qcom_create_urs_usb_platdev(struct device *dev)
704 struct platform_device *urs_usb = NULL;
705 struct fwnode_handle *fwh;
706 struct acpi_device *adev;
711 /* Figure out device id */
712 ret = sscanf(fwnode_get_name(dev->fwnode), "URS%d", &id);
716 /* Find the child using name */
717 snprintf(name, sizeof(name), "USB%d", id);
718 fwh = fwnode_get_named_child_node(dev->fwnode, name);
722 adev = to_acpi_device_node(fwh);
726 urs_usb = acpi_create_platform_device(adev, NULL);
727 if (IS_ERR_OR_NULL(urs_usb))
733 fwnode_handle_put(fwh);
738 static void dwc3_qcom_destroy_urs_usb_platdev(struct platform_device *urs_usb)
740 struct fwnode_handle *fwh = urs_usb->dev.fwnode;
742 platform_device_unregister(urs_usb);
743 fwnode_handle_put(fwh);
746 static int dwc3_qcom_probe(struct platform_device *pdev)
748 struct device_node *np = pdev->dev.of_node;
749 struct device *dev = &pdev->dev;
750 struct dwc3_qcom *qcom;
751 struct resource *res, *parent_res = NULL;
752 struct resource local_res;
754 bool ignore_pipe_clk;
756 qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL);
760 platform_set_drvdata(pdev, qcom);
761 qcom->dev = &pdev->dev;
763 if (has_acpi_companion(dev)) {
764 qcom->acpi_pdata = acpi_device_get_match_data(dev);
765 if (!qcom->acpi_pdata) {
766 dev_err(&pdev->dev, "no supporting ACPI device data\n");
771 qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
772 if (IS_ERR(qcom->resets)) {
773 ret = PTR_ERR(qcom->resets);
774 dev_err(&pdev->dev, "failed to get resets, err=%d\n", ret);
778 ret = reset_control_assert(qcom->resets);
780 dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
784 usleep_range(10, 1000);
786 ret = reset_control_deassert(qcom->resets);
788 dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
792 ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
794 dev_err(dev, "failed to get clocks\n");
798 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
803 memcpy(&local_res, res, sizeof(struct resource));
804 parent_res = &local_res;
806 parent_res->start = res->start +
807 qcom->acpi_pdata->qscratch_base_offset;
808 parent_res->end = parent_res->start +
809 qcom->acpi_pdata->qscratch_base_size;
811 if (qcom->acpi_pdata->is_urs) {
812 qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev);
813 if (IS_ERR_OR_NULL(qcom->urs_usb)) {
814 dev_err(dev, "failed to create URS USB platdev\n");
818 ret = PTR_ERR(qcom->urs_usb);
824 qcom->qscratch_base = devm_ioremap_resource(dev, parent_res);
825 if (IS_ERR(qcom->qscratch_base)) {
826 dev_err(dev, "failed to map qscratch, err=%d\n", ret);
827 ret = PTR_ERR(qcom->qscratch_base);
831 ret = dwc3_qcom_setup_irq(pdev);
833 dev_err(dev, "failed to setup IRQs, err=%d\n", ret);
838 * Disable pipe_clk requirement if specified. Used when dwc3
839 * operates without SSPHY and only HS/FS/LS modes are supported.
841 ignore_pipe_clk = device_property_read_bool(dev,
842 "qcom,select-utmi-as-pipe-clk");
844 dwc3_qcom_select_utmi_clk(qcom);
847 ret = dwc3_qcom_of_register_core(pdev);
849 ret = dwc3_qcom_acpi_register_core(pdev);
852 dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret);
856 ret = dwc3_qcom_interconnect_init(qcom);
860 qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev);
862 /* enable vbus override for device mode */
863 if (qcom->mode != USB_DR_MODE_HOST)
864 dwc3_qcom_vbus_override_enable(qcom, true);
866 /* register extcon to override sw_vbus on Vbus change later */
867 ret = dwc3_qcom_register_extcon(qcom);
869 goto interconnect_exit;
871 device_init_wakeup(&pdev->dev, 1);
872 qcom->is_suspended = false;
873 pm_runtime_set_active(dev);
874 pm_runtime_enable(dev);
875 pm_runtime_forbid(dev);
880 dwc3_qcom_interconnect_exit(qcom);
883 of_platform_depopulate(&pdev->dev);
885 platform_device_del(qcom->dwc3);
886 platform_device_put(qcom->dwc3);
889 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
891 for (i = qcom->num_clocks - 1; i >= 0; i--) {
892 clk_disable_unprepare(qcom->clks[i]);
893 clk_put(qcom->clks[i]);
896 reset_control_assert(qcom->resets);
901 static int dwc3_qcom_remove(struct platform_device *pdev)
903 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
904 struct device_node *np = pdev->dev.of_node;
905 struct device *dev = &pdev->dev;
909 of_platform_depopulate(&pdev->dev);
911 platform_device_del(qcom->dwc3);
912 platform_device_put(qcom->dwc3);
915 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
917 for (i = qcom->num_clocks - 1; i >= 0; i--) {
918 clk_disable_unprepare(qcom->clks[i]);
919 clk_put(qcom->clks[i]);
921 qcom->num_clocks = 0;
923 dwc3_qcom_interconnect_exit(qcom);
924 reset_control_assert(qcom->resets);
926 pm_runtime_allow(dev);
927 pm_runtime_disable(dev);
932 static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev)
934 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
937 ret = dwc3_qcom_suspend(qcom);
939 qcom->pm_suspended = true;
944 static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev)
946 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
949 ret = dwc3_qcom_resume(qcom);
951 qcom->pm_suspended = false;
956 static int __maybe_unused dwc3_qcom_runtime_suspend(struct device *dev)
958 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
960 return dwc3_qcom_suspend(qcom);
963 static int __maybe_unused dwc3_qcom_runtime_resume(struct device *dev)
965 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
967 return dwc3_qcom_resume(qcom);
970 static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = {
971 SET_SYSTEM_SLEEP_PM_OPS(dwc3_qcom_pm_suspend, dwc3_qcom_pm_resume)
972 SET_RUNTIME_PM_OPS(dwc3_qcom_runtime_suspend, dwc3_qcom_runtime_resume,
976 static const struct of_device_id dwc3_qcom_of_match[] = {
977 { .compatible = "qcom,dwc3" },
978 { .compatible = "qcom,msm8996-dwc3" },
979 { .compatible = "qcom,msm8998-dwc3" },
980 { .compatible = "qcom,sdm845-dwc3" },
983 MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match);
986 static const struct dwc3_acpi_pdata sdm845_acpi_pdata = {
987 .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET,
988 .qscratch_base_size = SDM845_QSCRATCH_SIZE,
989 .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE,
990 .hs_phy_irq_index = 1,
991 .dp_hs_phy_irq_index = 4,
992 .dm_hs_phy_irq_index = 3,
993 .ss_phy_irq_index = 2
996 static const struct dwc3_acpi_pdata sdm845_acpi_urs_pdata = {
997 .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET,
998 .qscratch_base_size = SDM845_QSCRATCH_SIZE,
999 .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE,
1000 .hs_phy_irq_index = 1,
1001 .dp_hs_phy_irq_index = 4,
1002 .dm_hs_phy_irq_index = 3,
1003 .ss_phy_irq_index = 2,
1007 static const struct acpi_device_id dwc3_qcom_acpi_match[] = {
1008 { "QCOM2430", (unsigned long)&sdm845_acpi_pdata },
1009 { "QCOM0304", (unsigned long)&sdm845_acpi_urs_pdata },
1010 { "QCOM0497", (unsigned long)&sdm845_acpi_urs_pdata },
1011 { "QCOM04A6", (unsigned long)&sdm845_acpi_pdata },
1014 MODULE_DEVICE_TABLE(acpi, dwc3_qcom_acpi_match);
1017 static struct platform_driver dwc3_qcom_driver = {
1018 .probe = dwc3_qcom_probe,
1019 .remove = dwc3_qcom_remove,
1021 .name = "dwc3-qcom",
1022 .pm = &dwc3_qcom_dev_pm_ops,
1023 .of_match_table = dwc3_qcom_of_match,
1024 .acpi_match_table = ACPI_PTR(dwc3_qcom_acpi_match),
1028 module_platform_driver(dwc3_qcom_driver);
1030 MODULE_LICENSE("GPL v2");
1031 MODULE_DESCRIPTION("DesignWare DWC3 QCOM Glue Driver");