Message ID | 20230320055746.2070049-1-joychakr@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1038723wrt; Sun, 19 Mar 2023 23:02:07 -0700 (PDT) X-Google-Smtp-Source: AK7set/HnmIT8/1Tj357hURyQ9SQ9BRYK1lL8WFfBItjv7y3Sf1BA6GEcABOuq2s+WBBGYk9bclB X-Received: by 2002:a05:6a20:1585:b0:d9:a977:fae with SMTP id h5-20020a056a20158500b000d9a9770faemr2260188pzj.3.1679292127274; Sun, 19 Mar 2023 23:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679292127; cv=none; d=google.com; s=arc-20160816; b=OHw6OjGJVZRLdqygtL+lxn0Ki8PxCEX+cBHenq2VcyG1TAqTqZRemZssTIaUfw5ED+ +EBN5prFyNX3hJHdFJ58I9G/qwCun5yDVsW1KsmGlWTIeQ2IZmSX7tg2BI4aYsjcOAjr ulK9NxYn0J24KQWBgWYT7NcPyy34Jkl9WnpFEThgf3qvNcvyJPdB12dzJqQ+ZO750L/b P97xWNGbNCDpn64RFLlUbF0ah0lVAZtzUrCOnBCA3Ga9nEraw+C28xy6jwcCzmP1z91H 2mLhoL0xh7INfGLVodqNqTEWCxNfoYlEq62IQqNHb+LO9Xk3lETYnYaohjvfRCgIeAbd 0MUQ== 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:mime-version:date :dkim-signature; bh=5UZlQUAmu7strlARsPQbQHPgHSDO20yOQ6kUECkItXc=; b=sfITHQDQBj0IK4xXjQQdavA29n5hlNWEPHULecSP+nGrq5Ue5AYe9XxGOIfLPQeRS7 HS6t8xrvitLrhS/Mm54EtiNHbICQhNqGLG92jfikL2lr9Ugnk/Mhaz4RdDezJ2xkz01G hpjQeMkDzq4d+kjYFEoJMYsgePFBNrvKEECnnyJGR8tfAY4Z20WpqS+hij1ZYsLILXy4 VB9X+fKXoIxq44NOVB9RTL5E/5mIeicsDZq3rI05FG0+yUEHLb7IKUw0u5E6tmPNLjrr E++lMr8WjgDmmgWqvzKI+0UIS5ScniafF4R3lGrT8vhHidUm6P6S1FQJ0CGZlDPWvVgL OyTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZGoucMXz; 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 bc22-20020a656d96000000b00503a029385asi9322778pgb.849.2023.03.19.23.01.54; Sun, 19 Mar 2023 23:02:07 -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=20210112 header.b=ZGoucMXz; 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 S229579AbjCTF6Z (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Mon, 20 Mar 2023 01:58:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjCTF6X (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 20 Mar 2023 01:58:23 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC001C590 for <linux-kernel@vger.kernel.org>; Sun, 19 Mar 2023 22:58:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-544b71b3114so101682367b3.13 for <linux-kernel@vger.kernel.org>; Sun, 19 Mar 2023 22:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679291901; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5UZlQUAmu7strlARsPQbQHPgHSDO20yOQ6kUECkItXc=; b=ZGoucMXzkK8RqTMy7kBVUHeV2x3N35UO0fn9jRYc+Wjus9NaoUiSWkJaajLEQfHP3M ju46UGN9iptwq1DJfcGaJnVRvdpuAANsUenZ5jhM+EzRz7v6kbz8UWrXS9vpB84gmRgn 7Pt2oHhruERAujOw5jkT+D2jD124DQVdCFLb3VxaMGYeIXMlU3NKl4eXZbKoadiEhl1g 840EERPWrEUBTmUt91m1oBAvMO1cpG15MZIV78pnQNzyMP0DEC7bKWgRTA+UIJ8Ypnn0 sPn8vV5VJMLc5bR9vdaRFKs5soo4RWPR0TnxJ7OSmGFfKbrSfWPOObbHGmLs7UeXvxsm Bjow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679291901; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5UZlQUAmu7strlARsPQbQHPgHSDO20yOQ6kUECkItXc=; b=3R8UcEhRSbS2joKtMgffJsFl6Q5HKevdLnie0aQpvflnUqsM4gPDX65xJLjGWFTAVG nrZMFu9q28bW8xTDUYi0HyrcM2ER1XufLNmMjmiwC1OXuuVF0F7uYl3MaO14I4KXOvR9 514b/z5o038IGj8GNhAbmS2OCN9lMrwom0u+jxT0wR5JT3QtSSP9GGwaXEZa9grQhNVQ 8cO5YPnvkxw5Re59IJaXEfVxQOEDWjKqvKEN7HaWs51cJ+ffNW3ahWX3RfPeKI/LwULj 1p9OaVd4NF7FZ11t3ytSmR8y1uFDitBgnzGCBDF+Xv15xXT5gHp/kJGqjMh+fBhf1H1x ROzA== X-Gm-Message-State: AO0yUKUw8QQUTs2+ZBxBnqYhUtUILEtxLQj4BfvYKYk1X/YFBM6Jr+Yl 95qnXlfrm/ZFo/H2be1mZaYH8o0Ubv/mBA== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a5b:9d0:0:b0:b46:4a5e:365f with SMTP id y16-20020a5b09d0000000b00b464a5e365fmr4714335ybq.8.1679291901466; Sun, 19 Mar 2023 22:58:21 -0700 (PDT) Date: Mon, 20 Mar 2023 05:57:46 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230320055746.2070049-1-joychakr@google.com> Subject: [PATCH] spi: dw: Add 32 bpw support to DW DMA Controller From: Joy Chakraborty <joychakr@google.com> To: Serge Semin <fancer.lancer@gmail.com>, Mark Brown <broonie@kernel.org> 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,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?1760865421840955813?= X-GMAIL-MSGID: =?utf-8?q?1760865421840955813?= |
Series |
spi: dw: Add 32 bpw support to DW DMA Controller
|
|
Commit Message
Joy Chakraborty
March 20, 2023, 5:57 a.m. UTC
If DW Controller is capable of 32 bits per word support then SW or DMA
controller has to write 32bit or 4byte data to the FIFO at a time.
This Patch adds support for AxSize = 4 bytes configuration from dw dma
driver if n_bytes i.e. number of bytes per write to fifo is 4.
Signed-off-by: Joy Chakraborty <joychakr@google.com>
---
drivers/spi/spi-dw-dma.c | 2 ++
1 file changed, 2 insertions(+)
Comments
Hello Joy. On Mon, Mar 20, 2023 at 05:57:46AM +0000, Joy Chakraborty wrote: > If DW Controller is capable of 32 bits per word support then SW or DMA > controller has to write 32bit or 4byte data to the FIFO at a time. > > This Patch adds support for AxSize = 4 bytes configuration from dw dma > driver if n_bytes i.e. number of bytes per write to fifo is 4. > > Signed-off-by: Joy Chakraborty <joychakr@google.com> > --- > drivers/spi/spi-dw-dma.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c > index ababb910b391..7d06ecfdebe1 100644 > --- a/drivers/spi/spi-dw-dma.c > +++ b/drivers/spi/spi-dw-dma.c > @@ -212,6 +212,8 @@ static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) > return DMA_SLAVE_BUSWIDTH_1_BYTE; > else if (n_bytes == 2) > return DMA_SLAVE_BUSWIDTH_2_BYTES; > + else if (n_bytes == 4) > + return DMA_SLAVE_BUSWIDTH_4_BYTES; In case of the DFS-width being of 32-bits size n_bytes can be 4 and theoretically _3_ (practically it's unluckily, but anyway). Here it is: ... if (dws->caps & DW_SPI_CAP_DFS32) master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); ... dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); ... So what about converting the dw_spi_dma_convert_width() method to having the switch-case statement and adding the adjacent "case 3: case 4:" statement there? * We could add the individual case-3 branch with DMA_SLAVE_BUSWIDTH_3_BYTES * returned, but the DMA-engines with 3-bytes bus width capability are * so rare. So is the case of having n_bytes == 3. Thus I guess it * won't hurt to extend the bus up to four bytes even though there are * only three bytes required. Please also note. Currently the spi-dw-dma.o driver doesn't make sure that the requested buswidth is actually supported by the DMA-engine (see dma_slave_caps.{src,dst}_addr_widths fields semantics). It would be nice to have some sanity check in there, but until then note DMA may still fail even if you specify a correct buswidth. -Serge(y) > > return DMA_SLAVE_BUSWIDTH_UNDEFINED; > } > -- > 2.40.0.rc1.284.g88254d51c5-goog >
Hi Serge(y), On Mon, Mar 20, 2023 at 7:34 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > Hello Joy. > > On Mon, Mar 20, 2023 at 05:57:46AM +0000, Joy Chakraborty wrote: > > If DW Controller is capable of 32 bits per word support then SW or DMA > > controller has to write 32bit or 4byte data to the FIFO at a time. > > > > This Patch adds support for AxSize = 4 bytes configuration from dw dma > > driver if n_bytes i.e. number of bytes per write to fifo is 4. > > > > Signed-off-by: Joy Chakraborty <joychakr@google.com> > > > --- > > drivers/spi/spi-dw-dma.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c > > index ababb910b391..7d06ecfdebe1 100644 > > --- a/drivers/spi/spi-dw-dma.c > > +++ b/drivers/spi/spi-dw-dma.c > > @@ -212,6 +212,8 @@ static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) > > return DMA_SLAVE_BUSWIDTH_1_BYTE; > > else if (n_bytes == 2) > > return DMA_SLAVE_BUSWIDTH_2_BYTES; > > > + else if (n_bytes == 4) > > + return DMA_SLAVE_BUSWIDTH_4_BYTES; > > In case of the DFS-width being of 32-bits size n_bytes can be 4 and > theoretically _3_ (practically it's unluckily, but anyway). Here > it is: > ... > if (dws->caps & DW_SPI_CAP_DFS32) > master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); > ... > dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); > ... > > So what about converting the dw_spi_dma_convert_width() method to > having the switch-case statement and adding the adjacent "case 3: > case 4:" statement there? > > * We could add the individual case-3 branch with DMA_SLAVE_BUSWIDTH_3_BYTES > * returned, but the DMA-engines with 3-bytes bus width capability are > * so rare. So is the case of having n_bytes == 3. Thus I guess it > * won't hurt to extend the bus up to four bytes even though there are > * only three bytes required. > > Please also note. Currently the spi-dw-dma.o driver doesn't make sure > that the requested buswidth is actually supported by the DMA-engine > (see dma_slave_caps.{src,dst}_addr_widths fields semantics). It would > be nice to have some sanity check in there, but until then note DMA > may still fail even if you specify a correct buswidth. > > -Serge(y) Will be creating a V2 Patch with the suggested changes. For the case of n_bytes = 3 would be using DMA_SLAVE_BUSWIDTH_4_BYTES since that is what the FIFO driver is doing as well while writing to the FIFO register in the core driver: ... if (dws->n_bytes == 1) txw = *(u8 *)(dws->tx); else if (dws->n_bytes == 2) txw = *(u16 *)(dws->tx); else txw = *(u32 *)(dws->tx); ... For the case of sanity checking of dma capability, I am planning to add it to can_dma function so that it defaults to a non-dma mode if the DMA controller is not capable of satisfying the bits/word requirement. Thanks Joy > > > > > return DMA_SLAVE_BUSWIDTH_UNDEFINED; > > } > > -- > > 2.40.0.rc1.284.g88254d51c5-goog > > On Mon, Mar 20, 2023 at 7:34 PM Serge Semin <fancer.lancer@gmail.com> wrote: > > Hello Joy. > > On Mon, Mar 20, 2023 at 05:57:46AM +0000, Joy Chakraborty wrote: > > If DW Controller is capable of 32 bits per word support then SW or DMA > > controller has to write 32bit or 4byte data to the FIFO at a time. > > > > This Patch adds support for AxSize = 4 bytes configuration from dw dma > > driver if n_bytes i.e. number of bytes per write to fifo is 4. > > > > Signed-off-by: Joy Chakraborty <joychakr@google.com> > > > --- > > drivers/spi/spi-dw-dma.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c > > index ababb910b391..7d06ecfdebe1 100644 > > --- a/drivers/spi/spi-dw-dma.c > > +++ b/drivers/spi/spi-dw-dma.c > > @@ -212,6 +212,8 @@ static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) > > return DMA_SLAVE_BUSWIDTH_1_BYTE; > > else if (n_bytes == 2) > > return DMA_SLAVE_BUSWIDTH_2_BYTES; > > > + else if (n_bytes == 4) > > + return DMA_SLAVE_BUSWIDTH_4_BYTES; > > In case of the DFS-width being of 32-bits size n_bytes can be 4 and > theoretically _3_ (practically it's unluckily, but anyway). Here > it is: > ... > if (dws->caps & DW_SPI_CAP_DFS32) > master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); > ... > dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); > ... > > So what about converting the dw_spi_dma_convert_width() method to > having the switch-case statement and adding the adjacent "case 3: > case 4:" statement there? > > * We could add the individual case-3 branch with DMA_SLAVE_BUSWIDTH_3_BYTES > * returned, but the DMA-engines with 3-bytes bus width capability are > * so rare. So is the case of having n_bytes == 3. Thus I guess it > * won't hurt to extend the bus up to four bytes even though there are > * only three bytes required. > > Please also note. Currently the spi-dw-dma.o driver doesn't make sure > that the requested buswidth is actually supported by the DMA-engine > (see dma_slave_caps.{src,dst}_addr_widths fields semantics). It would > be nice to have some sanity check in there, but until then note DMA > may still fail even if you specify a correct buswidth. > > -Serge(y) > > > > > return DMA_SLAVE_BUSWIDTH_UNDEFINED; > > } > > -- > > 2.40.0.rc1.284.g88254d51c5-goog > >
diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index ababb910b391..7d06ecfdebe1 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -212,6 +212,8 @@ static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) return DMA_SLAVE_BUSWIDTH_1_BYTE; else if (n_bytes == 2) return DMA_SLAVE_BUSWIDTH_2_BYTES; + else if (n_bytes == 4) + return DMA_SLAVE_BUSWIDTH_4_BYTES; return DMA_SLAVE_BUSWIDTH_UNDEFINED; }