All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rhyland Klein <rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Trent Piepho <tpiepho-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
	Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>,
	Laxman Dewangan
	<ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	"linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org"
	<spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: Re: [RESEND] spi/tegra114: Correct support for cs_change
Date: Tue, 24 Sep 2013 12:33:48 -0400	[thread overview]
Message-ID: <5241BEEC.9000508@nvidia.com> (raw)
In-Reply-To: <CA+7tXiiNMwyQh9sCsW4Qkid9Tn8RTcQ-uUmNse+kK-PZro1pyQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On 9/23/2013 7:08 PM, Trent Piepho wrote:
> On Mon, Sep 23, 2013 at 2:14 PM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:
>>
>> That sounds broken. Normally, shouldn't CS assert before a transaction,
>> stay asserted during a transaction, then deassert after the transaction?
>> It shouldn't rise and fall very quickly in between parts of the transaction.
> 
> That is normal, where a transaction is a spi_message made up of
> multiple spi_transfers.  The cs_change bit for a transfer will insert
> a de-asserted pulse after a transfer or leave CS de-asserted after the
> last transfer.
> 
>>>>> need to generate a falling-edge to trigger the beginning of a SPI
>>>>> transaction. Doing this write with the default value of SPI_COMMAND1
>>>>> causes a brief rise and fall of CS, giving us our falling-edge.
> 
> I wonder, is the real problem that the spi layer allows CS to possibly
> remain asserted between transactions to the same device?  Normally you
> would expect it to be de-asserted at the end of a spi_message, but I
> believe the Linux spi semantics are that it may or may not actually be
> de-asserted at that time.  It only guarantees that is will be
> de-asserted before a message to a different device starts.
> 
> I guess this is supposed to be an optimization.  Some drivers, like
> gpio bit-banging, probably have a cost associated with any CS change.
> Usually many messages in a row are to the same device.  Most devices
> don't care if CS pulses between messages.  Thus not pulsing CS between
> each message is faster.
> 
>>>
>>> Otherwise, this logic allows us to skip the spi of COMMAND1 which would
>>> normally be used to create the falling edge to start a new transaction,
>>> leaving the previous one open for more transfers.
>>
>> This sounds like something the SPI core should be managing. If a driver
>> is using the SPI bus to communicate with a device in a way that needs CS
>> left active while outside a transaction, it shouldn't be possible for
>> another driver to come along and communicate with another device before
>> the first transaction is all complete. The bus should be locked.
>> Allowing anything else could corrupt the protocol that required specific
>> CS states outside the transaction.
> 
> If the transaction is one message, which can be multiple transfers and
> multiple CS pulses, then the spi core always does it atomically.  The
> limitation is the driver can't get the result of the transaction until
> the entire transaction is finished.
> 
> If a driver needs to get part of a transaction to complete the rest,
> e.g. read a 16-bit length from the device and then read that many
> bytes, it can still be done.  It doesn't seem to be documented in
> spi-summary, but the way to do this is with spi_bus_(un)lock() and
> spi_(a)sync_locked() calls.  The driver must lock the bus, used the
> _locked versions to issue spi_messages, then unlock when done.  This
> should prevent another device on the bus from getting a messages, and
> thus CS pulses, in the middle of the transaction.

I suppose I can should reword my comment then on the code which checked:

