From patchwork Sun Mar 26 17:35:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13188396 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 CBB83C6FD1C for ; Sun, 26 Mar 2023 17:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231821AbjCZRfc (ORCPT ); Sun, 26 Mar 2023 13:35:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231764AbjCZRfa (ORCPT ); Sun, 26 Mar 2023 13:35:30 -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 0FE447689 for ; Sun, 26 Mar 2023 10:35:28 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id e186-20020a2537c3000000b00b72501acf50so6618432yba.20 for ; Sun, 26 Mar 2023 10:35:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679852128; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sPVKlHs8rdxB8UK5BU2ADWdalnh8Q9IQfmw/DaMpLMc=; b=n3l4VP3mBK1TbVo+LuBhHS5QICjfCzLhCC6pa7ew6+DG3lrLqM0jcVExkrHkPMB+R9 /RnmY9i2TkcdGJZHEjrEftiOmH8ad81+0GBzt+vFoJG3ujqZkELsxafZmHOdN6ihUYM6 mWYbIIdQO85MqMiws+BP4Gsm2WjIPMY2FafUxI/bQdMAh7py8RrdwxKUYDy72wtrnyZM zVOQ5FdaZeYq5ca3iPHPyLX5M93KahY1eviix1UcBl5uaj9G3FJCen4sjV9lHkK7AwPc OzvJ/TlkLhDFBlkPRiHvft3d+8kiN5qMHIXB4G9jZpm1h2lhKCB/OYFf39g7acaQYRGF gHKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679852128; 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=sPVKlHs8rdxB8UK5BU2ADWdalnh8Q9IQfmw/DaMpLMc=; b=mg1r8je9Obh6fzK6GPfKUAZ3mraM18tT8mQ0r7jrIi/4eGDN6ddsyTOgYI2tSuLlvC UWNBTu8vnnms7Fgc+y3Ry1AnCCG8xUh2Frqf5/Z6eHneSveLWThyHaMswsoMADGndPi4 z9dngQLoW5Gf6NQnzt5eyEGz9mYkhE98oVFPW3w7yj0TAdGFcyhtyl7BdSBG0ppq3v7u gQplVXFtgODSfvawFKkAfvwiLbYtXZ6N/vJ4B9jFubAdaj2t3zu3ZYtdoUURMqGqJK1h KcWrcpr6EOF8Xxm6ihDKi5qsg+kq//+tiNZxrJde0HpA1bTwbBFkfdhBobEPMGLM49wI 9Dsw== X-Gm-Message-State: AAQBX9dIW74QeMDWK3dpEGDDmkMOGUIHwHYFfZcmYdurXbsm+gFSozd2 KDHVexvVnCK0IR6VCNe7og8IvO612VONww== X-Google-Smtp-Source: AKy350ZSP6WrRql/Jvriaoj5YJN/Ndy94xPRoSF7VV0rufaPFiQH2/Gn+sK8NJf8CsfNeGvIv6OF6E7Ef28NSA== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:6902:1083:b0:b6d:1483:bc0f with SMTP id v3-20020a056902108300b00b6d1483bc0fmr4303725ybu.9.1679852128113; Sun, 26 Mar 2023 10:35:28 -0700 (PDT) Date: Sun, 26 Mar 2023 17:35:10 +0000 In-Reply-To: <20230326173511.710749-1-joychakr@google.com> Mime-Version: 1.0 References: <20230326173511.710749-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230326173511.710749-2-joychakr@google.com> Subject: [PATCH v3 1/2] spi: dw: Add 32 bpw support to DW DMA Controller From: Joy Chakraborty To: Serge Semin , Mark Brown 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 3 or 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. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index ababb910b391..b3a88bb75907 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -208,12 +208,17 @@ 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 3: + 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 Sun Mar 26 17:35:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 13188397 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 E93A4C6FD1C for ; Sun, 26 Mar 2023 17:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232011AbjCZRfm (ORCPT ); Sun, 26 Mar 2023 13:35:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjCZRfj (ORCPT ); Sun, 26 Mar 2023 13:35:39 -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 369BD76BD for ; Sun, 26 Mar 2023 10:35:33 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536a4eba107so66232297b3.19 for ; Sun, 26 Mar 2023 10:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679852132; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nn4CcHQY6f+/osyumFS4D5ECgTVcbf5phTsNY5AT6p0=; b=k4kHzLdN8mTqnSbEjYsbLNlAdV6ivn1Z2rwI5i0IVaunclsP2emP9cVoURmNh6CwTz GbqJFm8xvGbqNJDtvIxHnkOnKU5ruOnmB1jfFOpq8/+4F/vmT/lrTo/dy4dbS9P0/I79 BnP0XC2Q87IqI7OkENQ0VkwDIb/zoUbLHSAv7AciRDtcTO966x1rSI07FjUYNvIDONBt UTj2xf/puFEbErf4/kSHXkzMoWEJqcjJW878TQ+KmeUoF5F1rGAnivk3Jl8S5WbEnMLb NiRU35HyHvx1BN9cMqWsQxz+CMDHpMLPpR8rkdt54yEgv+NuKBR/2+ZQAAatxGjrjt2J BT6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679852132; 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=nn4CcHQY6f+/osyumFS4D5ECgTVcbf5phTsNY5AT6p0=; b=UmK6HP5SzF5ETZT0ihUBySa2O/jQ/HCswzlweAZi0IxFr2PES/UEv4vO4fIpZkwnkP pwM2d3DM0XIl8rWYe7KjuF7OkLX8ue+drTtx+xLsKgxDi9Xy2jeT5pzcQmfYRwSunedf sybp//dEINCY8Bcw2gJV+cwh2AGDD3UvL6icnkbu00jiILTF2PbgEkkgtkz4tVW1cHGo aX6e6GSa+fuMGPn5JI1JKtIrRlW6fhCK6VWnH0tMbuUmznyVAuYmQmIAVSPoSHPmBowH gWRzPXwcd2GjIO5KK1WmILDzx+/NEmbduJ67F/A1CekTkJdZ+lcbEsI7kJcYSW/LyzIM /TdA== X-Gm-Message-State: AAQBX9d/UqzvWO3U10N+Rd7MZ/z3oeW3WzYD7Fl16z+ojE+nPk8j+gFW yHG3Yea018ZDZ5v+yz1rjCnryjnwE3cAdg== X-Google-Smtp-Source: AKy350bIA6FTKaMx1Lr3Votg49I5qPynF31thJcEImjQCfaxTRC+Wx9FwvL2T2TDbzQAd6coUEPUffEYZnKb8Q== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:6902:10c3:b0:b77:97d9:f096 with SMTP id w3-20020a05690210c300b00b7797d9f096mr5340906ybu.10.1679852132297; Sun, 26 Mar 2023 10:35:32 -0700 (PDT) Date: Sun, 26 Mar 2023 17:35:11 +0000 In-Reply-To: <20230326173511.710749-1-joychakr@google.com> Mime-Version: 1.0 References: <20230326173511.710749-1-joychakr@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230326173511.710749-3-joychakr@google.com> Subject: [PATCH v3 2/2] spi: dw: Add dma controller capability checks From: Joy Chakraborty To: Serge Semin , Mark Brown 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 and store addr_width capabilities to check per transfer to make sure the bits/word requirement can be met for that transfer. Signed-off-by: Joy Chakraborty --- drivers/spi/spi-dw-dma.c | 54 ++++++++++++++++++++++++++++++++-------- drivers/spi/spi-dw.h | 1 + 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index b3a88bb75907..5a642ec9c269 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -23,6 +23,8 @@ #define DW_SPI_TX_BUSY 1 #define DW_SPI_TX_BURST_LEVEL 16 +static inline enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes); + static bool dw_spi_dma_chan_filter(struct dma_chan *chan, void *param) { struct dw_dma_slave *s = param; @@ -72,12 +74,15 @@ 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) { + int ret; struct dma_slave_caps tx = {0}, rx = {0}; - dma_get_slave_caps(dws->txchan, &tx); - dma_get_slave_caps(dws->rxchan, &rx); + ret = dma_get_slave_caps(dws->txchan, &tx); + ret |= dma_get_slave_caps(dws->rxchan, &rx); + if (ret) + return ret; if (tx.max_sg_burst > 0 && rx.max_sg_burst > 0) dws->dma_sg_burst = min(tx.max_sg_burst, rx.max_sg_burst); @@ -87,6 +92,18 @@ static void dw_spi_dma_sg_burst_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; + + if (!(tx.directions & BIT(DMA_MEM_TO_DEV) && + rx.directions & BIT(DMA_DEV_TO_MEM))) + return -ENXIO; + + return 0; } static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) @@ -95,6 +112,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 +142,24 @@ 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 +185,16 @@ 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; @@ -202,8 +228,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 enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) 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;