Skip to content

Commit 3666970

Browse files
elkabloLorenzo Pieralisi
authored andcommitted
PCI: aardvark: Add PHY support
With recent proposed changes for U-Boot it is possible that bootloader won't initialize the PHY for this controller (currently the PHY is initialized regardless whether PCI is used in U-Boot, but with these proposed changes the PHY is initialized only on request). Since the mvebu-a3700-comphy driver by Miquèl Raynal supports enabling PCIe PHY, and since Linux' functionality should be independent on what bootloader did, add code for enabling generic PHY if found in device OF node. The mvebu-a3700-comphy driver does PHY powering via SMC calls to ARM Trusted Firmware. The corresponding code in ARM Trusted Firmware skips one register write which U-Boot does not: step 7 ("Enable TX"), see [1]. Instead ARM Trusted Firmware expects PCIe driver to do this step, probably because the register is in PCIe controller address space, instead of PHY address space. We therefore add this step into the advk_pcie_setup_hw function. [1] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/drivers/marvell/comphy/phy-comphy-3700.c?h=v2.3-rc2#n836 Link: https://lore.kernel.org/r/20200430080625.26070-8-pali@kernel.org Tested-by: Tomasz Maciej Nowak <tmn505@gmail.com> Signed-off-by: Marek Behún <marek.behun@nic.cz> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Rob Herring <robh@kernel.org> Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Cc: Miquèl Raynal <miquel.raynal@bootlin.com>
1 parent b2a5646 commit 3666970

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

‎drivers/pci/controller/pci-aardvark.c‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/kernel.h>
1717
#include <linux/pci.h>
1818
#include <linux/init.h>
19+
#include <linux/phy/phy.h>
1920
#include <linux/platform_device.h>
2021
#include <linux/msi.h>
2122
#include <linux/of_address.h>
@@ -104,6 +105,8 @@
104105
#define PCIE_CORE_CTRL2_STRICT_ORDER_ENABLE BIT(5)
105106
#define PCIE_CORE_CTRL2_OB_WIN_ENABLE BIT(6)
106107
#define PCIE_CORE_CTRL2_MSI_ENABLE BIT(10)
108+
#define PCIE_CORE_REF_CLK_REG (CONTROL_BASE_ADDR + 0x14)
109+
#define PCIE_CORE_REF_CLK_TX_ENABLE BIT(1)
107110
#define PCIE_MSG_LOG_REG (CONTROL_BASE_ADDR + 0x30)
108111
#define PCIE_ISR0_REG (CONTROL_BASE_ADDR + 0x40)
109112
#define PCIE_MSG_PM_PME_MASK BIT(7)
@@ -207,6 +210,7 @@ struct advk_pcie {
207210
int link_gen;
208211
struct pci_bridge_emul bridge;
209212
struct gpio_desc *reset_gpio;
213+
struct phy *phy;
210214
};
211215

212216
static inline void advk_writel(struct advk_pcie *pcie, u32 val, u64 reg)
@@ -358,6 +362,11 @@ static void advk_pcie_setup_hw(struct advk_pcie *pcie)
358362

359363
advk_pcie_issue_perst(pcie);
360364

365+
/* Enable TX */
366+
reg = advk_readl(pcie, PCIE_CORE_REF_CLK_REG);
367+
reg |= PCIE_CORE_REF_CLK_TX_ENABLE;
368+
advk_writel(pcie, reg, PCIE_CORE_REF_CLK_REG);
369+
361370
/* Set to Direct mode */
362371
reg = advk_readl(pcie, CTRL_CONFIG_REG);
363372
reg &= ~(CTRL_MODE_MASK << CTRL_MODE_SHIFT);
@@ -1041,6 +1050,62 @@ static irqreturn_t advk_pcie_irq_handler(int irq, void *arg)
10411050
return IRQ_HANDLED;
10421051
}
10431052

1053+
static void __maybe_unused advk_pcie_disable_phy(struct advk_pcie *pcie)
1054+
{
1055+
phy_power_off(pcie->phy);
1056+
phy_exit(pcie->phy);
1057+
}
1058+
1059+
static int advk_pcie_enable_phy(struct advk_pcie *pcie)
1060+
{
1061+
int ret;
1062+
1063+
if (!pcie->phy)
1064+
return 0;
1065+
1066+
ret = phy_init(pcie->phy);
1067+
if (ret)
1068+
return ret;
1069+
1070+
ret = phy_set_mode(pcie->phy, PHY_MODE_PCIE);
1071+
if (ret) {
1072+
phy_exit(pcie->phy);
1073+
return ret;
1074+
}
1075+
1076+
ret = phy_power_on(pcie->phy);
1077+
if (ret) {
1078+
phy_exit(pcie->phy);
1079+
return ret;
1080+
}
1081+
1082+
return 0;
1083+
}
1084+
1085+
static int advk_pcie_setup_phy(struct advk_pcie *pcie)
1086+
{
1087+
struct device *dev = &pcie->pdev->dev;
1088+
struct device_node *node = dev->of_node;
1089+
int ret = 0;
1090+
1091+
pcie->phy = devm_of_phy_get(dev, node, NULL);
1092+
if (IS_ERR(pcie->phy) && (PTR_ERR(pcie->phy) == -EPROBE_DEFER))
1093+
return PTR_ERR(pcie->phy);
1094+
1095+
/* Old bindings miss the PHY handle */
1096+
if (IS_ERR(pcie->phy)) {
1097+
dev_warn(dev, "PHY unavailable (%ld)\n", PTR_ERR(pcie->phy));
1098+
pcie->phy = NULL;
1099+
return 0;
1100+
}
1101+
1102+
ret = advk_pcie_enable_phy(pcie);
1103+
if (ret)
1104+
dev_err(dev, "Failed to initialize PHY (%d)\n", ret);
1105+
1106+
return ret;
1107+
}
1108+
10441109
static int advk_pcie_probe(struct platform_device *pdev)
10451110
{
10461111
struct device *dev = &pdev->dev;
@@ -1100,6 +1165,10 @@ static int advk_pcie_probe(struct platform_device *pdev)
11001165
else
11011166
pcie->link_gen = ret;
11021167

1168+
ret = advk_pcie_setup_phy(pcie);
1169+
if (ret)
1170+
return ret;
1171+
11031172
advk_pcie_setup_hw(pcie);
11041173

11051174
advk_sw_pci_bridge_init(pcie);

0 commit comments

Comments
 (0)