From patchwork Tue Jul 9 16:02:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 1958534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WJQlL422Pz1xpd for ; Wed, 10 Jul 2024 02:03:42 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WJQlL3ZWpz3fQw for ; Wed, 10 Jul 2024 02:03:42 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=taln60.nuvoton.co.il (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tmaimon@taln60.nuvoton.co.il; receiver=lists.ozlabs.org) Received: from herzl.nuvoton.co.il (unknown [212.199.177.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WJQkZ2Tw2z2yvv for ; Wed, 10 Jul 2024 02:02:59 +1000 (AEST) Received: from NTILML01.nuvoton.com (212.199.177.18.static.012.net.il [212.199.177.18]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 469G2n7o030997 for ; Tue, 9 Jul 2024 19:02:50 +0300 Received: from NTHCML01A.nuvoton.com (10.1.8.177) by NTILML01.nuvoton.com (10.190.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 9 Jul 2024 19:02:49 +0300 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCML01A.nuvoton.com (10.1.8.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 10 Jul 2024 00:02:46 +0800 Received: from taln58.nuvoton.co.il (10.191.1.178) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 10 Jul 2024 00:02:46 +0800 Received: from taln60.nuvoton.co.il (taln60 [10.191.1.180]) by taln58.nuvoton.co.il (Postfix) with ESMTP id B0E295F5E4; Tue, 9 Jul 2024 19:02:45 +0300 (IDT) Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id B1A38DC1BAA; Tue, 9 Jul 2024 19:02:45 +0300 (IDT) From: Tomer Maimon To: Subject: [linux dev-6.6 v1 1/2] spi: npcm-pspi: add full duplex support Date: Tue, 9 Jul 2024 19:02:41 +0300 Message-ID: <20240709160242.1921541-2-tmaimon77@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240709160242.1921541-1-tmaimon77@gmail.com> References: <20240709160242.1921541-1-tmaimon77@gmail.com> MIME-Version: 1.0 X-NotSetDelaration: True X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joel Stanley , Tomer Maimon Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" The NPCM PSPI handler, on TX-buffer not null, would perform a dummy read but did not save the rx-data, this was valid only for half duplex. This patch adds full duplex support for NPCM PSPI driver by storing all rx-data when the Rx-buffer is defined also for TX-buffer handling. Signed-off-by: Tomer Maimon --- drivers/spi/spi-npcm-pspi.c | 75 +++++++++++++++---------------------- 1 file changed, 30 insertions(+), 45 deletions(-) diff --git a/drivers/spi/spi-npcm-pspi.c b/drivers/spi/spi-npcm-pspi.c index 64585c2a25c5..7961b5442082 100644 --- a/drivers/spi/spi-npcm-pspi.c +++ b/drivers/spi/spi-npcm-pspi.c @@ -195,22 +195,22 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi, static void npcm_pspi_send(struct npcm_pspi *priv) { int wsize; - u16 val; + u16 val = 0; wsize = min(bytes_per_word(priv->bits_per_word), priv->tx_bytes); priv->tx_bytes -= wsize; - if (!priv->tx_buf) - return; - switch (wsize) { case 1: - val = *priv->tx_buf++; + if (priv->tx_buf) + val = *priv->tx_buf++; iowrite8(val, NPCM_PSPI_DATA + priv->base); break; case 2: - val = *priv->tx_buf++; - val = *priv->tx_buf++ | (val << 8); + if (priv->tx_buf) { + val = *priv->tx_buf++; + val = *priv->tx_buf++ | (val << 8); + } iowrite16(val, NPCM_PSPI_DATA + priv->base); break; default: @@ -222,22 +222,24 @@ static void npcm_pspi_send(struct npcm_pspi *priv) static void npcm_pspi_recv(struct npcm_pspi *priv) { int rsize; - u16 val; + u16 val_16; + u8 val_8; rsize = min(bytes_per_word(priv->bits_per_word), priv->rx_bytes); priv->rx_bytes -= rsize; - if (!priv->rx_buf) - return; - switch (rsize) { case 1: - *priv->rx_buf++ = ioread8(priv->base + NPCM_PSPI_DATA); + val_8 = ioread8(priv->base + NPCM_PSPI_DATA); + if (priv->rx_buf) + *priv->rx_buf++ = val_8; break; case 2: - val = ioread16(priv->base + NPCM_PSPI_DATA); - *priv->rx_buf++ = (val >> 8); - *priv->rx_buf++ = val & 0xff; + val_16 = ioread16(priv->base + NPCM_PSPI_DATA); + if (priv->rx_buf) { + *priv->rx_buf++ = (val_16 >> 8); + *priv->rx_buf++ = val_16 & 0xff; + } break; default: WARN_ON_ONCE(1); @@ -296,43 +298,26 @@ static irqreturn_t npcm_pspi_handler(int irq, void *dev_id) struct npcm_pspi *priv = dev_id; u8 stat; - stat = ioread8(priv->base + NPCM_PSPI_STAT); - if (!priv->tx_buf && !priv->rx_buf) return IRQ_NONE; - if (priv->tx_buf) { - if (stat & NPCM_PSPI_STAT_RBF) { - ioread8(NPCM_PSPI_DATA + priv->base); - if (priv->tx_bytes == 0) { - npcm_pspi_disable(priv); - complete(&priv->xfer_done); - return IRQ_HANDLED; - } - } - - if ((stat & NPCM_PSPI_STAT_BSY) == 0) - if (priv->tx_bytes) - npcm_pspi_send(priv); + if (priv->tx_bytes == 0 && priv->rx_bytes == 0) { + npcm_pspi_disable(priv); + complete(&priv->xfer_done); + return IRQ_HANDLED; } - if (priv->rx_buf) { - if (stat & NPCM_PSPI_STAT_RBF) { - if (!priv->rx_bytes) - return IRQ_NONE; - - npcm_pspi_recv(priv); + stat = ioread8(priv->base + NPCM_PSPI_STAT); - if (!priv->rx_bytes) { - npcm_pspi_disable(priv); - complete(&priv->xfer_done); - return IRQ_HANDLED; - } - } + /* + * first we do the read since if we do the write we previous read might + * be lost (indeed low chances) + */ + if ((stat & NPCM_PSPI_STAT_RBF) && priv->rx_bytes) + npcm_pspi_recv(priv); - if (((stat & NPCM_PSPI_STAT_BSY) == 0) && !priv->tx_buf) - iowrite8(0x0, NPCM_PSPI_DATA + priv->base); - } + if (((stat & NPCM_PSPI_STAT_BSY) == 0) && priv->tx_bytes) + npcm_pspi_send(priv); return IRQ_HANDLED; } From patchwork Tue Jul 9 16:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 1958535 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WJQlr2lLcz1xpd for ; Wed, 10 Jul 2024 02:04:08 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WJQlr1yBrz3fVN for ; Wed, 10 Jul 2024 02:04:08 +1000 (AEST) X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=taln60.nuvoton.co.il (client-ip=212.199.177.27; helo=herzl.nuvoton.co.il; envelope-from=tmaimon@taln60.nuvoton.co.il; receiver=lists.ozlabs.org) Received: from herzl.nuvoton.co.il (unknown [212.199.177.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WJQkZ2XTbz30Wb for ; Wed, 10 Jul 2024 02:02:59 +1000 (AEST) Received: from NTILML01.nuvoton.com (212.199.177.18.static.012.net.il [212.199.177.18]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 469G2pne031002 for ; Tue, 9 Jul 2024 19:02:52 +0300 Received: from NTHCML01A.nuvoton.com (10.1.8.177) by NTILML01.nuvoton.com (10.190.1.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 9 Jul 2024 19:02:50 +0300 Received: from NTHCCAS01.nuvoton.com (10.1.8.28) by NTHCML01A.nuvoton.com (10.1.8.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 10 Jul 2024 00:02:47 +0800 Received: from taln58.nuvoton.co.il (10.191.1.178) by NTHCCAS01.nuvoton.com (10.1.8.28) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 10 Jul 2024 00:02:47 +0800 Received: from taln60.nuvoton.co.il (taln60 [10.191.1.180]) by taln58.nuvoton.co.il (Postfix) with ESMTP id 15CDA5F5E7; Tue, 9 Jul 2024 19:02:46 +0300 (IDT) Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 16B12DC1BAA; Tue, 9 Jul 2024 19:02:46 +0300 (IDT) From: Tomer Maimon To: Subject: [linux dev-6.6 v1 2/2] spi: npcm-pspi: Fix transfer bits per word issue Date: Tue, 9 Jul 2024 19:02:42 +0300 Message-ID: <20240709160242.1921541-3-tmaimon77@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240709160242.1921541-1-tmaimon77@gmail.com> References: <20240709160242.1921541-1-tmaimon77@gmail.com> MIME-Version: 1.0 X-NotSetDelaration: True X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cpchiang , Joel Stanley , Tomer Maimon Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" This patch fix transfer bits per word issue by avoid polluting SPI transfer data, as it may be reused and alter the transfer length and tx/rx buffer (e.g., tpm-spi). By default, use an 8-bit data interface mode. However, change to a 16-bit mode when the transfer length is even. Signed-off-by: cpchiang Signed-off-by: Tomer Maimon --- drivers/spi/spi-npcm-pspi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-npcm-pspi.c b/drivers/spi/spi-npcm-pspi.c index 7961b5442082..726e6dc01c7d 100644 --- a/drivers/spi/spi-npcm-pspi.c +++ b/drivers/spi/spi-npcm-pspi.c @@ -160,6 +160,7 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) { struct npcm_pspi *priv = spi_master_get_devdata(spi->master); + u8 bits_per_word = 8; priv->tx_buf = t->tx_buf; priv->rx_buf = t->rx_buf; @@ -172,15 +173,14 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi, } /* - * If transfer is even length, and 8 bits per word transfer, - * then implement 16 bits-per-word transfer. + * If transfer is even length, change to use 16 bits-per-word transfer. */ - if (priv->bits_per_word == 8 && !(t->len & 0x1)) - t->bits_per_word = 16; + if (!(t->len & 0x1)) + bits_per_word = 16; - if (!priv->is_save_param || priv->bits_per_word != t->bits_per_word) { - npcm_pspi_set_transfer_size(priv, t->bits_per_word); - priv->bits_per_word = t->bits_per_word; + if (!priv->is_save_param || priv->bits_per_word != bits_per_word) { + npcm_pspi_set_transfer_size(priv, bits_per_word); + priv->bits_per_word = bits_per_word; } if (!priv->is_save_param || priv->speed_hz != t->speed_hz) { @@ -339,6 +339,7 @@ static int npcm_pspi_probe(struct platform_device *pdev) priv = spi_master_get_devdata(master); priv->master = master; priv->is_save_param = false; + priv->bits_per_word = 8; priv->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->base)) {