Lines Matching +full:u3p +full:- +full:dis +full:- +full:msk
1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/dma-mapping.h>
22 /* u2-port0 should be powered on and enabled; */
25 void __iomem *ibase = ssusb->ippc_base; in ssusb_check_clocks()
35 dev_err(ssusb->dev, "clks of sts1 are not stable!\n"); in ssusb_check_clocks()
42 dev_err(ssusb->dev, "mac2 clock is not stable\n"); in ssusb_check_clocks()
55 if (!ssusb->is_host) in wait_for_ip_sleep()
62 ret = readl_poll_timeout(ssusb->ippc_base + U3D_SSUSB_IP_PW_STS1, value, in wait_for_ip_sleep()
65 dev_err(ssusb->dev, "ip sleep failed!!!\n"); in wait_for_ip_sleep()
66 ret = -EBUSY; in wait_for_ip_sleep()
80 for (i = 0; i < ssusb->num_phys; i++) { in ssusb_phy_init()
81 ret = phy_init(ssusb->phys[i]); in ssusb_phy_init()
88 for (; i > 0; i--) in ssusb_phy_init()
89 phy_exit(ssusb->phys[i - 1]); in ssusb_phy_init()
98 for (i = 0; i < ssusb->num_phys; i++) in ssusb_phy_exit()
99 phy_exit(ssusb->phys[i]); in ssusb_phy_exit()
109 for (i = 0; i < ssusb->num_phys; i++) { in ssusb_phy_power_on()
110 ret = phy_power_on(ssusb->phys[i]); in ssusb_phy_power_on()
117 for (; i > 0; i--) in ssusb_phy_power_on()
118 phy_power_off(ssusb->phys[i - 1]); in ssusb_phy_power_on()
127 for (i = 0; i < ssusb->num_phys; i++) in ssusb_phy_power_off()
128 phy_power_off(ssusb->phys[i]); in ssusb_phy_power_off()
135 ret = regulator_enable(ssusb->vusb33); in ssusb_rscs_init()
137 dev_err(ssusb->dev, "failed to enable vusb33\n"); in ssusb_rscs_init()
141 ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks); in ssusb_rscs_init()
147 dev_err(ssusb->dev, "failed to init phy\n"); in ssusb_rscs_init()
153 dev_err(ssusb->dev, "failed to power on phy\n"); in ssusb_rscs_init()
162 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); in ssusb_rscs_init()
164 regulator_disable(ssusb->vusb33); in ssusb_rscs_init()
171 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); in ssusb_rscs_exit()
172 regulator_disable(ssusb->vusb33); in ssusb_rscs_exit()
180 mtu3_setbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL0, SSUSB_IP_SW_RST); in ssusb_ip_sw_reset()
182 mtu3_clrbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL0, SSUSB_IP_SW_RST); in ssusb_ip_sw_reset()
187 * power down device ip, otherwise ip-sleep will fail when working as in ssusb_ip_sw_reset()
190 mtu3_setbits(ssusb->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); in ssusb_ip_sw_reset()
195 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; in ssusb_u3_drd_check()
201 if (ssusb->u3p_dis_msk & BIT(0)) { in ssusb_u3_drd_check()
202 otg_sx->is_u3_drd = false; in ssusb_u3_drd_check()
206 value = mtu3_readl(ssusb->ippc_base, U3D_SSUSB_IP_DEV_CAP); in ssusb_u3_drd_check()
209 value = mtu3_readl(ssusb->ippc_base, U3D_SSUSB_IP_XHCI_CAP); in ssusb_u3_drd_check()
212 otg_sx->is_u3_drd = !!(dev_u3p_num && host_u3p_num); in ssusb_u3_drd_check()
215 dev_info(ssusb->dev, "usb3-drd: %d\n", otg_sx->is_u3_drd); in ssusb_u3_drd_check()
220 struct device_node *node = pdev->dev.of_node; in get_ssusb_rscs()
221 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; in get_ssusb_rscs()
222 struct clk_bulk_data *clks = ssusb->clks; in get_ssusb_rscs()
223 struct device *dev = &pdev->dev; in get_ssusb_rscs()
227 ssusb->vusb33 = devm_regulator_get(dev, "vusb33"); in get_ssusb_rscs()
228 if (IS_ERR(ssusb->vusb33)) { in get_ssusb_rscs()
230 return PTR_ERR(ssusb->vusb33); in get_ssusb_rscs()
241 ssusb->num_phys = of_count_phandle_with_args(node, in get_ssusb_rscs()
242 "phys", "#phy-cells"); in get_ssusb_rscs()
243 if (ssusb->num_phys > 0) { in get_ssusb_rscs()
244 ssusb->phys = devm_kcalloc(dev, ssusb->num_phys, in get_ssusb_rscs()
245 sizeof(*ssusb->phys), GFP_KERNEL); in get_ssusb_rscs()
246 if (!ssusb->phys) in get_ssusb_rscs()
247 return -ENOMEM; in get_ssusb_rscs()
249 ssusb->num_phys = 0; in get_ssusb_rscs()
252 for (i = 0; i < ssusb->num_phys; i++) { in get_ssusb_rscs()
253 ssusb->phys[i] = devm_of_phy_get_by_index(dev, node, i); in get_ssusb_rscs()
254 if (IS_ERR(ssusb->phys[i])) { in get_ssusb_rscs()
255 dev_err(dev, "failed to get phy-%d\n", i); in get_ssusb_rscs()
256 return PTR_ERR(ssusb->phys[i]); in get_ssusb_rscs()
260 ssusb->ippc_base = devm_platform_ioremap_resource_byname(pdev, "ippc"); in get_ssusb_rscs()
261 if (IS_ERR(ssusb->ippc_base)) in get_ssusb_rscs()
262 return PTR_ERR(ssusb->ippc_base); in get_ssusb_rscs()
264 ssusb->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); in get_ssusb_rscs()
265 if (ssusb->wakeup_irq == -EPROBE_DEFER) in get_ssusb_rscs()
266 return ssusb->wakeup_irq; in get_ssusb_rscs()
268 ssusb->dr_mode = usb_get_dr_mode(dev); in get_ssusb_rscs()
269 if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) in get_ssusb_rscs()
270 ssusb->dr_mode = USB_DR_MODE_OTG; in get_ssusb_rscs()
272 of_property_read_u32(node, "mediatek,u3p-dis-msk", &ssusb->u3p_dis_msk); in get_ssusb_rscs()
274 if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL) in get_ssusb_rscs()
285 of_property_read_u32(node, "mediatek,u2p-dis-msk", in get_ssusb_rscs()
286 &ssusb->u2p_dis_msk); in get_ssusb_rscs()
288 otg_sx->vbus = devm_regulator_get(dev, "vbus"); in get_ssusb_rscs()
289 if (IS_ERR(otg_sx->vbus)) { in get_ssusb_rscs()
291 return PTR_ERR(otg_sx->vbus); in get_ssusb_rscs()
294 if (ssusb->dr_mode == USB_DR_MODE_HOST) in get_ssusb_rscs()
297 /* if dual-role mode is supported */ in get_ssusb_rscs()
298 otg_sx->manual_drd_enabled = in get_ssusb_rscs()
299 of_property_read_bool(node, "enable-manual-drd"); in get_ssusb_rscs()
300 otg_sx->role_sw_used = of_property_read_bool(node, "usb-role-switch"); in get_ssusb_rscs()
302 /* can't disable port0 when use dual-role mode */ in get_ssusb_rscs()
303 ssusb->u2p_dis_msk &= ~0x1; in get_ssusb_rscs()
305 if (otg_sx->role_sw_used || otg_sx->manual_drd_enabled) in get_ssusb_rscs()
309 otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0); in get_ssusb_rscs()
310 if (IS_ERR(otg_sx->edev)) { in get_ssusb_rscs()
311 return dev_err_probe(dev, PTR_ERR(otg_sx->edev), in get_ssusb_rscs()
317 dev_info(dev, "dr_mode: %d, drd: %s\n", ssusb->dr_mode, in get_ssusb_rscs()
318 otg_sx->manual_drd_enabled ? "manual" : "auto"); in get_ssusb_rscs()
320 ssusb->u2p_dis_msk, ssusb->u3p_dis_msk); in get_ssusb_rscs()
327 struct device_node *node = pdev->dev.of_node; in mtu3_probe()
328 struct device *dev = &pdev->dev; in mtu3_probe()
330 int ret = -ENOMEM; in mtu3_probe()
335 return -ENOMEM; in mtu3_probe()
340 return -ENOTSUPP; in mtu3_probe()
344 ssusb->dev = dev; in mtu3_probe()
365 if (ssusb->wakeup_irq > 0) { in mtu3_probe()
366 ret = dev_pm_set_dedicated_wake_irq_reverse(dev, ssusb->wakeup_irq); in mtu3_probe()
368 dev_err(dev, "failed to set wakeup irq %d\n", ssusb->wakeup_irq); in mtu3_probe()
371 dev_info(dev, "wakeup irq %d\n", ssusb->wakeup_irq); in mtu3_probe()
384 ssusb->dr_mode = USB_DR_MODE_HOST; in mtu3_probe()
386 ssusb->dr_mode = USB_DR_MODE_PERIPHERAL; in mtu3_probe()
389 ssusb->is_host = !(ssusb->dr_mode == USB_DR_MODE_PERIPHERAL); in mtu3_probe()
391 switch (ssusb->dr_mode) { in mtu3_probe()
426 dev_err(dev, "unsupported mode: %d\n", ssusb->dr_mode); in mtu3_probe()
427 ret = -EINVAL; in mtu3_probe()
456 pm_runtime_get_sync(&pdev->dev); in mtu3_remove()
458 switch (ssusb->dr_mode) { in mtu3_remove()
471 return -EINVAL; in mtu3_remove()
476 pm_runtime_disable(&pdev->dev); in mtu3_remove()
477 pm_runtime_put_noidle(&pdev->dev); in mtu3_remove()
478 pm_runtime_set_suspended(&pdev->dev); in mtu3_remove()
485 switch (ssusb->dr_mode) { in resume_ip_and_ports()
493 ssusb_host_resume(ssusb, !ssusb->is_host); in resume_ip_and_ports()
494 if (!ssusb->is_host) in resume_ip_and_ports()
499 return -EINVAL; in resume_ip_and_ports()
512 switch (ssusb->dr_mode) { in mtu3_suspend_common()
523 if (!ssusb->is_host) { in mtu3_suspend_common()
531 return -EINVAL; in mtu3_suspend_common()
539 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); in mtu3_suspend_common()
557 ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks); in mtu3_resume_common()
568 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); in mtu3_resume_common()
608 {.compatible = "mediatek,mt8173-mtu3",},