All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Ceresoli <luca@lucaceresoli.net>
To: "Marc Zyngier" <maz@kernel.org>, "Pali Rohár" <pali@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org,
	kernel-team@android.com, Alyssa Rosenzweig <alyssa@rosenzweig.io>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [PATCH v2] PCI: apple: Follow the PCIe specifications when resetting the port
Date: Mon, 22 Nov 2021 22:32:15 +0100	[thread overview]
Message-ID: <4fd0438e-b86b-2e1a-ea9a-2297d3580836@lucaceresoli.net> (raw)
In-Reply-To: <87zgpw5jza.wl-maz@kernel.org>

Hi Marc,

On 22/11/21 15:43, Marc Zyngier wrote:
> On Mon, 22 Nov 2021 12:03:47 +0000,
> Pali Rohár <pali@kernel.org> wrote:
>>
>> On Monday 22 November 2021 10:41:56 Marc Zyngier wrote:
>>> While the Apple PCIe driver works correctly when directly booted
>>> from the firmware, it fails to initialise when the kernel is booted
>>> from a bootloader using PCIe such as u-boot.
>>>
>>> That's beacuse we're missing a proper reset of the port (we only
>>> clear the reset, but never assert it).
>>>
>>> The PCIe spec requirements are two-fold:
>>>
>>> - #PERST must be asserted before setting up the clocks, and
>>>   stay asserted for at least 100us (Tperst-clk).
>>>
>>> - Once #PERST is deasserted, the OS must wait for at least 100ms
>>>   "from the end of a Conventional Reset" before we can start talking
>>>   to the devices
>>>
>>> Implementing this results in a booting system.
>>>
>>> Fixes: 1e33888fbe44 ("PCI: apple: Add initial hardware bring-up")
>>> Signed-off-by: Marc Zyngier <maz@kernel.org>
>>> Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>
>>> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>>> Cc: Bjorn Helgaas <bhelgaas@google.com>
>>> Cc: Pali Rohár <pali@kernel.org>
>>
>> Looks good, but see comment below.
>>
>> Acked-by: Pali Rohár <pali@kernel.org>
> 
> Thanks for that.
> 
>>
>>> ---
>>>  drivers/pci/controller/pcie-apple.c | 10 ++++++++++
>>>  1 file changed, 10 insertions(+)
>>>
>>> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
>>> index 1bf4d75b61be..957960a733c4 100644
>>> --- a/drivers/pci/controller/pcie-apple.c
>>> +++ b/drivers/pci/controller/pcie-apple.c
>>> @@ -539,13 +539,23 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
>>>  
>>>  	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
>>>  
>>> +	/* Engage #PERST before setting up the clock */
>>> +	gpiod_set_value(reset, 0);
>>> +
>>>  	ret = apple_pcie_setup_refclk(pcie, port);
>>>  	if (ret < 0)
>>>  		return ret;
>>>  
>>> +	/* The minimal Tperst-clk value is 100us (PCIe CMS r2.0, 2.6.2) */
>>> +	usleep_range(100, 200);
>>> +
>>> +	/* Deassert #PERST */
>>>  	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
>>>  	gpiod_set_value(reset, 1);
>>
>> + Luca
>>
>> Just one comment. PERST# (PCIe Reset) is active-low signal. De-asserting
>> means to really set value to 1.
>>
>> But there was a discussion that de-asserting should be done by call:
>>   gpiod_set_value(reset, 0);
>>
>> https://lore.kernel.org/linux-pci/51be082a-ff10-8a19-5648-f279aabcac51@lucaceresoli.net/
>>
>> Could we make this new pcie-apple.c driver to use gpiod_set_value(reset, 0)
>> for de-asserting, like in other drivers?

I agree it should be done right from the beginning since this is a new
driver. Fixing it later is a painful process.

> I guess it depends whether you care about the assertion or the signal
> itself. I think we may have a bug in the way the GPIOs are handled at
> the moment, as it makes no difference whether I register the GPIO are
> active high or active low...
>
> I guess that will be yet another thing to debug, but in the meantime
> we have a reliable reset.

Strange, in my case the "active low" pin polarity is correctly picked up
from device tree by the gpiolib code, thus using gpio_set_value(gpiod,
1) asserts the pin as it should, resulting in an electrically low pin.

-- 
Luca


WARNING: multiple messages have this Message-ID (diff)
From: Luca Ceresoli <luca@lucaceresoli.net>
To: "Marc Zyngier" <maz@kernel.org>, "Pali Rohár" <pali@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org,
	kernel-team@android.com, Alyssa Rosenzweig <alyssa@rosenzweig.io>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [PATCH v2] PCI: apple: Follow the PCIe specifications when resetting the port
Date: Mon, 22 Nov 2021 22:32:15 +0100	[thread overview]
Message-ID: <4fd0438e-b86b-2e1a-ea9a-2297d3580836@lucaceresoli.net> (raw)
In-Reply-To: <87zgpw5jza.wl-maz@kernel.org>

Hi Marc,

