stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Carlo Caione <ccaione@baylibre.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Kamlesh Gurudasani <kamlesh.gurudasani@gmail.com>,
	Sasha Levin <sashal@kernel.org>,
	airlied@gmail.com, daniel@ffwll.ch,
	dri-devel@lists.freedesktop.org
Subject: [PATCH AUTOSEL 6.2 08/60] drm/tiny: ili9486: Do not assume 8-bit only SPI controllers
Date: Sun, 26 Feb 2023 20:59:53 -0500	[thread overview]
Message-ID: <20230227020045.1045105-8-sashal@kernel.org> (raw)
In-Reply-To: <20230227020045.1045105-1-sashal@kernel.org>

From: Carlo Caione <ccaione@baylibre.com>

[ Upstream commit 77772e607522daa61f3af74df018559db75c43d6 ]

The pixel data for the ILI9486 is always 16-bits wide and it must be
sent over the SPI bus. When the controller is only able to deal with
8-bit transfers, this 16-bits data needs to be swapped before the
sending to account for the big endian bus, this is on the contrary not
needed when the SPI controller already supports 16-bits transfers.

The decision about swapping the pixel data or not is taken in the MIPI
DBI code by probing the controller capabilities: if the controller only
suppors 8-bit transfers the data is swapped, otherwise it is not.

This swapping/non-swapping is relying on the assumption that when the
controller does support 16-bit transactions then the data is sent
unswapped in 16-bits-per-word over SPI.

The problem with the ILI9486 driver is that it is forcing 8-bit
transactions also for controllers supporting 16-bits, violating the
assumption and corrupting the pixel data.

Align the driver to what is done in the MIPI DBI code by adjusting the
transfer size to the maximum allowed by the SPI controller.

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
Reviewed-by: Kamlesh Gurudasani <kamlesh.gurudasani@gmail.com>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20221116-s905x_spi_ili9486-v4-2-f86b4463b9e4@baylibre.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/tiny/ili9486.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/tiny/ili9486.c b/drivers/gpu/drm/tiny/ili9486.c
index 1bb847466b107..a63b15817f112 100644
--- a/drivers/gpu/drm/tiny/ili9486.c
+++ b/drivers/gpu/drm/tiny/ili9486.c
@@ -43,6 +43,7 @@ static int waveshare_command(struct mipi_dbi *mipi, u8 *cmd, u8 *par,
 			     size_t num)
 {
 	struct spi_device *spi = mipi->spi;
+	unsigned int bpw = 8;
 	void *data = par;
 	u32 speed_hz;
 	int i, ret;
@@ -56,8 +57,6 @@ static int waveshare_command(struct mipi_dbi *mipi, u8 *cmd, u8 *par,
 	 * The displays are Raspberry Pi HATs and connected to the 8-bit only
 	 * SPI controller, so 16-bit command and parameters need byte swapping
 	 * before being transferred as 8-bit on the big endian SPI bus.
-	 * Pixel data bytes have already been swapped before this function is
-	 * called.
 	 */
 	buf[0] = cpu_to_be16(*cmd);
 	gpiod_set_value_cansleep(mipi->dc, 0);
@@ -71,12 +70,18 @@ static int waveshare_command(struct mipi_dbi *mipi, u8 *cmd, u8 *par,
 		for (i = 0; i < num; i++)
 			buf[i] = cpu_to_be16(par[i]);
 		num *= 2;
-		speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num);
 		data = buf;
 	}
 
+	/*
+	 * Check whether pixel data bytes needs to be swapped or not
+	 */
+	if (*cmd == MIPI_DCS_WRITE_MEMORY_START && !mipi->swap_bytes)
+		bpw = 16;
+
 	gpiod_set_value_cansleep(mipi->dc, 1);
-	ret = mipi_dbi_spi_transfer(spi, speed_hz, 8, data, num);
+	speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num);
+	ret = mipi_dbi_spi_transfer(spi, speed_hz, bpw, data, num);
  free:
 	kfree(buf);
 
-- 
2.39.0


  parent reply	other threads:[~2023-02-27  2:01 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27  1:59 [PATCH AUTOSEL 6.2 01/60] drm: panel-orientation-quirks: Add quirk for Lenovo Yoga Tab 3 X90F Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 02/60] drm: panel-orientation-quirks: Add quirk for DynaBook K50 Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 03/60] drm/amd/display: Reduce expected sdp bandwidth for dcn321 Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 04/60] drm/amd/display: Revert Reduce delay when sink device not able to ACK 00340h write Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 05/60] drm/amd/display: Fix potential null-deref in dm_resume Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 06/60] drm/omap: dsi: Fix excessive stack usage Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 07/60] HID: Add Mapping for System Microphone Mute Sasha Levin
