Re: [PATCH v2 2/3] PCI: imx6: introduce drvdata
From: Lucas Stach
Date: Tue Nov 20 2018 - 09:36:33 EST
Am Dienstag, den 20.11.2018, 14:27 +0100 schrieb Stefan Agner:
> Introduce driver data struct. This will simplify handling of device
> specific differences.
>
> Signed-off-by: Stefan Agner <stefan@xxxxxxxx>
Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
> ---
> Changes in v2:
> - Split drvdata introduction in a separate patch
> - Use an array instead of individual struct imx6_pcie_drvdata declarations
>
> Âdrivers/pci/controller/dwc/pci-imx6.c | 38 +++++++++++++++++----------
> Â1 file changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 4a9a673b4777..7ac1a639fe91 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -39,6 +39,10 @@ enum imx6_pcie_variants {
> > Â IMX7D,
> Â};
> Â
> +struct imx6_pcie_drvdata {
> > + enum imx6_pcie_variants variant;
> +};
> +
> Âstruct imx6_pcie {
> > > Â struct dw_pcie *pci;
> > > Â int reset_gpio;
> @@ -50,7 +54,6 @@ struct imx6_pcie {
> > > Â struct regmap *iomuxc_gpr;
> > > Â struct reset_control *pciephy_reset;
> > > Â struct reset_control *apps_reset;
> > - enum imx6_pcie_variants variant;
> > > Â u32 tx_deemph_gen1;
> > > Â u32 tx_deemph_gen2_3p5db;
> > > Â u32 tx_deemph_gen2_6db;
> @@ -58,6 +61,7 @@ struct imx6_pcie {
> > > Â u32 tx_swing_low;
> > > Â int link_gen;
> > > Â struct regulator *vpcie;
> > + const struct imx6_pcie_drvdata *drvdata;
> Â};
> Â
> Â/* Parameters for the waiting for PCIe PHY PLL to lock on i.MX7 */
> @@ -285,7 +289,7 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
> Â{
> > Â struct device *dev = imx6_pcie->pci->dev;
> Â
> > - switch (imx6_pcie->variant) {
> > + switch (imx6_pcie->drvdata->variant) {
> > Â case IMX7D:
> > Â reset_control_assert(imx6_pcie->pciephy_reset);
> > Â reset_control_assert(imx6_pcie->apps_reset);
> @@ -327,7 +331,7 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
> > Â struct device *dev = pci->dev;
> > Â int ret = 0;
> Â
> > - switch (imx6_pcie->variant) {
> > + switch (imx6_pcie->drvdata->variant) {
> > Â case IMX6SX:
> > Â ret = clk_prepare_enable(imx6_pcie->pcie_inbound_axi);
> > Â if (ret) {
> @@ -430,7 +434,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
> > Â !imx6_pcie->gpio_active_high);
> > Â }
> Â
> > - switch (imx6_pcie->variant) {
> > + switch (imx6_pcie->drvdata->variant) {
> > Â case IMX7D:
> > Â reset_control_deassert(imx6_pcie->pciephy_reset);
> > Â imx7d_pcie_wait_for_phy_pll_lock(imx6_pcie);
> @@ -468,7 +472,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
> Â
> Âstatic void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
> Â{
> > - switch (imx6_pcie->variant) {
> > + switch (imx6_pcie->drvdata->variant) {
> > Â case IMX7D:
> > Â regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
> > Â ÂÂÂIMX7D_GPR12_PCIE_PHY_REFCLK_SEL, 0);
> @@ -560,7 +564,7 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
> > Â dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp);
> Â
> > Â /* Start LTSSM. */
> > - if (imx6_pcie->variant == IMX7D)
> > + if (imx6_pcie->drvdata->variant == IMX7D)
> > Â reset_control_deassert(imx6_pcie->apps_reset);
> > Â else
> > Â regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
> @@ -585,7 +589,7 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie)
> > Â tmp |= PORT_LOGIC_SPEED_CHANGE;
> > Â dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, tmp);
> Â
> > - if (imx6_pcie->variant != IMX7D) {
> > + if (imx6_pcie->drvdata->variant != IMX7D) {
> > Â /*
> > Â Â* On i.MX7, DIRECT_SPEED_CHANGE behaves differently
> > Â Â* from i.MX6 family when no link speed transition
> @@ -703,8 +707,7 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> > Â pci->ops = &dw_pcie_ops;
> Â
> > Â imx6_pcie->pci = pci;
> > - imx6_pcie->variant =
> > - (enum imx6_pcie_variants)of_device_get_match_data(dev);
> > + imx6_pcie->drvdata = of_device_get_match_data(dev);
> Â
> > Â dbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > Â pci->dbi_base = devm_ioremap_resource(dev, dbi_base);
> @@ -748,7 +751,7 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> > Â return PTR_ERR(imx6_pcie->pcie);
> > Â }
> Â
> > - switch (imx6_pcie->variant) {
> > + switch (imx6_pcie->drvdata->variant) {
> > Â case IMX6SX:
> > Â imx6_pcie->pcie_inbound_axi = devm_clk_get(dev,
> > Â ÂÂÂ"pcie_inbound_axi");
> @@ -835,11 +838,18 @@ static void imx6_pcie_shutdown(struct platform_device *pdev)
> > Â imx6_pcie_assert_core_reset(imx6_pcie);
> Â}
> Â
> +static const struct imx6_pcie_drvdata drvdata[] = {
> > + [IMX6Q] = { .variant = IMX6Q },
> > + [IMX6SX] = { .variant = IMX6SX },
> > + [IMX6QP] = { .variant = IMX6QP },
> > + [IMX7D] = { .variant = IMX7D },
> +};
> +
> Âstatic const struct of_device_id imx6_pcie_of_match[] = {
> > - { .compatible = "fsl,imx6q-pcie",ÂÂ.data = (void *)IMX6Q,ÂÂ},
> > - { .compatible = "fsl,imx6sx-pcie", .data = (void *)IMX6SX, },
> > - { .compatible = "fsl,imx6qp-pcie", .data = (void *)IMX6QP, },
> > - { .compatible = "fsl,imx7d-pcie",ÂÂ.data = (void *)IMX7D,ÂÂ},
> > + { .compatible = "fsl,imx6q-pcie",ÂÂ.data = &drvdata[IMX6Q],ÂÂ},
> > + { .compatible = "fsl,imx6sx-pcie", .data = &drvdata[IMX6SX], },
> > + { .compatible = "fsl,imx6qp-pcie", .data = &drvdata[IMX6QP], },
> > + { .compatible = "fsl,imx7d-pcie",ÂÂ.data = &drvdata[IMX7D],ÂÂ},
> > Â {},
> Â};
> Â