linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Sean Cross <xobs@kosagi.com>
Cc: devicetree@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Shawn Guo <shawn.guo@linaro.org>
Subject: Re: [PATCH v3 3/3] PCI: imx6: Add support for i.MX6 PCIe controller
Date: Thu, 12 Sep 2013 08:28:59 +0200	[thread overview]
Message-ID: <20130912062859.GM30088@pengutronix.de> (raw)
In-Reply-To: <1378958611-4274-4-git-send-email-xobs@kosagi.com>

Sean,

Several more comments.

Shawn,

A question about a clk_set_parent inside.

On Thu, Sep 12, 2013 at 04:03:31AM +0000, Sean Cross wrote:
> +
> +#define IMX6_ENTER_RESET 0
> +#define IMX6_EXIT_RESET 1

These are unused

> +
> +#define IMX6_POWER_OFF 0
> +#define IMX6_POWER_ON 1

unused aswell

> +static int pcie_phy_poll_ack(void __iomem *dbi_base, int max_iterations,
> +			     int exp_val)
> +{
> +	u32 val;
> +	u32 wait_counter = 0;
> +
> +	do {
> +		val = readl(dbi_base + PCIE_PHY_STAT);
> +		val = (val >> PCIE_PHY_STAT_ACK_LOC) & 0x1;
> +		wait_counter++;
> +	} while ((wait_counter < max_iterations) && (val != exp_val));

may_iterations is never something else than 100 so you should drop the
argument.
Also I would prefer a real timeout here rather than a counter.

> +
> +	if (val != exp_val)
> +		return -1;

By saying "A negative error value" I actually meant one of
include/uapi/asm-generic/errno*

> +static int pcie_phy_write(void __iomem *dbi_base, int addr, int data)
> +{
> +	u32 var;
> +
> +	/* write addr */
> +	/* cap addr */
> +	if (pcie_phy_wait_ack(dbi_base, addr))
> +		return -1;
> +
> +	var = data << PCIE_PHY_CTRL_DATA_LOC;
> +	writel(var, dbi_base + PCIE_PHY_CTRL);
> +
> +	/* capture data */
> +	var |= (0x1 << PCIE_PHY_CTRL_CAP_DAT_LOC);
> +	writel(var, dbi_base + PCIE_PHY_CTRL);
> +
> +	/* wait for ack */

Drop this comment.

> +	if (pcie_phy_poll_ack(dbi_base, 100, 1))
> +		return -1;
> +

...

> +static int imx6_pcie_deassert_core_reset(struct pcie_port *pp)
> +{
> +	int ret;
> +	struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
> +
> +	if (imx6_pcie->power_on_gpio >= 0)
> +		gpio_set_value(imx6_pcie->power_on_gpio, IMX6_POWER_ON);

in probe you used gpio_is_valid(). Why not here?

> +
> +	regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
> +			IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18);
> +	regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
> +			IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
> +
> +	ret = clk_set_parent(imx6_pcie->lvds1_sel, imx6_pcie->sata_ref);
> +	if (ret) {
> +		dev_err(pp->dev, "unable to set lvds1_gate parent\n");
> +		goto err_set_parent;
> +	}

I'm unsure this should be done here. Shawn, should we do this in SoC
code?

> +
> +	ret = clk_prepare_enable(imx6_pcie->pcie_ref_125m);
> +	if (ret) {
> +		dev_err(pp->dev, "unable to enable pcie_ref_125m\n");
> +		goto err_pcie_ref;
> +	}
> +
> +	ret = clk_prepare_enable(imx6_pcie->lvds1_gate);
> +	if (ret) {
> +		dev_err(pp->dev, "unable to enable lvds1_gate\n");
> +		goto err_lvds1_gate;
> +	}
> +
> +	ret = clk_prepare_enable(imx6_pcie->pcie_axi);
> +	if (ret) {
> +		dev_err(pp->dev, "unable to enable pcie_axi\n");
> +		goto err_pcie_axi;
> +	}
> +
> +	/* allow the clocks to stabilize */
> +	usleep_range(100, 200);
> +
> +	return 0;
> +
> +err_pcie_axi:
> +	clk_disable(imx6_pcie->lvds1_gate);

The counterpart of clk_prepare_enable is clk_disable_unprepare.

> +			return;
> +		}
> +	}
> +
> +	return;

