* [PATCH v9 0/2] Add Google Tensor SoC USB PHY support
@ 2025-12-22 21:31 Roy Luo
2025-12-22 21:31 ` [PATCH v9 1/2] dt-bindings: phy: google: Add Google Tensor G5 USB PHY Roy Luo
2025-12-22 21:31 ` [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver Roy Luo
0 siblings, 2 replies; 7+ messages in thread
From: Roy Luo @ 2025-12-22 21:31 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Peter Griffin,
André Draszik, Tudor Ambarus, Philipp Zabel, Neil Armstrong
Cc: Badhri Jagan Sridharan, Doug Anderson, linux-phy, devicetree,
linux-kernel, linux-arm-kernel, linux-samsung-soc,
Joy Chakraborty, Naveen Kumar, Roy Luo, Krzysztof Kozlowski
This series introduces USB PHY support for the Google Tensor G5
SoC (codename: Laguna), a new generation of Google silicon first
launched with Pixel 10 devices.
The Tensor G5 represents a significant architectural overhaul compared
to previous Tensor generations (e.g., gs101), which were based on Samsung
Exynos IP. Although the G5 still utilizes Synopsys IP for the USB
components, the custom top-level integration introduces a completely new
design for clock, reset scheme, register interfaces and programming
sequence, necessitating new drivers and device tree bindings.
The USB subsystem on Tensor G5 integrates a Synopsys DWC3 USB 3.1
DRD-Single Port controller with hibernation support, and a custom PHY
block comprising Synopsys eUSB2 and USB 3.2/DP combo PHYs. The controller
support is sent as a separate patch series.
Co-developed-by: Joy Chakraborty <joychakr@google.com>
Signed-off-by: Joy Chakraborty <joychakr@google.com>
Co-developed-by: Naveen Kumar <mnkumar@google.com>
Signed-off-by: Naveen Kumar <mnkumar@google.com>
Signed-off-by: Roy Luo <royluo@google.com>
---
Changes in v9:
- Per Greg's feedback, remove Kconfig dependency on ARCH_GOOGLE || COMPILE_TEST.
Remove ARCH_GOOGLE as it's not yet in the kernel, and COMPILE_TEST is no longer needed without it.
Link to v8: https://lore.kernel.org/r/20251205-phyb4-v8-0-c59ea80a4458@google.com
Changes in v8:
- Update the Kconfig dependency to depends on ARCH_GOOGLE || COMPILE_TEST
Note that ARCH_GOOGLE does not exist yet but will eventually
be there when the following patch lands
https://lore.kernel.org/r/20251111112158.3.I35b9e835ac49ab408e5ca3e0983930a1f1395814@changeid/
- Mention SoC codename Laguna in Kconfig description.
- Sort the header alphabetically and sort the variables using the
reverse christmas tree ordering.
- Add driver and binding files to the Tensor SoC MAINTAINER entry.
- Add detailed comment for phy_mutex
Link to v7: https://lore.kernel.org/r/20251121-phyb4-v7-0-df644fa62180@google.com
Changes in v7:
- Change the device tree binding example node name to usb-phy to follow
the hyphen-separated naming convention and remove label.
Link to v6: https://lore.kernel.org/r/20251120-phyb4-v6-0-b6694e1f0caf@google.com
Changes in v6:
- Use "lga" as SoC name instead of "gs5" to align with Tensor G5 device
tree https://lore.kernel.org/lkml/20251111192422.4180216-1-dianders@chromium.org
- Add "usb2_core" to the reg property to define the MMIO space for
the eUSB 2.0 PHY IP.
- Rename "usb3_top" reg as "usbdp_top" and update the description to
reflect its nature as a top-level wrapper and align with internal
documentation.
- Use syscon to access the "usb2_cfg" MMIO space.
- Remove minItems for clocks and resets, making all listed clocks and
resets (including USB3) mandatory.
Link to v5: https://lore.kernel.org/linux-phy/20251029214032.3175261-1-royluo@google.com
Changes in v5:
- Add usb3 registers/clks/resets to binding as suggested by Krzysztof
Kozlowski. This ensures completeness of the binding, though the
driver has not yet ultilized the resources. The usb3 clks and resets
are optional if usb2-only operation is desired, this is denoted by
minItems and descriptions in the clocks and resets properties.
Additionally, rename existing binding entries for consistency and to
better differntiate between usb2 and usb3.
- Move the description of the phy select to phy-cells in binding as
suggested by Krzysztof Kozlowski.
Link to v4: https://lore.kernel.org/linux-phy/20251017235159.2417576-1-royluo@google.com
Changes in v4:
- Separate controller and phy changes into two distinct patch series.
- Remove usb2only mode configuration and the corresponding usb_top_cfg
reg (moved to controller)
- Add more descriptions to dp_top reg to indicate it's not DP specific.
- Add u2phy_apb clk/reset
Link to v3: https://lore.kernel.org/linux-usb/20251010201607.1190967-1-royluo@google.com
Changes in v3:
- Align binding file name with the compatible string
- Simplify the compatible property in binding to a single const value.
- Add descriptive comments and use item list in binding.
- Rename binding entries for clarity and brevity.
Link to v2: https://lore.kernel.org/linux-usb/20251008060000.3136021-1-royluo@google.com
Changes in v2:
- Reorder patches to present bindings first.
- Update dt binding compatible strings to be SoC-specific (google,gs5-*).
- Better describe the hardware in dt binding commit messages and
descriptions.
- Adjust PHY driver commit subjects to use correct prefixes ("phy:").
- Move PHY driver from a subdirectory to drivers/phy/.
Link to v1: https://lore.kernel.org/linux-usb/20251006232125.1833979-1-royluo@google.com/
---
Roy Luo (2):
dt-bindings: phy: google: Add Google Tensor G5 USB PHY
phy: Add Google Tensor SoC USB PHY driver
.../bindings/phy/google,lga-usb-phy.yaml | 133 ++++++++++
MAINTAINERS | 2 +
drivers/phy/Kconfig | 10 +
drivers/phy/Makefile | 1 +
drivers/phy/phy-google-usb.c | 295 +++++++++++++++++++++
5 files changed, 441 insertions(+)
---
base-commit: ea1013c1539270e372fc99854bc6e4d94eaeff66
change-id: 20251119-phyb4-2e03a7c449c4
Best regards,
--
Roy Luo <royluo@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v9 1/2] dt-bindings: phy: google: Add Google Tensor G5 USB PHY
2025-12-22 21:31 [PATCH v9 0/2] Add Google Tensor SoC USB PHY support Roy Luo
@ 2025-12-22 21:31 ` Roy Luo
2025-12-22 21:31 ` [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver Roy Luo
1 sibling, 0 replies; 7+ messages in thread
From: Roy Luo @ 2025-12-22 21:31 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Peter Griffin,
André Draszik, Tudor Ambarus, Philipp Zabel, Neil Armstrong
Cc: Badhri Jagan Sridharan, Doug Anderson, linux-phy, devicetree,
linux-kernel, linux-arm-kernel, linux-samsung-soc,
Joy Chakraborty, Naveen Kumar, Roy Luo, Krzysztof Kozlowski
Document the device tree bindings for the USB PHY interfaces integrated
with the DWC3 controller on Google Tensor SoCs, starting with G5
generation (Laguna). The USB PHY on Tensor G5 includes two integrated
Synopsys PHY IPs: the eUSB 2.0 PHY IP and the USB 3.2/DisplayPort combo
PHY IP.
Due to a complete architectural overhaul in the Google Tensor G5, the
existing Samsung/Exynos USB PHY binding for older generations of Google
silicons such as gs101 are no longer compatible, necessitating this new
device tree binding.
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Signed-off-by: Roy Luo <royluo@google.com>
---
.../bindings/phy/google,lga-usb-phy.yaml | 133 +++++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 134 insertions(+)
diff --git a/Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml b/Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml
new file mode 100644
index 0000000000000000000000000000000000000000..427e2e3425f645f40c0813e29d6efe4f62b20609
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml
@@ -0,0 +1,133 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2025, Google LLC
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/google,lga-usb-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Google Tensor Series G5 (Laguna) USB PHY
+
+maintainers:
+ - Roy Luo <royluo@google.com>
+
+description:
+ Describes the USB PHY interfaces integrated with the DWC3 USB controller on
+ Google Tensor SoCs, starting with the G5 generation (laguna).
+ Two specific PHY IPs from Synopsys are integrated, including eUSB 2.0 PHY IP
+ and USB3.2/DisplayPort combo PHY IP.
+
+properties:
+ compatible:
+ const: google,lga-usb-phy
+
+ reg:
+ items:
+ - description: USB3.2/DisplayPort combo PHY core registers.
+ - description: USB3.2/DisplayPort combo PHY Type-C Assist registers.
+ - description: eUSB 2.0 PHY core registers.
+ - description: Top-level wrapper registers for the integrated PHYs.
+
+ reg-names:
+ items:
+ - const: usb3_core
+ - const: usb3_tca
+ - const: usb2_core
+ - const: usbdp_top
+
+ "#phy-cells":
+ description: |
+ The phandle's argument in the PHY specifier selects one of the three
+ following PHY interfaces.
+ - 0 for USB high-speed.
+ - 1 for USB super-speed.
+ - 2 for DisplayPort.
+ const: 1
+
+ clocks:
+ items:
+ - description: USB2 PHY clock.
+ - description: USB2 PHY APB clock.
+ - description: USB3.2/DisplayPort combo PHY clock.
+ - description: USB3.2/DisplayPort combo PHY firmware clock.
+
+ clock-names:
+ items:
+ - const: usb2
+ - const: usb2_apb
+ - const: usb3
+ - const: usb3_fw
+
+ resets:
+ items:
+ - description: USB2 PHY reset.
+ - description: USB2 PHY APB reset.
+ - description: USB3.2/DisplayPort combo PHY reset.
+
+ reset-names:
+ items:
+ - const: usb2
+ - const: usb2_apb
+ - const: usb3
+
+ power-domains:
+ maxItems: 1
+
+ orientation-switch:
+ type: boolean
+ description:
+ Indicates the PHY as a handler of USB Type-C orientation changes
+
+ google,usb-cfg-csr:
+ description:
+ A phandle to a syscon node used to access the USB configuration
+ registers. These registers are the top-level wrapper of the USB
+ subsystem and provide control and status for the integrated USB
+ controller and USB PHY.
+ $ref: /schemas/types.yaml#/definitions/phandle-array
+ items:
+ - items:
+ - description: phandle to the syscon node.
+ - description: USB2 PHY configuration register offset.
+
+required:
+ - compatible
+ - reg
+ - reg-names
+ - "#phy-cells"
+ - clocks
+ - clock-names
+ - resets
+ - reset-names
+ - power-domains
+ - orientation-switch
+ - google,usb-cfg-csr
+
+additionalProperties: false
+
+examples:
+ - |
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ usb-phy@c410000 {
+ compatible = "google,lga-usb-phy";
+ reg = <0 0x0c410000 0 0x20000>,
+ <0 0x0c430000 0 0x1000>,
+ <0 0x0c440000 0 0x10000>,
+ <0 0x0c637000 0 0xa0>;
+ reg-names = "usb3_core", "usb3_tca", "usb2_core", "usbdp_top";
+ #phy-cells = <1>;
+ clocks = <&hsion_usb2_phy_clk>, <&hsion_u2phy_apb_clk>,
+ <&hsion_usb3_phy_clk>, <&hsion_usb3_phy_fw_clk>;
+ clock-names = "usb2", "usb2_apb", "usb3", "usb3_fw";
+ resets = <&hsion_resets_usb2_phy>,
+ <&hsion_resets_u2phy_apb>,
+ <&hsion_resets_usb3_phy>;
+ reset-names = "usb2", "usb2_apb", "usb3";
+ power-domains = <&hsio_n_usb_pd>;
+ orientation-switch;
+ google,usb-cfg-csr = <&usb_cfg_csr 0x14>;
+ };
+ };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 5b11839cba9de1e9e43f63787578edd8c429ca39..8a2e94be2f5c5e6e7315bb7bec385798dbd52493 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10721,6 +10721,7 @@ S: Maintained
P: Documentation/process/maintainer-soc-clean-dts.rst
C: irc://irc.oftc.net/pixel6-kernel-dev
F: Documentation/devicetree/bindings/clock/google,gs101-clock.yaml
+F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml
F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml
F: arch/arm64/boot/dts/exynos/google/
F: drivers/clk/samsung/clk-gs101.c
--
2.52.0.358.g0dd7633a29-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver
2025-12-22 21:31 [PATCH v9 0/2] Add Google Tensor SoC USB PHY support Roy Luo
2025-12-22 21:31 ` [PATCH v9 1/2] dt-bindings: phy: google: Add Google Tensor G5 USB PHY Roy Luo
@ 2025-12-22 21:31 ` Roy Luo
2025-12-23 14:04 ` Vinod Koul
1 sibling, 1 reply; 7+ messages in thread
From: Roy Luo @ 2025-12-22 21:31 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Peter Griffin,
André Draszik, Tudor Ambarus, Philipp Zabel, Neil Armstrong
Cc: Badhri Jagan Sridharan, Doug Anderson, linux-phy, devicetree,
linux-kernel, linux-arm-kernel, linux-samsung-soc,
Joy Chakraborty, Naveen Kumar, Roy Luo
Support the USB PHY found on Google Tensor G5 (Laguna). This
particular USB PHY supports both high-speed and super-speed
operations, and is integrated with the SNPS DWC3 controller that's
also on the SoC. This initial patch specifically adds functionality
for high-speed.
Co-developed-by: Joy Chakraborty <joychakr@google.com>
Signed-off-by: Joy Chakraborty <joychakr@google.com>
Co-developed-by: Naveen Kumar <mnkumar@google.com>
Signed-off-by: Naveen Kumar <mnkumar@google.com>
Signed-off-by: Roy Luo <royluo@google.com>
---
MAINTAINERS | 1 +
drivers/phy/Kconfig | 10 ++
drivers/phy/Makefile | 1 +
drivers/phy/phy-google-usb.c | 295 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 307 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 8a2e94be2f5c5e6e7315bb7bec385798dbd52493..afd0d7484ffe5fa652798c9b3c86ae6d83302382 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10725,6 +10725,7 @@ F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml
F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml
F: arch/arm64/boot/dts/exynos/google/
F: drivers/clk/samsung/clk-gs101.c
+F: drivers/phy/phy-google-usb.c
F: drivers/soc/samsung/gs101-pmu.c
F: drivers/phy/samsung/phy-gs101-ufs.c
F: include/dt-bindings/clock/google,gs101*
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 678dd0452f0aa0597773433f04d2a9ba77474d2a..5a642e04caeeea9d40ac583767622cff2ef5e80c 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -101,6 +101,16 @@ config PHY_NXP_PTN3222
schemes. It supports all three USB 2.0 data rates: Low Speed, Full
Speed and High Speed.
+config PHY_GOOGLE_USB
+ tristate "Google Tensor SoC USB PHY driver"
+ select GENERIC_PHY
+ help
+ Enable support for the USB PHY on Google Tensor SoCs, starting with
+ the G5 generation (Laguna). This driver provides the PHY interfaces
+ to interact with the SNPS eUSB2 and USB 3.2/DisplayPort Combo PHY,
+ both of which are integrated with the DWC3 USB DRD controller.
+ This driver currently supports USB high-speed.
+
source "drivers/phy/allwinner/Kconfig"
source "drivers/phy/amlogic/Kconfig"
source "drivers/phy/broadcom/Kconfig"
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index bfb27fb5a494283d7fd05dd670ebd1b12df8b1a1..aeaaaf988554a24bb572d8b34b54638a6a3aed73 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -13,6 +13,7 @@ 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
+obj-$(CONFIG_PHY_GOOGLE_USB) += phy-google-usb.o
obj-y += allwinner/ \
amlogic/ \
broadcom/ \
diff --git a/drivers/phy/phy-google-usb.c b/drivers/phy/phy-google-usb.c
new file mode 100644
index 0000000000000000000000000000000000000000..97e345fdab9b3679e7a76f6957ae3814ef3420e8
--- /dev/null
+++ b/drivers/phy/phy-google-usb.c
@@ -0,0 +1,295 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * phy-google-usb.c - Google USB PHY driver
+ *
+ * Copyright (C) 2025, Google LLC
+ */
+
+#include <linux/bitfield.h>
+#include <linux/cleanup.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/usb/typec_mux.h>
+
+#define USBCS_USB2PHY_CFG19_OFFSET 0x0
+#define USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV GENMASK(19, 8)
+
+#define USBCS_USB2PHY_CFG21_OFFSET 0x8
+#define USBCS_USB2PHY_CFG21_PHY_ENABLE BIT(12)
+#define USBCS_USB2PHY_CFG21_REF_FREQ_SEL GENMASK(15, 13)
+#define USBCS_USB2PHY_CFG21_PHY_TX_DIG_BYPASS_SEL BIT(19)
+
+#define USBCS_PHY_CFG1_OFFSET 0x28
+#define USBCS_PHY_CFG1_SYS_VBUSVALID BIT(17)
+
+enum google_usb_phy_id {
+ GOOGLE_USB2_PHY,
+ GOOGLE_USB_PHY_NUM,
+};
+
+struct google_usb_phy_instance {
+ int index;
+ struct phy *phy;
+ int num_clks;
+ struct clk_bulk_data *clks;
+ int num_rsts;
+ struct reset_control_bulk_data *rsts;
+};
+
+struct google_usb_phy {
+ struct device *dev;
+ struct regmap *usb_cfg_regmap;
+ unsigned int usb2_cfg_offset;
+ void __iomem *usbdp_top_base;
+ struct google_usb_phy_instance insts[GOOGLE_USB_PHY_NUM];
+ /*
+ * Protect phy registers from concurrent access, specifically via
+ * google_usb_set_orientation callback.
+ */
+ struct mutex phy_mutex;
+ struct typec_switch_dev *sw;
+ enum typec_orientation orientation;
+};
+
+static inline struct google_usb_phy *to_google_usb_phy(struct google_usb_phy_instance *inst)
+{
+ return container_of(inst, struct google_usb_phy, insts[inst->index]);
+}
+
+static void set_vbus_valid(struct google_usb_phy *gphy)
+{
+ u32 reg;
+
+ if (gphy->orientation == TYPEC_ORIENTATION_NONE) {
+ reg = readl(gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
+ reg &= ~USBCS_PHY_CFG1_SYS_VBUSVALID;
+ writel(reg, gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
+ } else {
+ reg = readl(gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
+ reg |= USBCS_PHY_CFG1_SYS_VBUSVALID;
+ writel(reg, gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
+ }
+}
+
+static int google_usb_set_orientation(struct typec_switch_dev *sw,
+ enum typec_orientation orientation)
+{
+ struct google_usb_phy *gphy = typec_switch_get_drvdata(sw);
+
+ dev_dbg(gphy->dev, "set orientation %d\n", orientation);
+
+ gphy->orientation = orientation;
+
+ if (pm_runtime_suspended(gphy->dev))
+ return 0;
+
+ guard(mutex)(&gphy->phy_mutex);
+
+ set_vbus_valid(gphy);
+
+ return 0;
+}
+
+static int google_usb2_phy_init(struct phy *_phy)
+{
+ struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
+ struct google_usb_phy *gphy = to_google_usb_phy(inst);
+ u32 reg;
+ int ret = 0;
+
+ dev_dbg(gphy->dev, "initializing usb2 phy\n");
+
+ guard(mutex)(&gphy->phy_mutex);
+
+ regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
+ reg &= ~USBCS_USB2PHY_CFG21_PHY_TX_DIG_BYPASS_SEL;
+ reg &= ~USBCS_USB2PHY_CFG21_REF_FREQ_SEL;
+ reg |= FIELD_PREP(USBCS_USB2PHY_CFG21_REF_FREQ_SEL, 0);
+ regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
+
+ regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG19_OFFSET, ®);
+ reg &= ~USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV;
+ reg |= FIELD_PREP(USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV, 368);
+ regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG19_OFFSET, reg);
+
+ set_vbus_valid(gphy);
+
+ ret = clk_bulk_prepare_enable(inst->num_clks, inst->clks);
+ if (ret)
+ return ret;
+
+ ret = reset_control_bulk_deassert(inst->num_rsts, inst->rsts);
+ if (ret) {
+ clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
+ return ret;
+ }
+
+ regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
+ reg |= USBCS_USB2PHY_CFG21_PHY_ENABLE;
+ regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
+
+ return ret;
+}
+
+static int google_usb2_phy_exit(struct phy *_phy)
+{
+ struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
+ struct google_usb_phy *gphy = to_google_usb_phy(inst);
+ u32 reg;
+
+ dev_dbg(gphy->dev, "exiting usb2 phy\n");
+
+ guard(mutex)(&gphy->phy_mutex);
+
+ regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
+ reg &= ~USBCS_USB2PHY_CFG21_PHY_ENABLE;
+ regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
+
+ reset_control_bulk_assert(inst->num_rsts, inst->rsts);
+ clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
+
+ return 0;
+}
+
+static const struct phy_ops google_usb2_phy_ops = {
+ .init = google_usb2_phy_init,
+ .exit = google_usb2_phy_exit,
+};
+
+static struct phy *google_usb_phy_xlate(struct device *dev,
+ const struct of_phandle_args *args)
+{
+ struct google_usb_phy *gphy = dev_get_drvdata(dev);
+
+ if (args->args[0] >= GOOGLE_USB_PHY_NUM) {
+ dev_err(dev, "invalid PHY index requested from DT\n");
+ return ERR_PTR(-ENODEV);
+ }
+ return gphy->insts[args->args[0]].phy;
+}
+
+static int google_usb_phy_probe(struct platform_device *pdev)
+{
+ struct typec_switch_desc sw_desc = { };
+ struct google_usb_phy_instance *inst;
+ struct phy_provider *phy_provider;
+ struct device *dev = &pdev->dev;
+ struct google_usb_phy *gphy;
+ struct phy *phy;
+ u32 args[1];
+ int ret;
+
+ gphy = devm_kzalloc(dev, sizeof(*gphy), GFP_KERNEL);
+ if (!gphy)
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, gphy);
+ gphy->dev = dev;
+
+ ret = devm_mutex_init(dev, &gphy->phy_mutex);
+ if (ret)
+ return ret;
+
+ gphy->usb_cfg_regmap =
+ syscon_regmap_lookup_by_phandle_args(dev->of_node,
+ "google,usb-cfg-csr",
+ ARRAY_SIZE(args), args);
+ if (IS_ERR(gphy->usb_cfg_regmap)) {
+ return dev_err_probe(dev, PTR_ERR(gphy->usb_cfg_regmap),
+ "invalid usb cfg csr\n");
+ }
+
+ gphy->usb2_cfg_offset = args[0];
+
+ gphy->usbdp_top_base = devm_platform_ioremap_resource_byname(pdev,
+ "usbdp_top");
+ if (IS_ERR(gphy->usbdp_top_base))
+ return dev_err_probe(dev, PTR_ERR(gphy->usbdp_top_base),
+ "invalid usbdp top\n");
+
+ inst = &gphy->insts[GOOGLE_USB2_PHY];
+ inst->index = GOOGLE_USB2_PHY;
+ phy = devm_phy_create(dev, NULL, &google_usb2_phy_ops);
+ if (IS_ERR(phy))
+ return dev_err_probe(dev, PTR_ERR(phy),
+ "failed to create usb2 phy instance\n");
+ inst->phy = phy;
+ phy_set_drvdata(phy, inst);
+
+ inst->num_clks = 2;
+ inst->clks = devm_kcalloc(dev, inst->num_clks, sizeof(*inst->clks), GFP_KERNEL);
+ if (!inst->clks)
+ return -ENOMEM;
+ inst->clks[0].id = "usb2";
+ inst->clks[1].id = "usb2_apb";
+ ret = devm_clk_bulk_get(dev, inst->num_clks, inst->clks);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to get u2 phy clks\n");
+
+ inst->num_rsts = 2;
+ inst->rsts = devm_kcalloc(dev, inst->num_rsts, sizeof(*inst->rsts), GFP_KERNEL);
+ if (!inst->rsts)
+ return -ENOMEM;
+ inst->rsts[0].id = "usb2";
+ inst->rsts[1].id = "usb2_apb";
+ ret = devm_reset_control_bulk_get_exclusive(dev, inst->num_rsts, inst->rsts);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to get u2 phy resets\n");
+
+ phy_provider = devm_of_phy_provider_register(dev, google_usb_phy_xlate);
+ if (IS_ERR(phy_provider))
+ return dev_err_probe(dev, PTR_ERR(phy_provider),
+ "failed to register phy provider\n");
+
+ pm_runtime_enable(dev);
+
+ sw_desc.fwnode = dev_fwnode(dev);
+ sw_desc.drvdata = gphy;
+ sw_desc.name = fwnode_get_name(dev_fwnode(dev));
+ sw_desc.set = google_usb_set_orientation;
+
+ gphy->sw = typec_switch_register(dev, &sw_desc);
+ if (IS_ERR(gphy->sw))
+ return dev_err_probe(dev, PTR_ERR(gphy->sw),
+ "failed to register typec switch\n");
+
+ return 0;
+}
+
+static void google_usb_phy_remove(struct platform_device *pdev)
+{
+ struct google_usb_phy *gphy = dev_get_drvdata(&pdev->dev);
+
+ typec_switch_unregister(gphy->sw);
+ pm_runtime_disable(&pdev->dev);
+}
+
+static const struct of_device_id google_usb_phy_of_match[] = {
+ {
+ .compatible = "google,lga-usb-phy",
+ },
+ { }
+};
+MODULE_DEVICE_TABLE(of, google_usb_phy_of_match);
+
+static struct platform_driver google_usb_phy = {
+ .probe = google_usb_phy_probe,
+ .remove = google_usb_phy_remove,
+ .driver = {
+ .name = "google-usb-phy",
+ .of_match_table = google_usb_phy_of_match,
+ }
+};
+
+module_platform_driver(google_usb_phy);
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Google USB phy driver");
--
2.52.0.358.g0dd7633a29-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver
2025-12-22 21:31 ` [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver Roy Luo
@ 2025-12-23 14:04 ` Vinod Koul
2025-12-23 17:53 ` Roy Luo
0 siblings, 1 reply; 7+ messages in thread
From: Vinod Koul @ 2025-12-23 14:04 UTC (permalink / raw)
To: Roy Luo
Cc: Kishon Vijay Abraham I, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Peter Griffin, André Draszik, Tudor Ambarus,
Philipp Zabel, Neil Armstrong, Badhri Jagan Sridharan,
Doug Anderson, linux-phy, devicetree, linux-kernel,
linux-arm-kernel, linux-samsung-soc, Joy Chakraborty,
Naveen Kumar
On 22-12-25, 21:31, Roy Luo wrote:
> Support the USB PHY found on Google Tensor G5 (Laguna). This
> particular USB PHY supports both high-speed and super-speed
> operations, and is integrated with the SNPS DWC3 controller that's
> also on the SoC. This initial patch specifically adds functionality
> for high-speed.
>
> Co-developed-by: Joy Chakraborty <joychakr@google.com>
> Signed-off-by: Joy Chakraborty <joychakr@google.com>
> Co-developed-by: Naveen Kumar <mnkumar@google.com>
> Signed-off-by: Naveen Kumar <mnkumar@google.com>
> Signed-off-by: Roy Luo <royluo@google.com>
> ---
> MAINTAINERS | 1 +
> drivers/phy/Kconfig | 10 ++
> drivers/phy/Makefile | 1 +
> drivers/phy/phy-google-usb.c | 295 +++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 307 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 8a2e94be2f5c5e6e7315bb7bec385798dbd52493..afd0d7484ffe5fa652798c9b3c86ae6d83302382 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -10725,6 +10725,7 @@ F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml
> F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml
> F: arch/arm64/boot/dts/exynos/google/
> F: drivers/clk/samsung/clk-gs101.c
> +F: drivers/phy/phy-google-usb.c
> F: drivers/soc/samsung/gs101-pmu.c
> F: drivers/phy/samsung/phy-gs101-ufs.c
> F: include/dt-bindings/clock/google,gs101*
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index 678dd0452f0aa0597773433f04d2a9ba77474d2a..5a642e04caeeea9d40ac583767622cff2ef5e80c 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -101,6 +101,16 @@ config PHY_NXP_PTN3222
> schemes. It supports all three USB 2.0 data rates: Low Speed, Full
> Speed and High Speed.
>
> +config PHY_GOOGLE_USB
This does not seem sorted!
> + tristate "Google Tensor SoC USB PHY driver"
> + select GENERIC_PHY
> + help
> + Enable support for the USB PHY on Google Tensor SoCs, starting with
> + the G5 generation (Laguna). This driver provides the PHY interfaces
> + to interact with the SNPS eUSB2 and USB 3.2/DisplayPort Combo PHY,
> + both of which are integrated with the DWC3 USB DRD controller.
> + This driver currently supports USB high-speed.
> +
> source "drivers/phy/allwinner/Kconfig"
> source "drivers/phy/amlogic/Kconfig"
> source "drivers/phy/broadcom/Kconfig"
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index bfb27fb5a494283d7fd05dd670ebd1b12df8b1a1..aeaaaf988554a24bb572d8b34b54638a6a3aed73 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -13,6 +13,7 @@ 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
> +obj-$(CONFIG_PHY_GOOGLE_USB) += phy-google-usb.o
and here!
> obj-y += allwinner/ \
> amlogic/ \
> broadcom/ \
> diff --git a/drivers/phy/phy-google-usb.c b/drivers/phy/phy-google-usb.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..97e345fdab9b3679e7a76f6957ae3814ef3420e8
> --- /dev/null
> +++ b/drivers/phy/phy-google-usb.c
> @@ -0,0 +1,295 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * phy-google-usb.c - Google USB PHY driver
> + *
> + * Copyright (C) 2025, Google LLC
> + */
> +
> +#include <linux/bitfield.h>
> +#include <linux/cleanup.h>
> +#include <linux/clk.h>
> +#include <linux/io.h>
> +#include <linux/kernel.h>
> +#include <linux/mfd/syscon.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/of.h>
> +#include <linux/phy/phy.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/reset.h>
> +#include <linux/usb/typec_mux.h>
> +
> +#define USBCS_USB2PHY_CFG19_OFFSET 0x0
> +#define USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV GENMASK(19, 8)
> +
> +#define USBCS_USB2PHY_CFG21_OFFSET 0x8
> +#define USBCS_USB2PHY_CFG21_PHY_ENABLE BIT(12)
> +#define USBCS_USB2PHY_CFG21_REF_FREQ_SEL GENMASK(15, 13)
> +#define USBCS_USB2PHY_CFG21_PHY_TX_DIG_BYPASS_SEL BIT(19)
> +
> +#define USBCS_PHY_CFG1_OFFSET 0x28
> +#define USBCS_PHY_CFG1_SYS_VBUSVALID BIT(17)
> +
> +enum google_usb_phy_id {
> + GOOGLE_USB2_PHY,
> + GOOGLE_USB_PHY_NUM,
> +};
> +
> +struct google_usb_phy_instance {
> + int index;
maybe use unsigned?
> + struct phy *phy;
> + int num_clks;
here too?
> + struct clk_bulk_data *clks;
+ int num_rsts;
and here?
> + struct reset_control_bulk_data *rsts;
> +};
> +
> +struct google_usb_phy {
> + struct device *dev;
> + struct regmap *usb_cfg_regmap;
> + unsigned int usb2_cfg_offset;
> + void __iomem *usbdp_top_base;
> + struct google_usb_phy_instance insts[GOOGLE_USB_PHY_NUM];
so you have an array for one phy?
> + /*
> + * Protect phy registers from concurrent access, specifically via
> + * google_usb_set_orientation callback.
> + */
> + struct mutex phy_mutex;
> + struct typec_switch_dev *sw;
> + enum typec_orientation orientation;
> +};
> +
> +static inline struct google_usb_phy *to_google_usb_phy(struct google_usb_phy_instance *inst)
> +{
> + return container_of(inst, struct google_usb_phy, insts[inst->index]);
> +}
> +
> +static void set_vbus_valid(struct google_usb_phy *gphy)
> +{
> + u32 reg;
> +
> + if (gphy->orientation == TYPEC_ORIENTATION_NONE) {
> + reg = readl(gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> + reg &= ~USBCS_PHY_CFG1_SYS_VBUSVALID;
> + writel(reg, gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> + } else {
> + reg = readl(gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> + reg |= USBCS_PHY_CFG1_SYS_VBUSVALID;
> + writel(reg, gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> + }
> +}
> +
> +static int google_usb_set_orientation(struct typec_switch_dev *sw,
> + enum typec_orientation orientation)
> +{
> + struct google_usb_phy *gphy = typec_switch_get_drvdata(sw);
> +
> + dev_dbg(gphy->dev, "set orientation %d\n", orientation);
> +
> + gphy->orientation = orientation;
> +
> + if (pm_runtime_suspended(gphy->dev))
> + return 0;
> +
> + guard(mutex)(&gphy->phy_mutex);
> +
> + set_vbus_valid(gphy);
> +
> + return 0;
> +}
> +
> +static int google_usb2_phy_init(struct phy *_phy)
> +{
> + struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
> + struct google_usb_phy *gphy = to_google_usb_phy(inst);
> + u32 reg;
> + int ret = 0;
superfluous init
> +
> + dev_dbg(gphy->dev, "initializing usb2 phy\n");
> +
> + guard(mutex)(&gphy->phy_mutex);
> +
> + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> + reg &= ~USBCS_USB2PHY_CFG21_PHY_TX_DIG_BYPASS_SEL;
> + reg &= ~USBCS_USB2PHY_CFG21_REF_FREQ_SEL;
> + reg |= FIELD_PREP(USBCS_USB2PHY_CFG21_REF_FREQ_SEL, 0);
> + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> +
> + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG19_OFFSET, ®);
> + reg &= ~USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV;
> + reg |= FIELD_PREP(USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV, 368);
> + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG19_OFFSET, reg);
> +
> + set_vbus_valid(gphy);
> +
> + ret = clk_bulk_prepare_enable(inst->num_clks, inst->clks);
> + if (ret)
> + return ret;
> +
> + ret = reset_control_bulk_deassert(inst->num_rsts, inst->rsts);
> + if (ret) {
> + clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
> + return ret;
> + }
> +
> + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> + reg |= USBCS_USB2PHY_CFG21_PHY_ENABLE;
> + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> +
> + return ret;
would it not be return 0 here? can it be any other value
> +}
> +
> +static int google_usb2_phy_exit(struct phy *_phy)
> +{
> + struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
> + struct google_usb_phy *gphy = to_google_usb_phy(inst);
> + u32 reg;
> +
> + dev_dbg(gphy->dev, "exiting usb2 phy\n");
> +
> + guard(mutex)(&gphy->phy_mutex);
> +
> + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> + reg &= ~USBCS_USB2PHY_CFG21_PHY_ENABLE;
> + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> +
> + reset_control_bulk_assert(inst->num_rsts, inst->rsts);
> + clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
> +
> + return 0;
> +}
> +
> +static const struct phy_ops google_usb2_phy_ops = {
> + .init = google_usb2_phy_init,
> + .exit = google_usb2_phy_exit,
> +};
Only two ops? I would expect more... No power_on/off or set_mode?
--
~Vinod
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver
2025-12-23 14:04 ` Vinod Koul
@ 2025-12-23 17:53 ` Roy Luo
2025-12-24 5:30 ` Vinod Koul
0 siblings, 1 reply; 7+ messages in thread
From: Roy Luo @ 2025-12-23 17:53 UTC (permalink / raw)
To: Vinod Koul
Cc: Kishon Vijay Abraham I, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Peter Griffin, André Draszik, Tudor Ambarus,
Philipp Zabel, Neil Armstrong, Badhri Jagan Sridharan,
Doug Anderson, linux-phy, devicetree, linux-kernel,
linux-arm-kernel, linux-samsung-soc, Joy Chakraborty,
Naveen Kumar
On Tue, Dec 23, 2025 at 6:04 AM Vinod Koul <vkoul@kernel.org> wrote:
>
> On 22-12-25, 21:31, Roy Luo wrote:
> > Support the USB PHY found on Google Tensor G5 (Laguna). This
> > particular USB PHY supports both high-speed and super-speed
> > operations, and is integrated with the SNPS DWC3 controller that's
> > also on the SoC. This initial patch specifically adds functionality
> > for high-speed.
> >
> > Co-developed-by: Joy Chakraborty <joychakr@google.com>
> > Signed-off-by: Joy Chakraborty <joychakr@google.com>
> > Co-developed-by: Naveen Kumar <mnkumar@google.com>
> > Signed-off-by: Naveen Kumar <mnkumar@google.com>
> > Signed-off-by: Roy Luo <royluo@google.com>
> > ---
> > MAINTAINERS | 1 +
> > drivers/phy/Kconfig | 10 ++
> > drivers/phy/Makefile | 1 +
> > drivers/phy/phy-google-usb.c | 295 +++++++++++++++++++++++++++++++++++++++++++
> > 4 files changed, 307 insertions(+)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 8a2e94be2f5c5e6e7315bb7bec385798dbd52493..afd0d7484ffe5fa652798c9b3c86ae6d83302382 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -10725,6 +10725,7 @@ F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml
> > F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml
> > F: arch/arm64/boot/dts/exynos/google/
> > F: drivers/clk/samsung/clk-gs101.c
> > +F: drivers/phy/phy-google-usb.c
> > F: drivers/soc/samsung/gs101-pmu.c
> > F: drivers/phy/samsung/phy-gs101-ufs.c
> > F: include/dt-bindings/clock/google,gs101*
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index 678dd0452f0aa0597773433f04d2a9ba77474d2a..5a642e04caeeea9d40ac583767622cff2ef5e80c 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -101,6 +101,16 @@ config PHY_NXP_PTN3222
> > schemes. It supports all three USB 2.0 data rates: Low Speed, Full
> > Speed and High Speed.
> >
> > +config PHY_GOOGLE_USB
>
> This does not seem sorted!
>
> > + tristate "Google Tensor SoC USB PHY driver"
> > + select GENERIC_PHY
> > + help
> > + Enable support for the USB PHY on Google Tensor SoCs, starting with
> > + the G5 generation (Laguna). This driver provides the PHY interfaces
> > + to interact with the SNPS eUSB2 and USB 3.2/DisplayPort Combo PHY,
> > + both of which are integrated with the DWC3 USB DRD controller.
> > + This driver currently supports USB high-speed.
> > +
> > source "drivers/phy/allwinner/Kconfig"
> > source "drivers/phy/amlogic/Kconfig"
> > source "drivers/phy/broadcom/Kconfig"
> > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> > index bfb27fb5a494283d7fd05dd670ebd1b12df8b1a1..aeaaaf988554a24bb572d8b34b54638a6a3aed73 100644
> > --- a/drivers/phy/Makefile
> > +++ b/drivers/phy/Makefile
> > @@ -13,6 +13,7 @@ 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
> > +obj-$(CONFIG_PHY_GOOGLE_USB) += phy-google-usb.o
>
> and here!
>
> > obj-y += allwinner/ \
> > amlogic/ \
> > broadcom/ \
> > diff --git a/drivers/phy/phy-google-usb.c b/drivers/phy/phy-google-usb.c
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..97e345fdab9b3679e7a76f6957ae3814ef3420e8
> > --- /dev/null
> > +++ b/drivers/phy/phy-google-usb.c
> > @@ -0,0 +1,295 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * phy-google-usb.c - Google USB PHY driver
> > + *
> > + * Copyright (C) 2025, Google LLC
> > + */
> > +
> > +#include <linux/bitfield.h>
> > +#include <linux/cleanup.h>
> > +#include <linux/clk.h>
> > +#include <linux/io.h>
> > +#include <linux/kernel.h>
> > +#include <linux/mfd/syscon.h>
> > +#include <linux/module.h>
> > +#include <linux/mutex.h>
> > +#include <linux/of.h>
> > +#include <linux/phy/phy.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > +#include <linux/reset.h>
> > +#include <linux/usb/typec_mux.h>
> > +
> > +#define USBCS_USB2PHY_CFG19_OFFSET 0x0
> > +#define USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV GENMASK(19, 8)
> > +
> > +#define USBCS_USB2PHY_CFG21_OFFSET 0x8
> > +#define USBCS_USB2PHY_CFG21_PHY_ENABLE BIT(12)
> > +#define USBCS_USB2PHY_CFG21_REF_FREQ_SEL GENMASK(15, 13)
> > +#define USBCS_USB2PHY_CFG21_PHY_TX_DIG_BYPASS_SEL BIT(19)
> > +
> > +#define USBCS_PHY_CFG1_OFFSET 0x28
> > +#define USBCS_PHY_CFG1_SYS_VBUSVALID BIT(17)
> > +
> > +enum google_usb_phy_id {
> > + GOOGLE_USB2_PHY,
> > + GOOGLE_USB_PHY_NUM,
> > +};
> > +
> > +struct google_usb_phy_instance {
> > + int index;
>
> maybe use unsigned?
>
> > + struct phy *phy;
> > + int num_clks;
>
> here too?
>
> > + struct clk_bulk_data *clks;
> + int num_rsts;
>
> and here?
Ack to all the comments above, will fix them in the next version.
>
> > + struct reset_control_bulk_data *rsts;
> > +};
> > +
> > +struct google_usb_phy {
> > + struct device *dev;
> > + struct regmap *usb_cfg_regmap;
> > + unsigned int usb2_cfg_offset;
> > + void __iomem *usbdp_top_base;
> > + struct google_usb_phy_instance insts[GOOGLE_USB_PHY_NUM];
>
> so you have an array for one phy?
While the current patch only supports usb2, I used an array
to simplify future support for usb3 and DP. I understand this
might seem like over-engineering for now, and we could
certainly wait to implement the array until the second phy
support is added. I’m happy to move away from array if
you’d prefer a simpler approach for this iteration.
>
> > + /*
> > + * Protect phy registers from concurrent access, specifically via
> > + * google_usb_set_orientation callback.
> > + */
> > + struct mutex phy_mutex;
> > + struct typec_switch_dev *sw;
> > + enum typec_orientation orientation;
> > +};
> > +
> > +static inline struct google_usb_phy *to_google_usb_phy(struct google_usb_phy_instance *inst)
> > +{
> > + return container_of(inst, struct google_usb_phy, insts[inst->index]);
> > +}
> > +
> > +static void set_vbus_valid(struct google_usb_phy *gphy)
> > +{
> > + u32 reg;
> > +
> > + if (gphy->orientation == TYPEC_ORIENTATION_NONE) {
> > + reg = readl(gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> > + reg &= ~USBCS_PHY_CFG1_SYS_VBUSVALID;
> > + writel(reg, gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> > + } else {
> > + reg = readl(gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> > + reg |= USBCS_PHY_CFG1_SYS_VBUSVALID;
> > + writel(reg, gphy->usbdp_top_base + USBCS_PHY_CFG1_OFFSET);
> > + }
> > +}
> > +
> > +static int google_usb_set_orientation(struct typec_switch_dev *sw,
> > + enum typec_orientation orientation)
> > +{
> > + struct google_usb_phy *gphy = typec_switch_get_drvdata(sw);
> > +
> > + dev_dbg(gphy->dev, "set orientation %d\n", orientation);
> > +
> > + gphy->orientation = orientation;
> > +
> > + if (pm_runtime_suspended(gphy->dev))
> > + return 0;
> > +
> > + guard(mutex)(&gphy->phy_mutex);
> > +
> > + set_vbus_valid(gphy);
> > +
> > + return 0;
> > +}
> > +
> > +static int google_usb2_phy_init(struct phy *_phy)
> > +{
> > + struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
> > + struct google_usb_phy *gphy = to_google_usb_phy(inst);
> > + u32 reg;
> > + int ret = 0;
>
> superfluous init
Ack, will fix it in the next version.
>
> > +
> > + dev_dbg(gphy->dev, "initializing usb2 phy\n");
> > +
> > + guard(mutex)(&gphy->phy_mutex);
> > +
> > + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> > + reg &= ~USBCS_USB2PHY_CFG21_PHY_TX_DIG_BYPASS_SEL;
> > + reg &= ~USBCS_USB2PHY_CFG21_REF_FREQ_SEL;
> > + reg |= FIELD_PREP(USBCS_USB2PHY_CFG21_REF_FREQ_SEL, 0);
> > + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> > +
> > + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG19_OFFSET, ®);
> > + reg &= ~USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV;
> > + reg |= FIELD_PREP(USBCS_USB2PHY_CFG19_PHY_CFG_PLL_FB_DIV, 368);
> > + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG19_OFFSET, reg);
> > +
> > + set_vbus_valid(gphy);
> > +
> > + ret = clk_bulk_prepare_enable(inst->num_clks, inst->clks);
> > + if (ret)
> > + return ret;
> > +
> > + ret = reset_control_bulk_deassert(inst->num_rsts, inst->rsts);
> > + if (ret) {
> > + clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
> > + return ret;
> > + }
> > +
> > + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> > + reg |= USBCS_USB2PHY_CFG21_PHY_ENABLE;
> > + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> > +
> > + return ret;
>
> would it not be return 0 here? can it be any other value
No it cannot be any other value, will change it to "return 0".
>
> > +}
> > +
> > +static int google_usb2_phy_exit(struct phy *_phy)
> > +{
> > + struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
> > + struct google_usb_phy *gphy = to_google_usb_phy(inst);
> > + u32 reg;
> > +
> > + dev_dbg(gphy->dev, "exiting usb2 phy\n");
> > +
> > + guard(mutex)(&gphy->phy_mutex);
> > +
> > + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> > + reg &= ~USBCS_USB2PHY_CFG21_PHY_ENABLE;
> > + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> > +
> > + reset_control_bulk_assert(inst->num_rsts, inst->rsts);
> > + clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
> > +
> > + return 0;
> > +}
> > +
> > +static const struct phy_ops google_usb2_phy_ops = {
> > + .init = google_usb2_phy_init,
> > + .exit = google_usb2_phy_exit,
> > +};
>
> Only two ops? I would expect more... No power_on/off or set_mode?
>
> --
> ~Vinod
No, configuring usb2 phy is pretty straightforward. The hardware
does not distinguish between "initialized" and "powered on" states,
it also does not distinguish phy mode.
Thanks,
Roy
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver
2025-12-23 17:53 ` Roy Luo
@ 2025-12-24 5:30 ` Vinod Koul
2025-12-25 0:33 ` Roy Luo
0 siblings, 1 reply; 7+ messages in thread
From: Vinod Koul @ 2025-12-24 5:30 UTC (permalink / raw)
To: Roy Luo
Cc: Kishon Vijay Abraham I, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Peter Griffin, André Draszik, Tudor Ambarus,
Philipp Zabel, Neil Armstrong, Badhri Jagan Sridharan,
Doug Anderson, linux-phy, devicetree, linux-kernel,
linux-arm-kernel, linux-samsung-soc, Joy Chakraborty,
Naveen Kumar
On 23-12-25, 09:53, Roy Luo wrote:
> On Tue, Dec 23, 2025 at 6:04 AM Vinod Koul <vkoul@kernel.org> wrote:
> >
> > On 22-12-25, 21:31, Roy Luo wrote:
> > > +struct google_usb_phy {
> > > + struct device *dev;
> > > + struct regmap *usb_cfg_regmap;
> > > + unsigned int usb2_cfg_offset;
> > > + void __iomem *usbdp_top_base;
> > > + struct google_usb_phy_instance insts[GOOGLE_USB_PHY_NUM];
> >
> > so you have an array for one phy?
>
> While the current patch only supports usb2, I used an array
> to simplify future support for usb3 and DP. I understand this
> might seem like over-engineering for now, and we could
> certainly wait to implement the array until the second phy
> support is added. I’m happy to move away from array if
> you’d prefer a simpler approach for this iteration.
Rather than do array, allocate mem as probe based on how many phys will
be there and use that. That would be a better approach than static
allocation here
> > > +static int google_usb2_phy_exit(struct phy *_phy)
> > > +{
> > > + struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
> > > + struct google_usb_phy *gphy = to_google_usb_phy(inst);
> > > + u32 reg;
> > > +
> > > + dev_dbg(gphy->dev, "exiting usb2 phy\n");
> > > +
> > > + guard(mutex)(&gphy->phy_mutex);
> > > +
> > > + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> > > + reg &= ~USBCS_USB2PHY_CFG21_PHY_ENABLE;
> > > + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> > > +
> > > + reset_control_bulk_assert(inst->num_rsts, inst->rsts);
> > > + clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static const struct phy_ops google_usb2_phy_ops = {
> > > + .init = google_usb2_phy_init,
> > > + .exit = google_usb2_phy_exit,
> > > +};
> >
> > Only two ops? I would expect more... No power_on/off or set_mode?
> >
> > --
> > ~Vinod
>
> No, configuring usb2 phy is pretty straightforward. The hardware
> does not distinguish between "initialized" and "powered on" states,
> it also does not distinguish phy mode.
ok
--
~Vinod
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver
2025-12-24 5:30 ` Vinod Koul
@ 2025-12-25 0:33 ` Roy Luo
0 siblings, 0 replies; 7+ messages in thread
From: Roy Luo @ 2025-12-25 0:33 UTC (permalink / raw)
To: Vinod Koul
Cc: Kishon Vijay Abraham I, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Peter Griffin, André Draszik, Tudor Ambarus,
Philipp Zabel, Neil Armstrong, Badhri Jagan Sridharan,
Doug Anderson, linux-phy, devicetree, linux-kernel,
linux-arm-kernel, linux-samsung-soc, Joy Chakraborty,
Naveen Kumar
On Tue, Dec 23, 2025 at 9:30 PM Vinod Koul <vkoul@kernel.org> wrote:
>
> On 23-12-25, 09:53, Roy Luo wrote:
> > On Tue, Dec 23, 2025 at 6:04 AM Vinod Koul <vkoul@kernel.org> wrote:
> > >
> > > On 22-12-25, 21:31, Roy Luo wrote:
>
> > > > +struct google_usb_phy {
> > > > + struct device *dev;
> > > > + struct regmap *usb_cfg_regmap;
> > > > + unsigned int usb2_cfg_offset;
> > > > + void __iomem *usbdp_top_base;
> > > > + struct google_usb_phy_instance insts[GOOGLE_USB_PHY_NUM];
> > >
> > > so you have an array for one phy?
> >
> > While the current patch only supports usb2, I used an array
> > to simplify future support for usb3 and DP. I understand this
> > might seem like over-engineering for now, and we could
> > certainly wait to implement the array until the second phy
> > support is added. I’m happy to move away from array if
> > you’d prefer a simpler approach for this iteration.
>
> Rather than do array, allocate mem as probe based on how many phys will
> be there and use that. That would be a better approach than static
> allocation here
Make sense, will change it in the next version.
Thanks,
Roy
>
> > > > +static int google_usb2_phy_exit(struct phy *_phy)
> > > > +{
> > > > + struct google_usb_phy_instance *inst = phy_get_drvdata(_phy);
> > > > + struct google_usb_phy *gphy = to_google_usb_phy(inst);
> > > > + u32 reg;
> > > > +
> > > > + dev_dbg(gphy->dev, "exiting usb2 phy\n");
> > > > +
> > > > + guard(mutex)(&gphy->phy_mutex);
> > > > +
> > > > + regmap_read(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, ®);
> > > > + reg &= ~USBCS_USB2PHY_CFG21_PHY_ENABLE;
> > > > + regmap_write(gphy->usb_cfg_regmap, gphy->usb2_cfg_offset + USBCS_USB2PHY_CFG21_OFFSET, reg);
> > > > +
> > > > + reset_control_bulk_assert(inst->num_rsts, inst->rsts);
> > > > + clk_bulk_disable_unprepare(inst->num_clks, inst->clks);
> > > > +
> > > > + return 0;
> > > > +}
> > > > +
> > > > +static const struct phy_ops google_usb2_phy_ops = {
> > > > + .init = google_usb2_phy_init,
> > > > + .exit = google_usb2_phy_exit,
> > > > +};
> > >
> > > Only two ops? I would expect more... No power_on/off or set_mode?
> > >
> > > --
> > > ~Vinod
> >
> > No, configuring usb2 phy is pretty straightforward. The hardware
> > does not distinguish between "initialized" and "powered on" states,
> > it also does not distinguish phy mode.
>
> ok
>
> --
> ~Vinod
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-25 0:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-22 21:31 [PATCH v9 0/2] Add Google Tensor SoC USB PHY support Roy Luo
2025-12-22 21:31 ` [PATCH v9 1/2] dt-bindings: phy: google: Add Google Tensor G5 USB PHY Roy Luo
2025-12-22 21:31 ` [PATCH v9 2/2] phy: Add Google Tensor SoC USB PHY driver Roy Luo
2025-12-23 14:04 ` Vinod Koul
2025-12-23 17:53 ` Roy Luo
2025-12-24 5:30 ` Vinod Koul
2025-12-25 0:33 ` Roy Luo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).