Lines Matching +full:sdm845 +full:- +full:dwc3
1 // SPDX-License-Identifier: GPL-2.0
4 * Inspired by dwc3-of-simple.c
69 struct platform_device *dwc3; member
121 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
123 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
126 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
128 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
140 qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; in dwc3_qcom_vbus_notifier()
152 qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; in dwc3_qcom_host_notifier()
159 struct device *dev = qcom->dev; in dwc3_qcom_register_extcon()
163 if (!of_property_read_bool(dev->of_node, "extcon")) in dwc3_qcom_register_extcon()
166 qcom->edev = extcon_get_edev_by_phandle(dev, 0); in dwc3_qcom_register_extcon()
167 if (IS_ERR(qcom->edev)) in dwc3_qcom_register_extcon()
168 return PTR_ERR(qcom->edev); in dwc3_qcom_register_extcon()
170 qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier; in dwc3_qcom_register_extcon()
172 qcom->host_edev = extcon_get_edev_by_phandle(dev, 1); in dwc3_qcom_register_extcon()
173 if (IS_ERR(qcom->host_edev)) in dwc3_qcom_register_extcon()
174 qcom->host_edev = NULL; in dwc3_qcom_register_extcon()
176 ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB, in dwc3_qcom_register_extcon()
177 &qcom->vbus_nb); in dwc3_qcom_register_extcon()
183 if (qcom->host_edev) in dwc3_qcom_register_extcon()
184 host_edev = qcom->host_edev; in dwc3_qcom_register_extcon()
186 host_edev = qcom->edev; in dwc3_qcom_register_extcon()
188 qcom->host_nb.notifier_call = dwc3_qcom_host_notifier; in dwc3_qcom_register_extcon()
190 &qcom->host_nb); in dwc3_qcom_register_extcon()
197 if (extcon_get_state(qcom->edev, EXTCON_USB) || in dwc3_qcom_register_extcon()
199 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev); in dwc3_qcom_register_extcon()
201 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev); in dwc3_qcom_register_extcon()
210 ret = icc_enable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_enable()
214 ret = icc_enable(qcom->icc_path_apps); in dwc3_qcom_interconnect_enable()
216 icc_disable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_enable()
225 ret = icc_disable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_disable()
229 ret = icc_disable(qcom->icc_path_apps); in dwc3_qcom_interconnect_disable()
231 icc_enable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_disable()
237 * dwc3_qcom_interconnect_init() - Get interconnect path handles
244 struct device *dev = qcom->dev; in dwc3_qcom_interconnect_init()
250 qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); in dwc3_qcom_interconnect_init()
251 if (IS_ERR(qcom->icc_path_ddr)) { in dwc3_qcom_interconnect_init()
252 dev_err(dev, "failed to get usb-ddr path: %ld\n", in dwc3_qcom_interconnect_init()
253 PTR_ERR(qcom->icc_path_ddr)); in dwc3_qcom_interconnect_init()
254 return PTR_ERR(qcom->icc_path_ddr); in dwc3_qcom_interconnect_init()
257 qcom->icc_path_apps = of_icc_get(dev, "apps-usb"); in dwc3_qcom_interconnect_init()
258 if (IS_ERR(qcom->icc_path_apps)) { in dwc3_qcom_interconnect_init()
259 dev_err(dev, "failed to get apps-usb path: %ld\n", in dwc3_qcom_interconnect_init()
260 PTR_ERR(qcom->icc_path_apps)); in dwc3_qcom_interconnect_init()
261 ret = PTR_ERR(qcom->icc_path_apps); in dwc3_qcom_interconnect_init()
265 if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER || in dwc3_qcom_interconnect_init()
266 usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN) in dwc3_qcom_interconnect_init()
267 ret = icc_set_bw(qcom->icc_path_ddr, in dwc3_qcom_interconnect_init()
270 ret = icc_set_bw(qcom->icc_path_ddr, in dwc3_qcom_interconnect_init()
274 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); in dwc3_qcom_interconnect_init()
278 ret = icc_set_bw(qcom->icc_path_apps, in dwc3_qcom_interconnect_init()
281 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); in dwc3_qcom_interconnect_init()
288 icc_put(qcom->icc_path_apps); in dwc3_qcom_interconnect_init()
290 icc_put(qcom->icc_path_ddr); in dwc3_qcom_interconnect_init()
295 * dwc3_qcom_interconnect_exit() - Release interconnect path handles
302 icc_put(qcom->icc_path_ddr); in dwc3_qcom_interconnect_exit()
303 icc_put(qcom->icc_path_apps); in dwc3_qcom_interconnect_exit()
309 struct dwc3 *dwc; in dwc3_qcom_is_host()
314 dwc = platform_get_drvdata(qcom->dwc3); in dwc3_qcom_is_host()
320 return dwc->xhci; in dwc3_qcom_is_host()
325 if (qcom->hs_phy_irq) { in dwc3_qcom_disable_interrupts()
326 disable_irq_wake(qcom->hs_phy_irq); in dwc3_qcom_disable_interrupts()
327 disable_irq_nosync(qcom->hs_phy_irq); in dwc3_qcom_disable_interrupts()
330 if (qcom->dp_hs_phy_irq) { in dwc3_qcom_disable_interrupts()
331 disable_irq_wake(qcom->dp_hs_phy_irq); in dwc3_qcom_disable_interrupts()
332 disable_irq_nosync(qcom->dp_hs_phy_irq); in dwc3_qcom_disable_interrupts()
335 if (qcom->dm_hs_phy_irq) { in dwc3_qcom_disable_interrupts()
336 disable_irq_wake(qcom->dm_hs_phy_irq); in dwc3_qcom_disable_interrupts()
337 disable_irq_nosync(qcom->dm_hs_phy_irq); in dwc3_qcom_disable_interrupts()
340 if (qcom->ss_phy_irq) { in dwc3_qcom_disable_interrupts()
341 disable_irq_wake(qcom->ss_phy_irq); in dwc3_qcom_disable_interrupts()
342 disable_irq_nosync(qcom->ss_phy_irq); in dwc3_qcom_disable_interrupts()
348 if (qcom->hs_phy_irq) { in dwc3_qcom_enable_interrupts()
349 enable_irq(qcom->hs_phy_irq); in dwc3_qcom_enable_interrupts()
350 enable_irq_wake(qcom->hs_phy_irq); in dwc3_qcom_enable_interrupts()
353 if (qcom->dp_hs_phy_irq) { in dwc3_qcom_enable_interrupts()
354 enable_irq(qcom->dp_hs_phy_irq); in dwc3_qcom_enable_interrupts()
355 enable_irq_wake(qcom->dp_hs_phy_irq); in dwc3_qcom_enable_interrupts()
358 if (qcom->dm_hs_phy_irq) { in dwc3_qcom_enable_interrupts()
359 enable_irq(qcom->dm_hs_phy_irq); in dwc3_qcom_enable_interrupts()
360 enable_irq_wake(qcom->dm_hs_phy_irq); in dwc3_qcom_enable_interrupts()
363 if (qcom->ss_phy_irq) { in dwc3_qcom_enable_interrupts()
364 enable_irq(qcom->ss_phy_irq); in dwc3_qcom_enable_interrupts()
365 enable_irq_wake(qcom->ss_phy_irq); in dwc3_qcom_enable_interrupts()
374 if (qcom->is_suspended) in dwc3_qcom_suspend()
377 val = readl(qcom->qscratch_base + PWR_EVNT_IRQ_STAT_REG); in dwc3_qcom_suspend()
379 dev_err(qcom->dev, "HS-PHY not in L2\n"); in dwc3_qcom_suspend()
381 for (i = qcom->num_clocks - 1; i >= 0; i--) in dwc3_qcom_suspend()
382 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_suspend()
386 dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); in dwc3_qcom_suspend()
388 if (device_may_wakeup(qcom->dev)) in dwc3_qcom_suspend()
391 qcom->is_suspended = true; in dwc3_qcom_suspend()
401 if (!qcom->is_suspended) in dwc3_qcom_resume()
404 if (device_may_wakeup(qcom->dev)) in dwc3_qcom_resume()
407 for (i = 0; i < qcom->num_clocks; i++) { in dwc3_qcom_resume()
408 ret = clk_prepare_enable(qcom->clks[i]); in dwc3_qcom_resume()
410 while (--i >= 0) in dwc3_qcom_resume()
411 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_resume()
418 dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret); in dwc3_qcom_resume()
421 dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG, in dwc3_qcom_resume()
424 qcom->is_suspended = false; in dwc3_qcom_resume()
432 struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); in qcom_dwc3_resume_irq()
435 if (qcom->pm_suspended) in qcom_dwc3_resume_irq()
443 pm_runtime_resume(&dwc->xhci->dev); in qcom_dwc3_resume_irq()
450 /* Configure dwc3 to use UTMI clock as PIPE clock not present */ in dwc3_qcom_select_utmi_clk()
451 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
456 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
461 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
469 struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev; in dwc3_qcom_get_irq()
470 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_get_irq()
484 const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; in dwc3_qcom_setup_irq()
489 pdata ? pdata->hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
493 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
498 dev_err(qcom->dev, "hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
501 qcom->hs_phy_irq = irq; in dwc3_qcom_setup_irq()
505 pdata ? pdata->dp_hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
508 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
513 dev_err(qcom->dev, "dp_hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
516 qcom->dp_hs_phy_irq = irq; in dwc3_qcom_setup_irq()
520 pdata ? pdata->dm_hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
523 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
528 dev_err(qcom->dev, "dm_hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
531 qcom->dm_hs_phy_irq = irq; in dwc3_qcom_setup_irq()
535 pdata ? pdata->ss_phy_irq_index : -1); in dwc3_qcom_setup_irq()
538 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
543 dev_err(qcom->dev, "ss_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
546 qcom->ss_phy_irq = irq; in dwc3_qcom_setup_irq()
554 struct device *dev = qcom->dev; in dwc3_qcom_clk_init()
555 struct device_node *np = dev->of_node; in dwc3_qcom_clk_init()
564 qcom->num_clocks = count; in dwc3_qcom_clk_init()
566 qcom->clks = devm_kcalloc(dev, qcom->num_clocks, in dwc3_qcom_clk_init()
568 if (!qcom->clks) in dwc3_qcom_clk_init()
569 return -ENOMEM; in dwc3_qcom_clk_init()
571 for (i = 0; i < qcom->num_clocks; i++) { in dwc3_qcom_clk_init()
577 while (--i >= 0) in dwc3_qcom_clk_init()
578 clk_put(qcom->clks[i]); in dwc3_qcom_clk_init()
584 while (--i >= 0) { in dwc3_qcom_clk_init()
585 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_clk_init()
586 clk_put(qcom->clks[i]); in dwc3_qcom_clk_init()
593 qcom->clks[i] = clk; in dwc3_qcom_clk_init()
607 struct device *dev = &pdev->dev; in dwc3_qcom_acpi_register_core()
609 struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : in dwc3_qcom_acpi_register_core()
614 qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); in dwc3_qcom_acpi_register_core()
615 if (!qcom->dwc3) in dwc3_qcom_acpi_register_core()
616 return -ENOMEM; in dwc3_qcom_acpi_register_core()
618 qcom->dwc3->dev.parent = dev; in dwc3_qcom_acpi_register_core()
619 qcom->dwc3->dev.type = dev->type; in dwc3_qcom_acpi_register_core()
620 qcom->dwc3->dev.dma_mask = dev->dma_mask; in dwc3_qcom_acpi_register_core()
621 qcom->dwc3->dev.dma_parms = dev->dma_parms; in dwc3_qcom_acpi_register_core()
622 qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask; in dwc3_qcom_acpi_register_core()
626 platform_device_put(qcom->dwc3); in dwc3_qcom_acpi_register_core()
627 return -ENOMEM; in dwc3_qcom_acpi_register_core()
632 dev_err(&pdev->dev, "failed to get memory resource\n"); in dwc3_qcom_acpi_register_core()
633 ret = -ENODEV; in dwc3_qcom_acpi_register_core()
637 child_res[0].flags = res->flags; in dwc3_qcom_acpi_register_core()
638 child_res[0].start = res->start; in dwc3_qcom_acpi_register_core()
640 qcom->acpi_pdata->dwc3_core_base_size; in dwc3_qcom_acpi_register_core()
650 ret = platform_device_add_resources(qcom->dwc3, child_res, 2); in dwc3_qcom_acpi_register_core()
652 dev_err(&pdev->dev, "failed to add resources\n"); in dwc3_qcom_acpi_register_core()
656 ret = platform_device_add_properties(qcom->dwc3, in dwc3_qcom_acpi_register_core()
659 dev_err(&pdev->dev, "failed to add properties\n"); in dwc3_qcom_acpi_register_core()
663 ret = platform_device_add(qcom->dwc3); in dwc3_qcom_acpi_register_core()
665 dev_err(&pdev->dev, "failed to add device\n"); in dwc3_qcom_acpi_register_core()
672 platform_device_put(qcom->dwc3); in dwc3_qcom_acpi_register_core()
680 struct device_node *np = pdev->dev.of_node, *dwc3_np; in dwc3_qcom_of_register_core()
681 struct device *dev = &pdev->dev; in dwc3_qcom_of_register_core()
684 dwc3_np = of_get_child_by_name(np, "dwc3"); in dwc3_qcom_of_register_core()
686 dev_err(dev, "failed to find dwc3 core child\n"); in dwc3_qcom_of_register_core()
687 return -ENODEV; in dwc3_qcom_of_register_core()
692 dev_err(dev, "failed to register dwc3 core - %d\n", ret); in dwc3_qcom_of_register_core()
696 qcom->dwc3 = of_find_device_by_node(dwc3_np); in dwc3_qcom_of_register_core()
697 if (!qcom->dwc3) { in dwc3_qcom_of_register_core()
698 ret = -ENODEV; in dwc3_qcom_of_register_core()
699 dev_err(dev, "failed to get dwc3 platform device\n"); in dwc3_qcom_of_register_core()
719 ret = sscanf(fwnode_get_name(dev->fwnode), "URS%d", &id); in dwc3_qcom_create_urs_usb_platdev()
725 fwh = fwnode_get_named_child_node(dev->fwnode, name); in dwc3_qcom_create_urs_usb_platdev()
747 struct fwnode_handle *fwh = urs_usb->dev.fwnode; in dwc3_qcom_destroy_urs_usb_platdev()
755 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_probe()
756 struct device *dev = &pdev->dev; in dwc3_qcom_probe()
763 qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); in dwc3_qcom_probe()
765 return -ENOMEM; in dwc3_qcom_probe()
768 qcom->dev = &pdev->dev; in dwc3_qcom_probe()
771 qcom->acpi_pdata = acpi_device_get_match_data(dev); in dwc3_qcom_probe()
772 if (!qcom->acpi_pdata) { in dwc3_qcom_probe()
773 dev_err(&pdev->dev, "no supporting ACPI device data\n"); in dwc3_qcom_probe()
774 return -EINVAL; in dwc3_qcom_probe()
778 qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); in dwc3_qcom_probe()
779 if (IS_ERR(qcom->resets)) { in dwc3_qcom_probe()
780 ret = PTR_ERR(qcom->resets); in dwc3_qcom_probe()
781 dev_err(&pdev->dev, "failed to get resets, err=%d\n", ret); in dwc3_qcom_probe()
785 ret = reset_control_assert(qcom->resets); in dwc3_qcom_probe()
787 dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret); in dwc3_qcom_probe()
793 ret = reset_control_deassert(qcom->resets); in dwc3_qcom_probe()
795 dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret); in dwc3_qcom_probe()
813 parent_res->start = res->start + in dwc3_qcom_probe()
814 qcom->acpi_pdata->qscratch_base_offset; in dwc3_qcom_probe()
815 parent_res->end = parent_res->start + in dwc3_qcom_probe()
816 qcom->acpi_pdata->qscratch_base_size; in dwc3_qcom_probe()
818 if (qcom->acpi_pdata->is_urs) { in dwc3_qcom_probe()
819 qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev); in dwc3_qcom_probe()
820 if (IS_ERR_OR_NULL(qcom->urs_usb)) { in dwc3_qcom_probe()
822 if (!qcom->urs_usb) in dwc3_qcom_probe()
823 ret = -ENODEV; in dwc3_qcom_probe()
825 ret = PTR_ERR(qcom->urs_usb); in dwc3_qcom_probe()
831 qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); in dwc3_qcom_probe()
832 if (IS_ERR(qcom->qscratch_base)) { in dwc3_qcom_probe()
834 ret = PTR_ERR(qcom->qscratch_base); in dwc3_qcom_probe()
845 * Disable pipe_clk requirement if specified. Used when dwc3 in dwc3_qcom_probe()
849 "qcom,select-utmi-as-pipe-clk"); in dwc3_qcom_probe()
859 dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); in dwc3_qcom_probe()
867 qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev); in dwc3_qcom_probe()
870 if (qcom->mode != USB_DR_MODE_HOST) in dwc3_qcom_probe()
878 device_init_wakeup(&pdev->dev, 1); in dwc3_qcom_probe()
879 qcom->is_suspended = false; in dwc3_qcom_probe()
890 of_platform_depopulate(&pdev->dev); in dwc3_qcom_probe()
892 platform_device_del(qcom->dwc3); in dwc3_qcom_probe()
893 platform_device_put(qcom->dwc3); in dwc3_qcom_probe()
895 if (qcom->urs_usb) in dwc3_qcom_probe()
896 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); in dwc3_qcom_probe()
898 for (i = qcom->num_clocks - 1; i >= 0; i--) { in dwc3_qcom_probe()
899 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_probe()
900 clk_put(qcom->clks[i]); in dwc3_qcom_probe()
903 reset_control_assert(qcom->resets); in dwc3_qcom_probe()
911 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_remove()
912 struct device *dev = &pdev->dev; in dwc3_qcom_remove()
916 of_platform_depopulate(&pdev->dev); in dwc3_qcom_remove()
918 platform_device_del(qcom->dwc3); in dwc3_qcom_remove()
919 platform_device_put(qcom->dwc3); in dwc3_qcom_remove()
921 if (qcom->urs_usb) in dwc3_qcom_remove()
922 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); in dwc3_qcom_remove()
924 for (i = qcom->num_clocks - 1; i >= 0; i--) { in dwc3_qcom_remove()
925 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_remove()
926 clk_put(qcom->clks[i]); in dwc3_qcom_remove()
928 qcom->num_clocks = 0; in dwc3_qcom_remove()
931 reset_control_assert(qcom->resets); in dwc3_qcom_remove()
946 qcom->pm_suspended = true; in dwc3_qcom_pm_suspend()
958 qcom->pm_suspended = false; in dwc3_qcom_pm_resume()
984 { .compatible = "qcom,dwc3" },
985 { .compatible = "qcom,msm8996-dwc3" },
986 { .compatible = "qcom,msm8998-dwc3" },
987 { .compatible = "qcom,sdm845-dwc3" },
1028 .name = "dwc3-qcom",
1038 MODULE_DESCRIPTION("DesignWare DWC3 QCOM Glue Driver");