Skip to contentSkip to conversation

phy: ralink: mt7621-pci-phy: some improvements

PATCH RESEND In review Sergio Paracuellos 4 participants 12 messages May 8, 2021 – May 14, 2021

Subsystems (6)
lore
Share & tools
lore

Sergio Paracuellos

author maintainer
#0 lore raw

v2 cover phy: ralink: mt7621-pci-phy: some improvements

Hi all,

This series contains some improvements in the pci phy driver for MT7621 SoCs.

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")'

Because of this we can update schema documentation and device tree to add related clock entries and avoid custom architecture code in favour of using the clock kernel framework to retrieve clock frequency needed to properly configure the PCIe related Phys.

After this changes there is no problem to properly enable this driver for COMPILE_TEST.

Configuration has also modified from 'tristate' to 'bool' depending on PCI_MT7621 which seems to have more sense.

Thanks in advance for your time.

Changes in v2 resed:
- Forgot to send the series to devicetree list. Sorry for inconvenience.

Changes in v2:
- Drop 'clock-names' property from device tree and binding doc sice only one clock is needed.
- Update driver code to don't get clock name as identifier for the clock but just use NULL.
- Add patch to fix a COMPILE_TEST reported issue because of the way printing of a pointer was being done. This patch was already send by its own[0] but to have all of this applied together I prefer to include it here.

Best regards,
Sergio Paracuellos

[0]: http://lists.infradead.org/pipermail/linux-phy/2021-May/000395.html

Sergio Paracuellos (6):
staging: mt7621-dts: use clock in pci phy nodes
dt-bindings: phy: mediatek,mt7621-pci-phy: add clock entries
phy: ralink: phy-mt7621-pci: use kernel clock APIS
phy: ralink: Kconfig: enable COMPILE_TEST on mt7621-pci-phy driver
phy: ralink: Kconfig: convert mt7621-pci-phy into 'bool'
phy: ralink: phy-mt7621-pci: properly print pointer address

 .../bindings/phy/mediatek,mt7621-pci-phy.yaml |  5 +++
 drivers/phy/ralink/Kconfig                    |  4 +-
 drivers/phy/ralink/phy-mt7621-pci.c           | 37 +++++++++++--------
 drivers/staging/mt7621-dts/mt7621.dtsi        |  2 +
 4 files changed, 31 insertions(+), 17 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH RESEND v2 1/6 staging: mt7621-dts: use clock in pci phy nodes

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")' Hence we can use the clock in pcie phy nodes to
be able to get it from there in driver code.

---
 drivers/staging/mt7621-dts/mt7621.dtsi | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/mt7621-dts/mt7621.dtsi +2 -0
index 9ee11adefa79..840ba0c3ffed 100644
@@ -548,12 +548,14 @@ pcie@2,0 {
 	pcie0_phy: pcie-phy@1e149000 {
 		compatible = "mediatek,mt7621-pci-phy";
 		reg = <0x1e149000 0x0700>;
+		clocks = <&sysc MT7621_CLK_XTAL>;
 		#phy-cells = <1>;
 	};
 
 	pcie2_phy: pcie-phy@1e14a000 {
 		compatible = "mediatek,mt7621-pci-phy";
 		reg = <0x1e14a000 0x0700>;
+		clocks = <&sysc MT7621_CLK_XTAL>;
 		#phy-cells = <1>;
 	};
 };
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH RESEND v2 2/6 dt-bindings: phy: mediatek,mt7621-pci-phy: add clock entries

In reply to Sergio Paracuellos

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")' Hence update schema with the add of the entries related to clock. Since until now things were not properly being done we mark also 'clock' as required in the binding since this will be now the only way to properly retrieve frequency to be able to make a correct configuration of the PCIe phy registers.

---
 .../devicetree/bindings/phy/mediatek,mt7621-pci-phy.yaml     | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/phy/mediatek,mt7621-pci-phy.yaml +5 -0
index 0ccaded3f245..29d4123323c2 100644
@@ -16,6 +16,9 @@ properties:
   reg:
     maxItems: 1
 
+  clocks:
+    maxItems: 1
+
   "#phy-cells":
     const: 1
     description: selects if the phy is dual-ported
@@ -23,6 +26,7 @@ properties:
 required:
   - compatible
   - reg
