public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Vinod Koul <vkoul@kernel.org>
To: Varadarajan Narayanan <quic_varada@quicinc.com>
Cc: lpieralisi@kernel.org, kw@linux.com,
	manivannan.sadhasivam@linaro.org, robh@kernel.org,
	bhelgaas@google.com, krzk+dt@kernel.org, conor+dt@kernel.org,
	kishon@kernel.org, andersson@kernel.org, konradybcio@kernel.org,
	p.zabel@pengutronix.de, quic_nsekar@quicinc.com,
	dmitry.baryshkov@linaro.org, linux-arm-msm@vger.kernel.org,
	linux-pci@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org
Subject: Re: [PATCH v10 2/7] phy: qcom: Introduce PCIe UNIPHY 28LP driver
Date: Thu, 27 Feb 2025 11:30:24 +0530	[thread overview]
Message-ID: <Z7//eDJZw2SNNc5Z@vaman> (raw)
In-Reply-To: <Z7MChDND+iClDNES@hu-varada-blr.qualcomm.com>

On 17-02-25, 15:03, Varadarajan Narayanan wrote:
> On Thu, Feb 13, 2025 at 11:22:01PM +0530, Vinod Koul wrote:
> [ . . .]
> 
> > > +static const struct qcom_uniphy_pcie_data ipq5332_data = {
> > > +	.lane_offset	= 0x800,
> > > +	.phy_type	= PHY_TYPE_PCIE_GEN3,
> > > +	.init_seq	= ipq5332_regs,
> > > +	.init_seq_num	= ARRAY_SIZE(ipq5332_regs),
> > > +	.pipe_clk_rate	= 250000000,
> >
> > can be written as 250 * MEGA
> 
> Ok.
> 
> [ . . .]
> 
> > > +/*
> > > + * Register a fixed rate pipe clock.
> > > + *
> > > + * The <s>_pipe_clksrc generated by PHY goes to the GCC that gate
> > > + * controls it. The <s>_pipe_clk coming out of the GCC is requested
> > > + * by the PHY driver for its operations.
> > > + * We register the <s>_pipe_clksrc here. The gcc driver takes care
> > > + * of assigning this <s>_pipe_clksrc as parent to <s>_pipe_clk.
> > > + * Below picture shows this relationship.
> > > + *
> > > + *         +---------------+
> > > + *         |   PHY block   |<<---------------------------------------+
> > > + *         |               |                                         |
> > > + *         |   +-------+   |                   +-----+               |
> > > + *   I/P---^-->|  PLL  |---^--->pipe_clksrc--->| GCC |--->pipe_clk---+
> > > + *    clk  |   +-------+   |                   +-----+
> > > + *         +---------------+
> > > + */
> > > +static inline int phy_pipe_clk_register(struct qcom_uniphy_pcie *phy, int id)
> > > +{
> > > +	const struct qcom_uniphy_pcie_data *data = phy->data;
> > > +	struct clk_hw *hw;
> > > +	char name[64];
> > > +
> > > +	snprintf(name, sizeof(name), "phy%d_pipe_clk_src", id);
> > > +	hw = devm_clk_hw_register_fixed_rate(phy->dev, name, NULL, 0,
> > > +					     data->pipe_clk_rate);
> > > +	if (IS_ERR(hw))
> > > +		return dev_err_probe(phy->dev, PTR_ERR(hw),
> > > +				     "Unable to register %s\n", name);
> > > +
> > > +	return devm_of_clk_add_hw_provider(phy->dev, of_clk_hw_simple_get, hw);
> > > +}
> > > +
> > > +static const struct of_device_id qcom_uniphy_pcie_id_table[] = {
> > > +	{
> > > +		.compatible = "qcom,ipq5332-uniphy-pcie-phy",
> > > +		.data = &ipq5332_data,
> > > +	}, {
> > > +		/* Sentinel */
> > > +	},
> > > +};
> > > +MODULE_DEVICE_TABLE(of, qcom_uniphy_pcie_id_table);
> > > +
> > > +static const struct phy_ops pcie_ops = {
> > > +	.power_on	= qcom_uniphy_pcie_power_on,
> > > +	.power_off	= qcom_uniphy_pcie_power_off,
> > > +	.owner          = THIS_MODULE,
> > > +};
> > > +
> > > +static int qcom_uniphy_pcie_probe(struct platform_device *pdev)
> > > +{
> > > +	struct phy_provider *phy_provider;
> > > +	struct device *dev = &pdev->dev;
> > > +	struct qcom_uniphy_pcie *phy;
> > > +	struct phy *generic_phy;
> > > +	int ret;
> > > +
> > > +	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
> > > +	if (!phy)
> > > +		return -ENOMEM;
> > > +
> > > +	platform_set_drvdata(pdev, phy);
> > > +	phy->dev = &pdev->dev;
> > > +
> > > +	phy->data = of_device_get_match_data(dev);
> > > +	if (!phy->data)
> > > +		return -EINVAL;
> > > +
> > > +	ret = of_property_read_u32(dev_of_node(dev), "num-lanes", &phy->lanes);
> > > +	if (ret)
> > > +		return dev_err_probe(dev, ret, "Couldn't read num-lanes\n");
> > > +
> > > +	ret = qcom_uniphy_pcie_get_resources(pdev, phy);
> > > +	if (ret < 0)
> > > +		return dev_err_probe(&pdev->dev, ret,
> > > +				     "failed to get resources: %d\n", ret);
> > > +
> > > +	generic_phy = devm_phy_create(phy->dev, NULL, &pcie_ops);
> > > +	if (IS_ERR(generic_phy))
> > > +		return PTR_ERR(generic_phy);
> > > +
> > > +	phy_set_drvdata(generic_phy, phy);
> > > +
> > > +	ret = phy_pipe_clk_register(phy, generic_phy->id);
> > > +	if (ret)
> > > +		dev_err(&pdev->dev, "failed to register phy pipe clk\n");
> > > +
> > > +	phy_provider = devm_of_phy_provider_register(phy->dev,
> > > +						     of_phy_simple_xlate);
> > > +	if (IS_ERR(phy_provider))
> > > +		return PTR_ERR(phy_provider);
> >
> > should we not unroll the pipe clk registration here?
> 
> Since it is a 'devm_' clk_hw_register_fixed_rate, wouldn't the devm
> framework do the unregister?
> 
> 	$ git diff
> 	diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c
> 	index 6b4f76b9c4da..3fd1a12cc163 100644
> 	--- a/drivers/clk/clk-fixed-rate.c
> 	+++ b/drivers/clk/clk-fixed-rate.c
> 	@@ -58,6 +58,7 @@ static void
> 	devm_clk_hw_register_fixed_rate_release(struct device *dev, void *re
> 		 * the hw, resulting in double free. Just unregister the hw and
> 		 * let
> 		 * devres code kfree() it.
> 		 */
> 	+	printk("--> %s: %s\n", __func__, __clk_get_name(fix->hw.clk));
> 		clk_hw_unregister(&fix->hw);
> 	 }
> 
> 	diff --git a/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c
> 	b/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c
> 	index 311f98181177..9a8d8d9a7c2b 100644
> 	--- a/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c
> 	+++ b/drivers/phy/qualcomm/phy-qcom-uniphy-pcie-28lp.c
> 	@@ -267,6 +268,7 @@ static int qcom_uniphy_pcie_probe(struct
> 	platform_device *pdev)
> 
> 		phy_provider = devm_of_phy_provider_register(phy->dev,
> 							     of_phy_simple_xlate);
> 	+	phy_provider = ERR_PTR(-EINVAL);
> 		if (IS_ERR(phy_provider))
> 			return PTR_ERR(phy_provider);
> 
> I forced an error here and saw that devm_clk_hw_register_fixed_rate_release
> is getting called, which in turn calls clk_hw_unregister. Is that sufficient?
> Or am i missing something.

I missed that internally this is devm_, this is fine

-- 
~Vinod

  reply	other threads:[~2025-02-27  6:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 12:17 [PATCH v10 0/7] Add PCIe support for Qualcomm IPQ5332 Varadarajan Narayanan
2025-02-06 12:17 ` [PATCH v10 1/7] dt-bindings: phy: qcom,uniphy-pcie: Document PCIe uniphy Varadarajan Narayanan
2025-02-06 12:17 ` [PATCH v10 2/7] phy: qcom: Introduce PCIe UNIPHY 28LP driver Varadarajan Narayanan
2025-02-13 17:52   ` Vinod Koul
2025-02-17  9:33     ` Varadarajan Narayanan
2025-02-27  6:00       ` Vinod Koul [this message]
2025-02-27  8:53         ` Varadarajan Narayanan
2025-02-06 12:17 ` [PATCH v10 3/7] dt-bindings: PCI: qcom: Use sdx55 reg description for ipq9574 Varadarajan Narayanan
2025-02-06 12:18 ` [PATCH v10 4/7] arm64: dts: qcom: ipq9574: Reorder reg and reg-names Varadarajan Narayanan
2025-02-06 12:18 ` [PATCH v10 5/7] dt-bindings: PCI: qcom: Document the IPQ5332 PCIe controller Varadarajan Narayanan
2025-02-10  9:08   ` Krzysztof Kozlowski
2025-02-06 12:18 ` [PATCH v10 6/7] arm64: dts: qcom: ipq5332: Add PCIe related nodes Varadarajan Narayanan
2025-02-06 12:18 ` [PATCH v10 7/7] arm64: dts: qcom: ipq5332-rdp441: Enable PCIe phys and controllers Varadarajan Narayanan

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=Z7//eDJZw2SNNc5Z@vaman \
    --to=vkoul@kernel.org \
    --cc=andersson@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=kishon@kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kw@linux.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=lpieralisi@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=p.zabel@pengutronix.de \
    --cc=quic_nsekar@quicinc.com \
    --cc=quic_varada@quicinc.com \
    --cc=robh@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