Lines Matching +full:toggle +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/dma-mapping.h>
24 /* MediaTek controller toggle enable and status reg */
56 struct device *dev = glue->dev; in mtk_musb_clks_get()
58 glue->clks[0].id = "main"; in mtk_musb_clks_get()
59 glue->clks[1].id = "mcu"; in mtk_musb_clks_get()
60 glue->clks[2].id = "univpll"; in mtk_musb_clks_get()
62 return devm_clk_bulk_get(dev, MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_clks_get()
67 struct musb *musb = glue->musb; in mtk_otg_switch_set()
68 u8 devctl = readb(musb->mregs + MUSB_DEVCTL); in mtk_otg_switch_set()
71 if (role == glue->role) in mtk_otg_switch_set()
76 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in mtk_otg_switch_set()
77 glue->phy_mode = PHY_MODE_USB_HOST; in mtk_otg_switch_set()
79 if (glue->role == USB_ROLE_NONE) in mtk_otg_switch_set()
80 phy_power_on(glue->phy); in mtk_otg_switch_set()
83 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in mtk_otg_switch_set()
87 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in mtk_otg_switch_set()
88 glue->phy_mode = PHY_MODE_USB_DEVICE; in mtk_otg_switch_set()
91 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in mtk_otg_switch_set()
92 if (glue->role == USB_ROLE_NONE) in mtk_otg_switch_set()
93 phy_power_on(glue->phy); in mtk_otg_switch_set()
98 glue->phy_mode = PHY_MODE_USB_OTG; in mtk_otg_switch_set()
101 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in mtk_otg_switch_set()
102 if (glue->role != USB_ROLE_NONE) in mtk_otg_switch_set()
103 phy_power_off(glue->phy); in mtk_otg_switch_set()
107 dev_err(glue->dev, "Invalid State\n"); in mtk_otg_switch_set()
108 return -EINVAL; in mtk_otg_switch_set()
111 glue->role = new_role; in mtk_otg_switch_set()
112 phy_set_mode(glue->phy, glue->phy_mode); in mtk_otg_switch_set()
126 return glue->role; in musb_usb_role_sx_get()
136 role_sx_desc.fwnode = dev_fwnode(glue->dev); in mtk_otg_switch_init()
138 glue->role_sw = usb_role_switch_register(glue->dev, &role_sx_desc); in mtk_otg_switch_init()
140 return PTR_ERR_OR_ZERO(glue->role_sw); in mtk_otg_switch_init()
145 return usb_role_switch_unregister(glue->role_sw); in mtk_otg_switch_exit()
154 spin_lock_irqsave(&musb->lock, flags); in generic_interrupt()
155 musb->int_usb = musb_clearb(musb->mregs, MUSB_INTRUSB); in generic_interrupt()
156 musb->int_rx = musb_clearw(musb->mregs, MUSB_INTRRX); in generic_interrupt()
157 musb->int_tx = musb_clearw(musb->mregs, MUSB_INTRTX); in generic_interrupt()
159 if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) { in generic_interrupt()
160 /* ep0 FADDR must be 0 when (re)entering peripheral mode */ in generic_interrupt()
161 musb_ep_select(musb->mregs, 0); in generic_interrupt()
162 musb_writeb(musb->mregs, MUSB_FADDR, 0); in generic_interrupt()
165 if (musb->int_usb || musb->int_tx || musb->int_rx) in generic_interrupt()
168 spin_unlock_irqrestore(&musb->lock, flags); in generic_interrupt()
179 l1_ints = musb_readl(musb->mregs, USB_L1INTS) & in mtk_musb_interrupt()
180 musb_readl(musb->mregs, USB_L1INTM); in mtk_musb_interrupt()
187 retval = dma_controller_irq(irq, musb->dma_controller); in mtk_musb_interrupt()
217 static int mtk_musb_set_mode(struct musb *musb, u8 mode) in mtk_musb_set_mode() argument
219 struct device *dev = musb->controller; in mtk_musb_set_mode()
220 struct mtk_glue *glue = dev_get_drvdata(dev->parent); in mtk_musb_set_mode()
224 switch (mode) { in mtk_musb_set_mode()
238 dev_err(glue->dev, "Invalid mode request\n"); in mtk_musb_set_mode()
239 return -EINVAL; in mtk_musb_set_mode()
242 if (glue->phy_mode == new_mode) in mtk_musb_set_mode()
245 if (musb->port_mode != MUSB_OTG) { in mtk_musb_set_mode()
246 dev_err(glue->dev, "Does not support changing modes\n"); in mtk_musb_set_mode()
247 return -EINVAL; in mtk_musb_set_mode()
256 struct device *dev = musb->controller; in mtk_musb_init()
257 struct mtk_glue *glue = dev_get_drvdata(dev->parent); in mtk_musb_init()
260 glue->musb = musb; in mtk_musb_init()
261 musb->phy = glue->phy; in mtk_musb_init()
262 musb->xceiv = glue->xceiv; in mtk_musb_init()
263 musb->is_host = false; in mtk_musb_init()
264 musb->isr = mtk_musb_interrupt; in mtk_musb_init()
266 /* Set TX/RX toggle enable */ in mtk_musb_init()
267 musb_writew(musb->mregs, MUSB_TXTOGEN, MTK_TOGGLE_EN); in mtk_musb_init()
268 musb_writew(musb->mregs, MUSB_RXTOGEN, MTK_TOGGLE_EN); in mtk_musb_init()
270 if (musb->port_mode == MUSB_OTG) { in mtk_musb_init()
276 ret = phy_init(glue->phy); in mtk_musb_init()
280 ret = phy_power_on(glue->phy); in mtk_musb_init()
284 phy_set_mode(glue->phy, glue->phy_mode); in mtk_musb_init()
287 musb_writel(musb->mregs, MUSB_HSDMA_INTR, in mtk_musb_init()
290 musb_writel(musb->mregs, USB_L1INTM, TX_INT_STATUS | RX_INT_STATUS | in mtk_musb_init()
295 phy_exit(glue->phy); in mtk_musb_init()
303 struct musb *musb = qh->hw_ep->musb; in mtk_musb_get_toggle()
304 u8 epnum = qh->hw_ep->epnum; in mtk_musb_get_toggle()
305 u16 toggle; in mtk_musb_get_toggle() local
307 toggle = musb_readw(musb->mregs, is_out ? MUSB_TXTOG : MUSB_RXTOG); in mtk_musb_get_toggle()
308 return toggle & (1 << epnum); in mtk_musb_get_toggle()
313 struct musb *musb = qh->hw_ep->musb; in mtk_musb_set_toggle()
314 u8 epnum = qh->hw_ep->epnum; in mtk_musb_set_toggle()
315 u16 value, toggle; in mtk_musb_set_toggle() local
317 toggle = usb_gettoggle(urb->dev, qh->epnum, is_out); in mtk_musb_set_toggle()
320 value = musb_readw(musb->mregs, MUSB_TXTOG); in mtk_musb_set_toggle()
321 value |= toggle << epnum; in mtk_musb_set_toggle()
322 musb_writew(musb->mregs, MUSB_TXTOG, value); in mtk_musb_set_toggle()
324 value = musb_readw(musb->mregs, MUSB_RXTOG); in mtk_musb_set_toggle()
325 value |= toggle << epnum; in mtk_musb_set_toggle()
326 musb_writew(musb->mregs, MUSB_RXTOG, value); in mtk_musb_set_toggle()
334 struct device *dev = musb->controller; in mtk_musb_exit()
335 struct mtk_glue *glue = dev_get_drvdata(dev->parent); in mtk_musb_exit()
338 phy_power_off(glue->phy); in mtk_musb_exit()
339 phy_exit(glue->phy); in mtk_musb_exit()
340 clk_bulk_disable_unprepare(MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_exit()
393 .name = "musb-hdrc",
403 struct device *dev = &pdev->dev; in mtk_musb_probe()
404 struct device_node *np = dev->of_node; in mtk_musb_probe()
409 return -ENOMEM; in mtk_musb_probe()
411 glue->dev = dev; in mtk_musb_probe()
414 return -ENOMEM; in mtk_musb_probe()
426 pdata->config = &mtk_musb_hdrc_config; in mtk_musb_probe()
427 pdata->platform_ops = &mtk_musb_ops; in mtk_musb_probe()
428 pdata->mode = usb_get_dr_mode(dev); in mtk_musb_probe()
431 pdata->mode = USB_DR_MODE_HOST; in mtk_musb_probe()
433 pdata->mode = USB_DR_MODE_PERIPHERAL; in mtk_musb_probe()
435 switch (pdata->mode) { in mtk_musb_probe()
437 glue->phy_mode = PHY_MODE_USB_HOST; in mtk_musb_probe()
438 glue->role = USB_ROLE_HOST; in mtk_musb_probe()
441 glue->phy_mode = PHY_MODE_USB_DEVICE; in mtk_musb_probe()
442 glue->role = USB_ROLE_DEVICE; in mtk_musb_probe()
445 glue->phy_mode = PHY_MODE_USB_OTG; in mtk_musb_probe()
446 glue->role = USB_ROLE_NONE; in mtk_musb_probe()
449 dev_err(&pdev->dev, "Error 'dr_mode' property\n"); in mtk_musb_probe()
450 return -EINVAL; in mtk_musb_probe()
453 glue->phy = devm_of_phy_get_by_index(dev, np, 0); in mtk_musb_probe()
454 if (IS_ERR(glue->phy)) { in mtk_musb_probe()
456 PTR_ERR(glue->phy)); in mtk_musb_probe()
457 return PTR_ERR(glue->phy); in mtk_musb_probe()
460 glue->usb_phy = usb_phy_generic_register(); in mtk_musb_probe()
461 if (IS_ERR(glue->usb_phy)) { in mtk_musb_probe()
462 dev_err(dev, "fail to registering usb-phy %ld\n", in mtk_musb_probe()
463 PTR_ERR(glue->usb_phy)); in mtk_musb_probe()
464 return PTR_ERR(glue->usb_phy); in mtk_musb_probe()
467 glue->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); in mtk_musb_probe()
468 if (IS_ERR(glue->xceiv)) { in mtk_musb_probe()
469 ret = PTR_ERR(glue->xceiv); in mtk_musb_probe()
470 dev_err(dev, "fail to getting usb-phy %d\n", ret); in mtk_musb_probe()
478 ret = clk_bulk_prepare_enable(MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_probe()
484 pinfo.res = pdev->resource; in mtk_musb_probe()
485 pinfo.num_res = pdev->num_resources; in mtk_musb_probe()
491 glue->musb_pdev = platform_device_register_full(&pinfo); in mtk_musb_probe()
492 if (IS_ERR(glue->musb_pdev)) { in mtk_musb_probe()
493 ret = PTR_ERR(glue->musb_pdev); in mtk_musb_probe()
501 clk_bulk_disable_unprepare(MTK_MUSB_CLKS_NUM, glue->clks); in mtk_musb_probe()
506 usb_phy_generic_unregister(glue->usb_phy); in mtk_musb_probe()
513 struct platform_device *usb_phy = glue->usb_phy; in mtk_musb_remove()
515 platform_device_unregister(glue->musb_pdev); in mtk_musb_remove()
523 {.compatible = "mediatek,mtk-musb",},
533 .name = "musb-mtk",