From patchwork Sat Apr 13 18:24:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10899591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29EBF18B7 for ; Sat, 13 Apr 2019 18:25:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E974C28BC4 for ; Sat, 13 Apr 2019 18:25:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD51E28660; Sat, 13 Apr 2019 18:25:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49FC828C51 for ; Sat, 13 Apr 2019 18:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbfDMSZJ (ORCPT ); Sat, 13 Apr 2019 14:25:09 -0400 Received: from smtp.domeneshop.no ([194.63.252.55]:35972 "EHLO smtp.domeneshop.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727097AbfDMSZJ (ORCPT ); Sat, 13 Apr 2019 14:25:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=3Y1IxRXFOOIa+RsVhvks/0XBKK+13WLS553sNdJX+68=; b=dVy2qBCdq7zeCMOxBi7HN+SiqFVidjIKjKtoR26ndNqA2fUjOWDKF95T15wjM++g/H0vqtqfIQpoCCHrY4Ys6/25G0L2ivluvgxueBeOniTqGdGcVoJls/PDxTmCepz8bI0dxvH3WrnO2AEykOz7h9UXW3L/WYSE/ne4MjcRK96Mo7AG5jwL0Pm6uxgvI1h80Eyxr6jiUVZSekFTQv3Lplpp4biHSxRAghgRoOczENyNMfJCimWLKWMYC+wPm/VoPpk4QZ4u00JSGUeKDFBrqULqdTwS0W+HYWpoPPnT+NdDPY9XbXY/ed6bhx/zFmIgMHuyuHLquje94WE2URZZ9A==; Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:48766 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1hFNKs-0005SF-Oo; Sat, 13 Apr 2019 20:25:06 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: linux-spi@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: broonie@kernel.org, eric@anholt.net, stefan.wahren@i2se.com, kernel@martin.sperl.org, meghana.madhyastha@gmail.com, lukas@wunner.de, linux-rpi-kernel@lists.infradead.org, =?utf-8?q?Noralf_Tr=C3=B8nnes?= Subject: [PATCH v5 4/4] drm/tinydrm: Remove chunk splitting in tinydrm_spi_transfer Date: Sat, 13 Apr 2019 20:24:15 +0200 Message-Id: <20190413182415.38543-5-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190413182415.38543-1-noralf@tronnes.org> References: <20190413182415.38543-1-noralf@tronnes.org> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Meghana Madhyastha Remove chunk splitting in tinydrm_spi_transfer in tinydrm-helpers as spi-bcm2835 now can handle large buffers using DMA, automatic byte swapping in tinydrm_spi_transfer as it doesn't have users. Remove the spi_max module argument that now has lost its cause. The 16kB buffer size for Type C Option 1 (9-bit) interface is somewhat arbitrary, but a bigger buffer will have a miniscule impact on transfer speed, so it's probably fine. Signed-off-by: Meghana Madhyastha Signed-off-by: Noralf Trønnes --- .../gpu/drm/tinydrm/core/tinydrm-helpers.c | 83 ++----------------- drivers/gpu/drm/tinydrm/mipi-dbi.c | 10 +-- 2 files changed, 7 insertions(+), 86 deletions(-) diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index 6d540d93758f..a32dc859a9c1 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c @@ -22,41 +22,8 @@ #include #include -static unsigned int spi_max; -module_param(spi_max, uint, 0400); -MODULE_PARM_DESC(spi_max, "Set a lower SPI max transfer size"); - #if IS_ENABLED(CONFIG_SPI) -/** - * tinydrm_spi_max_transfer_size - Determine max SPI transfer size - * @spi: SPI device - * @max_len: Maximum buffer size needed (optional) - * - * This function returns the maximum size to use for SPI transfers. It checks - * the SPI master, the optional @max_len and the module parameter spi_max and - * returns the smallest. - * - * Returns: - * Maximum size for SPI transfers - */ -size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len) -{ - size_t ret; - - ret = min(spi_max_transfer_size(spi), spi->master->max_dma_len); - if (max_len) - ret = min(ret, max_len); - if (spi_max) - ret = min_t(size_t, ret, spi_max); - ret &= ~0x3; - if (ret < 4) - ret = 4; - - return ret; -} -EXPORT_SYMBOL(tinydrm_spi_max_transfer_size); - /** * tinydrm_spi_bpw_supported - Check if bits per word is supported * @spi: SPI device @@ -147,62 +114,22 @@ int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz, struct spi_transfer tr = { .bits_per_word = bpw, .speed_hz = speed_hz, + .tx_buf = buf, + .len = len }; struct spi_message m; - u16 *swap_buf = NULL; - size_t max_chunk; - size_t chunk; - int ret = 0; - - if (WARN_ON_ONCE(bpw != 8 && bpw != 16)) - return -EINVAL; - - max_chunk = tinydrm_spi_max_transfer_size(spi, 0); if (drm_debug & DRM_UT_DRIVER) - pr_debug("[drm:%s] bpw=%u, max_chunk=%zu, transfers:\n", - __func__, bpw, max_chunk); - - if (bpw == 16 && !tinydrm_spi_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; - } - } + pr_debug("[drm:%s] bpw=%u, transfers:\n", __func__, bpw); spi_message_init(&m); if (header) spi_message_add_tail(header, &m); spi_message_add_tail(&tr, &m); - while (len) { - chunk = min(len, max_chunk); + tinydrm_dbg_spi_message(spi, &m); - 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; - - tinydrm_dbg_spi_message(spi, &m); - ret = spi_sync(spi, &m); - if (ret) - return ret; - } - - return 0; + return spi_sync(spi, &m); } EXPORT_SYMBOL(tinydrm_spi_transfer); diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c index 85761b4abb83..0bcf6c764893 100644 --- a/drivers/gpu/drm/tinydrm/mipi-dbi.c +++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c @@ -975,15 +975,9 @@ static int mipi_dbi_typec3_command(struct mipi_dbi *mipi, u8 *cmd, int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi, struct gpio_desc *dc) { - size_t tx_size = tinydrm_spi_max_transfer_size(spi, 0); struct device *dev = &spi->dev; int ret; - if (tx_size < 16) { - DRM_ERROR("SPI transmit buffer too small: %zu\n", tx_size); - return -EINVAL; - } - /* * Even though it's not the SPI device that does DMA (the master does), * the dma mask is necessary for the dma_alloc_wc() in @@ -1013,8 +1007,8 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi, mipi->swap_bytes = true; } else { mipi->command = mipi_dbi_typec1_command; - mipi->tx_buf9_len = tx_size; - mipi->tx_buf9 = devm_kmalloc(dev, tx_size, GFP_KERNEL); + mipi->tx_buf9_len = SZ_16K; + mipi->tx_buf9 = devm_kmalloc(dev, mipi->tx_buf9_len, GFP_KERNEL); if (!mipi->tx_buf9) return -ENOMEM; }