phy: samsung: add Exynos2200 SNPS eUSB2 driver
Subsystems (4)
v5 cover phy: samsung: add Exynos2200 SNPS eUSB2 driver
Hey folks,
This patchset adds Exynos2200 support to the existing eUSB2 phy driver, as well as USBDRD support for that SoC.
The SoC features the same (as far as I can tell from comparing code) USBDRD 3.2 4nm block that Exynos2400 has, hence the common denominator. It consists of a SEC USB link controller, Synopsys eUSB2 and Synopsys USBDP combophy, which are independent underlying hardware blocks of the USBDRD controller.
In the vendor kernel, everything is handled in the usbdrd controller driver, with helpers for underlying hardware block functions outside it. Clocks and regulators are specified and enabled in one node, which makes it difficult to separate what clocks and regulators go where without access to schematics or TRMs. The following gates are defined for USB:
CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_USBSUBCTL_APB_PCLK CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_USBDPPHY_CTRL_PCLK CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_USBDPPHY_TCA_APB_CLK
CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_USBLINK_ACLK CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_USB32DRD_REF_CLK_40
CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_EUSB_CTRL_PCLK CLK_BLK_HSI0_UID_USB32DRD_IPCLKPORT_I_EUSB_APB_CLK CLK_BLK_HSI0_UID_AS_APB_EUSBPHY_HSI0_IPCLKPORT_PCLKM CLK_BLK_HSI0_UID_RSTNSYNC_CLK_HSI0_EUSB_IPCLKPORT_CLK
The vendor kernel specifies 4 regulators, 2 of which are for eUSB and the other 2 for the repeater. The rest of the PHYs and the dwc3 controller are on a single power domain (hsi0), so they're most likely sharing power rails.
As Qualcomm is also using the eUSB2 IP, the approach taken here is to rename the driver so that it can be used by other SoC vendors as well while keeping compatibles SoC-vendor prefixed (different vendors have different implementations of the IP with different register maps), add support for exynos2200 in it and implement support for exynos2200 in the existing exynos5-usbdrd driver (with link controller init).
A new USBDP driver will be added later on, so that super-speed can be configured.
Bindings have been tested:
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4 dt_binding_check DT_SCHEMA_FILES="Documentation/devicetree/bindings/phy/samsung,exynos2200-eusb2-phy.yaml" CHKDT ./Documentation/devicetree/bindings LINT ./Documentation/devicetree/bindings DTEX Documentation/devicetree/bindings/phy/samsung,exynos2200-eusb2-phy.example.dts DTC [C] Documentation/devicetree/bindings/phy/samsung,exynos2200-eusb2-phy.example.dtb
Best regards,
Ivaylo
Changes in v5:
EUSB2 changes:
- rename binding to match compatible
- simplify binding name
- indent binding example node properly
- add r-b tag for binding
USBDRD changes:
- add r-b tag for binding
Changes in v4:
EUSB2 changes:
- make a new separate binding for eusb2 ip found in samsung socs
- fix order of tags in 03/10
- change 'SNPS' to 'Synopsys' in the MODULE_DESCRIPTION in 04/10
- simplify code around device_get_match_data in 05/10 USBDRD changes:
- drop double colons and 'phandle to' in binding
Changes in v3:
USBCON changes:
- drop the driver and introduce it all in existing exynos5-usbdrd driver EUSB2 changes:
- split changes into multiple commits with clear diff
- add a commit to do table-based lookup for refclk
- clean up here and there
- correct the cover letter according to my new knowledge of how the hardware functions
- change commit message of the optional repeater patch
Changes in v2:
USBCON changes:
- drop unused header includes
- sanitize the binding
- proper init and exit power management
- shorten some variables
- unrelax reads and writes
- update commit description
- remodel to take other phys
- drop specified regulators as these are for the repeater
- make the kconfig description better
- general cleanup
EUSB2 changes:
- merge the previous separate driver into the qualcomm one
- drop the previous model of taking usbcon phandle
Ivaylo Ivanov (10):
dt-bindings: phy: add exynos2200 eusb2 phy support
dt-bindings: phy: samsung,usb3-drd-phy: add exynos2200 support
phy: move phy-qcom-snps-eusb2 out of its vendor sub-directory
phy: phy-snps-eusb2: refactor constructs names
phy: phy-snps-eusb2: split phy init code
phy: phy-snps-eusb2: make repeater optional
phy: phy-snps-eusb2: make reset control optional
phy: phy-snps-eusb2: refactor reference clock init
phy: phy-snps-eusb2: add support for exynos2200
phy: exynos5-usbdrd: support Exynos USBDRD 3.2 4nm controller
.../phy/samsung,exynos2200-eusb2-phy.yaml | 80 +++ .../bindings/phy/samsung,usb3-drd-phy.yaml | 38 +- drivers/phy/Kconfig | 8 + drivers/phy/Makefile | 1 + drivers/phy/phy-snps-eusb2.c | 627 ++++++++++++++++++ drivers/phy/qualcomm/Kconfig | 9 - drivers/phy/qualcomm/Makefile | 1 - drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 442 ------------ drivers/phy/samsung/phy-exynos5-usbdrd.c | 227 ++++++- include/linux/soc/samsung/exynos-regs-pmu.h | 3 + 10 files changed, 965 insertions(+), 471 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/samsung,exynos2200-eusb2-phy.yaml create mode 100644 drivers/phy/phy-snps-eusb2.c delete mode 100644 drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
Signature · 1 line
2.43.0
PATCH v5 1/10 dt-bindings: phy: add exynos2200 eusb2 phy support
Document the exynos2200 eUSB2 compatible. Unlike the currently documented Qualcomm SoCs, the driver doesn't make use of reset lines for reset control and uses more clocks.
--- .../phy/samsung,exynos2200-eusb2-phy.yaml | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/samsung,exynos2200-eusb2-phy.yaml
Documentation/devicetree/bindings/phy/samsung,exynos2200-eusb2-phy.yaml new file +80 -0
@@ -0,0 +1,80 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/samsung,exynos2200-eusb2-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Samsung Exynos2200 eUSB2 phy controller + +maintainers: + - Ivaylo Ivanov <[email protected]> + +description: + Samsung Exynos2200 eUSB2 phy, based on Synopsys eUSB2 IP block, supports + LS/FS/HS usb connectivity. + +properties: + compatible: + enum: + - samsung,exynos2200-eusb2-phy + + reg: + maxItems: 1 + + "#phy-cells": + const: 0 + + clocks: + items: + - description: Reference clock + - description: Bus (APB) clock + - description: Control clock + + clock-names: + items: + - const: ref + - const: bus + - const: ctrl + + resets: + maxItems: 1 + + phys: + maxItems: 1 + description: + Phandle to eUSB2 to USB 2.0 repeater + + vdd-supply: + description: + Phandle to 0.88V regulator supply to PHY digital circuit. + + vdda12-supply: + description: + Phandle to 1.2V regulator supply to PHY refclk pll block. + +required: + - compatible + - reg + - "#phy-cells" + - clocks + - clock-names + - vdd-supply + - vdda12-supply + +additionalProperties: false + +examples: + - | + usb_hsphy: phy@10ab0000 { + compatible = "samsung,exynos2200-eusb2-phy"; + reg = <0x10ab0000 0x10000>; + #phy-cells = <0>; + + clocks = <&cmu_hsi0 7>, + <&cmu_hsi0 5>, + <&cmu_hsi0 8>; + clock-names = "ref", "bus", "ctrl"; + + vdd-supply = <&vreg_0p88>; + vdda12-supply = <&vreg_1p2>; + };
Signature · 1 line
2.43.0
PATCH v5 2/10 dt-bindings: phy: samsung,usb3-drd-phy: add exynos2200 support
In reply to Ivaylo IvanovDocument support for Exynos2200. As the USBDRD 3.2 4nm controller consists of Synopsys eUSB2.0 phy and USBDP/SS combophy, which will be handled by external drivers, define only the bus clocked used by the link controller.
--- .../bindings/phy/samsung,usb3-drd-phy.yaml | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/phy/samsung,usb3-drd-phy.yaml +34 -4
@@ -26,6 +26,7 @@ properties: compatible: enum: - google,gs101-usb31drd-phy + - samsung,exynos2200-usb32drd-phy - samsung,exynos5250-usbdrd-phy - samsung,exynos5420-usbdrd-phy - samsung,exynos5433-usbdrd-phy
@@ -33,24 +34,32 @@ properties: - samsung,exynos850-usbdrd-phy clocks: - minItems: 2 + minItems: 1 maxItems: 5 clock-names: - minItems: 2 + minItems: 1 maxItems: 5 description: | - At least two clocks:: + Typically two clocks: - Main PHY clock (same as USB DRD controller i.e. DWC3 IP clock), used for register access. - PHY reference clock (usually crystal clock), used for PHY operations, associated by phy name. It is used to determine bit values for clock settings register. For Exynos5420 this is given as 'sclk_usbphy30' - in the CMU. + in the CMU. It's not needed for Exynos2200. "#phy-cells": const: 1 + phys: + maxItems: 1 + description: + USBDRD-underlying high-speed PHY + + phy-names: + const: hs + port: $ref: /schemas/graph.yaml#/properties/port description:
@@ -150,6 +159,27 @@ allOf: - vdda-usbdp-supply - vddh-usbdp-supply + - if: + properties: + compatible: + contains: + enum: + - samsung,exynos2200-usb32drd-phy + then: + properties: + clocks: + maxItems: 1 + clock-names: + items: + - const: phy + reg: + maxItems: 1 + reg-names: + maxItems: 1 + required: + - phys + - phy-names + - if: properties: compatible:
Signature · 1 line
2.43.0
PATCH v5 3/10 phy: move phy-qcom-snps-eusb2 out of its vendor sub-directory
In reply to Ivaylo IvanovAs not only Qualcomm, but also Samsung is using the Synopsys eUSB2 IP (albeit with a different register layout) in their newer SoCs, move the driver out of its vendor sub-directory and rename it to phy-snps-eusb2.
---
drivers/phy/Kconfig | 8 ++++++++
drivers/phy/Makefile | 1 +
.../{qualcomm/phy-qcom-snps-eusb2.c => phy-snps-eusb2.c} | 0
drivers/phy/qualcomm/Kconfig | 9 ---------
drivers/phy/qualcomm/Makefile | 1 -
5 files changed, 9 insertions(+), 10 deletions(-)
rename drivers/phy/{qualcomm/phy-qcom-snps-eusb2.c => phy-snps-eusb2.c} (100%)drivers/phy/Kconfig +8 -0
@@ -43,6 +43,14 @@ config PHY_PISTACHIO_USB help Enable this to support the USB2.0 PHY on the IMG Pistachio SoC. +config PHY_SNPS_EUSB2 + tristate "SNPS eUSB2 PHY Driver" + depends on OF && (ARCH_QCOM || COMPILE_TEST) + select GENERIC_PHY + help + Enable support for the USB high-speed SNPS eUSB2 phy on select + SoCs. The PHY is usually paired with a Synopsys DWC3 USB controller. + config PHY_XGENE tristate "APM X-Gene 15Gbps PHY support" depends on HAS_IOMEM && OF && (ARCH_XGENE || COMPILE_TEST)
drivers/phy/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_PHY_CAN_TRANSCEIVER) += phy-can-transceiver.o obj-$(CONFIG_PHY_LPC18XX_USB_OTG) += phy-lpc18xx-usb-otg.o obj-$(CONFIG_PHY_XGENE) += phy-xgene.o obj-$(CONFIG_PHY_PISTACHIO_USB) += phy-pistachio-usb.o +obj-$(CONFIG_PHY_SNPS_EUSB2) += phy-snps-eusb2.o obj-$(CONFIG_USB_LGM_PHY) += phy-lgm-usb.o obj-$(CONFIG_PHY_AIROHA_PCIE) += phy-airoha-pcie.o obj-$(CONFIG_PHY_NXP_PTN3222) += phy-nxp-ptn3222.o
drivers/phy/phy-snps-eusb2.c renamed from drivers/phy/qualcomm/phy-qcom-snps-eusb2.c +0 -0
drivers/phy/qualcomm/Kconfig +0 -9
@@ -125,15 +125,6 @@ config PHY_QCOM_QUSB2 PHY which is usually paired with either the ChipIdea or Synopsys DWC3 USB IPs on MSM SOCs. -config PHY_QCOM_SNPS_EUSB2 - tristate "Qualcomm SNPS eUSB2 PHY Driver" - depends on OF && (ARCH_QCOM || COMPILE_TEST) - select GENERIC_PHY - help - Enable support for the USB high-speed SNPS eUSB2 phy on Qualcomm - chipsets. The PHY is paired with a Synopsys DWC3 USB controller - on Qualcomm SOCs. - config PHY_QCOM_EUSB2_REPEATER tristate "Qualcomm SNPS eUSB2 Repeater Driver" depends on OF && (ARCH_QCOM || COMPILE_TEST)
drivers/phy/qualcomm/Makefile +0 -1
@@ -15,7 +15,6 @@ obj-$(CONFIG_PHY_QCOM_QMP_USB) += phy-qcom-qmp-usb.o obj-$(CONFIG_PHY_QCOM_QMP_USB_LEGACY) += phy-qcom-qmp-usb-legacy.o obj-$(CONFIG_PHY_QCOM_QUSB2) += phy-qcom-qusb2.o -obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2) += phy-qcom-snps-eusb2.o obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER) += phy-qcom-eusb2-repeater.o obj-$(CONFIG_PHY_QCOM_UNIPHY_PCIE_28LP) += phy-qcom-uniphy-pcie-28lp.o obj-$(CONFIG_PHY_QCOM_USB_HS) += phy-qcom-usb-hs.o
Signature · 1 line
2.43.0
PATCH v5 4/10 phy: phy-snps-eusb2: refactor constructs names
In reply to Ivaylo IvanovAs the driver now resides outside the phy subdirectory under a different name, refactor all definitions, structures and functions to explicitly specify what code is Qualcomm-specific and what is not.
--- drivers/phy/phy-snps-eusb2.c | 256 +++++++++++++++++------------------ 1 file changed, 128 insertions(+), 128 deletions(-)
drivers/phy/phy-snps-eusb2.c +128 -128
@@ -13,15 +13,15 @@#include <linux/regulator/consumer.h> #include <linux/reset.h> -#define USB_PHY_UTMI_CTRL0 (0x3c) +#define QCOM_USB_PHY_UTMI_CTRL0 (0x3c)#define SLEEPM BIT(0)#define OPMODE_MASK GENMASK(4, 3)#define OPMODE_NONDRIVING BIT(3) -#define USB_PHY_UTMI_CTRL5 (0x50) +#define QCOM_USB_PHY_UTMI_CTRL5 (0x50)#define POR BIT(1) -#define USB_PHY_HS_PHY_CTRL_COMMON0 (0x54) +#define QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 (0x54)#define PHY_ENABLE BIT(0)#define SIDDQ_SEL BIT(1)#define SIDDQ BIT(2)
@@ -30,15 +30,15 @@#define FSEL_19_2_MHZ_VAL (0x0)#define FSEL_38_4_MHZ_VAL (0x4) -#define USB_PHY_CFG_CTRL_1 (0x58) +#define QCOM_USB_PHY_CFG_CTRL_1 (0x58)#define PHY_CFG_PLL_CPBIAS_CNTRL_MASK GENMASK(7, 1) -#define USB_PHY_CFG_CTRL_2 (0x5c) +#define QCOM_USB_PHY_CFG_CTRL_2 (0x5c)#define PHY_CFG_PLL_FB_DIV_7_0_MASK GENMASK(7, 0)#define DIV_7_0_19_2_MHZ_VAL (0x90)#define DIV_7_0_38_4_MHZ_VAL (0xc8) -#define USB_PHY_CFG_CTRL_3 (0x60) +#define QCOM_USB_PHY_CFG_CTRL_3 (0x60)#define PHY_CFG_PLL_FB_DIV_11_8_MASK GENMASK(3, 0)#define DIV_11_8_19_2_MHZ_VAL (0x1)#define DIV_11_8_38_4_MHZ_VAL (0x0)
@@ -46,73 +46,73 @@#define PHY_CFG_PLL_REF_DIV GENMASK(7, 4)#define PLL_REF_DIV_VAL (0x0) -#define USB_PHY_HS_PHY_CTRL2 (0x64) +#define QCOM_USB_PHY_HS_PHY_CTRL2 (0x64)#define VBUSVLDEXT0 BIT(0)#define USB2_SUSPEND_N BIT(2)#define USB2_SUSPEND_N_SEL BIT(3)#define VBUS_DET_EXT_SEL BIT(4) -#define USB_PHY_CFG_CTRL_4 (0x68) +#define QCOM_USB_PHY_CFG_CTRL_4 (0x68)#define PHY_CFG_PLL_GMP_CNTRL_MASK GENMASK(1, 0)#define PHY_CFG_PLL_INT_CNTRL_MASK GENMASK(7, 2) -#define USB_PHY_CFG_CTRL_5 (0x6c) +#define QCOM_USB_PHY_CFG_CTRL_5 (0x6c)#define PHY_CFG_PLL_PROP_CNTRL_MASK GENMASK(4, 0)#define PHY_CFG_PLL_VREF_TUNE_MASK GENMASK(7, 6) -#define USB_PHY_CFG_CTRL_6 (0x70) +#define QCOM_USB_PHY_CFG_CTRL_6 (0x70)#define PHY_CFG_PLL_VCO_CNTRL_MASK GENMASK(2, 0) -#define USB_PHY_CFG_CTRL_7 (0x74) +#define QCOM_USB_PHY_CFG_CTRL_7 (0x74) -#define USB_PHY_CFG_CTRL_8 (0x78) +#define QCOM_USB_PHY_CFG_CTRL_8 (0x78)#define PHY_CFG_TX_FSLS_VREF_TUNE_MASK GENMASK(1, 0)#define PHY_CFG_TX_FSLS_VREG_BYPASS BIT(2)#define PHY_CFG_TX_HS_VREF_TUNE_MASK GENMASK(5, 3)#define PHY_CFG_TX_HS_XV_TUNE_MASK GENMASK(7, 6) -#define USB_PHY_CFG_CTRL_9 (0x7c) +#define QCOM_USB_PHY_CFG_CTRL_9 (0x7c)#define PHY_CFG_TX_PREEMP_TUNE_MASK GENMASK(2, 0)#define PHY_CFG_TX_RES_TUNE_MASK GENMASK(4, 3)#define PHY_CFG_TX_RISE_TUNE_MASK GENMASK(6, 5)#define PHY_CFG_RCAL_BYPASS BIT(7) -#define USB_PHY_CFG_CTRL_10 (0x80) +#define QCOM_USB_PHY_CFG_CTRL_10 (0x80) -#define USB_PHY_CFG0 (0x94) +#define QCOM_USB_PHY_CFG0 (0x94)#define DATAPATH_CTRL_OVERRIDE_EN BIT(0)#define CMN_CTRL_OVERRIDE_EN BIT(1) -#define UTMI_PHY_CMN_CTRL0 (0x98) +#define QCOM_UTMI_PHY_CMN_CTRL0 (0x98)#define TESTBURNIN BIT(6) -#define USB_PHY_FSEL_SEL (0xb8) +#define QCOM_USB_PHY_FSEL_SEL (0xb8)#define FSEL_SEL BIT(0) -#define USB_PHY_APB_ACCESS_CMD (0x130) +#define QCOM_USB_PHY_APB_ACCESS_CMD (0x130)#define RW_ACCESS BIT(0)#define APB_START_CMD BIT(1)#define APB_LOGIC_RESET BIT(2) -#define USB_PHY_APB_ACCESS_STATUS (0x134) +#define QCOM_USB_PHY_APB_ACCESS_STATUS (0x134)#define ACCESS_DONE BIT(0)#define TIMED_OUT BIT(1)#define ACCESS_ERROR BIT(2)#define ACCESS_IN_PROGRESS BIT(3) -#define USB_PHY_APB_ADDRESS (0x138) +#define QCOM_USB_PHY_APB_ADDRESS (0x138)#define APB_REG_ADDR_MASK GENMASK(7, 0) -#define USB_PHY_APB_WRDATA_LSB (0x13c) +#define QCOM_USB_PHY_APB_WRDATA_LSB (0x13c)#define APB_REG_WRDATA_7_0_MASK GENMASK(3, 0) -#define USB_PHY_APB_WRDATA_MSB (0x140) +#define QCOM_USB_PHY_APB_WRDATA_MSB (0x140)#define APB_REG_WRDATA_15_8_MASK GENMASK(7, 4) -#define USB_PHY_APB_RDDATA_LSB (0x144) +#define QCOM_USB_PHY_APB_RDDATA_LSB (0x144)#define APB_REG_RDDATA_7_0_MASK GENMASK(3, 0) -#define USB_PHY_APB_RDDATA_MSB (0x148) +#define QCOM_USB_PHY_APB_RDDATA_MSB (0x148)#define APB_REG_RDDATA_15_8_MASK GENMASK(7, 4)static const char *const eusb2_hsphy_vreg_names[] = {
@@ -121,7 +121,7 @@ static const char * const eusb2_hsphy_vreg_names[] = {#define EUSB2_NUM_VREGS ARRAY_SIZE(eusb2_hsphy_vreg_names) -struct qcom_snps_eusb2_hsphy { +struct snps_eusb2_hsphy {struct phy *phy;void __iomem *base;
@@ -135,17 +135,17 @@ struct qcom_snps_eusb2_hsphy {struct phy *repeater; }; -static int qcom_snps_eusb2_hsphy_set_mode (struct phy *p,enum phy_mode mode,int submode) +static int snps_eusb2_hsphy_set_mode (struct phy *p,enum phy_mode mode,int submode) { -struct qcom_snps_eusb2_hsphy *phy =phy_get_drvdata (p); +struct snps_eusb2_hsphy *phy =phy_get_drvdata (p); phy->mode = mode;return phy_set_mode_ext (phy->repeater, mode, submode); } -static void qcom_snps_eusb2_hsphy_write_mask (void __iomem *base,u32 offset, -u32 mask,u32 val) +static void snps_eusb2_hsphy_write_mask (void __iomem *base,u32 offset, +u32 mask,u32 val) {u32 reg;
@@ -158,65 +158,65 @@ static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,readl_relaxed (base + offset); } -static void qcom_eusb2_default_parameters (struct qcom_snps_eusb2_hsphy *phy) +static void qcom_eusb2_default_parameters (struct snps_eusb2_hsphy *phy) {/* default parameters: tx pre-emphasis */ -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_9 , -PHY_CFG_TX_PREEMP_TUNE_MASK , -FIELD_PREP (PHY_CFG_TX_PREEMP_TUNE_MASK ,0 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_9 , +PHY_CFG_TX_PREEMP_TUNE_MASK , +FIELD_PREP (PHY_CFG_TX_PREEMP_TUNE_MASK ,0 ));/* tx rise/fall time */ -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_9 , -PHY_CFG_TX_RISE_TUNE_MASK , -FIELD_PREP (PHY_CFG_TX_RISE_TUNE_MASK ,0x2 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_9 , +PHY_CFG_TX_RISE_TUNE_MASK , +FIELD_PREP (PHY_CFG_TX_RISE_TUNE_MASK ,0x2 ));/* source impedance adjustment */ -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_9 , -PHY_CFG_TX_RES_TUNE_MASK , -FIELD_PREP (PHY_CFG_TX_RES_TUNE_MASK ,0x1 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_9 , +PHY_CFG_TX_RES_TUNE_MASK , +FIELD_PREP (PHY_CFG_TX_RES_TUNE_MASK ,0x1 ));/* dc voltage level adjustement */ -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_8 , -PHY_CFG_TX_HS_VREF_TUNE_MASK , -FIELD_PREP (PHY_CFG_TX_HS_VREF_TUNE_MASK ,0x3 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_8 , +PHY_CFG_TX_HS_VREF_TUNE_MASK , +FIELD_PREP (PHY_CFG_TX_HS_VREF_TUNE_MASK ,0x3 ));/* transmitter HS crossover adjustement */ -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_8 , -PHY_CFG_TX_HS_XV_TUNE_MASK , -FIELD_PREP (PHY_CFG_TX_HS_XV_TUNE_MASK ,0x0 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_8 , +PHY_CFG_TX_HS_XV_TUNE_MASK , +FIELD_PREP (PHY_CFG_TX_HS_XV_TUNE_MASK ,0x0 )); } -static int qcom_eusb2_ref_clk_init (struct qcom_snps_eusb2_hsphy *phy) +static int qcom_eusb2_ref_clk_init (struct snps_eusb2_hsphy *phy) {unsigned long ref_clk_freq =clk_get_rate (phy->ref_clk);switch (ref_clk_freq) {case 19200000 : -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL_COMMON0 , -FSEL_MASK , -FIELD_PREP (FSEL_MASK ,FSEL_19_2_MHZ_VAL )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , +FSEL_MASK , +FIELD_PREP (FSEL_MASK ,FSEL_19_2_MHZ_VAL )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_2 , -PHY_CFG_PLL_FB_DIV_7_0_MASK , -DIV_7_0_19_2_MHZ_VAL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_2 , +PHY_CFG_PLL_FB_DIV_7_0_MASK , +DIV_7_0_19_2_MHZ_VAL ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_3 , -PHY_CFG_PLL_FB_DIV_11_8_MASK , -DIV_11_8_19_2_MHZ_VAL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 , +PHY_CFG_PLL_FB_DIV_11_8_MASK , +DIV_11_8_19_2_MHZ_VAL );break ;case 38400000 : -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL_COMMON0 , -FSEL_MASK , -FIELD_PREP (FSEL_MASK ,FSEL_38_4_MHZ_VAL )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , +FSEL_MASK , +FIELD_PREP (FSEL_MASK ,FSEL_38_4_MHZ_VAL )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_2 , -PHY_CFG_PLL_FB_DIV_7_0_MASK , -DIV_7_0_38_4_MHZ_VAL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_2 , +PHY_CFG_PLL_FB_DIV_7_0_MASK , +DIV_7_0_38_4_MHZ_VAL ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_3 , -PHY_CFG_PLL_FB_DIV_11_8_MASK , -DIV_11_8_38_4_MHZ_VAL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 , +PHY_CFG_PLL_FB_DIV_11_8_MASK , +DIV_11_8_38_4_MHZ_VAL );break ;default :
@@ -224,15 +224,15 @@ static int qcom_eusb2_ref_clk_init(struct qcom_snps_eusb2_hsphy *phy)return -EINVAL ; } -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_3 , -PHY_CFG_PLL_REF_DIV ,PLL_REF_DIV_VAL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 , +PHY_CFG_PLL_REF_DIV ,PLL_REF_DIV_VAL );return 0 ; } -static int qcom_snps_eusb2_hsphy_init (struct phy *p) +static int snps_eusb2_hsphy_init (struct phy *p) { -struct qcom_snps_eusb2_hsphy *phy =phy_get_drvdata (p); +struct snps_eusb2_hsphy *phy =phy_get_drvdata (p);int ret; ret =regulator_bulk_enable (ARRAY_SIZE (phy->vregs), phy->vregs);
@@ -265,73 +265,73 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p) goto disable_ref_clk; } -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG0 , -CMN_CTRL_OVERRIDE_EN ,CMN_CTRL_OVERRIDE_EN ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG0 , +CMN_CTRL_OVERRIDE_EN ,CMN_CTRL_OVERRIDE_EN ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_UTMI_CTRL5 ,POR ,POR ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_UTMI_CTRL5 ,POR ,POR ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL_COMMON0 , -PHY_ENABLE |RETENABLEN ,PHY_ENABLE |RETENABLEN ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , +PHY_ENABLE |RETENABLEN ,PHY_ENABLE |RETENABLEN ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_APB_ACCESS_CMD , -APB_LOGIC_RESET ,APB_LOGIC_RESET ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_APB_ACCESS_CMD , +APB_LOGIC_RESET ,APB_LOGIC_RESET ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,UTMI_PHY_CMN_CTRL0 ,TESTBURNIN ,0 ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_UTMI_PHY_CMN_CTRL0 ,TESTBURNIN ,0 ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_FSEL_SEL , -FSEL_SEL ,FSEL_SEL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_FSEL_SEL , +FSEL_SEL ,FSEL_SEL );/* update ref_clk related registers */ ret =qcom_eusb2_ref_clk_init (phy);if (ret) - goto disable_ref_clk; +return ret; -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_1 , -PHY_CFG_PLL_CPBIAS_CNTRL_MASK , -FIELD_PREP (PHY_CFG_PLL_CPBIAS_CNTRL_MASK ,0x1 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_1 , +PHY_CFG_PLL_CPBIAS_CNTRL_MASK , +FIELD_PREP (PHY_CFG_PLL_CPBIAS_CNTRL_MASK ,0x1 )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_4 , -PHY_CFG_PLL_INT_CNTRL_MASK , -FIELD_PREP (PHY_CFG_PLL_INT_CNTRL_MASK ,0x8 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_4 , +PHY_CFG_PLL_INT_CNTRL_MASK , +FIELD_PREP (PHY_CFG_PLL_INT_CNTRL_MASK ,0x8 )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_4 , -PHY_CFG_PLL_GMP_CNTRL_MASK , -FIELD_PREP (PHY_CFG_PLL_GMP_CNTRL_MASK ,0x1 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_4 , +PHY_CFG_PLL_GMP_CNTRL_MASK , +FIELD_PREP (PHY_CFG_PLL_GMP_CNTRL_MASK ,0x1 )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_5 , -PHY_CFG_PLL_PROP_CNTRL_MASK , -FIELD_PREP (PHY_CFG_PLL_PROP_CNTRL_MASK ,0x10 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_5 , +PHY_CFG_PLL_PROP_CNTRL_MASK , +FIELD_PREP (PHY_CFG_PLL_PROP_CNTRL_MASK ,0x10 )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_6 , -PHY_CFG_PLL_VCO_CNTRL_MASK , -FIELD_PREP (PHY_CFG_PLL_VCO_CNTRL_MASK ,0x0 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_6 , +PHY_CFG_PLL_VCO_CNTRL_MASK , +FIELD_PREP (PHY_CFG_PLL_VCO_CNTRL_MASK ,0x0 )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_CFG_CTRL_5 , -PHY_CFG_PLL_VREF_TUNE_MASK , -FIELD_PREP (PHY_CFG_PLL_VREF_TUNE_MASK ,0x1 )); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_5 , +PHY_CFG_PLL_VREF_TUNE_MASK , +FIELD_PREP (PHY_CFG_PLL_VREF_TUNE_MASK ,0x1 )); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL2 , -VBUS_DET_EXT_SEL ,VBUS_DET_EXT_SEL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL2 , +VBUS_DET_EXT_SEL ,VBUS_DET_EXT_SEL );/* set default parameters */ qcom_eusb2_default_parameters (phy); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL2 , -USB2_SUSPEND_N_SEL |USB2_SUSPEND_N , -USB2_SUSPEND_N_SEL |USB2_SUSPEND_N ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL2 , +USB2_SUSPEND_N_SEL |USB2_SUSPEND_N , +USB2_SUSPEND_N_SEL |USB2_SUSPEND_N ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_UTMI_CTRL0 ,SLEEPM ,SLEEPM ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_UTMI_CTRL0 ,SLEEPM ,SLEEPM ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL_COMMON0 , -SIDDQ_SEL ,SIDDQ_SEL ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , +SIDDQ_SEL ,SIDDQ_SEL ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL_COMMON0 , -SIDDQ ,0 ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , +SIDDQ ,0 ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_UTMI_CTRL5 ,POR ,0 ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_UTMI_CTRL5 ,POR ,0 ); -qcom_snps_eusb2_hsphy_write_mask (phy->base,USB_PHY_HS_PHY_CTRL2 , -USB2_SUSPEND_N_SEL ,0 ); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL2 , +USB2_SUSPEND_N_SEL ,0 );return 0 ;
@@ -344,9 +344,9 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)return ret; } -static int qcom_snps_eusb2_hsphy_exit (struct phy *p) +static int snps_eusb2_hsphy_exit (struct phy *p) { -struct qcom_snps_eusb2_hsphy *phy =phy_get_drvdata (p); +struct snps_eusb2_hsphy *phy =phy_get_drvdata (p);clk_disable_unprepare (phy->ref_clk);
@@ -357,18 +357,18 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)return 0 ; } -static const struct phy_ops qcom_snps_eusb2_hsphy_ops = { - .init = qcom_snps_eusb2_hsphy_init, - .exit = qcom_snps_eusb2_hsphy_exit, - .set_mode = qcom_snps_eusb2_hsphy_set_mode, +static const struct phy_ops snps_eusb2_hsphy_ops = { + .init = snps_eusb2_hsphy_init, + .exit = snps_eusb2_hsphy_exit, + .set_mode = snps_eusb2_hsphy_set_mode, .owner =THIS_MODULE , }; -static int qcom_snps_eusb2_hsphy_probe (struct platform_device *pdev) +static int snps_eusb2_hsphy_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct device_node *np = dev->of_node; -struct qcom_snps_eusb2_hsphy *phy; +struct snps_eusb2_hsphy *phy;struct phy_provider *phy_provider;struct phy *generic_phy;int ret, i;
@@ -405,7 +405,7 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (phy->repeater),"failed to get repeater\n" ); - generic_phy =devm_phy_create (dev,NULL , &qcom_snps_eusb2_hsphy_ops); + generic_phy =devm_phy_create (dev,NULL , &snps_eusb2_hsphy_ops);if (IS_ERR (generic_phy)) {dev_err (dev,"failed to create phy %d\n" , ret);return PTR_ERR (generic_phy);
@@ -418,25 +418,25 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)if (IS_ERR (phy_provider))return PTR_ERR (phy_provider); -dev_info (dev,"Registered Qcom-eUSB2 phy\n" ); +dev_info (dev,"Registered Snps-eUSB2 phy\n" );return 0 ; } -static const struct of_device_id qcom_snps_eusb2_hsphy_of_match_table[] = { +static const struct of_device_id snps_eusb2_hsphy_of_match_table[] = { { .compatible ="qcom,sm8550-snps-eusb2-phy" , }, { }, }; -MODULE_DEVICE_TABLE (of, qcom_snps_eusb2_hsphy_of_match_table); +MODULE_DEVICE_TABLE (of, snps_eusb2_hsphy_of_match_table); -static struct platform_driver qcom_snps_eusb2_hsphy_driver = { - .probe = qcom_snps_eusb2_hsphy_probe, +static struct platform_driver snps_eusb2_hsphy_driver = { + .probe = snps_eusb2_hsphy_probe, .driver = { - .name ="qcom-snps-eusb2-hsphy" , - .of_match_table = qcom_snps_eusb2_hsphy_of_match_table, + .name ="snps-eusb2-hsphy" , + .of_match_table = snps_eusb2_hsphy_of_match_table, }, }; -module_platform_driver (qcom_snps_eusb2_hsphy_driver); -MODULE_DESCRIPTION ("Qualcomm SNPS eUSB2 HS PHY driver" ); +module_platform_driver (snps_eusb2_hsphy_driver); +MODULE_DESCRIPTION ("Synopsys eUSB2 HS PHY driver" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.43.0
PATCH v5 5/10 phy: phy-snps-eusb2: split phy init code
In reply to Ivaylo IvanovThe current phy init consists of hardware power-up, as well as QCOM-specific eUSB2 init code. Split it into two parts, to make room for such non-QCOM init code.
--- drivers/phy/phy-snps-eusb2.c | 94 +++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 33 deletions(-)
drivers/phy/phy-snps-eusb2.c +61 -33
@@ -121,6 +121,10 @@ static const char * const eusb2_hsphy_vreg_names[] = {#define EUSB2_NUM_VREGS ARRAY_SIZE(eusb2_hsphy_vreg_names) +struct snps_eusb2_phy_drvdata { +int (*phy_init)(struct phy *p); +}; +struct snps_eusb2_hsphy {struct phy *phy;void __iomem *base;
@@ -133,6 +137,8 @@ struct snps_eusb2_hsphy {enum phy_mode mode;struct phy *repeater; + +const struct snps_eusb2_phy_drvdata *data; };static int snps_eusb2_hsphy_set_mode (struct phy *p,enum phy_mode mode,int submode)
@@ -230,41 +236,11 @@ static int qcom_eusb2_ref_clk_init(struct snps_eusb2_hsphy *phy)return 0 ; } -static int snps_eusb2_hsphy_init (struct phy *p) +static int qcom_snps_eusb2_hsphy_init (struct phy *p) {struct snps_eusb2_hsphy *phy =phy_get_drvdata (p);int ret; - ret =regulator_bulk_enable (ARRAY_SIZE (phy->vregs), phy->vregs); -if (ret) -return ret; - - ret =phy_init (phy->repeater); -if (ret) { -dev_err (&p->dev,"repeater init failed. %d\n" , ret); - goto disable_vreg; - } - - ret =clk_prepare_enable (phy->ref_clk); -if (ret) { -dev_err (&p->dev,"failed to enable ref clock, %d\n" , ret); - goto disable_vreg; - } - - ret =reset_control_assert (phy->phy_reset); -if (ret) { -dev_err (&p->dev,"failed to assert phy_reset, %d\n" , ret); - goto disable_ref_clk; - } - -usleep_range (100 ,150 ); - - ret =reset_control_deassert (phy->phy_reset); -if (ret) { -dev_err (&p->dev,"failed to de-assert phy_reset, %d\n" , ret); - goto disable_ref_clk; - } -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG0 ,CMN_CTRL_OVERRIDE_EN ,CMN_CTRL_OVERRIDE_EN );
@@ -334,6 +310,52 @@ static int snps_eusb2_hsphy_init(struct phy *p) USB2_SUSPEND_N_SEL, 0);return 0 ; +} + +static const struct snps_eusb2_phy_drvdata sm8550_snps_eusb2_phy = { + .phy_init = qcom_snps_eusb2_hsphy_init, +}; + +static int snps_eusb2_hsphy_init (struct phy *p) +{ +struct snps_eusb2_hsphy *phy =phy_get_drvdata (p); +int ret; + + ret =regulator_bulk_enable (ARRAY_SIZE (phy->vregs), phy->vregs); +if (ret) +return ret; + + ret =phy_init (phy->repeater); +if (ret) { +dev_err (&p->dev,"repeater init failed. %d\n" , ret); + goto disable_vreg; + } + + ret =clk_prepare_enable (phy->ref_clk); +if (ret) { +dev_err (&p->dev,"failed to enable ref clock, %d\n" , ret); + goto disable_vreg; + } + + ret =reset_control_assert (phy->phy_reset); +if (ret) { +dev_err (&p->dev,"failed to assert phy_reset, %d\n" , ret); + goto disable_ref_clk; + } + +usleep_range (100 ,150 ); + + ret =reset_control_deassert (phy->phy_reset); +if (ret) { +dev_err (&p->dev,"failed to de-assert phy_reset, %d\n" , ret); + goto disable_ref_clk; + } + + ret = phy->data->phy_init (p); +if (ret) + goto disable_ref_clk; + +return 0 ; disable_ref_clk:clk_disable_unprepare (phy->ref_clk);
@@ -378,6 +400,10 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev)if (!phy)return -ENOMEM ; + phy->data =device_get_match_data (dev); +if (!phy->data) +return -EINVAL ; + phy->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (phy->base))return PTR_ERR (phy->base);
@@ -424,8 +450,10 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev) }static const struct of_device_id snps_eusb2_hsphy_of_match_table[] = { - { .compatible ="qcom,sm8550-snps-eusb2-phy" , }, - { }, + { + .compatible ="qcom,sm8550-snps-eusb2-phy" , + .data = &sm8550_snps_eusb2_phy, + }, { }, };MODULE_DEVICE_TABLE (of, snps_eusb2_hsphy_of_match_table);
Signature · 1 line
2.43.0
PATCH v5 6/10 phy: phy-snps-eusb2: make repeater optional
In reply to Ivaylo IvanovAs described in the device tree bindings, it's not necessary for the SNPS eUSB2 phy to be connected to a repeater. In configurations where there are such instances, the driver probing fails and the usb controller does not work.
Make the repeater optional to avoid that, which also lets us use the eUSB2 phy when it's connected to a repeater that is not configurable by the kernel (for example it's missing a driver), as long as it has been configured beforehand (usually by the bootloader).
--- drivers/phy/phy-snps-eusb2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/phy-snps-eusb2.c +1 -1
@@ -426,7 +426,7 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev)return dev_err_probe (dev, ret,"failed to get regulator supplies\n" ); - phy->repeater =devm_of_phy_get_by_index (dev, np,0 ); + phy->repeater =devm_of_phy_optional_get (dev, np,0 );if (IS_ERR (phy->repeater))return dev_err_probe (dev,PTR_ERR (phy->repeater),"failed to get repeater\n" );
Signature · 1 line
2.43.0
PATCH v5 7/10 phy: phy-snps-eusb2: make reset control optional
In reply to Ivaylo IvanovNot all SoCs expose the reset line controls to the kernel, so make them optional.
--- drivers/phy/phy-snps-eusb2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/phy-snps-eusb2.c +1 -1
@@ -408,7 +408,7 @@ static int snps_eusb2_hsphy_probe(struct platform_device *pdev)if (IS_ERR (phy->base))return PTR_ERR (phy->base); - phy->phy_reset =devm_reset_control_get_exclusive (dev,NULL ); + phy->phy_reset =devm_reset_control_get_optional_exclusive (dev,NULL );if (IS_ERR (phy->phy_reset))return PTR_ERR (phy->phy_reset);
Signature · 1 line
2.43.0
PATCH v5 8/10 phy: phy-snps-eusb2: refactor reference clock init
In reply to Ivaylo IvanovInstead of matching frequencies with a switch and case, introduce a table-based lookup. This improves readability, reduces redundancy, and makes it easier to extend support for additional frequencies in the future.
--- drivers/phy/phy-snps-eusb2.c | 61 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 29 deletions(-)
drivers/phy/phy-snps-eusb2.c +32 -29
@@ -192,44 +192,47 @@ static void qcom_eusb2_default_parameters(struct snps_eusb2_hsphy *phy) FIELD_PREP(PHY_CFG_TX_HS_XV_TUNE_MASK, 0x0)); } +struct snps_eusb2_ref_clk { +unsigned long freq; +u32 fsel_val; +u32 div_7_0_val; +u32 div_11_8_val; +}; + +static const struct snps_eusb2_ref_clk qcom_eusb2_ref_clk[] = { + {19200000 ,FSEL_19_2_MHZ_VAL ,DIV_7_0_19_2_MHZ_VAL ,DIV_11_8_19_2_MHZ_VAL }, + {38400000 ,FSEL_38_4_MHZ_VAL ,DIV_7_0_38_4_MHZ_VAL ,DIV_11_8_38_4_MHZ_VAL }, +}; +static int qcom_eusb2_ref_clk_init (struct snps_eusb2_hsphy *phy) { +const struct snps_eusb2_ref_clk *config =NULL ;unsigned long ref_clk_freq =clk_get_rate (phy->ref_clk); -switch (ref_clk_freq) { -case 19200000 : -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , -FSEL_MASK , -FIELD_PREP (FSEL_MASK ,FSEL_19_2_MHZ_VAL )); - -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_2 , -PHY_CFG_PLL_FB_DIV_7_0_MASK , -DIV_7_0_19_2_MHZ_VAL ); - -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 , -PHY_CFG_PLL_FB_DIV_11_8_MASK , -DIV_11_8_19_2_MHZ_VAL ); -break ; - -case 38400000 : -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , -FSEL_MASK , -FIELD_PREP (FSEL_MASK ,FSEL_38_4_MHZ_VAL )); - -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_2 , -PHY_CFG_PLL_FB_DIV_7_0_MASK , -DIV_7_0_38_4_MHZ_VAL ); - -snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 , -PHY_CFG_PLL_FB_DIV_11_8_MASK , -DIV_11_8_38_4_MHZ_VAL ); -break ; +for (int i =0 ; i <ARRAY_SIZE (qcom_eusb2_ref_clk); i++) { +if (qcom_eusb2_ref_clk[i].freq == ref_clk_freq) { + config = &qcom_eusb2_ref_clk[i]; +break ; + } + } -default : +if (!config) {dev_err (&phy->phy->dev,"unsupported ref_clk_freq:%lu\n" , ref_clk_freq);return -EINVAL ; } +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_HS_PHY_CTRL_COMMON0 , +FSEL_MASK , +FIELD_PREP (FSEL_MASK , config->fsel_val)); + +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_2 , +PHY_CFG_PLL_FB_DIV_7_0_MASK , + config->div_7_0_val); + +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 , +PHY_CFG_PLL_FB_DIV_11_8_MASK , + config->div_11_8_val); +snps_eusb2_hsphy_write_mask (phy->base,QCOM_USB_PHY_CFG_CTRL_3 ,PHY_CFG_PLL_REF_DIV ,PLL_REF_DIV_VAL );
Signature · 1 line
2.43.0
PATCH v5 9/10 phy: phy-snps-eusb2: add support for exynos2200
In reply to Ivaylo IvanovThe Exynos2200 SoC reuses the Synopsis eUSB2 PHY IP, alongside an external repeater, for USB 2.0. Add support for it to the existing driver, while keeping in mind that it requires enabled more than the reference clock.
--- drivers/phy/Kconfig | 2 +- drivers/phy/phy-snps-eusb2.c | 162 ++++++++++++++++++++++++++++++++++- 2 files changed, 159 insertions(+), 5 deletions(-)
drivers/phy/Kconfig +1 -1
@@ -45,7 +45,7 @@ config PHY_PISTACHIO_USB config PHY_SNPS_EUSB2 tristate "SNPS eUSB2 PHY Driver" - depends on OF && (ARCH_QCOM || COMPILE_TEST) + depends on OF && (ARCH_EXYNOS || ARCH_QCOM || COMPILE_TEST) select GENERIC_PHY help Enable support for the USB high-speed SNPS eUSB2 phy on select
drivers/phy/phy-snps-eusb2.c +158 -4
224 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 10/10 phy: exynos5-usbdrd: support Exynos USBDRD 3.2 4nm controller
In reply to Ivaylo IvanovAdd support for the Exynos USB 3.2 DRD 4nm controller. It's used in recent 4nm SoCs like Exynos2200 and Exynos2400.
This device consists of 3 underlying and independent phys: SEC link control phy, Synopsys eUSB 2.0 and Synopsys USBDP/SS combophy. Unlike older device designs, where the internal phy blocks were all IP of Samsung, Synopsys phys are present. This means that the link controller is now mapped differently to account for missing bits and registers. The Synopsys phys also have separate register bases.
As there are non-SEC PHYs present now, it doesn't make much sense to implement them in this driver. They are expected to be configured by external drivers, so pass phandles to them. USBDRD3.2 link controller set up is still required beforehand.
This commit adds the necessary changes for USB HS to work. USB SS and DisplayPort are out of scope in this commit and will be introduced in the future.
--- drivers/phy/samsung/phy-exynos5-usbdrd.c | 227 ++++++++++++++++++-- include/linux/soc/samsung/exynos-regs-pmu.h | 3 + 2 files changed, 215 insertions(+), 15 deletions(-)
drivers/phy/samsung/phy-exynos5-usbdrd.c +212 -15
@@ -36,6 +36,21 @@#define EXYNOS5_FSEL_26MHZ 0x6#define EXYNOS5_FSEL_50MHZ 0x7 +/* USB 3.2 DRD 4nm PHY link controller registers */ +#define EXYNOS2200_DRD_CLKRST 0x0c +#define EXYNOS2200_CLKRST_LINK_PCLK_SEL BIT(1) + +#define EXYNOS2200_DRD_UTMI 0x10 +#define EXYNOS2200_UTMI_FORCE_VBUSVALID BIT(1) +#define EXYNOS2200_UTMI_FORCE_BVALID BIT(0) + +#define EXYNOS2200_DRD_HSP_MISC 0x114 +#define HSP_MISC_SET_REQ_IN2 BIT(4) +#define HSP_MISC_RES_TUNE GENMASK(1, 0) +#define RES_TUNE_PHY1_PHY2 0x1 +#define RES_TUNE_PHY1 0x2 +#define RES_TUNE_PHY2 0x3 +/* Exynos5: USB 3.0 DRD PHY registers */ #define EXYNOS5_DRD_LINKSYSTEM 0x04#define LINKSYSTEM_XHCI_VERSION_CONTROL BIT(27)
@@ -389,6 +404,7 @@ struct exynos5_usbdrd_phy_drvdata {* @clks: clocks for register access * @core_clks: core clocks for phy (ref, pipe3, utmi+, ITP, etc. as required) * @drv_data: pointer to SoC level driver data structure +* @hs_phy: pointer to non-Samsung IP high-speed phy controller * @phy_mutex: mutex protecting phy_init/exit & TCPC callbacks * @phys: array for 'EXYNOS5_DRDPHYS_NUM' number of PHY * instances each with its 'phy' and 'phy_cfg'.
@@ -406,6 +422,7 @@ struct exynos5_usbdrd_phy {struct clk_bulk_data *clks;struct clk_bulk_data *core_clks;const struct exynos5_usbdrd_phy_drvdata *drv_data; +struct phy *hs_phy;struct mutex phy_mutex;struct phy_usb_instance {struct phy *phy;
@@ -1075,6 +1092,149 @@ static const struct phy_ops exynos5_usbdrd_phy_ops = { .owner = THIS_MODULE, }; +static void exynos2200_usbdrd_utmi_init (struct exynos5_usbdrd_phy *phy_drd) +{ +/* Configure non-Samsung IP PHY, responsible for UTMI */ +phy_init (phy_drd->hs_phy); +} + +static void exynos2200_usbdrd_link_init (struct exynos5_usbdrd_phy *phy_drd) +{ +void __iomem *regs_base = phy_drd->reg_phy; +u32 reg; + +/* +* Disable HWACG (hardware auto clock gating control). This will force +* QACTIVE signal in Q-Channel interface to HIGH level, to make sure +* the PHY clock is not gated by the hardware. +*/ + reg =readl (regs_base +EXYNOS850_DRD_LINKCTRL ); + reg |=LINKCTRL_FORCE_QACT ; +writel (reg, regs_base +EXYNOS850_DRD_LINKCTRL ); + +/* De-assert link reset */ + reg =readl (regs_base +EXYNOS2200_DRD_CLKRST ); + reg &= ~CLKRST_LINK_SW_RST ; +writel (reg, regs_base +EXYNOS2200_DRD_CLKRST ); + +/* Set link VBUS Valid */ + reg =readl (regs_base +EXYNOS2200_DRD_UTMI ); + reg |=EXYNOS2200_UTMI_FORCE_BVALID |EXYNOS2200_UTMI_FORCE_VBUSVALID ; +writel (reg, regs_base +EXYNOS2200_DRD_UTMI ); +} + +static void +exynos2200_usbdrd_link_attach_detach_pipe3_phy (struct phy_usb_instance *inst) +{ +struct exynos5_usbdrd_phy *phy_drd =to_usbdrd_phy (inst); +void __iomem *regs_base = phy_drd->reg_phy; +u32 reg; + + reg =readl (regs_base +EXYNOS850_DRD_LINKCTRL ); +if (inst->phy_cfg->id ==EXYNOS5_DRDPHY_UTMI ) { +/* force pipe3 signal for link */ + reg &= ~LINKCTRL_FORCE_PHYSTATUS ; + reg |=LINKCTRL_FORCE_PIPE_EN |LINKCTRL_FORCE_RXELECIDLE ; + }else { +/* disable forcing pipe interface */ + reg &= ~LINKCTRL_FORCE_PIPE_EN ; + } +writel (reg, regs_base +EXYNOS850_DRD_LINKCTRL ); + + reg =readl (regs_base +EXYNOS2200_DRD_HSP_MISC ); +if (inst->phy_cfg->id ==EXYNOS5_DRDPHY_UTMI ) { +/* calibrate only eUSB phy */ + reg |=FIELD_PREP (HSP_MISC_RES_TUNE ,RES_TUNE_PHY1 ); + reg |=HSP_MISC_SET_REQ_IN2 ; + }else { +/* calibrate for dual phy */ + reg |=FIELD_PREP (HSP_MISC_RES_TUNE ,RES_TUNE_PHY1_PHY2 ); + reg &= ~HSP_MISC_SET_REQ_IN2 ; + } +writel (reg, regs_base +EXYNOS2200_DRD_HSP_MISC ); + + reg =readl (regs_base +EXYNOS2200_DRD_CLKRST ); +if (inst->phy_cfg->id ==EXYNOS5_DRDPHY_UTMI ) + reg &= ~EXYNOS2200_CLKRST_LINK_PCLK_SEL ; +else + reg |=EXYNOS2200_CLKRST_LINK_PCLK_SEL ; + +writel (reg, regs_base +EXYNOS2200_DRD_CLKRST ); +} + +static int exynos2200_usbdrd_phy_init (struct phy *phy) +{ +struct phy_usb_instance *inst =phy_get_drvdata (phy); +struct exynos5_usbdrd_phy *phy_drd =to_usbdrd_phy (inst); +int ret; + +if (inst->phy_cfg->id ==EXYNOS5_DRDPHY_UTMI ) { +/* Power-on PHY ... */ + ret =regulator_bulk_enable (phy_drd->drv_data->n_regulators, + phy_drd->regulators); +if (ret) { +dev_err (phy_drd->dev, +"Failed to enable PHY regulator(s)\n" ); +return ret; + } + } +/* +* ... and ungate power via PMU. Without this here, we get an SError +* trying to access PMA registers +*/ +exynos5_usbdrd_phy_isol (inst, false); + + ret =clk_bulk_prepare_enable (phy_drd->drv_data->n_clks, phy_drd->clks); +if (ret) +return ret; + +/* Set up the link controller */ +exynos2200_usbdrd_link_init (phy_drd); + +/* UTMI or PIPE3 link preparation */ +exynos2200_usbdrd_link_attach_detach_pipe3_phy (inst); + +/* UTMI or PIPE3 specific init */ + inst->phy_cfg->phy_init (phy_drd); + +clk_bulk_disable_unprepare (phy_drd->drv_data->n_clks, phy_drd->clks); + +return 0 ; +} + +static int exynos2200_usbdrd_phy_exit (struct phy *phy) +{ +struct phy_usb_instance *inst =phy_get_drvdata (phy); +struct exynos5_usbdrd_phy *phy_drd =to_usbdrd_phy (inst); +void __iomem *regs_base = phy_drd->reg_phy; +u32 reg; +int ret; + + ret =clk_bulk_prepare_enable (phy_drd->drv_data->n_clks, phy_drd->clks); +if (ret) +return ret; + + reg =readl (regs_base +EXYNOS2200_DRD_UTMI ); + reg &= ~(EXYNOS2200_UTMI_FORCE_BVALID |EXYNOS2200_UTMI_FORCE_VBUSVALID ); +writel (reg, regs_base +EXYNOS2200_DRD_UTMI ); + + reg =readl (regs_base +EXYNOS2200_DRD_CLKRST ); + reg |=CLKRST_LINK_SW_RST ; +writel (reg, regs_base +EXYNOS2200_DRD_CLKRST ); + +clk_bulk_disable_unprepare (phy_drd->drv_data->n_clks, phy_drd->clks); + +exynos5_usbdrd_phy_isol (inst, true); +return regulator_bulk_disable (phy_drd->drv_data->n_regulators, + phy_drd->regulators); +} + +static const struct phy_ops exynos2200_usbdrd_phy_ops = { + .init = exynos2200_usbdrd_phy_init, + .exit = exynos2200_usbdrd_phy_exit, + .owner =THIS_MODULE , +}; +static void exynos5_usbdrd_usb_v3p1_pipe_override (struct exynos5_usbdrd_phy *phy_drd) {
@@ -1384,27 +1544,37 @@ static int exynos5_usbdrd_phy_clk_handle(struct exynos5_usbdrd_phy *phy_drd)return dev_err_probe (phy_drd->dev, ret,"failed to get phy core clock(s)\n" ); - ref_clk =NULL ; -for (int i =0 ; i < phy_drd->drv_data->n_core_clks; ++i) { -if (!strcmp (phy_drd->core_clks[i].id,"ref" )) { - ref_clk = phy_drd->core_clks[i].clk; -break ; +if (phy_drd->drv_data->n_core_clks) { + ref_clk =NULL ; +for (int i =0 ; i < phy_drd->drv_data->n_core_clks; ++i) { +if (!strcmp (phy_drd->core_clks[i].id,"ref" )) { + ref_clk = phy_drd->core_clks[i].clk; +break ; + } } - } -if (!ref_clk) -return dev_err_probe (phy_drd->dev, -ENODEV , -"failed to find phy reference clock\n" ); +if (!ref_clk) +return dev_err_probe (phy_drd->dev, -ENODEV , +"failed to find phy reference clock\n" ); - ref_rate =clk_get_rate (ref_clk); - ret =exynos5_rate_to_clk (ref_rate, &phy_drd->extrefclk); -if (ret) -return dev_err_probe (phy_drd->dev, ret, -"clock rate (%ld) not supported\n" , - ref_rate); + ref_rate =clk_get_rate (ref_clk); + ret =exynos5_rate_to_clk (ref_rate, &phy_drd->extrefclk); +if (ret) +return dev_err_probe (phy_drd->dev, ret, +"clock rate (%ld) not supported\n" , + ref_rate); + }return 0 ; } +static const struct exynos5_usbdrd_phy_config phy_cfg_exynos2200[] = { + { + .id =EXYNOS5_DRDPHY_UTMI , + .phy_isol = exynos5_usbdrd_phy_isol, + .phy_init = exynos2200_usbdrd_utmi_init, + }, +}; +static int exynos5_usbdrd_orien_sw_set (struct typec_switch_dev *sw,enum typec_orientation orientation) {
@@ -1525,6 +1695,19 @@ static const char * const exynos5_regulator_names[] = { "vbus", "vbus-boost", }; +static const struct exynos5_usbdrd_phy_drvdata exynos2200_usb32drd_phy = { + .phy_cfg = phy_cfg_exynos2200, + .phy_ops = &exynos2200_usbdrd_phy_ops, + .pmu_offset_usbdrd0_phy =EXYNOS2200_PHY_CTRL_USB20 , + .clk_names = exynos5_clk_names, + .n_clks =ARRAY_SIZE (exynos5_clk_names), +/* clocks and regulators are specific to the underlying PHY blocks */ + .core_clk_names =NULL , + .n_core_clks =0 , + .regulator_names =NULL , + .n_regulators =0 , +}; +static const struct exynos5_usbdrd_phy_drvdata exynos5420_usbdrd_phy = { .phy_cfg = phy_cfg_exynos5, .phy_ops = &exynos5_usbdrd_phy_ops,
@@ -1769,6 +1952,9 @@ static const struct of_device_id exynos5_usbdrd_phy_of_match[] = { { .compatible = "google,gs101-usb31drd-phy", .data = &gs101_usbd31rd_phy + }, { + .compatible = "samsung,exynos2200-usb32drd-phy", + .data = &exynos2200_usb32drd_phy, }, { .compatible = "samsung,exynos5250-usbdrd-phy", .data = &exynos5250_usbdrd_phy
@@ -1841,6 +2027,17 @@ static int exynos5_usbdrd_phy_probe(struct platform_device *pdev)return PTR_ERR (phy_drd->reg_phy); } +/* +* USB32DRD 4nm controller implements Synopsys eUSB2.0 PHY +* and Synopsys SS/USBDP COMBOPHY, managed by external code. +*/ +if (of_property_present (dev->of_node,"phy-names" )) { + phy_drd->hs_phy =devm_of_phy_get (dev, dev->of_node,"hs" ); +if (IS_ERR (phy_drd->hs_phy)) +return dev_err_probe (dev,PTR_ERR (phy_drd->hs_phy), +"failed to get hs_phy\n" ); + } + ret =exynos5_usbdrd_phy_clk_handle (phy_drd);if (ret)return ret;
include/linux/soc/samsung/exynos-regs-pmu.h +3 -0
@@ -185,6 +185,9 @@/* Only for S5Pv210 */ #define S5PV210_EINT_WAKEUP_MASK 0xC004 +/* Only for Exynos2200 */ +#define EXYNOS2200_PHY_CTRL_USB20 0x72C +/* Only for Exynos4210 */ #define S5P_CMU_CLKSTOP_LCD1_LOWPWR 0x1154#define S5P_CMU_RESET_LCD1_LOWPWR 0x1174
Signature · 1 line
2.43.0
Quoted 5 lines · Ivaylo Ivanov
Hey folks,
This patchset adds Exynos2200 support to the existing eUSB2 phy driver, as well as USBDRD support for that SoC.
Quoted 7 lines
The SoC features the same (as far as I can tell from comparing code) USBDRD 3.2 4nm block that Exynos2400 has, hence the common denominator. It consists of a SEC USB link controller, Synopsys eUSB2 and Synopsys USBDP combophy, which are independent underlying hardware blocks of the USBDRD controller.
[...]
Applied, thanks!
[01/10] dt-bindings: phy: add exynos2200 eusb2 phy support
commit: 59cf7546079e3d08d105369c48f8834970290082
[02/10] dt-bindings: phy: samsung,usb3-drd-phy: add exynos2200 support
commit: e4c9a7b475e5d0d9b2440ee48f91d1364eabd6cb
[03/10] phy: move phy-qcom-snps-eusb2 out of its vendor sub-directory
commit: 8d3b5f6375466ffcd2cd98a0c84d31295470fe9d
[04/10] phy: phy-snps-eusb2: refactor constructs names
commit: 93dbe9b5b3a265c7e5466c7b6ada439b01577de5
[05/10] phy: phy-snps-eusb2: split phy init code
commit: 3983b4e9746da1b6091f1d9083f44ed3f12717cb
[06/10] phy: phy-snps-eusb2: make repeater optional
commit: d460be705ae599c0cbfc1ee4ba6a41b225525609
[07/10] phy: phy-snps-eusb2: make reset control optional
commit: aba7a966b50d11deeb3e2f1a66182d150eeb7843
[08/10] phy: phy-snps-eusb2: refactor reference clock init
commit: e36a5d1ecc5f2bda92e4f954f41d65d1ddd5728e
[09/10] phy: phy-snps-eusb2: add support for exynos2200
commit: c4098f3e6134e79e070ec44c58976e1f00d9bfad
[10/10] phy: exynos5-usbdrd: support Exynos USBDRD 3.2 4nm controller
commit: cc52a697f87e8b2d88298827aca3f81398385572Best regards,
Signature · 1 line
~Vinod