+  - clocks
   - "#phy-cells"
 
 additionalProperties: false
@@ -32,5 +36,6 @@ examples:
     pcie0_phy: pcie-phy@1e149000 {
       compatible = "mediatek,mt7621-pci-phy";
       reg = <0x1e149000 0x0700>;
+      clocks = <&sysc 0>;
       #phy-cells = <1>;
     };
Signature · 1 line
2.25.1
maintainer Acked-by on v2 2/6
#3 lore raw

Re: [PATCH RESEND v2 2/6] dt-bindings: phy: mediatek,mt7621-pci-phy: add clock entries

Quoted 8 lines · Sergio Paracuellos

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")' Hence update schema with the add of the entries related to clock. Since until now things were not properly being done we mark also 'clock' as required in the binding since this will be now the only way to properly retrieve frequency to be able to make a correct configuration of the PCIe phy registers.

Quoted 5 lines
---
 .../devicetree/bindings/phy/mediatek,mt7621-pci-phy.yaml     | 5 +++++
 1 file changed, 5 insertions(+)
author maintainer
#4 lore raw

PATCH RESEND v2 3/6 phy: ralink: phy-mt7621-pci: use kernel clock APIS

In reply to Sergio Paracuellos

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")' This allow us to properly use kernel clock apis to get
the clock frequency needed for the phy configuration instead of use custom architecture code to do the same.

---
 drivers/phy/ralink/phy-mt7621-pci.c | 33 +++++++++++++++++------------
 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/phy/ralink/phy-mt7621-pci.c +20 -13
index 753cb5bab930..f56ff10b0885 100644
@@ -5,6 +5,7 @@
  */
 
 #include <dt-bindings/phy/phy.h>
+#include <linux/clk.h>
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
 #include <linux/module.h>
@@ -14,8 +15,6 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/sys_soc.h>
-#include <mt7621.h>
-#include <ralink_regs.h>
 
 #define RG_PE1_PIPE_REG				0x02c
 #define RG_PE1_PIPE_RST				BIT(12)
@@ -62,8 +61,6 @@
 
 #define RG_PE1_FRC_MSTCKDIV			BIT(5)
 
-#define XTAL_MASK				GENMASK(8, 6)
-
 #define MAX_PHYS	2
 
 /**
@@ -71,6 +68,7 @@
  * @dev: pointer to device
  * @regmap: kernel regmap pointer
  * @phy: pointer to the kernel PHY device
+ * @sys_clk: pointer to the system XTAL clock
  * @port_base: base register
  * @has_dual_port: if the phy has dual ports.
  * @bypass_pipe_rst: mark if 'mt7621_bypass_pipe_rst'
@@ -80,6 +78,7 @@ struct mt7621_pci_phy {
 	struct device *dev;
 	struct regmap *regmap;
 	struct phy *phy;
+	struct clk *sys_clk;
 	void __iomem *port_base;
 	bool has_dual_port;
 	bool bypass_pipe_rst;
@@ -116,12 +115,14 @@ static void mt7621_bypass_pipe_rst(struct mt7621_pci_phy *phy)
 	}
 }
 
-static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy)
+static int mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy)
 {
 	struct device *dev = phy->dev;
-	u32 xtal_mode;
+	unsigned long clk_rate;
 
-	xtal_mode = FIELD_GET(XTAL_MASK, rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0));
+	clk_rate = clk_get_rate(phy->sys_clk);
+	if (!clk_rate)
+		return -EINVAL;
 
 	/* Set PCIe Port PHY to disable SSC */
 	/* Debug Xtal Type */
@@ -139,13 +140,13 @@ static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy)
 			       RG_PE1_PHY_EN, RG_PE1_FRC_PHY_EN);
 	}
 
