Lines Matching +full:u2p +full:- +full:dis +full:- +full:msk
1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/dma-mapping.h>
24 #include "xhci-mtk.h"
135 struct device *dev = mtk->dev; in xhci_mtk_set_frame_interval()
136 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_set_frame_interval()
139 if (!of_device_is_compatible(dev->of_node, "mediatek,mt8195-xhci")) in xhci_mtk_set_frame_interval()
142 value = readl(hcd->regs + HFCNTR_CFG); in xhci_mtk_set_frame_interval()
145 writel(value, hcd->regs + HFCNTR_CFG); in xhci_mtk_set_frame_interval()
147 value = readl(hcd->regs + LS_EOF_CFG); in xhci_mtk_set_frame_interval()
150 writel(value, hcd->regs + LS_EOF_CFG); in xhci_mtk_set_frame_interval()
152 value = readl(hcd->regs + FS_EOF_CFG); in xhci_mtk_set_frame_interval()
155 writel(value, hcd->regs + FS_EOF_CFG); in xhci_mtk_set_frame_interval()
157 value = readl(hcd->regs + SS_GEN1_EOF_CFG); in xhci_mtk_set_frame_interval()
160 writel(value, hcd->regs + SS_GEN1_EOF_CFG); in xhci_mtk_set_frame_interval()
162 value = readl(hcd->regs + SS_GEN2_EOF_CFG); in xhci_mtk_set_frame_interval()
165 writel(value, hcd->regs + SS_GEN2_EOF_CFG); in xhci_mtk_set_frame_interval()
170 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; in xhci_mtk_host_enable()
176 if (!mtk->has_ippc) in xhci_mtk_host_enable()
180 value = readl(&ippc->ip_pw_ctr1); in xhci_mtk_host_enable()
182 writel(value, &ippc->ip_pw_ctr1); in xhci_mtk_host_enable()
185 for (i = 0; i < mtk->num_u3_ports; i++) { in xhci_mtk_host_enable()
186 if ((0x1 << i) & mtk->u3p_dis_msk) { in xhci_mtk_host_enable()
191 value = readl(&ippc->u3_ctrl_p[i]); in xhci_mtk_host_enable()
194 writel(value, &ippc->u3_ctrl_p[i]); in xhci_mtk_host_enable()
198 for (i = 0; i < mtk->num_u2_ports; i++) { in xhci_mtk_host_enable()
199 if (BIT(i) & mtk->u2p_dis_msk) in xhci_mtk_host_enable()
202 value = readl(&ippc->u2_ctrl_p[i]); in xhci_mtk_host_enable()
205 writel(value, &ippc->u2_ctrl_p[i]); in xhci_mtk_host_enable()
215 if (mtk->num_u3_ports > u3_ports_disabled) in xhci_mtk_host_enable()
218 ret = readl_poll_timeout(&ippc->ip_pw_sts1, value, in xhci_mtk_host_enable()
221 dev_err(mtk->dev, "clocks are not stable (0x%x)\n", value); in xhci_mtk_host_enable()
230 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; in xhci_mtk_host_disable()
235 if (!mtk->has_ippc) in xhci_mtk_host_disable()
239 for (i = 0; i < mtk->num_u3_ports; i++) { in xhci_mtk_host_disable()
240 if ((0x1 << i) & mtk->u3p_dis_msk) in xhci_mtk_host_disable()
243 value = readl(&ippc->u3_ctrl_p[i]); in xhci_mtk_host_disable()
245 writel(value, &ippc->u3_ctrl_p[i]); in xhci_mtk_host_disable()
249 for (i = 0; i < mtk->num_u2_ports; i++) { in xhci_mtk_host_disable()
250 if (BIT(i) & mtk->u2p_dis_msk) in xhci_mtk_host_disable()
253 value = readl(&ippc->u2_ctrl_p[i]); in xhci_mtk_host_disable()
255 writel(value, &ippc->u2_ctrl_p[i]); in xhci_mtk_host_disable()
259 value = readl(&ippc->ip_pw_ctr1); in xhci_mtk_host_disable()
261 writel(value, &ippc->ip_pw_ctr1); in xhci_mtk_host_disable()
264 ret = readl_poll_timeout(&ippc->ip_pw_sts1, value, in xhci_mtk_host_disable()
267 dev_err(mtk->dev, "ip sleep failed!!!\n"); in xhci_mtk_host_disable()
276 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; in xhci_mtk_ssusb_config()
279 if (!mtk->has_ippc) in xhci_mtk_ssusb_config()
283 value = readl(&ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
285 writel(value, &ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
287 value = readl(&ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
289 writel(value, &ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
292 * device ip is default power-on in fact in xhci_mtk_ssusb_config()
293 * power down device ip, otherwise ip-sleep will fail in xhci_mtk_ssusb_config()
295 value = readl(&ippc->ip_pw_ctr2); in xhci_mtk_ssusb_config()
297 writel(value, &ippc->ip_pw_ctr2); in xhci_mtk_ssusb_config()
299 value = readl(&ippc->ip_xhci_cap); in xhci_mtk_ssusb_config()
300 mtk->num_u3_ports = CAP_U3_PORT_NUM(value); in xhci_mtk_ssusb_config()
301 mtk->num_u2_ports = CAP_U2_PORT_NUM(value); in xhci_mtk_ssusb_config()
302 dev_dbg(mtk->dev, "%s u2p:%d, u3p:%d\n", __func__, in xhci_mtk_ssusb_config()
303 mtk->num_u2_ports, mtk->num_u3_ports); in xhci_mtk_ssusb_config()
308 /* only clocks can be turn off for ip-sleep wakeup mode */
311 u32 reg, msk, val; in usb_wakeup_ip_sleep_set() local
313 switch (mtk->uwk_vers) { in usb_wakeup_ip_sleep_set()
315 reg = mtk->uwk_reg_base + PERI_WK_CTRL1; in usb_wakeup_ip_sleep_set()
316 msk = WC1_IS_EN | WC1_IS_C(0xf) | WC1_IS_P; in usb_wakeup_ip_sleep_set()
320 reg = mtk->uwk_reg_base + PERI_WK_CTRL0; in usb_wakeup_ip_sleep_set()
321 msk = WC0_IS_EN | WC0_IS_C(0xf) | WC0_IS_P; in usb_wakeup_ip_sleep_set()
325 reg = mtk->uwk_reg_base + PERI_WK_CTRL0; in usb_wakeup_ip_sleep_set()
326 msk = WC0_SSUSB0_CDEN | WC0_IS_SPM_EN; in usb_wakeup_ip_sleep_set()
327 val = enable ? msk : 0; in usb_wakeup_ip_sleep_set()
330 reg = mtk->uwk_reg_base + PERI_WK_CTRL1_8195; in usb_wakeup_ip_sleep_set()
331 msk = WC1_IS_EN_P0_95 | WC1_IS_C_95(0xf) | WC1_IS_P_95; in usb_wakeup_ip_sleep_set()
335 reg = mtk->uwk_reg_base + PERI_WK_CTRL0_8195; in usb_wakeup_ip_sleep_set()
336 msk = WC0_IS_EN_P1_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; in usb_wakeup_ip_sleep_set()
340 reg = mtk->uwk_reg_base + PERI_WK_CTRL0_8195; in usb_wakeup_ip_sleep_set()
341 msk = WC0_IS_EN_P2_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; in usb_wakeup_ip_sleep_set()
345 reg = mtk->uwk_reg_base + PERI_WK_CTRL0_8195; in usb_wakeup_ip_sleep_set()
346 msk = WC0_IS_EN_P3_95 | WC0_IS_C_95(0x7) | WC0_IS_P_95; in usb_wakeup_ip_sleep_set()
350 reg = mtk->uwk_reg_base + PERI_SSUSB_SPM_CTRL; in usb_wakeup_ip_sleep_set()
351 msk = SSC_IP_SLEEP_EN | SSC_SPM_INT_EN; in usb_wakeup_ip_sleep_set()
352 val = enable ? msk : 0; in usb_wakeup_ip_sleep_set()
357 regmap_update_bits(mtk->uwk, reg, msk, val); in usb_wakeup_ip_sleep_set()
367 mtk->uwk_en = of_property_read_bool(dn, "wakeup-source"); in usb_wakeup_of_property_parse()
368 if (!mtk->uwk_en) in usb_wakeup_of_property_parse()
372 "mediatek,syscon-wakeup", 2, 0, &args); in usb_wakeup_of_property_parse()
376 mtk->uwk_reg_base = args.args[0]; in usb_wakeup_of_property_parse()
377 mtk->uwk_vers = args.args[1]; in usb_wakeup_of_property_parse()
378 mtk->uwk = syscon_node_to_regmap(args.np); in usb_wakeup_of_property_parse()
380 dev_info(mtk->dev, "uwk - reg:0x%x, version:%d\n", in usb_wakeup_of_property_parse()
381 mtk->uwk_reg_base, mtk->uwk_vers); in usb_wakeup_of_property_parse()
383 return PTR_ERR_OR_ZERO(mtk->uwk); in usb_wakeup_of_property_parse()
388 if (mtk->uwk_en) in usb_wakeup_set()
394 struct clk_bulk_data *clks = mtk->clks; in xhci_mtk_clks_get()
402 return devm_clk_bulk_get_optional(mtk->dev, BULK_CLKS_NUM, clks); in xhci_mtk_clks_get()
407 struct regulator_bulk_data *supplies = mtk->supplies; in xhci_mtk_vregs_get()
412 return devm_regulator_bulk_get(mtk->dev, BULK_VREGS_NUM, supplies); in xhci_mtk_vregs_get()
425 xhci->quirks |= XHCI_PLAT; in xhci_mtk_quirks()
426 xhci->quirks |= XHCI_MTK_HOST; in xhci_mtk_quirks()
431 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_mtk_quirks()
432 if (mtk->lpm_support) in xhci_mtk_quirks()
433 xhci->quirks |= XHCI_LPM_SUPPORT; in xhci_mtk_quirks()
434 if (mtk->u2_lpm_disable) in xhci_mtk_quirks()
435 xhci->quirks |= XHCI_HW_LPM_DISABLE; in xhci_mtk_quirks()
441 if (xhci->hci_version < 0x100 && HCC_MAX_PSA(xhci->hcc_params) == 4) in xhci_mtk_quirks()
442 xhci->quirks |= XHCI_BROKEN_STREAMS; in xhci_mtk_quirks()
482 struct device *dev = &pdev->dev; in xhci_mtk_probe()
483 struct device_node *node = dev->of_node; in xhci_mtk_probe()
489 int ret = -ENODEV; in xhci_mtk_probe()
494 return -ENODEV; in xhci_mtk_probe()
499 return -ENOMEM; in xhci_mtk_probe()
501 mtk->dev = dev; in xhci_mtk_probe()
513 if (irq == -EPROBE_DEFER) in xhci_mtk_probe()
523 if (wakeup_irq == -EPROBE_DEFER) in xhci_mtk_probe()
526 mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable"); in xhci_mtk_probe()
527 mtk->u2_lpm_disable = of_property_read_bool(node, "usb2-lpm-disable"); in xhci_mtk_probe()
529 of_property_read_u32(node, "mediatek,u3p-dis-msk", in xhci_mtk_probe()
530 &mtk->u3p_dis_msk); in xhci_mtk_probe()
531 of_property_read_u32(node, "mediatek,u2p-dis-msk", in xhci_mtk_probe()
532 &mtk->u2p_dis_msk); in xhci_mtk_probe()
546 ret = regulator_bulk_enable(BULK_VREGS_NUM, mtk->supplies); in xhci_mtk_probe()
550 ret = clk_bulk_prepare_enable(BULK_CLKS_NUM, mtk->clks); in xhci_mtk_probe()
562 ret = -ENOMEM; in xhci_mtk_probe()
570 mtk->hcd = platform_get_drvdata(pdev); in xhci_mtk_probe()
574 hcd->regs = devm_ioremap_resource(dev, res); in xhci_mtk_probe()
575 if (IS_ERR(hcd->regs)) { in xhci_mtk_probe()
576 ret = PTR_ERR(hcd->regs); in xhci_mtk_probe()
579 hcd->rsrc_start = res->start; in xhci_mtk_probe()
580 hcd->rsrc_len = resource_size(res); in xhci_mtk_probe()
584 mtk->ippc_regs = devm_ioremap_resource(dev, res); in xhci_mtk_probe()
585 if (IS_ERR(mtk->ippc_regs)) { in xhci_mtk_probe()
586 ret = PTR_ERR(mtk->ippc_regs); in xhci_mtk_probe()
589 mtk->has_ippc = true; in xhci_mtk_probe()
595 xhci->main_hcd = hcd; in xhci_mtk_probe()
602 xhci->imod_interval = 5000; in xhci_mtk_probe()
603 device_property_read_u32(dev, "imod-interval-ns", &xhci->imod_interval); in xhci_mtk_probe()
605 xhci->shared_hcd = usb_create_shared_hcd(driver, dev, in xhci_mtk_probe()
607 if (!xhci->shared_hcd) { in xhci_mtk_probe()
608 ret = -ENOMEM; in xhci_mtk_probe()
616 if (HCC_MAX_PSA(xhci->hcc_params) >= 4 && in xhci_mtk_probe()
617 !(xhci->quirks & XHCI_BROKEN_STREAMS)) in xhci_mtk_probe()
618 xhci->shared_hcd->can_do_streams = 1; in xhci_mtk_probe()
620 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); in xhci_mtk_probe()
641 usb_remove_hcd(xhci->shared_hcd); in xhci_mtk_probe()
642 xhci->shared_hcd = NULL; in xhci_mtk_probe()
649 usb_put_hcd(xhci->shared_hcd); in xhci_mtk_probe()
658 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); in xhci_mtk_probe()
661 regulator_bulk_disable(BULK_VREGS_NUM, mtk->supplies); in xhci_mtk_probe()
672 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_remove()
674 struct usb_hcd *shared_hcd = xhci->shared_hcd; in xhci_mtk_remove()
675 struct device *dev = &pdev->dev; in xhci_mtk_remove()
678 xhci->xhc_state |= XHCI_STATE_REMOVING; in xhci_mtk_remove()
683 xhci->shared_hcd = NULL; in xhci_mtk_remove()
688 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); in xhci_mtk_remove()
689 regulator_bulk_disable(BULK_VREGS_NUM, mtk->supplies); in xhci_mtk_remove()
701 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_suspend()
706 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_mtk_suspend()
707 del_timer_sync(&hcd->rh_timer); in xhci_mtk_suspend()
708 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_mtk_suspend()
709 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_mtk_suspend()
715 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); in xhci_mtk_suspend()
721 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_mtk_suspend()
722 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_mtk_suspend()
723 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_mtk_suspend()
731 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_resume()
736 ret = clk_bulk_prepare_enable(BULK_CLKS_NUM, mtk->clks); in xhci_mtk_resume()
745 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_mtk_resume()
746 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_mtk_resume()
747 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_mtk_resume()
752 clk_bulk_disable_unprepare(BULK_CLKS_NUM, mtk->clks); in xhci_mtk_resume()
761 struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd); in xhci_mtk_runtime_suspend()
764 if (xhci->xhc_state) in xhci_mtk_runtime_suspend()
765 return -ESHUTDOWN; in xhci_mtk_runtime_suspend()
770 /* -EBUSY: let PM automatically reschedule another autosuspend */ in xhci_mtk_runtime_suspend()
771 return ret ? -EBUSY : 0; in xhci_mtk_runtime_suspend()
777 struct xhci_hcd *xhci = hcd_to_xhci(mtk->hcd); in xhci_mtk_runtime_resume()
780 if (xhci->xhc_state) in xhci_mtk_runtime_resume()
781 return -ESHUTDOWN; in xhci_mtk_runtime_resume()
798 { .compatible = "mediatek,mt8173-xhci"},
799 { .compatible = "mediatek,mt8195-xhci"},
800 { .compatible = "mediatek,mtk-xhci"},
809 .name = "xhci-mtk",