Lines Matching +full:toggle +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/dma-mapping.h>
25 /* MediaTek controller toggle enable and status reg */
57 struct device *dev = glue->dev; in mtk_musb_clks_get()
59 glue->clks[0].id = "main"; in mtk_musb_clks_get()
60 glue->clks[1].id = "mcu"; in mtk_musb_clks_get()
61 glue->clks[2].id = "univpll"; in mtk_musb_clks_get()
63 return devm_clk_bulk_get(dev, MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_clks_get()
68 struct musb *musb = glue->musb; in mtk_otg_switch_set()
69 u8 devctl = readb(musb->mregs + MUSB_DEVCTL); in mtk_otg_switch_set()
72 if (role == glue->role) in mtk_otg_switch_set()
77 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in mtk_otg_switch_set()
78 glue->phy_mode = PHY_MODE_USB_HOST; in mtk_otg_switch_set()
80 if (glue->role == USB_ROLE_NONE) in mtk_otg_switch_set()
81 phy_power_on(glue->phy); in mtk_otg_switch_set()
84 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in mtk_otg_switch_set()
88 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in mtk_otg_switch_set()
89 glue->phy_mode = PHY_MODE_USB_DEVICE; in mtk_otg_switch_set()
92 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in mtk_otg_switch_set()
93 if (glue->role == USB_ROLE_NONE) in mtk_otg_switch_set()
94 phy_power_on(glue->phy); in mtk_otg_switch_set()
99 glue->phy_mode = PHY_MODE_USB_OTG; in mtk_otg_switch_set()
102 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in mtk_otg_switch_set()
103 if (glue->role != USB_ROLE_NONE) in mtk_otg_switch_set()
104 phy_power_off(glue->phy); in mtk_otg_switch_set()
108 dev_err(glue->dev, "Invalid State\n"); in mtk_otg_switch_set()
109 return -EINVAL; in mtk_otg_switch_set()
112 glue->role = new_role; in mtk_otg_switch_set()
113 phy_set_mode(glue->phy, glue->phy_mode); in mtk_otg_switch_set()
127 return glue->role; in musb_usb_role_sx_get()
137 role_sx_desc.fwnode = dev_fwnode(glue->dev); in mtk_otg_switch_init()
139 glue->role_sw = usb_role_switch_register(glue->dev, &role_sx_desc); in mtk_otg_switch_init()
141 return PTR_ERR_OR_ZERO(glue->role_sw); in mtk_otg_switch_init()
146 return usb_role_switch_unregister(glue->role_sw); in mtk_otg_switch_exit()
155 spin_lock_irqsave(&musb->lock, flags); in generic_interrupt()
156 musb->int_usb = musb_clearb(musb->mregs, MUSB_INTRUSB); in generic_interrupt()
157 musb->int_rx = musb_clearw(musb->mregs, MUSB_INTRRX); in generic_interrupt()
158 musb->int_tx = musb_clearw(musb->mregs, MUSB_INTRTX); in generic_interrupt()
160 if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) { in generic_interrupt()
161 /* ep0 FADDR must be 0 when (re)entering peripheral mode */ in generic_interrupt()
162 musb_ep_select(musb->mregs, 0); in generic_interrupt()
163 musb_writeb(musb->mregs, MUSB_FADDR, 0); in generic_interrupt()
166 if (musb->int_usb || musb->int_tx || musb->int_rx) in generic_interrupt()
169 spin_unlock_irqrestore(&musb->lock, flags); in generic_interrupt()
180 l1_ints = musb_readl(musb->mregs, USB_L1INTS) & in mtk_musb_interrupt()
181 musb_readl(musb->mregs, USB_L1INTM); in mtk_musb_interrupt()
188 retval = dma_controller_irq(irq, musb->dma_controller); in mtk_musb_interrupt()
218 static int mtk_musb_set_mode(struct musb *musb, u8 mode) in mtk_musb_set_mode() argument
220 struct device *dev = musb->controller; in mtk_musb_set_mode()
221 struct mtk_glue *glue = dev_get_drvdata(dev->parent); in mtk_musb_set_mode()
225 switch (mode) { in mtk_musb_set_mode()
239 dev_err(glue->dev, "Invalid mode request\n"); in mtk_musb_set_mode()
240 return -EINVAL; in mtk_musb_set_mode()
243 if (glue->phy_mode == new_mode) in mtk_musb_set_mode()
246 if (musb->port_mode != MUSB_OTG) { in mtk_musb_set_mode()
247 dev_err(glue->dev, "Does not support changing modes\n"); in mtk_musb_set_mode()
248 return -EINVAL; in mtk_musb_set_mode()
257 struct device *dev = musb->controller; in mtk_musb_init()
258 struct mtk_glue *glue = dev_get_drvdata(dev->parent); in mtk_musb_init()
261 glue->musb = musb; in mtk_musb_init()
262 musb->phy = glue->phy; in mtk_musb_init()
263 musb->xceiv = glue->xceiv; in mtk_musb_init()
264 musb->is_host = false; in mtk_musb_init()
265 musb->isr = mtk_musb_interrupt; in mtk_musb_init()
267 /* Set TX/RX toggle enable */ in mtk_musb_init()
268 musb_writew(musb->mregs, MUSB_TXTOGEN, MTK_TOGGLE_EN); in mtk_musb_init()
269 musb_writew(musb->mregs, MUSB_RXTOGEN, MTK_TOGGLE_EN); in mtk_musb_init()
271 if (musb->port_mode == MUSB_OTG) { in mtk_musb_init()
277 ret = phy_init(glue->phy); in mtk_musb_init()
281 ret = phy_power_on(glue->phy); in mtk_musb_init()
285 phy_set_mode(glue->phy, glue->phy_mode); in mtk_musb_init()
288 musb_writel(musb->mregs, MUSB_HSDMA_INTR, in mtk_musb_init()
291 musb_writel(musb->mregs, USB_L1INTM, TX_INT_STATUS | RX_INT_STATUS | in mtk_musb_init()
296 phy_exit(glue->phy); in mtk_musb_init()
298 if (musb->port_mode == MUSB_OTG) in mtk_musb_init()
305 struct musb *musb = qh->hw_ep->musb; in mtk_musb_get_toggle()
306 u8 epnum = qh->hw_ep->epnum; in mtk_musb_get_toggle()
307 u16 toggle; in mtk_musb_get_toggle() local
309 toggle = musb_readw(musb->mregs, is_out ? MUSB_TXTOG : MUSB_RXTOG); in mtk_musb_get_toggle()
310 return toggle & (1 << epnum); in mtk_musb_get_toggle()
315 struct musb *musb = qh->hw_ep->musb; in mtk_musb_set_toggle()
316 u8 epnum = qh->hw_ep->epnum; in mtk_musb_set_toggle()
317 u16 value, toggle; in mtk_musb_set_toggle() local
319 toggle = usb_gettoggle(urb->dev, qh->epnum, is_out); in mtk_musb_set_toggle()
322 value = musb_readw(musb->mregs, MUSB_TXTOG); in mtk_musb_set_toggle()
323 value |= toggle << epnum; in mtk_musb_set_toggle()
324 musb_writew(musb->mregs, MUSB_TXTOG, value); in mtk_musb_set_toggle()
326 value = musb_readw(musb->mregs, MUSB_RXTOG); in mtk_musb_set_toggle()
327 value |= toggle << epnum; in mtk_musb_set_toggle()
328 musb_writew(musb->mregs, MUSB_RXTOG, value); in mtk_musb_set_toggle()
336 struct device *dev = musb->controller; in mtk_musb_exit()
337 struct mtk_glue *glue = dev_get_drvdata(dev->parent); in mtk_musb_exit()
340 phy_power_off(glue->phy); in mtk_musb_exit()
341 phy_exit(glue->phy); in mtk_musb_exit()
342 clk_bulk_disable_unprepare(MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_exit()
395 .name = "musb-hdrc",
405 struct device *dev = &pdev->dev; in mtk_musb_probe()
406 struct device_node *np = dev->of_node; in mtk_musb_probe()
411 return -ENOMEM; in mtk_musb_probe()
413 glue->dev = dev; in mtk_musb_probe()
416 return -ENOMEM; in mtk_musb_probe()
427 pdata->config = &mtk_musb_hdrc_config; in mtk_musb_probe()
428 pdata->platform_ops = &mtk_musb_ops; in mtk_musb_probe()
429 pdata->mode = usb_get_dr_mode(dev); in mtk_musb_probe()
432 pdata->mode = USB_DR_MODE_HOST; in mtk_musb_probe()
434 pdata->mode = USB_DR_MODE_PERIPHERAL; in mtk_musb_probe()
436 switch (pdata->mode) { in mtk_musb_probe()
438 glue->phy_mode = PHY_MODE_USB_HOST; in mtk_musb_probe()
439 glue->role = USB_ROLE_HOST; in mtk_musb_probe()
442 glue->phy_mode = PHY_MODE_USB_DEVICE; in mtk_musb_probe()
443 glue->role = USB_ROLE_DEVICE; in mtk_musb_probe()
446 glue->phy_mode = PHY_MODE_USB_OTG; in mtk_musb_probe()
447 glue->role = USB_ROLE_NONE; in mtk_musb_probe()
450 return dev_err_probe(&pdev->dev, -EINVAL, in mtk_musb_probe()
454 glue->phy = devm_of_phy_get_by_index(dev, np, 0); in mtk_musb_probe()
455 if (IS_ERR(glue->phy)) in mtk_musb_probe()
456 return dev_err_probe(dev, PTR_ERR(glue->phy), in mtk_musb_probe()
459 glue->usb_phy = usb_phy_generic_register(); in mtk_musb_probe()
460 if (IS_ERR(glue->usb_phy)) in mtk_musb_probe()
461 return dev_err_probe(dev, PTR_ERR(glue->usb_phy), in mtk_musb_probe()
462 "fail to registering usb-phy\n"); in mtk_musb_probe()
464 glue->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in mtk_musb_probe()
465 if (IS_ERR(glue->xceiv)) { in mtk_musb_probe()
466 ret = PTR_ERR(glue->xceiv); in mtk_musb_probe()
467 dev_err(dev, "fail to getting usb-phy %d\n", ret); in mtk_musb_probe()
475 ret = clk_bulk_prepare_enable(MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_probe()
481 pinfo.res = pdev->resource; in mtk_musb_probe()
482 pinfo.num_res = pdev->num_resources; in mtk_musb_probe()
488 glue->musb_pdev = platform_device_register_full(&pinfo); in mtk_musb_probe()
489 if (IS_ERR(glue->musb_pdev)) { in mtk_musb_probe()
490 ret = PTR_ERR(glue->musb_pdev); in mtk_musb_probe()
498 clk_bulk_disable_unprepare(MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_probe()
503 usb_phy_generic_unregister(glue->usb_phy); in mtk_musb_probe()
510 struct platform_device *usb_phy = glue->usb_phy; in mtk_musb_remove()
512 platform_device_unregister(glue->musb_pdev); in mtk_musb_remove()
518 {.compatible = "mediatek,mtk-musb",},
528 .name = "musb-mtk",