-	if (xtal_mode <= 5 && xtal_mode >= 3) { /* 40MHz Xtal */
+	if (clk_rate == 40000000) { /* 40MHz Xtal */
 		/* Set Pre-divider ratio (for host mode) */
 		mt7621_phy_rmw(phy, RG_PE1_H_PLL_REG, RG_PE1_H_PLL_PREDIV,
 			       FIELD_PREP(RG_PE1_H_PLL_PREDIV, 0x01));
 
 		dev_dbg(dev, "Xtal is 40MHz\n");
-	} else if (xtal_mode >= 6) { /* 25MHz Xal */
+	} else if (clk_rate == 25000000) { /* 25MHz Xal */
 		mt7621_phy_rmw(phy, RG_PE1_H_PLL_REG, RG_PE1_H_PLL_PREDIV,
 			       FIELD_PREP(RG_PE1_H_PLL_PREDIV, 0x00));
 
@@ -196,13 +197,15 @@ static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy)
 	mt7621_phy_rmw(phy, RG_PE1_H_PLL_BR_REG, RG_PE1_H_PLL_BR,
 		       FIELD_PREP(RG_PE1_H_PLL_BR, 0x00));
 
-	if (xtal_mode <= 5 && xtal_mode >= 3) { /* 40MHz Xtal */
+	if (clk_rate == 40000000) { /* 40MHz Xtal */
 		/* set force mode enable of da_pe1_mstckdiv */
 		mt7621_phy_rmw(phy, RG_PE1_MSTCKDIV_REG,
 			       RG_PE1_MSTCKDIV | RG_PE1_FRC_MSTCKDIV,
 			       FIELD_PREP(RG_PE1_MSTCKDIV, 0x01) |
 			       RG_PE1_FRC_MSTCKDIV);
 	}
+
+	return 0;
 }
 
 static int mt7621_pci_phy_init(struct phy *phy)
@@ -212,9 +215,7 @@ static int mt7621_pci_phy_init(struct phy *phy)
 	if (mphy->bypass_pipe_rst)
 		mt7621_bypass_pipe_rst(mphy);
 
-	mt7621_set_phy_for_ssc(mphy);
-
-	return 0;
+	return mt7621_set_phy_for_ssc(mphy);
 }
 
 static int mt7621_pci_phy_power_on(struct phy *phy)
@@ -324,6 +325,12 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev)
 		return PTR_ERR(phy->phy);
 	}
 
+	phy->sys_clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(phy->sys_clk)) {
+		dev_err(dev, "failed to get phy clock\n");
+		return PTR_ERR(phy->sys_clk);
+	}
+
 	phy_set_drvdata(phy->phy, phy);
 
 	provider = devm_of_phy_provider_register(dev, mt7621_pcie_phy_of_xlate);
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH RESEND v2 4/6 phy: ralink: Kconfig: enable COMPILE_TEST on mt7621-pci-phy driver

In reply to Sergio Paracuellos

After use the clock apis and avoid custom architecture code this driver can properly be enabled for COMPILE_TEST.

---
 drivers/phy/ralink/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/ralink/Kconfig +1 -1
index ecc309ba9fee..c2373b30b8a6 100644
@@ -4,7 +4,7 @@
 #
 config PHY_MT7621_PCI
 	tristate "MediaTek MT7621 PCI PHY Driver"
-	depends on RALINK && OF
+	depends on (RALINK && OF) || COMPILE_TEST
 	select GENERIC_PHY
 	select REGMAP_MMIO
 	help
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH RESEND v2 5/6 phy: ralink: Kconfig: convert mt7621-pci-phy into 'bool'

In reply to Sergio Paracuellos

Make dependent on PCI_MT7621 configuration option and mark this pci phy configuration as bool which has more sense.

---
 drivers/phy/ralink/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/ralink/Kconfig +2 -2
index c2373b30b8a6..ed0c71eff2c4 100644
@@ -3,8 +3,8 @@
 # PHY drivers for Ralink platforms.
 #
 config PHY_MT7621_PCI
-	tristate "MediaTek MT7621 PCI PHY Driver"
-	depends on (RALINK && OF) || COMPILE_TEST
+	bool "MediaTek MT7621 PCI PHY Driver"
+	depends on (RALINK && OF && PCI_MT7621) || COMPILE_TEST
 	select GENERIC_PHY
 	select REGMAP_MMIO
 	help
Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH RESEND v2 6/6 phy: ralink: phy-mt7621-pci: properly print pointer address

In reply to Sergio Paracuellos

The way of printing the pointer address for the 'port_base' address got into compile warnings on some architectures [-Wpointer-to-int-cast]. Instead of use '%08x' and cast to an 'unsigned int' just make use of '%px' and avoid the cast. To avoid not really needed driver verbosity on normal behaviour change also from 'dev_info' to 'dev_dbg'.

