From patchwork Fri Apr 14 12:05:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13211379 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 67A29C77B6E for ; Fri, 14 Apr 2023 12:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230117AbjDNMFe (ORCPT ); Fri, 14 Apr 2023 08:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbjDNMFd (ORCPT ); Fri, 14 Apr 2023 08:05:33 -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 EE13E13A for ; Fri, 14 Apr 2023 05:05:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id e6-20020a25e706000000b00b7c653a0a4aso11059563ybh.23 for ; Fri, 14 Apr 2023 05:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681473931; x=1684065931; 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=MileTBwtlL0qqRT9AiQfm9JMqrnFA9bJsAcMj7ZZ9KppF1hAzoRuBJa+Y6TzrKhNh9 0zpRMfy7KoXKTtjw/1phr1Ju8Q7MUC3Pv2KXsUmij4naENHQWdy5ESjF2rESYm0/J1nH ZnXqByO+tcKc/Uosx35Kpn+fCdC0j9wB2QkGB8bZgQAQQ0gPupXYv3MWdmOAItIRdjlp wtWbEs8sADYLMeffdzvE/pty1M/x1pgUZbGEUahJgaG3Q4TzOWLa8UGhJfh4ER628TTZ M7K0CE9thwSsjjvv6lkLhAR6VG4lMylReBNHP7mHOm+66jtDweWML0O0f9DBsbI3hIWD HkAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681473931; x=1684065931; 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=d547h8SzJRpZTEITgNj/MA35W0TF4wVbrS19Q+RbuiTt6/YCFBKLxcXJeNUcJcqmU2 qj93B4V7309gLz+HHoaDlcdHPxgfQviUdZ+pXM+UuBvFN5urBXnbKiP7GO0G2HTRyOiJ AouVL7Y/h+ikILyyj9HH/0dhRsIGU5335mht60mjz3V1snIvN7voz6DaZNbXH1ry0jZK VQjlIKxF1QAjr+ATxuiWcjyk9scaA+T36k8m73kEmgzi2tWkEyV6ZBJpVU6HEhOebKNx JT7ukkHh41Wz6M7WN/cpPH+xe4UyikdIGg0x0aOzsKb+2Rj0/0bETGD7SaokkSaeVvkt C3ag== X-Gm-Message-State: AAQBX9cXUQnvjfWnGB6nknZiWkFkKofi+7MsKw5EjtFXYh5JaN+hRcLJ 1R4sRI9KnTD921/9cfmEGUNYmjAm2VRNQQ== X-Google-Smtp-Source: AKy350a9gF3w+RP8mepYYKXHkZEFXcxJEDXBIq8pWYHsarXhytOBxhA9HNZ+Zy6tUQ/ULgM9WREsIAd858B47g== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:73d1:0:b0:b92:1f57:8d03 with SMTP id o200-20020a2573d1000000b00b921f578d03mr355881ybc.9.1681473931261; Fri, 14 Apr 2023 05:05:31 -0700 (PDT) Date: Fri, 14 Apr 2023 12:05:16 +0000 In-Reply-To: <20230414120520.360291-1-joychakr@google.com> Mime-Version: 1.0 References: <20230414120520.360291-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230414120520.360291-2-joychakr@google.com> Subject: [PATCH v6 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 Fri Apr 14 12:05:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13211380 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 5FA08C77B72 for ; Fri, 14 Apr 2023 12:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbjDNMFk (ORCPT ); Fri, 14 Apr 2023 08:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbjDNMFi (ORCPT ); Fri, 14 Apr 2023 08:05:38 -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 AC74FA27C for ; Fri, 14 Apr 2023 05:05:36 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id c193-20020a25c0ca000000b00b868826cdfeso37049987ybf.0 for ; Fri, 14 Apr 2023 05:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681473936; x=1684065936; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=65uwjwswhP+aUopNhPv3UiA4NcKEqdUIfoVkzM6bAyo=; b=uQubCHw71w6O5XUQutjA0LoDpSL+v+TuXE7SpijzhdY0JXfM0e0pQaW2iEN6icIOIn /s75BK6Tjvx1t0KMTqBurrQfuw3f6vYbuyu4tcYmsAXpvsr0nZKk1831iznXGpFKYWYJ UcftyaBaMnZ4i2G6zZJTBSS7QWCMH3Al34GMKx8XLeB2UrazIZsFWXpLrzEKvADfMYyX nuvtJjH8kJ9QMIgrJ17Rn0gQ+Dy+EVO6Yo8R0ZOaQ9LNL4i/jynn5CGsLzwBkafmpoa4 r4PdLkG5fgB0AJfp++xDofE0gCar0kFtZRO88adxNRP//ldNAki3n3toqaKsW0p/WsnZ fGKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681473936; x=1684065936; 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=65uwjwswhP+aUopNhPv3UiA4NcKEqdUIfoVkzM6bAyo=; b=iBsXOpFZqirCww3isTTE7MXwuEETP8o/n48JBFfMB5C7bX7B0KaBD+o/GMUOtERJlD wkIOjLZCi/rZJdVDpR9U0aJLmCPFqAMEneQIfYkLaHRkLacFP7cxTd4O/hqWz9BKfRt2 c1OIEx9wxNtgGuCeUKCUpP84dBBl+xBf7W8KIWpS8FfCQdPe9lu8figgShp1zBAWTlTF z8YdASC2d9e3bR5seM5d3XH6ymbuP70Ign4ffHQwydbKgZ4EGLfOFHfAf/dKFHL0OHhv kUdCh+qkyAEg1YE76yUt1d8qYxGodg+51ngtSnadkeVZVgEHQIEwE4vTPd1tPFh93buL 7R+A== X-Gm-Message-State: AAQBX9fUG0H6Z/1aOsuXV6WrivsdVxBbII7Q2ROjP51ApWu31g73zamy 3DsBQR8dW+xIlUNww7I9P3qCBTSipJMbKw== X-Google-Smtp-Source: AKy350bhmj53MiLlrrVDFOyFrorofDJY+k0jBT6zxQESV24P49jM10JlfoTG44JJfHCDoHSP3Ga+rXN5G+Pt0A== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a81:b303:0:b0:545:1d7f:abfe with SMTP id r3-20020a81b303000000b005451d7fabfemr3555808ywh.7.1681473935975; Fri, 14 Apr 2023 05:05:35 -0700 (PDT) Date: Fri, 14 Apr 2023 12:05:17 +0000 In-Reply-To: <20230414120520.360291-1-joychakr@google.com> Mime-Version: 1.0 References: <20230414120520.360291-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230414120520.360291-3-joychakr@google.com> Subject: [PATCH v6 2/5] spi: dw: Move "dw_spi_can_dma" function 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" function implementation below "dw_spi_dma_convert_width" function for handing compile dependency in future patches. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index c1b42cb59965..75e1b11af7c9 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,15 @@ 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 Fri Apr 14 12:05:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13211381 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 9283FC77B6E for ; Fri, 14 Apr 2023 12:06:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229925AbjDNMF7 (ORCPT ); Fri, 14 Apr 2023 08:05:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbjDNMFq (ORCPT ); Fri, 14 Apr 2023 08:05:46 -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 17F6BA272 for ; Fri, 14 Apr 2023 05:05:41 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54f8d4f1ca1so88669937b3.20 for ; Fri, 14 Apr 2023 05:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681473940; x=1684065940; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mmE5jy/83AbiExum2uWOlw9WgET/yaio4sgA6DKa4Xo=; b=CRnOvexc4uGaJtlXBpBxwAWjNrG2u375+vOuoxlfqXISvkbR4BgeLVDUT99nIw2Uy6 mwS8LAsYjm1VzgPyAPlrQt+NEim2Bcw48d1C0xYxN6Eq3+zRRfDdmD20DFxn6eRMPzgv klohmurUf0OZJ9ZGBoNOdxSkQFMHRqt7VFZ7YG6sTclCI43BYxTvdApYKOHOuGNe0Uuc jvI94OIMQBVfv5hzMM+bDRy4FB9sEtW2FR5WHn3nRNcYzVsnvBTnHNpWgRculEvIwbs/ 0LEnvMaNJJQDN5W0n7z7r88h8q67/zikyGBNTl7BbSTxp7GwtHe7dSuzswJ9GKyzkigo nVZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681473940; x=1684065940; 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=mmE5jy/83AbiExum2uWOlw9WgET/yaio4sgA6DKa4Xo=; b=l5A7lgWFJoOqjhXIsVQhU/PmpwtQw1azIjIpJjUqFvXOCE1koWKSj6Q6U7MAPdjiu+ wGAeHW+ChPowudWunZGltYDu4wJMNp+e5HIt1b+0RiEE0oci4EnD8Ivm4Ydm35Up/AnZ P0gnFuA5HoTBhEdq7ktCz+S/W6qMOxCNoXosV/CW50TmbCMBWhxzIGodDtDZnow91mbl g/loYH5NqYtBdxiwF3yjJ7GUauHniGGzJFI6TubNvJGmy0iLXz9EU7PRqYlDwdrMloSU KAnL/Go8y/yQRpW5c8DBqZRqRK83OLAzJZ4wPOgoUUyWHHjUROT6sPsdpr4VMEcvgITW NIzg== X-Gm-Message-State: AAQBX9fmgb2hLlqLW2/S+7EZI0cKalHc8PJ/g0txPKZFDy1Ge+flMCj3 h9maf3mINvHfAfg9J1oiiGlbuuGNiGhUSA== X-Google-Smtp-Source: AKy350bZPbwaevptDno+qvPHOfr8KublJAUevFp8oBFM9cbUZujqK/KKIYxuICd9/bEGrNo0rrEDI6cNiwW7Mw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:da43:0:b0:b8a:7b2d:6556 with SMTP id n64-20020a25da43000000b00b8a7b2d6556mr3624830ybf.8.1681473940307; Fri, 14 Apr 2023 05:05:40 -0700 (PDT) Date: Fri, 14 Apr 2023 12:05:18 +0000 In-Reply-To: <20230414120520.360291-1-joychakr@google.com> Mime-Version: 1.0 References: <20230414120520.360291-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230414120520.360291-4-joychakr@google.com> Subject: [PATCH v6 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 75e1b11af7c9..e1dd13fe4fd0 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 Fri Apr 14 12:05:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13211382 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 7540DC77B72 for ; Fri, 14 Apr 2023 12:06:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbjDNMGA (ORCPT ); Fri, 14 Apr 2023 08:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbjDNMFz (ORCPT ); Fri, 14 Apr 2023 08:05:55 -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 8E1DFB740 for ; Fri, 14 Apr 2023 05:05:46 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id f66-20020a255145000000b00b7f75c3cafdso3263596ybb.16 for ; Fri, 14 Apr 2023 05:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681473944; x=1684065944; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9Z3uzwpPzb9VI4QQ6yS9D24bwvkUC2CAvsehyf1JMvE=; b=Ou1uK5F20L6r3e7SB7x5q5L0CnE5r9AV4LcR+uW9hQU807GkWv51UdfdG7hInhv4sM TNNn+GqUjNNfnHNcELyJ6nNkzMU/nFDuGtm7ka9C/fJFayqz1Y9IeoJA4Te8fjpMEk8y PWPDwfq3O/CTnzodGfkYJu2s7O42iceHNvs/hU1pMm+Dd1PFsUJUsbWWLEgpNOvvmq2+ c3kRMzcKSmWAj/UehpADE7vtrRG+TBX247ste/8w8NdDB49ftji2AUEcHCQ5HMny19sS C50QI8ZkJ022JaYREQbDb/jiIK4AVfkK4mI7aG1lYSrkGVnGDwTFheR4qlrcgPMGmHBy KycA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681473944; x=1684065944; 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=9Z3uzwpPzb9VI4QQ6yS9D24bwvkUC2CAvsehyf1JMvE=; b=WS6eMMXpzfKGGMCee+253nwsKxuMiAWqTz2FTn/ISTiEBM3ZtCPZmxV355B7L5jqg1 8s0aLluTrGR/AZHvFtMrb3ZmZjlfdNjNfYMpzxrx6AsyT5BKC8azHOle8uQf83u8m/hq y3qzJdTXBtIw0dTWi7auKGXo4FIXH0+iMCs0r36c6NNVLAzRGLozbXB6uYCCXS8T/fF4 4FyulDlH+v5un5dmNoofyl9DPyiBUxxjaXRxrmdJkLxoEIT4d3plPn/ILrJPU3OxOcHQ 2sgEl5BVqR9IQ+0YwV/NPhgf+D6WpdQCpme+zxUfkVJlWLztbrEbYqk5aJ7IdSQYoYMM z9CA== X-Gm-Message-State: AAQBX9ew2h72CRqHQ0hFR+ZxXYCq3z9AUEj6vYAKD2QNCX2BoFS2dKG/ QBl5A+GRWw5dbKamEDiNsLC00YOgfBhBiw== X-Google-Smtp-Source: AKy350ZqSm5SfWAbvP/hpYF8agstj/3XeSp2uhP5Ya1Any3Gz8rMS2RMteYaTt3rWSqbP5Bc3Ob9khp4BmEdjQ== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a81:af1e:0:b0:52e:e095:d840 with SMTP id n30-20020a81af1e000000b0052ee095d840mr3677516ywh.0.1681473944443; Fri, 14 Apr 2023 05:05:44 -0700 (PDT) Date: Fri, 14 Apr 2023 12:05:19 +0000 In-Reply-To: <20230414120520.360291-1-joychakr@google.com> Mime-Version: 1.0 References: <20230414120520.360291-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230414120520.360291-5-joychakr@google.com> Subject: [PATCH v6 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, 16 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index e1dd13fe4fd0..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,10 +245,15 @@ 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; - return xfer->len > dws->fifo_len; -} + if (xfer->len <= dws->fifo_len) + return false; + dma_bus_width = dw_spi_dma_convert_width(dws->n_bytes); + + 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 Fri Apr 14 12:05:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13211383 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 799F1C77B6E for ; Fri, 14 Apr 2023 12:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230351AbjDNMGQ (ORCPT ); Fri, 14 Apr 2023 08:06:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjDNMGN (ORCPT ); Fri, 14 Apr 2023 08:06:13 -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 F24F6AD27 for ; Fri, 14 Apr 2023 05:05:49 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54c17fb245dso239897117b3.21 for ; Fri, 14 Apr 2023 05:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681473949; x=1684065949; 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=BjBk4IFfphPEvkF6oNu0FALs6uDTF7SOGFv3xTJX9fN+uejADR6Jzn/lNLnIuNHVaS 7rK0a+DvjrxnYz2Nc6HcVasynWLHhIY2+xJw9uGOOQYkxclfiVPQrYrB/7tyIMsM04j0 tt/ToVH+x2LAv0Zk66w7fjuo571bhxyaYUbq4r3r0No8bHmqgiZz0sTryCw7bvu85vKX WIF4wo+llgaXEzmoubYyqe5rHKGjcJ7q3xmHdwAyoWE7mITNRmDV990wb4UToHE6vdJB 7nNI62LjTFqAyebdPa+uMh8n7u5b7PWA+50T1QrAiKnlYZctziaSErhec27QXUPE+JXD iK9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681473949; x=1684065949; 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=I1c9KWdI90sTojMjxJ+TKOByJ9RIavD75AR/jaQCw1JSTCxQ/SdF2QNsyZgccEuNN2 WKDwx+QwgiWMw6gYg+aqNifamv5YMDzwXJncg47GiD46uiAUuRsU50wCfe2VhXBu8YQ7 vrbu4HcjbVO/hlqHky4SjkwgYwrILP4E/4CxPGWmiSzs4g2Aduf/N9L5yY8aCjrjbzbl KGbt9GUcMnDer6qbVFHwakuVdCqe4war58H2b6+Ngo9P95h9USpk9riP5Er+beN2By3v yVy6xz0nC5IbcX3vU+2MHLmLDI/xCJR5WTgxNSRb1eBC/wnlZKa5YGwi6cCYzOetMC0R oeHg== X-Gm-Message-State: AAQBX9ecGCp/0IwOFaEnR2J1tYGvlF5MsVLwBHzlBDcIIgJco9NkRBiV ZX4vCuZxsqIWL0pGhmMcu4pvk2poufyOFw== X-Google-Smtp-Source: AKy350btW+p1AMej9BMNQTOwi1zlSSgujlz7EFCFmu5Ck4LJ+KBKvqkoAjGiLKh42cRQVIydYBvZfMzF9ULK4A== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:ca83:0:b0:b8f:6944:afeb with SMTP id a125-20020a25ca83000000b00b8f6944afebmr1727314ybg.3.1681473948816; Fri, 14 Apr 2023 05:05:48 -0700 (PDT) Date: Fri, 14 Apr 2023 12:05:20 +0000 In-Reply-To: <20230414120520.360291-1-joychakr@google.com> Mime-Version: 1.0 References: <20230414120520.360291-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <20230414120520.360291-6-joychakr@google.com> Subject: [PATCH v6 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;