Skip to content

Commit

Permalink
phy: ralink: phy-mt7621-pci: use kernel clock APIS
Browse files Browse the repository at this point in the history
MT7621 SoC clock driver has already mainlined in
'commit 48df7a2 ("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.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
  • Loading branch information
paraka authored and intel-lab-lkp committed May 6, 2021
1 parent f383f95 commit fb00549
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions drivers/phy/ralink/phy-mt7621-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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)
Expand Down Expand Up @@ -62,15 +61,14 @@

#define RG_PE1_FRC_MSTCKDIV BIT(5)

#define XTAL_MASK GENMASK(8, 6)

#define MAX_PHYS 2

/**
* struct mt7621_pci_phy - Mt7621 Pcie PHY core
* @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'
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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));

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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, "sys_clk");
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);
Expand Down

0 comments on commit fb00549

Please sign in to comment.