From: Frank Li <Frank.li@nxp.com>
To: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Cc: bhelgaas@google.com, conor+dt@kernel.org,
devicetree@vger.kernel.org, festevam@gmail.com,
helgaas@kernel.org, hongxing.zhu@nxp.com, imx@lists.linux.dev,
kernel@pengutronix.de, krzysztof.kozlowski+dt@linaro.org,
kw@linux.com, l.stach@pengutronix.de,
linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
lpieralisi@kernel.org, robh@kernel.org, s.hauer@pengutronix.de,
shawnguo@kernel.org
Subject: Re: [PATCH v3 01/13] PCI: imx6: Simplify clock handling by using HAS_CLK_* bitmask
Date: Tue, 12 Dec 2023 13:32:11 -0500 [thread overview]
Message-ID: <ZXinK/RF0Kc4ySYX@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20231212164913.GA21240@thinkpad>
On Tue, Dec 12, 2023 at 10:19:13PM +0530, Manivannan Sadhasivam wrote:
> On Mon, Dec 11, 2023 at 04:58:30PM -0500, Frank Li wrote:
> > Refactors the clock handling logic in the imx6 PCI driver by adding
> > HAS_CLK_* bitmask define for drvdata::flags . Simplifies the code and makes
> > it more maintainable, as future additions of SOC support will only require
> > straightforward changes. The drvdata::flags and a bitmask ensures a cleaner
> > and more scalable switch-case structure for handling clocks.
> >
>
> Is there any necessity to validate each clock in the driver? I mean, can't you
> just rely on devicetree to provide enough clocks for the functioning of the PCIe
> controller?
>
> If you can rely on devicetree (everyone should in an ideal world), then you can
> just use devm_clk_bulk_get_all() to get all available clocks for the SoC and
> just enable/disable whatever is available.
>
> This will greatly simplify the code.
>
> Only downside of this approach is, if the devicetree is not supplying enough
> clocks, then it will be difficult to find why PCIe is not working. But this also
> means that the devicetree is screwed.
I have idea, how about add clk name array in drvdata.
such as
clk_names[] = {"bus", "aux", "axi", ...}
clk_cnt = 4.
Then use devm_clk_blk_get_all().
Code will be simplied and not too much depend on devicetree's validate.
Frank
>
> - Mani
>
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> >
> > Notes:
> > Change from v1 to v3
> > - none
> >
> > drivers/pci/controller/dwc/pci-imx6.c | 84 +++++++++++++--------------
> > 1 file changed, 42 insertions(+), 42 deletions(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> > index 74703362aeec7..8a9b527934f80 100644
> > --- a/drivers/pci/controller/dwc/pci-imx6.c
> > +++ b/drivers/pci/controller/dwc/pci-imx6.c
> > @@ -60,6 +60,10 @@ enum imx6_pcie_variants {
> > #define IMX6_PCIE_FLAG_IMX6_PHY BIT(0)
> > #define IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE BIT(1)
> > #define IMX6_PCIE_FLAG_SUPPORTS_SUSPEND BIT(2)
> > +#define IMX6_PCIE_FLAG_HAS_CLK_INBOUND_AXI BIT(3)
> > +#define IMX6_PCIE_FLAG_HAS_CLK_AUX BIT(4)
> > +
> > +#define imx6_check_flag(pci, val) (pci->drvdata->flags & val)
> >
> > struct imx6_pcie_drvdata {
> > enum imx6_pcie_variants variant;
> > @@ -550,19 +554,23 @@ static int imx6_pcie_attach_pd(struct device *dev)
> >
> > 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) {
> > - case IMX6SX:
> > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_CLK_INBOUND_AXI)) {
> > ret = clk_prepare_enable(imx6_pcie->pcie_inbound_axi);
> > - if (ret) {
> > - dev_err(dev, "unable to enable pcie_axi clock\n");
> > - break;
> > - }
> > + if (ret)
> > + return ret;
> > + }
> >
> > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_CLK_AUX)) {
> > + ret = clk_prepare_enable(imx6_pcie->pcie_aux);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + switch (imx6_pcie->drvdata->variant) {
> > + case IMX6SX:
> > regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
> > IMX6SX_GPR12_PCIE_TEST_POWERDOWN, 0);
> > break;
> > @@ -589,12 +597,6 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
> > case IMX8MQ_EP:
> > case IMX8MP:
> > case IMX8MP_EP:
> > - ret = clk_prepare_enable(imx6_pcie->pcie_aux);
> > - if (ret) {
> > - dev_err(dev, "unable to enable pcie_aux clock\n");
> > - break;
> > - }
> > -
> > offset = imx6_pcie_grp_offset(imx6_pcie);
> > /*
> > * Set the over ride low and enabled
> > @@ -614,10 +616,13 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
> >
> > static void imx6_pcie_disable_ref_clk(struct imx6_pcie *imx6_pcie)
> > {
> > - switch (imx6_pcie->drvdata->variant) {
> > - case IMX6SX:
> > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_CLK_INBOUND_AXI))
> > clk_disable_unprepare(imx6_pcie->pcie_inbound_axi);
> > - break;
> > +
> > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_CLK_AUX))
> > + clk_disable_unprepare(imx6_pcie->pcie_aux);
> > +
> > + switch (imx6_pcie->drvdata->variant) {
> > case IMX6QP:
> > case IMX6Q:
> > regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
> > @@ -631,14 +636,6 @@ static void imx6_pcie_disable_ref_clk(struct imx6_pcie *imx6_pcie)
> > IMX7D_GPR12_PCIE_PHY_REFCLK_SEL,
> > IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);
> > break;
> > - case IMX8MM:
> > - case IMX8MM_EP:
> > - case IMX8MQ:
> > - case IMX8MQ_EP:
> > - case IMX8MP:
> > - case IMX8MP_EP:
> > - clk_disable_unprepare(imx6_pcie->pcie_aux);
> > - break;
> > default:
> > break;
> > }
> > @@ -1316,21 +1313,21 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> > return dev_err_probe(dev, PTR_ERR(imx6_pcie->pcie),
> > "pcie clock source missing or invalid\n");
> >
> > - switch (imx6_pcie->drvdata->variant) {
> > - case IMX6SX:
> > - imx6_pcie->pcie_inbound_axi = devm_clk_get(dev,
> > - "pcie_inbound_axi");
> > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_CLK_INBOUND_AXI)) {
> > + imx6_pcie->pcie_inbound_axi = devm_clk_get(dev, "pcie_inbound_axi");
> > if (IS_ERR(imx6_pcie->pcie_inbound_axi))
> > - return dev_err_probe(dev, PTR_ERR(imx6_pcie->pcie_inbound_axi),
> > - "pcie_inbound_axi clock missing or invalid\n");
> > - break;
> > - case IMX8MQ:
> > - case IMX8MQ_EP:
> > + dev_err_probe(dev, PTR_ERR(imx6_pcie->pcie_inbound_axi),
> > + "pcie_inbound_axi clock missing or invalid\n");
> > + }
> > +
> > + if (imx6_check_flag(imx6_pcie, IMX6_PCIE_FLAG_HAS_CLK_AUX)) {
> > imx6_pcie->pcie_aux = devm_clk_get(dev, "pcie_aux");
> > if (IS_ERR(imx6_pcie->pcie_aux))
> > return dev_err_probe(dev, PTR_ERR(imx6_pcie->pcie_aux),
> > "pcie_aux clock source missing or invalid\n");
> > - fallthrough;
> > + }
> > +
> > + switch (imx6_pcie->drvdata->variant) {
> > case IMX7D:
> > if (dbi_base->start == IMX8MQ_PCIE2_BASE_ADDR)
> > imx6_pcie->controller_id = 1;
> > @@ -1353,10 +1350,6 @@ static int imx6_pcie_probe(struct platform_device *pdev)
> > case IMX8MM_EP:
> > case IMX8MP:
> > case IMX8MP_EP:
> > - imx6_pcie->pcie_aux = devm_clk_get(dev, "pcie_aux");
> > - if (IS_ERR(imx6_pcie->pcie_aux))
> > - return dev_err_probe(dev, PTR_ERR(imx6_pcie->pcie_aux),
> > - "pcie_aux clock source missing or invalid\n");
> > imx6_pcie->apps_reset = devm_reset_control_get_exclusive(dev,
> > "apps");
> > if (IS_ERR(imx6_pcie->apps_reset))
> > @@ -1482,7 +1475,8 @@ static const struct imx6_pcie_drvdata drvdata[] = {
> > .variant = IMX6SX,
> > .flags = IMX6_PCIE_FLAG_IMX6_PHY |
> > IMX6_PCIE_FLAG_IMX6_SPEED_CHANGE |
> > - IMX6_PCIE_FLAG_SUPPORTS_SUSPEND,
> > + IMX6_PCIE_FLAG_SUPPORTS_SUSPEND |
> > + IMX6_PCIE_FLAG_HAS_CLK_INBOUND_AXI,
> > .gpr = "fsl,imx6q-iomuxc-gpr",
> > },
> > [IMX6QP] = {
> > @@ -1500,30 +1494,36 @@ static const struct imx6_pcie_drvdata drvdata[] = {
> > },
> > [IMX8MQ] = {
> > .variant = IMX8MQ,
> > + .flags = IMX6_PCIE_FLAG_HAS_CLK_AUX,
> > .gpr = "fsl,imx8mq-iomuxc-gpr",
> > },
> > [IMX8MM] = {
> > .variant = IMX8MM,
> > - .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND,
> > + .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND |
> > + IMX6_PCIE_FLAG_HAS_CLK_AUX,
> > .gpr = "fsl,imx8mm-iomuxc-gpr",
> > },
> > [IMX8MP] = {
> > .variant = IMX8MP,
> > - .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND,
> > + .flags = IMX6_PCIE_FLAG_SUPPORTS_SUSPEND |
> > + IMX6_PCIE_FLAG_HAS_CLK_AUX,
> > .gpr = "fsl,imx8mp-iomuxc-gpr",
> > },
> > [IMX8MQ_EP] = {
> > .variant = IMX8MQ_EP,
> > + .flags = IMX6_PCIE_FLAG_HAS_CLK_AUX,
> > .mode = DW_PCIE_EP_TYPE,
> > .gpr = "fsl,imx8mq-iomuxc-gpr",
> > },
> > [IMX8MM_EP] = {
> > .variant = IMX8MM_EP,
> > + .flags = IMX6_PCIE_FLAG_HAS_CLK_AUX,
> > .mode = DW_PCIE_EP_TYPE,
> > .gpr = "fsl,imx8mm-iomuxc-gpr",
> > },
> > [IMX8MP_EP] = {
> > .variant = IMX8MP_EP,
> > + .flags = IMX6_PCIE_FLAG_HAS_CLK_AUX,
> > .mode = DW_PCIE_EP_TYPE,
> > .gpr = "fsl,imx8mp-iomuxc-gpr",
> > },
> > --
> > 2.34.1
> >
>
> --
> மணிவண்ணன் சதாசிவம்
next prev parent reply other threads:[~2023-12-12 18:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 21:58 [PATCH v3 00/13] PCI: imx6: Clean up and add imx95 pci support Frank Li
2023-12-11 21:58 ` [PATCH v3 01/13] PCI: imx6: Simplify clock handling by using HAS_CLK_* bitmask Frank Li
2023-12-12 16:49 ` Manivannan Sadhasivam
2023-12-12 18:32 ` Frank Li [this message]
2023-12-12 22:54 ` Rob Herring
2023-12-12 23:18 ` Frank Li
2023-12-11 21:58 ` [PATCH v3 02/13] PCI: imx6: Simplify phy handling by using by using IMX6_PCIE_FLAG_HAS_PHY Frank Li
2023-12-11 21:58 ` [PATCH v3 03/13] PCI: imx6: Simplify reset handling by using by using *_FLAG_HAS_*_RESET Frank Li
2023-12-11 21:58 ` [PATCH v3 04/13] PCI: imx6: Using "linux,pci-domain" as slot ID Frank Li
2023-12-11 21:58 ` [PATCH v3 05/13] PCI: imx6: Simplify ltssm_enable() by using ltssm_off and ltssm_mask Frank Li
2023-12-11 21:58 ` [PATCH v3 06/13] PCI: imx6: Simplify configure_type() by using mode_off and mode_mask Frank Li
2023-12-11 21:58 ` [PATCH v3 07/13] PCI: imx6: Simplify switch-case logic by involve init_phy callback Frank Li
2023-12-11 21:58 ` [PATCH v3 08/13] dt-bindings: imx6q-pcie: Add imx95 pcie compatible string Frank Li
2023-12-12 22:44 ` Rob Herring
2023-12-12 23:28 ` Frank Li
2023-12-13 6:28 ` Krzysztof Kozlowski
2023-12-13 14:36 ` Rob Herring
2023-12-13 15:39 ` Frank Li
2023-12-13 16:46 ` Frank Li
2023-12-11 21:58 ` [PATCH v3 09/13] PCI: imx6: Add iMX95 PCIe support Frank Li
2023-12-11 21:58 ` [PATCH v3 10/13] PCI: imx6: Clean up get addr_space code Frank Li
2023-12-11 21:58 ` [PATCH v3 11/13] PCI: imx6: Add epc_features in imx6_pcie_drvdata Frank Li
2023-12-11 21:58 ` [PATCH v3 12/13] dt-bindings: imx6q-pcie: Add iMX95 pcie endpoint compatible string Frank Li
2023-12-12 16:51 ` Conor Dooley
2023-12-13 6:29 ` Krzysztof Kozlowski
2023-12-11 21:58 ` [PATCH v3 13/13] PCI: imx6: Add iMX95 Endpoint (EP) function support Frank Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZXinK/RF0Kc4ySYX@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=bhelgaas@google.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=helgaas@kernel.org \
--cc=hongxing.zhu@nxp.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kw@linux.com \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox