Re: [PATCH v4 4/4] PCI: imx6: Add support for i.MX8MQ
From: Lucas Stach
Date: Tue Jan 08 2019 - 03:23:35 EST
Am Freitag, den 04.01.2019, 08:53 -0800 schrieb Andrey Smirnov:
> Add code needed to support i.MX8MQ variant.
>
> > Cc: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
> > Cc: Fabio Estevam <fabio.estevam@xxxxxxx>
> > Cc: Chris Healy <cphealy@xxxxxxxxx>
> > Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> > Cc: Leonard Crestez <leonard.crestez@xxxxxxx>
> > Cc: "A.s. Dong" <aisheng.dong@xxxxxxx>
> > Cc: Richard Zhu <hongxing.zhu@xxxxxxx>
> > Cc: Rob Herring <robh@xxxxxxxxxx>,
> > Cc: devicetree@xxxxxxxxxxxxxxx,
> Cc: linux-imx@xxxxxxx
> Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Cc: linux-pci@xxxxxxxxxxxxxxx
> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> ---
> Â.../bindings/pci/fsl,imx6q-pcie.txtÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ3 +-
> Âdrivers/pci/controller/dwc/KconfigÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ4 +-
> Âdrivers/pci/controller/dwc/pci-imx6.cÂÂÂÂÂÂÂÂÂ| 77 ++++++++++++++++++-
> Â3 files changed, 79 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt
> index d514c1f2365f..920ca93870a8 100644
> --- a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt
> +++ b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt
> @@ -9,6 +9,7 @@ Required properties:
> > Â - "fsl,imx6sx-pcie",
> > Â - "fsl,imx6qp-pcie"
> > Â - "fsl,imx7d-pcie"
> > + - "fsl,imx8mq-pcie"
> Â- reg: base address and length of the PCIe controller
> Â- interrupts: A list of interrupt outputs of the controller. Must contain an
> ÂÂÂentry for each entry in the interrupt-names property.
> @@ -45,7 +46,7 @@ Additional required properties for imx6sx-pcie:
> ÂÂÂPCIE_PHY power domains
> Â- power-domain-names: Must be "pcie", "pcie_phy"
> Â
> -Additional required properties for imx7d-pcie:
> +Additional required properties for imx7d-pcie and imx8mq-pcie:
> Â- power-domains: Must be set to a phandle pointing to PCIE_PHY power domain
> Â- resets: Must contain phandles to PCIe-related reset lines exposed by SRC
> ÂÂÂIP block
> diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig
> index 6aafec3fad00..83ea318ad989 100644
> --- a/drivers/pci/controller/dwc/Kconfig
> +++ b/drivers/pci/controller/dwc/Kconfig
> @@ -89,8 +89,8 @@ config PCI_EXYNOS
> > Â select PCIE_DW_HOST
> Â
> Âconfig PCI_IMX6
> > - bool "Freescale i.MX6/7 PCIe controller"
> > - depends on SOC_IMX6Q || SOC_IMX7D || (ARM && COMPILE_TEST)
> > + bool "Freescale i.MX6/7/8 PCIe controller"
> > + depends on SOC_IMX6Q || SOC_IMX7D || (ARM64 && ARCH_MXC) || ((ARM || ARM64) && COMPILE_TEST)
> > Â depends on PCI_MSI_IRQ_DOMAIN
> > Â select PCIE_DW_HOST
> Â
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 75ee0cd7af3b..dd9d8732f6ba 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -8,6 +8,7 @@
> > Â * Author: Sean Cross <xobs@xxxxxxxxxx>
> Â */
> Â
> +#include <linux/bitfield.h>
> Â#include <linux/clk.h>
> Â#include <linux/delay.h>
> Â#include <linux/gpio.h>
> @@ -32,6 +33,12 @@
> Â
> Â#include "pcie-designware.h"
> Â
> > +#define IMX8MQ_GPR_PCIE_REF_USE_PAD BIT(9)
> > +#define IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN BIT(10)
> > +#define IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE BIT(11)
> > +#define IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE GENMASK(11, 8)
> > +#define IMX8MQ_PCIE2_BASE_ADDR 0x33c00000
> +
> > Â#define to_imx6_pcie(x) dev_get_drvdata((x)->dev)
> Â
> Âenum imx6_pcie_variants {
> @@ -39,6 +46,7 @@ enum imx6_pcie_variants {
> > Â IMX6SX,
> > Â IMX6QP,
> > Â IMX7D,
> > + IMX8MQ,
> Â};
> Â
> > Â#define IMX6_PCIE_FLAG_IMX6_PHY BIT(0)
> @@ -58,6 +66,7 @@ struct imx6_pcie {
> > > Â struct clk *pcie_inbound_axi;
> > > Â struct clk *pcie;
> > > Â struct regmap *iomuxc_gpr;
> > > + u32 controller_id;
> > > Â struct reset_control *pciephy_reset;
> > > Â struct reset_control *apps_reset;
> > > Â struct reset_control *turnoff_reset;
> @@ -276,6 +285,7 @@ static void imx6_pcie_reset_phy(struct imx6_pcie *imx6_pcie)
> > Â pcie_phy_write(imx6_pcie, PHY_RX_OVRD_IN_LO, tmp);
> Â}
> Â
> +#ifdef CONFIG_ARM
> Â/*ÂÂAdded for PCI abort handling */
> Âstatic int imx6q_pcie_abort_handler(unsigned long addr,
> > Â unsigned int fsr, struct pt_regs *regs)
> @@ -309,6 +319,7 @@ static int imx6q_pcie_abort_handler(unsigned long addr,
> Â
> > Â return 1;
> Â}
> +#endif
> Â
> Âstatic int imx6_pcie_attach_pd(struct device *dev)
> Â{
> @@ -353,6 +364,7 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
> Â
> > Â switch (imx6_pcie->drvdata->variant) {
> > Â case IMX7D:
> > + case IMX8MQ:
> > Â reset_control_assert(imx6_pcie->pciephy_reset);
> > Â reset_control_assert(imx6_pcie->apps_reset);
> > Â break;
> @@ -387,10 +399,17 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
> > Â }
> Â}
> Â
> +static unsigned int imx6_pcie_grp_offset(const struct imx6_pcie *imx6_pcie)
> +{
> > + WARN_ON(imx6_pcie->drvdata->variant != IMX8MQ);
> > + return imx6_pcie->controller_id == 1 ? IOMUXC_GPR16 : IOMUXC_GPR14;
> +}
> +
> Âstatic int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
> Â{
> > Â struct dw_pcie *pci = imx6_pcie->pci;
> > Â struct device *dev = pci->dev;
> > + unsigned int offset;
> > Â int ret = 0;
> Â
> > Â switch (imx6_pcie->drvdata->variant) {
> @@ -421,6 +440,19 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
> > Â break;
> > Â case IMX7D:
> > Â break;
> > + case IMX8MQ:
> > + offset = imx6_pcie_grp_offset(imx6_pcie);
> > + /*
> > + Â* Set the over ride low and enabled
> > + Â* make sure that REF_CLK is turned on.
> > + Â*/
> > + regmap_update_bits(imx6_pcie->iomuxc_gpr, offset,
> > + ÂÂÂIMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE,
> > + ÂÂÂ0);
> > + regmap_update_bits(imx6_pcie->iomuxc_gpr, offset,
> > + ÂÂÂIMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN,
> > + ÂÂÂIMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN);
> > + break;
> > Â }
> Â
> > Â return ret;
> @@ -497,6 +529,9 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
> > Â }
> Â
> > Â switch (imx6_pcie->drvdata->variant) {
> > + case IMX8MQ:
> > + reset_control_deassert(imx6_pcie->pciephy_reset);
> > + break;
> > Â case IMX7D:
> > Â reset_control_deassert(imx6_pcie->pciephy_reset);
> > Â imx7d_pcie_wait_for_phy_pll_lock(imx6_pcie);
> @@ -532,9 +567,37 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
> > Â }
> Â}
> Â
> +static void imx6_pcie_configure_type(struct imx6_pcie *imx6_pcie)
> +{
> > + unsigned int mask, val;
> +
> > + if (imx6_pcie->drvdata->variant == IMX8MQ &&
> > + ÂÂÂÂimx6_pcie->controller_id == 1) {
> > + maskÂÂÂ= IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE;
> > + valÂÂÂÂ= FIELD_PREP(IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE,
> > + ÂÂÂÂPCI_EXP_TYPE_ROOT_PORT);
> > + } else {
> > + mask = IMX6Q_GPR12_DEVICE_TYPE;
> > + valÂÂ= FIELD_PREP(IMX6Q_GPR12_DEVICE_TYPE,
> > + ÂÂPCI_EXP_TYPE_ROOT_PORT);
> > + }
> +
> > + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, mask, val);
> +}
> +
> Âstatic void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
> Â{
> > Â switch (imx6_pcie->drvdata->variant) {
> > + case IMX8MQ:
> > + /*
> > + Â* TODO: Currently this code assumes external
> > + Â* oscillator is being used
> > + Â*/
> > + regmap_update_bits(imx6_pcie->iomuxc_gpr,
> > + ÂÂÂimx6_pcie_grp_offset(imx6_pcie),
> > + ÂÂÂIMX8MQ_GPR_PCIE_REF_USE_PAD,
> > + ÂÂÂIMX8MQ_GPR_PCIE_REF_USE_PAD);
> > + break;
> > Â case IMX7D:
> > Â regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
> > Â ÂÂÂIMX7D_GPR12_PCIE_PHY_REFCLK_SEL, 0);
> @@ -570,8 +633,7 @@ static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
> > Â break;
> > Â }
> Â
> > - regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
> > - IMX6Q_GPR12_DEVICE_TYPE, PCI_EXP_TYPE_ROOT_PORT << 12);
> > + imx6_pcie_configure_type(imx6_pcie);
> Â}
> Â
> Âstatic int imx6_setup_phy_mpll(struct imx6_pcie *imx6_pcie)
> @@ -668,6 +730,7 @@ static void imx6_pcie_ltssm_enable(struct device *dev)
> > Â ÂÂÂIMX6Q_GPR12_PCIE_CTL_2);
> > Â break;
> > Â case IMX7D:
> > + case IMX8MQ:
> > Â reset_control_deassert(imx6_pcie->apps_reset);
> > Â break;
> > Â }
> @@ -1008,6 +1071,10 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> > Â }
> > Â break;
> > Â case IMX7D:
> > + case IMX8MQ:
> > + if (dbi_base->start == IMX8MQ_PCIE2_BASE_ADDR)
> > + imx6_pcie->controller_id = 1;
> +
> > Â imx6_pcie->pciephy_reset = devm_reset_control_get_exclusive(dev,
> > Â ÂÂÂÂ"pciephy");
> > Â if (IS_ERR(imx6_pcie->pciephy_reset)) {
> @@ -1115,6 +1182,9 @@ static const struct imx6_pcie_drvdata drvdata[] = {
> > Â [IMX7D] = {
> > Â .variant = IMX7D,
> > Â },
> > + [IMX8MQ] = {
> > + .variant = IMX8MQ,
> > + },
> Â};
> Â
> Âstatic const struct of_device_id imx6_pcie_of_match[] = {
> @@ -1122,6 +1192,7 @@ static const struct of_device_id imx6_pcie_of_match[] = {
> > Â { .compatible = "fsl,imx6sx-pcie", .data = &drvdata[IMX6SX], },
> > Â { .compatible = "fsl,imx6qp-pcie", .data = &drvdata[IMX6QP], },
> > Â { .compatible = "fsl,imx7d-pcie",ÂÂ.data = &drvdata[IMX7D],ÂÂ},
> > + { .compatible = "fsl,imx8mq-pcie", .data = &drvdata[IMX8MQ], } ,
> > Â {},
> Â};
> Â
> @@ -1138,6 +1209,7 @@ static struct platform_driver imx6_pcie_driver = {
> Â
> Âstatic int __init imx6_pcie_init(void)
> Â{
> +#ifdef CONFIG_ARM
> > Â /*
> > Â Â* Since probe() can be deferred we need to make sure that
> > Â Â* hook_fault_code is not called after __init memory is freed
> @@ -1147,6 +1219,7 @@ static int __init imx6_pcie_init(void)
> > Â Â*/
> > Â hook_fault_code(8, imx6q_pcie_abort_handler, SIGBUS, 0,
> > Â "external abort on non-linefetch");
> +#endif
> Â
> > Â return platform_driver_register(&imx6_pcie_driver);
> Â}