From nobody Mon Dec 15 18:55:56 2025 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D03AA31618F for ; Wed, 29 Oct 2025 08:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761727243; cv=none; b=Jr7nrNzqWc/MZQcJyUYq8s2itWvAMJ6CNNskJHoYahXN3ukTaVjcz9tLkgDfQ1imGaOeXO1eZN7rqOjnYbF6/CCNbFJXjhsJLEAEkS6s1ifblNQhQwdmSNDt9xzp/zjSsdfYFodYpdH1RsNx/eoycNnQLiUlANzdZ+/sll0q1Pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761727243; c=relaxed/simple; bh=3dfxHvLEODjIsoBymhUDZZGiO3PfPaDxRfipDf2Q+eU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YaiH6UkHU1jpr7wiv3RGUw2ATlBKgWB4ox/7K6eHmMg0LHwZDHCBSW6tYRbB1S6JT0TB1L6j0LW0E8GBXpiCfVcGVosVW8XLgxgbqb+e5FAvvJ3IFqcXUcIugiG2SujwnuIkx3d/xcBu+yZzyfhn0VXY9QyjY+XviWpiVfRlAzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Rm10YfvX; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Rm10YfvX" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3ece1102998so4953602f8f.2 for ; Wed, 29 Oct 2025 01:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761727240; x=1762332040; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5zDKBowBIfgO2OmsFcxAdae/8qYwuZcAE+WV1T/cljM=; b=Rm10YfvX39NGehU72t5+bv4SznCrV20Ajt+EeSvYl+Mm6LRpHQt3O5zIq8n7Cik6pc 4lR2UxNyF+uqb/tnh5Uc2lGCTAnfZB127b6XN75hV13gTzyjJnaasoYoLPTnypw60iMF fWA5wUpFtzIWQyKI5rySOd3j4iSYDPVnj4BvMNbixh1t7h9SDo3I5b2y0YiUtlguxthd wLlaR2ICjNP+n2UM5gDX6799S++NHaVLng1R/TfAVb46FmYdTy4mfiYYdILPwyp87FE4 IvJky5X+6ERZYpOC9udc1HZ38JDYLqEVAGGI+nP8IXOrqWpN5uOSwCXQ9FY3pSdxkfOk fTJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761727240; x=1762332040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5zDKBowBIfgO2OmsFcxAdae/8qYwuZcAE+WV1T/cljM=; b=bwN7MH/ozomCQq260Tdcr+U1Bcl1J12LPI4Uh6sncqxPGrt96WC1JYoVme6oTXIFC2 FD5faEAknlenNNG7aYTCVfxInolvzggVCi+qD3wU7Ct8BqTNoOAdUDLBgVsqGWw80xpy /Eju7rca+tau9xn13Hs+dm0eH4GAlxIZknxhXUwdezAPLYEgT5GZv06/epOYf3oZzvTj JRt4FLkFuhs99fWdUEPBDxyuYG08TD8HP9MeMPc67bDG7HKaUomvmyVzPv/iHb8AqxSI LGQxKyHwJITGbCOrgFZuVhJuyTv6aFCz/oWct9R3DTYiDnPVNaNmXamKwUD6tLUhQKY7 fXtQ== X-Forwarded-Encrypted: i=1; AJvYcCWy8PJVYovZEsGAJwD9hxJhUk8yGcTDJPEcgzX8+ULlhZlZe12QX4IJC7aq7svTGm+gzOZ1eX4Y19/vkKE=@vger.kernel.org X-Gm-Message-State: AOJu0YyYL7KR06GeSDssXhjVQZRfgmolb4SasRCzml23VDBoHlDY5row UkkHnlC+b2LCPw64DQ20m97e/O9NAPtpyULhbDYiZ2RTN94PAeSS4bG0 X-Gm-Gg: ASbGncvhjSakuCj+tyrP3amovhKvSzUYd61hgqs730Q7S6COjD5+t8O6xNtLtDp0XRC uthC3PrL/gMosLppZQu56E13MJmzvoxt/18hf0ZgdJvxGb1GyjI8tyr7Et4StJN87Tl4GPv4r+J zQc+D1V17f1cYq7qbTYZwDBfP5wkELmS3WN+HWkLRC01AZxoBtn7xI1f38ukgo7eonEHqFBcUxz wrIKrH7zSHuRBQAOs9vEH7XjW8NyZ1W+lx/7auDp7/Z9iqbKkWVzCgUKT/c4Jb3hABRjp479y0T mQ6x8DVykSOuI4pSv+R8YsMw7kXwARy7zLg+rauX6FZB7K1rblamngthS8/QXcqqXOWGjq1tonA kLv5sZfxV+UcyLq/UF6K+aruIkVrUBMUTr6doF4NBCl3vwq0jYnzKMJCjYDj4X/uIyU4a4MM/km gD2or+MhuZlK4hr/LGK2vrRFHrT53rRN0NBAxJSxIjGxuAfyGU64xBZN8R5b59 X-Google-Smtp-Source: AGHT+IF3LoH+MVR8GJt0HNUZBmCSpCGxlcDgvQw6PVT+Io7cZd3fZ9aRwEFQRwsDZ93XErw9fNatZA== X-Received: by 2002:a05:600c:4e91:b0:46e:39e1:fc27 with SMTP id 5b1f17b1804b1-4771e16596fmr20457285e9.5.1761727239965; Wed, 29 Oct 2025 01:40:39 -0700 (PDT) Received: from biju.lan (host86-162-200-138.range86-162.btcentralplus.com. [86.162.200.138]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771e3a88fdsm39485785e9.10.2025.10.29.01.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Oct 2025 01:40:39 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: Vinod Koul , Kishon Vijay Abraham I , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das , Conor Dooley Subject: [PATCH v4 1/2] dt-bindings: phy: renesas: Document Renesas RZ/G3E USB3.0 PHY Date: Wed, 29 Oct 2025 08:40:33 +0000 Message-ID: <20251029084037.108610-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251029084037.108610-1-biju.das.jz@bp.renesas.com> References: <20251029084037.108610-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das Document Renesas RZ/G3E USB3.0 PHY. This IP is connected between USB3HOST and PHY module. The main functions of the module are as follows: - Reset control - Control of PHY input pins - Monitoring of PHY output pins Acked-by: Conor Dooley Signed-off-by: Biju Das Reviewed-by: Geert Uytterhoeven --- v3->v4: * Collected tag from Geert. v2->v3: * No change. v1->v2: * Collected tag. --- .../bindings/phy/renesas,rzg3e-usb3-phy.yaml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/renesas,rzg3e-usb= 3-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/renesas,rzg3e-usb3-phy.y= aml b/Documentation/devicetree/bindings/phy/renesas,rzg3e-usb3-phy.yaml new file mode 100644 index 000000000000..b86dc7a291a4 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/renesas,rzg3e-usb3-phy.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/renesas,rzg3e-usb3-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas RZ/G3E USB 3.0 PHY + +maintainers: + - Biju Das + +properties: + compatible: + const: renesas,r9a09g047-usb3-phy + + reg: + maxItems: 1 + + clocks: + items: + - description: APB bus clock + - description: USB 2.0 PHY reference clock + - description: USB 3.0 PHY reference clock + + clock-names: + items: + - const: pclk + - const: core + - const: ref_alt_clk_p + + power-domains: + maxItems: 1 + + resets: + maxItems: 1 + + '#phy-cells': + const: 0 + +required: + - compatible + - reg + - clocks + - clock-names + - power-domains + - resets + - '#phy-cells' + +additionalProperties: false + +examples: + - | + #include + + usb-phy@15870000 { + compatible =3D "renesas,r9a09g047-usb3-phy"; + reg =3D <0x15870000 0x10000>; + clocks =3D <&cpg CPG_MOD 0xb0>, <&cpg CPG_CORE 13>, <&cpg CPG_CORE= 12>; + clock-names =3D "pclk", "core", "ref_alt_clk_p"; + power-domains =3D <&cpg>; + resets =3D <&cpg 0xaa>; + #phy-cells =3D <0>; + }; --=20 2.43.0 From nobody Mon Dec 15 18:55:56 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8527D3176EE for ; Wed, 29 Oct 2025 08:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761727244; cv=none; b=pfZY1xfrR4ZtgjU3ZsuvryJVEnpniubFZU5rKesk3X2LzdDcdGfJIWjKw9SGUG88PZhc8GZoy2b3d0snRRb9gI/LNBQwc2SsLY6Dj5z33jbLl8P8+xy7l+bgjs6KLptK8q2Mqr4pjjKQ5Lb0G4ybwInaWMJcvBLAJ2RPaRDlxqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761727244; c=relaxed/simple; bh=vhg77NPrJbfbtlwLph27UEV+rMaDy6NMQ2zzIVBSguE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B0Y0j5Q678BCt2gAyaqRePCiVIA0q2n/m9mQ3uNDOwrSltvEIDhgOSeaCtcL5hRqsR9gOCxAq2Ygx7IQX79w4Oqllic89rKid7T5NqCJh+G3Mfv6vVhX83Jk4AQRfpUJ8NwCXyk28mhogV6YTLKPcXpQJtbHzHGLbbPcqzNZa9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iiUM19+A; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iiUM19+A" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4770c2cd96fso29072315e9.3 for ; Wed, 29 Oct 2025 01:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761727241; x=1762332041; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yOAdXeCySbjJEk/kibiqyjUANlvv/DZXMZMEq2j8UHo=; b=iiUM19+Aec09SJLdt/0kcPmxxvBLTdJ21Wj6hwIIAUtt6YuJyhUwF0U0gHb8LgGbtM FnEglNTMEXQS/d+FMJJkO2ypMoIrRQ8h+AF4X+lKuneBvYheh6uJWQAPsGVa43nkF8MY iy5JYdzd1aURYmDJQSFhDhFyaEqm6oYvip4dY1YiSXIusTFbN2DTXnFqsb5Ghen1iewm 3Ubg4s1SFqRl+DbxamQ7dXb349T6tjj24iW/oItQ9bT2LIeihIaNhjBIh0J7NMighfrH t3GPW31k6lV2xwvWBqqOxPQ/oY4aZKqdkPmD9QiItLFJ+IRgwzfA+ods+3As71Q/cFIc F2kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761727241; x=1762332041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yOAdXeCySbjJEk/kibiqyjUANlvv/DZXMZMEq2j8UHo=; b=haEDLw16oEwLEJXkdHqbBjxVbcqhJhbOaRCXhuQX6Zyuz1bEteEejgPb06pv1G9Avr E55e9a4wTDj9715iAS4SWLTe756/UF0Z/PAVFxPDbsXtPco3gj3Juo6ndm3hSRDj1nlx Vh2FjFTaiUOtbO3m7/EqdjjTnTRV4bA+Ga6udvDfX84WW1RE9lra0mzp1WwRn7TzNWFs 0eTSBPSPdCOMgxiH6KN52B6Lzzl/2ZKra9RBeoZI8/rxmKmwO2QKsCiU4UJ+Zslb6KKL 0yhAxTxfrMISI08s3dMGz5muvxuhNnRzJIClMlH7dHLU2T5+XfHYCjagRmXoEwWzQrBB 9uPQ== X-Forwarded-Encrypted: i=1; AJvYcCVp2XJHU6RAlpEICQbUm632PzsadbDuGCNHuTkBt1oFE+zrgbc0wyUrhk6W885Kx9m/dPhssjFVWM4QK/o=@vger.kernel.org X-Gm-Message-State: AOJu0YzpAyRMEO1DNAQtTbgl1k7AVl/aP8wBycdnsmkMBOVB9JmmSLMH nW/1LDt/8NJkhe/3AGcRk1VnWoGeF09vvjcL35gwQ+BZ9XcIks3Mwj6J X-Gm-Gg: ASbGncuXLuE9WXhPEpeNma6KmlDCm2eaBK9hq7a05UFTe9vOX+HuaXKa9pNq+0dLUgQ apGk6aUsJnZw5Ts6nor7PSGvgjeEx5h9R3DwZiZjAB4uObN1sI0m0BJeQpjrY3643JKV3YswYYK 1HXxDVFesAz/hrTIIi4ATT7F9YXDCjZeCPhqTNxD8xnA3dMm6QGN5v0R5L1f8ywNbX7vCcPQ+8k HgKmZVfEzYGpk2eoHxhE81hr+227OeXEd4QweA5jI9KMcEPKE2jNywemKtRSaMr3xBAEZfM4Gsb xs63C+INDI3ms3XEZs2eX6LgIpON8LWPQKjkAlSnNewdBSL/qOcBQu4EEog67h8OAhNtiEOpX53 Kur39xsQQ94YTjZT4QaTBQDKeWpauJtGWeGNE09gVAb/J+I6a+Aq7iuBMRyXmczy4HYuyDv7cnZ ZpV4Tx5efuP7Bq8NqQX/ECp1ZfkIdyGQ0LEdF/3hILUJAilCjauJcd51DESEE5kCs+mhmzkpU= X-Google-Smtp-Source: AGHT+IH9RIrjLksdUCrbzSCp311nPeAZD3eSrYvoTKYR1LiJXSO0CMRVDNEtnW9UaULBQXM+sISFRQ== X-Received: by 2002:a05:600c:3106:b0:45b:47e1:ef6d with SMTP id 5b1f17b1804b1-4771e406a08mr18821965e9.36.1761727240435; Wed, 29 Oct 2025 01:40:40 -0700 (PDT) Received: from biju.lan (host86-162-200-138.range86-162.btcentralplus.com. [86.162.200.138]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771e3a88fdsm39485785e9.10.2025.10.29.01.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Oct 2025 01:40:40 -0700 (PDT) From: Biju X-Google-Original-From: Biju To: Vinod Koul , Kishon Vijay Abraham I , Philipp Zabel , Geert Uytterhoeven , Magnus Damm Cc: Biju Das , linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das Subject: [PATCH v4 2/2] phy: renesas: Add Renesas RZ/G3E USB3.0 PHY driver Date: Wed, 29 Oct 2025 08:40:34 +0000 Message-ID: <20251029084037.108610-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251029084037.108610-1-biju.das.jz@bp.renesas.com> References: <20251029084037.108610-1-biju.das.jz@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Biju Das Add Renesas RZ/G3E USB3.0 PHY driver. This module is connected between USB3 Host and PHY module. The main functions of this module are: 1) Reset control 2) Control of PHY input pins 3) Monitoring of PHY output pins Signed-off-by: Biju Das --- v3->v4: * No change. v2->v3: * Replaced devm_reset_control_get_{shared}->{shared_deasserted} * Dropped remove() callback v1->v2: * Replaced magic numbers with macros. --- drivers/phy/renesas/Kconfig | 7 + drivers/phy/renesas/Makefile | 1 + drivers/phy/renesas/phy-rzg3e-usb3.c | 259 +++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/phy/renesas/phy-rzg3e-usb3.c diff --git a/drivers/phy/renesas/Kconfig b/drivers/phy/renesas/Kconfig index e342eef0640b..16211072098e 100644 --- a/drivers/phy/renesas/Kconfig +++ b/drivers/phy/renesas/Kconfig @@ -40,3 +40,10 @@ config PHY_RCAR_GEN3_USB3 select GENERIC_PHY help Support for USB 3.0 PHY found on Renesas R-Car generation 3 SoCs. + +config PHY_RZ_G3E_USB3 + tristate "Renesas RZ/G3E USB 3.0 PHY driver" + depends on ARCH_RENESAS || COMPILE_TEST + select GENERIC_PHY + help + Support for USB 3.0 PHY found on Renesas RZ/G3E SoCs. diff --git a/drivers/phy/renesas/Makefile b/drivers/phy/renesas/Makefile index 8896d1919faa..0e98083f2f0c 100644 --- a/drivers/phy/renesas/Makefile +++ b/drivers/phy/renesas/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_PHY_RCAR_GEN2) +=3D phy-rcar-gen2.o obj-$(CONFIG_PHY_RCAR_GEN3_PCIE) +=3D phy-rcar-gen3-pcie.o obj-$(CONFIG_PHY_RCAR_GEN3_USB2) +=3D phy-rcar-gen3-usb2.o obj-$(CONFIG_PHY_RCAR_GEN3_USB3) +=3D phy-rcar-gen3-usb3.o +obj-$(CONFIG_PHY_RZ_G3E_USB3) +=3D phy-rzg3e-usb3.o diff --git a/drivers/phy/renesas/phy-rzg3e-usb3.c b/drivers/phy/renesas/phy= -rzg3e-usb3.c new file mode 100644 index 000000000000..6b3453ea0004 --- /dev/null +++ b/drivers/phy/renesas/phy-rzg3e-usb3.c @@ -0,0 +1,259 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Renesas RZ/G3E USB3.0 PHY driver + * + * Copyright (C) 2025 Renesas Electronics Corporation + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define USB3_TEST_RESET 0x0000 +#define USB3_TEST_UTMICTRL2 0x0b04 +#define USB3_TEST_PRMCTRL5_R 0x0c10 +#define USB3_TEST_PRMCTRL6_R 0x0c14 + +#define USB3_TEST_RSTCTRL 0x1000 +#define USB3_TEST_CLKCTRL 0x1004 +#define USB3_TEST_RAMCTRL 0x100c +#define USB3_TEST_CREGCTRL 0x1010 +#define USB3_TEST_LANECONFIG0 0x1030 + +#define USB3_TEST_RESET_PORTRESET0_CTRL BIT(9) +#define USB3_TEST_RESET_SIDDQ BIT(3) +#define USB3_TEST_RESET_PHY_RESET BIT(2) +#define USB3_TEST_RESET_PORTRESET0 BIT(1) +#define USB3_TEST_RESET_RELEASE_OVERRIDE (0) + +#define USB3_TEST_UTMICTRL2_CTRL_MASK GENMASK(9, 8) +#define USB3_TEST_UTMICTRL2_MODE_MASK GENMASK(1, 0) + +#define USB3_TEST_PRMCTRL5_R_TXPREEMPAMPTUNE0_MASK GENMASK(2, 1) + +#define USB3_TEST_PRMCTRL6_R_OTGTUNE0_MASK GENMASK(2, 0) + +#define USB3_TEST_RSTCTRL_HARDRESET_ODEN BIT(9) +#define USB3_TEST_RSTCTRL_PIPERESET_ODEN BIT(8) +#define USB3_TEST_RSTCTRL_HARDRESET BIT(1) +#define USB3_TEST_RSTCTRL_PIPERESET BIT(0) +#define USB3_TEST_RSTCTRL_ASSERT \ + (USB3_TEST_RSTCTRL_HARDRESET_ODEN | USB3_TEST_RSTCTRL_PIPERESET_ODEN | \ + USB3_TEST_RSTCTRL_HARDRESET | USB3_TEST_RSTCTRL_PIPERESET) +#define USB3_TEST_RSTCTRL_RELEASE_HARDRESET \ + (USB3_TEST_RSTCTRL_HARDRESET_ODEN | USB3_TEST_RSTCTRL_PIPERESET_ODEN | \ + USB3_TEST_RSTCTRL_PIPERESET) +#define USB3_TEST_RSTCTRL_DEASSERT \ + (USB3_TEST_RSTCTRL_HARDRESET_ODEN | USB3_TEST_RSTCTRL_PIPERESET_ODEN) +#define USB3_TEST_RSTCTRL_RELEASE_OVERRIDE (0) + +#define USB3_TEST_CLKCTRL_MPLLA_SSC_EN BIT(2) + +#define USB3_TEST_RAMCTRL_SRAM_INIT_DONE BIT(2) +#define USB3_TEST_RAMCTRL_SRAM_EXT_LD_DONE BIT(0) + +#define USB3_TEST_CREGCTRL_PARA_SEL BIT(8) + +#define USB3_TEST_LANECONFIG0_DEFAULT (0xd) + +struct rz_usb3 { + void __iomem *base; + struct reset_control *rstc; + bool skip_reinit; +}; + +static void rzg3e_phy_usb2test_phy_init(void __iomem *base) +{ + u32 val; + + val =3D readl(base + USB3_TEST_UTMICTRL2); + val |=3D USB3_TEST_UTMICTRL2_CTRL_MASK | USB3_TEST_UTMICTRL2_MODE_MASK; + writel(val, base + USB3_TEST_UTMICTRL2); + + val =3D readl(base + USB3_TEST_PRMCTRL5_R); + val &=3D ~USB3_TEST_PRMCTRL5_R_TXPREEMPAMPTUNE0_MASK; + val |=3D FIELD_PREP(USB3_TEST_PRMCTRL5_R_TXPREEMPAMPTUNE0_MASK, 2); + writel(val, base + USB3_TEST_PRMCTRL5_R); + + val =3D readl(base + USB3_TEST_PRMCTRL6_R); + val &=3D ~USB3_TEST_PRMCTRL6_R_OTGTUNE0_MASK; + val |=3D FIELD_PREP(USB3_TEST_PRMCTRL6_R_OTGTUNE0_MASK, 7); + writel(val, base + USB3_TEST_PRMCTRL6_R); + + val =3D readl(base + USB3_TEST_RESET); + val &=3D ~USB3_TEST_RESET_SIDDQ; + val |=3D USB3_TEST_RESET_PORTRESET0_CTRL | USB3_TEST_RESET_PHY_RESET | + USB3_TEST_RESET_PORTRESET0; + writel(val, base + USB3_TEST_RESET); + fsleep(10); + + val &=3D ~(USB3_TEST_RESET_PHY_RESET | USB3_TEST_RESET_PORTRESET0); + writel(val, base + USB3_TEST_RESET); + fsleep(10); + + val =3D readl(base + USB3_TEST_UTMICTRL2); + val &=3D ~USB3_TEST_UTMICTRL2_CTRL_MASK; + writel(val, base + USB3_TEST_UTMICTRL2); + + writel(USB3_TEST_RESET_RELEASE_OVERRIDE, base + USB3_TEST_RESET); +} + +static int rzg3e_phy_usb3test_phy_init(void __iomem *base) +{ + int ret; + u32 val; + + writel(USB3_TEST_CREGCTRL_PARA_SEL, base + USB3_TEST_CREGCTRL); + writel(USB3_TEST_RSTCTRL_ASSERT, base + USB3_TEST_RSTCTRL); + fsleep(20); + + writel(USB3_TEST_CLKCTRL_MPLLA_SSC_EN, base + USB3_TEST_CLKCTRL); + writel(USB3_TEST_LANECONFIG0_DEFAULT, base + USB3_TEST_LANECONFIG0); + writel(USB3_TEST_RSTCTRL_RELEASE_HARDRESET, base + USB3_TEST_RSTCTRL); + + ret =3D readl_poll_timeout_atomic(base + USB3_TEST_RAMCTRL, val, + val & USB3_TEST_RAMCTRL_SRAM_INIT_DONE, 1, 10000); + if (ret) + return ret; + + writel(USB3_TEST_RSTCTRL_DEASSERT, base + USB3_TEST_RSTCTRL); + writel(USB3_TEST_RAMCTRL_SRAM_EXT_LD_DONE, base + USB3_TEST_RAMCTRL); + writel(USB3_TEST_RSTCTRL_RELEASE_OVERRIDE, base + USB3_TEST_RSTCTRL); + + return 0; +} + +static int rzg3e_phy_usb3_init_helper(void __iomem *base) +{ + rzg3e_phy_usb2test_phy_init(base); + + return rzg3e_phy_usb3test_phy_init(base); +} + +static int rzg3e_phy_usb3_init(struct phy *p) +{ + struct rz_usb3 *r =3D phy_get_drvdata(p); + int ret =3D 0; + + if (!r->skip_reinit) + ret =3D rzg3e_phy_usb3_init_helper(r->base); + + return ret; +} + +static const struct phy_ops rzg3e_phy_usb3_ops =3D { + .init =3D rzg3e_phy_usb3_init, + .owner =3D THIS_MODULE, +}; + +static int rzg3e_phy_usb3_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct phy_provider *provider; + struct rz_usb3 *r; + struct phy *phy; + int ret; + + r =3D devm_kzalloc(dev, sizeof(*r), GFP_KERNEL); + if (!r) + return -ENOMEM; + + r->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(r->base)) + return PTR_ERR(r->base); + + r->rstc =3D devm_reset_control_get_shared_deasserted(dev, NULL); + if (IS_ERR(r->rstc)) + return dev_err_probe(dev, PTR_ERR(r->rstc), "failed to get deasserted re= set\n"); + + /* + * devm_phy_create() will call pm_runtime_enable(&phy->dev); + * And then, phy-core will manage runtime pm for this device. + */ + ret =3D devm_pm_runtime_enable(dev); + if (ret < 0) + return ret; + + phy =3D devm_phy_create(dev, NULL, &rzg3e_phy_usb3_ops); + if (IS_ERR(phy)) + return dev_err_probe(dev, PTR_ERR(phy), "failed to create USB3 PHY\n"); + + platform_set_drvdata(pdev, r); + phy_set_drvdata(phy, r); + + provider =3D devm_of_phy_provider_register(dev, of_phy_simple_xlate); + if (IS_ERR(provider)) + return dev_err_probe(dev, PTR_ERR(provider), "failed to register PHY pro= vider\n"); + + return 0; +} + +static int rzg3e_phy_usb3_suspend(struct device *dev) +{ + struct rz_usb3 *r =3D dev_get_drvdata(dev); + + pm_runtime_put(dev); + reset_control_assert(r->rstc); + r->skip_reinit =3D false; + + return 0; +} + +static int rzg3e_phy_usb3_resume(struct device *dev) +{ + struct rz_usb3 *r =3D dev_get_drvdata(dev); + int ret; + + ret =3D reset_control_deassert(r->rstc); + if (ret) + return ret; + + ret =3D pm_runtime_resume_and_get(dev); + if (ret) + goto reset_assert; + + ret =3D rzg3e_phy_usb3_init_helper(r->base); + if (ret) + goto pm_put; + + r->skip_reinit =3D true; + + return 0; + +pm_put: + pm_runtime_put(dev); +reset_assert: + reset_control_assert(r->rstc); + return ret; +} + +static const struct dev_pm_ops rzg3e_phy_usb3_pm =3D { + NOIRQ_SYSTEM_SLEEP_PM_OPS(rzg3e_phy_usb3_suspend, rzg3e_phy_usb3_resume) +}; + +static const struct of_device_id rzg3e_phy_usb3_match_table[] =3D { + { .compatible =3D "renesas,r9a09g047-usb3-phy" }, + { /* Sentinel */ } +}; + +MODULE_DEVICE_TABLE(of, rzg3e_phy_usb3_match_table); +static struct platform_driver rzg3e_phy_usb3_driver =3D { + .driver =3D { + .name =3D "phy_rzg3e_usb3", + .of_match_table =3D rzg3e_phy_usb3_match_table, + .pm =3D pm_sleep_ptr(&rzg3e_phy_usb3_pm), + }, + .probe =3D rzg3e_phy_usb3_probe, +}; +module_platform_driver(rzg3e_phy_usb3_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Renesas RZ/G3E USB3.0 PHY Driver"); +MODULE_AUTHOR("biju.das.jz@bp.renesas.com>"); --=20 2.43.0