Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2703956imm; Sun, 30 Sep 2018 03:05:00 -0700 (PDT) X-Google-Smtp-Source: ACcGV61jNJSbpnOsNXaXVCrCRnxACpxHwdtKcuv7ModqfCsFUNa/NCwL16XUkeKq+ynC5hYiBVoT X-Received: by 2002:a63:5fc5:: with SMTP id t188-v6mr5895836pgb.346.1538301900436; Sun, 30 Sep 2018 03:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538301900; cv=none; d=google.com; s=arc-20160816; b=E3wh4MiuVCpW1zWpJeiBr4OWKFFnkWWF3GybENNiHp6lASshFTmKbi/CFK2Zb7Yzzf YoCkMFVQOtfo8jE9392A8JAj1tXcOhQEyXhoGpG/VdUUMbbyB252UUi/ts4meJ/geeLQ UX5ugUp42ICIr5LUeNXpPm4pbVWve/FEHYOm/qmGkt4vg9GRwIkeDo/qv03gQgZxk4eI FWEQA8OjOn6sL/1YAgMMu7s+Nz86jx8XihFLqUAPqJ4HGw8KhbpRedTFujfBY7A9JqKM RGHRoRiaHLGozcIT6FZrq9o6AGoOBe5k3M6pqPZ3Xfvg0TgkiZp59ByCCTh7mFhA17+u 6ExQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=YPWEasKx7XLm8Xnjv+cEErs/Dumk8ccdhWdQjpGwpWA=; b=urlSQ4P6kuVcfBJrO4gLPPO2oXuT246wiom/nbnzlpZAIg+D0AmAotqOchFtnxEGtL YT/Z7kXATsX5TlBkj6y/VNZPBwHMmXxCTsswHVavMR1+2VmakDdCnQxWiI+z5wwpExsa IM9O6WrNvkzS6U1udNGHaKd2v/7t2zb28FWSRTOgv/pojKauKgvuUMuRyysFT+QMzL6Q oEdNMjZBo+fwIyX7uuCMZ7d2v9L+WNiSn9DYs66Racxfnj5U5Dfo536CgjMYf5z+AcEq kL2PXYh6cxCyCQU/jJD6/KALHK/VOr36cCHc77DnJVpTmzO/j2uPoHpnZeGPjc361s8u uSyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67-v6si9151897pgi.606.2018.09.30.03.04.33; Sun, 30 Sep 2018 03:05:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728055AbeI3Qgv (ORCPT + 99 others); Sun, 30 Sep 2018 12:36:51 -0400 Received: from mail.bootlin.com ([62.4.15.54]:38403 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727793AbeI3Qgv (ORCPT ); Sun, 30 Sep 2018 12:36:51 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 25136207D8; Sun, 30 Sep 2018 12:04:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id E3F4F206A2; Sun, 30 Sep 2018 12:04:25 +0200 (CEST) Date: Sun, 30 Sep 2018 12:04:25 +0200 From: Boris Brezillon To: Chuanhua Han Cc: broonie@kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, eha@deif.com Subject: Re: [PATCH v2 1/4] spi: spi-mem: Add the spi_set_xfer_bpw function Message-ID: <20180930120425.7715cb29@bbrezillon> In-Reply-To: <20180930092535.24544-1-chuanhua.han@nxp.com> References: <20180930092535.24544-1-chuanhua.han@nxp.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chuanhua, On Sun, 30 Sep 2018 17:25:32 +0800 Chuanhua Han wrote: > Before we add this spi_transfer to the spi_message chain table, we need > bits_per_word_mask based on spi_control to set the bits_per_word of > this spi_transfer. Let's make it clearer: this is wrong. The spi-mem protocol is just using bytes, not custom size words. Fix the fsl-dspi driver if needed, but don't try to adjust xfer->bits_per_word in spi-mem.c, because this is inappropriate. Regards, Boris > > Signed-off-by: Chuanhua Han > --- > Changes in v2: > -The original patch is divided into multiple patches(the original > patch theme is "spi: spi-fsl-dspi: Fix support for XSPI transport > mode"),one of which is segmented. > > drivers/spi/spi-mem.c | 39 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index eb72dba71d83..717e711c0952 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -175,6 +175,41 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op) > } > EXPORT_SYMBOL_GPL(spi_mem_supports_op); > > +/** > + * spi_set_xfer_bpw() - Set the bits_per_word for each transfer based on > + * the bits_per_word_mask of the spi controller > + * @ctrl: the spi controller > + * @xfer: the spi transfer > + * > + * This function sets the bits_per_word for each transfer based on the spi > + * controller's bits_per_word_mask to improve the efficiency of spi transport. > + * > + * Return: 0 in case of success, a negative error code otherwise. > + */ > +int spi_set_xfer_bpw(struct spi_controller *ctlr, struct spi_transfer *xfer) > +{ > + if (!ctlr || !xfer) { > + dev_err(&ctlr->dev, > + "Fail to set bits_per_word for spi transfer\n"); > + return -EINVAL; > + } > + > + if (ctlr->bits_per_word_mask) { > + if (!(xfer->len % 4)) { > + if (ctlr->bits_per_word_mask & SPI_BPW_MASK(32)) > + xfer->bits_per_word = 32; > + } else if (!(xfer->len % 2)) { > + if (ctlr->bits_per_word_mask & SPI_BPW_MASK(16)) > + xfer->bits_per_word = 16; > + } else { > + xfer->bits_per_word = 8; > + } > + } > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(spi_set_xfer_bpw); > + > /** > * spi_mem_exec_op() - Execute a memory operation > * @mem: the SPI memory > @@ -252,6 +287,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > xfers[xferpos].tx_buf = tmpbuf; > xfers[xferpos].len = sizeof(op->cmd.opcode); > xfers[xferpos].tx_nbits = op->cmd.buswidth; > + spi_set_xfer_bpw(ctlr, &xfers[xferpos]); > spi_message_add_tail(&xfers[xferpos], &msg); > xferpos++; > totalxferlen++; > @@ -266,6 +302,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > xfers[xferpos].tx_buf = tmpbuf + 1; > xfers[xferpos].len = op->addr.nbytes; > xfers[xferpos].tx_nbits = op->addr.buswidth; > + spi_set_xfer_bpw(ctlr, &xfers[xferpos]); > spi_message_add_tail(&xfers[xferpos], &msg); > xferpos++; > totalxferlen += op->addr.nbytes; > @@ -276,6 +313,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1; > xfers[xferpos].len = op->dummy.nbytes; > xfers[xferpos].tx_nbits = op->dummy.buswidth; > + spi_set_xfer_bpw(ctlr, &xfers[xferpos]); > spi_message_add_tail(&xfers[xferpos], &msg); > xferpos++; > totalxferlen += op->dummy.nbytes; > @@ -291,6 +329,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > } > > xfers[xferpos].len = op->data.nbytes; > + spi_set_xfer_bpw(ctlr, &xfers[xferpos]); > spi_message_add_tail(&xfers[xferpos], &msg); > xferpos++; > totalxferlen += op->data.nbytes;