From patchwork Thu Apr 20 05:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13217902 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B76B1C77B72 for ; Thu, 20 Apr 2023 05:52:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233633AbjDTFw4 (ORCPT ); Thu, 20 Apr 2023 01:52:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbjDTFwx (ORCPT ); Thu, 20 Apr 2023 01:52:53 -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 5AA2140D9 for ; Wed, 19 Apr 2023 22:52:52 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id n66-20020a254045000000b00b95a177fbe4so1318716yba.18 for ; Wed, 19 Apr 2023 22:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681969971; x=1684561971; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nKDaeGp5EKkZDqIsokus1OmDmfvkWgZNrRNY08uRrUc=; b=hBdio5Hud+tuSe+ZQm4GoT0N6QYKFYKojEcyGL/qjoyc/axMq0gDkSpE/VFgh26tbc 9q8iGkzUfuitRECTe5d1TJDHxKIm68sYk9FF+2MLlGf8ehbAadYIXFn7QdnMecMeY5Fj LRSXD3aAKe5FaJ/yWBXcVwVpasAaWJ1hXi4lkvhtQFsmrlluih/cIQc+YesdMJaAPopG p4ZeKe5wK2visIca0s9Uq53oKncjovWGL61aF0nIW5v3YmpZuniZF0+u3C6jjLrI23Bj 1EzesEb/RvRHXb2DfDm5DByZUrgffeA8os1m2UO1GM0n12djtpg2+3JkRZCaF+HnRb5K jqlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969971; x=1684561971; 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=nKDaeGp5EKkZDqIsokus1OmDmfvkWgZNrRNY08uRrUc=; b=I2X4fOyl22ywp6mnQDSA8GpcTk+5buTsU/cpVso4w2on+XDFk8zi3jWY9vXNxuCOLB gIJum/JykkUzi28kLIQYbL1yU5MH8vBu09dCMbMHLmfnZnlNc6w2d9Bg0Db8qV+pQJJ8 gxgh2VOQp8GEboK421GsjcW2GeQ+L+tjbvuKUPbqpyF5NaMYHG1TkoycpQO15n/iMd8r JCdT5MHK2c4X/eOsPh2f+aEemPiqxk67lsq/15LbFGd1XH5MkaXNCW/iOuZO7T9jRo44 nW40HL/m2adp9/Pv/pnabPpuGAsdK431kZ0lMOQj9oTg9VX8tKC2qo063/Neqwi++sRE bjBA== X-Gm-Message-State: AAQBX9cB2wTeYxozQJzcpQjevWTAhkSue8LDjpays147jcf9OCMx+Yzz EVb7LPVNNQjwrmMoozru3/LobwbaD4QT3g== X-Google-Smtp-Source: AKy350Zbkqg+2egd1zA6LpwJpF6Lng4fPe/eUc7oJU056vMPU6dj6eIsj7Vu0a4/TXGx9hYvanOn+J4Ea0qdNw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:d284:0:b0:b92:2c78:1481 with SMTP id j126-20020a25d284000000b00b922c781481mr308871ybg.12.1681969971649; Wed, 19 Apr 2023 22:52:51 -0700 (PDT) Date: Thu, 20 Apr 2023 05:51:27 +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-2-joychakr@google.com> Subject: [PATCH v8 1/5] spi: dw: Add 32 bpw support to SPI DW DMA driver From: Joy Chakraborty To: Serge Semin , Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Add Support for AxSize = 4 bytes configuration from dw dma driver if n_bytes i.e. number of bytes per write to fifo is 4. Number of bytes written to fifo per write is depended on the bits/word configuration being used which the DW core driver translates to n_bytes. Hence, for bits per word values between 17 and 32 n_bytes should be equal to 4. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index ababb910b391..c1b42cb59965 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -208,12 +208,16 @@ static bool dw_spi_can_dma(struct spi_controller *master, static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) { - if (n_bytes == 1) + switch (n_bytes) { + case 1: return DMA_SLAVE_BUSWIDTH_1_BYTE; - else if (n_bytes == 2) + case 2: return DMA_SLAVE_BUSWIDTH_2_BYTES; - - return DMA_SLAVE_BUSWIDTH_UNDEFINED; + case 4: + return DMA_SLAVE_BUSWIDTH_4_BYTES; + default: + return DMA_SLAVE_BUSWIDTH_UNDEFINED; + } } static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed) From patchwork Thu Apr 20 05:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13217903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C644C77B73 for ; Thu, 20 Apr 2023 05:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233713AbjDTFxC (ORCPT ); Thu, 20 Apr 2023 01:53:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233788AbjDTFw7 (ORCPT ); Thu, 20 Apr 2023 01:52:59 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD03040D5 for ; Wed, 19 Apr 2023 22:52:56 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54fba72c1adso14356537b3.18 for ; Wed, 19 Apr 2023 22:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681969976; x=1684561976; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8xCBVt+yTzL9gm6ligFFQCFbRni90/tGiHt7eRsjBtY=; b=GYjayEHTH0DTFM7kLY9bVfMA2J7m/p62X4TtHqIrE81LrGEdzUtYqYo+3PqkGKe/PP xFKTLUmHAalIQMGpb5k7bntgsjNGP0pZPo4Na5+8sawig3szQDTNnx25Aq31dRhf41we m7XlLrEnhZfXFcS1Rwj1lnrvIoGm+j9yPTsQLQjZmDtx6mRbmAxSM2Pr+g3zYCQYPp2X MktbbEevw9lhMaNqnpy0Q4NgotUlEfww8ij7NuvbU2VHsEwHYKFhdpL/nipcBOvMGYwq SsQZO0hFLViLjndPQObcqY7+eZq9kXkjCRunkR5OxygH+N2I7Y9DYlohfTWdLtcRcvqx fcJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969976; x=1684561976; 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=8xCBVt+yTzL9gm6ligFFQCFbRni90/tGiHt7eRsjBtY=; b=A9NDnvGE9FNE7cyBosY/0zjzKT0+cP8I8SKc2H7HZvT8/gCohdbdTMaRRZRNoMw1j+ pjbfjv9PbSFZ165/m5+VIhSStBSC6qKoN4/j/bGIrQkuCfVTQUoVaDKlX7JSKnCQyISB J2DDW3OlN6PoA0+qZU3wo/T0VCTNUiw65SAYBTB6FTKZZ9o1taE2txD9JzxQkd6chMVc hQxTJZLptV/Q/D8d3fR2za43DTnWJldgLu54zja4n2PnyGL90y7cYd7BiKsCwGBHbqHV cFdOqw6VOFURdTWMgPVD1mXFvBQ7zSVeC8NVctAc2PGMq0nJQeFn+bceSgMXPcs5y85K cvwQ== X-Gm-Message-State: AAQBX9eXCsHh8t9u1SmL1QZ18u1N1HoZ8F3LH7Hn72GoBDyRV4J07DmT OJaDbdvSY6+v3u3ivJpBi0kdgnCEWxqwMA== X-Google-Smtp-Source: AKy350ZPZBC7QCtpkWz4OAE8WRsC3sGRYmMChEsbN7/Q4y6a0qg4jQR8PY1s4trNZJzA5KgED/0yImjC1Fzf3w== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:6902:1241:b0:b92:238b:574a with SMTP id t1-20020a056902124100b00b92238b574amr1547530ybu.0.1681969976120; Wed, 19 Apr 2023 22:52:56 -0700 (PDT) Date: Thu, 20 Apr 2023 05:51:28 +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-3-joychakr@google.com> Subject: [PATCH v8 2/5] spi: dw: Move dw_spi_can_dma() From: Joy Chakraborty To: Serge Semin , Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Move dw_spi_can_dma() implementation below dw_spi_dma_convert_width() for handing compile dependency in future patches. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index c1b42cb59965..f19c092920a1 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -198,14 +198,6 @@ static irqreturn_t dw_spi_dma_transfer_handler(struct dw_spi *dws) return IRQ_HANDLED; } -static bool dw_spi_can_dma(struct spi_controller *master, - struct spi_device *spi, struct spi_transfer *xfer) -{ - struct dw_spi *dws = spi_controller_get_devdata(master); - - return xfer->len > dws->fifo_len; -} - static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) { switch (n_bytes) { @@ -220,6 +212,14 @@ static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) } } +static bool dw_spi_can_dma(struct spi_controller *master, + struct spi_device *spi, struct spi_transfer *xfer) +{ + struct dw_spi *dws = spi_controller_get_devdata(master); + + return xfer->len > dws->fifo_len; +} + static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed) { unsigned long long ms; From patchwork Thu Apr 20 05:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13217904 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 601C3C77B72 for ; Thu, 20 Apr 2023 05:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233801AbjDTFxH (ORCPT ); Thu, 20 Apr 2023 01:53:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbjDTFxG (ORCPT ); Thu, 20 Apr 2023 01:53:06 -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 211A740E2 for ; Wed, 19 Apr 2023 22:53:01 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54c17fb245dso14285267b3.21 for ; Wed, 19 Apr 2023 22:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681969981; x=1684561981; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Suw/5ECmRYhQu6IA1gmyYkwu6OL87LNt9wtEORwfKxU=; b=Nic2FQHT1rZcir8AOnmbrVQPU6NAfnIjYV4nIHCfkVKQ/GoGbaNkbxtwGkF5Om1bYv V6+uX0yYKgWBiNd9F78J/n+s6PyxBNJXg4LkdJcVUPRmgGAEBmeqIC+zwvTTD5D5M181 ZlTGroz/DAtZMujsWNJ983a47tVbO9qmPah4pS3s9yldeH2ZWuq6rVgQo6RdfcAqtzY1 bHnv7Alw7+AnTco490Jm5j0ql4RFj27sUppjmdlMYnTHjF3wkGFanlbRuPMwlHWV84ZY 4rjkPUeogytWmy9OebXbApw2ftvCJty+sqj4lF1H2tD+fYAumBWj/H9o+OBlMa7fpyfX kNYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969981; x=1684561981; 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=Suw/5ECmRYhQu6IA1gmyYkwu6OL87LNt9wtEORwfKxU=; b=Eup29D7uFxXjuChAC7MKYDli7fCBCTDTKeW21uechhQelmm6SESwpwlxqbG8j6Tz3T b4vIigcmCwYjXBe27HmcUcA/GrHSJ/YxM+CkvehxWO9aWXgaGZ/+WzZ2vuCbD3OADUDx WwSpJk+zbfWee4t8YoIpfrDWmj2jYVfPZMc/oPIlnJPHf1AbMWinuMTd9qh6kmEyGyd9 6S0tytvfCxStxSou2uzZbowwJUZGWkYwP4JMiwqne7ZD36Li7js8OSFMHEpif3nohuvj zoUeLBHmahQODV+o1GX++ZbVzhbbAKgEXlYGZSiUGOGl+2tWpSwoDYM32t6kmaI4unUO 98aA== X-Gm-Message-State: AAQBX9dBkJ7cZMZRfZIqwWoWJksV26e6C7lRmoR4Gtj7HqtSA3usZQrS hTIrtCgTF9bWXNCAxu90j1PKAeq7yVvxrg== X-Google-Smtp-Source: AKy350ay/+o35VVgLfkm1KU5oZXdmcYctJBH3H9ps3Kkq5rgHGfsM7OemGOqjFNEJ2EPDGX6C9R3yUPdRzUA8g== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a81:b625:0:b0:541:693f:cdd1 with SMTP id u37-20020a81b625000000b00541693fcdd1mr3450551ywh.9.1681969981044; Wed, 19 Apr 2023 22:53:01 -0700 (PDT) Date: Thu, 20 Apr 2023 05:51:29 +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-4-joychakr@google.com> Subject: [PATCH v8 3/5] spi: dw: Add DMA directional capability check From: Joy Chakraborty To: Serge Semin , Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Check capabilities of DMA controller during init to make sure it is capable of handling MEM2DEV for tx channel, DEV2MEM for rx channel. Current DW DMA driver requires both tx and rx channel to be configured and functional for any kind of transfers to take effect including half duplex. Hence, check for both tx and rx direction and fail on unavailbility of either. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index f19c092920a1..22d0727a3789 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -72,12 +72,22 @@ static void dw_spi_dma_maxburst_init(struct dw_spi *dws) dw_writel(dws, DW_SPI_DMATDLR, dws->txburst); } -static void dw_spi_dma_sg_burst_init(struct dw_spi *dws) +static int dw_spi_dma_caps_init(struct dw_spi *dws) { - struct dma_slave_caps tx = {0}, rx = {0}; + struct dma_slave_caps tx, rx; + int ret; + + ret = dma_get_slave_caps(dws->txchan, &tx); + if (ret) + return ret; + + ret = dma_get_slave_caps(dws->rxchan, &rx); + if (ret) + return ret; - dma_get_slave_caps(dws->txchan, &tx); - dma_get_slave_caps(dws->rxchan, &rx); + if (!(tx.directions & BIT(DMA_MEM_TO_DEV) && + rx.directions & BIT(DMA_DEV_TO_MEM))) + return -ENXIO; if (tx.max_sg_burst > 0 && rx.max_sg_burst > 0) dws->dma_sg_burst = min(tx.max_sg_burst, rx.max_sg_burst); @@ -95,6 +105,7 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) struct dw_dma_slave dma_rx = { .src_id = 0 }, *rx = &dma_rx; struct pci_dev *dma_dev; dma_cap_mask_t mask; + int ret = -EBUSY; /* * Get pci device for DMA controller, currently it could only @@ -124,20 +135,25 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) init_completion(&dws->dma_completion); - dw_spi_dma_maxburst_init(dws); + ret = dw_spi_dma_caps_init(dws); + if (ret) + goto free_txchan; - dw_spi_dma_sg_burst_init(dws); + dw_spi_dma_maxburst_init(dws); pci_dev_put(dma_dev); return 0; +free_txchan: + dma_release_channel(dws->txchan); + dws->txchan = NULL; free_rxchan: dma_release_channel(dws->rxchan); dws->rxchan = NULL; err_exit: pci_dev_put(dma_dev); - return -EBUSY; + return ret; } static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) @@ -163,12 +179,17 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) init_completion(&dws->dma_completion); - dw_spi_dma_maxburst_init(dws); + ret = dw_spi_dma_caps_init(dws); + if (ret) + goto free_txchan; - dw_spi_dma_sg_burst_init(dws); + dw_spi_dma_maxburst_init(dws); return 0; +free_txchan: + dma_release_channel(dws->txchan); + dws->txchan = NULL; free_rxchan: dma_release_channel(dws->rxchan); dws->rxchan = NULL; From patchwork Thu Apr 20 05:51:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13217905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFA16C77B72 for ; Thu, 20 Apr 2023 05:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233826AbjDTFxW (ORCPT ); Thu, 20 Apr 2023 01:53:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233839AbjDTFxT (ORCPT ); Thu, 20 Apr 2023 01:53:19 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B48CE59D5 for ; Wed, 19 Apr 2023 22:53:07 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54fde069e4aso15221007b3.3 for ; Wed, 19 Apr 2023 22:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681969985; x=1684561985; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1Pw11IJF74xsEjxmIFJb01azmaJEP3MTEgikPdGTfV0=; b=Ghdjh7vA1YPqlAZpZKBCngCnmwyCqEnfPR3DWXDkkfIn5X9nZY7Cm2lQCb5PBIXRma nBj2ld7j3BXfFLqsWYVXAVfuRaBlCLDXVsDiem8dshSSwvY+DOvGotlqaer6eF3ujaao V9pGdoJqZp1yvMmDhnNzv8b1aWngib70WDj0h77MgymbkKIFESsdG3019rClpkpWj53v 7jRDPe1+eNJHSyNSyz5sDRVRrXs8ueAQy/l1+pN0aKlr/e66XCA+RdiMxCyR8TTVueFi wM9QojpXSDE9EaXtMNllPxU3HTe/hbe82gr6VtjUromEji66LTWH3RfFrX1/++liNklN gyIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681969985; x=1684561985; 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=1Pw11IJF74xsEjxmIFJb01azmaJEP3MTEgikPdGTfV0=; b=ORtFNg8amh5tNf4LVvnVl0M4J+0z4GH/LeaebpLzm11SqWB9v6DVxDNN8SxP6qIBgg fW+Stu7qxwy8CycmdBSYMkWVhhHE0qGhv1G1TxWyvjMULbmDjpj5r5GwY4XrTZg9BlwY ZN/HDyMLUOaSZLDXlMvRUUOz2db9IheDt5rPvcNo3dp3B8nueudru6gu2gKXzg7RwXsw I1xck5l5wXF2Jjd/dPn0WNWuH7aStnzraYpvqfyXgMfDnYPn6n9z1mbpho4miNrpT6u4 6Acaz6udWHivkZ2AGuHttPBUINOwljDn+gYl8M1ZbpL0Uu3vNN5lSjYcU7gRNaf8tigJ rN1A== X-Gm-Message-State: AAQBX9eLv+nR9+cypLbhdqsH4b7ovjguNe3byiFY49+xYBs8MwuRL2Md sjJvJEs572ybgLzCLXTLiki0j8CD+cAtnw== X-Google-Smtp-Source: AKy350aHEAmQUugbZRgWImjQc/pmpAOgcunt234vDef1PlbRapAYOq9br9v/OAOdB0HSKG0Ghr4THwRqnfKvXg== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:ca4a:0:b0:b96:7fb0:f927 with SMTP id a71-20020a25ca4a000000b00b967fb0f927mr309752ybg.12.1681969985826; Wed, 19 Apr 2023 22:53:05 -0700 (PDT) Date: Thu, 20 Apr 2023 05:51:30 +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-5-joychakr@google.com> Subject: [PATCH v8 4/5] spi: dw: Add DMA address widths capability check From: Joy Chakraborty To: Serge Semin , Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Store address width capabilities of DMA controller during init and check the same per transfer to make sure the bits/word requirement can be met. Current DW DMA driver requires both tx and rx channel to be configured and functional hence a subset of both tx and rx channel address width capability is checked with the width requirement(n_bytes) for a transfer. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 17 ++++++++++++++++- drivers/spi/spi-dw.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index 22d0727a3789..df819652901a 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -97,6 +97,15 @@ static int dw_spi_dma_caps_init(struct dw_spi *dws) dws->dma_sg_burst = rx.max_sg_burst; else dws->dma_sg_burst = 0; + + /* + * Assuming both channels belong to the same DMA controller hence the + * peripheral side address width capabilities most likely would be + * the same. + */ + dws->dma_addr_widths = tx.dst_addr_widths & rx.src_addr_widths; + + return 0; } static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) @@ -237,8 +246,14 @@ static bool dw_spi_can_dma(struct spi_controller *master, struct spi_device *spi, struct spi_transfer *xfer) { struct dw_spi *dws = spi_controller_get_devdata(master); + enum dma_slave_buswidth dma_bus_width; + + if (xfer->len <= dws->fifo_len) + return false; + + dma_bus_width = dw_spi_dma_convert_width(dws->n_bytes); - return xfer->len > dws->fifo_len; + return dws->dma_addr_widths & BIT(dma_bus_width); } static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed) diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h index 9e8eb2b52d5c..3962e6dcf880 100644 --- a/drivers/spi/spi-dw.h +++ b/drivers/spi/spi-dw.h @@ -190,6 +190,7 @@ struct dw_spi { struct dma_chan *rxchan; u32 rxburst; u32 dma_sg_burst; + u32 dma_addr_widths; unsigned long dma_chan_busy; dma_addr_t dma_addr; /* phy address of the Data register */ const struct dw_spi_dma_ops *dma_ops; From patchwork Thu Apr 20 05:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13217906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F6E9C77B78 for ; Thu, 20 Apr 2023 05:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233849AbjDTFx2 (ORCPT ); Thu, 20 Apr 2023 01:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233832AbjDTFxZ (ORCPT ); Thu, 20 Apr 2023 01:53:25 -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 7224C55AB for ; Wed, 19 Apr 2023 22:53:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-555d8c556faso15069527b3.5 for ; Wed, 19 Apr 2023 22:53:13 -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=GA/itxdtCyJrDeDjYiZEQYp0fC2piCoZptzpkxhSvlz7ASRZ0z+GOhxS51Idoe+iOW y9Rs3x4WNCs3tXsXknB3Nm24NqkgELfCuSqzC5oFybViN27csJNsg4RYBcLLt6mgHORU ZLOVqffiHvvBKVxVL9LaxoSH0DQScyFh2eSJY04lKb/E5PSXo1mRabEJiw7NwwjwfJV1 Nc5Qy83yulpisqBd6JjRyjfB6s+8EaFjOyYQuM/iCLsd762FH1nKx6kyfGVRDTFcFD2b lWSYRBpy/4lv4Vrsiz5szh1ro5wwZs5Kr2NqxYIVJl1dx1C9cECnA4Bwz6neNwQcV+CE OINA== X-Gm-Message-State: AAQBX9dvuHT+psLJ3jh6VmMUkQntEepLZ+yrACbrhi2yPm/ksP3IvF8C cLf2IEg0OWyF9OZpb+lHBImzdoy3ggticw== X-Google-Smtp-Source: AKy350aZp1jhQxfVc44iBqg7o9bq0B/QDYh5+kVoGotSwm59TwPJoS4VXXowbQ0zfZffFl6cBk/hg1YSfupTOQ== 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 To: Serge Semin , Mark Brown , Andy Shevchenko Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com, Joy Chakraborty Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org 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 Signed-off-by: Joy Chakraborty --- 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)); dws->tx = (void *)transfer->tx_buf; dws->tx_len = transfer->len / dws->n_bytes; dws->rx = transfer->rx_buf;