Fixes d87da32372a0 ("phy: ralink: Add PHY driver for MT7621 PCIe PHY")
---
 drivers/phy/ralink/phy-mt7621-pci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/ralink/phy-mt7621-pci.c +2 -2
index f56ff10b0885..242c5d8b8635 100644
@@ -273,8 +273,8 @@ static struct phy *mt7621_pcie_phy_of_xlate(struct device *dev,
 
 	mt7621_phy->has_dual_port = args->args[0];
 
-	dev_info(dev, "PHY for 0x%08x (dual port = %d)\n",
-		 (unsigned int)mt7621_phy->port_base, mt7621_phy->has_dual_port);
+	dev_dbg(dev, "PHY for 0x%px (dual port = %d)\n",
+		mt7621_phy->port_base, mt7621_phy->has_dual_port);
 
 	return mt7621_phy->phy;
 }
Signature · 1 line
2.25.1
maintainer
#8 lore raw
In reply to Sergio Paracuellos
Quoted 13 lines · Sergio Paracuellos

Hi all,

This series contains some improvements in the pci phy driver for MT7621 SoCs.

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")'

Because of this we can update schema documentation and device tree to add related clock entries and avoid custom architecture code in favour of using the clock kernel framework to retrieve clock frequency needed to properly configure the PCIe related Phys.

Quoted 5 lines

After this changes there is no problem to properly enable this driver for COMPILE_TEST.

Configuration has also modified from 'tristate' to 'bool' depending on PCI_MT7621 which seems to have more sense.

Applied 2-6, thanks

Signature · 1 line
~Vinod
author maintainer
#9 lore raw
Quoted 15 lines · Vinod Koul
Quoted 13 lines · Sergio Paracuellos

Hi all,

This series contains some improvements in the pci phy driver for MT7621 SoCs.

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")'

Because of this we can update schema documentation and device tree to add related clock entries and avoid custom architecture code in favour of using the clock kernel framework to retrieve clock frequency needed to properly configure the PCIe related Phys.

Quoted 7 lines
Quoted 5 lines

After this changes there is no problem to properly enable this driver for COMPILE_TEST.

Configuration has also modified from 'tristate' to 'bool' depending on PCI_MT7621 which seems to have more sense.

Applied 2-6, thanks

Thanks, Vinod.

Greg, can you take patch 1 through your tree?

Best regards,
Sergio Paracuellos

Quoted 3 lines

--
~Vinod

maintainer
#10 lore raw
Quoted 19 lines · Sergio Paracuellos
Quoted 18 lines · Vinod Koul
Quoted 16 lines · Sergio Paracuellos

Hi all,

This series contains some improvements in the pci phy driver for MT7621 SoCs.

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")'

Because of this we can update schema documentation and device tree to add related clock entries and avoid custom architecture code in favour of using the clock kernel framework to retrieve clock frequency needed to properly configure the PCIe related Phys.

After this changes there is no problem to properly enable this driver for COMPILE_TEST.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Configuration has also modified from 'tristate' to 'bool' depending on PCI_MT7621 which seems to have more sense.

Applied 2-6, thanks

Thanks, Vinod.

Greg, can you take patch 1 through your tree?

Sure, can you resend it?

thanks,

greg k-h

author maintainer
#11 lore raw
Quoted 24 lines · Greg KH
Quoted 22 lines · Sergio Paracuellos
Quoted 21 lines · Vinod Koul
Quoted 18 lines · Sergio Paracuellos

Hi all,

This series contains some improvements in the pci phy driver for MT7621 SoCs.

MT7621 SoC clock driver has already mainlined in
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")'

Because of this we can update schema documentation and device tree to add related clock entries and avoid custom architecture code in favour of using the clock kernel framework to retrieve clock frequency needed to properly configure the PCIe related Phys.

After this changes there is no problem to properly enable this driver for COMPILE_TEST.

Configuration has also modified from 'tristate' to 'bool' depending on PCI_MT7621 which seems to have more sense.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Applied 2-6, thanks

Thanks, Vinod.

Greg, can you take patch 1 through your tree?

Sure, can you resend it?

Thanks, I have just resent it.

Quoted 4 lines

thanks,

greg k-h

Best regards,
Sergio Paracuellos