public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Jérôme Carretero" <cJ-uboot@zougloub.eu>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] davinci/spi: allow usage of other chip selects and buses
Date: Sun, 8 Apr 2012 17:22:52 -0400	[thread overview]
Message-ID: <20120408172252.113ecc48@Bidule> (raw)

Use the spi_slave bus and cs attributes, reduce C2T/T2C delays,
allow overriding of spi_cs_is_valid().

As it is, this patch breaks the configuration files for DaVinci boards
that only use SPI1.

Signed-off-by: J?r?me Carretero <cJ@zougloub.eu>
CC: Manjunathappa, Prakash <prakash.pm@ti.com>
--
 drivers/spi/davinci_spi.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
index 13aca52..74f385e 100644
--- a/drivers/spi/davinci_spi.c
+++ b/drivers/spi/davinci_spi.c
@@ -23,6 +23,9 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  * MA 02111-1307 USA
+ *
+ * References: SPRUH77 Chapter 30
+ *
  */
 #include <common.h>
 #include <spi.h>
@@ -50,7 +53,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
 	ds->slave.bus = bus;
 	ds->slave.cs = cs;
-	ds->regs = (struct davinci_spi_regs *)CONFIG_SYS_SPI_BASE;
+	ds->regs = (struct davinci_spi_regs *)(bus == 0 ? DAVINCI_SPI0_BASE : DAVINCI_SPI1_BASE);
 	ds->freq = max_hz;
 
 	return &ds->slave;
@@ -67,6 +70,7 @@ int spi_claim_bus(struct spi_slave *slave)
 {
 	struct davinci_spi_slave *ds = to_davinci_spi(slave);
 	unsigned int scalar;
+	unsigned int cs;
 
 	/* Enable the SPI hardware */
 	writel(SPIGCR0_SPIRST_MASK, &ds->regs->gcr0);
@@ -76,8 +80,9 @@ int spi_claim_bus(struct spi_slave *slave)
 	/* Set master mode, powered up and not activated */
 	writel(SPIGCR1_MASTER_MASK | SPIGCR1_CLKMOD_MASK, &ds->regs->gcr1);
 
+	cs = BIT(slave->cs); /* SPIPC0_EN0FUN_MASK ... */
 	/* CS, CLK, SIMO and SOMI are functional pins */
-	writel((SPIPC0_EN0FUN_MASK | SPIPC0_CLKFUN_MASK |
+	writel((cs | SPIPC0_CLKFUN_MASK |
 		SPIPC0_DOFUN_MASK | SPIPC0_DIFUN_MASK), &ds->regs->pc0);
 
 	/* setup format */
@@ -97,11 +102,11 @@ int spi_claim_bus(struct spi_slave *slave)
 	 * Including a minor delay. No science here. Should be good even with
 	 * no delay
 	 */
-	writel((50 << SPI_C2TDELAY_SHIFT) |
-		(50 << SPI_T2CDELAY_SHIFT), &ds->regs->delay);
+	writel((10 << SPI_C2TDELAY_SHIFT) |
+		(10 << SPI_T2CDELAY_SHIFT), &ds->regs->delay);
 
 	/* default chip select register */
-	writel(SPIDEF_CSDEF0_MASK, &ds->regs->def);
+	writel(cs, &ds->regs->def);
 
 	/* no interrupts */
 	writel(0, &ds->regs->int0);
@@ -280,6 +285,7 @@ out:
 	return 0;
 }
 
+__attribute__((weak))
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
 	return bus == 0 && cs == 0;
-- 
1.7.9.4

             reply	other threads:[~2012-04-08 21:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-08 21:22 Jérôme Carretero [this message]
2012-04-09 16:24 ` [U-Boot] [PATCH] davinci/spi: allow usage of other chip selects and buses Tom Rini

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=20120408172252.113ecc48@Bidule \
    --to=cj-uboot@zougloub.eu \
    --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