All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: david@lechnology.com
Subject: [PATCH 05/10] drm/tinydrm: Clean up tinydrm_spi_transfer()
Date: Wed, 17 Jul 2019 13:58:12 +0200	[thread overview]
Message-ID: <20190717115817.30110-6-noralf@tronnes.org> (raw)
In-Reply-To: <20190717115817.30110-1-noralf@tronnes.org>

Prep work before moving the function to mipi-dbi.

tinydrm_spi_transfer() was made to support one class of drivers in
drivers/staging/fbtft that has not been converted to DRM yet, so strip
away the unused functionality:
- Start byte (header) is not used.
- No driver relies on the automatic 16-bit byte swapping on little endian
  machines with SPI controllers only supporting 8 bits per word.

Other changes:
- No need to initialize ret
- No need for the WARN since mipi-dbi only uses 8 and 16 bpw.
- Use spi_message_init_with_transfers()

Cc: David Lechner <david@lechnology.com>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 .../gpu/drm/tinydrm/core/tinydrm-helpers.c    | 40 ++-----------------
 drivers/gpu/drm/tinydrm/ili9225.c             |  4 +-
 drivers/gpu/drm/tinydrm/mipi-dbi.c            |  4 +-
 include/drm/tinydrm/tinydrm-helpers.h         |  3 +-
 4 files changed, 9 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
index af5bec8861de..d95eb50fa9d4 100644
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
@@ -24,23 +24,18 @@
  * tinydrm_spi_transfer - SPI transfer helper
  * @spi: SPI device
  * @speed_hz: Override speed (optional)
- * @header: Optional header transfer
  * @bpw: Bits per word
  * @buf: Buffer to transfer
  * @len: Buffer length
  *
  * This SPI transfer helper breaks up the transfer of @buf into chunks which
- * the SPI master driver can handle. If the machine is Little Endian and the
- * SPI master driver doesn't support 16 bits per word, it swaps the bytes and
- * does a 8-bit transfer.
- * If @header is set, it is prepended to each SPI message.
+ * the SPI controller driver can handle.
  *
  * Returns:
  * Zero on success, negative error code on failure.
  */
 int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,
