Message ID | 20230420055131.2048959-6-joychakr@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp103353vqo; Wed, 19 Apr 2023 23:03:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgO8qFiLTrzPvAlntsGc74NQSrklaLzOKco1o3WmdY1Eo2/Vqk8AE4FQPxu6lsQQR4YnGI X-Received: by 2002:aca:280a:0:b0:389:234:6107 with SMTP id 10-20020aca280a000000b0038902346107mr326941oix.25.1681970593282; Wed, 19 Apr 2023 23:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681970593; cv=none; d=google.com; s=arc-20160816; b=HLIxbesEyut8vO4w6a3xRvkzA2qIDj8IIfuIsHfAIx9qJLEsP3mYug76U/RuXt4iSz c5UoNuk0qtekzPs6a2IX0577QrPVRslMgixKOgQRsP3NZd1DXvr1G/PIR1HzeFcBZJSF UeQg0hs8C7YEcyeUpaCszDa0YkuhuhLdAslwbi96iMXHPlyv9p8z0IjlY8TYss0YkcSq iGq9njTQur8/ZYjpWn1iycd4iEWxumcOoumOeZRgMZhN9SQ4FCzWXlWFFzFlm+djoqCZ mG5SKx5BXyIxNbcFSW0PwcZMeclQXSc+XF2d9V7Onf6LSoTyCMZvzAx1zyXBwTlYg8vv wIgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Fmf17OkL5SCBMBWD99k+zYNzeo76qcWOQzqTUdEaNA4=; b=iO/fEp/BsQC41PC1QuH2cxT7T+9h9UhwnMxo1CRSG0GQIRSjgTUn23iNa2+v8RgrKH CRPnhhnkAVcluP/JnzCrpCYlAbbZW9t2owwi5g69QZfvg0OF6JE4iLilim7HJI5Rn4Xv gnXrRLpLplgMkJPtYpQf3XWqil1Gu4PaEhfm0PR05eNu6kCBZ1MZNilvL75rzNA4gYAU nktswA3iY2FhbtFx8yaB/MrswD/OxE3HGJ+3fkKlA68Lutni4e0KJ+CyOZzN4G/QL1W8 +qrARC7k/85lpUcQMQ/QHjFF7UqCw9K3s9rU0jANSVEvoV8J/14IqwofS1DIiTAVJvsn 33Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=wP4LdQuS; 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=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020acaa808000000b0038cabdbe3a0si821463oie.7.2023.04.19.23.02.59; Wed, 19 Apr 2023 23:03:13 -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=@google.com header.s=20221208 header.b=wP4LdQuS; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233822AbjDTFx2 (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Thu, 20 Apr 2023 01:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233823AbjDTFxY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Apr 2023 01:53:24 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C8C40CA for <linux-kernel@vger.kernel.org>; Wed, 19 Apr 2023 22:53:12 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 188-20020a250ac5000000b00b9265c9a5e9so1359998ybk.11 for <linux-kernel@vger.kernel.org>; Wed, 19 Apr 2023 22:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681969990; x=1684561990; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Fmf17OkL5SCBMBWD99k+zYNzeo76qcWOQzqTUdEaNA4=; b=wP4LdQuSoesNvn/B4nq+v65j9QBURAtfrTfJclyIGQZl/zwlfdNdJk9rDvE+kJen70 KrMp944AeYP1jG4zsWJL8KqCjL7ehlImk2NQGbHDJXbKlV6ksBUb5Szyn63HVFN15p9X ZdZTIiKtAlOSw04ORDBVFNr9N1YF6VreBh6brM47mSF8r2T7YO9s872kdz6IUsOraA4B XZgr783K4qPobQTNyib+UTF9lzfKpDUudWPLkzkgdi8XDkeEqfoRkm4OIRbSCRjYB5cN sG+wM4RZqUlfjFPfWoc2QLvy/yXVDJxN9SM2P3SkKfFV6DTfkbKBDuZe8XiaDjpKhDr0 4u5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969990; x=1684561990; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fmf17OkL5SCBMBWD99k+zYNzeo76qcWOQzqTUdEaNA4=; b=QdehQp/+queeEZwM3FT0oPtYK3VnNOsCfXlIpSFbOjO902VPIn2lsydTe/RvrsdO1N gYk14MaDfvziK68vKBJbg0drDa09UQhKf46gOjS8wQZ1pYbvmoyl0UCl3YvpztycUpg0 0lft2TQhsENJhc8/xRzeYVOPRiAQRrCa6vvlPNTGJoZ5a2FMu9GdXUfl21bAIDFckZ1n b+FAhyH318Jt+HtrB6SdM1xmNpdSsu0YBysI14tiL3m2UEGGmxRi0Rvq58geqhcNhycS GN9rJdR+kW8UgRG+m8fRV3MmKGFSwdF4t8EfAt7zQpaFzgNiGnTRYLiIbpnBDxeQdrpW NXJg== X-Gm-Message-State: AAQBX9efWW39yooRBPPStHQ9IZuALf/WMjea6zbtnVgrhXw5QGefUdl7 amXetZxynsdOwlFQV0xnKHvUAJ4AfGQNmw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:3157:0:b0:b8f:3647:d757 with SMTP id x84-20020a253157000000b00b8f3647d757mr310587ybx.11.1681969990443; Wed, 19 Apr 2023 22:53:10 -0700 (PDT) Date: Thu, 20 Apr 2023 05:51:31 +0000 In-Reply-To: <20230420055131.2048959-1-joychakr@google.com> Mime-Version: 1.0 References: <20230420055131.2048959-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230420055131.2048959-6-joychakr@google.com> Subject: [PATCH v8 5/5] spi: dw: Round of n_bytes to power of 2 From: Joy Chakraborty <joychakr@google.com> To: Serge Semin <fancer.lancer@gmail.com>, Mark Brown <broonie@kernel.org>, Andy Shevchenko <andriy.shevchenko@intel.com> Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty <joychakr@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763673996733485139?= X-GMAIL-MSGID: =?utf-8?q?1763673996733485139?= |
Series |
spi: dw: DW SPI DMA Driver updates
|
|
Commit Message
Joy Chakraborty
April 20, 2023, 5:51 a.m. UTC
n_bytes variable in the driver represents the number of bytes per word
that needs to be sent/copied to fifo. Bits/word can be between 8 and 32
bits from the client but in memory they are a power of 2, same is mentioned
in spi.h header:
"
* @bits_per_word: Data transfers involve one or more words; word sizes
* like eight or 12 bits are common. In-memory wordsizes are
* powers of two bytes (e.g. 20 bit samples use 32 bits).
* This may be changed by the device's driver, or left at the
* default (0) indicating protocol words are eight bit bytes.
* The spi_transfer.bits_per_word can override this for each transfer.
"
Hence, round of n_bytes to a power of 2 to avoid values like 3 which
would generate unalligned/odd accesses to memory/fifo.
Fixes: a51acc2400d4 ("spi: dw: Add support for 32-bits max xfer size")
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Joy Chakraborty <joychakr@google.com>
---
drivers/spi/spi-dw-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Apr 20, 2023 at 05:51:31AM +0000, Joy Chakraborty wrote: > n_bytes variable in the driver represents the number of bytes per word > that needs to be sent/copied to fifo. Bits/word can be between 8 and 32 > bits from the client but in memory they are a power of 2, same is mentioned > in spi.h header: > " > * @bits_per_word: Data transfers involve one or more words; word sizes > * like eight or 12 bits are common. In-memory wordsizes are > * powers of two bytes (e.g. 20 bit samples use 32 bits). > * This may be changed by the device's driver, or left at the > * default (0) indicating protocol words are eight bit bytes. > * The spi_transfer.bits_per_word can override this for each transfer. > " > > Hence, round of n_bytes to a power of 2 to avoid values like 3 which > would generate unalligned/odd accesses to memory/fifo. > > Fixes: a51acc2400d4 ("spi: dw: Add support for 32-bits max xfer size") > Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com> > Signed-off-by: Joy Chakraborty <joychakr@google.com> > --- > drivers/spi/spi-dw-core.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c > index c3bfb6c84cab..a6486db46c61 100644 > --- a/drivers/spi/spi-dw-core.c > +++ b/drivers/spi/spi-dw-core.c > @@ -426,7 +426,7 @@ static int dw_spi_transfer_one(struct spi_controller *master, > int ret; > > dws->dma_mapped = 0; > - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); > + dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); Almost 100 symbols looks too bulky. Moreover single-lined nested call makes things a bit harder to read. What about formatting it up like this? dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); or like this: dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); Splitting the line into chunks will simplify the visual differentiation between the outer and inner calls. * Note even though the 80-char columns limit isn't that strict rule now, but it's still preferable unless exceeding the limit significantly increases readability. The update you suggest doesn't seem like the case which would improve the readability. -Serge(y) > dws->tx = (void *)transfer->tx_buf; > dws->tx_len = transfer->len / dws->n_bytes; > dws->rx = transfer->rx_buf; > -- > 2.40.0.634.g4ca3ef3211-goog >
On Fri, Apr 21, 2023 at 2:23 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > On Thu, Apr 20, 2023 at 05:51:31AM +0000, Joy Chakraborty wrote: > > n_bytes variable in the driver represents the number of bytes per word > > that needs to be sent/copied to fifo. Bits/word can be between 8 and 32 > > bits from the client but in memory they are a power of 2, same is mentioned > > in spi.h header: > > " > > * @bits_per_word: Data transfers involve one or more words; word sizes > > * like eight or 12 bits are common. In-memory wordsizes are > > * powers of two bytes (e.g. 20 bit samples use 32 bits). > > * This may be changed by the device's driver, or left at the > > * default (0) indicating protocol words are eight bit bytes. > > * The spi_transfer.bits_per_word can override this for each transfer. > > " > > > > Hence, round of n_bytes to a power of 2 to avoid values like 3 which > > would generate unalligned/odd accesses to memory/fifo. > > > > Fixes: a51acc2400d4 ("spi: dw: Add support for 32-bits max xfer size") > > Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com> > > Signed-off-by: Joy Chakraborty <joychakr@google.com> > > --- > > drivers/spi/spi-dw-core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c > > index c3bfb6c84cab..a6486db46c61 100644 > > --- a/drivers/spi/spi-dw-core.c > > +++ b/drivers/spi/spi-dw-core.c > > @@ -426,7 +426,7 @@ static int dw_spi_transfer_one(struct spi_controller *master, > > int ret; > > > > dws->dma_mapped = 0; > > > - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); > > + dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); > > Almost 100 symbols looks too bulky. Moreover single-lined nested call > makes things a bit harder to read. What about formatting it up like > this? > > dws->n_bytes = > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > BITS_PER_BYTE)); > > or like this: > > dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > BITS_PER_BYTE)); > > Splitting the line into chunks will simplify the visual > differentiation between the outer and inner calls. > > * Note even though the 80-char columns limit isn't that strict rule > now, but it's still preferable unless exceeding the limit significantly > increases readability. The update you suggest doesn't seem like the case > which would improve the readability. > Sure, I can make the following change in the formatting and send the patch series: dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); Thanks Joy > -Serge(y) > > > dws->tx = (void *)transfer->tx_buf; > > dws->tx_len = transfer->len / dws->n_bytes; > > dws->rx = transfer->rx_buf; > > -- > > 2.40.0.634.g4ca3ef3211-goog > >
On Fri, Apr 21, 2023 at 02:51:58PM +0530, Joy Chakraborty wrote: > On Fri, Apr 21, 2023 at 2:23 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > > > On Thu, Apr 20, 2023 at 05:51:31AM +0000, Joy Chakraborty wrote: > > > n_bytes variable in the driver represents the number of bytes per word > > > that needs to be sent/copied to fifo. Bits/word can be between 8 and 32 > > > bits from the client but in memory they are a power of 2, same is mentioned > > > in spi.h header: > > > " > > > * @bits_per_word: Data transfers involve one or more words; word sizes > > > * like eight or 12 bits are common. In-memory wordsizes are > > > * powers of two bytes (e.g. 20 bit samples use 32 bits). > > > * This may be changed by the device's driver, or left at the > > > * default (0) indicating protocol words are eight bit bytes. > > > * The spi_transfer.bits_per_word can override this for each transfer. > > > " > > > > > > Hence, round of n_bytes to a power of 2 to avoid values like 3 which > > > would generate unalligned/odd accesses to memory/fifo. > > > > > > Fixes: a51acc2400d4 ("spi: dw: Add support for 32-bits max xfer size") > > > Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com> > > > Signed-off-by: Joy Chakraborty <joychakr@google.com> > > > --- > > > drivers/spi/spi-dw-core.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c > > > index c3bfb6c84cab..a6486db46c61 100644 > > > --- a/drivers/spi/spi-dw-core.c > > > +++ b/drivers/spi/spi-dw-core.c > > > @@ -426,7 +426,7 @@ static int dw_spi_transfer_one(struct spi_controller *master, > > > int ret; > > > > > > dws->dma_mapped = 0; > > > > > - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); > > > + dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); > > > > Almost 100 symbols looks too bulky. Moreover single-lined nested call > > makes things a bit harder to read. What about formatting it up like > > this? > > > > dws->n_bytes = > > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > > BITS_PER_BYTE)); > > > > or like this: > > > > dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > > BITS_PER_BYTE)); > > > > Splitting the line into chunks will simplify the visual > > differentiation between the outer and inner calls. > > > > * Note even though the 80-char columns limit isn't that strict rule > > now, but it's still preferable unless exceeding the limit significantly > > increases readability. The update you suggest doesn't seem like the case > > which would improve the readability. > > > > Sure, I can make the following change in the formatting and send the > patch series: > dws->n_bytes = > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > BITS_PER_BYTE)); Ok. Thanks in advance. -Serge(y) > > Thanks > Joy > > -Serge(y) > > > > > dws->tx = (void *)transfer->tx_buf; > > > dws->tx_len = transfer->len / dws->n_bytes; > > > dws->rx = transfer->rx_buf; > > > -- > > > 2.40.0.634.g4ca3ef3211-goog > > >
From: Joy Chakraborty > Sent: 21 April 2023 10:22 ... > Sure, I can make the following change in the formatting and send the > patch series: > dws->n_bytes = > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > BITS_PER_BYTE)); Won't checkpatch bleat about that? Is it ever actually valid for the caller to provide a value that isn't 8, 16 or 32 ? I'm sure it looked as though some other lengths/counts where likely to go badly wrong. I know there are times when it is useful to bit-bang 'odd' numbers of bits - like command+address+delay for fast reads but that is a sub-32bit transfer so (at least somewhere) is 1 word but not all the bits. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Fri, Apr 21, 2023 at 04:39:30PM +0000, David Laight wrote: > From: Joy Chakraborty > > Sent: 21 April 2023 10:22 > ... > > Sure, I can make the following change in the formatting and send the > > patch series: > > dws->n_bytes = > > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > > BITS_PER_BYTE)); > > Won't checkpatch bleat about that? Why would it? > > Is it ever actually valid for the caller to provide a > value that isn't 8, 16 or 32 ? Judging by this https://elixir.bootlin.com/linux/v6.3-rc7/source/drivers/spi/spi.c#L3630 it is. SPI-controller also supports word lengths within the pre-synthesized range. So it's up to the SPI-peripherals and their protocols what word length to select. -Serge(y) > > I'm sure it looked as though some other lengths/counts > where likely to go badly wrong. > > I know there are times when it is useful to bit-bang 'odd' > numbers of bits - like command+address+delay for fast reads > but that is a sub-32bit transfer so (at least somewhere) > is 1 word but not all the bits. > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)
On Fri, Apr 21, 2023 at 10:18 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > On Fri, Apr 21, 2023 at 04:39:30PM +0000, David Laight wrote: > > From: Joy Chakraborty > > > Sent: 21 April 2023 10:22 > > ... > > > Sure, I can make the following change in the formatting and send the > > > patch series: > > > dws->n_bytes = > > > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > > > BITS_PER_BYTE)); > > > > > Won't checkpatch bleat about that? > > Why would it? I ran checkpatch on this and it seems to be fine with minor spacing changes. > > > > > Is it ever actually valid for the caller to provide a > > value that isn't 8, 16 or 32 ? > > Judging by this > https://elixir.bootlin.com/linux/v6.3-rc7/source/drivers/spi/spi.c#L3630 > it is. SPI-controller also supports word lengths within the > pre-synthesized range. So it's up to the SPI-peripherals and their > protocols what word length to select. > > -Serge(y) > > > > > I'm sure it looked as though some other lengths/counts > > where likely to go badly wrong. > > > > I know there are times when it is useful to bit-bang 'odd' > > numbers of bits - like command+address+delay for fast reads > > but that is a sub-32bit transfer so (at least somewhere) > > is 1 word but not all the bits. > > > > David > > > > - > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > > Registration No: 1397386 (Wales)
On Fri, Apr 21, 2023 at 10:40:44PM +0530, Joy Chakraborty wrote: > On Fri, Apr 21, 2023 at 10:18 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > > > On Fri, Apr 21, 2023 at 04:39:30PM +0000, David Laight wrote: > > > From: Joy Chakraborty > > > > Sent: 21 April 2023 10:22 > > > ... > > > > Sure, I can make the following change in the formatting and send the > > > > patch series: > > > > dws->n_bytes = > > > > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > > > > BITS_PER_BYTE)); > > > > > > > > Won't checkpatch bleat about that? > > > > Why would it? > > I ran checkpatch on this and it seems to be fine with minor spacing changes. What spacing do you mean? No problem with the change as is: [fancer@mobilestation] kernel $ git show HEAD | grep -A1 -B2 roundup_pow_of_two - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); + dws->n_bytes = + roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, + BITS_PER_BYTE)); [fancer@mobilestation] kernel $ ./scripts/checkpatch.pl --git HEAD total: 0 errors, 0 warnings, 10 lines checked Commit e18b699257db ("spi: dw: Round of n_bytes to power of 2") has no obvious style problems and is ready for submission. -Serge(y) > > > > > > > > > Is it ever actually valid for the caller to provide a > > > value that isn't 8, 16 or 32 ? > > > > Judging by this > > https://elixir.bootlin.com/linux/v6.3-rc7/source/drivers/spi/spi.c#L3630 > > it is. SPI-controller also supports word lengths within the > > pre-synthesized range. So it's up to the SPI-peripherals and their > > protocols what word length to select. > > > > -Serge(y) > > > > > > > > I'm sure it looked as though some other lengths/counts > > > where likely to go badly wrong. > > > > > > I know there are times when it is useful to bit-bang 'odd' > > > numbers of bits - like command+address+delay for fast reads > > > but that is a sub-32bit transfer so (at least somewhere) > > > is 1 word but not all the bits. > > > > > > David > > > > > > - > > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > > > Registration No: 1397386 (Wales)
On Fri, Apr 21, 2023 at 10:45 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > On Fri, Apr 21, 2023 at 10:40:44PM +0530, Joy Chakraborty wrote: > > On Fri, Apr 21, 2023 at 10:18 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > > > > > On Fri, Apr 21, 2023 at 04:39:30PM +0000, David Laight wrote: > > > > From: Joy Chakraborty > > > > > Sent: 21 April 2023 10:22 > > > > ... > > > > > Sure, I can make the following change in the formatting and send the > > > > > patch series: > > > > > dws->n_bytes = > > > > > roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > > > > > BITS_PER_BYTE)); > > > > > > > > > > > Won't checkpatch bleat about that? > > > > > > Why would it? > > > > I ran checkpatch on this and it seems to be fine with minor spacing changes. > > What spacing do you mean? No problem with the change as is: > [fancer@mobilestation] kernel $ git show HEAD | grep -A1 -B2 roundup_pow_of_two > - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); > + dws->n_bytes = > + roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, > + BITS_PER_BYTE)); > [fancer@mobilestation] kernel $ ./scripts/checkpatch.pl --git HEAD > total: 0 errors, 0 warnings, 10 lines checked > > Commit e18b699257db ("spi: dw: Round of n_bytes to power of 2") has no obvious style problems and is ready for submission. > > -Serge(y) > Sorry for my error, it looks like my email client does not show it correctly. What I was going to upload in V9 is the same as you mentioned. Thanks Joy > > > > > > > > > > > > > Is it ever actually valid for the caller to provide a > > > > value that isn't 8, 16 or 32 ? > > > > > > Judging by this > > > https://elixir.bootlin.com/linux/v6.3-rc7/source/drivers/spi/spi.c#L3630 > > > it is. SPI-controller also supports word lengths within the > > > pre-synthesized range. So it's up to the SPI-peripherals and their > > > protocols what word length to select. > > > > > > -Serge(y) > > > > > > > > > > > I'm sure it looked as though some other lengths/counts > > > > where likely to go badly wrong. > > > > > > > > I know there are times when it is useful to bit-bang 'odd' > > > > numbers of bits - like command+address+delay for fast reads > > > > but that is a sub-32bit transfer so (at least somewhere) > > > > is 1 word but not all the bits. > > > > > > > > David > > > > > > > > - > > > > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > > > > Registration No: 1397386 (Wales)
diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c index c3bfb6c84cab..a6486db46c61 100644 --- a/drivers/spi/spi-dw-core.c +++ b/drivers/spi/spi-dw-core.c @@ -426,7 +426,7 @@ static int dw_spi_transfer_one(struct spi_controller *master, int ret; dws->dma_mapped = 0; - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); + dws->n_bytes = roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE)); dws->tx = (void *)transfer->tx_buf; dws->tx_len = transfer->len / dws->n_bytes; dws->rx = transfer->rx_buf;