Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2680065imm; Sun, 30 Sep 2018 02:26:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV631dNk0Vnv7kQhSLPnEHfzgTfvTxFH5P4QDbsAzsYQ9C4r/SOE6sUzmsHW6zULtf/O1GVLH X-Received: by 2002:a62:8891:: with SMTP id l139-v6mr6297693pfd.198.1538299563896; Sun, 30 Sep 2018 02:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538299563; cv=none; d=google.com; s=arc-20160816; b=pvhlTQJfd0qj6J2sPwcNPvW62EiAREVLnbCX0EmTHzejT2ok5CHL6+xHx6c7cSsNnv cfbZ1gEtXaDtcqfhQJkczbLpmVJz7lWnyZc25MmOQxLISHXvKMXecCwM9BAPiVR3QjVd VJsyvciwurSHCLWyKpuvJoyMslqvTEA0vrOmNVQjG8KnS0K1rhdXEzItIDAhkC0nANDD P1+I7kzUTO63XUeji5P+S0QSQe0OUo0v3/Ls4teNO7H6CY0iHohVJJfinvrjusH+/jpn JrQUn83vNIQupleF36H6qH/PbI1iEmhZSffXhaFk064bpUSgbWVlNXzya17+ZcEL9nW1 MD4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=VIPNi4iDFZ609+iCzElGoh8z0utK2RiY+h12nY+pY4o=; b=uLjDRNNsvEoJW9KBvuNibAq5Bs20OsSSO96OaBs2OUyhuadZCzzkpDPvK/hwUiTeev euTf95xRqWrplG/DDuLEw3c+eEdZtc8Jm8G8jZYgydptwzHeuTU85OoARoqLR0zK40eV 6rx6FuE/UEmWjw4SK1HjWXPTZ3j5BLLWUAKAqKFeb63XPIwcrHLLACSJY76whDP+AiQ6 Yl8e72HyKCYP9Y5yNzg9iusT/tdZLuu1HVO8bWcHuUzcWhTItsu1GhvAvZgxXSMYe3Hj KeB/H/5dS6FjzagFnQvW1BJ8TRmRP+oFbRMBJAxZly6GjNmjVy83EayWf24c8KQUgwnE 2/2A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16-v6si8959120pgb.18.2018.09.30.02.25.49; Sun, 30 Sep 2018 02:26:03 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728195AbeI3P5o (ORCPT + 99 others); Sun, 30 Sep 2018 11:57:44 -0400 Received: from inva021.nxp.com ([92.121.34.21]:44768 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbeI3P5n (ORCPT ); Sun, 30 Sep 2018 11:57:43 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id AE589200042; Sun, 30 Sep 2018 11:25:27 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 4101D200003; Sun, 30 Sep 2018 11:25:24 +0200 (CEST) Received: from mega.ap.freescale.net (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id AA29B402C1; Sun, 30 Sep 2018 17:25:19 +0800 (SGT) From: Chuanhua Han To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, boris.brezillon@bootlin.com, eha@deif.com, Chuanhua Han Subject: [PATCH v2 1/4] spi: spi-mem: Add the spi_set_xfer_bpw function Date: Sun, 30 Sep 2018 17:25:32 +0800 Message-Id: <20180930092535.24544-1-chuanhua.han@nxp.com> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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; -- 2.17.1