linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcus Folkesson <marcus.folkesson@gmail.com>
To: Lee Jones <lee.jones@linaro.org>
Cc: linux-kernel@vger.kernel.org,
	Marcus Folkesson <marcus.folkesson@gmail.com>
Subject: [PATCH] mfd: mc13xxx-spi: make SPI buffers DMA-safe
Date: Fri,  9 Dec 2016 11:24:58 +0100	[thread overview]
Message-ID: <20161209102458.30696-1-marcus.folkesson@gmail.com> (raw)

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
 drivers/mfd/mc13xxx-spi.c | 14 +++++++-------
 drivers/mfd/mc13xxx.h     |  4 ++++
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c
index cbc1e5ed599c..f6bfbee9d9ef 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -63,14 +63,13 @@ static const struct regmap_config mc13xxx_regmap_spi_config = {
 static int mc13xxx_spi_read(void *context, const void *reg, size_t reg_size,
 				void *val, size_t val_size)
 {
-	unsigned char w[4] = { *((unsigned char *) reg), 0, 0, 0};
-	unsigned char r[4];
 	unsigned char *p = val;
 	struct device *dev = context;
 	struct spi_device *spi = to_spi_device(dev);
+	struct mc13xxx *mc13xxx = dev_get_drvdata(dev);
 	struct spi_transfer t = {
-		.tx_buf = w,
-		.rx_buf = r,
+		.tx_buf = mc13xxx->wbuf,
+		.rx_buf = mc13xxx->rbuf,
 		.len = 4,
 	};
 
@@ -80,11 +79,12 @@ static int mc13xxx_spi_read(void *context, const void *reg, size_t reg_size,
 	if (val_size != 3 || reg_size != 1)
 		return -ENOTSUPP;
 
+	mc13xxx->wbuf[0] = *(unsigned char *)reg;
 	spi_message_init(&m);
 	spi_message_add_tail(&t, &m);
 	ret = spi_sync(spi, &m);
 
-	memcpy(p, &r[1], 3);
+	memcpy(p, &mc13xxx->rbuf[1], 3);
 
 	return ret;
 }
@@ -100,9 +100,9 @@ static int mc13xxx_spi_write(void *context, const void *data, size_t count)
 
 	/* include errata fix for spi audio problems */
 	if (*reg == MC13783_AUDIO_CODEC || *reg == MC13783_AUDIO_DAC)
-		spi_write(spi, data, count);
+		spi_write_then_read(spi, data, count, NULL, 0);
 
-	return spi_write(spi, data, count);
+	return spi_write_then_read(spi, data, count, NULL, 0);
 }
 
 /*
diff --git a/drivers/mfd/mc13xxx.h b/drivers/mfd/mc13xxx.h
index 33677d1dcf66..1b35632e1d7e 100644
--- a/drivers/mfd/mc13xxx.h
+++ b/drivers/mfd/mc13xxx.h
@@ -44,6 +44,10 @@ struct mc13xxx {
 	int flags;
 
 	int adcflags;
+#ifdef CONFIG_MFD_MC13XXX_SPI
+	unsigned char wbuf[4] ____cacheline_aligned;
+	unsigned char rbuf[4];
+#endif
 };
 
 int mc13xxx_common_init(struct device *dev);
-- 
2.11.0.rc2

             reply	other threads:[~2016-12-09 10:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-09 10:24 Marcus Folkesson [this message]
2016-12-09 10:25 [PATCH] mfd: mc13xxx-spi: make SPI buffers DMA-safe Marcus Folkesson
2016-12-19 22:43 ` kbuild test robot

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=20161209102458.30696-1-marcus.folkesson@gmail.com \
    --to=marcus.folkesson@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.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).