-			 struct spi_transfer *header, u8 bpw, const void *buf,
-			 size_t len)
+			 u8 bpw, const void *buf, size_t len)
 {
 	size_t max_chunk = spi_max_transfer_size(spi);
 	struct spi_transfer tr = {
@@ -48,43 +43,16 @@ int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,
 		.speed_hz = speed_hz,
 	};
 	struct spi_message m;
-	u16 *swap_buf = NULL;
 	size_t chunk;
-	int ret = 0;
+	int ret;
 
-	if (WARN_ON_ONCE(bpw != 8 && bpw != 16))
-		return -EINVAL;
-
-	if (bpw == 16 && !spi_is_bpw_supported(spi, 16)) {
-		tr.bits_per_word = 8;
-		if (tinydrm_machine_little_endian()) {
-			swap_buf = kmalloc(min(len, max_chunk), GFP_KERNEL);
-			if (!swap_buf)
-				return -ENOMEM;
-		}
-	}
-
-	spi_message_init(&m);
-	if (header)
-		spi_message_add_tail(header, &m);
-	spi_message_add_tail(&tr, &m);
+	spi_message_init_with_transfers(&m, &tr, 1);
 
 	while (len) {
 		chunk = min(len, max_chunk);
 
 		tr.tx_buf = buf;
 		tr.len = chunk;
-
-		if (swap_buf) {
-			const u16 *buf16 = buf;
-			unsigned int i;
-
-			for (i = 0; i < chunk / 2; i++)
-				swap_buf[i] = swab16(buf16[i]);
-
-			tr.tx_buf = swap_buf;
-		}
-
 		buf += chunk;
 		len -= chunk;
 
diff --git a/drivers/gpu/drm/tinydrm/ili9225.c b/drivers/gpu/drm/tinydrm/ili9225.c
index 7a8e1b4a37ee..21677e3ed38b 100644
--- a/drivers/gpu/drm/tinydrm/ili9225.c
+++ b/drivers/gpu/drm/tinydrm/ili9225.c
@@ -323,7 +323,7 @@ static int ili9225_dbi_command(struct mipi_dbi *mipi, u8 *cmd, u8 *par,
 
 	gpiod_set_value_cansleep(mipi->dc, 0);
 	speed_hz = mipi_dbi_spi_cmd_max_speed(spi, 1);
-	ret = tinydrm_spi_transfer(spi, speed_hz, NULL, 8, cmd, 1);
+	ret = tinydrm_spi_transfer(spi, speed_hz, 8, cmd, 1);
 	if (ret || !num)
 		return ret;
 
@@ -333,7 +333,7 @@ static int ili9225_dbi_command(struct mipi_dbi *mipi, u8 *cmd, u8 *par,
 	gpiod_set_value_cansleep(mipi->dc, 1);
 	speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num);
 
-	return tinydrm_spi_transfer(spi, speed_hz, NULL, bpw, par, num);
+	return tinydrm_spi_transfer(spi, speed_hz, bpw, par, num);
 }
 
 static const struct drm_simple_display_pipe_funcs ili9225_pipe_funcs = {
diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c
index ae31a5c9aa1b..8fb6ce4ca6fc 100644
--- a/drivers/gpu/drm/tinydrm/mipi-dbi.c
+++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c
@@ -926,7 +926,7 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, u8 *cmd,
 
 	gpiod_set_value_cansleep(mipi->dc, 0);
 	speed_hz = mipi_dbi_spi_cmd_max_speed(spi, 1);
-	ret = tinydrm_spi_transfer(spi, speed_hz, NULL, 8, cmd, 1);
+	ret = tinydrm_spi_transfer(spi, speed_hz, 8, cmd, 1);
 	if (ret || !num)
 		return ret;
 
@@ -936,7 +936,7 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, u8 *cmd,
 	gpiod_set_value_cansleep(mipi->dc, 1);
 	speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num);
 
-	return tinydrm_spi_transfer(spi, speed_hz, NULL, bpw, par, num);
+	return tinydrm_spi_transfer(spi, speed_hz, bpw, par, num);
 }
 
 /**
diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h
index 10b35375a009..708c5a7d51e0 100644
--- a/include/drm/tinydrm/tinydrm-helpers.h
+++ b/include/drm/tinydrm/tinydrm-helpers.h
@@ -42,7 +42,6 @@ int tinydrm_display_pipe_init(struct drm_device *drm,
 			      unsigned int rotation);
 
 int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,
-			 struct spi_transfer *header, u8 bpw, const void *buf,
-			 size_t len);
+			 u8 bpw, const void *buf, size_t len);
 
 #endif /* __LINUX_TINYDRM_HELPERS_H */
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-07-17 11:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-17 11:58 [PATCH 00/10] drm/tinydrm: Remove tinydrm.ko Noralf Trønnes
2019-07-17 11:58 ` [PATCH 01/10] drm: Add SPI connector type Noralf Trønnes
2019-07-17 19:24   ` David Lechner
2019-07-19  9:17   ` Daniel Vetter
2019-07-19 12:34     ` Noralf Trønnes
2019-07-19 12:39       ` Daniel Vetter
2019-07-17 11:58 ` [PATCH 02/10] drm/tinydrm: Use spi_is_bpw_supported() Noralf Trønnes
2019-07-17 11:58 ` [PATCH 03/10] drm/tinydrm: Remove spi debug buffer dumping Noralf Trønnes
2019-07-17 11:58 ` [PATCH 04/10] drm/tinydrm: Remove tinydrm_spi_max_transfer_size() Noralf Trønnes
2019-07-17 11:58 ` Noralf Trønnes [this message]
2019-07-17 13:09   ` [PATCH 05/10] drm/tinydrm: Clean up tinydrm_spi_transfer() Sam Ravnborg
2019-07-17 16:18     ` Noralf Trønnes
2019-07-17 18:13       ` Sam Ravnborg
2019-07-17 19:37   ` David Lechner
2019-07-17 11:58 ` [PATCH 06/10] drm/tinydrm: Move tinydrm_spi_transfer() Noralf Trønnes
2019-07-17 13:15   ` Sam Ravnborg
2019-07-17 16:20     ` Noralf Trønnes
2019-07-17 19:48   ` David Lechner
2019-07-18 12:14     ` Noralf Trønnes
2019-07-25 14:16       ` Noralf Trønnes
2019-07-25 14:29         ` David Lechner
2019-07-17 11:58 ` [PATCH 07/10] drm/tinydrm: Move tinydrm_machine_little_endian() Noralf Trønnes
2019-07-17 20:09   ` David Lechner
2019-07-18 12:20     ` Noralf Trønnes
2019-07-17 11:58 ` [PATCH 08/10] drm/tinydrm/repaper: Don't use tinydrm_display_pipe_init() Noralf Trønnes
2019-07-17 11:58 ` [PATCH 09/10] drm/tinydrm/mipi-dbi: Add mipi_dbi_init_with_formats() Noralf Trønnes
2019-07-17 20:38   ` David Lechner
2019-07-17 11:58 ` [PATCH 10/10] drm/tinydrm: Move tinydrm_display_pipe_init() to mipi-dbi Noralf Trønnes
2019-07-17 13:34   ` Sam Ravnborg
2019-07-17 20:46   ` David Lechner
2019-07-18 12:27     ` Noralf Trønnes
2019-07-17 13:31 ` [PATCH 00/10] drm/tinydrm: Remove tinydrm.ko Sam Ravnborg
2019-07-17 16:22   ` Noralf Trønnes

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=20190717115817.30110-6-noralf@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=david@lechnology.com \
    --cc=dri-devel@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.