linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Shawn Lin <shawn.lin@rock-chips.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org, linux-rockchip@lists.infradead.org,
	Wenrui Li <wenrui.li@rock-chips.com>,
	Brian Norris <briannorris@chromium.org>
Subject: Re: [PATCH v4 1/4] PCI: rockchip: Provide captured slot power limit and scale
Date: Fri, 11 Nov 2016 16:03:42 -0600	[thread overview]
Message-ID: <20161111220342.GP9868@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <1476754889-21804-1-git-send-email-shawn.lin@rock-chips.com>

On Tue, Oct 18, 2016 at 09:41:26AM +0800, Shawn Lin wrote:
> If vpcie3v3 is available, we could provide these information
> via RC's configure register to make EP able to know the power
> limit.
> 
> Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>

I applied all four of these to pci/host-rockchip for v4.10, thanks!

> ---
> 
> Changes in v4:
> - rebase on next branch
> 
> Changes in v3:
> - rebase the code since it isn't cleanly applied again.
> 
> Changes in v2:
> - rebase the code since it isn't cleanly applied after Bjorn's cleanup
> 
>  drivers/pci/host/pcie-rockchip.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c
> index e0b22da..3ede865 100644
> --- a/drivers/pci/host/pcie-rockchip.c
> +++ b/drivers/pci/host/pcie-rockchip.c
> @@ -135,6 +135,10 @@
>  #define PCIE_RC_CONFIG_VENDOR		(PCIE_RC_CONFIG_BASE + 0x00)
>  #define PCIE_RC_CONFIG_RID_CCR		(PCIE_RC_CONFIG_BASE + 0x08)
>  #define   PCIE_RC_CONFIG_SCC_SHIFT		16
> +#define PCIE_RC_CONFIG_DCR		(PCIE_RC_CONFIG_BASE + 0xc4)
> +#define   PCIE_RC_CONFIG_DCR_CSPL_SHIFT		18
> +#define   PCIE_RC_CONFIG_DCR_CSPL_LIMIT		0xff
> +#define   PCIE_RC_CONFIG_DCR_CPLS_SHIFT		26
>  #define PCIE_RC_CONFIG_LCS		(PCIE_RC_CONFIG_BASE + 0xd0)
>  #define   PCIE_RC_CONFIG_LCS_RETRAIN_LINK	BIT(5)
>  #define   PCIE_RC_CONFIG_LCS_LBMIE		BIT(10)
> @@ -395,6 +399,40 @@ static struct pci_ops rockchip_pcie_ops = {
>  	.write = rockchip_pcie_wr_conf,
>  };
>  
> +static void rockchip_pcie_set_power_limit(struct rockchip_pcie *rockchip)
> +{
> +	u32 status, curr, scale, power;
> +
> +	if (IS_ERR(rockchip->vpcie3v3))
> +		return;
> +
> +	/*
> +	 * Set RC's captured slot power limit and scale if
> +	 * vpcie3v3 available. The default values are both zero
> +	 * which means the software should set these two according
> +	 * to the actual power supply.
> +	 */
> +	curr = regulator_get_current_limit(rockchip->vpcie3v3);
> +	if (curr > 0) {
> +		scale = 3; /* 0.001x */
> +		curr = curr / 1000; /* convert to mA */
> +		power = (curr * 3300) / 1000; /* milliwatt */
> +		while (power > PCIE_RC_CONFIG_DCR_CSPL_LIMIT) {
> +			if (!scale) {
> +				dev_warn(rockchip->dev, "invalid power supply\n");
> +				return;
> +			}
> +			scale--;
> +			power = power / 10;
> +		}
> +
> +		status = rockchip_pcie_read(rockchip, PCIE_RC_CONFIG_DCR);
> +		status |= (power << PCIE_RC_CONFIG_DCR_CSPL_SHIFT) |
> +			  (scale << PCIE_RC_CONFIG_DCR_CPLS_SHIFT);
> +		rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_DCR);
> +	}
> +}
> +
>  /**
>   * rockchip_pcie_init_port - Initialize hardware
>   * @rockchip: PCIe port information
> @@ -496,6 +534,8 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
>  		 (PCIE_CORE_CTRL_PLC1_FTS_CNT << PCIE_CORE_CTRL_PLC1_FTS_SHIFT);
>  	rockchip_pcie_write(rockchip, status, PCIE_CORE_CTRL_PLC1);
>  
> +	rockchip_pcie_set_power_limit(rockchip);
> +
>  	/* Enable Gen1 training */
>  	rockchip_pcie_write(rockchip, PCIE_CLIENT_LINK_TRAIN_ENABLE,
>  			    PCIE_CLIENT_CONFIG);
> -- 
> 2.3.7
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2016-11-11 22:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18  1:41 [PATCH v4 1/4] PCI: rockchip: Provide captured slot power limit and scale Shawn Lin
2016-10-18  1:41 ` [PATCH v4 2/4] PCI: rockchip: Mark RC as common clock architecture Shawn Lin
2016-11-11 22:09   ` Bjorn Helgaas
2016-11-12  1:54     ` Shawn Lin
2016-10-18  1:41 ` [PATCH v4 3/4] PCI: rockchip: add COMPILE_TEST for Kconfig Shawn Lin
2016-10-18  1:41 ` [PATCH v4 4/4] PCI: rockchip: fix wrong negotiated lanes calculation Shawn Lin
2016-11-11 22:03 ` Bjorn Helgaas [this message]

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=20161111220342.GP9868@bhelgaas-glaptop.roam.corp.google.com \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=briannorris@chromium.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=shawn.lin@rock-chips.com \
    --cc=wenrui.li@rock-chips.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).