Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4111473imm; Sat, 21 Jul 2018 10:23:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfrUBg/8efpJbeAyrC9DGE8rPOYJh4t71HcH5P69ICnW3R+EdiLWFAMXpnmcH/bDm+/fWIQ X-Received: by 2002:a65:448c:: with SMTP id l12-v6mr6065896pgq.277.1532193784710; Sat, 21 Jul 2018 10:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532193784; cv=none; d=google.com; s=arc-20160816; b=Aw1rySo5OxqRdi0NGS/hyfAHuRFa+MmDhaTAKF1DNaWj1xfXy/+tVSrykCqnwVFjfj u8DkSy2hnAZkhPnKkDCdxsCq5nymNkTDI+ZjV3tQi7KdbSS4KVE+iBNvfiMYS2jrAKmY 8w9inKeCaNPbY0WtnewTzhU8XqE/PM82YtiFRZpKubWeykM3ciZJ6XYsW4St9oLVlRRV 0x0Vhv/voIuQyCczIugvELo8Jbl7N4VHM9/3FUSJZXoHy9Z9jsalGL70gjbH5SJ4k54c uondL6U/4hqlt7vd0h5CybDTRpKevUg2YnXauo0hctGIe6sfeoF92mKigBvPfLUNVfA7 nSrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=yNAnQ6YeL5zXH6ZmPcDuDXfWW76L8B6jMrZQk0/Z1kM=; b=gKp5VsyrVGzGO+WC7rm0Q46wYZUjuHctYKNuzlRadPaJ+B7GwsXs5HSgP62I+3HgEZ 2AdrwW7ec2jrOvJnADy8twkyU4BURwd7jVF9eJe/hLZYsgm2oF2HLH4WeaUipjoXNJCM nplU1RbBrLP/leuAl39otTyKQ5y056ybIkTwGH6YB1ueKgKsbn/a5NyyrGkrKxWsojfL u5ciPzgVcy8LltNl6MQouiTy4E79eJeSFLwCULapH8wIKw9da+o7mB4pCLZyUShnSezc F3tXJStT/lhh4xMU1VewP5G8yqxs4eKK2RZCXQGsA/Re5tdEOHrsHYHjS31UCwyVuWdK JPDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v71-v6si4837075pfj.354.2018.07.21.10.22.49; Sat, 21 Jul 2018 10:23:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728144AbeGUSPJ (ORCPT + 99 others); Sat, 21 Jul 2018 14:15:09 -0400 Received: from mail.bootlin.com ([62.4.15.54]:49351 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727483AbeGUSPJ (ORCPT ); Sat, 21 Jul 2018 14:15:09 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id B19DC20737; Sat, 21 Jul 2018 19:21:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [37.173.79.60]) by mail.bootlin.com (Postfix) with ESMTPSA id 8ADDC207B4; Sat, 21 Jul 2018 19:21:24 +0200 (CEST) Date: Sat, 21 Jul 2018 19:21:01 +0200 From: Boris Brezillon To: Miquel Raynal Cc: Wenyou Yang , Josh Wu , Tudor Ambarus , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Nicolas Ferre , Alexandre Belloni , Kamal Dasu , Masahiro Yamada , Han Xu , Harvey Hunt , Vladimir Zapolskiy , Sylvain Lemieux , Xiaolei Li , Matthias Brugger , Maxime Ripard , Chen-Yu Tsai , Marc Gonzalez , Mans Rullgard , Stefan Agner , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-mediatek@lists.infradead.org Subject: Re: [PATCH v4 16/35] mtd: rawnand: nandsim: convert driver to nand_scan() Message-ID: <20180721192101.0e0d1860@bbrezillon> In-Reply-To: <20180720151527.16038-17-miquel.raynal@bootlin.com> References: <20180720151527.16038-1-miquel.raynal@bootlin.com> <20180720151527.16038-17-miquel.raynal@bootlin.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Jul 2018 17:15:08 +0200 Miquel Raynal wrote: > Two helpers have been added to the core to make ECC-related > configuration between the detection phase and the final NAND scan. Use > these hooks and convert the driver to just use nand_scan() instead of > both nand_scan_ident() and nand_scan_tail(). > > Signed-off-by: Miquel Raynal Reviewed-by: Boris Brezillon > --- > drivers/mtd/nand/raw/nandsim.c | 82 +++++++++++++++++++++++------------------- > 1 file changed, 45 insertions(+), 37 deletions(-) > > diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c > index 8a3b36cfe5ea..71ac034aee9c 100644 > --- a/drivers/mtd/nand/raw/nandsim.c > +++ b/drivers/mtd/nand/raw/nandsim.c > @@ -2192,6 +2192,48 @@ static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) > return; > } > > +static int ns_attach_chip(struct nand_chip *chip) > +{ > + unsigned int eccsteps, eccbytes; > + > + if (!bch) > + return 0; > + > + if (!mtd_nand_has_bch()) { > + NS_ERR("BCH ECC support is disabled\n"); > + return -EINVAL; > + } > + > + /* Use 512-byte ecc blocks */ > + eccsteps = nsmtd->writesize / 512; > + eccbytes = ((bch * 13) + 7) / 8; > + > + /* Do not bother supporting small page devices */ > + if (nsmtd->oobsize < 64 || !eccsteps) { > + NS_ERR("BCH not available on small page devices\n"); > + return -EINVAL; > + } > + > + if (((eccbytes * eccsteps) + 2) > nsmtd->oobsize) { > + NS_ERR("Invalid BCH value %u\n", bch); > + return -EINVAL; > + } > + > + chip->ecc.mode = NAND_ECC_SOFT; > + chip->ecc.algo = NAND_ECC_BCH; > + chip->ecc.size = 512; > + chip->ecc.strength = bch; > + chip->ecc.bytes = eccbytes; > + > + NS_INFO("Using %u-bit/%u bytes BCH ECC\n", bch, chip->ecc.size); > + > + return 0; > +} > + > +static const struct nand_controller_ops ns_controller_ops = { > + .attach_chip = ns_attach_chip, > +}; > + > /* > * Module initialization function > */ > @@ -2276,44 +2318,10 @@ static int __init ns_init_module(void) > if ((retval = parse_gravepages()) != 0) > goto error; > > - retval = nand_scan_ident(nsmtd, 1, NULL); > + chip->dummy_controller.ops = &ns_controller_ops; > + retval = nand_scan(nsmtd, 1); > if (retval) { > - NS_ERR("cannot scan NAND Simulator device\n"); > - goto error; > - } > - > - if (bch) { > - unsigned int eccsteps, eccbytes; > - if (!mtd_nand_has_bch()) { > - NS_ERR("BCH ECC support is disabled\n"); > - retval = -EINVAL; > - goto error; > - } > - /* use 512-byte ecc blocks */ > - eccsteps = nsmtd->writesize/512; > - eccbytes = (bch*13+7)/8; > - /* do not bother supporting small page devices */ > - if ((nsmtd->oobsize < 64) || !eccsteps) { > - NS_ERR("bch not available on small page devices\n"); > - retval = -EINVAL; > - goto error; > - } > - if ((eccbytes*eccsteps+2) > nsmtd->oobsize) { > - NS_ERR("invalid bch value %u\n", bch); > - retval = -EINVAL; > - goto error; > - } > - chip->ecc.mode = NAND_ECC_SOFT; > - chip->ecc.algo = NAND_ECC_BCH; > - chip->ecc.size = 512; > - chip->ecc.strength = bch; > - chip->ecc.bytes = eccbytes; > - NS_INFO("using %u-bit/%u bytes BCH ECC\n", bch, chip->ecc.size); > - } > - > - retval = nand_scan_tail(nsmtd); > - if (retval) { > - NS_ERR("can't register NAND Simulator\n"); > + NS_ERR("Could not scan NAND Simulator device\n"); > goto error; > } >