From patchwork Tue May 9 16:41:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 91664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3032777vqo; Tue, 9 May 2023 09:58:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4heqalgvRZI/ZlxZSO3BBxQQaA8MMXk8X22ittlqUF788VHqpGN2YtcW0YjiQth3u/qW3C X-Received: by 2002:a05:6a20:7345:b0:100:bda9:4b37 with SMTP id v5-20020a056a20734500b00100bda94b37mr8136058pzc.57.1683651523646; Tue, 09 May 2023 09:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683651523; cv=none; d=google.com; s=arc-20160816; b=TMLRoywgwzd4/1yfVH8dlDi9cUCSb98gnjBkGYjvzJhHcqw6U3HXzHN1EsYocKOfo1 577PJX6UgarhOVJCbMf9q3OpMGv+Wyb2s/V2t1UB36nVjzE4ss4GlM97tf7kiqY/IchQ 9gHqBsUz4UwkaVLQ8GqzOmayd9kqpSoyfuuocnFiu1ebRinB+3BcPnZMnso5wS0Ir6Bg rMYztm3iSqWTRwYXgqzNdTuzVAeAhZxODJGTWI9HAnqp/RT+IGxnxfj0yLpYj/MIdVNa 7IqOokI7j5ha/miPJGcAwSoZmKcO3jDbYZs0uf4jDBr2IKUmr0DMyRiVhaVXXbRCK34S IG9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qQM04fH8wYbMYV9sluxk+y4zEawLXJoiozfeS8Zvv7M=; b=FxK/3hkiheXArDabhRyjqmqSafpB5fwqdXOIjKd6AqD06Gf1fv4XTQn79PnTojIoar 9a0b6qU5ZpOXvCoGtlbbgeco+mXRB123tV9SxmoZIMLP++/Gj3W6Xpp5agSR6ooWK/nP k/s2TtCOTFgfIAbFMzY+rIHd3X0Kv06S5k7yaG6mWqXMpyhQOTCCCus4KtfEokbZEOVl 3wunfONrR+4WnHvDs8S5dVAZ01EJsaBF28uhvymzac5MIvBait6YXPCDlyNQO3M0pNO3 GFygt5XxYyZb8YKIv5H1Alw/2M8yXeWDSXEG+sLjsk7GvhpzyJoye93HyGMyWMK+c0mM 3GOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=OuuAD703; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s69-20020a632c48000000b0051909d663d8si1843701pgs.656.2023.05.09.09.58.30; Tue, 09 May 2023 09:58:43 -0700 (PDT) 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=@cirrus.com header.s=PODMain02222019 header.b=OuuAD703; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233513AbjEIQmL (ORCPT + 99 others); Tue, 9 May 2023 12:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjEIQmG (ORCPT ); Tue, 9 May 2023 12:42:06 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35CEF3C35; Tue, 9 May 2023 09:42:05 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 349GKZNL008998; Tue, 9 May 2023 11:41:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=qQM04fH8wYbMYV9sluxk+y4zEawLXJoiozfeS8Zvv7M=; b=OuuAD7036JIIFa4hLIuHWmPNDMXr4O26A8SdnlCO6CRuI21Q1vwabgcDnLaVL2yfjmrJ qxzBj0lTfOjBTqSPQR/7DGUzhzdeiTexUxjRIVBXkYJTt0JfJTLOf/SGb9ErDQiGvSJH gmvfgrZxXXXrTry2CvhFEdY7BEsLcdKSL3jxJwz9SZE01PUO/5GJpOfmrM1KPrg4g8/i 5pxMmWSGIoSQjYvwM8Jx9Z+XNDE0M9ODurjTYbOuq9y4/G6KKWxUfr8daefsHMlqa2bh Z5adhmtkOCA2oxSnFuYvh2SouD7y0JNKnWEKLb/0KnDxqTzOYGZ6JRKwzSWiYTyq8yM9 lw== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3qf7s41ahu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 May 2023 11:41:54 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 9 May 2023 11:41:53 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 9 May 2023 11:41:53 -0500 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 2C58011D4; Tue, 9 May 2023 16:41:53 +0000 (UTC) From: Charles Keepax To: CC: , , , Subject: [PATCH 1/2] spi: spi-cadence: Avoid read of RX FIFO before its ready Date: Tue, 9 May 2023 17:41:52 +0100 Message-ID: <20230509164153.3907694-1-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: PMVYRC2i7GEEEdQKK_jielB5LHBdePS9 X-Proofpoint-GUID: PMVYRC2i7GEEEdQKK_jielB5LHBdePS9 X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765436580260676790?= X-GMAIL-MSGID: =?utf-8?q?1765436580260676790?= Recent changes to cdns_spi_irq introduced some issues. Firstly, when writing the end of a longer transaction, the code in cdns_spi_irq will write data into the TX FIFO, then immediately fall into the if (!xspi->tx_bytes) path and attempt to read data from the RX FIFO. However this required waiting for the TX FIFO to empty before the RX data was ready. Secondly, the variable trans_cnt is now rather inaccurately named since in cases, where the watermark is set to 1, trans_cnt will be 1 but the count of bytes transferred would be much longer. Finally, when setting up the transaction we set the watermark to 50% of the FIFO if the transaction is great than 50% of the FIFO. However, there is no need to split a tranaction that is smaller than the whole FIFO, so anything up to the FIFO size can be done in a single transaction. Tidy up the code a little, to avoid repeatedly calling cdns_spi_read_rx_fifo with a count of 1, and correct the three issues noted above. Fixes: b1b90514eaa3 ("spi: spi-cadence: Add support for Slave mode") Signed-off-by: Charles Keepax --- drivers/spi/spi-cadence.c | 42 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c index ac85d55622127..b0ccb138e3566 100644 --- a/drivers/spi/spi-cadence.c +++ b/drivers/spi/spi-cadence.c @@ -304,13 +304,11 @@ static int cdns_spi_setup_transfer(struct spi_device *spi, * cdns_spi_fill_tx_fifo - Fills the TX FIFO with as many bytes as possible * @xspi: Pointer to the cdns_spi structure */ -static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi) +static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi, unsigned int avail) { unsigned long trans_cnt = 0; - while ((trans_cnt < xspi->tx_fifo_depth) && - (xspi->tx_bytes > 0)) { - + while ((trans_cnt < avail) && (xspi->tx_bytes > 0)) { /* When xspi in busy condition, bytes may send failed, * then spi control did't work thoroughly, add one byte delay */ @@ -381,33 +379,23 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id) spi_finalize_current_transfer(ctlr); status = IRQ_HANDLED; } else if (intr_status & CDNS_SPI_IXR_TXOW) { - int trans_cnt = cdns_spi_read(xspi, CDNS_SPI_THLD); + int threshold = cdns_spi_read(xspi, CDNS_SPI_THLD); + int trans_cnt = xspi->rx_bytes - xspi->tx_bytes; + + if (threshold > 1) + trans_cnt -= threshold; + /* Set threshold to one if number of pending are * less than half fifo */ if (xspi->tx_bytes < xspi->tx_fifo_depth >> 1) cdns_spi_write(xspi, CDNS_SPI_THLD, 1); - while (trans_cnt) { - cdns_spi_read_rx_fifo(xspi, 1); - - if (xspi->tx_bytes) { - if (xspi->txbuf) - cdns_spi_write(xspi, CDNS_SPI_TXD, - *xspi->txbuf++); - else - cdns_spi_write(xspi, CDNS_SPI_TXD, 0); - xspi->tx_bytes--; - } - trans_cnt--; - } - if (!xspi->tx_bytes) { - /* Fixed delay due to controller limitation with - * RX_NEMPTY incorrect status - * Xilinx AR:65885 contains more details - */ - udelay(10); - cdns_spi_read_rx_fifo(xspi, xspi->rx_bytes); + cdns_spi_read_rx_fifo(xspi, trans_cnt); + + if (xspi->tx_bytes) { + cdns_spi_fill_tx_fifo(xspi, trans_cnt); + } else { cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_DEFAULT); spi_finalize_current_transfer(ctlr); @@ -456,10 +444,10 @@ static int cdns_transfer_one(struct spi_controller *ctlr, /* Set TX empty threshold to half of FIFO depth * only if TX bytes are more than half FIFO depth. */ - if (xspi->tx_bytes > (xspi->tx_fifo_depth >> 1)) + if (xspi->tx_bytes > xspi->tx_fifo_depth) cdns_spi_write(xspi, CDNS_SPI_THLD, xspi->tx_fifo_depth >> 1); - cdns_spi_fill_tx_fifo(xspi); + cdns_spi_fill_tx_fifo(xspi, xspi->tx_fifo_depth); spi_transfer_delay_exec(transfer); cdns_spi_write(xspi, CDNS_SPI_IER, CDNS_SPI_IXR_DEFAULT); From patchwork Tue May 9 16:41:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 91663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3032572vqo; Tue, 9 May 2023 09:58:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DDybpwe8q8YJbV62qFxLVfsagSknSXMsnYNcwdjT2t8AwpvHVEhlTXFvmE6uMrnBZ+sP5 X-Received: by 2002:a05:6a20:a11a:b0:f0:d50c:4ac5 with SMTP id q26-20020a056a20a11a00b000f0d50c4ac5mr18680823pzk.51.1683651494983; Tue, 09 May 2023 09:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683651494; cv=none; d=google.com; s=arc-20160816; b=ylqAhn7Gsqt+uRAdGLB0DGGmK+//eiYTUpwcgRmYXZiz6RVXE7wQRobCfW/PSSniky MTQraRqCWSzyWPfB6Am89YZ5yznO8z1LO3/wN6F68fIqAQE+BqoDGYY7j8/oHyR+ntL7 Qcdm/B5cfA0WXks1kClGP21w+MiyLlkCdy4a6AsB4aAu6N+NugpcNtv4bsKsvmvD21+n ytgyGOcUS97EzjVG1Q5kUBeNaphbmtcmEKnrrO9z9OeovDhak/KfTXqIczoIIkcM6bc6 s7jXafWnazc0Fj1x0KRcX/Giwnyq4PU/Pmm1c4BEUY/j5E522ITz44L4+RH0a6XPGX32 oCNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OjQmmXmIcH9+jcR8c3ItshyYbkN74w1OkLiozi3slDA=; b=LgTp1H3NcfsfqRjX5u8KkW0WvmTtRwWWOGZ8rgtyJCHYHMUY89OFCfiMSW3vroAWHR c3Tq2zdOZVSAuFan6tlu6az23Me0xEZCTEBG8wGMU48Q2A1aCsTWV2PD+yo9iVZxn4um JoBWAsHFGqg/O2K4UnMz/NlGuvF44oqmnYfwkN5ustmT3CGK0r7doAeErFpZTTItUaTY DWT3jDGZShl1WrrLKyuUoS2k230Y1E5NxUpeZvs4UvCfKqUd85fcWrli08GTlL8dhBON DnpURy7rYgqKAGy+YdmTWR4oPDtnObvjpqM2rXCk1f9XQ15q2U5Rg0rnVoN8kyMY+Xt/ ZENA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=L9r7qoas; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r71-20020a632b4a000000b0052cc0f960ebsi1827333pgr.714.2023.05.09.09.58.02; Tue, 09 May 2023 09:58:14 -0700 (PDT) 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=@cirrus.com header.s=PODMain02222019 header.b=L9r7qoas; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234009AbjEIQm0 (ORCPT + 99 others); Tue, 9 May 2023 12:42:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233293AbjEIQmK (ORCPT ); Tue, 9 May 2023 12:42:10 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D684225; Tue, 9 May 2023 09:42:07 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 349GKtb4009501; Tue, 9 May 2023 11:41:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=OjQmmXmIcH9+jcR8c3ItshyYbkN74w1OkLiozi3slDA=; b=L9r7qoasMnNbqSDBoKFDEqNM/N6u8SEfS3QNG54ncBAZPWp1Xmcy/kb716TgH+qZ/DDR dMoxzP7slx5O3ekxAX/x3yWSXL3rOCNAum1QHfuzJCr5iAvzBVaqiXMbMStcvP623Aqc EbyqTF2P6WNWn0OrXvN8LNiXjsYYC2/rz787mhJrzB7Ny3VhsVnpHaHGW1ddFLLjJlZ9 AFGRy772quyv2NmOJQNRAACW+dWjHnXrbM2fV1FwuL3A4AF+LB3/oT8ZWoTBU0YtSPJ1 TJOekg5m0Vz4hrByS+iMS0ibuEbzL8M7WmgOPYDTR0w/pVE6TpRL/u6kCOGM0tXZareF qg== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3qf7s41aht-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 May 2023 11:41:54 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 9 May 2023 11:41:53 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 9 May 2023 11:41:53 -0500 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 3E37E45; Tue, 9 May 2023 16:41:53 +0000 (UTC) From: Charles Keepax To: CC: , , , Subject: [PATCH 2/2] spi: spi-cadence: Only overlap FIFO transactions in slave mode Date: Tue, 9 May 2023 17:41:53 +0100 Message-ID: <20230509164153.3907694-2-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230509164153.3907694-1-ckeepax@opensource.cirrus.com> References: <20230509164153.3907694-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: cGxDQoXFL9mc-Nc8A6YsQtY593bxSw-h X-Proofpoint-GUID: cGxDQoXFL9mc-Nc8A6YsQtY593bxSw-h X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765436550298132699?= X-GMAIL-MSGID: =?utf-8?q?1765436550298132699?= Commit b1b90514eaa3 ("spi: spi-cadence: Add support for Slave mode") updated the code to trigger the IRQ when the FIFO was half empty, overlapping filling more data into the FIFO and sending what is left. This appears to cause regressions on the Zynq 7000, for transactions longer than the FIFO size, below that no overlapping occurs. It would appear from my testing that any attempt to put new data into the FIFO whilst data is still transmitting causes data corruption on both send and receive. If I am reading the commit message right on commit 49530e641178 ("spi: cadence: Add usleep_range() for cdns_spi_fill_tx_fifo()"), that would also seem to imply this is the case. On the assumption that this isn't an issue on the platform the original slave mode support was added for, update the cdns_transfer_one to only set the watermark to 50% of the FIFO size when in slave mode. There by retaining the new behaviour for slave mode but reverting to the older behaviour when the SPI is used a master. Fixes: b1b90514eaa3 ("spi: spi-cadence: Add support for Slave mode") Signed-off-by: Charles Keepax --- drivers/spi/spi-cadence.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c index b0ccb138e3566..ff02d81041319 100644 --- a/drivers/spi/spi-cadence.c +++ b/drivers/spi/spi-cadence.c @@ -438,14 +438,15 @@ static int cdns_transfer_one(struct spi_controller *ctlr, xspi->tx_bytes = transfer->len; xspi->rx_bytes = transfer->len; - if (!spi_controller_is_slave(ctlr)) + if (!spi_controller_is_slave(ctlr)) { cdns_spi_setup_transfer(spi, transfer); - - /* Set TX empty threshold to half of FIFO depth - * only if TX bytes are more than half FIFO depth. - */ - if (xspi->tx_bytes > xspi->tx_fifo_depth) - cdns_spi_write(xspi, CDNS_SPI_THLD, xspi->tx_fifo_depth >> 1); + } else { + /* Set TX empty threshold to half of FIFO depth + * only if TX bytes are more than half FIFO depth. + */ + if (xspi->tx_bytes > xspi->tx_fifo_depth) + cdns_spi_write(xspi, CDNS_SPI_THLD, xspi->tx_fifo_depth >> 1); + } cdns_spi_fill_tx_fifo(xspi, xspi->tx_fifo_depth); spi_transfer_delay_exec(transfer);