From patchwork Thu Apr 27 12:33: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: 88255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp254755vqo; Thu, 27 Apr 2023 06:08:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FSB5UBa2iL0LXsByfKGl5DbVIrCMyqG3K6EPlnNlaXxngipfGoBMVKw6Evz43ERDu0agp X-Received: by 2002:a05:6a00:2294:b0:63d:2d99:2e72 with SMTP id f20-20020a056a00229400b0063d2d992e72mr2604975pfe.7.1682600935589; Thu, 27 Apr 2023 06:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682600935; cv=none; d=google.com; s=arc-20160816; b=xte40lZfjk7u73W3P4PXkzKfRutQh0aX4GIe/wC3fOxECXPrV21dCLHvgDigZd+Vwi 5g++qUE861JSJD8CK7E8RTb3yRwCogBlXsl+KZwaiEv7q27nhN9LQhu1CfTmdpXSQToR YDN3cEgZ40w4w+xb+rf5lz/Hge8NNlGESlamw/bNpZ++i1GCBQd5T8OgtSsAK4CSXfni He+MwuPC2ZMqgTeh35bZIEl9j8yICXbr14ajimJ8NEw+5M7kI3rAAJMLoItEMVwDFi42 dHhG+9XKeDgCfnx7jwb2zJr8xqK4YAz6THoeKSCI5tErk5xNC/6HgCqKYJDafwv/EYjX X8tw== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=S6Q/VO/y6Fq41tZ4izLIBk5IF+y5iSwGGeoALfMszCI=; b=nKsJluDYN/97ZiN1Rc01UK7b22XCXA3UOvGwWqUwNPc5skS2A1NNc/6IZVbMO1aOnI rtbD8pPD0MepPTP/hjCmxh4PIc74e/QurKXSwmeIKmCxAYSagWHWZ82PyqNBedDlcV7F DOXv4Y8M0y6nt5W6icwFqfMS59eQ/hMrv9YBibKDRAZkJTPCHYvhSg6yYSlYZ1pOAIPR n/98pimlDFYkLPd6G2ADJlm9v6t5oCTDR2x/cBWehcQaKCBnJCKrFHcGTpEnwv0Cxv1p M26JbBysXb1tiZ4Wrw3BrsI90kxAyYidX33vr7d8ZTsQ/CrDJlFlvAbWxvzSV0vVX9zU oJyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7SF3AaYc; 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 o10-20020aa7978a000000b0063b733e67c2si18759702pfp.121.2023.04.27.06.08.40; Thu, 27 Apr 2023 06:08:55 -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=20221208 header.b=7SF3AaYc; 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 S243555AbjD0Mdd (ORCPT + 99 others); Thu, 27 Apr 2023 08:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243201AbjD0Mdb (ORCPT ); Thu, 27 Apr 2023 08:33:31 -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 6D00D4ECA for ; Thu, 27 Apr 2023 05:33:26 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-556f4e20131so17568977b3.1 for ; Thu, 27 Apr 2023 05:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682598805; x=1685190805; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=S6Q/VO/y6Fq41tZ4izLIBk5IF+y5iSwGGeoALfMszCI=; b=7SF3AaYcSGoW/ypNoGCNNc3chh/C711C/2zAVabYkzWAjXS5uyIHJjMv2VhpJCI9gE Ry4FjZgURKjz7Orp7MNpjEeG+C+Ud35NeSimsViU8ifp/RZjHbUQoHR2KqcOcI73D27C KIMkrFI0jgZiBCRYSEOaW7GJo+hme96imkeLIPRGUp+zzoG9rX9fqexYwtdXAne8cxIY E1Izj/Lk3eB8spEO5RpQr2XxNYls/ajcmzrfrQCxYOUnjVzOsNkXQl5IPHQMp67aon4J 2LojHEtH9Nkvr90LmeyKmUEzS6yaQ5RN4fuDox9tgy4P5j5DVnHnggAWctFk9STKNJQG 0m0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682598805; x=1685190805; 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=S6Q/VO/y6Fq41tZ4izLIBk5IF+y5iSwGGeoALfMszCI=; b=cOWDzh4dzg59uzm4qavsaYpvzwfcNBUl6ZuDQNh+7BNaEPSV2VGMxgph0juKyot0RO vqgzdYHv5WMJ61r5afZvG07oGFkGC7AOGmBP3C+z8AHKacIcSLZmrAHO0UTILbujxXkS bEt/bxxuLRZxiLfecTRs4pqAIOI9TQe6kGgJe/B/6eN75oActiz+nbW/4ftwL70Zw1GF y8Qrxbf9Gt6yAThd89SAnvBTXEC3svixROZEnHzhyziDwUeiAMBxBUtbX03M3di89xob Sl3OoQUegmQqvzspIX/EdJu2kgzV84feY5fOXJ39qnDrpCuIQhy3Edlu2TfVGFjWDZyu kf2A== X-Gm-Message-State: AC+VfDzOSJBz8HmWGesA+15i2JhQfAwQThNOcrotcjtkIG5k12WImLyg yOCRR49hBJ+6H+XX1okBo6S6i0hEcHB5UA== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:690c:725:b0:54f:bb71:c7b3 with SMTP id bt5-20020a05690c072500b0054fbb71c7b3mr997276ywb.9.1682598805726; Thu, 27 Apr 2023 05:33:25 -0700 (PDT) Date: Thu, 27 Apr 2023 12:33:10 +0000 In-Reply-To: <20230427123314.1997152-1-joychakr@google.com> Mime-Version: 1.0 References: <20230427123314.1997152-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230427123314.1997152-2-joychakr@google.com> Subject: [PATCH v9 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 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,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764334958709113223?= X-GMAIL-MSGID: =?utf-8?q?1764334958709113223?= 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 Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- 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 27 12:33: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: 88250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp247004vqo; Thu, 27 Apr 2023 06:00:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xXSqDPMSl+YDwuVu+tLzg0515yJ3bjV2GCOHHxBe7FgXIhppbUVG+aAtl2M+FU5O4ebHG X-Received: by 2002:a05:6a20:9150:b0:f5:d6cc:e3f1 with SMTP id x16-20020a056a20915000b000f5d6cce3f1mr1804525pzc.20.1682600404679; Thu, 27 Apr 2023 06:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682600404; cv=none; d=google.com; s=arc-20160816; b=n9dZGa2I7frVayNh0hNIcNhZl84dn0Jf9B9NCdYQOveBfG9Tyi5kmHPz/yv/iFFGWX 8Hue+++1kYYlstbscgRXgOps69sUTwlqcXeIppgHYzgLyJTxSdJlcTivhDIHrIKGpVoW EPzoyr78kRQbXSgXucFqsJ0Dab13WyWKKdrjgIE0yqwAoCNZprg9ZcCjlV82EYzzEfLS F+++GpsiwIz82kU+apqSuu8htcTzdTOo2dz+poMG20Nu/UDi9rLJ6KJHvw88ElzTgIPT S5pXDgXCdLvrJ/ReKRbpdh0cHwujuh81rJ82MorUJCI27NC9D9oZlWw6ET7ft7KZLgdB E+cw== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=Adm4j45gizFfC/DwqDNV4am9AZ8vYB5z8Xwbghf5BGo=; b=PV9siqg502TQMcZlWy5T47noCpUM3EXO5vnI2Uzr48DKP/198iTVphTznynLGHAnFE JVrdcsS1xLsrS980gb/HUwACwqtOOPJSwxzca0epDpBTvxfQ+2yuqpeG7cLPEPZC3vVk sHuk+SUEHtm0y0jttHLyr9jijsxCa4JrS5rMow26OCI1qm1UO4cKpfcuQeOLTrLjCVRN sugpKeT6urDHQIgMJCXJTcdEc00qZ8qO62t9sisSJgmUrurhAFMMXDhi+jFckUU3vi2W 9AuTylQM/2pXAua/F+tdLnxYaPE2qkaW1iucraEbZpaiVR5PkBfClN+axr7KoNZ91DwF KPZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=zsszPebu; 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 r23-20020a63e517000000b004fbd7827010si18604335pgh.263.2023.04.27.05.59.49; Thu, 27 Apr 2023 06:00:04 -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=20221208 header.b=zsszPebu; 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 S243654AbjD0Mdg (ORCPT + 99 others); Thu, 27 Apr 2023 08:33:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243563AbjD0Mdd (ORCPT ); Thu, 27 Apr 2023 08:33: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 2D1624C03 for ; Thu, 27 Apr 2023 05:33:31 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9a2abd8f7bso4215441276.2 for ; Thu, 27 Apr 2023 05:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682598810; x=1685190810; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Adm4j45gizFfC/DwqDNV4am9AZ8vYB5z8Xwbghf5BGo=; b=zsszPebuf3cwDmVN7gVllalvKOsKsT+K5wl7znryh8N/HuMkkoSIt3lbU+p0W3aYVh SSSaO27ReLEqOCzG3BSuuDNm2DML74Zfb99YQZlQWs65vMnUHWeMpPKTpa65fLps3gi2 vSlUH4rS8Pu+gwunef7GF7styB0VyU+lahLQDrrM1XEL1K1PH+DfH0h555dj0y86CX4S lKaRbe6XIL1XAsx1lcGj5DnQdzwgD/3Qx6kdhWH5H24GnIS9WomZLqartGvw6G98OBZf 1P06hkAeYdfaQtcpR4dTlCKGVVZ+Bs7kqxOzix3okyVRG7k5QpKflpKuUzNRhgNZeD0I XdeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682598810; x=1685190810; 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=Adm4j45gizFfC/DwqDNV4am9AZ8vYB5z8Xwbghf5BGo=; b=ZZDIGjurqAcPnt1fr+K7uELCTVgFMPNvKfitLyGWHf0Wy24NkQgCYe2KaHegbYlMOE uboimyC4L1IOzNoE+ZLPCb1uEWCSF1k4PYuGnmqoQAMGAg7Ttme6ZVjsZY04nIL9gr0U y6BatLcOlc5siyB67YIjVjI3x2/QPOMCEbovn/LgtSQyoKISsTsuko/RKH3gQv44HjoY mELLi9y7HcQa6WwiX0VHOixqJrXKb4q3f39c4NEnH9q0bg++lU8tWi7Jp/zVoClUBG5U gDdt4S3ogQ7PdKjsRSlil5n9TvDDvv5/H+6RG4dJaBgvmlGq5t4xwV1ltjJ/71GqTbN5 s2LQ== X-Gm-Message-State: AC+VfDxuXUugVHYhJYa+k31sc2cUJjKEdSmwGOrJ/907AKierR6jGt2J 5k/UByCJ8BtA/+0r84ZAo9NBRRhESf9Gfg== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:c041:0:b0:b96:5b8a:3c34 with SMTP id c62-20020a25c041000000b00b965b8a3c34mr441564ybf.11.1682598810419; Thu, 27 Apr 2023 05:33:30 -0700 (PDT) Date: Thu, 27 Apr 2023 12:33:11 +0000 In-Reply-To: <20230427123314.1997152-1-joychakr@google.com> Mime-Version: 1.0 References: <20230427123314.1997152-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230427123314.1997152-3-joychakr@google.com> Subject: [PATCH v9 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 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,T_SCC_BODY_TEXT_LINE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764334401942169649?= X-GMAIL-MSGID: =?utf-8?q?1764334401942169649?= Move dw_spi_can_dma() implementation below dw_spi_dma_convert_width() for handing compile dependency in future patches. Signed-off-by: Joy Chakraborty Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- 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 27 12:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 88252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp252646vqo; Thu, 27 Apr 2023 06:06:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jaKExRQ01nQrXJNvPjKoZobYeomTab7FInRezNE9BAWd8fgWZ7ovbjI0bITcf1ZnFwsv1 X-Received: by 2002:a17:903:11c7:b0:1a9:7e26:d72 with SMTP id q7-20020a17090311c700b001a97e260d72mr1682721plh.9.1682600789482; Thu, 27 Apr 2023 06:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682600789; cv=none; d=google.com; s=arc-20160816; b=SqjwhSPpSL8rdw7DGVrlegxHnRSjS7ZVDH6+x3JSn3YRmh/tmImDwktg7v1JsCANNp rgrJlBAdoLvbhijWIgNKD9dLmpE9P9pT3UK4V3W+YR4UiMEADbzwHjUFCUHXUyC5YUkQ rXLqMYd2dg+xAMp0mcA6cMsrST8W5xp8eU9NKeaVpX1qFnK2U1g61KcvuOj+qPILc0FR g2xo68Qjdo0LNz0jUz+viWBqowaGrMhEvXHWfgc5CSoDcBf3c4WD2JbprZidCsFt9FMx FoI2kRpULrazR7eo7StNN29B123/yinV0sBaQ+AD99dry6fqCSbgh5kIfLccW/kTox68 An8Q== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=o8GsQCBaZJI/kD+802nQ+4grvsSl0JkV2Q+XulPct0A=; b=ZELfWhmOQkB7ve7uzUBSLIwSAGQmQZs9uADz9giqTZwO7otojAp+VaxJMuY3BH04pO U3fIVBNpeBM2uttux6m2NXYiJlXx6Dwl53fpbSaCwncxbh/gpCxRO65a8XEi4ifcSWK+ 1ErYtr0VvdT2oN4H3x7TBYrnHobhzCPr0U10utVyT+/S8Clcmuhh42a0CfZmGH6ta6fc aOzCBLOxgg8WurtsrfGKZlHBjK/44OAi8JOLrVgOimY2LrRjiPzjg/PEDb2c6BotKrYL SVlGJcGwZC4kemteHRtY4CFZ7a80/HZTZJWoylYLvO7Pr/5EJQRaOJN7dTdvARhGohXW iMNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=CIwS7rv0; 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 b3-20020a170902e94300b001a64b5976c4si19663030pll.110.2023.04.27.06.06.11; Thu, 27 Apr 2023 06:06:29 -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=20221208 header.b=CIwS7rv0; 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 S243717AbjD0Mdr (ORCPT + 99 others); Thu, 27 Apr 2023 08:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243695AbjD0Mdn (ORCPT ); Thu, 27 Apr 2023 08:33:43 -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 04D26526F for ; Thu, 27 Apr 2023 05:33:36 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a6eeea78cso4370822276.0 for ; Thu, 27 Apr 2023 05:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682598815; x=1685190815; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=o8GsQCBaZJI/kD+802nQ+4grvsSl0JkV2Q+XulPct0A=; b=CIwS7rv0Bt1NRSpeLAH2zHX1mFDLuSSyyWHxoyQnbpJ6drNZh7T5je0G8bmM11LmtV sL2mbhnvGL7nmxnTE6+xDc4VfwbDWu/5t1acHTsWuPeOvHsVRykoUE6+pvz8q6BaKzym td3aouq+E4LHEGNotLcWdg+FDtThdDALNOnC8q5SnosK4pGYp5t0MGHPgfknsNEIVqSE EtAEPpGLrbirluU/9g7gyc2fpsW0t48xDoA4+qCWWt0zzax/0JchhEaVOcaFUPYF2FT4 D/GdvuTD+e422rsRMt+nW8BTLCXrybYZ1nCdgL6dzfzTMh+57+xMBcbVtNNg46RCkZX2 +lWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682598815; x=1685190815; 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=o8GsQCBaZJI/kD+802nQ+4grvsSl0JkV2Q+XulPct0A=; b=Cc4q6Ha3ueEev8uPAVyZ4CvyQeinLnaTGlaPFJvmJPCV/stLbq4nc6+WRqLgUGAP3H c/9dXl/u78QdCt2fWJePOsXKhqAeTcQOAmYHEwm6i4A90/Hluoi6wWqRoR3hvlgDb3Og xL1Iev7SY4mbprUBboqrDKyjYuH56xKNio9zmAyQadIc0J3KSQNZ1JkaD/gvdNlMoIRx PKry2n31K7eLeHaXGQP8+3fB/X1wcjQmug9QSjmw0iKXaQHInItNm6iplJnA3HNwpW4N iRGq1FjrA2znDBP2hWnvlTPFzIdCr8cvcr7lrnR+d5o8kCWEJC/k9s2DpYuquLAIQsZI zxww== X-Gm-Message-State: AC+VfDxXN6LIZMMpmG4d39g46TuHI7N+KrBZlEczOcajOgP9urNU3Myb 0HLb6SIgLr/yHCCQU0GXkqh85xLVvHBcVQ== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a5b:ac5:0:b0:b8f:5b11:6d6c with SMTP id a5-20020a5b0ac5000000b00b8f5b116d6cmr3736264ybr.1.1682598815226; Thu, 27 Apr 2023 05:33:35 -0700 (PDT) Date: Thu, 27 Apr 2023 12:33:12 +0000 In-Reply-To: <20230427123314.1997152-1-joychakr@google.com> Mime-Version: 1.0 References: <20230427123314.1997152-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230427123314.1997152-4-joychakr@google.com> Subject: [PATCH v9 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 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,T_SCC_BODY_TEXT_LINE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764334805345051995?= X-GMAIL-MSGID: =?utf-8?q?1764334805345051995?= 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 Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- 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 27 12:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 88257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp256453vqo; Thu, 27 Apr 2023 06:11:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4L2DaMU8Kw0y6BrgbUtD6FRTa5i5Qu3YPFao+8lxeDeExakiRC6xjcVfS7MnDWOJOZg+I8 X-Received: by 2002:a05:6a00:2383:b0:63d:315f:560f with SMTP id f3-20020a056a00238300b0063d315f560fmr2363858pfc.13.1682601074970; Thu, 27 Apr 2023 06:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682601074; cv=none; d=google.com; s=arc-20160816; b=CAhYoJgc95ODBD/zFS2pXddSRTiWT1iV7h56bz1USbwx551cWm1JxHLdbWnGgs7LWp A2ByOV7u0yQyJCmmY7BmyckHIIXybCVHCuNVcXbtbNmmj41DMj950L2xdUHXUWtuAXon /B6oC317FwHEZCt8SYjlu8quG8VN8fbnHJaw0UV7V64h05+epu/njCZBjP/7Oql8LNwc db1AcjWo7NXd2yyLiqyGuwxggE9zCCaycsCe8rw3EcfB/FHvx8h0Q79ZKN4hu+8rsnru VDESQefR6yHtZkiShsyZamCPVftWMxIQ4GDImQInOl1vueOyqEwrkvhXfWnDtQPrnROG VIdg== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=fLvnCO6evlKbK+xj/d2Id6gaw49UQ3nh6G31gbqAkCk=; b=pcHgKUkrGUzzW4P+b6YwBvDP5dGC3Ngp+x+fGw+jcfcWGip52OugBxBKWd43hlqzjn s8CDke5Qd61Hi1ajM2LGjljIJ7GJ7RMLnwiMNo9d0gind8Mcqwx62pOXhnrlGJahSEsa ph3grUIN6NTr0aPJS0NO7UpsCxN8xi+TIL3GhIQfbwOq9u5be59pcQwDqyL8WkC/Py+x 2SmbuZKZxAdNSjw5DJtA0UNdYbd8bO0TW9wnhmECKlqCuXb83XHfI9KTvhTfZJQqwn3M MvJqEUuAAuN0gyKsQRPco9HvzZA68PRU+DlAJkDg50JZZQVnYVknACmh1OVppsGoHnhB KETg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=3DLTZ423; 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 j191-20020a6380c8000000b00524d36c533dsi17591445pgd.98.2023.04.27.06.10.35; Thu, 27 Apr 2023 06:11:14 -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=20221208 header.b=3DLTZ423; 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 S243797AbjD0Mdw (ORCPT + 99 others); Thu, 27 Apr 2023 08:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243851AbjD0Mdq (ORCPT ); Thu, 27 Apr 2023 08:33:46 -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 8B3BC5BAD for ; Thu, 27 Apr 2023 05:33:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b8f32cc8c31so14480233276.2 for ; Thu, 27 Apr 2023 05:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682598819; x=1685190819; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fLvnCO6evlKbK+xj/d2Id6gaw49UQ3nh6G31gbqAkCk=; b=3DLTZ423zj75HZE3dLX2ol2fkvJhx+OfxNx9TMkA1hLwBabuiMsxVL4wEmuUfF45UQ +i0GLG+Em2uXwmyHcJLuJRz+vWS5vYw+EdRJvVSn8prLzEyev1YSa/j+nCoeGTno7mIi 56DwSlzeCplHTll72n8yKAasRvyfeO6rsIFX5krBUDP7yXf9nWgwyHjFnGAR7KN3XITs ggptjW7770nyYfIoSP2/MyjD9plolbqIVxbccmGTDnK3ijXt0EvYQzVSbjIXOrCmvRyb SThdIXn6S3njt7z3q77aTsYuoeW9Bbf8L+UTaIWZAOdV+J1f4sLYODoPz9ZCNsw1QcgN 7UJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682598819; x=1685190819; 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=fLvnCO6evlKbK+xj/d2Id6gaw49UQ3nh6G31gbqAkCk=; b=j67E6NB1gugK4sJN8b+uioFrzantLKMWXF4dDiO1nvX7GoUSa4Kv3KimzutpL8SF0w KjYBlmZ+c3825vi/GpzWENMrh1VkrzjJwyyr5NeqMX/lkub3iclig1wkRbwKtIghwn+J bgLUa/lqarSPPW6NvgQrMSYd2bZpO2lwzaP7wQ2ft8cSxXnzgkt9DEBbGK6Y91M4l19k +wzsCcMz+regdgkSc277NgQUfQWLZW0oYbrobty7YXwh3L/bSoXizsHhGqouTss8L9We XQDP0sBFI6THlImaBX4SLSXuDwgCWBpPxC5zWHg42hVCaLkwa/HL7RTT4GHCFGd2y1gT I7dg== X-Gm-Message-State: AC+VfDy2RLIJ+ey2Yx+1D39mzZzstYJLDis/5wspwTOzH0Big5YblsDI rVo+pugGkrsnWUKtSOzC1Im3WXISaRVjyg== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:5843:0:b0:b99:df0b:cb1e with SMTP id m64-20020a255843000000b00b99df0bcb1emr501204ybb.4.1682598819554; Thu, 27 Apr 2023 05:33:39 -0700 (PDT) Date: Thu, 27 Apr 2023 12:33:13 +0000 In-Reply-To: <20230427123314.1997152-1-joychakr@google.com> Mime-Version: 1.0 References: <20230427123314.1997152-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230427123314.1997152-5-joychakr@google.com> Subject: [PATCH v9 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 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,T_SCC_BODY_TEXT_LINE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764335104943572325?= X-GMAIL-MSGID: =?utf-8?q?1764335104943572325?= 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 Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- 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 27 12:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 88256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp255580vqo; Thu, 27 Apr 2023 06:10:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66TNPw/VcF6GIAx3+/WMWPegQneWsHFmCb8hXyqEsUgcxY308HL0TdKf9ZuDSoyEJm2hf5 X-Received: by 2002:a17:90b:1e4c:b0:247:53b4:ec52 with SMTP id pi12-20020a17090b1e4c00b0024753b4ec52mr1942492pjb.8.1682601003649; Thu, 27 Apr 2023 06:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682601003; cv=none; d=google.com; s=arc-20160816; b=BgpATxtRXY6OrVdm2Gnm0XAvxbHWNSaGFPG+m3hUxkcoqCKZE67mKMt7ntbQl4ZsD0 msMNHGBjLLmDf1GbBomEh1bgKoaXVaa4XNgYffS02YywtJcCm5vbTqWB1+gdoIDcOMR6 k0k5mNcD+a1WiCa/ZDA7nIIN7Uhpk0O8i/+aiVbhz0w5ytRvWhRVLed0j/kxCR4JrC5e yyLXfYIvcK9Nl3DRmeBm3n8fbWfLJnosszvd2KCvb74sGhhyuQoQjP4GLR53pSJi8GK5 RY3eVTujrXK63iWxG4vmX4X+vzsChSxfsN3Ctbxo5fn0kRLEZlyyZ29h9crkXDTrfmpu pm1w== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=1ypFgisKdugG378RCE4wuNj0FpBiItt6cq8MGNIIYGA=; b=QjDfDfJFDOGC3BhxIbt0xrB6uAFewuIafl7BRZ56UGQ2212uOgK9z4Jgx0Ihj5F8FV RmvEgsyNxXIgTh+QC7vt/L8VhGZ5fEAN7rFogu6lg3ZtsL9o5xC6Kx+ci8LHkjHm/87s 6qCYkP6L6PocLmzFEr5HlCShw+LoJ4LHS3cPwy0E+ncIY3XRax+bdhXsYWD+E+au+qoB vNqokYWfQbZGiA6ylVlUOje6urZQyC2i6V318vsT3ow6aBKdcdwYQ8dPZU3FL3nWyNio XXA3HU/L/A2Z2LteCz94vBL/iq+itoArfyq71dAoWDIIaiYDGh0SJvb4naDUmBVie/aA SSrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Otk4yIq6; 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 bv11-20020a17090af18b00b0023d2380862csi18730018pjb.77.2023.04.27.06.09.49; Thu, 27 Apr 2023 06:10:03 -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=20221208 header.b=Otk4yIq6; 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 S243832AbjD0MeH (ORCPT + 99 others); Thu, 27 Apr 2023 08:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243549AbjD0Mdz (ORCPT ); Thu, 27 Apr 2023 08:33: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 DA76D5244 for ; Thu, 27 Apr 2023 05:33:44 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a805e82a9so870279276.3 for ; Thu, 27 Apr 2023 05:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682598824; x=1685190824; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1ypFgisKdugG378RCE4wuNj0FpBiItt6cq8MGNIIYGA=; b=Otk4yIq6Sbhtb4TihxX60Psghxw0hddCiysw1B0c+w6rnLG6DP8tPh7lvgZ5M1w7Ye /KMpNEQS+6aA+ZZqtzogfKKjwXsEHaMZabvreo32p165z5+9THvfuz6i2eVem5FxByk5 NSkh1R4Dju3S2xWB3oOJfa8/VG+1AndSfU92fsztFbXNf2MW0nTgXYJmr5kbIEXH/KXe dJ0BL3lS/iY691UuIba82p7XuGmUI8tkKLjGMH9g/IvXuY1UdU9I/n3fQD07YYh+eS0J zYKWa0puQ3ZWy3qAXei/C3PLQsVTFyHGJdVqvOyMJIjn1Pv8ILZH8IMXqikGBxumAPgU fLqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682598824; x=1685190824; 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=1ypFgisKdugG378RCE4wuNj0FpBiItt6cq8MGNIIYGA=; b=BnkoSiqMubYr8AJEcE7CRm1JzrWElTiO1gMr/SyODBKVQk5v8a0y4VOrvabcQut2sP WnZ30fwTRAkiJ18Ylv/+knSn03UZ36XKlvxXQIaIPnfRLhdKT3vqwFUrsjUbxYjiOdo2 yN6Xt2hQV6Wp54IMBYEDnM4nCNr0b25i5a+KQLQnHnvndS2EJUEu+/Hy4ByfnrSE5vMM MQ5r52QeWbLHJqOC9G1RQFbxQSxdgB0M0DdT/+gmk8Pb0SUNES3kqJY5BW9QW4qEHXOX PSAjxrtXitO1xuraLY2UlK+9T+EHaucnOOqo2PWrs/5niyxEPu47eiVCLiC/WOtFzSvT ZvgQ== X-Gm-Message-State: AC+VfDwzBz292OZzOkUFihAczHcnfdbSCwacLHdUSKTHn1v9+ojrrK/F VtaUUX5znZVBL5oB3p9SPpvxd5gbrweMpw== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:6902:188d:b0:b96:a18:1b4c with SMTP id cj13-20020a056902188d00b00b960a181b4cmr497926ybb.13.1682598824170; Thu, 27 Apr 2023 05:33:44 -0700 (PDT) Date: Thu, 27 Apr 2023 12:33:14 +0000 In-Reply-To: <20230427123314.1997152-1-joychakr@google.com> Mime-Version: 1.0 References: <20230427123314.1997152-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230427123314.1997152-6-joychakr@google.com> Subject: [PATCH v9 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 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,T_SCC_BODY_TEXT_LINE,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764335030396334326?= X-GMAIL-MSGID: =?utf-8?q?1764335030396334326?= 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 Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- drivers/spi/spi-dw-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c index c3bfb6c84cab..4976e3b8923e 100644 --- a/drivers/spi/spi-dw-core.c +++ b/drivers/spi/spi-dw-core.c @@ -426,7 +426,10 @@ 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;