mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH] spi: omap: support swapping D0/D1
Date: Thu, 15 May 2014 08:11:10 +0200	[thread overview]
Message-ID: <1400134270-21234-1-git-send-email-s.hauer@pengutronix.de> (raw)

From: Jan Luebbe <jlu@pengutronix.de>

The OMAP SPI core allows swapping MISO/MOSI and some boards are
wired up that way, so add a property to swap the lines.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/spi/omap3_spi.c | 24 ++++++++++++++++++++++--
 drivers/spi/omap3_spi.h |  1 +
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 073a98f..c62288b 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -106,8 +106,15 @@ int spi_claim_bus(struct spi_device *spi)
 	/* standard 4-wire master mode:	SCK, MOSI/out, MISO/in, nCS
 	 * REVISIT: this controller could support SPI_3WIRE mode.
 	 */
-	conf &= ~(OMAP3_MCSPI_CHCONF_IS|OMAP3_MCSPI_CHCONF_DPE1);
-	conf |= OMAP3_MCSPI_CHCONF_DPE0;
+	if (omap3_master->swap_miso_mosi) {
+		/* swapped */
+		conf |= (OMAP3_MCSPI_CHCONF_IS | OMAP3_MCSPI_CHCONF_DPE1);
+		conf &= ~OMAP3_MCSPI_CHCONF_DPE0;
+	} else {
+		 /* bootloader default */
+		conf &= ~(OMAP3_MCSPI_CHCONF_IS | OMAP3_MCSPI_CHCONF_DPE1);
+		conf |= OMAP3_MCSPI_CHCONF_DPE0;
+	}
 
 	/* wordlength */
 	conf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
@@ -343,6 +350,17 @@ static int omap3_spi_setup(struct spi_device *spi)
 	return 0;
 }
 
+static int omap3_spi_probe_dt(struct device_d *dev, struct omap3_spi_master *omap3_master)
+{
+	if (!IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node)
+		return -ENODEV;
+
+	if (of_property_read_bool(dev->device_node, "ti,pindir-d0-out-d1-in"))
+		omap3_master->swap_miso_mosi = 1;
+
+	return 0;
+}
+
 static int omap3_spi_probe(struct device_d *dev)
 {
 	struct spi_master *master;
@@ -356,6 +374,8 @@ static int omap3_spi_probe(struct device_d *dev)
 
 	omap3_master = xzalloc(sizeof(*omap3_master));
 
+	omap3_spi_probe_dt(dev, omap3_master);
+
 	master = &omap3_master->master;
 	master->dev = dev;
 
diff --git a/drivers/spi/omap3_spi.h b/drivers/spi/omap3_spi.h
index ce4a29b..6fd6bda 100644
--- a/drivers/spi/omap3_spi.h
+++ b/drivers/spi/omap3_spi.h
@@ -93,6 +93,7 @@ struct omap3_spi_master {
 			     * offset of 0x100 between start of register space
 			     * and registers
 			     */
+	int swap_miso_mosi;
 };
 
 #endif /* _OMAP3_SPI_H_ */
-- 
2.0.0.rc0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2014-05-15  6:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1400134270-21234-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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