unnecessary return

> +
> +	imx6_pcie->power_on_gpio = of_get_named_gpio(np, "power-on-gpio", 0);
> +	if (gpio_is_valid(imx6_pcie->power_on_gpio))
> +		devm_gpio_request_one(&pdev->dev, imx6_pcie->power_on_gpio,
> +				    GPIOF_OUT_INIT_LOW,
> +				    "PCIe power enable");

devm_gpio_request_one can still fail.

> +
> +	imx6_pcie->wake_up_gpio = of_get_named_gpio(np, "wake-up-gpio", 0);
> +	if (gpio_is_valid(imx6_pcie->wake_up_gpio))
> +		devm_gpio_request_one(&pdev->dev, imx6_pcie->wake_up_gpio,
> +				    GPIOF_IN,
> +				    "PCIe wake up");
> +
> +	imx6_pcie->disable_gpio = of_get_named_gpio(np, "disable-gpio", 0);
> +	if (gpio_is_valid(imx6_pcie->disable_gpio))
> +		devm_gpio_request_one(&pdev->dev, imx6_pcie->disable_gpio,
> +				    GPIOF_OUT_INIT_HIGH,
> +				    "PCIe disable endpoint");
> +
> +	/* Fetch clocks */
> +	imx6_pcie->lvds1_sel = clk_get(&pdev->dev, "lvds1_sel");
> +	if (IS_ERR(imx6_pcie->lvds1_sel)) {
> +		dev_err(&pdev->dev,
> +			"lvds1_sel clock missing or invalid\n");
> +		ret = PTR_ERR(imx6_pcie->lvds1_sel);
> +		goto err;
> +	}
> +
> +	imx6_pcie->lvds1_gate = clk_get(&pdev->dev, "lvds1_gate");
> +	if (IS_ERR(imx6_pcie->lvds1_gate)) {
> +		dev_err(&pdev->dev,
> +			"lvds1_gate clock select missing or invalid\n");
> +		ret = PTR_ERR(imx6_pcie->lvds1_gate);
> +		goto err;
> +	}

devm_clk_get(). Otherwise you need to release the clock un
unregister/probe failure.

> +static int __exit imx6_pcie_remove(struct platform_device *pdev)
> +{
> +	struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev);
> +
> +	clk_disable_unprepare(imx6_pcie->pcie_axi);
> +	clk_disable_unprepare(imx6_pcie->lvds1_gate);
> +	clk_disable_unprepare(imx6_pcie->pcie_ref_125m);

Still no unregister for the pcie controller?

> +
> +	return 0;
> +}
> +

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2013-09-12  6:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-12  4:03 [PATCH v3 0/3] Add PCIe support for i.MX6q Sean Cross
2013-09-12  4:03 ` [PATCH v3 1/3] ARM: imx: Add LVDS general-purpose clocks to i.MX6Q Sean Cross
2013-09-12  4:03 ` [PATCH v3 2/3] ARM: imx6q: Add PCIe bits to GPR syscon definition Sean Cross
2013-09-12  4:03 ` [PATCH v3 3/3] PCI: imx6: Add support for i.MX6 PCIe controller Sean Cross
2013-09-12  6:28   ` Sascha Hauer [this message]
2013-09-12  6:44     ` Sean Cross
2013-09-12  7:01       ` Sascha Hauer
2013-09-12  7:11         ` Sean Cross
2013-09-12 10:41           ` Sascha Hauer
2013-09-12  6:35   ` Zhu Richard-R65037
2013-09-12  6:55     ` Sean Cross

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=20130912062859.GM30088@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=shawn.guo@linaro.org \
    --cc=xobs@kosagi.com \
    /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;
as well as URLs for NNTP newsgroup(s).