Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: renesas: rcar-gen3-usb2: Add support to initialize the bus

The Renesas RZ/G3S need to initialize the USB BUS before transferring data
due to hardware limitation. As the register that need to be touched for
this is in the address space of the USB PHY, and the UBS PHY need to be
initialized before any other USB drivers handling data transfer, add
support to initialize the USB BUS.

As the USB PHY is probed before any other USB drivers that enables
clocks and de-assert the reset signals and the BUS initialization is done
in the probe phase, we need to add code to de-assert reset signal and
runtime resume the device (which enables its clocks) before accessing
the registers.

As the reset signals are not required by the USB PHY driver for the other
USB PHY hardware variants, the reset signals and runtime PM was handled
only in the function that initialize the USB BUS.

The PHY initialization was done right after runtime PM enable to have
all in place when the PHYs are registered.

Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Link: https://lore.kernel.org/r/20240822152801.602318-11-claudiu.beznea.uj@bp.renesas.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Claudiu Beznea and committed by
Vinod Koul
4eae1637 0d5a213c

+47 -3
+47 -3
drivers/phy/renesas/phy-rcar-gen3-usb2.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/pm_runtime.h> 21 21 #include <linux/regulator/consumer.h> 22 + #include <linux/reset.h> 22 23 #include <linux/string.h> 23 24 #include <linux/usb/of.h> 24 25 #include <linux/workqueue.h> 25 26 26 27 /******* USB2.0 Host registers (original offset is +0x200) *******/ 27 28 #define USB2_INT_ENABLE 0x000 29 + #define USB2_AHB_BUS_CTR 0x008 28 30 #define USB2_USBCTR 0x00c 29 31 #define USB2_SPD_RSM_TIMSET 0x10c 30 32 #define USB2_OC_TIMSET 0x110 ··· 41 39 #define USB2_INT_ENABLE_UCOM_INTEN BIT(3) 42 40 #define USB2_INT_ENABLE_USBH_INTB_EN BIT(2) /* For EHCI */ 43 41 #define USB2_INT_ENABLE_USBH_INTA_EN BIT(1) /* For OHCI */ 42 + 43 + /* AHB_BUS_CTR */ 44 + #define USB2_AHB_BUS_CTR_MBL_MASK GENMASK(1, 0) 45 + #define USB2_AHB_BUS_CTR_MBL_INCR4 2 44 46 45 47 /* USBCTR */ 46 48 #define USB2_USBCTR_DIRPD BIT(2) ··· 117 111 struct extcon_dev *extcon; 118 112 struct rcar_gen3_phy rphys[NUM_OF_PHYS]; 119 113 struct regulator *vbus; 114 + struct reset_control *rstc; 120 115 struct work_struct work; 121 116 struct mutex lock; /* protects rphys[...].powered */ 122 117 enum usb_dr_mode dr_mode; ··· 132 125 struct rcar_gen3_phy_drv_data { 133 126 const struct phy_ops *phy_usb2_ops; 134 127 bool no_adp_ctrl; 128 + bool init_bus; 135 129 }; 136 130 137 131 /* ··· 658 650 return candidate; 659 651 } 660 652 653 + static int rcar_gen3_phy_usb2_init_bus(struct rcar_gen3_chan *channel) 654 + { 655 + struct device *dev = channel->dev; 656 + int ret; 657 + u32 val; 658 + 659 + channel->rstc = devm_reset_control_array_get_shared(dev); 660 + if (IS_ERR(channel->rstc)) 661 + return PTR_ERR(channel->rstc); 662 + 663 + ret = pm_runtime_resume_and_get(dev); 664 + if (ret) 665 + return ret; 666 + 667 + ret = reset_control_deassert(channel->rstc); 668 + if (ret) 669 + goto rpm_put; 670 + 671 + val = readl(channel->base + USB2_AHB_BUS_CTR); 672 + val &= ~USB2_AHB_BUS_CTR_MBL_MASK; 673 + val |= USB2_AHB_BUS_CTR_MBL_INCR4; 674 + writel(val, channel->base + USB2_AHB_BUS_CTR); 675 + 676 + rpm_put: 677 + pm_runtime_put(dev); 678 + 679 + return ret; 680 + } 681 + 661 682 static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) 662 683 { 663 684 const struct rcar_gen3_phy_drv_data *phy_data; ··· 740 703 goto error; 741 704 } 742 705 706 + platform_set_drvdata(pdev, channel); 707 + channel->dev = dev; 708 + 709 + if (phy_data->init_bus) { 710 + ret = rcar_gen3_phy_usb2_init_bus(channel); 711 + if (ret) 712 + goto error; 713 + } 714 + 743 715 channel->soc_no_adp_ctrl = phy_data->no_adp_ctrl; 744 716 if (phy_data->no_adp_ctrl) 745 717 channel->obint_enable_bits = USB2_OBINT_IDCHG_EN; ··· 779 733 channel->vbus = NULL; 780 734 } 781 735 782 - platform_set_drvdata(pdev, channel); 783 - channel->dev = dev; 784 - 785 736 provider = devm_of_phy_provider_register(dev, rcar_gen3_phy_usb2_xlate); 786 737 if (IS_ERR(provider)) { 787 738 dev_err(dev, "Failed to register PHY provider\n"); ··· 805 762 if (channel->is_otg_channel) 806 763 device_remove_file(&pdev->dev, &dev_attr_role); 807 764 765 + reset_control_assert(channel->rstc); 808 766 pm_runtime_disable(&pdev->dev); 809 767 }; 810 768