Lines Matching +full:assert +full:- +full:falling +full:- +full:edge

1 // SPDX-License-Identifier: GPL-2.0
4 * Inspired by dwc3-of-simple.c
123 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
125 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
128 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
130 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, in dwc3_qcom_vbus_override_enable()
142 qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; in dwc3_qcom_vbus_notifier()
154 qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; in dwc3_qcom_host_notifier()
161 struct device *dev = qcom->dev; in dwc3_qcom_register_extcon()
165 if (!of_property_read_bool(dev->of_node, "extcon")) in dwc3_qcom_register_extcon()
168 qcom->edev = extcon_get_edev_by_phandle(dev, 0); in dwc3_qcom_register_extcon()
169 if (IS_ERR(qcom->edev)) in dwc3_qcom_register_extcon()
170 return dev_err_probe(dev, PTR_ERR(qcom->edev), in dwc3_qcom_register_extcon()
173 qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier; in dwc3_qcom_register_extcon()
175 qcom->host_edev = extcon_get_edev_by_phandle(dev, 1); in dwc3_qcom_register_extcon()
176 if (IS_ERR(qcom->host_edev)) in dwc3_qcom_register_extcon()
177 qcom->host_edev = NULL; in dwc3_qcom_register_extcon()
179 ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB, in dwc3_qcom_register_extcon()
180 &qcom->vbus_nb); in dwc3_qcom_register_extcon()
186 if (qcom->host_edev) in dwc3_qcom_register_extcon()
187 host_edev = qcom->host_edev; in dwc3_qcom_register_extcon()
189 host_edev = qcom->edev; in dwc3_qcom_register_extcon()
191 qcom->host_nb.notifier_call = dwc3_qcom_host_notifier; in dwc3_qcom_register_extcon()
193 &qcom->host_nb); in dwc3_qcom_register_extcon()
200 if (extcon_get_state(qcom->edev, EXTCON_USB) || in dwc3_qcom_register_extcon()
202 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev); in dwc3_qcom_register_extcon()
204 dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev); in dwc3_qcom_register_extcon()
213 ret = icc_enable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_enable()
217 ret = icc_enable(qcom->icc_path_apps); in dwc3_qcom_interconnect_enable()
219 icc_disable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_enable()
228 ret = icc_disable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_disable()
232 ret = icc_disable(qcom->icc_path_apps); in dwc3_qcom_interconnect_disable()
234 icc_enable(qcom->icc_path_ddr); in dwc3_qcom_interconnect_disable()
240 * dwc3_qcom_interconnect_init() - Get interconnect path handles
248 struct device *dev = qcom->dev; in dwc3_qcom_interconnect_init()
254 qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); in dwc3_qcom_interconnect_init()
255 if (IS_ERR(qcom->icc_path_ddr)) { in dwc3_qcom_interconnect_init()
256 return dev_err_probe(dev, PTR_ERR(qcom->icc_path_ddr), in dwc3_qcom_interconnect_init()
257 "failed to get usb-ddr path\n"); in dwc3_qcom_interconnect_init()
260 qcom->icc_path_apps = of_icc_get(dev, "apps-usb"); in dwc3_qcom_interconnect_init()
261 if (IS_ERR(qcom->icc_path_apps)) { in dwc3_qcom_interconnect_init()
262 ret = dev_err_probe(dev, PTR_ERR(qcom->icc_path_apps), in dwc3_qcom_interconnect_init()
263 "failed to get apps-usb path\n"); in dwc3_qcom_interconnect_init()
267 max_speed = usb_get_maximum_speed(&qcom->dwc3->dev); in dwc3_qcom_interconnect_init()
269 ret = icc_set_bw(qcom->icc_path_ddr, in dwc3_qcom_interconnect_init()
272 ret = icc_set_bw(qcom->icc_path_ddr, in dwc3_qcom_interconnect_init()
276 dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); in dwc3_qcom_interconnect_init()
280 ret = icc_set_bw(qcom->icc_path_apps, APPS_USB_AVG_BW, APPS_USB_PEAK_BW); in dwc3_qcom_interconnect_init()
282 dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); in dwc3_qcom_interconnect_init()
289 icc_put(qcom->icc_path_apps); in dwc3_qcom_interconnect_init()
291 icc_put(qcom->icc_path_ddr); in dwc3_qcom_interconnect_init()
296 * dwc3_qcom_interconnect_exit() - Release interconnect path handles
303 icc_put(qcom->icc_path_ddr); in dwc3_qcom_interconnect_exit()
304 icc_put(qcom->icc_path_apps); in dwc3_qcom_interconnect_exit()
315 dwc = platform_get_drvdata(qcom->dwc3); in dwc3_qcom_is_host()
321 return dwc->xhci; in dwc3_qcom_is_host()
326 struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); in dwc3_qcom_read_usb2_speed()
333 hcd = platform_get_drvdata(dwc->xhci); in dwc3_qcom_read_usb2_speed()
342 udev = usb_hub_find_child(hcd->self.root_hub, 1); in dwc3_qcom_read_usb2_speed()
349 return udev->speed; in dwc3_qcom_read_usb2_speed()
375 dwc3_qcom_disable_wakeup_irq(qcom->qusb2_phy_irq); in dwc3_qcom_disable_interrupts()
377 if (qcom->usb2_speed == USB_SPEED_LOW) { in dwc3_qcom_disable_interrupts()
378 dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq); in dwc3_qcom_disable_interrupts()
379 } else if ((qcom->usb2_speed == USB_SPEED_HIGH) || in dwc3_qcom_disable_interrupts()
380 (qcom->usb2_speed == USB_SPEED_FULL)) { in dwc3_qcom_disable_interrupts()
381 dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq); in dwc3_qcom_disable_interrupts()
383 dwc3_qcom_disable_wakeup_irq(qcom->dp_hs_phy_irq); in dwc3_qcom_disable_interrupts()
384 dwc3_qcom_disable_wakeup_irq(qcom->dm_hs_phy_irq); in dwc3_qcom_disable_interrupts()
387 dwc3_qcom_disable_wakeup_irq(qcom->ss_phy_irq); in dwc3_qcom_disable_interrupts()
392 dwc3_qcom_enable_wakeup_irq(qcom->qusb2_phy_irq, 0); in dwc3_qcom_enable_interrupts()
397 * as falling edge to detect both disconnect and remote wakeup scenarios. When in dwc3_qcom_enable_interrupts()
398 * LS device is connected, configure DM line as falling edge to detect both in dwc3_qcom_enable_interrupts()
400 * DP and DM lines as rising edge to detect HS/HS/LS device connect scenario. in dwc3_qcom_enable_interrupts()
403 if (qcom->usb2_speed == USB_SPEED_LOW) { in dwc3_qcom_enable_interrupts()
404 dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq, in dwc3_qcom_enable_interrupts()
406 } else if ((qcom->usb2_speed == USB_SPEED_HIGH) || in dwc3_qcom_enable_interrupts()
407 (qcom->usb2_speed == USB_SPEED_FULL)) { in dwc3_qcom_enable_interrupts()
408 dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq, in dwc3_qcom_enable_interrupts()
411 dwc3_qcom_enable_wakeup_irq(qcom->dp_hs_phy_irq, in dwc3_qcom_enable_interrupts()
413 dwc3_qcom_enable_wakeup_irq(qcom->dm_hs_phy_irq, in dwc3_qcom_enable_interrupts()
417 dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq, 0); in dwc3_qcom_enable_interrupts()
425 if (qcom->is_suspended) in dwc3_qcom_suspend()
428 val = readl(qcom->qscratch_base + PWR_EVNT_IRQ_STAT_REG); in dwc3_qcom_suspend()
430 dev_err(qcom->dev, "HS-PHY not in L2\n"); in dwc3_qcom_suspend()
432 for (i = qcom->num_clocks - 1; i >= 0; i--) in dwc3_qcom_suspend()
433 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_suspend()
437 dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); in dwc3_qcom_suspend()
444 qcom->usb2_speed = dwc3_qcom_read_usb2_speed(qcom); in dwc3_qcom_suspend()
448 qcom->is_suspended = true; in dwc3_qcom_suspend()
458 if (!qcom->is_suspended) in dwc3_qcom_resume()
464 for (i = 0; i < qcom->num_clocks; i++) { in dwc3_qcom_resume()
465 ret = clk_prepare_enable(qcom->clks[i]); in dwc3_qcom_resume()
467 while (--i >= 0) in dwc3_qcom_resume()
468 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_resume()
475 dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret); in dwc3_qcom_resume()
478 dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG, in dwc3_qcom_resume()
481 qcom->is_suspended = false; in dwc3_qcom_resume()
489 struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); in qcom_dwc3_resume_irq()
492 if (qcom->pm_suspended) in qcom_dwc3_resume_irq()
500 pm_runtime_resume(&dwc->xhci->dev); in qcom_dwc3_resume_irq()
508 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
513 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
518 dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, in dwc3_qcom_select_utmi_clk()
526 struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev; in dwc3_qcom_get_irq()
527 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_get_irq()
541 const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; in dwc3_qcom_setup_irq()
546 pdata ? pdata->qusb2_phy_irq_index : -1); in dwc3_qcom_setup_irq()
549 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
554 dev_err(qcom->dev, "qusb2_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
557 qcom->qusb2_phy_irq = irq; in dwc3_qcom_setup_irq()
561 pdata ? pdata->dp_hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
563 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
568 dev_err(qcom->dev, "dp_hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
571 qcom->dp_hs_phy_irq = irq; in dwc3_qcom_setup_irq()
575 pdata ? pdata->dm_hs_phy_irq_index : -1); in dwc3_qcom_setup_irq()
577 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
582 dev_err(qcom->dev, "dm_hs_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
585 qcom->dm_hs_phy_irq = irq; in dwc3_qcom_setup_irq()
589 pdata ? pdata->ss_phy_irq_index : -1); in dwc3_qcom_setup_irq()
591 ret = devm_request_threaded_irq(qcom->dev, irq, NULL, in dwc3_qcom_setup_irq()
596 dev_err(qcom->dev, "ss_phy_irq failed: %d\n", ret); in dwc3_qcom_setup_irq()
599 qcom->ss_phy_irq = irq; in dwc3_qcom_setup_irq()
607 struct device *dev = qcom->dev; in dwc3_qcom_clk_init()
608 struct device_node *np = dev->of_node; in dwc3_qcom_clk_init()
617 qcom->num_clocks = count; in dwc3_qcom_clk_init()
619 qcom->clks = devm_kcalloc(dev, qcom->num_clocks, in dwc3_qcom_clk_init()
621 if (!qcom->clks) in dwc3_qcom_clk_init()
622 return -ENOMEM; in dwc3_qcom_clk_init()
624 for (i = 0; i < qcom->num_clocks; i++) { in dwc3_qcom_clk_init()
630 while (--i >= 0) in dwc3_qcom_clk_init()
631 clk_put(qcom->clks[i]); in dwc3_qcom_clk_init()
637 while (--i >= 0) { in dwc3_qcom_clk_init()
638 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_clk_init()
639 clk_put(qcom->clks[i]); in dwc3_qcom_clk_init()
646 qcom->clks[i] = clk; in dwc3_qcom_clk_init()
664 struct device *dev = &pdev->dev; in dwc3_qcom_acpi_register_core()
666 struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : in dwc3_qcom_acpi_register_core()
671 qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); in dwc3_qcom_acpi_register_core()
672 if (!qcom->dwc3) in dwc3_qcom_acpi_register_core()
673 return -ENOMEM; in dwc3_qcom_acpi_register_core()
675 qcom->dwc3->dev.parent = dev; in dwc3_qcom_acpi_register_core()
676 qcom->dwc3->dev.type = dev->type; in dwc3_qcom_acpi_register_core()
677 qcom->dwc3->dev.dma_mask = dev->dma_mask; in dwc3_qcom_acpi_register_core()
678 qcom->dwc3->dev.dma_parms = dev->dma_parms; in dwc3_qcom_acpi_register_core()
679 qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask; in dwc3_qcom_acpi_register_core()
683 platform_device_put(qcom->dwc3); in dwc3_qcom_acpi_register_core()
684 return -ENOMEM; in dwc3_qcom_acpi_register_core()
689 dev_err(&pdev->dev, "failed to get memory resource\n"); in dwc3_qcom_acpi_register_core()
690 ret = -ENODEV; in dwc3_qcom_acpi_register_core()
694 child_res[0].flags = res->flags; in dwc3_qcom_acpi_register_core()
695 child_res[0].start = res->start; in dwc3_qcom_acpi_register_core()
697 qcom->acpi_pdata->dwc3_core_base_size; in dwc3_qcom_acpi_register_core()
707 ret = platform_device_add_resources(qcom->dwc3, child_res, 2); in dwc3_qcom_acpi_register_core()
709 dev_err(&pdev->dev, "failed to add resources\n"); in dwc3_qcom_acpi_register_core()
713 ret = device_add_software_node(&qcom->dwc3->dev, &dwc3_qcom_swnode); in dwc3_qcom_acpi_register_core()
715 dev_err(&pdev->dev, "failed to add properties\n"); in dwc3_qcom_acpi_register_core()
719 ret = platform_device_add(qcom->dwc3); in dwc3_qcom_acpi_register_core()
721 dev_err(&pdev->dev, "failed to add device\n"); in dwc3_qcom_acpi_register_core()
722 device_remove_software_node(&qcom->dwc3->dev); in dwc3_qcom_acpi_register_core()
729 platform_device_put(qcom->dwc3); in dwc3_qcom_acpi_register_core()
737 struct device_node *np = pdev->dev.of_node, *dwc3_np; in dwc3_qcom_of_register_core()
738 struct device *dev = &pdev->dev; in dwc3_qcom_of_register_core()
744 return -ENODEV; in dwc3_qcom_of_register_core()
749 dev_err(dev, "failed to register dwc3 core - %d\n", ret); in dwc3_qcom_of_register_core()
753 qcom->dwc3 = of_find_device_by_node(dwc3_np); in dwc3_qcom_of_register_core()
754 if (!qcom->dwc3) { in dwc3_qcom_of_register_core()
755 ret = -ENODEV; in dwc3_qcom_of_register_core()
776 ret = sscanf(fwnode_get_name(dev->fwnode), "URS%d", &id); in dwc3_qcom_create_urs_usb_platdev()
782 fwh = fwnode_get_named_child_node(dev->fwnode, name); in dwc3_qcom_create_urs_usb_platdev()
804 struct fwnode_handle *fwh = urs_usb->dev.fwnode; in dwc3_qcom_destroy_urs_usb_platdev()
812 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_probe()
813 struct device *dev = &pdev->dev; in dwc3_qcom_probe()
821 qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); in dwc3_qcom_probe()
823 return -ENOMEM; in dwc3_qcom_probe()
826 qcom->dev = &pdev->dev; in dwc3_qcom_probe()
829 qcom->acpi_pdata = acpi_device_get_match_data(dev); in dwc3_qcom_probe()
830 if (!qcom->acpi_pdata) { in dwc3_qcom_probe()
831 dev_err(&pdev->dev, "no supporting ACPI device data\n"); in dwc3_qcom_probe()
832 return -EINVAL; in dwc3_qcom_probe()
836 qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); in dwc3_qcom_probe()
837 if (IS_ERR(qcom->resets)) { in dwc3_qcom_probe()
838 return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets), in dwc3_qcom_probe()
842 ret = reset_control_assert(qcom->resets); in dwc3_qcom_probe()
844 dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret); in dwc3_qcom_probe()
850 ret = reset_control_deassert(qcom->resets); in dwc3_qcom_probe()
852 dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret); in dwc3_qcom_probe()
870 parent_res->start = res->start + in dwc3_qcom_probe()
871 qcom->acpi_pdata->qscratch_base_offset; in dwc3_qcom_probe()
872 parent_res->end = parent_res->start + in dwc3_qcom_probe()
873 qcom->acpi_pdata->qscratch_base_size; in dwc3_qcom_probe()
875 if (qcom->acpi_pdata->is_urs) { in dwc3_qcom_probe()
876 qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev); in dwc3_qcom_probe()
877 if (IS_ERR_OR_NULL(qcom->urs_usb)) { in dwc3_qcom_probe()
879 if (!qcom->urs_usb) in dwc3_qcom_probe()
880 ret = -ENODEV; in dwc3_qcom_probe()
882 ret = PTR_ERR(qcom->urs_usb); in dwc3_qcom_probe()
888 qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); in dwc3_qcom_probe()
889 if (IS_ERR(qcom->qscratch_base)) { in dwc3_qcom_probe()
890 ret = PTR_ERR(qcom->qscratch_base); in dwc3_qcom_probe()
905 "qcom,select-utmi-as-pipe-clk"); in dwc3_qcom_probe()
923 qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev); in dwc3_qcom_probe()
926 if (qcom->mode != USB_DR_MODE_HOST) in dwc3_qcom_probe()
934 wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source"); in dwc3_qcom_probe()
935 device_init_wakeup(&pdev->dev, wakeup_source); in dwc3_qcom_probe()
936 device_init_wakeup(&qcom->dwc3->dev, wakeup_source); in dwc3_qcom_probe()
938 qcom->is_suspended = false; in dwc3_qcom_probe()
949 of_platform_depopulate(&pdev->dev); in dwc3_qcom_probe()
951 device_remove_software_node(&qcom->dwc3->dev); in dwc3_qcom_probe()
952 platform_device_del(qcom->dwc3); in dwc3_qcom_probe()
954 platform_device_put(qcom->dwc3); in dwc3_qcom_probe()
956 if (qcom->urs_usb) in dwc3_qcom_probe()
957 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); in dwc3_qcom_probe()
959 for (i = qcom->num_clocks - 1; i >= 0; i--) { in dwc3_qcom_probe()
960 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_probe()
961 clk_put(qcom->clks[i]); in dwc3_qcom_probe()
964 reset_control_assert(qcom->resets); in dwc3_qcom_probe()
972 struct device_node *np = pdev->dev.of_node; in dwc3_qcom_remove()
973 struct device *dev = &pdev->dev; in dwc3_qcom_remove()
977 of_platform_depopulate(&pdev->dev); in dwc3_qcom_remove()
979 device_remove_software_node(&qcom->dwc3->dev); in dwc3_qcom_remove()
980 platform_device_del(qcom->dwc3); in dwc3_qcom_remove()
982 platform_device_put(qcom->dwc3); in dwc3_qcom_remove()
984 if (qcom->urs_usb) in dwc3_qcom_remove()
985 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb); in dwc3_qcom_remove()
987 for (i = qcom->num_clocks - 1; i >= 0; i--) { in dwc3_qcom_remove()
988 clk_disable_unprepare(qcom->clks[i]); in dwc3_qcom_remove()
989 clk_put(qcom->clks[i]); in dwc3_qcom_remove()
991 qcom->num_clocks = 0; in dwc3_qcom_remove()
994 reset_control_assert(qcom->resets); in dwc3_qcom_remove()
1010 qcom->pm_suspended = true; in dwc3_qcom_pm_suspend()
1025 qcom->pm_suspended = false; in dwc3_qcom_pm_resume()
1092 .name = "dwc3-qcom",