From patchwork Wed Mar 27 08:43:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 783540 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BE953398B; Wed, 27 Mar 2024 08:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529029; cv=none; b=GqwKkY15xXl8t9gKi2XeSiyI8FJrPrNDRgflRocuww1V1avR6ltnzuhRS0yeur40mp+q44rXgGHZOiMv0AXIu3da2nKqunIUzpNUwPcCw1ml76lKL3w+BtjxIw1tUClhlAjXOygjawSiAxyxKVDEEwaWd7L0aM8ER3bh3tU5BK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529029; c=relaxed/simple; bh=BrFNjhI8oLc26SSKfKHH6M/L+OciIVtrBnTYO5nLL64=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dY60EY9EyM5CHNIET3YDTuUYgZ5+LBnIDd9qJnS/xarjG3bqmMacZbklB6zN5OP1qzhAu5jzJ/GsyCm/0CXSnpkC8KJyjHyV1WvE3iOrNFYQV7a5OXD9OO7e9L+wr+iQ0oV2tiQ/dnifc35zLuBotw5jUw9LnazkThZAhiSyJAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=e8MtlAb1; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="e8MtlAb1" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0C3A4FF806; Wed, 27 Mar 2024 08:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711529025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=knHSdAeL3C8xPiNb5BV1ixMXuco9YBgoOV7376ixMAg=; b=e8MtlAb1gLizUVrUWLAnv7MSFuCqG87189i5izDIbvatnrYSeTLq2NmaIae3jGhGZSWCPA 5vbC9hXODrCKregYiq+CQNXgG74AscToTY7VLGojn+49xohpVwNHswnzCGvUV957WtbVng EFUSs7WWPyrmghpbzzjavDaddxf7Wa+ZayECQLxdKOjVYaNEQQNAiTZqy7ws3O8X1J9wHN aoRiepxPEFM/3w852FOekaK8oSCKI5PRmca0Ol8/4wcv/5dqopxjs/Y81T3f4d0/6d8uHN RLruLD3MWyl9F+fVwOpvXLv+mpsG3bkHA7a4+MPMnm/Wr4GAwumwiROFUn7DAQ== From: Louis Chauvet Date: Wed, 27 Mar 2024 09:43:36 +0100 Subject: [PATCH v3 1/3] spi: spi-omap2-mcspi.c: revert "Toggle CS after each word" Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240327-spi-omap2-mcspi-multi-mode-v3-1-c4ac329dd5a2@bootlin.com> References: <20240327-spi-omap2-mcspi-multi-mode-v3-0-c4ac329dd5a2@bootlin.com> In-Reply-To: <20240327-spi-omap2-mcspi-multi-mode-v3-0-c4ac329dd5a2@bootlin.com> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Miquel Raynal , yen-mei.goh@keysight.com, koon-kee.lie@keysight.com, jeremie.dautheribes@bootlin.com, Louis Chauvet X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2319; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=BrFNjhI8oLc26SSKfKHH6M/L+OciIVtrBnTYO5nLL64=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmA9w/NUAnDS/xLvqKxxcULsx6ggIPcYgTe+hD3tlb cclGh1mJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZgPcPwAKCRAgrS7GWxAs4jNlEA CByt+wrzLsf0tJos+LC6LHl5GBgNrz7OGAAxqKF3d0Jo/rsP0GEvseAmlM9+K8b4ON0CxX/fWH4qj5 QBrItoWv3mw4zwVTe+c0T+04O91RGqRm11MPAtzp4+P3i50sEs2c69M7xqDaR77prFvZntRgtwfSf9 rT74msmQT1QvjiQ6dPR77bxS4Z4Bpo+bH7hP1ZB2C47MAAqM6op3mSYvbYk6UzBopdH5gGm0pE47av L8/ouqGTbWnTQlUoRfumWvvB37HToeeuEzItqx7twjrqBR9HAIq5pwFh6LIO1wMxgOoNEgQsOaqvwn UEb7apefQxuSdTYKgzQwQKC5BEq9ZDTSyhkVhbjzd+p9fMqEYD+bqM/g+aupsyF9ve/JqC1vVkEJk/ rX5qJ+Hhdhc+0hntAFxXbVtguhbc0d0w1zG8AwfVYHgYydr0XJMhyvmQKfhFISq/Mh7Co4tVa7OlIa OOOr/7VAd4QXwBM8swkLpI9qFRr9v7Noj6uzX+IyvSBuZXeE2ZKAmbvKpDeqDLEzUWYIIk4y5qojmM iqDUhIq8ngjBI3Nd+tg5eFiQD5CR53afN3FAXHfcv8kuOznjf/YT6ILzyuk//PpZDGThHev4DF12Bs rs/nO6qO2RTmQP13oNUBazSixe3KlizM/CRogSepSVX+JEFYnUa0Y3dSVocA== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Commit 5cbc7ca987fb ("spi: spi-omap2-mcspi.c: Toggle CS after each word") introduced the toggling of CS after each word for the omap2-mcspi controller. The implementation is not respectful of the actual spi_message content, so the CS can be raised after each word even if the transfer structure asks to keep the CS active for the whole operation. As it is not used anyway in the current Linux tree, it can be safely removed. Signed-off-by: Louis Chauvet --- drivers/spi/spi-omap2-mcspi.c | 15 --------------- include/linux/platform_data/spi-omap2-mcspi.h | 3 --- 2 files changed, 18 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index ddf1c684bcc7..601acec37eca 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -1175,13 +1175,6 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr, t->bits_per_word == spi->bits_per_word) par_override = 0; } - if (cd && cd->cs_per_word) { - chconf = mcspi->ctx.modulctrl; - chconf &= ~OMAP2_MCSPI_MODULCTRL_SINGLE; - mcspi_write_reg(ctlr, OMAP2_MCSPI_MODULCTRL, chconf); - mcspi->ctx.modulctrl = - mcspi_read_cs_reg(spi, OMAP2_MCSPI_MODULCTRL); - } chconf = mcspi_cached_chconf0(spi); chconf &= ~OMAP2_MCSPI_CHCONF_TRM_MASK; @@ -1240,14 +1233,6 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr, status = omap2_mcspi_setup_transfer(spi, NULL); } - if (cd && cd->cs_per_word) { - chconf = mcspi->ctx.modulctrl; - chconf |= OMAP2_MCSPI_MODULCTRL_SINGLE; - mcspi_write_reg(ctlr, OMAP2_MCSPI_MODULCTRL, chconf); - mcspi->ctx.modulctrl = - mcspi_read_cs_reg(spi, OMAP2_MCSPI_MODULCTRL); - } - omap2_mcspi_set_enable(spi, 0); if (spi_get_csgpiod(spi, 0)) diff --git a/include/linux/platform_data/spi-omap2-mcspi.h b/include/linux/platform_data/spi-omap2-mcspi.h index 3b400b1919a9..9e3c15b4ac91 100644 --- a/include/linux/platform_data/spi-omap2-mcspi.h +++ b/include/linux/platform_data/spi-omap2-mcspi.h @@ -16,9 +16,6 @@ struct omap2_mcspi_platform_config { struct omap2_mcspi_device_config { unsigned turbo_mode:1; - - /* toggle chip select after every word */ - unsigned cs_per_word:1; }; #endif From patchwork Wed Mar 27 08:43:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 784743 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C19A93612A; Wed, 27 Mar 2024 08:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529030; cv=none; b=n4xR5v4if/4MVsj4eOVUr0W1xh6u4J9a5Fwt4QZa59eKaoKj++z7bpR3Xb6phL3bRd1apDzKY+1NWoR5QE2/AY/gL/RAagXH2y4fICKWDUXkeClxzm0tQz2y3TgKmF5R0HbAkYyub+WEB1SzGQETL2aTcZtqu9gEDGBGWhHlm+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529030; c=relaxed/simple; bh=8Rj4UzLQ+lgPhSr/BeYRiEb1FGa5j8sUlqT6xDm+xaQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sio8WwtgnGEwQyLafi3FLipQIFLAeCAhKpfxxvkeces8uwMcZBkgJyJrvSXF1FWR5NioOXNE5hfEC1B7A9rzJt6fDEl+6hX4syPAO78sNzLVwVVvMdmj5wuvf9VxR+0vvRHeXwoP+PO1XoAlT6VfKu6WJyyCSY+QCrPzVonAqqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=hiEPrHVI; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="hiEPrHVI" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8849EFF812; Wed, 27 Mar 2024 08:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711529025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oPTp0MTYjMgxYrxDkNPxdDoi7haxm4pB5iRe0mgUIg8=; b=hiEPrHVIUKUYdZE6f9vyrw5ldmPi1zW3NYWPTWr9ghHKkhEOohdB+rwmc/tBF6BSfVu6O+ vbcsKSUizhw2MZ9ZrmBnGCnD066QINYltG5tLEqEZQ6vEZWTw+RNiQnwPy953oGtlNhBWR D7C7mKb735EGp069dj/McsXOyEDmQjKudNqqrD2tJ++6pxLaJ+1931tG/7YGAcGVffqNvZ 7YrQCVGsQqYVZaiK0s0XkXX+OYmB0B/W/RrEbthZPkRiURhThivp+gN77nCNQTs0RIGDwE 0jgoYNMQh7pPyqWO+knZ24CyWzJ92Oh7Kkq+8hOmDkVErksEURtYDnDR95N2jw== From: Louis Chauvet Date: Wed, 27 Mar 2024 09:43:37 +0100 Subject: [PATCH v3 2/3] spi: omap2-mcspi: Add support for MULTI-mode Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240327-spi-omap2-mcspi-multi-mode-v3-2-c4ac329dd5a2@bootlin.com> References: <20240327-spi-omap2-mcspi-multi-mode-v3-0-c4ac329dd5a2@bootlin.com> In-Reply-To: <20240327-spi-omap2-mcspi-multi-mode-v3-0-c4ac329dd5a2@bootlin.com> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Miquel Raynal , yen-mei.goh@keysight.com, koon-kee.lie@keysight.com, jeremie.dautheribes@bootlin.com, Louis Chauvet X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4742; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=8Rj4UzLQ+lgPhSr/BeYRiEb1FGa5j8sUlqT6xDm+xaQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmA9w/KNsYbiOqJspFOpgHcOO0Om0GrgRHRHnPSknq qnq4Z1OJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZgPcPwAKCRAgrS7GWxAs4qzpEA DBQUmIrfY+iTI8ZR7Vao4r570bxb+K1oS+Tyvc8+9ZRidUB+kZVhFfBwBU8hAMpwAkhl82Ru7Pl5dC e2V1wg3t2lJUqeHVsa/hN6/cRcjOsQTjo+JlBsza9SzK9O/ZujHRTft+lmHwfaMJlITNHNzN+YxGYi YquKOUN6aw3BcMFd/tfOojtpWBhEAx1XndqNB0E5c9g2vpNisXoVVySCq9EzbHK+R5iHtrkpVfzN6c XtPHc6Stki+c5hk/J6sAEVLdbd2A7AGsE+Ov4Wg1bzIkE8NWRBT4BNziRR+v9MrrYgkhJ1Vw5qJD0q 7zNK6xfP9ahJItKnHL6ocGQ13Yl5cMgFqrnyYu7VTNus50SUaYhQTxGQ9ZNvL5cvn70AU5UDt3MM3m ynnov0tS9Kw2Rh3MJUUMp/rRmufer7Bmymde92yGEG4yN7klCcY8NmXwUzkNTujFPvOfaWW63sssZz KebfVX58/rKWFBOj7oxey1VP+hlLpjrmEtSgnnjHv+P6StVtPv0uGFcJ0WLvTCFcz1TyiUqjF3+qzs mxb6IHbAs8PUHBhjvLMviD5zH7p9CtAyxGVwtrtG0ziOWTY1RIQLCeS8cfcf2Dbs1TgqOZ4DAtXwYO em6Pd8hZz+n5tBrIGHsSahwmsI+ebC2c6OFfGrx+1PGsd/mS4Up+voSBguxQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Introduce support for MULTI-mode in the OMAP2 MCSPI driver. Currently, the driver always uses SINGLE mode to handle the chip select (CS). With this enhancement, MULTI-mode is enabled for specific messages, allowing for a shorter delay between CS enable and the message (some FPGA devices are sensitive to this delay). The OMAP2 MCSPI device can use two different mode to send messages, SINGLE and MULTI: In SINGLE mode, the controller only leverages one single FIFO, and the host system has to manually select the CS it wants to enable. In MULTI mode, each CS is bound to a FIFO, the host system then writes the data to the relevant FIFO, as the hardware will take care of the CS The drawback of multi-mode is that it's not possible to keep the CS enabled between each words. Therefore, this patch enables multi-mode only for specific messages: the spi_message must contain only spi_transfer of 1 word (of any size) with cs_change enabled. A new member is introduced in the omap2_mcspi structure to keep track of the current used mode. Signed-off-by: Louis Chauvet --- drivers/spi/spi-omap2-mcspi.c | 67 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 601acec37eca..002f29dbcea6 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -131,6 +131,7 @@ struct omap2_mcspi { unsigned int pin_dir:1; size_t max_xfer_len; u32 ref_clk_hz; + bool use_multi_mode; }; struct omap2_mcspi_cs { @@ -256,10 +257,15 @@ static void omap2_mcspi_set_cs(struct spi_device *spi, bool enable) l = mcspi_cached_chconf0(spi); - if (enable) + /* Only enable chip select manually if single mode is used */ + if (mcspi->use_multi_mode) { l &= ~OMAP2_MCSPI_CHCONF_FORCE; - else - l |= OMAP2_MCSPI_CHCONF_FORCE; + } else { + if (enable) + l &= ~OMAP2_MCSPI_CHCONF_FORCE; + else + l |= OMAP2_MCSPI_CHCONF_FORCE; + } mcspi_write_chconf0(spi, l); @@ -283,7 +289,12 @@ static void omap2_mcspi_set_mode(struct spi_controller *ctlr) l |= (OMAP2_MCSPI_MODULCTRL_MS); } else { l &= ~(OMAP2_MCSPI_MODULCTRL_MS); - l |= OMAP2_MCSPI_MODULCTRL_SINGLE; + + /* Enable single mode if needed */ + if (mcspi->use_multi_mode) + l &= ~OMAP2_MCSPI_MODULCTRL_SINGLE; + else + l |= OMAP2_MCSPI_MODULCTRL_SINGLE; } mcspi_write_reg(ctlr, OMAP2_MCSPI_MODULCTRL, l); @@ -1250,15 +1261,59 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr, struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); struct omap2_mcspi_regs *ctx = &mcspi->ctx; struct omap2_mcspi_cs *cs; + struct spi_transfer *tr; + u8 bits_per_word; - /* Only a single channel can have the FORCE bit enabled + /* + * The conditions are strict, it is mandatory to check each transfer of the list to see if + * multi-mode is applicable. + */ + mcspi->use_multi_mode = true; + list_for_each_entry(tr, &msg->transfers, transfer_list) { + if (!tr->bits_per_word) + bits_per_word = msg->spi->bits_per_word; + else + bits_per_word = tr->bits_per_word; + + /* + * Check if this transfer contains only one word; + */ + if (bits_per_word < 8 && tr->len == 1) { + /* multi-mode is applicable, only one word (1..7 bits) */ + } else if (bits_per_word >= 8 && tr->len == bits_per_word / 8) { + /* multi-mode is applicable, only one word (8..32 bits) */ + } else { + /* multi-mode is not applicable: more than one word in the transfer */ + mcspi->use_multi_mode = false; + } + + /* Check if transfer asks to change the CS status after the transfer */ + if (!tr->cs_change) + mcspi->use_multi_mode = false; + + /* + * If at least one message is not compatible, switch back to single mode + * + * The bits_per_word of certain transfer can be different, but it will have no + * impact on the signal itself. + */ + if (!mcspi->use_multi_mode) + break; + } + + omap2_mcspi_set_mode(ctlr); + + /* In single mode only a single channel can have the FORCE bit enabled * in its chconf0 register. * Scan all channels and disable them except the current one. * A FORCE can remain from a last transfer having cs_change enabled + * + * In multi mode all FORCE bits must be disabled. */ list_for_each_entry(cs, &ctx->cs, node) { - if (msg->spi->controller_state == cs) + if (msg->spi->controller_state == cs && !mcspi->use_multi_mode) { continue; + } if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE)) { cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE; From patchwork Wed Mar 27 08:43:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 783539 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27DAD36139; Wed, 27 Mar 2024 08:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529030; cv=none; b=sfbyDh7SzJdI5eReq+qBUjdljw6hVl2Q70oJ2tzqmibE+JQYsBCThgiO3mTVntI29QQhOv0LbhvMvLNeWIeLHdpahIh+yTuudVN+EqeMhJsVgYVo5G8RrQwmbQ0xhx1G38WfeaMdMfk3YHQR+on89964YWKEEsJoK7wRok6Pvpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529030; c=relaxed/simple; bh=cbd6GULlhJHFj+W57GD2PRSA9IAx+XadTpMqn6sKLXU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dFr6g8qk3USx7VFy6sMXW3NQIN6TFody6FEM+Q2EbpHsFJP4u5pxxoTnRa11SbUiBRVGEvtZYxuwjq2kDFacNwxLat893fSdIoAvt6C/EkzB4SwNRdEOVcThFzSCQKJgv8lpOhWPFFh3SjXN7pcHoJi7k3aONz19ACNn/ZruR0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=gVC7Biy8; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="gVC7Biy8" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0F285FF80E; Wed, 27 Mar 2024 08:43:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711529026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ES9AYn9DDU2tdqD0EP064jr5Z2SbWzjTTb1Ww7Q0SZk=; b=gVC7Biy8Y13RV03xjjvfVigmmpyXTBmLYp7EGeQTclWgVI4zKSsBCGt+HYNpudpETKPtP0 tocr1x5ijZ0bBcj7o8lZJzUXzENZobQ9KYE6wbNLxa4K+NrCX6KbqfzS37ZJbMBQpHfSFH 5dpbnSW5fxv2pvQzwQVAm/L9I5s2dwJoLhr7YnX/izKKz48p4nC3iClA8DPc3OExfj5p+/ rb07KHdSG2lTlk1nriYAF/4V3RY09qkoVX31WwCmjNggk0+Tu4W0ISfZkFCCVJpGBAvhjg 3yWlcCl4yyBdtJHcshiKCAVSvo9SZD3L45OtBlUrx4Rk7k8fVguPeKHRn+gk5w== From: Louis Chauvet Date: Wed, 27 Mar 2024 09:43:38 +0100 Subject: [PATCH v3 3/3] spi: omap2-mcpsi: Enable MULTI-mode in more situations Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240327-spi-omap2-mcspi-multi-mode-v3-3-c4ac329dd5a2@bootlin.com> References: <20240327-spi-omap2-mcspi-multi-mode-v3-0-c4ac329dd5a2@bootlin.com> In-Reply-To: <20240327-spi-omap2-mcspi-multi-mode-v3-0-c4ac329dd5a2@bootlin.com> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Miquel Raynal , yen-mei.goh@keysight.com, koon-kee.lie@keysight.com, jeremie.dautheribes@bootlin.com, Louis Chauvet X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2389; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=cbd6GULlhJHFj+W57GD2PRSA9IAx+XadTpMqn6sKLXU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmA9xAmZq8OlpvK656DoBX54JytpZ8m1w4dOlDkNzX jgKH6UeJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZgPcQAAKCRAgrS7GWxAs4pF1EA CkMw4PGPP4k3fo5bX3sCIYZlP3+TQ7DmgnF8RzvIyEugtDwbhe8tVz/xGRYduFgVQGShiJ5j92VvNW FTd9MMl/iG1DCQ0QIkktuB/ml3spIVcX0ChiTZcSkNdhrFXvVj4ldMtv4SXqItMnZP6fx0aFEXpVAp LyZpYwJYQoMSNKIL6emVbzCZUK+gY6f88q0g3Q76+pTu7LUAHjDsWdOFA89cctkhKnlZ0ycCxgHsCP vHQXe9yd/zb6k+vVDC+vypHL9/lugDF3marizLxtOkESbmgZv/Z14HVCXMKsDSX6N1ITaWx+sockff qfq++43/oOT2Gf6YL/VvA0VWHyYBHrySahcTrnK1ZC184RQ92wpc0Pws7OhnU0kQgU9+NgV3K1irdf oOQphnzj3xZATv/vm7ChWVj0oU3W86xc5Lv7SsSyoSvdUS3SQjERFlnwbyx6YivIDiCH/tQTVdn9z9 L3gUyb57zXckhZeVRr0NU9Qs2DgCKf7uDWdTYPj08sFr2JUszYSjAsXzYW1+W6PEdslQhs93nFfESA krqaJPo6LrAy8Q8LFP9iQcq2SRSL6oleJ4abxk5/kW1P2udRmms4Wm/WPEluY49ivt7x3UczLS3LSI 2QBOqlxo3B5i0rupnkegGX/eNZrqLkjuYiFZsa98UyZ1fnOipzjFPCXUjCyg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Enable multimode when a transfer of multiple small words can be transformed in a transfer with a single bigger word. This is allowed as long as the result on the cable is the same, so word_delay must be zero. Signed-off-by: Louis Chauvet --- I am not sure if this is the best place to put such "optimization". I think this improvment should be in the core, as it is not depending on the driver itself, but I think Mark suggested something like this so if that fits to what was expected, I am happy to share this small improvement. --- drivers/spi/spi-omap2-mcspi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 002f29dbcea6..7e3083b83534 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -1277,11 +1277,24 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr, /* * Check if this transfer contains only one word; + * OR contains 1 to 4 words, with bits_per_word == 8 and no delay between each word + * OR contains 1 to 2 words, with bits_per_word == 16 and no delay between each word + * + * If one of the two last case is true, this also change the bits_per_word of this + * transfer to make it a bit faster. + * It's not an issue to change the bits_per_word here even if the multi-mode is not + * applicable for this message, the signal on the wire will be the same. */ if (bits_per_word < 8 && tr->len == 1) { /* multi-mode is applicable, only one word (1..7 bits) */ + } else if (tr->word_delay.value == 0 && bits_per_word == 8 && tr->len <= 4) { + /* multi-mode is applicable, only one "bigger" word (8,16,24,32 bits) */ + tr->bits_per_word = tr->len * bits_per_word; + } else if (tr->word_delay.value == 0 && bits_per_word == 16 && tr->len <= 2) { + /* multi-mode is applicable, only one "bigger" word (16,32 bits) */ + tr->bits_per_word = tr->len * bits_per_word / 2; } else if (bits_per_word >= 8 && tr->len == bits_per_word / 8) { - /* multi-mode is applicable, only one word (8..32 bits) */ + /* multi-mode is applicable, only one word (9..15,17..32 bits) */ } else { /* multi-mode is not applicable: more than one word in the transfer */ mcspi->use_multi_mode = false;