From patchwork Mon May 15 14:07:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 94168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6966290vqo; Mon, 15 May 2023 07:31:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5q2txS6H1YhtMi/Yp4X+hSXSrQ27+Y4xlorHrwPnwfaHZiDbCfZ8gifboSiyp/psjmOGbk X-Received: by 2002:a05:6a20:7349:b0:104:2d89:8f5d with SMTP id v9-20020a056a20734900b001042d898f5dmr16649550pzc.10.1684161102547; Mon, 15 May 2023 07:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684161102; cv=none; d=google.com; s=arc-20160816; b=XmUQ88Fx/vl33m90dTUHW4Wg2c3vQw44bkG4hOIpyYrTlYAAHGAesdMRG6UIVONHzg MA3qkN4fGbSAEzLshVtL021rMgebatwKuZZwqsn5k7EjBz3bWJwrXPzyLoVBhW8rMQBs qMcXSXAXufctfbGdGx1IegH/9ODXSsTodBleAoA/CTTS59HtvzFVmBamcN77lsWDK7m7 aDZrSY90b+hEawob6TAa9L55V9ZkqJK+6q1R/VRlvSeQ0NU2Qy5xH1bVkzwXrEJ2lb5L ZUKVZqc+R0Fo3T1waJcVIKK7VBP7GGd7j1aK6JfqNwb9vCv/cvPJktiTpHYRBqK9fkoQ BAVg== 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; bh=Uo+Xjdp8g4l5f7Q1hhdsevFDSUADg5RUa/zANDnT9Xw=; b=FR6K2U4q0cwcfJR82FC3E4mO0tSg6ITx6kAYAFm3eNDg51jUzbL8YiHxL5MmWRneOR IJIRwJyPus5ZSwNBWt68Wh95FRmO3ST2Q8aQ+xMkYzYOA0L7qL/KvKTXdhAVTdrbMAhI WDCJXx6+LH7ywkLgX8+GdaBmTJv5SvgJQCOfVf7U5tBWzfzfElGuTQHhllfoMxBC9tFV 41Rzdl5vsa0R+Gx2rzLJbe6Rhl7RZYGC7tw1zaLGkQZLruW0f12PoWfas6dmeshZ+8t2 DrccMJNyWQ0pp9lmu6VsMgXe66ZZpAHERQD1mn7BJjanJfMiqvu8ddcXEA6WeOCoVaqX 8a8A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a13-20020aa7970d000000b006281ec442absi17576991pfg.309.2023.05.15.07.31.26; Mon, 15 May 2023 07:31:42 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240266AbjEOOUx (ORCPT + 99 others); Mon, 15 May 2023 10:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240436AbjEOOUn (ORCPT ); Mon, 15 May 2023 10:20:43 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 847DE2D4F; Mon, 15 May 2023 07:20:39 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4QKh686nRNz9sff; Mon, 15 May 2023 16:08:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sP8Prco6FGrk; Mon, 15 May 2023 16:08:00 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4QKh660K6pz9sfM; Mon, 15 May 2023 16:07:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id EE52A8B770; Mon, 15 May 2023 16:07:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id YeSbbQzs-Bkw; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.36]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B28C18B763; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 34FE7Poh583509 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 May 2023 16:07:25 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 34FE7P9G583508; Mon, 15 May 2023 16:07:25 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Mark Brown Subject: [PATCH 1/2][For 5.15/5.10/5.4] spi: fsl-spi: Re-organise transfer bits_per_word adaptation Date: Mon, 15 May 2023 16:07:16 +0200 Message-Id: <1e4bfb4850ba849c316f48a0ab0d7123da0e2f54.1684156552.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> References: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684159635; l=4013; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=5Lf/4Fp+QxG7Girtdqkg/6yPgFLDCR7G2jYrA/4gH7M=; b=n/nc1XrPunIxYVs+C91SiaBWUQz7EQotCpbnWzkQnrWyZJAuP9PYD8FAok5YUKMZbB6tDx27t 8oi3cU8toekARz39ad/vDwPWmDli59fCmFYun/sUCYfs451s5lHs74v X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1765970732274227117?= X-GMAIL-MSGID: =?utf-8?q?1765970912255404445?= (backported from upstream 8a5299a1278eadf1e08a598a5345c376206f171e) For different reasons, fsl-spi driver performs bits_per_word modifications for different reasons: - On CPU mode, to minimise amount of interrupts - On CPM/QE mode to work around controller byte order For CPU mode that's done in fsl_spi_prepare_message() while for CPM mode that's done in fsl_spi_setup_transfer(). Reunify all of it in fsl_spi_prepare_message(), and catch impossible cases early through master's bits_per_word_mask instead of returning EINVAL later. Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/0ce96fe96e8b07cba0613e4097cfd94d09b8919a.1680371809.git.christophe.leroy@csgroup.eu Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-spi.c | 50 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 1bad0ceac81b..f1d4aa310233 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -203,26 +203,6 @@ static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs, return bits_per_word; } -static int mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs, - struct spi_device *spi, - int bits_per_word) -{ - /* CPM/QE uses Little Endian for words > 8 - * so transform 16 and 32 bits words into 8 bits - * Unfortnatly that doesn't work for LSB so - * reject these for now */ - /* Note: 32 bits word, LSB works iff - * tfcr/rfcr is set to CPMFCR_GBL */ - if (spi->mode & SPI_LSB_FIRST && - bits_per_word > 8) - return -EINVAL; - if (bits_per_word <= 8) - return bits_per_word; - if (bits_per_word == 16 || bits_per_word == 32) - return 8; /* pretend its 8 bits */ - return -EINVAL; -} - static int fsl_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) { @@ -250,9 +230,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi, bits_per_word = mspi_apply_cpu_mode_quirks(cs, spi, mpc8xxx_spi, bits_per_word); - else - bits_per_word = mspi_apply_qe_mode_quirks(cs, spi, - bits_per_word); if (bits_per_word < 0) return bits_per_word; @@ -370,14 +347,27 @@ static int fsl_spi_do_one_msg(struct spi_master *master, * In CPU mode, optimize large byte transfers to use larger * bits_per_word values to reduce number of interrupts taken. */ - if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { - list_for_each_entry(t, &m->transfers, transfer_list) { + list_for_each_entry(t, &m->transfers, transfer_list) { + if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { if (t->len < 256 || t->bits_per_word != 8) continue; if ((t->len & 3) == 0) t->bits_per_word = 32; else if ((t->len & 1) == 0) t->bits_per_word = 16; + } else { + /* + * CPM/QE uses Little Endian for words > 8 + * so transform 16 and 32 bits words into 8 bits + * Unfortnatly that doesn't work for LSB so + * reject these for now + * Note: 32 bits word, LSB works iff + * tfcr/rfcr is set to CPMFCR_GBL + */ + if (m->spi->mode & SPI_LSB_FIRST && t->bits_per_word > 8) + return -EINVAL; + if (t->bits_per_word == 16 || t->bits_per_word == 32) + t->bits_per_word = 8; /* pretend its 8 bits */ } } @@ -635,8 +625,14 @@ static struct spi_master *fsl_spi_probe(struct device *dev, if (mpc8xxx_spi->type == TYPE_GRLIB) fsl_spi_grlib_probe(dev); - master->bits_per_word_mask = - (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)) & + if (mpc8xxx_spi->flags & SPI_CPM_MODE) + master->bits_per_word_mask = + (SPI_BPW_RANGE_MASK(4, 8) | SPI_BPW_MASK(16) | SPI_BPW_MASK(32)); + else + master->bits_per_word_mask = + (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)); + + master->bits_per_word_mask &= SPI_BPW_RANGE_MASK(1, mpc8xxx_spi->max_bits_per_word); if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) From patchwork Mon May 15 14:07:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 94164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6959990vqo; Mon, 15 May 2023 07:22:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7lU21986qyp9+lrf+5MjxO2o1Egg/PMb+wU1f0T6JQfWo88EqShJBx+HZEV/SMoioJ5Elu X-Received: by 2002:a17:90a:db8c:b0:24b:52cb:9a31 with SMTP id h12-20020a17090adb8c00b0024b52cb9a31mr44778771pjv.22.1684160546609; Mon, 15 May 2023 07:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684160546; cv=none; d=google.com; s=arc-20160816; b=nuumt/MyZyPmYsplcK/pel3kbCDOpzvcqjUHdjQjg9BatevQHXrBSrPDDviaD5WzS+ VagTK0VbzilwfVam8MLIAvXp8q02ENR0YtCBeMtzOE6/cQcqDlAQrGyfITiqPem7UFX0 4+UFihKEwOqzJ1RIePspPhpvIacdZJXk23QLcQJ3Lc/NrBfJ8GEHLz0TR1ZK2n/vJ2AH qC8JmAVGE9KycL/jb3gnkKHcPpo0w+t8GjQ+sYkwL6hj31xXZyfsIvFuvMPTQya4wGye Ebs4KaObnAxlXT28lwVAXoyjyf5JCcjzrwOuZbAyWJHRySV7OCgZJamk+Zcy19koVQQh +OIA== 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; bh=WZ3cohfKh9Qtq+uI964plygUGh28Z3jFv5reOd9UgPw=; b=DZj9koM1jaUxqBsPD86VckOwSHhuBfp/awAZ1khp5XBRzi5S7BKByoZwnfvUpGuqKL Y/L0xAnxt1t4+tMTrnemEY57Myir88dI87fX4e+l6bdQDNrgZjSZHs1L0cljf6v5TX5w C7HItUsAf0mTzKJpLXxEtiqBXlIKRYAwwbLyRyhW+Y1LtEEa5+5TQ/scZ7Mj+QmEZmUb kpFSczMZCN8yzqCdeKizbrI/C9LuOtWYBXGFalT01bRpetCU1y2rFh2klQNC2ZgA2M5c ysAoR1e11rnhmrQQphiAeLKJuE+qwIynNeAoe+hPDLYUKep+lqhKrcW0A45UsyT6KCgu otxw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f9-20020a17090ace0900b002527f171401si12023533pju.182.2023.05.15.07.21.47; Mon, 15 May 2023 07:22:26 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239639AbjEOOU2 (ORCPT + 99 others); Mon, 15 May 2023 10:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237208AbjEOOU0 (ORCPT ); Mon, 15 May 2023 10:20:26 -0400 X-Greylist: delayed 732 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 15 May 2023 07:20:11 PDT Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45ABD1BFB; Mon, 15 May 2023 07:20:11 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4QKh661Dlvz9sfQ; Mon, 15 May 2023 16:07:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w4uLJCqqlfgU; Mon, 15 May 2023 16:07:58 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4QKh653GcGz9sfH; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 612298B770; Mon, 15 May 2023 16:07:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id XkCE40cnUtUC; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.36]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 1C1658B763; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 34FE7P2x583513 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 May 2023 16:07:25 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 34FE7PPr583512; Mon, 15 May 2023 16:07:25 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Mark Brown Subject: [PATCH 2/2][For 5.15/5.10/5.4] spi: fsl-cpm: Use 16 bit mode for large transfers with even size Date: Mon, 15 May 2023 16:07:17 +0200 Message-Id: <3a1b8774ad7004acb594fbf220f98488dbaa2896.1684156552.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <1e4bfb4850ba849c316f48a0ab0d7123da0e2f54.1684156552.git.christophe.leroy@csgroup.eu> References: <1e4bfb4850ba849c316f48a0ab0d7123da0e2f54.1684156552.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684159635; l=3126; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=rWNKzWkmM4gdwZv1WlKPnv51S6gxaEarWczSGvDbNzU=; b=oSiEq83dOBUPrvqbyLZ/irXtj4gfJMUpwNyaspQMKeCsGOEpp4RJ69yRyVpJasLnuv0zqY1L+ WRp2fzaSzmuCaxKZGPG11CgXaCdmBLzPVLcokvicW5OtVYvRVTtLEgr X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR 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?1765970329055111672?= X-GMAIL-MSGID: =?utf-8?q?1765970329055111672?= (cherry picked from upstream fc96ec826bced75cc6b9c07a4ac44bbf651337ab) On CPM, the RISC core is a lot more efficiant when doing transfers in 16-bits chunks than in 8-bits chunks, but unfortunately the words need to be byte swapped as seen in a previous commit. So, for large tranfers with an even size, allocate a temporary tx buffer and byte-swap data before and after transfer. This change allows setting higher speed for transfer. For instance on an MPC 8xx (CPM1 comms RISC processor), the documentation tells that transfer in byte mode at 1 kbit/s uses 0.200% of CPM load at 25 MHz while a word transfer at the same speed uses 0.032% of CPM load. This means the speed can be 6 times higher in word mode for the same CPM load. For the time being, only do it on CPM1 as there must be a trade-off between the CPM load reduction and the CPU load required to byte swap the data. Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/f2e981f20f92dd28983c3949702a09248c23845c.1680371809.git.christophe.leroy@csgroup.eu Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-cpm.c | 23 +++++++++++++++++++++++ drivers/spi/spi-fsl-spi.c | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c index ee905880769e..7832ce330b29 100644 --- a/drivers/spi/spi-fsl-cpm.c +++ b/drivers/spi/spi-fsl-cpm.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "spi-fsl-cpm.h" #include "spi-fsl-lib.h" @@ -120,6 +121,21 @@ int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, mspi->rx_dma = mspi->dma_dummy_rx; mspi->map_rx_dma = 0; } + if (t->bits_per_word == 16 && t->tx_buf) { + const u16 *src = t->tx_buf; + u16 *dst; + int i; + + dst = kmalloc(t->len, GFP_KERNEL); + if (!dst) + return -ENOMEM; + + for (i = 0; i < t->len >> 1; i++) + dst[i] = cpu_to_le16p(src + i); + + mspi->tx = dst; + mspi->map_tx_dma = 1; + } if (mspi->map_tx_dma) { void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */ @@ -173,6 +189,13 @@ void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) if (mspi->map_rx_dma) dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE); mspi->xfer_in_progress = NULL; + + if (t->bits_per_word == 16 && t->rx_buf) { + int i; + + for (i = 0; i < t->len; i += 2) + le16_to_cpus(t->rx_buf + i); + } } EXPORT_SYMBOL_GPL(fsl_spi_cpm_bufs_complete); diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index f1d4aa310233..63302e21e574 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -368,6 +368,9 @@ static int fsl_spi_do_one_msg(struct spi_master *master, return -EINVAL; if (t->bits_per_word == 16 || t->bits_per_word == 32) t->bits_per_word = 8; /* pretend its 8 bits */ + if (t->bits_per_word == 8 && t->len >= 256 && + (mpc8xxx_spi->flags & SPI_CPM1)) + t->bits_per_word = 16; } }