linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Sa, Nuno" <Nuno.Sa@analog.com>
To: "lukas@wunner.de" <lukas@wunner.de>,
	"wahrenst@gmx.net" <wahrenst@gmx.net>
Cc: "linux-spi@vger.kernel.org" <linux-spi@vger.kernel.org>,
	"bcm-kernel-feedback-list@broadcom.com" 
	<bcm-kernel-feedback-list@broadcom.com>,
	"broonie@kernel.org" <broonie@kernel.org>,
	"kernel@martin.sperl.org" <kernel@martin.sperl.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"sbranden@broadcom.com" <sbranden@broadcom.com>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	"rjui@broadcom.com" <rjui@broadcom.com>,
	"linux-rpi-kernel@lists.infradead.org" 
	<linux-rpi-kernel@lists.infradead.org>,
	"eric@anholt.net" <eric@anholt.net>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] spi: spi-bcm2835.c: Fix 3-wire mode
Date: Mon, 1 Jul 2019 07:24:23 +0000	[thread overview]
Message-ID: <54323339606a36febc6a8633a8d3a7db84b975c4.camel@analog.com> (raw)
In-Reply-To: <20190628190022.vya4h2lihm6x2xpb@wunner.de>

Hi Lukas and Stefan,

On Fri, 2019-06-28 at 21:00 +0200, Lukas Wunner wrote:
> 
> On Fri, Jun 28, 2019 at 05:23:54PM +0200, Stefan Wahren wrote:
> > Am 28.06.19 um 14:30 schrieb Nuno Sá:
> > > As stated in
> > > https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md,
> > > one of rx or tx buffer's must be null. However, if DMA is
> > > enabled, the
> > > driver sets the SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX
> > > on the
> > > controller flags. Hence, the spi core will provide dummy buffers
> > > even if
> > > one of the buffers was set to null by the device driver. Thus,
> > > the
> > > communication with the 3-wire device fails.
> > > 
> > > This patch uses the prepare_message callback to look for the
> > > device mode
> > > and sets/clears the SPI_CONTROLLER_MUST_RX |
> > > SPI_CONTROLLER_MUST_TX on a
> > > per spi message basis. It also assumes that DMA is not supported
> > > on
> > > half-duplex devices.
> > > 
> > > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> > 
> > i never tested the 3-wire mode. Could you please describe your test
> > setup?

I'm working on a rpi cape which uses this device 
https://github.com/analogdevicesinc/linux/blob/master/drivers/iio/frequency/adf4371.c
which is connected in 3-WIRE mode. I could confirm that spi was not
working.

> 
> __spi_validate() returns -EINVAL if 3-wire mode is used and both
> buffers
> are non-NULL, I guess that's the problem.

In my case, __spi_validate() was ok because my device driver is passing
one of rx or tx as NULL. The problem is in spi_map_msg() which
allocates dummy buffers (because of the ctrl flags). As a result, in
bcm2835_spi_transfer_one() we set "cs |= BCM2835_SPI_CS_REN;" when we
want to do tx only. I believe this was the actual problem...

> 
> 
> > @Martin, @Lukas Are you fine with this patch?
> 
> I have a patch set in the pipeline to drop SPI_CONTROLLER_MUST_RX
> and SPI_CONTROLLER_MUST_TX from spi-bcm2835.c.
> 
> Latest snapshot is available here (top-most 10 commits):
> https://github.com/l1k/linux/commits/revpi_staging
> 
> @Nuno, could you give this branch a spin and see if it fixes the
> issue for you?  If so, this might be a better solution.  Your patch
> is fine in principle since it works around the problem, but the
> patch set on the above-linked branch fixes it at the root.
> It also provides a nice welcome speedup and reduces resource
> consumption.
> 
> I've been working on this on-and-off for about half a year,
> I think the patch set is in pretty good shape now so I was
> planning to submit it probably in 2 weeks or so.
> 

This looks great. I will try to give this a try still today.

> Thanks,
> 
> Lukas

Regards,
Nuno Sá

  reply	other threads:[~2019-07-01 11:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-28 12:30 [PATCH] spi: spi-bcm2835.c: Fix 3-wire mode Nuno Sá
2019-06-28 15:23 ` Stefan Wahren
2019-06-28 19:00   ` Lukas Wunner
2019-07-01  7:24     ` Sa, Nuno [this message]
2019-07-01 11:55       ` Lukas Wunner
2019-07-01 14:21         ` Sa, Nuno
2019-07-03 10:43           ` Lukas Wunner

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=54323339606a36febc6a8633a8d3a7db84b975c4.camel@analog.com \
    --to=nuno.sa@analog.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=broonie@kernel.org \
    --cc=eric@anholt.net \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@martin.sperl.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=wahrenst@gmx.net \
    /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).