public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Guennadi Liakhovetski <g.liakhovetski@pengutronix.de>
Cc: linux-kernel@vger.kernel.org, spi-devel-general@lists.sourceforge.net
Subject: Re: [PATCH] gpio: gpio driver for max7301 SPI GPIO expander
Date: Thu, 12 Jun 2008 00:15:50 -0700	[thread overview]
Message-ID: <200806120015.50953.david-b@pacbell.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0806061625260.3338@axis700.grange>

Some comments about one routine; presumably more to follow:


On Friday 06 June 2008, Guennadi Liakhovetski wrote:
> +/**
> + * max7301_read - Read back register content
> + * @spi: The SPI device
> + * @reg: Register offset
> + *
> + * A read from the MAX7301 means one message with two transfers

That's not what you implement though ... what it needs is:

	- transfer #1:
		* select
		* write 16 bit command, discard rx data
		* deselect
	- transfer #2
		* select
		* write 16 bit command, saving rx data
		* deselect

That's from the data sheet.  Now, that *could* be implemented
with a single message ... or, as you do, with two messages.

You should at least correct the comment, if you don't want to
switch to a slightly faster single-message implementation.  :)


> + *
> + * Returns positive 8 bit value from device if successfull or a
> + * negative value on error

Actually it returns a 16 bit value... also, "successful" has one "l".
You seem to have forgotten to mask off the high byte ...


> + */
> +static int max7301_read(struct spi_device *spi, unsigned int reg)
> +{
> +       int ret;
> +       u16 word;
> +
> +       word = 0x8000 | (reg << 8);
> +       if ((ret = spi_write(spi, (const u8*)&word, siz

> eof(word))) != 0) 
> +               return ret;
> +       /*
> +        * FIXME: This read should write 0x0000 (=NOOP at MAX7301 side)

Take out this FIXME, and just replace it with a note that this relies
on the fact that TX always shifts out zeroes if there's no data specified.

> +        */
> +       if ((ret = spi_read(spi, (u8*)&word, sizeof(word))))
> +               return ret;
> +       return word;
> +}
> +


Oh, and in the probe():

> +       spi->master->setup(spi);

should be

	ret = spi_setup(spi);
	if (ret < 0)
		return ret;

It's quite possible that something get misconfigured, so you end up trying
to talk through a spi_master controller that doesn't support 16-bit words.

- Dave


  reply	other threads:[~2008-06-12  7:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-06 14:37 [PATCH] gpio: gpio driver for max7301 SPI GPIO expander Guennadi Liakhovetski
2008-06-12  7:15 ` David Brownell [this message]
2008-06-12  8:00   ` Guennadi Liakhovetski
2008-06-12 13:13   ` [PATCH -mm] max7301: check spi_setup() return code, general cleanup Guennadi Liakhovetski

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=200806120015.50953.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=g.liakhovetski@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spi-devel-general@lists.sourceforge.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