Lines Matching +full:mt8173 +full:- +full:mtu3
1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/dma-mapping.h>
18 #include "mtu3.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()
243 ssusb->num_phys = of_count_phandle_with_args(node, in get_ssusb_rscs()
244 "phys", "#phy-cells"); in get_ssusb_rscs()
245 if (ssusb->num_phys > 0) { in get_ssusb_rscs()
246 ssusb->phys = devm_kcalloc(dev, ssusb->num_phys, in get_ssusb_rscs()
247 sizeof(*ssusb->phys), GFP_KERNEL); in get_ssusb_rscs()
248 if (!ssusb->phys) in get_ssusb_rscs()
249 return -ENOMEM; in get_ssusb_rscs()
251 ssusb->num_phys = 0; in get_ssusb_rscs()
254 for (i = 0; i < ssusb->num_phys; i++) { in get_ssusb_rscs()
255 ssusb->phys[i] = devm_of_phy_get_by_index(dev, node, i); in get_ssusb_rscs()
256 if (IS_ERR(ssusb->phys[i])) { in get_ssusb_rscs()
257 dev_err(dev, "failed to get phy-%d\n", i); in get_ssusb_rscs()
258 return PTR_ERR(ssusb->phys[i]); in get_ssusb_rscs()
262 ssusb->ippc_base = devm_platform_ioremap_resource_byname(pdev, "ippc"); in get_ssusb_rscs()
263 if (IS_ERR(ssusb->ippc_base)) in get_ssusb_rscs()
264 return PTR_ERR(ssusb->ippc_base); in get_ssusb_rscs()
266 ssusb->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); in get_ssusb_rscs()
267 if (ssusb->wakeup_irq == -EPROBE_DEFER) in get_ssusb_rscs()
268 return ssusb->wakeup_irq; in get_ssusb_rscs()
270 ssusb->dr_mode = usb_get_dr_mode(dev); in get_ssusb_rscs()
271 if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) in get_ssusb_rscs()
272 ssusb->dr_mode = USB_DR_MODE_OTG; in get_ssusb_rscs()
274 of_property_read_u32(node, "mediatek,u3p-dis-msk", &ssusb->u3p_dis_msk); in get_ssusb_rscs()
276 if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL) in get_ssusb_rscs()
287 of_property_read_u32(node, "mediatek,u2p-dis-msk", in get_ssusb_rscs()
288 &ssusb->u2p_dis_msk); in get_ssusb_rscs()
290 otg_sx->vbus = devm_regulator_get(dev, "vbus"); in get_ssusb_rscs()
291 if (IS_ERR(otg_sx->vbus)) { in get_ssusb_rscs()
293 return PTR_ERR(otg_sx->vbus); in get_ssusb_rscs()
296 if (ssusb->dr_mode == USB_DR_MODE_HOST) in get_ssusb_rscs()
299 /* if dual-role mode is supported */ in get_ssusb_rscs()
300 otg_sx->manual_drd_enabled = in get_ssusb_rscs()
301 of_property_read_bool(node, "enable-manual-drd"); in get_ssusb_rscs()
302 otg_sx->role_sw_used = of_property_read_bool(node, "usb-role-switch"); in get_ssusb_rscs()
304 /* can't disable port0 when use dual-role mode */ in get_ssusb_rscs()
305 ssusb->u2p_dis_msk &= ~0x1; in get_ssusb_rscs()
307 if (otg_sx->role_sw_used || otg_sx->manual_drd_enabled) in get_ssusb_rscs()
311 otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0); in get_ssusb_rscs()
312 if (IS_ERR(otg_sx->edev)) { in get_ssusb_rscs()
313 return dev_err_probe(dev, PTR_ERR(otg_sx->edev), in get_ssusb_rscs()
319 dev_info(dev, "dr_mode: %d, drd: %s\n", ssusb->dr_mode, in get_ssusb_rscs()
320 otg_sx->manual_drd_enabled ? "manual" : "auto"); in get_ssusb_rscs()
322 ssusb->u2p_dis_msk, ssusb->u3p_dis_msk); in get_ssusb_rscs()
329 struct device_node *node = pdev->dev.of_node; in mtu3_probe()
330 struct device *dev = &pdev->dev; in mtu3_probe()
332 int ret = -ENOMEM; in mtu3_probe()
337 return -ENOMEM; in mtu3_probe()
342 return -ENOTSUPP; in mtu3_probe()
346 ssusb->dev = dev; in mtu3_probe()
367 if (ssusb->wakeup_irq > 0) { in mtu3_probe()
368 ret = dev_pm_set_dedicated_wake_irq_reverse(dev, ssusb->wakeup_irq); in mtu3_probe()
370 dev_err(dev, "failed to set wakeup irq %d\n", ssusb->wakeup_irq); in mtu3_probe()
373 dev_info(dev, "wakeup irq %d\n", ssusb->wakeup_irq); in mtu3_probe()
386 ssusb->dr_mode = USB_DR_MODE_HOST; in mtu3_probe()
388 ssusb->dr_mode = USB_DR_MODE_PERIPHERAL; in mtu3_probe()
391 ssusb->is_host = !(ssusb->dr_mode == USB_DR_MODE_PERIPHERAL); in mtu3_probe()
393 switch (ssusb->dr_mode) { in mtu3_probe()
428 dev_err(dev, "unsupported mode: %d\n", ssusb->dr_mode); in mtu3_probe()
429 ret = -EINVAL; in mtu3_probe()
458 pm_runtime_get_sync(&pdev->dev); in mtu3_remove()
460 switch (ssusb->dr_mode) { in mtu3_remove()
486 pm_runtime_disable(&pdev->dev); in mtu3_remove()
487 pm_runtime_put_noidle(&pdev->dev); in mtu3_remove()
488 pm_runtime_set_suspended(&pdev->dev); in mtu3_remove()
493 switch (ssusb->dr_mode) { in resume_ip_and_ports()
501 ssusb_host_resume(ssusb, !ssusb->is_host); in resume_ip_and_ports()
502 if (!ssusb->is_host) in resume_ip_and_ports()
507 return -EINVAL; in resume_ip_and_ports()
520 switch (ssusb->dr_mode) { in mtu3_suspend_common()
531 if (!ssusb->is_host) { in mtu3_suspend_common()
539 return -EINVAL; in mtu3_suspend_common()
547 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); in mtu3_suspend_common()
565 ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks); in mtu3_resume_common()
576 clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); in mtu3_resume_common()
616 {.compatible = "mediatek,mt8173-mtu3",},
617 {.compatible = "mediatek,mtu3",},