Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7140420rwb; Tue, 6 Dec 2022 01:32:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf77yVSMLpdwC7CC+dSdr6EVj8ep5Yi5WGxTzoeTHZGJxeEKkWzLZE7YQqzQdAWKRItNcqeq X-Received: by 2002:a17:90a:62c2:b0:20d:bc7f:4fee with SMTP id k2-20020a17090a62c200b0020dbc7f4feemr100930688pjs.168.1670319148374; Tue, 06 Dec 2022 01:32:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670319148; cv=none; d=google.com; s=arc-20160816; b=PyCc3RQvG8rILxcu3N+4EJPA7DbKxsGE+lDeTP587J56kQUainByO5NKP2lJDKpqTp LQyyy0qvfbVX55xVOajx0FO8FWF+B48PWYQrs+OH/KJQyD9aZtZgBqKHqaC9Z9+6vo9W ELaowMZydl6fTsR3pUI3GW6RYGxu3buk51L/yAdI7OH+zRHQwloNlJpbKNH2Hy+U3JkS t//nU5Knn57DmQhHVa60QFr9ypJOPpogMBLVMioF2fKwGmaf7ZYnT7KDVPkunLmO44k1 9CA9Ly8Nq7m1l9KFIss9lA1dNe4sgg8McCh3vSFOOypBS4xJtV4gBLrKec6Sf+gom43a /ZlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=6+091FGCQ4rhzDvkB3AYfkA+OM7BJLCJxULLW5x6V0Y=; b=aR4BSp766dOVAnem/5edddIU+WdRXgmR3I/wfibrBCHjkMLJgnhX4I7BOhAxEkkpDz xjSWD/mSIyI7ieT8kOwzxqIXSwPoEMj0NmwOOStqPlmbetuD+u3PdM8OB9Bv0/y8oO0Z P4fAuiDZQbyMRqx1QzdabaHxUHfdsUBWKtILDjMEe8+H5xnR/ytWsQdZ5SdO1Rli9QkY OP7wC7v7F/4Hs4DY+ATz9u6Hv5WVXB37fARtkMSe0fa3vP8zow34MHQfPR2LM/5jGjaI CXZyaK9wzBNPRl70y6K9tfqg20j8JfByy/6/x/RgKoIo78xPYCjq74EmYh0U8Pw0Ls2H jwQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=CMulTRGH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a170902d4cf00b00186b697ec66si17403177plg.399.2022.12.06.01.32.18; Tue, 06 Dec 2022 01:32:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=CMulTRGH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234031AbiLFIeU (ORCPT + 79 others); Tue, 6 Dec 2022 03:34:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233613AbiLFIeM (ORCPT ); Tue, 6 Dec 2022 03:34:12 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C13141024 for ; Tue, 6 Dec 2022 00:34:11 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id i15so11063396edf.2 for ; Tue, 06 Dec 2022 00:34:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6+091FGCQ4rhzDvkB3AYfkA+OM7BJLCJxULLW5x6V0Y=; b=CMulTRGHBt8iZM34cI32BL92j4m/IGpI6bWJ+J8LmB3Bk9XlO8T2iVFu0JkuBVf5zj 8Wr0rXr9XVkORpLTFHEUXRXlrgQds3a+N8OJcv8pyp5UWyhX043kgJV1IYaeEM1if5ls fcn1Xmbm29SFIoT4NocFl/j01Dm8x/9dT3pH/70rdtr7Eiq5IyhhHdZgMX3hHJEvfaOw uXWTFUo5QnhQaRm3Q8kBsLYm1Rz7Cg/AknnwM7TowRNpVAl9Bh3+7ivfKDgQHnnwTSgu 669PfAVJ5wR334uRsypLCsWVOL5aYLZS1wPHtmj3LtsaCbwak5Q8yk1GI3C4z0kIfkyk FLgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6+091FGCQ4rhzDvkB3AYfkA+OM7BJLCJxULLW5x6V0Y=; b=eKeBTyJhlcLOCd37jOmstkXnXoibuVIXaQTetEEUo8x6DGcINHiMdCc51firXrB6ap cR03PDohn3mBMjp+jX8pGNozEnf6ZYtiDCtvKMNhXNLwQLUdZQ4Zp0SaIDXh4AKheJUx HI80W5rl0PpYYGV1XwuP6jVCg6cJRyRMWktyDzV735FTYrFzo/iEIcZEpf/L1E2j+BlA M8nbnabf5RWB6kyeqYfi/LTYad3x5hzGClSj+o/sn46Wg6KuPFt2r6yKXLBf/hVljIUG 1xl25zQrOJuZg1VJaTI93+tGKseJjO+xxBPrQs46cRmau/LIeHKG/bz5IdbNDmTaCOuu cnoQ== X-Gm-Message-State: ANoB5plzHba3zLADg9w7vIs0Yv0lkUbS9wWmZlkINMXISK1c00bRQmHn Na5KyPufZJlwWmk/fCs82fH5EA== X-Received: by 2002:a05:6402:4516:b0:467:b88c:f3af with SMTP id ez22-20020a056402451600b00467b88cf3afmr1991786edb.24.1670315650207; Tue, 06 Dec 2022 00:34:10 -0800 (PST) Received: from [127.0.1.1] ([2a0e:41a:894f:0:2017:359e:18ef:1c49]) by smtp.gmail.com with ESMTPSA id g18-20020a17090604d200b0078d9b967962sm7019390eja.65.2022.12.06.00.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 00:34:09 -0800 (PST) From: Carlo Caione Date: Tue, 06 Dec 2022 09:34:02 +0100 Subject: [PATCH v3 2/3] drm/tiny: ili9486: Do not assume 8-bit only SPI controllers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20221116-s905x_spi_ili9486-v3-2-59c6b58cbfe3@baylibre.com> References: <20221116-s905x_spi_ili9486-v3-0-59c6b58cbfe3@baylibre.com> In-Reply-To: <20221116-s905x_spi_ili9486-v3-0-59c6b58cbfe3@baylibre.com> To: Daniel Vetter , Jerome Brunet , David Airlie , Kamlesh Gurudasani , Mark Brown , Martin Blumenstingl , Kevin Hilman , Neil Armstrong Cc: linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-amlogic@lists.infradead.org, Carlo Caione , linux-kernel@vger.kernel.org X-Mailer: b4 0.10.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Carlo Caione --- 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 2ca7c59771f3..14a9e6ad2d15 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); -- b4 0.10.1