Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4649214imm; Sun, 22 Jul 2018 02:30:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe2hu9hO7zxvwwftXBnDuPirWz8AgXSRjoPe15M8mNdFFN/A/7qwKeEw79I0+f+ZxR8knIr X-Received: by 2002:a62:3703:: with SMTP id e3-v6mr8828379pfa.117.1532251838179; Sun, 22 Jul 2018 02:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532251838; cv=none; d=google.com; s=arc-20160816; b=dA0z5GzgDKmCMpdLxZZ7ic4K62nQ2T9/AKyuKSo3d0hpCBLxesMHE5vCw0Xj1ucKle QtOz/c+r4SvOyo/jW02Xr+61UY0i2OSqL3qldSxR1glks/l4HQk6TCs5xFWhbRE3aVfA RqstbT5qRSIJm+oDkxR+LI0Ls5Fs1OX1JQqs/21lXyQ9poTcwghxiRlzxpVU5uhGfDZp kJ+opCxnK78mV2j3uimKtJjw4WfEY0YBaC3pAmFbkBRN1MEMhkQ7tPXzMEut7adtmkqY wP8MHNJQJN0QhHgDklAvL6qkfgs0zAO5grylOsGwIuk/1vtG16EtbLGoh/FHi4k+B7TZ VWcQ== 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=mUegj0nyMGruYpRKfG5cH9UOwft0Ts+WTiw2bslw1Gk=; b=UFltalnR7kMY1nPKXgvVg9+Rfu1gXCU/AQovkOhcTlnRYWxQVBbrd6NrtwBLkTSS// SVf01lA9nMjzoKhuTwG9IV8iwfZ76jURYWNuzh4fLMXmo2SF8KbigjpYh+mWQSC8SR5p FygdWHJoUKL1/yvxFmWGaFylSQ766aRdfpZSzAKz6pKrmeLdef1y5gn++H6pO7oPNCME HaX/CZ+ROKWqfaOjLq123CbrSZP5RE0u2wpdRq3n9WHkuBRLVKG+EGhOplEt+jfU7p67 PWGpbPBM9KNXbnIDyqgFJ+OTj4faks6PagmBhFpBIMJkjVOb0R9iffzN18KxZx2BHJmi VfPw== 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 f67-v6si5980707plb.460.2018.07.22.02.30.23; Sun, 22 Jul 2018 02:30:38 -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 S1728363AbeGVKZj (ORCPT + 99 others); Sun, 22 Jul 2018 06:25:39 -0400 Received: from mail.bootlin.com ([62.4.15.54]:59592 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728022AbeGVKZj (ORCPT ); Sun, 22 Jul 2018 06:25:39 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 4199A20737; Sun, 22 Jul 2018 11:29:33 +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 shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [37.173.49.123]) by mail.bootlin.com (Postfix) with ESMTPSA id 3E91B20737; Sun, 22 Jul 2018 11:29:31 +0200 (CEST) Date: Sun, 22 Jul 2018 11:29:30 +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 31/35] mtd: rawnand: jz4740: convert driver to nand_scan() Message-ID: <20180722112930.5d62c3e9@bbrezillon> In-Reply-To: <20180720151527.16038-32-miquel.raynal@bootlin.com> References: <20180720151527.16038-1-miquel.raynal@bootlin.com> <20180720151527.16038-32-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:23 +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 > --- > drivers/mtd/nand/raw/jz4740_nand.c | 46 ++++++++++++++++++++++++-------------- > 1 file changed, 29 insertions(+), 17 deletions(-) > > diff --git a/drivers/mtd/nand/raw/jz4740_nand.c b/drivers/mtd/nand/raw/jz4740_nand.c > index 9bb8a89e09f9..8f821fdf8a1c 100644 > --- a/drivers/mtd/nand/raw/jz4740_nand.c > +++ b/drivers/mtd/nand/raw/jz4740_nand.c > @@ -59,6 +59,7 @@ > > struct jz_nand { > struct nand_chip chip; > + struct platform_device *pdev; You don't need this field. You can just do to_platform_device(mtd->dev.parent) to get the platform_device. > void __iomem *base; > struct resource *mem; > > @@ -329,8 +330,8 @@ static int jz_nand_detect_bank(struct platform_device *pdev, > writel(ctrl, nand->base + JZ_REG_NAND_CTRL); > > if (chipnr == 0) { > - /* Detect first chip. */ > - ret = nand_scan_ident(mtd, 1, NULL); > + /* Detect the first chip and register it */ > + ret = nand_scan(mtd, 1); > if (ret) > goto notfound_id; > > @@ -367,6 +368,25 @@ static int jz_nand_detect_bank(struct platform_device *pdev, > return ret; > } > > +static int jz_nand_attach_chip(struct nand_chip *chip) > +{ > + struct mtd_info *mtd = nand_to_mtd(chip); > + struct jz_nand *nand = mtd_to_jz_nand(mtd); > + struct device *dev = mtd->dev.parent; > + struct jz_nand_platform_data *pdata = dev_get_platdata(dev); > + > + if (pdata && pdata->ident_callback) { > + pdata->ident_callback(nand->pdev, mtd, &pdata->partitions, > + &pdata->num_partitions); > + } Curly braces are not needed. > + > + return 0; > +} > + > +static const struct nand_controller_ops jz_nand_controller_ops = { > + .attach_chip = jz_nand_attach_chip, > +}; > + > static int jz_nand_probe(struct platform_device *pdev) > { > int ret; > @@ -397,6 +417,7 @@ static int jz_nand_probe(struct platform_device *pdev) > mtd = nand_to_mtd(chip); > mtd->dev.parent = &pdev->dev; > mtd->name = "jz4740-nand"; > + nand->pdev = pdev; > > chip->ecc.hwctl = jz_nand_hwctl; > chip->ecc.calculate = jz_nand_calculate_ecc_rs; > @@ -410,6 +431,7 @@ static int jz_nand_probe(struct platform_device *pdev) > chip->chip_delay = 50; > chip->cmd_ctrl = jz_nand_cmd_ctrl; > chip->select_chip = jz_nand_select_chip; > + chip->dummy_controller.ops = &jz_nand_controller_ops; > > if (nand->busy_gpio) > chip->dev_ready = jz_nand_dev_ready; > @@ -450,20 +472,10 @@ static int jz_nand_probe(struct platform_device *pdev) > else > nand->banks[chipnr] = 0; > } > + > if (chipnr == 0) { > dev_err(&pdev->dev, "No NAND chips found\n"); > - goto err_iounmap_mmio; > - } > - > - if (pdata && pdata->ident_callback) { > - pdata->ident_callback(pdev, mtd, &pdata->partitions, > - &pdata->num_partitions); > - } > - > - ret = nand_scan_tail(mtd); > - if (ret) { > - dev_err(&pdev->dev, "Failed to scan NAND\n"); > - goto err_unclaim_banks; > + goto err_nand_release; > } As for the atmel driver, I'd prefer to have one patch to moves nand_scan_ident() and nand_scan_tail() in the same function so that the transition to nand_scan()+attach_chip is easier to review. > > ret = mtd_device_register(mtd, pdata ? pdata->partitions : NULL, > @@ -471,15 +483,13 @@ static int jz_nand_probe(struct platform_device *pdev) > > if (ret) { > dev_err(&pdev->dev, "Failed to add mtd device\n"); > - goto err_nand_release; > + goto err_unclaim_banks; > } > > dev_info(&pdev->dev, "Successfully registered JZ4740 NAND driver\n"); > > return 0; > > -err_nand_release: > - nand_release(mtd); > err_unclaim_banks: > while (chipnr--) { > unsigned char bank = nand->banks[chipnr]; > @@ -487,6 +497,8 @@ static int jz_nand_probe(struct platform_device *pdev) > nand->bank_base[bank - 1]); > } > writel(0, nand->base + JZ_REG_NAND_CTRL); > +err_nand_release: > + nand_release(mtd); > err_iounmap_mmio: > jz_nand_iounmap_resource(nand->mem, nand->base); > err_free: