Lines Matching +full:sdm845 +full:- +full:dwc3

1 // SPDX-License-Identifier: GPL-2.0
4 * Inspired by dwc3-of-simple.c
68 struct platform_device *dwc3; member
119 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, in dwc3_qcom_vbus_overrride_enable()
121 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, in dwc3_qcom_vbus_overrride_enable()
124 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, in dwc3_qcom_vbus_overrride_enable()
126 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, in dwc3_qcom_vbus_overrride_enable()
138 qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; in dwc3_qcom_vbus_notifier()
150 qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; in dwc3_qcom_host_notifier()
157 struct device *dev = qcom->dev; in dwc3_qcom_register_extcon()
161 if (!of_property_read_bool(dev->of_node, "extcon")) in dwc3_qcom_register_extcon()
164 qcom->edev = extcon_get_edev_by_phandle(dev, 0); in dwc3_qcom_register_extcon()
165 if (IS_ERR(qcom->edev)) in dwc3_qcom_register_extcon()
166 return PTR_ERR(qcom->edev); in dwc3_qcom_register_extcon()
168 qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier; in dwc3_qcom_register_extcon()
170 qcom->host_edev = extcon_get_edev_by_phandle(dev, 1); in dwc3_qcom_register_extcon()
171 if (IS_ERR(qcom->host_edev)) in dwc3_qcom_register_extcon()
172 qcom->host_edev = NULL; in dwc3_qcom_register_extcon()
174 ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB, in dwc3_qcom_register_extcon()
175 &qcom->vbus_nb); in dwc3_qcom_register_extcon()
181 if (qcom->host_edev) in dwc3_qcom_register_extcon()
182 host_edev = qcom->host_edev; in dwc3_qcom_register_extcon()
184 host_edev = qcom->edev; in dwc3_qcom_register_extcon()
186 qcom->host_nb.notifier_call = dwc3_qcom_host_notifier; in dwc3_qcom_register_extcon()
188 &qcom->host_nb); in dwc3_qcom_register_extcon()
195 if (extcon_get_state(qcom->edev, EXTCON_USB) || in dwc3_qcom_register_extcon()
197 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev); in dwc3_qcom_register_extcon()
199 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev); in dwc3_qcom_register_extcon()
208 ret = icc_enable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_enable()
212 ret = icc_enable(qcom->icc_path_apps); in dwc3_qcom_interconnect_enable()
214 icc_disable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_enable()
223 ret = icc_disable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_disable()
227 ret = icc_disable(qcom->icc_path_apps); in dwc3_qcom_interconnect_disable()
229 icc_enable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_disable()
235 * dwc3_qcom_interconnect_init() - Get interconnect path handles
242 struct device *dev = qcom->dev; in dwc3_qcom_interconnect_init()
245 qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); in dwc3_qcom_interconnect_init()
246 if (IS_ERR(qcom->icc_path_ddr)) { in dwc3_qcom_interconnect_init()
247 dev_err(dev, "failed to get usb-ddr path: %ld\n", in dwc3_qcom_interconnect_init()
248 PTR_ERR(qcom->icc_path_ddr)); in dwc3_qcom_interconnect_init()
249 return PTR_ERR(qcom->icc_path_ddr); in dwc3_qcom_interconnect_init()
252 qcom->icc_path_apps = of_icc_get(dev, "apps-usb"); in dwc3_qcom_interconnect_init()
253 if (IS_ERR(qcom->icc_path_apps)) { in dwc3_qcom_interconnect_init()
254 dev_err(dev, "failed to get apps-usb path: %ld\n", in dwc3_qcom_interconnect_init()
255 PTR_ERR(qcom->icc_path_apps)); in dwc3_qcom_interconnect_init()
256 return PTR_ERR(qcom->icc_path_apps); in dwc3_qcom_interconnect_init()
259 if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER || in dwc3_qcom_interconnect_init()
260 usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN) in dwc3_qcom_interconnect_init()
261 ret = icc_set_bw(qcom->icc_path_ddr, in dwc3_qcom_interconnect_init()
264 ret = icc_set_bw(qcom->icc_path_ddr, in dwc3_qcom_interconnect_init()
268 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); in dwc3_qcom_interconnect_init()
272 ret = icc_set_bw(qcom->icc_path_apps, in dwc3_qcom_interconnect_init()
275 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); in dwc3_qcom_interconnect_init()
283 * dwc3_qcom_interconnect_exit() - Release interconnect path handles
290 icc_put(qcom->icc_path_ddr); in dwc3_qcom_interconnect_exit()
291 icc_put(qcom->icc_path_apps); in dwc3_qcom_interconnect_exit()
296 if (qcom->hs_phy_irq) { in dwc3_qcom_disable_interrupts()
297 disable_irq_wake(qcom->hs_phy_irq); in dwc3_qcom_disable_interrupts()
298 disable_irq_nosync(qcom->hs_phy_irq); in dwc3_qcom_disable_interrupts()
301 if (qcom->dp_hs_phy_irq) { in dwc3_qcom_disable_interrupts()
302 disable_irq_wake(qcom->dp_hs_phy_irq); in dwc3_qcom_disable_interrupts()
303 disable_irq_nosync(qcom->dp_hs_phy_irq); in dwc3_qcom_disable_interrupts()
306 if (qcom->dm_hs_phy_irq) { in dwc3_qcom_disable_interrupts()
307 disable_irq_wake(qcom->dm_hs_phy_irq); in dwc3_qcom_disable_interrupts()
308 disable_irq_nosync(qcom->dm_hs_phy_irq); in dwc3_qcom_disable_interrupts()
311 if (qcom->ss_phy_irq) { in dwc3_qcom_disable_interrupts()
312 disable_irq_wake(qcom->ss_phy_irq); in dwc3_qcom_disable_interrupts()
313 disable_irq_nosync(qcom->ss_phy_irq); in dwc3_qcom_disable_interrupts()
319 if (qcom->hs_phy_irq) { in dwc3_qcom_enable_interrupts()
320 enable_irq(qcom->hs_phy_irq); in dwc3_qcom_enable_interrupts()
321 enable_irq_wake(qcom->hs_phy_irq); in dwc3_qcom_enable_interrupts()
324 if (qcom->dp_hs_phy_irq) { in dwc3_qcom_enable_interrupts()
325 enable_irq(qcom->dp_hs_phy_irq); in dwc3_qcom_enable_interrupts()
326 enable_irq_wake(qcom->dp_hs_phy_irq); in dwc3_qcom_enable_interrupts()
329 if (qcom->dm_hs_phy_irq) { in dwc3_qcom_enable_interrupts()
330 enable_irq(qcom->dm_hs_phy_irq); in dwc3_qcom_enable_interrupts()
331 enable_irq_wake(qcom->dm_hs_phy_irq); in dwc3_qcom_enable_interrupts()
334 if (qcom->ss_phy_irq) { in dwc3_qcom_enable_interrupts()
335 enable_irq(qcom->ss_phy_irq); in dwc3_qcom_enable_interrupts()
336 enable_irq_wake(qcom->ss_phy_irq); in dwc3_qcom_enable_interrupts()
345 if (qcom->is_suspended) in dwc3_qcom_suspend()
348 val = readl(qcom->qscratch_base + PWR_EVNT_IRQ_STAT_REG); in dwc3_qcom_suspend()
350 dev_err(qcom->dev, "HS-PHY not in L2\n"); in dwc3_qcom_suspend()
352 for (i = qcom->num_clocks - 1; i >= 0; i--) in dwc3_qcom_suspend()
353 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_suspend()
357 dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); in dwc3_qcom_suspend()
359 qcom->is_suspended = true; in dwc3_qcom_suspend()
370 if (!qcom->is_suspended) in dwc3_qcom_resume()
375 for (i = 0; i < qcom->num_clocks; i++) { in dwc3_qcom_resume()
376 ret = clk_prepare_enable(qcom->clks[i]); in dwc3_qcom_resume()
378 while (--i >= 0) in dwc3_qcom_resume()
379 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_resume()
386 dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret); in dwc3_qcom_resume()
389 dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG, in dwc3_qcom_resume()
392 qcom->is_suspended = false; in dwc3_qcom_resume()
400 struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); in qcom_dwc3_resume_irq()
403 if (qcom->pm_suspended) in qcom_dwc3_resume_irq()
406 if (dwc->xhci) in qcom_dwc3_resume_irq()
407 pm_runtime_resume(&dwc->xhci->dev); in qcom_dwc3_resume_irq()
414 /* Configure dwc3 to use UTMI clock as PIPE clock not present */ in dwc3_qcom_select_utmi_clk()
415 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
420 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
425 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
432 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_get_irq()
446 const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; in dwc3_qcom_setup_irq()
451 pdata ? pdata->hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
455 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
460 dev_err(qcom->dev, "hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
463 qcom->hs_phy_irq = irq; in dwc3_qcom_setup_irq()
467 pdata ? pdata->dp_hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
470 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
475 dev_err(qcom->dev, "dp_hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
478 qcom->dp_hs_phy_irq = irq; in dwc3_qcom_setup_irq()
482 pdata ? pdata->dm_hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
485 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
490 dev_err(qcom->dev, "dm_hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
493 qcom->dm_hs_phy_irq = irq; in dwc3_qcom_setup_irq()
497 pdata ? pdata->ss_phy_irq_index : -1); in dwc3_qcom_setup_irq()
500 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
505 dev_err(qcom->dev, "ss_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
508 qcom->ss_phy_irq = irq; in dwc3_qcom_setup_irq()
516 struct device *dev = qcom->dev; in dwc3_qcom_clk_init()
517 struct device_node *np = dev->of_node; in dwc3_qcom_clk_init()
526 qcom->num_clocks = count; in dwc3_qcom_clk_init()
528 qcom->clks = devm_kcalloc(dev, qcom->num_clocks, in dwc3_qcom_clk_init()
530 if (!qcom->clks) in dwc3_qcom_clk_init()
531 return -ENOMEM; in dwc3_qcom_clk_init()
533 for (i = 0; i < qcom->num_clocks; i++) { in dwc3_qcom_clk_init()
539 while (--i >= 0) in dwc3_qcom_clk_init()
540 clk_put(qcom->clks[i]); in dwc3_qcom_clk_init()
546 while (--i >= 0) { in dwc3_qcom_clk_init()
547 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_clk_init()
548 clk_put(qcom->clks[i]); in dwc3_qcom_clk_init()
555 qcom->clks[i] = clk; in dwc3_qcom_clk_init()
569 struct device *dev = &pdev->dev; in dwc3_qcom_acpi_register_core()
574 qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); in dwc3_qcom_acpi_register_core()
575 if (!qcom->dwc3) in dwc3_qcom_acpi_register_core()
576 return -ENOMEM; in dwc3_qcom_acpi_register_core()
578 qcom->dwc3->dev.parent = dev; in dwc3_qcom_acpi_register_core()
579 qcom->dwc3->dev.type = dev->type; in dwc3_qcom_acpi_register_core()
580 qcom->dwc3->dev.dma_mask = dev->dma_mask; in dwc3_qcom_acpi_register_core()
581 qcom->dwc3->dev.dma_parms = dev->dma_parms; in dwc3_qcom_acpi_register_core()
582 qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask; in dwc3_qcom_acpi_register_core()
586 return -ENOMEM; in dwc3_qcom_acpi_register_core()
590 dev_err(&pdev->dev, "failed to get memory resource\n"); in dwc3_qcom_acpi_register_core()
591 ret = -ENODEV; in dwc3_qcom_acpi_register_core()
595 child_res[0].flags = res->flags; in dwc3_qcom_acpi_register_core()
596 child_res[0].start = res->start; in dwc3_qcom_acpi_register_core()
598 qcom->acpi_pdata->dwc3_core_base_size; in dwc3_qcom_acpi_register_core()
604 ret = platform_device_add_resources(qcom->dwc3, child_res, 2); in dwc3_qcom_acpi_register_core()
606 dev_err(&pdev->dev, "failed to add resources\n"); in dwc3_qcom_acpi_register_core()
610 ret = platform_device_add_properties(qcom->dwc3, in dwc3_qcom_acpi_register_core()
613 dev_err(&pdev->dev, "failed to add properties\n"); in dwc3_qcom_acpi_register_core()
617 ret = platform_device_add(qcom->dwc3); in dwc3_qcom_acpi_register_core()
619 dev_err(&pdev->dev, "failed to add device\n"); in dwc3_qcom_acpi_register_core()
629 struct device_node *np = pdev->dev.of_node, *dwc3_np; in dwc3_qcom_of_register_core()
630 struct device *dev = &pdev->dev; in dwc3_qcom_of_register_core()
633 dwc3_np = of_get_child_by_name(np, "dwc3"); in dwc3_qcom_of_register_core()
635 dev_err(dev, "failed to find dwc3 core child\n"); in dwc3_qcom_of_register_core()
636 return -ENODEV; in dwc3_qcom_of_register_core()
641 dev_err(dev, "failed to register dwc3 core - %d\n", ret); in dwc3_qcom_of_register_core()
645 qcom->dwc3 = of_find_device_by_node(dwc3_np); in dwc3_qcom_of_register_core()
646 if (!qcom->dwc3) { in dwc3_qcom_of_register_core()
647 dev_err(dev, "failed to get dwc3 platform device\n"); in dwc3_qcom_of_register_core()
648 return -ENODEV; in dwc3_qcom_of_register_core()
656 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_probe()
657 struct device *dev = &pdev->dev; in dwc3_qcom_probe()
663 qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); in dwc3_qcom_probe()
665 return -ENOMEM; in dwc3_qcom_probe()
668 qcom->dev = &pdev->dev; in dwc3_qcom_probe()
671 qcom->acpi_pdata = acpi_device_get_match_data(dev); in dwc3_qcom_probe()
672 if (!qcom->acpi_pdata) { in dwc3_qcom_probe()
673 dev_err(&pdev->dev, "no supporting ACPI device data\n"); in dwc3_qcom_probe()
674 return -EINVAL; in dwc3_qcom_probe()
678 qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); in dwc3_qcom_probe()
679 if (IS_ERR(qcom->resets)) { in dwc3_qcom_probe()
680 ret = PTR_ERR(qcom->resets); in dwc3_qcom_probe()
681 dev_err(&pdev->dev, "failed to get resets, err=%d\n", ret); in dwc3_qcom_probe()
685 ret = reset_control_assert(qcom->resets); in dwc3_qcom_probe()
687 dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret); in dwc3_qcom_probe()
693 ret = reset_control_deassert(qcom->resets); in dwc3_qcom_probe()
695 dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret); in dwc3_qcom_probe()
712 return -ENOMEM; in dwc3_qcom_probe()
714 parent_res->start = res->start + in dwc3_qcom_probe()
715 qcom->acpi_pdata->qscratch_base_offset; in dwc3_qcom_probe()
716 parent_res->end = parent_res->start + in dwc3_qcom_probe()
717 qcom->acpi_pdata->qscratch_base_size; in dwc3_qcom_probe()
720 qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); in dwc3_qcom_probe()
721 if (IS_ERR(qcom->qscratch_base)) { in dwc3_qcom_probe()
723 ret = PTR_ERR(qcom->qscratch_base); in dwc3_qcom_probe()
734 * Disable pipe_clk requirement if specified. Used when dwc3 in dwc3_qcom_probe()
738 "qcom,select-utmi-as-pipe-clk"); in dwc3_qcom_probe()
748 dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); in dwc3_qcom_probe()
756 qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev); in dwc3_qcom_probe()
759 if (qcom->mode == USB_DR_MODE_PERIPHERAL) in dwc3_qcom_probe()
767 device_init_wakeup(&pdev->dev, 1); in dwc3_qcom_probe()
768 qcom->is_suspended = false; in dwc3_qcom_probe()
779 of_platform_depopulate(&pdev->dev); in dwc3_qcom_probe()
783 for (i = qcom->num_clocks - 1; i >= 0; i--) { in dwc3_qcom_probe()
784 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_probe()
785 clk_put(qcom->clks[i]); in dwc3_qcom_probe()
788 reset_control_assert(qcom->resets); in dwc3_qcom_probe()
796 struct device *dev = &pdev->dev; in dwc3_qcom_remove()
801 for (i = qcom->num_clocks - 1; i >= 0; i--) { in dwc3_qcom_remove()
802 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_remove()
803 clk_put(qcom->clks[i]); in dwc3_qcom_remove()
805 qcom->num_clocks = 0; in dwc3_qcom_remove()
808 reset_control_assert(qcom->resets); in dwc3_qcom_remove()
823 qcom->pm_suspended = true; in dwc3_qcom_pm_suspend()
835 qcom->pm_suspended = false; in dwc3_qcom_pm_resume()
861 { .compatible = "qcom,dwc3" },
862 { .compatible = "qcom,msm8996-dwc3" },
863 { .compatible = "qcom,msm8998-dwc3" },
864 { .compatible = "qcom,sdm845-dwc3" },
891 .name = "dwc3-qcom",
901 MODULE_DESCRIPTION("DesignWare DWC3 QCOM Glue Driver");