Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2226983pxu; Sun, 13 Dec 2020 18:25:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxp+bSC+HKE5WA0yvjawnLf7jO2+Axj6rDWdj5XJ/LoFFXomoCVRGLJ364/clovhiaCMRPY X-Received: by 2002:a17:906:7fca:: with SMTP id r10mr20918175ejs.24.1607912752666; Sun, 13 Dec 2020 18:25:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607912752; cv=none; d=google.com; s=arc-20160816; b=SGbXnQHELQ644hI/nu5wPNJbgUCopVPWJySxkonrkD98yYGgxot8nhFnleKd0ATiqG FckDjc69xGw/L3/SItHnsECp9hVLrwzkLNiLJaagG3r2sOB7FcjJpLwlL/IF6Qc2jXym j+p+Zsppxeme6WW5e4EJOPD85EUKqPPyJ/leZ/GB9bYmSDGR/qLpmBnxKKs/8lEOLoXq mUNWVfDXJKftW0i9Rz0TIyx70SbsSa+L/1bS1TiROc79NyWQYozGxdrXtqGQUQOY/Zi8 BduaYUG14Ii5UIKw3tSHqOjtTa9Nu3qF8Tj/tyfv6mu/ZhvIjXCSy41Xdc4U2qUhaX9I nKsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=8Uxya1CCG3OZwiKIHenTJalTRwjm2M9vyhKxfW9cJoI=; b=mHAHmDMcYOpX41ZWiKN9cFtYziWCyPX7aoJZTR2ogyjO+xi6pAZbi9SQRAkxUNTTo7 3XjzlUGUWMuGj1Z1G3VSyRILR+Mi48smZmpRXMX+M9O9X4QI40ZQcQIK+4l9CHVCdhQs 870FO1GZIzUS+zKjmMjLJpEhOx5pp2DjcSO9c+nDRQXF5MpDcqSDL1sXitWiPmUD2CHx s0jSx2gpn1Qdt3xJHeOQDClXWSyX7gYhVCbAFyhkZkaxvNsiqF2fEGhIJMe1DcUWjM35 taSB8v95HcyjzOtZYfiy7hNgXzGAirZsj9JGbj3gbHCr8C/vYSpfdNGP35la52vFo+3G esGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t20si9580249edw.31.2020.12.13.18.25.15; Sun, 13 Dec 2020 18:25:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438858AbgLLK6L (ORCPT + 99 others); Sat, 12 Dec 2020 05:58:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726374AbgLLK6B (ORCPT ); Sat, 12 Dec 2020 05:58:01 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0A01C0613D3; Sat, 12 Dec 2020 02:57:20 -0800 (PST) Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 6E9431F45DBA; Sat, 12 Dec 2020 10:57:18 +0000 (GMT) Date: Sat, 12 Dec 2020 11:57:15 +0100 From: Boris Brezillon To: Sowjanya Komatineni Cc: , , , , , , , , , , , Subject: Re: [PATCH v3 5/9] spi: spi-mem: Allow masters to transfer dummy cycles directly by hardware Message-ID: <20201212115715.31a8d755@collabora.com> In-Reply-To: <1607721363-8879-6-git-send-email-skomatineni@nvidia.com> References: <1607721363-8879-1-git-send-email-skomatineni@nvidia.com> <1607721363-8879-6-git-send-email-skomatineni@nvidia.com> Organization: Collabora X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Dec 2020 13:15:59 -0800 Sowjanya Komatineni wrote: > This patch adds a flag SPI_MASTER_USES_HW_DUMMY_CYCLES for the controllers > that support transfer of dummy cycles by the hardware directly. Hm, not sure this is a good idea. I mean, if we expect regular SPI devices to use this feature, then why not, but if it's just for spi-mem, I'd recommend implementing a driver-specific exec_op() instead of using the default one. If we go for those core changes, we should at least add a ctrl->max_dummy_cycles field so the core can fallback to regular writes when the number of dummy cycles in the spi_mem_op exceeds what the controller can do. > > For controller with this flag set, spi-mem driver will skip dummy bytes > transfer in the spi message. > > Controller drivers can get the number of dummy cycles from spi_message. > > Signed-off-by: Sowjanya Komatineni > --- > drivers/spi/spi-mem.c | 18 +++++++++++------- > include/linux/spi/spi.h | 8 ++++++++ > 2 files changed, 19 insertions(+), 7 deletions(-) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index f3a3f19..38a523b 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -350,13 +350,17 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > } > > if (op->dummy.nbytes) { > - memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes); > - xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1; > - xfers[xferpos].len = op->dummy.nbytes; > - xfers[xferpos].tx_nbits = op->dummy.buswidth; > - spi_message_add_tail(&xfers[xferpos], &msg); > - xferpos++; > - totalxferlen += op->dummy.nbytes; > + if (ctlr->flags & SPI_MASTER_USES_HW_DUMMY_CYCLES) { > + msg.dummy_cycles = (op->dummy.nbytes * 8) / op->dummy.buswidth; > + } else { > + memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes); > + xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1; > + xfers[xferpos].len = op->dummy.nbytes; > + xfers[xferpos].tx_nbits = op->dummy.buswidth; > + spi_message_add_tail(&xfers[xferpos], &msg); > + xferpos++; > + totalxferlen += op->dummy.nbytes; > + } > } > > if (op->data.nbytes) { > diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h > index aa09fdc..2024149 100644 > --- a/include/linux/spi/spi.h > +++ b/include/linux/spi/spi.h > @@ -512,6 +512,8 @@ struct spi_controller { > > #define SPI_MASTER_GPIO_SS BIT(5) /* GPIO CS must select slave */ > > +#define SPI_MASTER_USES_HW_DUMMY_CYCLES BIT(6) /* HW dummy bytes transfer */ > + > /* flag indicating this is an SPI slave controller */ > bool slave; > > @@ -1022,6 +1024,12 @@ struct spi_message { > unsigned actual_length; > int status; > > + /* > + * dummy cycles in the message transfer. This is used by the controller > + * drivers supports transfer of dummy cycles directly by the hardware. > + */ > + u8 dummy_cycles; > + > /* for optional use by whatever driver currently owns the > * spi_message ... between calls to spi_async and then later > * complete(), that's the spi_controller controller driver.