linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Geert Uytterhoeven <geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Geert Uytterhoeven
	<geert+renesas-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
Subject: Re: [PATCH V2 4/8] spi: rspi: Add support for 8-bit Data Register access
Date: Mon, 13 Jan 2014 12:29:12 +0000	[thread overview]
Message-ID: <20140113122912.GT29039@sirena.org.uk> (raw)
In-Reply-To: <1389522464-1569-5-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1492 bytes --]

On Sun, Jan 12, 2014 at 11:27:40AM +0100, Geert Uytterhoeven wrote:

> +static void rspi_write_data(const struct rspi_data *rspi, u16 data)
> +{
> +	if (rspi->data_width == 8)
> +		rspi_write8(rspi, data, RSPI_SPDR);
> +	else /* 16 bit only */
> +		rspi_write16(rspi, data, RSPI_SPDR);
> +}

A switch statement is the more natural way of writing this.

> +static int rspi_parse_platform_data(struct rspi_data *rspi,
> +				    const struct rspi_plat_data *rspi_pd)
> +{
> +	if (rspi_pd && rspi_pd->data_width) {
> +		rspi->data_width = rspi_pd->data_width;
> +		switch (rspi_pd->data_width) {
> +		case 8:
> +			rspi->spdcr = SPDCR_SPLBYTE;
> +			break;
> +		case 16:
> +			rspi->spdcr = SPDCR_SPLWORD;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +	} else {
> +		/*
> +		 * Use legacy 16-bit width data access if a data_width value
> +		 * isn't defined in the platform data.
> +		 */
> +		rspi->data_width = 16;
> +		rspi->spdcr = 0;
> +	}

This looks very strange - if no platform data is specified the value set
for spdcr is one that can't be arrived at via platform data.  What's
going on here?  It'd seem more idiomatic to treat missing platform data
and a zero data_width identically too.

> +	ret = ops->parse_platform_data(rspi, rspi_pd);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "rspi invalid platform data.\n");
> +		goto error1;
> +	}

I'd move the error logging up into the parse function and have it say
what exactly is wrong - that'd be more friendly to users.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2014-01-13 12:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-12 10:27 [PATCH V2 0/8] spi: rspi: Add support for RZ/A1H Geert Uytterhoeven
     [not found] ` <1389522464-1569-1-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-01-12 10:27   ` [PATCH V2 1/8] spi: rspi: Add more RSPI register documentation Geert Uytterhoeven
2014-01-13 12:10     ` Mark Brown
2014-01-12 10:27   ` [PATCH V2 2/8] spi: rspi: Add more QSPI " Geert Uytterhoeven
     [not found]     ` <1389522464-1569-3-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-01-13 12:10       ` Mark Brown
2014-01-12 10:27   ` [PATCH V2 3/8] spi: rspi: Add support for more than one interrupt Geert Uytterhoeven
     [not found]     ` <1389522464-1569-4-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-01-13 12:16       ` Mark Brown
2014-01-12 10:27   ` [PATCH V2 4/8] spi: rspi: Add support for 8-bit Data Register access Geert Uytterhoeven
     [not found]     ` <1389522464-1569-5-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-01-13 12:29       ` Mark Brown [this message]
     [not found]         ` <20140113122912.GT29039-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-01-13 13:29           ` Geert Uytterhoeven
     [not found]             ` <CAMuHMdViLJD9O4gnovR6x7RTWor9GYPBZuzP5X7JmVw5g=o4kw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-13 15:55               ` Mark Brown
2014-01-13 19:05                 ` Geert Uytterhoeven
2014-01-12 10:27   ` [PATCH V2 7/8] spi: rspi: Add support for specifying CPHA/CPOL Geert Uytterhoeven
2014-01-13 17:23     ` Mark Brown
2014-01-12 10:27   ` [PATCH V2 8/8] spi: rspi: Add support for loopback mode Geert Uytterhoeven
2014-01-12 10:27 ` [PATCH V2 5/8] spi: rspi: Add support for no TX only mode Geert Uytterhoeven
2014-01-12 10:27 ` [PATCH V2 6/8] spi: rspi: Add support for missing SPCR2 register Geert Uytterhoeven
     [not found]   ` <1389522464-1569-7-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-01-13 12:36     ` Sergei Shtylyov
     [not found]       ` <52D3DDDB.309-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
2014-01-19 11:39         ` Geert Uytterhoeven

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=20140113122912.GT29039@sirena.org.uk \
    --to=broonie-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=geert+renesas-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
    --cc=geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
    --cc=linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@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 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).