Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2398954pxb; Fri, 17 Sep 2021 08:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCjUbeOO5+Ua/Gbu6gZbRC82yrW4OhlJEPMa4i2jkzlZqO38SrWrLfJ7pkg5swAUe7yxVk X-Received: by 2002:a92:2a10:: with SMTP id r16mr8489115ile.309.1631894177536; Fri, 17 Sep 2021 08:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631894177; cv=none; d=google.com; s=arc-20160816; b=Kqo9+SNFEPhBSGSaTyLBHdLvvhWP6kBy7O8AfWozyMTeK5K3wxCUADorGOzSuHOSO2 HzDgOfalXE6Uvg+SDnApqDmRSQPAcsQG4Z2bmTwguM/nAsvMBRcItKd6ragEb4upwgay lQlDY3i61Yo+i1e5/Of4ZTB0XkgLD+MouRkY/HTRng5C8vwUDypgabpLnLerSTMx3szU +ziveLt4DJ90EPpP6SVMm7akcWaLyRftOHl6H/nC7hTroPSxCuvRJKelOmECmxuOhjWO 4ulYQGEl3dwcYiOVUNR9GkuUKGqurGf/8Q6RDUX3JytsbUez4Ok+3VmIkUgbwz82qhkm xdsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=FpSx1P1ztfw4Ht9cePdwGxOqWxGVw2lycADFYpuiT0A=; b=uRl/2kUlwnGDrgWGSeSqJEIK4v/w5/kxIOXeL1LqQUaLYaBB8kPi0W0lrqE28AxUvN 5bKyqNFS3VP0gcBpv73fTibqnL98ob3KkCifV0BGeDUH1vgW8q0PdQU6/8b5CTju/B1s DCZT3sf8sQvR5C12l/vIxX0fYhhw+Cnu5nN+g62ignvBovFLu088jJ20vRKqMtSTwe8U EPQm8Vh/uaPofM7pu6MopWtRDorQsoYEOn3DeUfYCfPz64TW0TeqQZ94jK8mban6johB K5csINwzDy2yBv0V+HQfmlAEgw2Jdg1rl858dlQB8dCf0QMcWHHZ+VL4DzA4u/rQYHtq W50A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si6499365ilu.13.2021.09.17.08.56.05; Fri, 17 Sep 2021 08:56:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242857AbhIQCz6 (ORCPT + 99 others); Thu, 16 Sep 2021 22:55:58 -0400 Received: from inva020.nxp.com ([92.121.34.13]:47714 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242906AbhIQCzx (ORCPT ); Thu, 16 Sep 2021 22:55:53 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id AC5971A12B8; Fri, 17 Sep 2021 04:54:30 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 3EEC21A0BBB; Fri, 17 Sep 2021 04:54:30 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id A0423183AC4C; Fri, 17 Sep 2021 10:54:28 +0800 (+08) From: Richard Zhu To: l.stach@pengutronix.de, kishon@ti.com, vkoul@kernel.org, robh@kernel.org, galak@kernel.crashing.org, shawnguo@kernel.org Cc: linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com, Richard Zhu Subject: [PATCH 4/4] phy: freescale: pcie: initialize the imx8 pcie standalone phy driver Date: Fri, 17 Sep 2021 10:31:03 +0800 Message-Id: <1631845863-24249-5-git-send-email-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1631845863-24249-1-git-send-email-hongxing.zhu@nxp.com> References: <1631845863-24249-1-git-send-email-hongxing.zhu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the standalone i.MX8 PCIe PHY driver. Some reset bits should be manipulated between PHY configurations and status check(internal PLL is locked or not). So, do the PHY configuration in the phy_calibrate(). And check the PHY is ready or not in the phy_init(). Signed-off-by: Richard Zhu --- drivers/phy/freescale/Kconfig | 9 ++ drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-fsl-imx8-pcie.c | 167 ++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 drivers/phy/freescale/phy-fsl-imx8-pcie.c diff --git a/drivers/phy/freescale/Kconfig b/drivers/phy/freescale/Kconfig index 320630ffe3cd..da078a676fbc 100644 --- a/drivers/phy/freescale/Kconfig +++ b/drivers/phy/freescale/Kconfig @@ -14,3 +14,12 @@ config PHY_MIXEL_MIPI_DPHY help Enable this to add support for the Mixel DSI PHY as found on NXP's i.MX8 family of SOCs. + +config PHY_FSL_IMX8_PCIE + tristate "Freescale i.MX8 PCIE PHY" + depends on OF && HAS_IOMEM + select GENERIC_PHY + default ARCH_MXC + help + Enable this to add support for the PCIE PHY as found on i.MX8 + family of SOCs. diff --git a/drivers/phy/freescale/Makefile b/drivers/phy/freescale/Makefile index 1d02e3869b45..9fd467b58621 100644 --- a/drivers/phy/freescale/Makefile +++ b/drivers/phy/freescale/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_PHY_FSL_IMX8MQ_USB) += phy-fsl-imx8mq-usb.o obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-fsl-imx8-mipi-dphy.o +obj-$(CONFIG_PHY_FSL_IMX8_PCIE) += phy-fsl-imx8-pcie.o diff --git a/drivers/phy/freescale/phy-fsl-imx8-pcie.c b/drivers/phy/freescale/phy-fsl-imx8-pcie.c new file mode 100644 index 000000000000..ff47d6b83686 --- /dev/null +++ b/drivers/phy/freescale/phy-fsl-imx8-pcie.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 NXP + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define IMX8MM_PCIE_PHY_CMN_REG061 0x184 +#define ANA_PLL_CLK_OUT_TO_EXT_IO_EN BIT(0) +#define IMX8MM_PCIE_PHY_CMN_REG062 0x188 +#define ANA_PLL_CLK_OUT_TO_EXT_IO_SEL BIT(3) +#define IMX8MM_PCIE_PHY_CMN_REG063 0x18C +#define AUX_PLL_REFCLK_SEL_SYS_PLL GENMASK(7, 6) +#define IMX8MM_PCIE_PHY_CMN_REG064 0x190 +#define ANA_AUX_RX_TX_SEL_TX BIT(7) +#define ANA_AUX_RX_TERM_GND_EN BIT(3) +#define ANA_AUX_TX_TERM BIT(2) +#define IMX8MM_PCIE_PHY_CMN_REG065 0x194 +#define ANA_AUX_RX_TERM (BIT(7) | BIT(4)) +#define ANA_AUX_TX_LVL GENMASK(3, 0) +#define IMX8MM_PCIE_PHY_CMN_REG75 0x1D4 +#define PCIE_PHY_CMN_REG75_PLL_DONE 0x3 +#define PCIE_PHY_TRSV_REG5 0x414 +#define PCIE_PHY_TRSV_REG5_GEN1_DEEMP 0x2D +#define PCIE_PHY_TRSV_REG6 0x418 +#define PCIE_PHY_TRSV_REG6_GEN2_DEEMP 0xF + +struct imx8_pcie_phy { + u32 refclk_pad_mode; + void __iomem *base; + struct clk *clk; + struct phy *phy; +}; + +static int imx8_pcie_phy_init(struct phy *phy) +{ + int ret; + u32 val; + struct imx8_pcie_phy *imx8_phy = phy_get_drvdata(phy); + + ret = readl_poll_timeout(imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG75, + val, val == PCIE_PHY_CMN_REG75_PLL_DONE, + 10, 20000); + return ret; +} + +static int imx8_pcie_phy_cal(struct phy *phy) +{ + u32 value, pad_mode; + struct imx8_pcie_phy *imx8_phy = phy_get_drvdata(phy); + + pad_mode = imx8_phy->refclk_pad_mode; + if (pad_mode == IMX8_PCIE_REFCLK_PAD_INPUT) { + /* Configure the pad as input */ + value = readl(imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG061); + writel(value & ~ANA_PLL_CLK_OUT_TO_EXT_IO_EN, + imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG061); + } else if (pad_mode == IMX8_PCIE_REFCLK_PAD_OUTPUT) { + /* Configure the PHY to output the refclock via pad */ + writel(ANA_PLL_CLK_OUT_TO_EXT_IO_EN, + imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG061); + writel(ANA_PLL_CLK_OUT_TO_EXT_IO_SEL, + imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG062); + writel(AUX_PLL_REFCLK_SEL_SYS_PLL, + imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG063); + value = ANA_AUX_RX_TX_SEL_TX | ANA_AUX_TX_TERM; + writel(value | ANA_AUX_RX_TERM_GND_EN, + imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG064); + writel(ANA_AUX_RX_TERM | ANA_AUX_TX_LVL, + imx8_phy->base + IMX8MM_PCIE_PHY_CMN_REG065); + } + + /* Tune PHY de-emphasis setting to pass PCIe compliance. */ + writel(PCIE_PHY_TRSV_REG5_GEN1_DEEMP, + imx8_phy->base + PCIE_PHY_TRSV_REG5); + writel(PCIE_PHY_TRSV_REG6_GEN2_DEEMP, + imx8_phy->base + PCIE_PHY_TRSV_REG6); + + return 0; +} + +static int imx8_pcie_phy_power_on(struct phy *phy) +{ + struct imx8_pcie_phy *imx8_phy = phy_get_drvdata(phy); + + return clk_prepare_enable(imx8_phy->clk); +} + +static int imx8_pcie_phy_power_off(struct phy *phy) +{ + struct imx8_pcie_phy *imx8_phy = phy_get_drvdata(phy); + + clk_disable_unprepare(imx8_phy->clk); + + return 0; +} + +static const struct phy_ops imx8_pcie_phy_ops = { + .init = imx8_pcie_phy_init, + .calibrate = imx8_pcie_phy_cal, + .power_on = imx8_pcie_phy_power_on, + .power_off = imx8_pcie_phy_power_off, + .owner = THIS_MODULE, +}; + +static int imx8_pcie_phy_probe(struct platform_device *pdev) +{ + struct phy_provider *phy_provider; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct imx8_pcie_phy *imx8_phy; + struct resource *res; + + imx8_phy = devm_kzalloc(dev, sizeof(*imx8_phy), GFP_KERNEL); + if (!imx8_phy) + return -ENOMEM; + + /* get PHY refclk pad mode */ + of_property_read_u32(np, "fsl,refclk-pad-mode", + &imx8_phy->refclk_pad_mode); + + imx8_phy->clk = devm_clk_get(dev, "phy"); + if (IS_ERR(imx8_phy->clk)) { + dev_err(dev, "failed to get imx pcie phy clock\n"); + return PTR_ERR(imx8_phy->clk); + } + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + imx8_phy->base = devm_ioremap_resource(dev, res); + if (IS_ERR(imx8_phy->base)) + return PTR_ERR(imx8_phy->base); + + imx8_phy->phy = devm_phy_create(dev, NULL, &imx8_pcie_phy_ops); + if (IS_ERR(imx8_phy->phy)) + return PTR_ERR(imx8_phy->phy); + + phy_set_drvdata(imx8_phy->phy, imx8_phy); + + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(phy_provider); +} + +static const struct of_device_id imx8_pcie_phy_of_match[] = { + {.compatible = "fsl,imx8mm-pcie-phy",}, + { }, +}; +MODULE_DEVICE_TABLE(of, imx8_pcie_phy_of_match); + +static struct platform_driver imx8_pcie_phy_driver = { + .probe = imx8_pcie_phy_probe, + .driver = { + .name = "imx8-pcie-phy", + .of_match_table = imx8_pcie_phy_of_match, + } +}; +module_platform_driver(imx8_pcie_phy_driver); + +MODULE_DESCRIPTION("FSL IMX8 PCIE PHY driver"); +MODULE_LICENSE("GPL"); -- 2.25.1