U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: "Tom Rini" <trini@konsulko.com>,
	"Lukasz Majewski" <lukma@denx.de>,
	"Sean Anderson" <seanga2@gmail.com>,
	"Ryder Lee" <ryder.lee@mediatek.com>,
	"Weijie Gao" <weijie.gao@mediatek.com>,
	"Chunfeng Yun" <chunfeng.yun@mediatek.com>,
	GSS_MTK_Uboot_upstream <GSS_MTK_Uboot_upstream@mediatek.com>,
	"Heiko Schocher" <hs@denx.de>, "Peng Fan" <peng.fan@nxp.com>,
	"Jaehoon Chung" <jh80.chung@samsung.com>,
	"Joe Hershberger" <joe.hershberger@ni.com>,
	"Ramon Fried" <rfried.dev@gmail.com>,
	"Jagan Teki" <jagan@amarulasolutions.com>,
	"Christian Marangi" <ansuelsmth@gmail.com>,
	"Sam Shih" <sam.shih@mediatek.com>,
	"Francois Berder" <fberder@outlook.fr>,
	"Simon Glass" <sjg@chromium.org>,
	"Julien Masson" <jmasson@baylibre.com>,
	"Peter Robinson" <pbrobinson@gmail.com>,
	"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
	"Bo-Cun Chen" <bc-bocun.chen@mediatek.com>,
	"This contributor prefers not to receive mails"
	<noreply@example.com>, "Michal Simek" <michal.simek@amd.com>,
	"John Crispin" <john@phrozen.org>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Mason Huo" <mason.huo@starfivetech.com>,
	"Stefan Roese" <sr@denx.de>, "Sumit Garg" <sumit.garg@linaro.org>,
	"Mark Kettenis" <kettenis@openbsd.org>,
	"Sergei Antonov" <saproj@gmail.com>,
	"Mayuresh Chitale" <mchitale@ventanamicro.com>,
	"SkyLake.Huang" <skylake.huang@mediatek.com>,
	"Nicolò Veronese" <nicveronese@gmail.com>,
	u-boot@lists.denx.de
Subject: [PATCH 01/11] phy: phy-mtk-tphy: add support for phy type switch
Date: Wed,  5 Jun 2024 21:02:08 +0200	[thread overview]
Message-ID: <20240605190220.17616-2-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20240605190220.17616-1-ansuelsmth@gmail.com>

Add support for PHY type switch via the mediatek topmisc syscon.

This is needed on mt7981 to make the PCIe correctly work and display
LinkUp.

Follow the same implementation done on Linux kernel with the usage of
the mediatek,syscon-type property.

Example:

u3port0: usb-phy@11e10700 {
	reg = <0x11e10700 0x900>;
	clocks = <&topckgen CK_TOP_USB3_PHY_SEL>;
	clock-names = "ref";
	#phy-cells = <1>;
	mediatek,syscon-type = <&topmisc 0x218 0>;
	status = "okay";
};

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/phy/phy-mtk-tphy.c | 80 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index ea9edf212c6..24938c8d2e3 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -11,6 +11,8 @@
 #include <generic-phy.h>
 #include <malloc.h>
 #include <mapmem.h>
+#include <regmap.h>
+#include <syscon.h>
 #include <asm/io.h>
 #include <dm/device_compat.h>
 #include <dm/devres.h>
@@ -216,6 +218,14 @@
 #define ANA_EQ_EYE_CTRL_SIGNAL5		0xdc
 #define RG_CDR_BIRLTD0_GEN3_MSK		GENMASK(4, 0)
 
