Re: [PATCH v5 02/16] phy: qcom: add Qualcomm QUSB2 USB PHY driver
On Thu, 28 Mar 2024 at 23:29, Caleb Connolly wrote: > > From: Bhupesh Sharma > > The Snapdragon 845 and several other Qualcomm SoCs feature this > USB high-speed phy. Add a driver for it based on the Linux driver, with > support for the SDM845, and the QCM2290 and SM6115 SoCs which will gain > support in U-Boot in future patches. > > Signed-off-by: Bhupesh Sharma > [code cleanup, switch to clk_bulk] > Signed-off-by: Caleb Connolly > --- > drivers/phy/qcom/Kconfig | 7 + > drivers/phy/qcom/Makefile | 1 + > drivers/phy/qcom/phy-qcom-qusb2.c | 429 > ++ > 3 files changed, 437 insertions(+) > Acked-by: Sumit Garg -Sumit > diff --git a/drivers/phy/qcom/Kconfig b/drivers/phy/qcom/Kconfig > index f4ca174805a4..361dfb6e1126 100644 > --- a/drivers/phy/qcom/Kconfig > +++ b/drivers/phy/qcom/Kconfig > @@ -11,8 +11,15 @@ config PHY_QCOM_IPQ4019_USB > depends on PHY && ARCH_IPQ40XX > help > Support for the USB PHY-s on Qualcomm IPQ40xx SoC-s. > > +config PHY_QCOM_QUSB2 > + tristate "Qualcomm USB QUSB2 PHY driver" > + depends on PHY && ARCH_SNAPDRAGON > + help > + Enable this to support the Super-Speed USB transceiver on various > + Qualcomm chipsets. > + > config PHY_QCOM_USB_HS_28NM > tristate "Qualcomm 28nm High-Speed PHY" > depends on PHY && ARCH_SNAPDRAGON > help > diff --git a/drivers/phy/qcom/Makefile b/drivers/phy/qcom/Makefile > index 2113f178c0c7..f6af985666a4 100644 > --- a/drivers/phy/qcom/Makefile > +++ b/drivers/phy/qcom/Makefile > @@ -1,4 +1,5 @@ > obj-$(CONFIG_PHY_QCOM_IPQ4019_USB) += phy-qcom-ipq4019-usb.o > obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o > +obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o > obj-$(CONFIG_PHY_QCOM_USB_HS_28NM) += phy-qcom-usb-hs-28nm.o > obj-$(CONFIG_PHY_QCOM_USB_SS) += phy-qcom-usb-ss.o > diff --git a/drivers/phy/qcom/phy-qcom-qusb2.c > b/drivers/phy/qcom/phy-qcom-qusb2.c > new file mode 100644 > index ..c91ba18c4ab1 > --- /dev/null > +++ b/drivers/phy/qcom/phy-qcom-qusb2.c > @@ -0,0 +1,429 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2023 Bhupesh Sharma > + * > + * Based on Linux driver > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#define QUSB2PHY_PLL 0x0 > +#define QUSB2PHY_PLL_TEST 0x04 > +#define CLK_REF_SEL BIT(7) > + > +#define QUSB2PHY_PLL_TUNE 0x08 > +#define QUSB2PHY_PLL_USER_CTL1 0x0c > +#define QUSB2PHY_PLL_USER_CTL2 0x10 > +#define QUSB2PHY_PLL_AUTOPGM_CTL1 0x1c > +#define QUSB2PHY_PLL_PWR_CTRL 0x18 > + > +/* QUSB2PHY_PLL_STATUS register bits */ > +#define PLL_LOCKED BIT(5) > + > +/* QUSB2PHY_PLL_COMMON_STATUS_ONE register bits */ > +#define CORE_READY_STATUS BIT(0) > + > +/* QUSB2PHY_PORT_POWERDOWN register bits */ > +#define CLAMP_N_EN BIT(5) > +#define FREEZIO_N BIT(1) > +#define POWER_DOWN BIT(0) > + > +/* QUSB2PHY_PWR_CTRL1 register bits */ > +#define PWR_CTRL1_VREF_SUPPLY_TRIM BIT(5) > +#define PWR_CTRL1_CLAMP_N_EN BIT(1) > + > +#define QUSB2PHY_REFCLK_ENABLE BIT(0) > + > +#define PHY_CLK_SCHEME_SEL BIT(0) > + > +/* QUSB2PHY_INTR_CTRL register bits */ > +#define DMSE_INTR_HIGH_SEL BIT(4) > +#define DPSE_INTR_HIGH_SEL BIT(3) > +#define CHG_DET_INTR_EN BIT(2) > +#define DMSE_INTR_EN BIT(1) > +#define DPSE_INTR_EN BIT(0) > + > +/* QUSB2PHY_PLL_CORE_INPUT_OVERRIDE register bits */ > +#define CORE_PLL_EN_FROM_RESET BIT(4) > +#define CORE_RESET BIT(5) > +#define CORE_RESET_MUX BIT(6) > + > +/* QUSB2PHY_IMP_CTRL1 register bits */ > +#define IMP_RES_OFFSET_MASK GENMASK(5, 0) > +#define IMP_RES_OFFSET_SHIFT 0x0 > + > +/* QUSB2PHY_PLL_BIAS_CONTROL_2 register bits */ > +#define BIAS_CTRL2_RES_OFFSET_MASK GENMASK(5, 0) > +#define BIAS_CTRL2_RES_OFFSET_SHIFT 0x0 > + > +/* QUSB2PHY_CHG_CONTROL_2 register bits */ > +#define CHG_CTRL2_OFFSET_MASK GENMASK(5, 4) > +#define CHG_CTRL2_OFFSET_SHIFT 0x4 > + > +/* QUSB2PHY_PORT_TUNE1 register bits */ > +#define HSTX_TRIM_MASK GENMASK(7, 4) > +#define HSTX_TRIM_SHIFT 0x4 > +#define PREEMPH_WIDTH_HALF_BIT BIT(2) > +#define PREEMPHASIS_EN_MASK GENMASK(1, 0) > +#define PREEMPHASIS_EN_SHIFT 0x0 > + > +/* QUSB2PHY_PORT_TUNE2 register bits */ > +#define HSDISC_TRIM_MASK GENMASK(1, 0) > +#define HSDISC_TRIM_SHIFT 0x0 > + > +#define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04 > +#define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c > +#define QUSB2PHY_PLL_CMODE 0x2c > +#define QUSB2PHY_PLL_LOCK_DELAY 0x184 > +#define QUSB2PHY_PLL_DIGITAL_TIMERS_TWO 0xb4 > +#define QUSB2PHY_PLL_BIAS_CONTROL_1 0x194 > +#define QUSB2PHY_PLL_BIAS_CONTROL_2 0x198 > +#define QUSB2PHY_PWR_CTRL2 0x214 > +#define QUSB2PHY_IMP_CTRL1 0x220 > +#define QUSB2PHY_IMP_CTRL2 0x224 > +#define QUSB2PHY_CHG_CTRL2 0x23c > + > +struct qusb2_phy_init_tbl { > + unsigned int offset; > + unsigned int val; > + /* > +* register part of layout ? > +* if yes, then offset gives index in
[PATCH v5 02/16] phy: qcom: add Qualcomm QUSB2 USB PHY driver
From: Bhupesh Sharma The Snapdragon 845 and several other Qualcomm SoCs feature this USB high-speed phy. Add a driver for it based on the Linux driver, with support for the SDM845, and the QCM2290 and SM6115 SoCs which will gain support in U-Boot in future patches. Signed-off-by: Bhupesh Sharma [code cleanup, switch to clk_bulk] Signed-off-by: Caleb Connolly --- drivers/phy/qcom/Kconfig | 7 + drivers/phy/qcom/Makefile | 1 + drivers/phy/qcom/phy-qcom-qusb2.c | 429 ++ 3 files changed, 437 insertions(+) diff --git a/drivers/phy/qcom/Kconfig b/drivers/phy/qcom/Kconfig index f4ca174805a4..361dfb6e1126 100644 --- a/drivers/phy/qcom/Kconfig +++ b/drivers/phy/qcom/Kconfig @@ -11,8 +11,15 @@ config PHY_QCOM_IPQ4019_USB depends on PHY && ARCH_IPQ40XX help Support for the USB PHY-s on Qualcomm IPQ40xx SoC-s. +config PHY_QCOM_QUSB2 + tristate "Qualcomm USB QUSB2 PHY driver" + depends on PHY && ARCH_SNAPDRAGON + help + Enable this to support the Super-Speed USB transceiver on various + Qualcomm chipsets. + config PHY_QCOM_USB_HS_28NM tristate "Qualcomm 28nm High-Speed PHY" depends on PHY && ARCH_SNAPDRAGON help diff --git a/drivers/phy/qcom/Makefile b/drivers/phy/qcom/Makefile index 2113f178c0c7..f6af985666a4 100644 --- a/drivers/phy/qcom/Makefile +++ b/drivers/phy/qcom/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_PHY_QCOM_IPQ4019_USB) += phy-qcom-ipq4019-usb.o obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o +obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o obj-$(CONFIG_PHY_QCOM_USB_HS_28NM) += phy-qcom-usb-hs-28nm.o obj-$(CONFIG_PHY_QCOM_USB_SS) += phy-qcom-usb-ss.o diff --git a/drivers/phy/qcom/phy-qcom-qusb2.c b/drivers/phy/qcom/phy-qcom-qusb2.c new file mode 100644 index ..c91ba18c4ab1 --- /dev/null +++ b/drivers/phy/qcom/phy-qcom-qusb2.c @@ -0,0 +1,429 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2023 Bhupesh Sharma + * + * Based on Linux driver + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define QUSB2PHY_PLL 0x0 +#define QUSB2PHY_PLL_TEST 0x04 +#define CLK_REF_SEL BIT(7) + +#define QUSB2PHY_PLL_TUNE 0x08 +#define QUSB2PHY_PLL_USER_CTL1 0x0c +#define QUSB2PHY_PLL_USER_CTL2 0x10 +#define QUSB2PHY_PLL_AUTOPGM_CTL1 0x1c +#define QUSB2PHY_PLL_PWR_CTRL 0x18 + +/* QUSB2PHY_PLL_STATUS register bits */ +#define PLL_LOCKED BIT(5) + +/* QUSB2PHY_PLL_COMMON_STATUS_ONE register bits */ +#define CORE_READY_STATUS BIT(0) + +/* QUSB2PHY_PORT_POWERDOWN register bits */ +#define CLAMP_N_EN BIT(5) +#define FREEZIO_N BIT(1) +#define POWER_DOWN BIT(0) + +/* QUSB2PHY_PWR_CTRL1 register bits */ +#define PWR_CTRL1_VREF_SUPPLY_TRIM BIT(5) +#define PWR_CTRL1_CLAMP_N_EN BIT(1) + +#define QUSB2PHY_REFCLK_ENABLE BIT(0) + +#define PHY_CLK_SCHEME_SEL BIT(0) + +/* QUSB2PHY_INTR_CTRL register bits */ +#define DMSE_INTR_HIGH_SEL BIT(4) +#define DPSE_INTR_HIGH_SEL BIT(3) +#define CHG_DET_INTR_EN BIT(2) +#define DMSE_INTR_EN BIT(1) +#define DPSE_INTR_EN BIT(0) + +/* QUSB2PHY_PLL_CORE_INPUT_OVERRIDE register bits */ +#define CORE_PLL_EN_FROM_RESET BIT(4) +#define CORE_RESET BIT(5) +#define CORE_RESET_MUX BIT(6) + +/* QUSB2PHY_IMP_CTRL1 register bits */ +#define IMP_RES_OFFSET_MASK GENMASK(5, 0) +#define IMP_RES_OFFSET_SHIFT 0x0 + +/* QUSB2PHY_PLL_BIAS_CONTROL_2 register bits */ +#define BIAS_CTRL2_RES_OFFSET_MASK GENMASK(5, 0) +#define BIAS_CTRL2_RES_OFFSET_SHIFT 0x0 + +/* QUSB2PHY_CHG_CONTROL_2 register bits */ +#define CHG_CTRL2_OFFSET_MASK GENMASK(5, 4) +#define CHG_CTRL2_OFFSET_SHIFT 0x4 + +/* QUSB2PHY_PORT_TUNE1 register bits */ +#define HSTX_TRIM_MASK GENMASK(7, 4) +#define HSTX_TRIM_SHIFT 0x4 +#define PREEMPH_WIDTH_HALF_BIT BIT(2) +#define PREEMPHASIS_EN_MASK GENMASK(1, 0) +#define PREEMPHASIS_EN_SHIFT 0x0 + +/* QUSB2PHY_PORT_TUNE2 register bits */ +#define HSDISC_TRIM_MASK GENMASK(1, 0) +#define HSDISC_TRIM_SHIFT 0x0 + +#define QUSB2PHY_PLL_ANALOG_CONTROLS_TWO 0x04 +#define QUSB2PHY_PLL_CLOCK_INVERTERS 0x18c +#define QUSB2PHY_PLL_CMODE 0x2c +#define QUSB2PHY_PLL_LOCK_DELAY 0x184 +#define QUSB2PHY_PLL_DIGITAL_TIMERS_TWO 0xb4 +#define QUSB2PHY_PLL_BIAS_CONTROL_1 0x194 +#define QUSB2PHY_PLL_BIAS_CONTROL_2 0x198 +#define QUSB2PHY_PWR_CTRL2 0x214 +#define QUSB2PHY_IMP_CTRL1 0x220 +#define QUSB2PHY_IMP_CTRL2 0x224 +#define QUSB2PHY_CHG_CTRL2 0x23c + +struct qusb2_phy_init_tbl { + unsigned int offset; + unsigned int val; + /* +* register part of layout ? +* if yes, then offset gives index in the reg-layout +*/ + int in_layout; +}; + +struct qusb2_phy_cfg { + const struct qusb2_phy_init_tbl *tbl; + /* number of entries in the table */ + unsigned int tbl_num; + /* offset to PHY_CLK_SCHEME register in TCSR map */ + unsigned int clk_scheme_offset; + + /* array of registers with different offsets */ + const unsigned int