From patchwork Tue Apr 18 05:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13215038 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 8CD68C77B71 for ; Tue, 18 Apr 2023 05:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbjDRF3U (ORCPT ); Tue, 18 Apr 2023 01:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbjDRF3O (ORCPT ); Tue, 18 Apr 2023 01:29:14 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7294D5595 for ; Mon, 17 Apr 2023 22:29:13 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 84-20020a251457000000b00b8f59a09e1fso11690915ybu.5 for ; Mon, 17 Apr 2023 22:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681795752; x=1684387752; 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=FYeN9SBMek5PY0NUGiKB4PDLSCJlT+j7HehxrNt6HMPnXxkb2hDFelKYyUgKjiziLJ tVL1u6x5vxXSoC1takibB3sIH8S5a4H/zcAlUkmwd/KdiZUbajfB7BLtA9HeauREN51e nXpSIgJ6Rhyfs8s9UE+1sdCU+RjVrt24eppqDajoloeN9DjHFI1gZzPGdoKCX21oevkM 7BV4SlPWznZ6RPNiZJQNSzTfqp5FCxtuyrMusF6mbwi3CATBxDGXZAtz2m1Bj2gtnO1D rn6UAwLmvLFoSrIo1NjxrVFRxc7oNUiE8XEtQ3ICRudfANtgmGOv/eB+zA6LPING2H7J jDGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681795752; x=1684387752; 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=Yy4un73latQIkItf0iZNHqYdNxymLzJug4k9sR1y75Nhtyo6cH1Mbf+iZuabBKbYC3 b5NlZ8/axBovTgbDzv1EpvK7jwAv6QJPasQ+NbmXRtks+aRiuXnpqcKyAysdt0arRDd0 mzzN4UNuOKdctt7u6lYw1MCJQXR36iLuI5lbPPzzu4iaMNo7DM+ddZLdAqgY5BsuDiu1 yeiE+De9I+k269vRbhUgeJc9d5Rn8bdAEzH435ureOpSINZKSU4rv+o3QzEiPlQ1Os2M ca4Gh2wjBrS33kSniNAWAytOoeUt/CwQvZ/yNrv1sEOQf53DTL3LoUKrZRO/k4q3kvWs BxkA== X-Gm-Message-State: AAQBX9eV6PIl7b/582zF7Z1cygPNwD/iKlts1Y8IGaVit3YXzTvYH8SX pKVAV9d4f8hNBF0k/bjvBOr4vikvgiPt0w== X-Google-Smtp-Source: AKy350bdIBV7qoBsvNLSgcYeJ9hwtBweLbKLDpYB3err3fbJEZWBFuD+8dThBnEI018wEnGEF+V/2UF5MBTiIQ== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a81:ac57:0:b0:54d:3afc:d503 with SMTP id z23-20020a81ac57000000b0054d3afcd503mr11607964ywj.8.1681795752753; Mon, 17 Apr 2023 22:29:12 -0700 (PDT) Date: Tue, 18 Apr 2023 05:28:58 +0000 In-Reply-To: <20230418052902.1336866-1-joychakr@google.com> Mime-Version: 1.0 References: <20230418052902.1336866-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418052902.1336866-2-joychakr@google.com> Subject: [PATCH v7 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 Tue Apr 18 05:28:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13215039 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 15B1FC77B76 for ; Tue, 18 Apr 2023 05:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230315AbjDRF3X (ORCPT ); Tue, 18 Apr 2023 01:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjDRF3U (ORCPT ); Tue, 18 Apr 2023 01:29:20 -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 C20C859FA for ; Mon, 17 Apr 2023 22:29:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id n66-20020a254045000000b00b95a177fbe4so119886yba.18 for ; Mon, 17 Apr 2023 22:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681795757; x=1684387757; 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=6XqlMtOxsqrT/1r2wZChHQ9ZpRkAmrUq+OgSX89spFBhvd/cSZJLUdWgaOp8WIePRa PSSby6xBdcgXm6GSBJtUxdkkVhgbn76OAIzMm/qb3Jd3d3cOI/DxQZSDVfK1Gyavudy/ gqGBDA5QaQlZ1Vag2qsySvdPZlBZncqqptuZ3ZzRaiuuiXqI4vaA20IgbcB3lKGE8YfK IWIj5XP+2e2gi0GQshi/crBqMcV5H1AueWiSPrem+/BxIPu7Wrn2sn6kXDbbyHttpmfW 1NpPO6KsFIIaezfKaU82RfGgYofxQzOg3y5qII5BkT2eSoKsN3e77Y/Fesk/40vFvwX4 PwhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681795757; x=1684387757; 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=Swg2JesoaW0yr4HK5WwjVtYjSAdy9IfoT+OvAUCh653XQ/W/OXEidw4soiXedRgqUg JEYjyoicMjekdIxlESHhPkvAB9P6EH3+pK2G7ZHYLwX9u4NFiSSlMFqd8rKVfAwBgJ+F vf/XaKQf0lbwgUfiThRymTf5jrzktHkeBmaLImLDmU6IZ3DOy/3Y7SKrAVNc26Unusfv sn2PRXoDq3K9fqt87dYR1fjg+qvh9qIdJyMFCNuwdbJHldPjmsM7ESn+9vzGRNUHkXoI j6hyu4FUX9ERqUPFcSZolCF6sDnbFYX+sNrGuUcEKnmXc9U/BXDSkA6Ai5fI+PY4+/cz JEnw== X-Gm-Message-State: AAQBX9eTmOZpEf+Vbe/uMTuLGfLQMzmYB5S/QN77uscUOK1iX/rAAFtf U7lTf1GbvZZoyrNYFIKyRcmpk1+hDu0prw== X-Google-Smtp-Source: AKy350Yf//dH2i9AgFuLu9VrJMm1EIuJVblpEOY/OMkXrVfGj8yH/tow4BRilElcc+FFfJJqiUUwbRjvODXnkg== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:690c:706:b0:545:5f92:f7ee with SMTP id bs6-20020a05690c070600b005455f92f7eemr11663447ywb.2.1681795757018; Mon, 17 Apr 2023 22:29:17 -0700 (PDT) Date: Tue, 18 Apr 2023 05:28:59 +0000 In-Reply-To: <20230418052902.1336866-1-joychakr@google.com> Mime-Version: 1.0 References: <20230418052902.1336866-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418052902.1336866-3-joychakr@google.com> Subject: [PATCH v7 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 Tue Apr 18 05:29:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13215040 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 91016C77B71 for ; Tue, 18 Apr 2023 05:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229516AbjDRF3c (ORCPT ); Tue, 18 Apr 2023 01:29:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbjDRF30 (ORCPT ); Tue, 18 Apr 2023 01:29:26 -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 AAF985B87 for ; Mon, 17 Apr 2023 22:29:22 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-552e3233b26so35353707b3.9 for ; Mon, 17 Apr 2023 22:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681795762; x=1684387762; 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=Evar251cw7DqRlp2ye27lHI+fpqOTsgpuJ5EmMqcMu6vFnAQvjd8vRQPafVAuV+pUU J2gDRGws2FhQtxwmAVgYn/+yz1oYsqfNDJkIvo8HwMnXZb/FI9EHTNAaWP8Z8/rQtuOk lfNDeAL1EX8aW9Q2we5U0Xq6YapVOgmzdX+K9NyirqsdwN3Lk6JCcx+XZdS8sFZwOs11 HVjrLfYUJxIi8RF4yEGYVZtdXt2oOFdFfzSPudGkt0cd/XJeymVQv87HCSQpMfIOlU3q DPXh2lQc59Pukf8ZWzFSKjV9pwyTrVRGas2/uFK2oPt1c2M9dAxBiBiTJcOmj4CGViVX AVUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681795762; x=1684387762; 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=JEwa09yVrS+wvmUOVevPLIeYu7F5ExCkf02n7sOPJxX/wfKxvZaKq0SbeELWNWTmSP 3E1aWe7qhLvR2/OaAVGcYc2y33GxKMOPtmIveULXY+Q8URTpIcPwAXKm+4mSdX6Sq3iO 4TwnVFDSqVyJm+QIJjc3ruTyWqtdi2XADmuohnhJcwPiE20ZmlpV4tAELcVnIrCan/Lb ZV4kZlEv/xR2lYJ0cOd46tKCRXOg9+pgxaT3Qbj5F1keh6Z/TgWdun6gIZEflws2JGT4 yWVcG3R2Wu7QHwtYYH/CVyD8+oSJzgoixwuvqjGS/L/zTbZm1j/1SKlQ4Q2yyRik5OQO yCrQ== X-Gm-Message-State: AAQBX9dfqc2iOnp09g9sNXSLGD/2bbsaMb9K7wHg7OHf3sxu4PmbCYSm frLPHg06BlpwMOXUw3mBORVpDnQqj7pZzA== X-Google-Smtp-Source: AKy350bH0/6RH6j68nyH9pouJam17JSPS/6e2cVsz2aNQasER4QvJhzUVKi/6oopvSdF9py+yX+KCHNJr48LxA== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a81:4524:0:b0:54f:aa4b:100c with SMTP id s36-20020a814524000000b0054faa4b100cmr10637678ywa.8.1681795761848; Mon, 17 Apr 2023 22:29:21 -0700 (PDT) Date: Tue, 18 Apr 2023 05:29:00 +0000 In-Reply-To: <20230418052902.1336866-1-joychakr@google.com> Mime-Version: 1.0 References: <20230418052902.1336866-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418052902.1336866-4-joychakr@google.com> Subject: [PATCH v7 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 Tue Apr 18 05:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13215041 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 70C07C77B75 for ; Tue, 18 Apr 2023 05:29:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229518AbjDRF3g (ORCPT ); Tue, 18 Apr 2023 01:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230355AbjDRF3c (ORCPT ); Tue, 18 Apr 2023 01:29:32 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 992036588 for ; Mon, 17 Apr 2023 22:29:27 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id l124-20020a252582000000b00b8f5572bcdaso12608084ybl.13 for ; Mon, 17 Apr 2023 22:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681795766; x=1684387766; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ULD/pG+rE68BAxC1WDHgKiKZL8SDfWGnG2YjCeWvC3k=; b=qwjLzEiux581S2bwXnijENgLs2i3vekPUCQxMzop5Vx0D89HCDCPGFyxAs2bVC5zK6 jZUx8em8Gl0+gyvoF1TWJqxt1mPYUOoO1z3B+XnY/vXbVEuq0m5wTSUJHI4yipjdpX1t t3yoTSirJxVGnzV+L0hOlNUCbBErO5LgN3RatdWdCHSHqmQgrtxUs7ml06v2YFRBytDe 7DtgyepGhLyY/Qc99jM1r5asfItKZ+1Ti+g7B3O1JUln4fDvjTNxNE6ePefnwQwNSjex qcNAJRM0ypXCInn8v1b9tFMflu2LbAhHn9kmCnEFg484BSiEitHf6CPsLcbOLchhp8SE JNyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681795766; x=1684387766; 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=ULD/pG+rE68BAxC1WDHgKiKZL8SDfWGnG2YjCeWvC3k=; b=YWc6MKmvjTDzlqwPtPk+glOQstagBmyyK8m3eU1cuaQHCab5FYUlLI1M5pAmyq8q0P JL2uB8W+roe/Vdw/92b4J4mwjwBkFjXO9sAGMGu1/qLz+TVPpNwmDy90/23If1urJvEK oy29or289qlkEcOEOwjrh++qEkt/3ThfesOiOrZfOqJyRIK861JFNo6cnjaCCC/YR/9j xJMDnNp/a/52gxNyKDLdJHNMW/XA+OA1CcEDHU6dOD8WkLIs030jpHgGv5zyN3ao17n3 RAVIrAUVwS8nDLnhkR9hxQh6nmdWOqCwnkfxSnqDVZpiJxXNGE83f+kU/y2T6ZNi6hEN o7ig== X-Gm-Message-State: AAQBX9dtAM0kUllgL2rKLuXKTTNU5g1hHkvhDtHK8dcdL8qRGJ3rfmrw aTlJ1DCaEBhjknLMal/yr6yhqBRjCkO7Zg== X-Google-Smtp-Source: AKy350Zbxb/MLGxinwfLDVNWFu+GOJwfHCvNZ0wV6p7AE3/JXlFSnZFapdikxMFEUEgDt7vtMa2xUBQPSSUzKQ== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a81:4411:0:b0:54f:93c0:4ba8 with SMTP id r17-20020a814411000000b0054f93c04ba8mr11022458ywa.2.1681795766496; Mon, 17 Apr 2023 22:29:26 -0700 (PDT) Date: Tue, 18 Apr 2023 05:29:01 +0000 In-Reply-To: <20230418052902.1336866-1-joychakr@google.com> Mime-Version: 1.0 References: <20230418052902.1336866-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418052902.1336866-5-joychakr@google.com> Subject: [PATCH v7 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 | 16 +++++++++++++++- drivers/spi/spi-dw.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index 22d0727a3789..45980c46946d 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -97,6 +97,14 @@ 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 + * 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 +245,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 Tue Apr 18 05:29:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13215042 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 0279FC77B75 for ; Tue, 18 Apr 2023 05:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230359AbjDRF3s (ORCPT ); Tue, 18 Apr 2023 01:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbjDRF3q (ORCPT ); Tue, 18 Apr 2023 01:29:46 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E16C65B0 for ; Mon, 17 Apr 2023 22:29:31 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id 98e67ed59e1d1-24708bfb463so1347358a91.0 for ; Mon, 17 Apr 2023 22:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681795771; x=1684387771; 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=ZLGNlq1PGDuNXmKXCLEpwmCrcSVfz8bJTIn49O4DCgqv4BhkDZPhhsZZqXBoVChY4+ Ra4LogSmWM4SDLlCF7CSa4DPJ5nSCBspbm82HDOGzaGkTlGaNSBT0E1ZSB7aNab3llYn Ix7lWThLXLkhH0eOr+JohXRTjVQUdlA++00RQl2KVy784t6G/WBvEmUXA7+NnFt8AP18 xCt2KWflMpoZkec7CqL5XH/aZXVICoNiD+ymyHfhXbGnazme9J1wWTxmpnZLXlF7GlMy QsJ7TbF3vu4Y9erMH8vv+2tqX9teQG0ilKR6CUhtZFSnnEYffZj5ANb6hn7OBDEqBP7x ZTtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681795771; x=1684387771; 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=ExLDBrH0cP337FcKRCPuZsUtvids6svlH6856Ng2RoOzBKcpjgMxU+089J+0DL7Ycd 2/dVCufpNPSSPMC6uzN3OF/YIKmt2622+fv7oq3dfT25o+k4lYC/BgToQRO0k8MaR9sG 8gA8dS4Bb64GN+x0M15zPbYQM4A/VPbZ/rPimuYsr8N5YzwtU8eOHtYkRn/qyNyCmje6 j1i0LJ+/khUnuOXNGJ1IC9sneFbBb5Fvlc/LOcru1iwgA/onWsoQHwLqaoMdmnBP+hIA dqCsxIXHfiSNBHswHDbF1/fOQ195c13P9bx3B3j8faP6cbbeIiQwUDTE2v9+ZJ35XheZ kXQA== X-Gm-Message-State: AAQBX9d7sIy6Zq7k24YuxWIDuQQOwRTCG/tOMl6ZcLKlItqR/V+NN6nY DPtZeqsoNV2zewGqfEJALPlqauKBl66Qzg== X-Google-Smtp-Source: AKy350aajvAgsYG7NiI4EKXnrMPoSQwdFAFDCxuRpR+k/AvuEzgKLZO54jV/kPal++hSl5YcIVmP4pdBx8AHtw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a17:90a:2b07:b0:240:c13d:1325 with SMTP id x7-20020a17090a2b0700b00240c13d1325mr280814pjc.5.1681795771097; Mon, 17 Apr 2023 22:29:31 -0700 (PDT) Date: Tue, 18 Apr 2023 05:29:02 +0000 In-Reply-To: <20230418052902.1336866-1-joychakr@google.com> Mime-Version: 1.0 References: <20230418052902.1336866-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230418052902.1336866-6-joychakr@google.com> Subject: [PATCH v7 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;