+/* PHY switch between pcie/usb3/sgmii/sata */
+#define USB_PHY_SWITCH_CTRL	0x0
+#define RG_PHY_SW_TYPE		GENMASK(3, 0)
+#define RG_PHY_SW_PCIE		0x0
+#define RG_PHY_SW_USB3		0x1
+#define RG_PHY_SW_SGMII		0x2
+#define RG_PHY_SW_SATA		0x3
+
 enum mtk_phy_version {
 	MTK_TPHY_V1 = 1,
 	MTK_TPHY_V2,
@@ -258,6 +268,10 @@ struct mtk_phy_instance {
 	u32 index;
 	u32 type;
 
+	struct regmap *type_sw;
+	u32 type_sw_reg;
+	u32 type_sw_index;
+
 	u32 eye_vrt;
 	u32 eye_term;
 	u32 discth;
@@ -617,6 +631,67 @@ static void u2_phy_props_set(struct mtk_tphy *tphy,
 				FIELD_PREP(PA6_RG_U2_PRE_EMP, instance->pre_emphasis));
 }
 
+/* type switch for usb3/pcie/sgmii/sata */
+static int phy_type_syscon_get(struct udevice *dev, struct mtk_phy_instance *instance,
+			       ofnode dn)
+{
+	struct ofnode_phandle_args args;
+	int err;
+
+	if (!ofnode_read_bool(dn, "mediatek,syscon-type"))
+		return 0;
+
+	err = ofnode_parse_phandle_with_args(dn, "mediatek,syscon-type",
+					     NULL, 2, 0, &args);
+	if (err)
+		return err;
+
+	instance->type_sw_reg = args.args[0];
+	instance->type_sw_index = args.args[1] & 0x3; /* <=3 */
+	instance->type_sw = syscon_node_to_regmap(args.node);
+	if (IS_ERR(instance->type_sw))
+		return PTR_ERR(instance->type_sw);
+
+	debug("phy-%s.%d: type_sw - reg %#x, index %d\n",
+	      dev->name, instance->index, instance->type_sw_reg,
+	      instance->type_sw_index);
+
+	return 0;
+}
+
+static int phy_type_set(struct mtk_phy_instance *instance)
+{
+	int type;
+	u32 offset;
+
+	if (!instance->type_sw)
+		return 0;
+
+	switch (instance->type) {
+	case PHY_TYPE_USB3:
+		type = RG_PHY_SW_USB3;
+		break;
+	case PHY_TYPE_PCIE:
+		type = RG_PHY_SW_PCIE;
+		break;
+	case PHY_TYPE_SGMII:
+		type = RG_PHY_SW_SGMII;
+		break;
+	case PHY_TYPE_SATA:
+		type = RG_PHY_SW_SATA;
+		break;
+	case PHY_TYPE_USB2:
+	default:
+		return 0;
+	}
+
+	offset = instance->type_sw_index * BITS_PER_BYTE;
+	regmap_update_bits(instance->type_sw, instance->type_sw_reg,
+			   RG_PHY_SW_TYPE << offset, type << offset);
+
+	return 0;
+}
+
 static int mtk_phy_init(struct phy *phy)
 {
 	struct mtk_tphy *tphy = dev_get_priv(phy->dev);
@@ -747,6 +822,7 @@ static int mtk_phy_xlate(struct phy *phy,
 	}
 
 	phy_parse_property(tphy, instance);
+	phy_type_set(instance);
 
 	return 0;
 }
@@ -808,6 +884,10 @@ static int mtk_tphy_probe(struct udevice *dev)
 						     &instance->da_ref_clk);
 		if (err)
 			return err;
+
+		err = phy_type_syscon_get(dev, instance, subnode);
+		if (err)
+			return err;
 	}
 
 	return 0;
-- 
2.43.0


  reply	other threads:[~2024-06-05 19:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 19:02 [PATCH 00/11] mediatek: cumulative trivial fix for OF_UPSTREAM support Christian Marangi
2024-06-05 19:02 ` Christian Marangi [this message]
2024-06-05 19:02 ` [PATCH 02/11] pci: mediatek: add PCIe controller support for filogic silicon Christian Marangi
2024-06-05 19:02 ` [PATCH 03/11] spi: mtk_spim: add support for upstream mediatek, spi-ipm compatible Christian Marangi
2024-06-05 19:02 ` [PATCH 04/11] net: mediatek: handle alternative name for pn_swap property Christian Marangi
2024-06-05 19:02 ` [PATCH 05/11] i2c: mediatek: add support for optional arb and pmic clock Christian Marangi
2024-06-06  4:27   ` Heiko Schocher
2024-06-05 19:02 ` [PATCH 06/11] serial: mediatek: add support for bus clock and enable it Christian Marangi
2024-06-05 19:02 ` [PATCH 07/11] serial: mediatek: add special handling for highspeed and linux compat Christian Marangi
2024-06-05 19:02 ` [PATCH 08/11] mmc: mediatek: add support for upstream linux clock and property Christian Marangi
2024-06-05 19:02 ` [PATCH 09/11] clk: mediatek: mt7981: support alternative compatible for fixed-plls Christian Marangi
2024-06-05 19:02 ` [PATCH 10/11] pinctrl: mediatek: add support for gpio-controller property in root node Christian Marangi
2024-06-05 19:02 ` [PATCH 11/11] pinctrl: mediatek: mt7981: init device before relocation Christian Marangi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240605190220.17616-2-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=GSS_MTK_Uboot_upstream@mediatek.com \
    --cc=bc-bocun.chen@mediatek.com \
    --cc=chunfeng.yun@mediatek.com \
    --cc=fberder@outlook.fr \
    --cc=hs@denx.de \
    --cc=jagan@amarulasolutions.com \
    --cc=jh80.chung@samsung.com \
    --cc=jmasson@baylibre.com \
    --cc=joe.hershberger@ni.com \
    --cc=john@phrozen.org \
    --cc=kettenis@openbsd.org \
    --cc=lukma@denx.de \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=mason.huo@starfivetech.com \
    --cc=mchitale@ventanamicro.com \
    --cc=michal.simek@amd.com \
    --cc=nicveronese@gmail.com \
    --cc=noreply@example.com \
    --cc=pbrobinson@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=rfried.dev@gmail.com \
    --cc=ryder.lee@mediatek.com \
    --cc=sam.shih@mediatek.com \
    --cc=saproj@gmail.com \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=skylake.huang@mediatek.com \
    --cc=sr@denx.de \
    --cc=sumit.garg@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=weijie.gao@mediatek.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox