linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Phil Elwell <phil@raspberrypi.org>,
	Oskar Andero <oskar.andero@gmail.com>,
	Andrea Galbusera <gizero@gmail.com>,
	Akinobu Mita <akinobu.mita@gmail.com>,
	Manfred Schlaegl <manfred.schlaegl@gmx.at>,
	Michael Welling <mwelling@ieee.org>,
	Soeren Andersen <san@rosetechnology.dk>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH 6/6] iio: adc: mcp320x: Add support for mcp3550/1/3
Date: Sun, 10 Sep 2017 14:40:22 +0100	[thread overview]
Message-ID: <20170910144022.5a608d94@archlinux> (raw)
In-Reply-To: <20170907064450.GA15733@wunner.de>

On Thu, 7 Sep 2017 08:44:50 +0200
Lukas Wunner <lukas@wunner.de> wrote:

> On Sun, Sep 03, 2017 at 03:22:39PM +0100, Jonathan Cameron wrote:
> > On Tue, 22 Aug 2017 15:33:00 +0200 Lukas Wunner <lukas@wunner.de> wrote:  
> > > After power-on reset, the chip sometimes fails to perform conversions
> > > and clocks out "all ones".  For some reason it can be unwedged by
> > > carrying out two consecutive conversions, without any delay between them.  
> > 
> > Put this description inline in the driver.
> >   
> > > If there is a delay the chip stays wedged.  I tried various other things
> > > to no avail, such as extending the conversion time, extending the CS
> > > assertion time to start a conversion or clocking out a few bytes.
> > > This may be an undocumented bug in the chip's internal state machine,
> > > possibly caused by the SPI pins' state on boot of the bcm2837.
> > > The driver unconditionally performs these two conversions on ->probe to
> > > ascertain all subsequent conversions succeed.  On platforms that support
> > > system sleep, it may be necessary to repeat this procedure upon resume.  
> [snip]
> > > +		/* perform two consecutive conversions to unwedge device */
> > > +		mcp320x_adc_conversion(adc, 0, 1, device_index, &val);
> > > +		mcp320x_adc_conversion(adc, 0, 1, device_index, &val);  
> > 
> > That needs more explanation.  Why would the device need unwedging?  
> 
> The pin controller on the BCM2835 (Raspberry Pi) by default initializes
> all GPIOs to direction "input" with pull down.  Thus, when the machine
> boots, the CS pin is either floating or low until the SPI master is
> initialized, which happens several seconds after power-on.  (I recall
> seeing on the oscilloscope that CS was initially low and then jumped
> to high on SPI master initialization, so the pin is probably not floating
> but low on boot.)
> 
> Per the spec, if CS is asserted for prolonged time the chip enters
> continuous conversion mode.  If CS is then driven high, the chip goes
> into shutdown (Fig 5-3, page 22 of the datasheet).
> 
> If CS is subsequently driven low again, the chip should wake up and
> start a conversion, but sometimes it doesn't and clocks out 0xffffff.
> Thus, about 50% of the time the chip would not work after boot.
> To me this looks like a bug in the chip's internal state machine.
> 
> By accident I've found that performing two conversions without any
> delay between them causes the chip to work again.
> 
> It's possible to change the initial pin controller configuration
> of the BCM2835 by supplying a dt-blob.bin which is consumed by the
> firmware.  If I set the initial configuration of the CS pin to output /
> active-low, the chip *always* works on boot.  However it seems fragile
> to depend on proper pin configuration, hence I've decided to always
> reset the chip on ->probe using the two conversion magic sequence.

It is certainly preferable to not have to rely on correct initialization
but there are numerous cases where it is true with other hardware.

Good to put a workaround in place if one is known though - like here!
> 
> I will expand the comment as requested.

Great, will be good to not lose the hard work you've done to come
up with a workaround!

> 
> These pin issues suggest that switching back and forth between single
> conversion and continuous conversion may not work as expected.  The chip
> is hairy and I'm glad that I have it working reliably now in single
> conversion mode.  The boards I have here aren't designed to run it in
> continuous conversion mode, so I can't really test that.  I've moved
> support for it to a separate commit and will mark it informational when
> posting, that commit is not intended for merging but merely to get others
> started who have a suitable board.
> 
> 
> > > @@ -398,6 +517,10 @@ static const struct spi_device_id mcp320x_id[] = {
> > >  	{ "mcp3204", mcp3204 },
> > >  	{ "mcp3208", mcp3208 },
> > >  	{ "mcp3301", mcp3301 },
> > > +	{ "mcp3550-50", mcp3550_50 },
> > > +	{ "mcp3550-60", mcp3550_60 },  
> > 
> > From a kernel point of view do we care if they have 50Hz or 60Hz rejection?
> > i.e. do we want to represent the two models, or are we better off with
> > just mcp3350?  
> 
> The 50 Hz and 60 Hz versions have different conversion times, hence the
> distinction.
> 
> Thanks a lot for the review,
> 
> Lukas


      reply	other threads:[~2017-09-10 13:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-22 13:33 [PATCH 0/6] IIO driver for MCP3550/1/3 Lukas Wunner
2017-08-22 13:33 ` [PATCH 3/6] iio: adc: mcp320x: Speed up readout of single-channel ADCs Lukas Wunner
2017-09-03 13:48   ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 4/6] iio: adc: mcp320x: Drop unnecessary of_device_id attributes Lukas Wunner
2017-09-03 13:59   ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 2/6] iio: adc: mcp320x: Fix readout of negative voltages Lukas Wunner
2017-09-03 13:44   ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 1/6] iio: adc: mcp320x: Fix oops on module unload Lukas Wunner
2017-09-03 13:41   ` Jonathan Cameron
2017-08-22 13:33 ` [PATCH 5/6] dt-bindings: iio: adc: mcp320x: Update for mcp3550/1/3 Lukas Wunner
2017-08-25 19:59   ` Rob Herring
2017-08-27 15:34     ` Lukas Wunner
2017-08-29  7:21       ` Adriana Reus
2017-09-03 13:37         ` Jonathan Cameron
2017-09-03 18:20           ` Lukas Wunner
2017-09-04 12:36             ` Jonathan Cameron
2017-09-04 17:22           ` Mark Brown
2017-09-10 13:36             ` Jonathan Cameron
2017-09-05 18:49       ` Rob Herring
2017-08-22 13:33 ` [PATCH 6/6] iio: adc: mcp320x: Add support " Lukas Wunner
2017-09-03 14:22   ` Jonathan Cameron
2017-09-07  6:44     ` Lukas Wunner
2017-09-10 13:40       ` Jonathan Cameron [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=20170910144022.5a608d94@archlinux \
    --to=jic23@kernel.org \
    --cc=akinobu.mita@gmail.com \
    --cc=gizero@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=manfred.schlaegl@gmx.at \
    --cc=mwelling@ieee.org \
    --cc=oskar.andero@gmail.com \
    --cc=phil@raspberrypi.org \
    --cc=pmeerw@pmeerw.net \
    --cc=san@rosetechnology.dk \
    /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).