Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp864022rwe; Fri, 26 Aug 2022 16:48:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR5FvPCY/EcP37o9lSqwen49FbetPofqS/r9MTH5af4m5IHl+FEZnsYCgmKo4m7pBLwKjqni X-Received: by 2002:a17:906:fe46:b0:73d:939a:ec99 with SMTP id wz6-20020a170906fe4600b0073d939aec99mr6890807ejb.169.1661557717238; Fri, 26 Aug 2022 16:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661557717; cv=none; d=google.com; s=arc-20160816; b=CaMowDcryWN6aLmK1ePlehVqlMbgoc3fS7yJZNX7PnkX8gz79vhk8zCb41oEZFBGSP DXCLLYFYog1gj8fEHRbdJg6LvHCAYgeHwGRv9FcoVu9Q3jJ0XG/NenJhRJyXC5HM/xJ0 xInJgd+s9cjn2YfLWeNjoLK+wVyej8tNFNje75fdDqrmmngKepy7m99E0Up+HbVQ0FeV J1/wioapr9fgBvx4/gCbPGQ2I4PKdKqQsEJkHLcb1L59jA6l+jUdraUw9KxpZ5DkHq5j QPyO3nYXLKmGiw73Bh6KZGLNRgRApNGSPb5fE9GJspISIoNQfTfoDwjxp1bP3z6sNWvM fYdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cuhcfpneE0iqUirTacYqWVnOAjrXs1Oi/XMfPrLa4Cc=; b=nlr/IqBnHoERDuL7y1K/HAEAJXn8RUf+Pv+0RK97vzBOr+VN3sbMdYTg0Wii4l3hRr v40fZUtdQLj1gw6a37G5oBpUr9npcLi5te1I6y2jKguwkGQP0BgbPA8GEs2mppNYYh8+ 7ZeMJJvHATAxDaPqRbQMVZQfqxL8ZbOHrQop9ty005MCcpVjYtuTqRSBOKpxfiVhL1Jq o0CmbPZEfEIFXi5L0afW/S2cqGDZPqps0yoh8TyD4n04wa2Vm0AYzCcoPOX2ylyxbso/ NFboVghNQ75MAA0zWcZ76Xr834ajH8H9gMcYfFLn46zP+OKZHlEFhFgUdR65ugNVlMOD 4n+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IhItt1sK; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a17090666c500b00722fcbbb636si1859697ejp.138.2022.08.26.16.48.11; Fri, 26 Aug 2022 16:48:37 -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=@gmail.com header.s=20210112 header.b=IhItt1sK; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345473AbiHZXTb (ORCPT + 99 others); Fri, 26 Aug 2022 19:19:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345227AbiHZXT3 (ORCPT ); Fri, 26 Aug 2022 19:19:29 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E7BE9A95; Fri, 26 Aug 2022 16:19:28 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id m5so3835185lfj.4; Fri, 26 Aug 2022 16:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=cuhcfpneE0iqUirTacYqWVnOAjrXs1Oi/XMfPrLa4Cc=; b=IhItt1sKQ1Rf3A4YMzt3fUbMifY8Vpl/L2kD8xlXTB72Okyxr013Utr1Bm7/5OWa1y W534j4ToouEeEnATiHaVYGxw9RbZG/244h0qye8tK569LI6rOTYb/xpFzXcnZMquQmBQ ZQ96SKxPKJ5zxdw/fWOj9AS2ObW9zBfJpur5uoNx1KUpDQJRLeIAl1f9gw84Ff6GaLCZ NzmJZoWUOWAdN64pExNTBIbcFZKg26FXUGqjA8XVCb0Q/WAuMMFvzLx1UvrzlUoI0jpS htJ/5JiSpoHct1L/FwC6YL2DRkNZXPR39GMuXZi3dfzlE9O0dhxNgdejDVWDoJqBBnxH O+YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=cuhcfpneE0iqUirTacYqWVnOAjrXs1Oi/XMfPrLa4Cc=; b=Z8bSz4SAjiQ/LW9T4SK++MonDVLDnZw11pCIwqvvb8xSr3ygnhHpwHWIi3/UXGZPC1 im1wTHUR1+DorsQw8agCBtiA0XFMSR5bCZuagrk1x/y5kgK6FmgQSj2/Tlup688Yokiq AlyjEswbKSoBcNLtlnY57vYI4jC0WMLZiyxO8Jng9jqQF12pRUdqB7tOSZOkUBu0p9xg WzpvV5yg15jstPenD+9kltLuPIIjPLOeVs5cWW7G5kbh8aMsKotLd4S9yEYyKIBm9QAi h+2+v0YJcOB2zKF0L3NG8F5EpfZ62UnL/bhe0qdqD0xbthTF48JBleqXZkIflo4S9BPP OqzQ== X-Gm-Message-State: ACgBeo3ZeRR7Yk0iyVaYnShO9rLbFOhrAOb7AYDC/DKV/xjKz/Hv8MWA wIM5oOALtdC2H+X2hAeWhoc= X-Received: by 2002:a05:6512:20c5:b0:494:603c:1994 with SMTP id u5-20020a05651220c500b00494603c1994mr86973lfr.637.1661555966373; Fri, 26 Aug 2022 16:19:26 -0700 (PDT) Received: from mobilestation ([95.79.140.178]) by smtp.gmail.com with ESMTPSA id s9-20020ac24649000000b00492d108777dsm500442lfo.136.2022.08.26.16.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 16:19:25 -0700 (PDT) Date: Sat, 27 Aug 2022 02:19:22 +0300 From: Serge Semin To: Sudip Mukherjee Cc: Serge Semin , Mark Brown , Rob Herring , Krzysztof Kozlowski , greentime.hu@sifive.com, jude.onyenegecha@sifive.com, william.salmon@sifive.com, adnan.chowdhury@sifive.com, ben.dooks@sifive.com, linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, jeegar.lakhani@sifive.com Subject: Re: [PATCH 09/11] spi: dw: prepare the transfer routine for enhanced mode Message-ID: <20220826231922.4jr73tzpt3vwpxyd@mobilestation> References: <20220802175755.6530-1-sudip.mukherjee@sifive.com> <20220802175755.6530-10-sudip.mukherjee@sifive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220802175755.6530-10-sudip.mukherjee@sifive.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Tue, Aug 02, 2022 at 06:57:53PM +0100, Sudip Mukherjee wrote: > The transfer routine of dual/quad/octal is similar to standard SPI mode > except that we do not need to worry about CS being de-asserted and we > will be writing the address to a single FIFO location. Please redesign this patch to having the IRQ-based transfers. For instance you can just create a new dw_spi_enh_write_then_read() method which would initialize the IRQs, set up a custom dw_spi_enh_transfer_handler() method as transfer_handler (or perhaps re-use the already available dw_spi_transfer_handler() method?) and initiate the transfer by writing the command and address data to the Tx FIFO. Feel free to create some preparation patches if it's needed to reach the goal. -Sergey > > Signed-off-by: Sudip Mukherjee > --- > drivers/spi/spi-dw-core.c | 141 +++++++++++++++++++++++++++++++++----- > 1 file changed, 125 insertions(+), 16 deletions(-) > > diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c > index 2564a2276572..d6afa75e7023 100644 > --- a/drivers/spi/spi-dw-core.c > +++ b/drivers/spi/spi-dw-core.c > @@ -712,6 +712,28 @@ static int dw_spi_wait_mem_op_done(struct dw_spi *dws) > return 0; > } > > +static void ext_transfer_delay(struct dw_spi *dws) > +{ > + struct spi_delay delay; > + unsigned long ns, us; > + u32 nents; > + > + nents = dw_readl(dws, DW_SPI_TXFLR); > + ns = NSEC_PER_SEC / dws->current_freq * nents; > + ns *= dws->n_bytes * BITS_PER_BYTE; > + if (ns <= NSEC_PER_USEC) { > + delay.unit = SPI_DELAY_UNIT_NSECS; > + delay.value = ns; > + } else { > + us = DIV_ROUND_UP(ns, NSEC_PER_USEC); > + delay.unit = SPI_DELAY_UNIT_USECS; > + delay.value = clamp_val(us, 0, USHRT_MAX); > + } > + /* wait until there is some space in TX FIFO */ > + while (!(dw_readl(dws, DW_SPI_SR) & DW_SPI_SR_TF_NOT_FULL)) > + spi_delay_exec(&delay, NULL); > +} > + > static void dw_spi_stop_mem_op(struct dw_spi *dws, struct spi_device *spi) > { > dw_spi_enable_chip(dws, 0); > @@ -719,6 +741,82 @@ static void dw_spi_stop_mem_op(struct dw_spi *dws, struct spi_device *spi) > dw_spi_enable_chip(dws, 1); > } > > +static int enhanced_transfer(struct dw_spi *dws, struct spi_device *spi, > + const struct spi_mem_op *op) > +{ > + u32 max, txw = 0, rxw; > + bool cs_done = false; > + void *buf = dws->tx; > + int ret; > + > + /* Send cmd as 32 bit value */ > + if (buf) { > + txw = *(u32 *)(buf); > + dw_write_io_reg(dws, DW_SPI_DR, txw); > + buf += 4; > + dws->tx_len--; > + if (op->addr.nbytes) { > + /* > + * Send address as 32 bit value if address > + * is present in the instruction. > + */ > + txw = *(u32 *)(buf); > + dw_write_io_reg(dws, DW_SPI_DR, txw); > + buf += 4; > + dws->tx_len--; > + } > + } > + > + do { > + max = min_t(u32, dws->tx_len, dws->fifo_len - > + dw_readl(dws, DW_SPI_TXFLR)); > + while (max--) { > + if (buf) { > + txw = *(u8 *)(buf); > + buf += dws->n_bytes; > + } > + dw_write_io_reg(dws, DW_SPI_DR, txw); > + --dws->tx_len; > + } > + /* Enable CS after filling up FIFO */ > + if (!cs_done) { > + dw_spi_set_cs(spi, false); > + cs_done = true; > + } > + ext_transfer_delay(dws); > + if (!dws->tx_len && !dws->rx_len) { > + /* > + * We only need to wait for done if there is > + * nothing to receive and there is nothing more > + * to transmit. If we are receiving, then the > + * wait cycles will make sure we wait. > + */ > + ret = dw_spi_wait_mem_op_done(dws); > + if (ret) > + return ret; > + } > + } while (dws->tx_len); > + > + buf = dws->rx; > + while (dws->rx_len) { > + max = dw_spi_rx_max(dws); > + > + while (max--) { > + rxw = dw_read_io_reg(dws, DW_SPI_DR); > + if (buf) { > + *(u8 *)(buf) = rxw; > + buf += dws->n_bytes; > + } > + --dws->rx_len; > + } > + > + ret = dw_spi_check_status(dws, true); > + if (ret) > + return ret; > + } > + return 0; > +} > + > static void update_spi_ctrl0(struct dw_spi *dws, const struct spi_mem_op *op, bool enable) > { > u32 spi_ctrlr0; > @@ -846,25 +944,36 @@ static int dw_spi_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) > * manually restricting the SPI bus frequency using the > * dws->max_mem_freq parameter. > */ > - local_irq_save(flags); > - preempt_disable(); > + if (!enhanced_spi) { > + local_irq_save(flags); > + preempt_disable(); > > - ret = dw_spi_write_then_read(dws, mem->spi); > + ret = dw_spi_write_then_read(dws, mem->spi); > > - local_irq_restore(flags); > - preempt_enable(); > + local_irq_restore(flags); > + preempt_enable(); > > - /* > - * Wait for the operation being finished and check the controller > - * status only if there hasn't been any run-time error detected. In the > - * former case it's just pointless. In the later one to prevent an > - * additional error message printing since any hw error flag being set > - * would be due to an error detected on the data transfer. > - */ > - if (!ret) { > - ret = dw_spi_wait_mem_op_done(dws); > - if (!ret) > - ret = dw_spi_check_status(dws, true); > + /* > + * Wait for the operation being finished and check the > + * controller status only if there hasn't been any > + * run-time error detected. In the former case it's > + * just pointless. In the later one to prevent an > + * additional error message printing since any hw error > + * flag being set would be due to an error detected on > + * the data transfer. > + */ > + if (!ret) { > + ret = dw_spi_wait_mem_op_done(dws); > + if (!ret) > + ret = dw_spi_check_status(dws, true); > + } > + } else { > + /* > + * We donot need to disable IRQs as clock stretching will > + * be enabled in enhanced mode which will prevent CS > + * from being de-assert. > + */ > + ret = enhanced_transfer(dws, mem->spi, op); > } > > dw_spi_stop_mem_op(dws, mem->spi); > -- > 2.30.2 >