+		if (tspi->cs_control) {
+			if (tspi->cs_control != spi)
+				tegra_spi_writel(tspi, command1, SPI_COMMAND1);

While this does do exactly what I said, ending a previous "on-going"
transaction in favor of a new one, this shouldn't be expected to be the
way for clients to guarantee that they have locked a bus. This is more
of a way internally to the Tegra SPI driver to clear its state.

-rhyland
-- 
nvpublic

WARNING: multiple messages have this Message-ID (diff)
From: Rhyland Klein <rklein@nvidia.com>
To: Trent Piepho <tpiepho@gmail.com>
Cc: Stephen Warren <swarren@wwwdotorg.org>,
	Simon Glass <sjg@chromium.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Olof Johansson <olof@lixom.net>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	"spi-devel-general@lists.sourceforge.net" 
	<spi-devel-general@lists.sourceforge.net>
Subject: Re: [RESEND] spi/tegra114: Correct support for cs_change
Date: Tue, 24 Sep 2013 12:33:48 -0400	[thread overview]
Message-ID: <5241BEEC.9000508@nvidia.com> (raw)
In-Reply-To: <CA+7tXiiNMwyQh9sCsW4Qkid9Tn8RTcQ-uUmNse+kK-PZro1pyQ@mail.gmail.com>

On 9/23/2013 7:08 PM, Trent Piepho wrote:
> On Mon, Sep 23, 2013 at 2:14 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
>>
>> That sounds broken. Normally, shouldn't CS assert before a transaction,
>> stay asserted during a transaction, then deassert after the transaction?
>> It shouldn't rise and fall very quickly in between parts of the transaction.
> 
> That is normal, where a transaction is a spi_message made up of
> multiple spi_transfers.  The cs_change bit for a transfer will insert
> a de-asserted pulse after a transfer or leave CS de-asserted after the
> last transfer.
> 
>>>>> need to generate a falling-edge to trigger the beginning of a SPI
>>>>> transaction. Doing this write with the default value of SPI_COMMAND1
>>>>> causes a brief rise and fall of CS, giving us our falling-edge.
> 
> I wonder, is the real problem that the spi layer allows CS to possibly
> remain asserted between transactions to the same device?  Normally you
> would expect it to be de-asserted at the end of a spi_message, but I
> believe the Linux spi semantics are that it may or may not actually be
> de-asserted at that time.  It only guarantees that is will be
> de-asserted before a message to a different device starts.
> 
> I guess this is supposed to be an optimization.  Some drivers, like
> gpio bit-banging, probably have a cost associated with any CS change.
> Usually many messages in a row are to the same device.  Most devices
> don't care if CS pulses between messages.  Thus not pulsing CS between
> each message is faster.
> 
>>>
>>> Otherwise, this logic allows us to skip the spi of COMMAND1 which would
>>> normally be used to create the falling edge to start a new transaction,
>>> leaving the previous one open for more transfers.
>>
>> This sounds like something the SPI core should be managing. If a driver
>> is using the SPI bus to communicate with a device in a way that needs CS
>> left active while outside a transaction, it shouldn't be possible for
>> another driver to come along and communicate with another device before
>> the first transaction is all complete. The bus should be locked.
>> Allowing anything else could corrupt the protocol that required specific
>> CS states outside the transaction.
> 
> If the transaction is one message, which can be multiple transfers and
> multiple CS pulses, then the spi core always does it atomically.  The
> limitation is the driver can't get the result of the transaction until
> the entire transaction is finished.
> 
> If a driver needs to get part of a transaction to complete the rest,
> e.g. read a 16-bit length from the device and then read that many
> bytes, it can still be done.  It doesn't seem to be documented in
> spi-summary, but the way to do this is with spi_bus_(un)lock() and
> spi_(a)sync_locked() calls.  The driver must lock the bus, used the
> _locked versions to issue spi_messages, then unlock when done.  This
> should prevent another device on the bus from getting a messages, and
> thus CS pulses, in the middle of the transaction.

I suppose I can should reword my comment then on the code which checked:

+		if (tspi->cs_control) {
+			if (tspi->cs_control != spi)
+				tegra_spi_writel(tspi, command1, SPI_COMMAND1);

While this does do exactly what I said, ending a previous "on-going"
transaction in favor of a new one, this shouldn't be expected to be the
way for clients to guarantee that they have locked a bus. This is more
of a way internally to the Tegra SPI driver to clear its state.

-rhyland
-- 
nvpublic

  parent reply	other threads:[~2013-09-24 16:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-18 18:17 [RESEND] spi/tegra114: Correct support for cs_change Rhyland Klein
2013-09-18 18:17 ` Rhyland Klein
2013-09-18 18:17 ` Rhyland Klein
     [not found] ` <1379528245-6283-1-git-send-email-rklein-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-09-23 18:51   ` Stephen Warren
2013-09-23 18:51     ` Stephen Warren
     [not found]     ` <52408DC8.3020407-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-09-23 19:48       ` Rhyland Klein
2013-09-23 19:48         ` Rhyland Klein
     [not found]         ` <52409B1E.3030405-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-09-23 19:58           ` Stephen Warren
2013-09-23 19:58             ` Stephen Warren
     [not found]             ` <52409D63.3020909-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-09-23 21:01               ` Rhyland Klein
2013-09-23 21:01                 ` Rhyland Klein
     [not found]                 ` <5240AC3A.9060206-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-09-23 21:14                   ` Stephen Warren
2013-09-23 21:14                     ` Stephen Warren
     [not found]                     ` <5240AF20.8030301-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-09-23 22:23                       ` Simon Glass
2013-09-23 22:24                       ` Simon Glass
2013-09-23 22:24                         ` Simon Glass
2013-09-23 23:08                       ` Trent Piepho
2013-09-23 23:08                         ` Trent Piepho
     [not found]                         ` <CA+7tXiiNMwyQh9sCsW4Qkid9Tn8RTcQ-uUmNse+kK-PZro1pyQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-09-24 16:33                           ` Rhyland Klein [this message]
2013-09-24 16:33                             ` Rhyland Klein

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=5241BEEC.9000508@nvidia.com \
    --to=rklein-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
    --cc=tpiepho-Re5JQEeQqe8AvxtiuMwx3w@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 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.