On 22/11/21 15:43, Marc Zyngier wrote:
> On Mon, 22 Nov 2021 12:03:47 +0000,
> Pali Rohár <pali@kernel.org> wrote:
>>
>> On Monday 22 November 2021 10:41:56 Marc Zyngier wrote:
>>> While the Apple PCIe driver works correctly when directly booted
>>> from the firmware, it fails to initialise when the kernel is booted
>>> from a bootloader using PCIe such as u-boot.
>>>
>>> That's beacuse we're missing a proper reset of the port (we only
>>> clear the reset, but never assert it).
>>>
>>> The PCIe spec requirements are two-fold:
>>>
>>> - #PERST must be asserted before setting up the clocks, and
>>>   stay asserted for at least 100us (Tperst-clk).
>>>
>>> - Once #PERST is deasserted, the OS must wait for at least 100ms
>>>   "from the end of a Conventional Reset" before we can start talking
>>>   to the devices
>>>
>>> Implementing this results in a booting system.
>>>
>>> Fixes: 1e33888fbe44 ("PCI: apple: Add initial hardware bring-up")
>>> Signed-off-by: Marc Zyngier <maz@kernel.org>
>>> Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>
>>> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>>> Cc: Bjorn Helgaas <bhelgaas@google.com>
>>> Cc: Pali Rohár <pali@kernel.org>
>>
>> Looks good, but see comment below.
>>
>> Acked-by: Pali Rohár <pali@kernel.org>
> 
> Thanks for that.
> 
>>
>>> ---
>>>  drivers/pci/controller/pcie-apple.c | 10 ++++++++++
>>>  1 file changed, 10 insertions(+)
>>>
>>> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
>>> index 1bf4d75b61be..957960a733c4 100644
>>> --- a/drivers/pci/controller/pcie-apple.c
>>> +++ b/drivers/pci/controller/pcie-apple.c
>>> @@ -539,13 +539,23 @@ static int apple_pcie_setup_port(struct apple_pcie *pcie,
>>>  
>>>  	rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
>>>  
>>> +	/* Engage #PERST before setting up the clock */
>>> +	gpiod_set_value(reset, 0);
>>> +
>>>  	ret = apple_pcie_setup_refclk(pcie, port);
>>>  	if (ret < 0)
>>>  		return ret;
>>>  
>>> +	/* The minimal Tperst-clk value is 100us (PCIe CMS r2.0, 2.6.2) */
>>> +	usleep_range(100, 200);
>>> +
>>> +	/* Deassert #PERST */
>>>  	rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
>>>  	gpiod_set_value(reset, 1);
>>
>> + Luca
>>
>> Just one comment. PERST# (PCIe Reset) is active-low signal. De-asserting
>> means to really set value to 1.
>>
>> But there was a discussion that de-asserting should be done by call:
>>   gpiod_set_value(reset, 0);
>>
>> https://lore.kernel.org/linux-pci/51be082a-ff10-8a19-5648-f279aabcac51@lucaceresoli.net/
>>
>> Could we make this new pcie-apple.c driver to use gpiod_set_value(reset, 0)
>> for de-asserting, like in other drivers?

I agree it should be done right from the beginning since this is a new
driver. Fixing it later is a painful process.

> I guess it depends whether you care about the assertion or the signal
> itself. I think we may have a bug in the way the GPIOs are handled at
> the moment, as it makes no difference whether I register the GPIO are
> active high or active low...
>
> I guess that will be yet another thing to debug, but in the meantime
> we have a reliable reset.

Strange, in my case the "active low" pin polarity is correctly picked up
from device tree by the gpiolib code, thus using gpio_set_value(gpiod,
1) asserts the pin as it should, resulting in an electrically low pin.

-- 
Luca


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-11-22 21:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 10:41 [PATCH v2] PCI: apple: Follow the PCIe specifications when resetting the port Marc Zyngier
2021-11-22 10:41 ` Marc Zyngier
2021-11-22 12:03 ` Pali Rohár
2021-11-22 12:03   ` Pali Rohár
2021-11-22 14:43   ` Marc Zyngier
2021-11-22 14:43     ` Marc Zyngier
2021-11-22 21:32     ` Luca Ceresoli [this message]
2021-11-22 21:32       ` Luca Ceresoli
2021-11-23  8:48       ` Marc Zyngier
2021-11-23  8:48         ` Marc Zyngier
2021-11-23 12:27         ` Mark Kettenis
2021-11-23 12:27           ` Mark Kettenis
2021-11-22 21:50     ` Mark Kettenis
2021-11-22 21:50       ` Mark Kettenis
2021-11-23 12:24       ` Marc Zyngier
2021-11-23 12:24         ` Marc Zyngier
2021-11-23 12:27         ` Pali Rohár
2021-11-23 12:27           ` Pali Rohár
2021-11-23 13:09           ` Marc Zyngier
2021-11-23 13:09             ` Marc Zyngier
2021-11-23 12:49         ` Mark Kettenis
2021-11-23 12:49           ` Mark Kettenis

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=4fd0438e-b86b-2e1a-ea9a-2297d3580836@lucaceresoli.net \
    --to=luca@lucaceresoli.net \
    --cc=alyssa@rosenzweig.io \
    --cc=bhelgaas@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=maz@kernel.org \
    --cc=pali@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.