2023-02-27  1:59 ` Sasha Levin [this message]
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 09/60] drm/amd/display: Defer DIG FIFO disable after VID stream enable Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 10/60] drm/radeon: free iio for atombios when driver shutdown Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 11/60] drm/amd: Avoid BUG() for case of SRIOV missing IP version Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 12/60] drm/amdkfd: Page aligned memory reserve size Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 13/60] scsi: lpfc: Fix use-after-free KFENCE violation during sysfs firmware write Sasha Levin
2023-02-27  1:59 ` [PATCH AUTOSEL 6.2 14/60] Revert "fbcon: don't lose the console font across generic->chip driver switch" Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 15/60] drm/amd: Avoid ASSERT for some message failures Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 16/60] drm: amd: display: Fix memory leakage Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 17/60] drm/amd/display: fix mapping to non-allocated address Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 18/60] drm/msm/dp: Remove INIT_SETUP delay Sasha Levin
2023-02-27  9:12   ` Johan Hovold
2023-03-01 14:15     ` Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 19/60] HID: uclogic: Add frame type quirk Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 20/60] HID: uclogic: Add battery quirk Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 21/60] HID: uclogic: Add support for XP-PEN Deco Pro SW Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 22/60] HID: uclogic: Add support for XP-PEN Deco Pro MW Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 23/60] HID: multitouch: Add quirks for flipped axes Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 24/60] drm/msm/dsi: Add missing check for alloc_ordered_workqueue Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 25/60] drm: rcar-du: Add quirk for H3 ES1.x pclk workaround Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 26/60] drm: rcar-du: Fix setting a reserved bit in DPLLCR Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 27/60] drm/drm_print: correct format problem Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 28/60] drm/amd/display: Set hvm_enabled flag for S/G mode Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 29/60] drm/client: Test for connectors before sending hotplug event Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 30/60] habanalabs: extend fatal messages to contain PCI info Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 31/60] habanalabs: fix bug in timestamps registration code Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 32/60] docs/scripts/gdb: add necessary make scripts_gdb step Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 33/60] drm/msm/dpu: Add DSC hardware blocks to register snapshot Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 34/60] ASoC: soc-compress: Reposition and add pcm_mutex Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 35/60] ASoC: kirkwood: Iterate over array indexes instead of using pointer math Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 36/60] regulator: max77802: Bounds check regulator id against opmode Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 37/60] regulator: s5m8767: Bounds check id indexing into arrays Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 38/60] Revert "drm/amdgpu: TA unload messages are not actually sent to psp when amdgpu is uninstalled" Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 39/60] drm/amd/display: fix FCLK pstate change underflow Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 40/60] gfs2: Improve gfs2_make_fs_rw error handling Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 41/60] hwmon: (coretemp) Simplify platform device handling Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 42/60] hwmon: (nct6775) Directly call ASUS ACPI WMI method Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 43/60] hwmon: (nct6775) B650/B660/X670 ASUS boards support Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 44/60] pinctrl: at91: use devm_kasprintf() to avoid potential leaks Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 45/60] drm/amd/display: Do not set DRR on pipe commit Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 46/60] drm/amd/display: Do not commit pipe when updating DRR Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 47/60] scsi: snic: Fix memory leak with using debugfs_lookup() Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 48/60] scsi: ufs: core: Fix device management cmd timeout flow Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 49/60] HID: logitech-hidpp: Don't restart communication if not necessary Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 50/60] drm/amd/display: Move DCN314 DOMAIN power control to DMCUB Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 51/60] drm/amd/display: Enable P-state validation checks for DCN314 Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 52/60] drm: panel-orientation-quirks: Add quirk for Lenovo IdeaPad Duet 3 10IGL5 Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 53/60] drm/amd/display: Disable HUBP/DPP PG on DCN314 for now Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 54/60] drm/amd/display: disable SubVP + DRR to prevent underflow Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 55/60] dm thin: add cond_resched() to various workqueue loops Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 56/60] dm cache: " Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 57/60] nfsd: zero out pointers after putting nfsd_files on COPY setup error Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 58/60] nfsd: clean up potential nfsd_file refcount leaks in COPY codepath Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 59/60] nfsd: don't hand out delegation on setuid files being opened for write Sasha Levin
2023-02-27  2:00 ` [PATCH AUTOSEL 6.2 60/60] cifs: prevent data race in smb2_reconnect() Sasha Levin

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=20230227020045.1045105-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=airlied@gmail.com \
    --cc=ccaione@baylibre.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kamlesh.gurudasani@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=stable@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).