public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] spi: add altera spi controller support
Date: Tue, 23 Mar 2010 17:29:06 -0400	[thread overview]
Message-ID: <201003231729.07252.vapier@gentoo.org> (raw)
In-Reply-To: <1269315379-6378-1-git-send-email-thomas@wytron.com.tw>

On Monday 22 March 2010 23:36:19 Thomas Chou wrote:
> +#include <common.h>
> +#include <malloc.h>
> +#include <spi.h>
> +#include <asm/io.h>
> +#include <nios2-io.h>

side note, but am i the only one who thinks nios headers in include/ is bad 
mojo ?

> +static nios_spi_t *nios_spi = (nios_spi_t *)CONFIG_SYS_SPI_BASE;

shouldnt this be based on the bus # so that you can support multiple ones at 
runtime ?  i.e. you add a regs member to the spi slave struct and operate off 
that at runtime.

> +void spi_init (void)

i think the spaces should be consumed before the paren per LKML style

> +{
> +	/* empty read buffer */
> +	if (readl (&nios_spi->status) & NIOS_SPI_RRDY)
> +		readl (&nios_spi->rxdata);
> +	return;
> +}

useless return ...

> +struct spi_slave *spi_setup_slave (unsigned int bus, unsigned int cs,
> +				  unsigned int max_hz, unsigned int mode)
> +{
> +	struct spi_slave *slave;
> +
> +	slave = malloc (sizeof(struct spi_slave));

sizeof(*slave)

> +	if (!slave)
> +		return NULL;
> +
> +	slave->bus = bus;
> +	slave->cs = cs;
> +
> +	return slave;
> +}

shouldnt you be validating the bus/cs values here ?  presumably you only have 
1 bus atm, so bus != 0 is an error.  and the cs is being used to write to an 
"unsigned slaveselect", so the range of values is at most 0...31 inclusive 
(assuming your hardware can actually support 32 CS's).

> +int spi_claim_bus (struct spi_slave *slave)
> +{
> +	return 0;
> +}
> +
> +void spi_release_bus (struct spi_slave *slave)
> +{
> +	return;
> +}

i'm pretty sure you should be programming either nios_spi->slaveselect or 
nios_spi->control here rather than in the spi_xfer func ...

> +int spi_xfer (struct spi_slave *slave, unsigned int bitlen, const void
> *dout, +	     void *din, unsigned long flags)
> +{
> +	int i, iter = bitlen >> 3;
> +	const uchar *txp = dout;
> +	uchar *rxp = din;
> +	uchar d;
> +
> +	if (flags & SPI_XFER_BEGIN) {
> +		writel (1 << slave->cs, &nios_spi->slaveselect);
> +		writel (NIOS_SPI_SSO, &nios_spi->control);
> +	}
> +
> +	for (i = 0; i < iter; i++) {
> +		writel (txp ? txp[i] : 0, &nios_spi->txdata);
> +		while (!(readl (&nios_spi->status) & NIOS_SPI_RRDY))
> +			;
> +		d = readl (&nios_spi->rxdata);
> +		if (rxp)
> +			rxp[i] = d;
> +	}
> +	if (flags & SPI_XFER_END)
> +		writel (0, &nios_spi->control);
> +
> +	return 0;
> +}

since you only support multiples of 8 bytes here, your code should return an 
error when (bitlen & 0x7)

your XFER_END should force the CS to go low ... is that what the control does, 
or is it the slaveselect ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20100323/c7acb0fe/attachment.pgp 

  parent reply	other threads:[~2010-03-23 21:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-23  3:36 [U-Boot] [PATCH v2] spi: add altera spi controller support Thomas Chou
2010-03-23 20:05 ` Scott McNutt
2010-03-23 21:29 ` Mike Frysinger [this message]
2010-03-23 21:43   ` Scott McNutt
2010-03-26  3:23 ` [U-Boot] [PATCH v3] " Thomas Chou
2010-03-26  3:31   ` Mike Frysinger
2010-03-26  5:55 ` [U-Boot] [PATCH v4] " Thomas Chou
2010-03-28  4:08 ` [U-Boot] [PATCH v5 tabify] " Thomas Chou
2010-04-22  4:21 ` [U-Boot] [PATCH v6] " Thomas Chou
2010-04-22  4:39 ` [U-Boot] [PATCH v7] " Thomas Chou
2010-04-27  2:01 ` [U-Boot] [PATCH v8] " Thomas Chou
2010-04-28  2:45 ` [U-Boot] [PATCH v9] " Thomas Chou

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=201003231729.07252.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=u-boot@lists.denx.de \
    /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