• Home
  • Raw
  • Download

Lines Matching +full:u3p +full:- +full:dis +full:- +full:msk

1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/dma-mapping.h>
23 #include "xhci-mtk.h"
78 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; in xhci_mtk_host_enable()
84 if (!mtk->has_ippc) in xhci_mtk_host_enable()
88 value = readl(&ippc->ip_pw_ctr1); in xhci_mtk_host_enable()
90 writel(value, &ippc->ip_pw_ctr1); in xhci_mtk_host_enable()
93 for (i = 0; i < mtk->num_u3_ports; i++) { in xhci_mtk_host_enable()
94 if ((0x1 << i) & mtk->u3p_dis_msk) { in xhci_mtk_host_enable()
99 value = readl(&ippc->u3_ctrl_p[i]); in xhci_mtk_host_enable()
102 writel(value, &ippc->u3_ctrl_p[i]); in xhci_mtk_host_enable()
106 for (i = 0; i < mtk->num_u2_ports; i++) { in xhci_mtk_host_enable()
107 value = readl(&ippc->u2_ctrl_p[i]); in xhci_mtk_host_enable()
110 writel(value, &ippc->u2_ctrl_p[i]); in xhci_mtk_host_enable()
120 if (mtk->num_u3_ports > u3_ports_disabled) in xhci_mtk_host_enable()
123 ret = readl_poll_timeout(&ippc->ip_pw_sts1, value, in xhci_mtk_host_enable()
126 dev_err(mtk->dev, "clocks are not stable (0x%x)\n", value); in xhci_mtk_host_enable()
135 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; in xhci_mtk_host_disable()
140 if (!mtk->has_ippc) in xhci_mtk_host_disable()
144 for (i = 0; i < mtk->num_u3_ports; i++) { in xhci_mtk_host_disable()
145 if ((0x1 << i) & mtk->u3p_dis_msk) in xhci_mtk_host_disable()
148 value = readl(&ippc->u3_ctrl_p[i]); in xhci_mtk_host_disable()
150 writel(value, &ippc->u3_ctrl_p[i]); in xhci_mtk_host_disable()
154 for (i = 0; i < mtk->num_u2_ports; i++) { in xhci_mtk_host_disable()
155 value = readl(&ippc->u2_ctrl_p[i]); in xhci_mtk_host_disable()
157 writel(value, &ippc->u2_ctrl_p[i]); in xhci_mtk_host_disable()
161 value = readl(&ippc->ip_pw_ctr1); in xhci_mtk_host_disable()
163 writel(value, &ippc->ip_pw_ctr1); in xhci_mtk_host_disable()
166 ret = readl_poll_timeout(&ippc->ip_pw_sts1, value, in xhci_mtk_host_disable()
169 dev_err(mtk->dev, "ip sleep failed!!!\n"); in xhci_mtk_host_disable()
177 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; in xhci_mtk_ssusb_config()
180 if (!mtk->has_ippc) in xhci_mtk_ssusb_config()
184 value = readl(&ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
186 writel(value, &ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
188 value = readl(&ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
190 writel(value, &ippc->ip_pw_ctr0); in xhci_mtk_ssusb_config()
193 * device ip is default power-on in fact in xhci_mtk_ssusb_config()
194 * power down device ip, otherwise ip-sleep will fail in xhci_mtk_ssusb_config()
196 value = readl(&ippc->ip_pw_ctr2); in xhci_mtk_ssusb_config()
198 writel(value, &ippc->ip_pw_ctr2); in xhci_mtk_ssusb_config()
200 value = readl(&ippc->ip_xhci_cap); in xhci_mtk_ssusb_config()
201 mtk->num_u3_ports = CAP_U3_PORT_NUM(value); in xhci_mtk_ssusb_config()
202 mtk->num_u2_ports = CAP_U2_PORT_NUM(value); in xhci_mtk_ssusb_config()
203 dev_dbg(mtk->dev, "%s u2p:%d, u3p:%d\n", __func__, in xhci_mtk_ssusb_config()
204 mtk->num_u2_ports, mtk->num_u3_ports); in xhci_mtk_ssusb_config()
211 struct device *dev = mtk->dev; in xhci_mtk_clks_get()
213 mtk->sys_clk = devm_clk_get(dev, "sys_ck"); in xhci_mtk_clks_get()
214 if (IS_ERR(mtk->sys_clk)) { in xhci_mtk_clks_get()
216 return PTR_ERR(mtk->sys_clk); in xhci_mtk_clks_get()
219 mtk->xhci_clk = devm_clk_get_optional(dev, "xhci_ck"); in xhci_mtk_clks_get()
220 if (IS_ERR(mtk->xhci_clk)) in xhci_mtk_clks_get()
221 return PTR_ERR(mtk->xhci_clk); in xhci_mtk_clks_get()
223 mtk->ref_clk = devm_clk_get_optional(dev, "ref_ck"); in xhci_mtk_clks_get()
224 if (IS_ERR(mtk->ref_clk)) in xhci_mtk_clks_get()
225 return PTR_ERR(mtk->ref_clk); in xhci_mtk_clks_get()
227 mtk->mcu_clk = devm_clk_get_optional(dev, "mcu_ck"); in xhci_mtk_clks_get()
228 if (IS_ERR(mtk->mcu_clk)) in xhci_mtk_clks_get()
229 return PTR_ERR(mtk->mcu_clk); in xhci_mtk_clks_get()
231 mtk->dma_clk = devm_clk_get_optional(dev, "dma_ck"); in xhci_mtk_clks_get()
232 return PTR_ERR_OR_ZERO(mtk->dma_clk); in xhci_mtk_clks_get()
239 ret = clk_prepare_enable(mtk->ref_clk); in xhci_mtk_clks_enable()
241 dev_err(mtk->dev, "failed to enable ref_clk\n"); in xhci_mtk_clks_enable()
245 ret = clk_prepare_enable(mtk->sys_clk); in xhci_mtk_clks_enable()
247 dev_err(mtk->dev, "failed to enable sys_clk\n"); in xhci_mtk_clks_enable()
251 ret = clk_prepare_enable(mtk->xhci_clk); in xhci_mtk_clks_enable()
253 dev_err(mtk->dev, "failed to enable xhci_clk\n"); in xhci_mtk_clks_enable()
257 ret = clk_prepare_enable(mtk->mcu_clk); in xhci_mtk_clks_enable()
259 dev_err(mtk->dev, "failed to enable mcu_clk\n"); in xhci_mtk_clks_enable()
263 ret = clk_prepare_enable(mtk->dma_clk); in xhci_mtk_clks_enable()
265 dev_err(mtk->dev, "failed to enable dma_clk\n"); in xhci_mtk_clks_enable()
272 clk_disable_unprepare(mtk->mcu_clk); in xhci_mtk_clks_enable()
274 clk_disable_unprepare(mtk->xhci_clk); in xhci_mtk_clks_enable()
276 clk_disable_unprepare(mtk->sys_clk); in xhci_mtk_clks_enable()
278 clk_disable_unprepare(mtk->ref_clk); in xhci_mtk_clks_enable()
285 clk_disable_unprepare(mtk->dma_clk); in xhci_mtk_clks_disable()
286 clk_disable_unprepare(mtk->mcu_clk); in xhci_mtk_clks_disable()
287 clk_disable_unprepare(mtk->xhci_clk); in xhci_mtk_clks_disable()
288 clk_disable_unprepare(mtk->sys_clk); in xhci_mtk_clks_disable()
289 clk_disable_unprepare(mtk->ref_clk); in xhci_mtk_clks_disable()
292 /* only clocks can be turn off for ip-sleep wakeup mode */
295 u32 reg, msk, val; in usb_wakeup_ip_sleep_set() local
297 switch (mtk->uwk_vers) { in usb_wakeup_ip_sleep_set()
299 reg = mtk->uwk_reg_base + PERI_WK_CTRL1; in usb_wakeup_ip_sleep_set()
300 msk = WC1_IS_EN | WC1_IS_C(0xf) | WC1_IS_P; in usb_wakeup_ip_sleep_set()
304 reg = mtk->uwk_reg_base + PERI_SSUSB_SPM_CTRL; in usb_wakeup_ip_sleep_set()
305 msk = SSC_IP_SLEEP_EN | SSC_SPM_INT_EN; in usb_wakeup_ip_sleep_set()
306 val = enable ? msk : 0; in usb_wakeup_ip_sleep_set()
311 regmap_update_bits(mtk->uwk, reg, msk, val); in usb_wakeup_ip_sleep_set()
321 mtk->uwk_en = of_property_read_bool(dn, "wakeup-source"); in usb_wakeup_of_property_parse()
322 if (!mtk->uwk_en) in usb_wakeup_of_property_parse()
326 "mediatek,syscon-wakeup", 2, 0, &args); in usb_wakeup_of_property_parse()
330 mtk->uwk_reg_base = args.args[0]; in usb_wakeup_of_property_parse()
331 mtk->uwk_vers = args.args[1]; in usb_wakeup_of_property_parse()
332 mtk->uwk = syscon_node_to_regmap(args.np); in usb_wakeup_of_property_parse()
334 dev_info(mtk->dev, "uwk - reg:0x%x, version:%d\n", in usb_wakeup_of_property_parse()
335 mtk->uwk_reg_base, mtk->uwk_vers); in usb_wakeup_of_property_parse()
337 return PTR_ERR_OR_ZERO(mtk->uwk); in usb_wakeup_of_property_parse()
343 if (mtk->uwk_en) in usb_wakeup_set()
360 ret = regulator_enable(mtk->vbus); in xhci_mtk_ldos_enable()
362 dev_err(mtk->dev, "failed to enable vbus\n"); in xhci_mtk_ldos_enable()
366 ret = regulator_enable(mtk->vusb33); in xhci_mtk_ldos_enable()
368 dev_err(mtk->dev, "failed to enable vusb33\n"); in xhci_mtk_ldos_enable()
369 regulator_disable(mtk->vbus); in xhci_mtk_ldos_enable()
377 regulator_disable(mtk->vbus); in xhci_mtk_ldos_disable()
378 regulator_disable(mtk->vusb33); in xhci_mtk_ldos_disable()
391 xhci->quirks |= XHCI_PLAT; in xhci_mtk_quirks()
392 xhci->quirks |= XHCI_MTK_HOST; in xhci_mtk_quirks()
397 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; in xhci_mtk_quirks()
398 if (mtk->lpm_support) in xhci_mtk_quirks()
399 xhci->quirks |= XHCI_LPM_SUPPORT; in xhci_mtk_quirks()
400 if (mtk->u2_lpm_disable) in xhci_mtk_quirks()
401 xhci->quirks |= XHCI_HW_LPM_DISABLE; in xhci_mtk_quirks()
407 if (xhci->hci_version < 0x100 && HCC_MAX_PSA(xhci->hcc_params) == 4) in xhci_mtk_quirks()
408 xhci->quirks |= XHCI_BROKEN_STREAMS; in xhci_mtk_quirks()
438 struct device *dev = &pdev->dev; in xhci_mtk_probe()
439 struct device_node *node = dev->of_node; in xhci_mtk_probe()
445 int ret = -ENODEV; in xhci_mtk_probe()
449 return -ENODEV; in xhci_mtk_probe()
454 return -ENOMEM; in xhci_mtk_probe()
456 mtk->dev = dev; in xhci_mtk_probe()
457 mtk->vbus = devm_regulator_get(dev, "vbus"); in xhci_mtk_probe()
458 if (IS_ERR(mtk->vbus)) { in xhci_mtk_probe()
460 return PTR_ERR(mtk->vbus); in xhci_mtk_probe()
463 mtk->vusb33 = devm_regulator_get(dev, "vusb33"); in xhci_mtk_probe()
464 if (IS_ERR(mtk->vusb33)) { in xhci_mtk_probe()
466 return PTR_ERR(mtk->vusb33); in xhci_mtk_probe()
473 mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable"); in xhci_mtk_probe()
474 mtk->u2_lpm_disable = of_property_read_bool(node, "usb2-lpm-disable"); in xhci_mtk_probe()
476 of_property_read_u32(node, "mediatek,u3p-dis-msk", in xhci_mtk_probe()
477 &mtk->u3p_dis_msk); in xhci_mtk_probe()
505 ret = -ENOMEM; in xhci_mtk_probe()
513 mtk->hcd = platform_get_drvdata(pdev); in xhci_mtk_probe()
517 hcd->regs = devm_ioremap_resource(dev, res); in xhci_mtk_probe()
518 if (IS_ERR(hcd->regs)) { in xhci_mtk_probe()
519 ret = PTR_ERR(hcd->regs); in xhci_mtk_probe()
522 hcd->rsrc_start = res->start; in xhci_mtk_probe()
523 hcd->rsrc_len = resource_size(res); in xhci_mtk_probe()
527 mtk->ippc_regs = devm_ioremap_resource(dev, res); in xhci_mtk_probe()
528 if (IS_ERR(mtk->ippc_regs)) { in xhci_mtk_probe()
529 ret = PTR_ERR(mtk->ippc_regs); in xhci_mtk_probe()
532 mtk->has_ippc = true; in xhci_mtk_probe()
534 mtk->has_ippc = false; in xhci_mtk_probe()
541 xhci->main_hcd = hcd; in xhci_mtk_probe()
548 xhci->imod_interval = 5000; in xhci_mtk_probe()
549 device_property_read_u32(dev, "imod-interval-ns", &xhci->imod_interval); in xhci_mtk_probe()
551 xhci->shared_hcd = usb_create_shared_hcd(driver, dev, in xhci_mtk_probe()
553 if (!xhci->shared_hcd) { in xhci_mtk_probe()
554 ret = -ENOMEM; in xhci_mtk_probe()
562 if (HCC_MAX_PSA(xhci->hcc_params) >= 4 && in xhci_mtk_probe()
563 !(xhci->quirks & XHCI_BROKEN_STREAMS)) in xhci_mtk_probe()
564 xhci->shared_hcd->can_do_streams = 1; in xhci_mtk_probe()
566 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); in xhci_mtk_probe()
577 usb_put_hcd(xhci->shared_hcd); in xhci_mtk_probe()
600 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_remove()
602 struct usb_hcd *shared_hcd = xhci->shared_hcd; in xhci_mtk_remove()
604 pm_runtime_put_noidle(&dev->dev); in xhci_mtk_remove()
605 pm_runtime_disable(&dev->dev); in xhci_mtk_remove()
608 xhci->shared_hcd = NULL; in xhci_mtk_remove()
609 device_init_wakeup(&dev->dev, false); in xhci_mtk_remove()
631 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_suspend()
635 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_mtk_suspend()
636 del_timer_sync(&hcd->rh_timer); in xhci_mtk_suspend()
637 clear_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_mtk_suspend()
638 del_timer_sync(&xhci->shared_hcd->rh_timer); in xhci_mtk_suspend()
649 struct usb_hcd *hcd = mtk->hcd; in xhci_mtk_resume()
657 set_bit(HCD_FLAG_POLL_RH, &xhci->shared_hcd->flags); in xhci_mtk_resume()
658 usb_hcd_poll_rh_status(xhci->shared_hcd); in xhci_mtk_resume()
659 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in xhci_mtk_resume()
671 { .compatible = "mediatek,mt8173-xhci"},
672 { .compatible = "mediatek,mtk-xhci"},
682 .name = "xhci-mtk",
687 MODULE_ALIAS("platform:xhci-mtk");