public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chris Packham <judge.packham@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] spi: kirkwood_spi: implement mvebu_spi_set_mode()
Date: Thu, 27 Oct 2016 21:16:05 +1300	[thread overview]
Message-ID: <20161027081605.26475-1-judge.packham@gmail.com> (raw)
In-Reply-To: <CAD6G_RQG2bkY9Wu33yX7cvDQomm4nUkXD+VXJRWpH8h_MJZRXw@mail.gmail.com>

Set the appropriate bits in the interface config register based
on the SPI_ mode flags.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
---

Changes in v2:
- Clear bits before updating

 arch/arm/include/asm/arch-mvebu/spi.h |  4 ++++
 drivers/spi/kirkwood_spi.c            | 15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/arch/arm/include/asm/arch-mvebu/spi.h b/arch/arm/include/asm/arch-mvebu/spi.h
index 78869a253d1f..3545aed17347 100644
--- a/arch/arm/include/asm/arch-mvebu/spi.h
+++ b/arch/arm/include/asm/arch-mvebu/spi.h
@@ -52,6 +52,10 @@ struct kwspi_registers {
 #define KWSPI_ADRLEN_3BYTE	(2 << 8)
 #define KWSPI_ADRLEN_4BYTE	(3 << 8)
 #define KWSPI_ADRLEN_MASK	(3 << 8)
+#define KWSPI_CPOL		(1 << 11)
+#define KWSPI_CPHA		(1 << 12)
+#define KWSPI_TXLSBF		(1 << 13)
+#define KWSPI_RXLSBF		(1 << 14)
 
 #define KWSPI_IRQUNMASK		1 /* unmask SPI interrupt */
 #define KWSPI_IRQMASK		0 /* mask SPI interrupt */
diff --git a/drivers/spi/kirkwood_spi.c b/drivers/spi/kirkwood_spi.c
index 6851ba942f51..791f3e8099c8 100644
--- a/drivers/spi/kirkwood_spi.c
+++ b/drivers/spi/kirkwood_spi.c
@@ -271,6 +271,21 @@ static int mvebu_spi_set_speed(struct udevice *bus, uint hz)
 
 static int mvebu_spi_set_mode(struct udevice *bus, uint mode)
 {
+	struct mvebu_spi_platdata *plat = dev_get_platdata(bus);
+	struct kwspi_registers *reg = plat->spireg;
+	u32 data = readl(&reg->cfg);
+
+	data &= ~(KWSPI_CPHA | KWSPI_CPOL | KWSPI_RXLSBF | KWSPI_TXLSBF);
+
+	if (mode & SPI_CPHA)
+		data |= KWSPI_CPHA;
+	if (mode & SPI_CPOL)
+		data |= KWSPI_CPOL;
+	if (mode & SPI_LSB_FIRST)
+		data |= (KWSPI_RXLSBF | KWSPI_TXLSBF);
+
+	writel(data, &reg->cfg);
+
 	return 0;
 }
 
-- 
2.10.1

  reply	other threads:[~2016-10-27  8:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14  3:19 [U-Boot] [PATCH] spi: kirkwood_spi: implement mvebu_spi_set_mode() Chris Packham
2016-10-18  5:29 ` Stefan Roese
2016-10-26  7:15 ` Jagan Teki
2016-10-27  8:16   ` Chris Packham [this message]
2016-10-27  9:41     ` [U-Boot] [PATCH v2] " Jagan Teki
2016-10-27  9:49       ` Chris Packham
2016-10-27  9:51         ` Stefan Roese
2016-10-27 10:09           ` Jagan Teki

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=20161027081605.26475-1-judge.packham@gmail.com \
    --to=judge.packham@gmail.com \
    --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