From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19AB4C433E0 for ; Wed, 24 Mar 2021 08:05:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D84C461A06 for ; Wed, 24 Mar 2021 08:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbhCXIFL (ORCPT ); Wed, 24 Mar 2021 04:05:11 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:48412 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbhCXIEt (ORCPT ); Wed, 24 Mar 2021 04:04:49 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 12O84T2N043735; Wed, 24 Mar 2021 03:04:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1616573069; bh=6H1aesmlYIQY1gMDqIA98xvXLO/tQxyI/+0fx/1If18=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=iWMQE982gdUcdheAQLJxDlHjxAv1ou2IO0quK9du4FH4OMxiWlf+HRSLXmObjPPbn FHVEltI4d4Bbi0ivBZqC9dv5Jpo7bLeF3q9BRtNDdy9U+pEajljPDXQ56zSY+ARuAO Urug7YBC0vC0p5a2fjE69YmlBamXW0lehW8Jzmik= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 12O84TAi014287 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 24 Mar 2021 03:04:29 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 24 Mar 2021 03:04:29 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Wed, 24 Mar 2021 03:04:29 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 12O84S16050686; Wed, 24 Mar 2021 03:04:28 -0500 Date: Wed, 24 Mar 2021 13:34:27 +0530 From: Pratyush Yadav To: Michael Walle CC: Nishanth Menon , Tero Kristo , Rob Herring , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mark Brown , , , , , , Lokesh Vutla Subject: Re: [RFC PATCH 2/6] mtd: spi-nor: core: consolidate read op creation Message-ID: <20210324080425.c4ospw4p6w7lrjok@ti.com> References: <20210311191216.7363-1-p.yadav@ti.com> <20210311191216.7363-3-p.yadav@ti.com> <77a4d73b65bd371e93538886038f1acb@walle.cc> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <77a4d73b65bd371e93538886038f1acb@walle.cc> User-Agent: NeoMutt/20171215 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/03/21 12:17AM, Michael Walle wrote: > Am 2021-03-11 20:12, schrieb Pratyush Yadav: > > Currently the spi_mem_op to read from the flash is used in two places: > > spi_nor_create_read_dirmap() and spi_nor_spimem_read_data(). In a later > > commit this number will increase to three. Instead of repeating the same > > code thrice, add a function that returns a template of the read op. The > > callers can then fill in the details like address, data length, data > > buffer location. > > > > Signed-off-by: Pratyush Yadav > > --- > > drivers/mtd/spi-nor/core.c | 62 ++++++++++++++++++++------------------ > > 1 file changed, 32 insertions(+), 30 deletions(-) > > > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > > index 4a315cb1c4db..88888df009f0 100644 > > --- a/drivers/mtd/spi-nor/core.c > > +++ b/drivers/mtd/spi-nor/core.c > > @@ -183,6 +183,33 @@ static int spi_nor_controller_ops_erase(struct > > spi_nor *nor, loff_t offs) > > return nor->controller_ops->erase(nor, offs); > > } > > > > +/** > > + * spi_nor_spimem_get_read_op() - return a template for the spi_mem_op > > used for > > + * reading data from the flash via > > spi-mem. > > + * @nor: pointer to 'struct spi_nor' > > + * > > + * Return: A template of the 'struct spi_mem_op' for used for reading > > data from > > + * the flash. The caller is expected to fill in the address, data > > length, and > > + * the data buffer. > > + */ > > +static struct spi_mem_op spi_nor_spimem_get_read_op(struct spi_nor > > *nor) > > +{ > > + struct spi_mem_op op = > > + SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > + SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), > > + SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > + SPI_MEM_OP_DATA_IN(1, NULL, 0)); > > + > > + spi_nor_spimem_setup_op(nor, &op, nor->read_proto); > > + > > + /* convert the dummy cycles to the number of bytes */ > > + op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > + if (spi_nor_protocol_is_dtr(nor->read_proto)) > > + op.dummy.nbytes *= 2; > > + > > + return op; > > +} > > + > > /** > > * spi_nor_spimem_read_data() - read data from flash's memory region > > via > > * spi-mem > > @@ -196,21 +223,14 @@ static int spi_nor_controller_ops_erase(struct > > spi_nor *nor, loff_t offs) > > static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t > > from, > > size_t len, u8 *buf) > > { > > - struct spi_mem_op op = > > - SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > - SPI_MEM_OP_ADDR(nor->addr_width, from, 0), > > - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > - SPI_MEM_OP_DATA_IN(len, buf, 0)); > > + struct spi_mem_op op = spi_nor_spimem_get_read_op(nor); > > bool usebouncebuf; > > ssize_t nbytes; > > int error; > > > > - spi_nor_spimem_setup_op(nor, &op, nor->read_proto); > > - > > - /* convert the dummy cycles to the number of bytes */ > > - op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > - if (spi_nor_protocol_is_dtr(nor->read_proto)) > > - op.dummy.nbytes *= 2; > > + op.addr.val = from; > > + op.data.nbytes = len; > > + op.data.buf.in = buf; > > > > usebouncebuf = spi_nor_spimem_bounce(nor, &op); > > > > @@ -3581,28 +3601,10 @@ EXPORT_SYMBOL_GPL(spi_nor_scan); > > static int spi_nor_create_read_dirmap(struct spi_nor *nor) > > { > > struct spi_mem_dirmap_info info = { > > - .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > - SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), > > - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > - SPI_MEM_OP_DATA_IN(0, NULL, 0)), > > + .op_tmpl = spi_nor_spimem_get_read_op(nor), > > .offset = 0, > > .length = nor->mtd.size, > > }; > > - struct spi_mem_op *op = &info.op_tmpl; > > - > > - spi_nor_spimem_setup_op(nor, op, nor->read_proto); > > - > > - /* convert the dummy cycles to the number of bytes */ > > - op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8; > > - if (spi_nor_protocol_is_dtr(nor->read_proto)) > > - op->dummy.nbytes *= 2; > > - > > - /* > > - * Since spi_nor_spimem_setup_op() only sets buswidth when the number > > - * of data bytes is non-zero, the data buswidth won't be set here. So, > > - * do it explicitly. > > - */ > > - op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); > > I guess this isn't needed anymore because spi_nor_spimem_get_read_op() uses > a > data length of 1, right? Yes. > > > > > nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, > > &info); > > -michael -- Regards, Pratyush Yadav Texas Instruments Inc. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3019EC433C1 for ; Wed, 24 Mar 2021 08:06:16 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA32C619F6 for ; Wed, 24 Mar 2021 08:06:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA32C619F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=h9faYkmlbJchFIHpOc51T/Imz7Q6zzFVVlNckuX6b0U=; b=asyW48h8Yfe2CWsEJ17g+9R6J cKOGnrgSuuH+sR50KAxL8w7kKaJ+zzOhiA7qVz5bDoG0or2Qhl6SMscIA+6jsdyO5ejStBhgmbjX0 v3jGbblv1QZ2AkgWMADmbeFnvBKlBBz57J5nzFX8oEDcCGWNYCN48dBvc4T0vFsKWhwZuVmBeRa+4 zafOc8TAJUNIvcHFMOHN34QCyy3K7ZGywdVgwPZUhFz5zdXYigFWICUjWmWA827eV518V7Tyetu4F xG4uVp6nXQdlqrMMJPCdRx5IB+YdYF6OcuaSEWKVgCZyZkRyx9hZLWt0g2LSa+5k7qLBlvkI03ZzO dgrx2p7Ag==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lOyVO-00GXDo-T0; Wed, 24 Mar 2021 08:04:43 +0000 Received: from fllv0015.ext.ti.com ([198.47.19.141]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lOyVH-00GXCn-Ee; Wed, 24 Mar 2021 08:04:38 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 12O84T2N043735; Wed, 24 Mar 2021 03:04:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1616573069; bh=6H1aesmlYIQY1gMDqIA98xvXLO/tQxyI/+0fx/1If18=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=iWMQE982gdUcdheAQLJxDlHjxAv1ou2IO0quK9du4FH4OMxiWlf+HRSLXmObjPPbn FHVEltI4d4Bbi0ivBZqC9dv5Jpo7bLeF3q9BRtNDdy9U+pEajljPDXQ56zSY+ARuAO Urug7YBC0vC0p5a2fjE69YmlBamXW0lehW8Jzmik= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 12O84TAi014287 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 24 Mar 2021 03:04:29 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 24 Mar 2021 03:04:29 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Wed, 24 Mar 2021 03:04:29 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 12O84S16050686; Wed, 24 Mar 2021 03:04:28 -0500 Date: Wed, 24 Mar 2021 13:34:27 +0530 From: Pratyush Yadav To: Michael Walle CC: Nishanth Menon , Tero Kristo , Rob Herring , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mark Brown , , , , , , Lokesh Vutla Subject: Re: [RFC PATCH 2/6] mtd: spi-nor: core: consolidate read op creation Message-ID: <20210324080425.c4ospw4p6w7lrjok@ti.com> References: <20210311191216.7363-1-p.yadav@ti.com> <20210311191216.7363-3-p.yadav@ti.com> <77a4d73b65bd371e93538886038f1acb@walle.cc> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <77a4d73b65bd371e93538886038f1acb@walle.cc> User-Agent: NeoMutt/20171215 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210324_080436_557182_CAD11264 X-CRM114-Status: GOOD ( 29.82 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org On 24/03/21 12:17AM, Michael Walle wrote: > Am 2021-03-11 20:12, schrieb Pratyush Yadav: > > Currently the spi_mem_op to read from the flash is used in two places: > > spi_nor_create_read_dirmap() and spi_nor_spimem_read_data(). In a later > > commit this number will increase to three. Instead of repeating the same > > code thrice, add a function that returns a template of the read op. The > > callers can then fill in the details like address, data length, data > > buffer location. > > > > Signed-off-by: Pratyush Yadav > > --- > > drivers/mtd/spi-nor/core.c | 62 ++++++++++++++++++++------------------ > > 1 file changed, 32 insertions(+), 30 deletions(-) > > > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > > index 4a315cb1c4db..88888df009f0 100644 > > --- a/drivers/mtd/spi-nor/core.c > > +++ b/drivers/mtd/spi-nor/core.c > > @@ -183,6 +183,33 @@ static int spi_nor_controller_ops_erase(struct > > spi_nor *nor, loff_t offs) > > return nor->controller_ops->erase(nor, offs); > > } > > > > +/** > > + * spi_nor_spimem_get_read_op() - return a template for the spi_mem_op > > used for > > + * reading data from the flash via > > spi-mem. > > + * @nor: pointer to 'struct spi_nor' > > + * > > + * Return: A template of the 'struct spi_mem_op' for used for reading > > data from > > + * the flash. The caller is expected to fill in the address, data > > length, and > > + * the data buffer. > > + */ > > +static struct spi_mem_op spi_nor_spimem_get_read_op(struct spi_nor > > *nor) > > +{ > > + struct spi_mem_op op = > > + SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > + SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), > > + SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > + SPI_MEM_OP_DATA_IN(1, NULL, 0)); > > + > > + spi_nor_spimem_setup_op(nor, &op, nor->read_proto); > > + > > + /* convert the dummy cycles to the number of bytes */ > > + op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > + if (spi_nor_protocol_is_dtr(nor->read_proto)) > > + op.dummy.nbytes *= 2; > > + > > + return op; > > +} > > + > > /** > > * spi_nor_spimem_read_data() - read data from flash's memory region > > via > > * spi-mem > > @@ -196,21 +223,14 @@ static int spi_nor_controller_ops_erase(struct > > spi_nor *nor, loff_t offs) > > static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t > > from, > > size_t len, u8 *buf) > > { > > - struct spi_mem_op op = > > - SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > - SPI_MEM_OP_ADDR(nor->addr_width, from, 0), > > - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > - SPI_MEM_OP_DATA_IN(len, buf, 0)); > > + struct spi_mem_op op = spi_nor_spimem_get_read_op(nor); > > bool usebouncebuf; > > ssize_t nbytes; > > int error; > > > > - spi_nor_spimem_setup_op(nor, &op, nor->read_proto); > > - > > - /* convert the dummy cycles to the number of bytes */ > > - op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > - if (spi_nor_protocol_is_dtr(nor->read_proto)) > > - op.dummy.nbytes *= 2; > > + op.addr.val = from; > > + op.data.nbytes = len; > > + op.data.buf.in = buf; > > > > usebouncebuf = spi_nor_spimem_bounce(nor, &op); > > > > @@ -3581,28 +3601,10 @@ EXPORT_SYMBOL_GPL(spi_nor_scan); > > static int spi_nor_create_read_dirmap(struct spi_nor *nor) > > { > > struct spi_mem_dirmap_info info = { > > - .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > - SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), > > - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > - SPI_MEM_OP_DATA_IN(0, NULL, 0)), > > + .op_tmpl = spi_nor_spimem_get_read_op(nor), > > .offset = 0, > > .length = nor->mtd.size, > > }; > > - struct spi_mem_op *op = &info.op_tmpl; > > - > > - spi_nor_spimem_setup_op(nor, op, nor->read_proto); > > - > > - /* convert the dummy cycles to the number of bytes */ > > - op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8; > > - if (spi_nor_protocol_is_dtr(nor->read_proto)) > > - op->dummy.nbytes *= 2; > > - > > - /* > > - * Since spi_nor_spimem_setup_op() only sets buswidth when the number > > - * of data bytes is non-zero, the data buswidth won't be set here. So, > > - * do it explicitly. > > - */ > > - op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); > > I guess this isn't needed anymore because spi_nor_spimem_get_read_op() uses > a > data length of 1, right? Yes. > > > > > nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, > > &info); > > -michael -- Regards, Pratyush Yadav Texas Instruments Inc. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B0C2C433DB for ; Wed, 24 Mar 2021 08:06:48 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 011AB619FB for ; Wed, 24 Mar 2021 08:06:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 011AB619FB Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vdcwwP9fLlDYIRihc9njm/0782afcIVIE+/Yr8H2zhY=; b=lQE9LyAraqVvaUbRdbRbu/JYT K0h0IbXKmmKQ5qWnMi8FCqLbBOHWPBSRdmitTCz7Vwou//gi5kAFdEc0J6Q9du8hqwvD1ZDyQXO/v TlqrVWfZ+SZXmCCfT4vyH9xfKllCHqfe+KC356gS22BAKkBGtttPgXA/Dd875tQNVNi6rlzVOZAqW /XNviYVfhf9/Kct4Pn459a342eAnlo0mW+Ban5LGPzfkTthp4efTX/5rZSrJOFHHn4p4YguKUUHUf gcNC6M76ha2RHV73dHR6priNXz7RAqJArmcn0M3MDN1VX4qRooUMl//+wEw3CsI1pXlrZHliO+CgX oS6vdP0LQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lOyVa-00GXEx-1R; Wed, 24 Mar 2021 08:04:54 +0000 Received: from fllv0015.ext.ti.com ([198.47.19.141]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lOyVH-00GXCn-Ee; Wed, 24 Mar 2021 08:04:38 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 12O84T2N043735; Wed, 24 Mar 2021 03:04:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1616573069; bh=6H1aesmlYIQY1gMDqIA98xvXLO/tQxyI/+0fx/1If18=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=iWMQE982gdUcdheAQLJxDlHjxAv1ou2IO0quK9du4FH4OMxiWlf+HRSLXmObjPPbn FHVEltI4d4Bbi0ivBZqC9dv5Jpo7bLeF3q9BRtNDdy9U+pEajljPDXQ56zSY+ARuAO Urug7YBC0vC0p5a2fjE69YmlBamXW0lehW8Jzmik= Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 12O84TAi014287 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 24 Mar 2021 03:04:29 -0500 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 24 Mar 2021 03:04:29 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Wed, 24 Mar 2021 03:04:29 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 12O84S16050686; Wed, 24 Mar 2021 03:04:28 -0500 Date: Wed, 24 Mar 2021 13:34:27 +0530 From: Pratyush Yadav To: Michael Walle CC: Nishanth Menon , Tero Kristo , Rob Herring , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mark Brown , , , , , , Lokesh Vutla Subject: Re: [RFC PATCH 2/6] mtd: spi-nor: core: consolidate read op creation Message-ID: <20210324080425.c4ospw4p6w7lrjok@ti.com> References: <20210311191216.7363-1-p.yadav@ti.com> <20210311191216.7363-3-p.yadav@ti.com> <77a4d73b65bd371e93538886038f1acb@walle.cc> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <77a4d73b65bd371e93538886038f1acb@walle.cc> User-Agent: NeoMutt/20171215 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210324_080436_557182_CAD11264 X-CRM114-Status: GOOD ( 29.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 24/03/21 12:17AM, Michael Walle wrote: > Am 2021-03-11 20:12, schrieb Pratyush Yadav: > > Currently the spi_mem_op to read from the flash is used in two places: > > spi_nor_create_read_dirmap() and spi_nor_spimem_read_data(). In a later > > commit this number will increase to three. Instead of repeating the same > > code thrice, add a function that returns a template of the read op. The > > callers can then fill in the details like address, data length, data > > buffer location. > > > > Signed-off-by: Pratyush Yadav > > --- > > drivers/mtd/spi-nor/core.c | 62 ++++++++++++++++++++------------------ > > 1 file changed, 32 insertions(+), 30 deletions(-) > > > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > > index 4a315cb1c4db..88888df009f0 100644 > > --- a/drivers/mtd/spi-nor/core.c > > +++ b/drivers/mtd/spi-nor/core.c > > @@ -183,6 +183,33 @@ static int spi_nor_controller_ops_erase(struct > > spi_nor *nor, loff_t offs) > > return nor->controller_ops->erase(nor, offs); > > } > > > > +/** > > + * spi_nor_spimem_get_read_op() - return a template for the spi_mem_op > > used for > > + * reading data from the flash via > > spi-mem. > > + * @nor: pointer to 'struct spi_nor' > > + * > > + * Return: A template of the 'struct spi_mem_op' for used for reading > > data from > > + * the flash. The caller is expected to fill in the address, data > > length, and > > + * the data buffer. > > + */ > > +static struct spi_mem_op spi_nor_spimem_get_read_op(struct spi_nor > > *nor) > > +{ > > + struct spi_mem_op op = > > + SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > + SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), > > + SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > + SPI_MEM_OP_DATA_IN(1, NULL, 0)); > > + > > + spi_nor_spimem_setup_op(nor, &op, nor->read_proto); > > + > > + /* convert the dummy cycles to the number of bytes */ > > + op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > + if (spi_nor_protocol_is_dtr(nor->read_proto)) > > + op.dummy.nbytes *= 2; > > + > > + return op; > > +} > > + > > /** > > * spi_nor_spimem_read_data() - read data from flash's memory region > > via > > * spi-mem > > @@ -196,21 +223,14 @@ static int spi_nor_controller_ops_erase(struct > > spi_nor *nor, loff_t offs) > > static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t > > from, > > size_t len, u8 *buf) > > { > > - struct spi_mem_op op = > > - SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > - SPI_MEM_OP_ADDR(nor->addr_width, from, 0), > > - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > - SPI_MEM_OP_DATA_IN(len, buf, 0)); > > + struct spi_mem_op op = spi_nor_spimem_get_read_op(nor); > > bool usebouncebuf; > > ssize_t nbytes; > > int error; > > > > - spi_nor_spimem_setup_op(nor, &op, nor->read_proto); > > - > > - /* convert the dummy cycles to the number of bytes */ > > - op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; > > - if (spi_nor_protocol_is_dtr(nor->read_proto)) > > - op.dummy.nbytes *= 2; > > + op.addr.val = from; > > + op.data.nbytes = len; > > + op.data.buf.in = buf; > > > > usebouncebuf = spi_nor_spimem_bounce(nor, &op); > > > > @@ -3581,28 +3601,10 @@ EXPORT_SYMBOL_GPL(spi_nor_scan); > > static int spi_nor_create_read_dirmap(struct spi_nor *nor) > > { > > struct spi_mem_dirmap_info info = { > > - .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), > > - SPI_MEM_OP_ADDR(nor->addr_width, 0, 0), > > - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), > > - SPI_MEM_OP_DATA_IN(0, NULL, 0)), > > + .op_tmpl = spi_nor_spimem_get_read_op(nor), > > .offset = 0, > > .length = nor->mtd.size, > > }; > > - struct spi_mem_op *op = &info.op_tmpl; > > - > > - spi_nor_spimem_setup_op(nor, op, nor->read_proto); > > - > > - /* convert the dummy cycles to the number of bytes */ > > - op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8; > > - if (spi_nor_protocol_is_dtr(nor->read_proto)) > > - op->dummy.nbytes *= 2; > > - > > - /* > > - * Since spi_nor_spimem_setup_op() only sets buswidth when the number > > - * of data bytes is non-zero, the data buswidth won't be set here. So, > > - * do it explicitly. > > - */ > > - op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); > > I guess this isn't needed anymore because spi_nor_spimem_get_read_op() uses > a > data length of 1, right? Yes. > > > > > nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, > > &info); > > -michael -- Regards, Pratyush Yadav Texas Instruments Inc. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel