Lines Matching +full:usb2 +full:- +full:phy1

1 // SPDX-License-Identifier: GPL-2.0
11 * - Control registers for each USB2 Ports
12 * - Control registers for the USB PHY layer
13 * - SuperSpeed PHY can be enabled only if port is used
14 * - Dynamic OTG switching with ID change interrupt
33 /* USB2 Ports Control Registers, offsets are per-port */
120 "usb2-phy0", "usb2-phy1", "usb2-phy2",
124 "usb2-phy0", "usb2-phy1", "usb3-phy0",
133 * correctly when only the "usb2-phy1" phy is specified on-par with the
137 "usb2-phy0", "usb2-phy1"
184 * In order to still switch from Host to Device on an USB Type-A port,
269 return phy_set_mode(priv->phys[i], mode); in dwc3_meson_gxl_set_phy_mode()
276 return priv->drvdata->set_phy_mode(priv, i, in dwc3_meson_gxl_usb2_init_phy()
285 regmap_update_bits(priv->u2p_regmap[i], U2P_R0, in dwc3_meson_g12a_set_phy_mode()
289 regmap_update_bits(priv->u2p_regmap[i], U2P_R0, in dwc3_meson_g12a_set_phy_mode()
300 regmap_update_bits(priv->u2p_regmap[i], U2P_R0, in dwc3_meson_g12a_usb2_init_phy()
305 regmap_update_bits(priv->u2p_regmap[i], U2P_R0, in dwc3_meson_g12a_usb2_init_phy()
309 ret = priv->drvdata->set_phy_mode(priv, i, mode); in dwc3_meson_g12a_usb2_init_phy()
311 ret = priv->drvdata->set_phy_mode(priv, i, in dwc3_meson_g12a_usb2_init_phy()
317 regmap_update_bits(priv->u2p_regmap[i], U2P_R0, in dwc3_meson_g12a_usb2_init_phy()
328 for (i = 0; i < priv->drvdata->num_phys; ++i) { in dwc3_meson_g12a_usb2_init()
329 if (!priv->phys[i]) in dwc3_meson_g12a_usb2_init()
332 if (!strstr(priv->drvdata->phy_names[i], "usb2")) in dwc3_meson_g12a_usb2_init()
335 ret = priv->drvdata->usb2_init_phy(priv, i, mode); in dwc3_meson_g12a_usb2_init()
345 regmap_update_bits(priv->usb_glue_regmap, USB_R3, in dwc3_meson_g12a_usb3_init()
353 regmap_update_bits(priv->usb_glue_regmap, USB_R2, in dwc3_meson_g12a_usb3_init()
357 regmap_update_bits(priv->usb_glue_regmap, USB_R2, in dwc3_meson_g12a_usb3_init()
363 regmap_update_bits(priv->usb_glue_regmap, USB_R1, in dwc3_meson_g12a_usb3_init()
367 regmap_update_bits(priv->usb_glue_regmap, USB_R1, in dwc3_meson_g12a_usb3_init()
376 if (priv->otg_mode != USB_DR_MODE_OTG && in dwc3_meson_g12a_usb_otg_apply_mode()
377 priv->drvdata->otg_phy_host_port_disable) in dwc3_meson_g12a_usb_otg_apply_mode()
379 regmap_update_bits(priv->usb_glue_regmap, USB_R1, in dwc3_meson_g12a_usb_otg_apply_mode()
384 regmap_update_bits(priv->usb_glue_regmap, USB_R0, in dwc3_meson_g12a_usb_otg_apply_mode()
386 regmap_update_bits(priv->usb_glue_regmap, USB_R0, in dwc3_meson_g12a_usb_otg_apply_mode()
388 regmap_update_bits(priv->usb_glue_regmap, USB_R4, in dwc3_meson_g12a_usb_otg_apply_mode()
391 if (priv->otg_mode != USB_DR_MODE_OTG && in dwc3_meson_g12a_usb_otg_apply_mode()
392 priv->drvdata->otg_phy_host_port_disable) { in dwc3_meson_g12a_usb_otg_apply_mode()
393 regmap_update_bits(priv->usb_glue_regmap, USB_R1, in dwc3_meson_g12a_usb_otg_apply_mode()
397 regmap_update_bits(priv->usb_glue_regmap, USB_R0, in dwc3_meson_g12a_usb_otg_apply_mode()
399 regmap_update_bits(priv->usb_glue_regmap, USB_R4, in dwc3_meson_g12a_usb_otg_apply_mode()
413 regmap_update_bits(priv->usb_glue_regmap, USB_R1, in dwc3_meson_g12a_usb_init_glue()
417 regmap_update_bits(priv->usb_glue_regmap, USB_R5, in dwc3_meson_g12a_usb_init_glue()
420 regmap_update_bits(priv->usb_glue_regmap, USB_R5, in dwc3_meson_g12a_usb_init_glue()
423 regmap_update_bits(priv->usb_glue_regmap, USB_R5, in dwc3_meson_g12a_usb_init_glue()
428 if (priv->usb3_ports) in dwc3_meson_g12a_usb_init_glue()
437 .name = "usb-glue",
449 for (i = 0 ; i < priv->drvdata->num_phys ; ++i) { in dwc3_meson_g12a_get_phys()
450 phy_name = priv->drvdata->phy_names[i]; in dwc3_meson_g12a_get_phys()
451 priv->phys[i] = devm_phy_optional_get(priv->dev, phy_name); in dwc3_meson_g12a_get_phys()
452 if (!priv->phys[i]) in dwc3_meson_g12a_get_phys()
455 if (IS_ERR(priv->phys[i])) in dwc3_meson_g12a_get_phys()
456 return PTR_ERR(priv->phys[i]); in dwc3_meson_g12a_get_phys()
459 priv->usb3_ports++; in dwc3_meson_g12a_get_phys()
461 priv->usb2_ports++; in dwc3_meson_g12a_get_phys()
464 dev_info(priv->dev, "USB2 ports: %d\n", priv->usb2_ports); in dwc3_meson_g12a_get_phys()
465 dev_info(priv->dev, "USB3 ports: %d\n", priv->usb3_ports); in dwc3_meson_g12a_get_phys()
474 regmap_read(priv->usb_glue_regmap, USB_R5, &reg); in dwc3_meson_g12a_get_id()
487 if (!priv->phys[USB2_OTG_PHY]) in dwc3_meson_g12a_otg_mode_set()
488 return -EINVAL; in dwc3_meson_g12a_otg_mode_set()
491 dev_info(priv->dev, "switching to Host Mode\n"); in dwc3_meson_g12a_otg_mode_set()
493 dev_info(priv->dev, "switching to Device Mode\n"); in dwc3_meson_g12a_otg_mode_set()
495 if (priv->vbus) { in dwc3_meson_g12a_otg_mode_set()
497 ret = regulator_disable(priv->vbus); in dwc3_meson_g12a_otg_mode_set()
499 ret = regulator_enable(priv->vbus); in dwc3_meson_g12a_otg_mode_set()
504 priv->otg_phy_mode = mode; in dwc3_meson_g12a_otg_mode_set()
506 ret = priv->drvdata->set_phy_mode(priv, USB2_OTG_PHY, mode); in dwc3_meson_g12a_otg_mode_set()
527 if (mode == priv->otg_phy_mode) in dwc3_meson_g12a_role_set()
530 if (priv->drvdata->otg_phy_host_port_disable) in dwc3_meson_g12a_role_set()
531 dev_warn_once(priv->dev, "Broken manual OTG switch\n"); in dwc3_meson_g12a_role_set()
540 return priv->otg_phy_mode == PHY_MODE_USB_HOST ? in dwc3_meson_g12a_role_get()
550 if (otg_id != priv->otg_phy_mode) { in dwc3_meson_g12a_irq_thread()
552 dev_warn(priv->dev, "Failed to switch OTG mode\n"); in dwc3_meson_g12a_irq_thread()
555 regmap_update_bits(priv->usb_glue_regmap, USB_R5, in dwc3_meson_g12a_irq_thread()
567 np = of_get_compatible_child(dev->of_node, compatible); in dwc3_meson_g12_find_child()
576 return &pdev->dev; in dwc3_meson_g12_find_child()
584 struct device *dev = &pdev->dev; in dwc3_meson_g12a_otg_init()
586 if (priv->otg_mode == USB_DR_MODE_OTG) { in dwc3_meson_g12a_otg_init()
588 regmap_update_bits(priv->usb_glue_regmap, USB_R5, in dwc3_meson_g12a_otg_init()
594 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in dwc3_meson_g12a_otg_init()
596 IRQF_ONESHOT, pdev->name, priv); in dwc3_meson_g12a_otg_init()
602 if (priv->otg_mode == USB_DR_MODE_OTG) { in dwc3_meson_g12a_otg_init()
604 if (otg_id != priv->otg_phy_mode) { in dwc3_meson_g12a_otg_init()
611 priv->switch_desc.usb2_port = dwc3_meson_g12_find_child(dev, in dwc3_meson_g12a_otg_init()
613 priv->switch_desc.udc = dwc3_meson_g12_find_child(dev, "snps,dwc2"); in dwc3_meson_g12a_otg_init()
614 priv->switch_desc.allow_userspace_control = true; in dwc3_meson_g12a_otg_init()
615 priv->switch_desc.set = dwc3_meson_g12a_role_set; in dwc3_meson_g12a_otg_init()
616 priv->switch_desc.get = dwc3_meson_g12a_role_get; in dwc3_meson_g12a_otg_init()
617 priv->switch_desc.driver_data = priv; in dwc3_meson_g12a_otg_init()
619 priv->role_switch = usb_role_switch_register(dev, &priv->switch_desc); in dwc3_meson_g12a_otg_init()
620 if (IS_ERR(priv->role_switch)) in dwc3_meson_g12a_otg_init()
630 priv->usb_glue_regmap = devm_regmap_init_mmio(priv->dev, base, in dwc3_meson_gxl_setup_regmaps()
632 return PTR_ERR_OR_ZERO(priv->usb_glue_regmap); in dwc3_meson_gxl_setup_regmaps()
640 priv->usb_glue_regmap = devm_regmap_init_mmio(priv->dev, in dwc3_meson_g12a_setup_regmaps()
643 if (IS_ERR(priv->usb_glue_regmap)) in dwc3_meson_g12a_setup_regmaps()
644 return PTR_ERR(priv->usb_glue_regmap); in dwc3_meson_g12a_setup_regmaps()
646 /* Create a regmap for each USB2 PHY control register set */ in dwc3_meson_g12a_setup_regmaps()
647 for (i = 0; i < priv->drvdata->num_phys; i++) { in dwc3_meson_g12a_setup_regmaps()
655 if (!strstr(priv->drvdata->phy_names[i], "usb2")) in dwc3_meson_g12a_setup_regmaps()
658 u2p_regmap_config.name = devm_kasprintf(priv->dev, GFP_KERNEL, in dwc3_meson_g12a_setup_regmaps()
659 "u2p-%d", i); in dwc3_meson_g12a_setup_regmaps()
661 return -ENOMEM; in dwc3_meson_g12a_setup_regmaps()
663 priv->u2p_regmap[i] = devm_regmap_init_mmio(priv->dev, in dwc3_meson_g12a_setup_regmaps()
666 if (IS_ERR(priv->u2p_regmap[i])) in dwc3_meson_g12a_setup_regmaps()
667 return PTR_ERR(priv->u2p_regmap[i]); in dwc3_meson_g12a_setup_regmaps()
675 return dwc3_meson_g12a_usb_init_glue(priv, priv->otg_phy_mode); in dwc3_meson_g12a_usb_init()
687 ret = priv->drvdata->set_phy_mode(priv, USB2_OTG_PHY, in dwc3_meson_gxl_usb_post_init()
688 priv->otg_phy_mode); in dwc3_meson_gxl_usb_post_init()
692 dwc3_meson_g12a_usb_otg_apply_mode(priv, priv->otg_phy_mode); in dwc3_meson_gxl_usb_post_init()
700 struct device *dev = &pdev->dev; in dwc3_meson_g12a_probe()
701 struct device_node *np = dev->of_node; in dwc3_meson_g12a_probe()
707 return -ENOMEM; in dwc3_meson_g12a_probe()
713 priv->drvdata = of_device_get_match_data(&pdev->dev); in dwc3_meson_g12a_probe()
714 priv->dev = dev; in dwc3_meson_g12a_probe()
716 priv->vbus = devm_regulator_get_optional(dev, "vbus"); in dwc3_meson_g12a_probe()
717 if (IS_ERR(priv->vbus)) { in dwc3_meson_g12a_probe()
718 if (PTR_ERR(priv->vbus) == -EPROBE_DEFER) in dwc3_meson_g12a_probe()
719 return PTR_ERR(priv->vbus); in dwc3_meson_g12a_probe()
720 priv->vbus = NULL; in dwc3_meson_g12a_probe()
724 priv->drvdata->num_clks, in dwc3_meson_g12a_probe()
725 priv->drvdata->clks); in dwc3_meson_g12a_probe()
729 ret = clk_bulk_prepare_enable(priv->drvdata->num_clks, in dwc3_meson_g12a_probe()
730 priv->drvdata->clks); in dwc3_meson_g12a_probe()
736 priv->reset = devm_reset_control_get_shared(dev, NULL); in dwc3_meson_g12a_probe()
737 if (IS_ERR(priv->reset)) { in dwc3_meson_g12a_probe()
738 ret = PTR_ERR(priv->reset); in dwc3_meson_g12a_probe()
743 ret = reset_control_reset(priv->reset); in dwc3_meson_g12a_probe()
751 ret = priv->drvdata->setup_regmaps(priv, base); in dwc3_meson_g12a_probe()
755 if (priv->vbus) { in dwc3_meson_g12a_probe()
756 ret = regulator_enable(priv->vbus); in dwc3_meson_g12a_probe()
762 priv->otg_mode = usb_get_dr_mode(dev); in dwc3_meson_g12a_probe()
764 if (priv->otg_mode == USB_DR_MODE_PERIPHERAL) in dwc3_meson_g12a_probe()
765 priv->otg_phy_mode = PHY_MODE_USB_DEVICE; in dwc3_meson_g12a_probe()
767 priv->otg_phy_mode = PHY_MODE_USB_HOST; in dwc3_meson_g12a_probe()
769 ret = priv->drvdata->usb_init(priv); in dwc3_meson_g12a_probe()
775 ret = phy_init(priv->phys[i]); in dwc3_meson_g12a_probe()
782 ret = phy_power_on(priv->phys[i]); in dwc3_meson_g12a_probe()
787 if (priv->drvdata->usb_post_init) { in dwc3_meson_g12a_probe()
788 ret = priv->drvdata->usb_post_init(priv); in dwc3_meson_g12a_probe()
812 phy_power_off(priv->phys[i]); in dwc3_meson_g12a_probe()
816 phy_exit(priv->phys[i]); in dwc3_meson_g12a_probe()
819 if (priv->vbus) in dwc3_meson_g12a_probe()
820 regulator_disable(priv->vbus); in dwc3_meson_g12a_probe()
823 reset_control_rearm(priv->reset); in dwc3_meson_g12a_probe()
826 clk_bulk_disable_unprepare(priv->drvdata->num_clks, in dwc3_meson_g12a_probe()
827 priv->drvdata->clks); in dwc3_meson_g12a_probe()
835 struct device *dev = &pdev->dev; in dwc3_meson_g12a_remove()
838 usb_role_switch_unregister(priv->role_switch); in dwc3_meson_g12a_remove()
843 phy_power_off(priv->phys[i]); in dwc3_meson_g12a_remove()
844 phy_exit(priv->phys[i]); in dwc3_meson_g12a_remove()
851 reset_control_rearm(priv->reset); in dwc3_meson_g12a_remove()
853 clk_bulk_disable_unprepare(priv->drvdata->num_clks, in dwc3_meson_g12a_remove()
854 priv->drvdata->clks); in dwc3_meson_g12a_remove()
861 clk_bulk_disable_unprepare(priv->drvdata->num_clks, in dwc3_meson_g12a_runtime_suspend()
862 priv->drvdata->clks); in dwc3_meson_g12a_runtime_suspend()
871 return clk_bulk_prepare_enable(priv->drvdata->num_clks, in dwc3_meson_g12a_runtime_resume()
872 priv->drvdata->clks); in dwc3_meson_g12a_runtime_resume()
880 if (priv->vbus && priv->otg_phy_mode == PHY_MODE_USB_HOST) { in dwc3_meson_g12a_suspend()
881 ret = regulator_disable(priv->vbus); in dwc3_meson_g12a_suspend()
887 phy_power_off(priv->phys[i]); in dwc3_meson_g12a_suspend()
888 phy_exit(priv->phys[i]); in dwc3_meson_g12a_suspend()
891 reset_control_rearm(priv->reset); in dwc3_meson_g12a_suspend()
901 ret = reset_control_reset(priv->reset); in dwc3_meson_g12a_resume()
905 ret = priv->drvdata->usb_init(priv); in dwc3_meson_g12a_resume()
911 ret = phy_init(priv->phys[i]); in dwc3_meson_g12a_resume()
918 ret = phy_power_on(priv->phys[i]); in dwc3_meson_g12a_resume()
923 if (priv->vbus && priv->otg_phy_mode == PHY_MODE_USB_HOST) { in dwc3_meson_g12a_resume()
924 ret = regulator_enable(priv->vbus); in dwc3_meson_g12a_resume()
929 if (priv->drvdata->usb_post_init) { in dwc3_meson_g12a_resume()
930 ret = priv->drvdata->usb_post_init(priv); in dwc3_meson_g12a_resume()
946 .compatible = "amlogic,meson-gxl-usb-ctrl",
950 .compatible = "amlogic,meson-gxm-usb-ctrl",
954 .compatible = "amlogic,meson-axg-usb-ctrl",
958 .compatible = "amlogic,meson-g12a-usb-ctrl",
962 .compatible = "amlogic,meson-a1-usb-ctrl",
973 .name = "dwc3-meson-g12a",