devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Sean Cross <xobs-nXMMniAx+RbQT0dZR+AlfA@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Zhu Richard-R65037
	<r65037-KZfg59tc24xl57MIdRCFDg@public.gmane.org>,
	Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	tharvey-UMMOYl/HMS+akBO8gow8eQ@public.gmane.org,
	bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH v5 3/3] PCI: imx6: Add support for i.MX6 PCIe controller
Date: Mon, 16 Sep 2013 09:40:45 +0200	[thread overview]
Message-ID: <20130916074045.GT30088@pengutronix.de> (raw)
In-Reply-To: <1379310497-12362-4-git-send-email-xobs-nXMMniAx+RbQT0dZR+AlfA@public.gmane.org>

On Mon, Sep 16, 2013 at 05:48:17AM +0000, Sean Cross wrote:
> Add support for the PCIe port present on the i.MX6 family of controllers.
> These use the Synopsis Designware core tied to their own PHY.
> 
> diff --git a/arch/arm/mach-imx/clk-imx6q.c b/arch/arm/mach-imx/clk-imx6q.c
> index 971356b..d30ff63 100644
> --- a/arch/arm/mach-imx/clk-imx6q.c
> +++ b/arch/arm/mach-imx/clk-imx6q.c
> @@ -623,6 +623,18 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
>  	if (ret)
>  		pr_warn("failed to set up CLKO: %d\n", ret);
>  
> +	/*
> +	 * All existing boards with PCIe use LVDS1
> +	 */
> +	if (IS_ENABLED(CONFIG_PCI_IMX6)) {
> +		clk_set_parent(clk[lvds1_sel], clk[sata_ref]);

This is fine,

> +		clk_prepare_enable(clk[lvds1_gate]);
> +		clk_prepare_enable(clk[pcie_ref_125m]);
> +		clk_prepare_enable(clk[sata_ref_100m]);
> +		clk_prepare_enable(clk[pcie_axi]);

but the clocks should be really enabled in the driver that needs them.

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

		if (val == exp_val)
			return 0;

> +		udelay(1);

Avoids the udelay when the value is correct during the first iteration.

> +	} while ((wait_counter < max_iterations) && (val != exp_val));
> +
> +	if (val != exp_val)
> +		return -ETIMEDOUT;
> +
> +	return 0;
> +}
> +

...

> +/* Read from the 16-bit PCIe PHY control registers (not memory-mapped) */
> +static int pcie_phy_read(void __iomem *dbi_base, int addr , int *data)
> +{
> +	u32 val, phy_ctl;
> +	int ret;
> +
> +	ret = pcie_phy_wait_ack(dbi_base, addr);
> +	if (ret)
> +		return ret;
> +
> +	/* assert Read signal */
> +	phy_ctl = 0x1 << PCIE_PHY_CTRL_RD_LOC;
> +	writel(phy_ctl, dbi_base + PCIE_PHY_CTRL);
> +
> +	ret = pcie_phy_poll_ack(dbi_base, 1);
> +	if (ret)
> +		return ret;
> +
> +	val = readl(dbi_base + PCIE_PHY_STAT);
> +	*data = (val & (0xffff << PCIE_PHY_STAT_DATA_LOC));

This works because PCIE_PHY_STAT_DATA_LOC is 0. Otherwise you would have
to do:

	*data = (val >> PCIE_PHY_STAT_DATA_LOC) & 0xfff;

I suggest to simply drop the bogus zero bit shift.

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 |
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-09-16  7:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-16  5:48 [PATCH v5 0/3] Add PCIe support for i.MX6q Sean Cross
     [not found] ` <1379310497-12362-1-git-send-email-xobs-nXMMniAx+RbQT0dZR+AlfA@public.gmane.org>
2013-09-16  5:48   ` [PATCH v5 1/3] ARM: imx: Add LVDS general-purpose clocks to i.MX6Q Sean Cross
     [not found]     ` <1379310497-12362-2-git-send-email-xobs-nXMMniAx+RbQT0dZR+AlfA@public.gmane.org>
2013-09-16  6:23       ` Shawn Guo
2013-09-16  5:48   ` [PATCH v5 3/3] PCI: imx6: Add support for i.MX6 PCIe controller Sean Cross
     [not found]     ` <1379310497-12362-4-git-send-email-xobs-nXMMniAx+RbQT0dZR+AlfA@public.gmane.org>
2013-09-16  6:14       ` Shawn Guo
2013-09-16  7:40       ` Sascha Hauer [this message]
2013-09-16  5:48 ` [PATCH v5 2/3] ARM: imx6q: Add PCIe bits to GPR syscon definition 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=20130916074045.GT30088@pengutronix.de \
    --to=s.hauer-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=bhelgaas-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-pci-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=r65037-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=tharvey-UMMOYl/HMS+akBO8gow8eQ@public.gmane.org \
    --cc=xobs-nXMMniAx+RbQT0dZR+AlfA@public.gmane.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;
as well as URLs for NNTP newsgroup(s).