Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4551522imm; Sat, 21 Jul 2018 23:42:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf2kddvHAG75r8uOFVMZDJUDddANUFECOovX9a2akZTL/SB/ilFuF8qMIADReU//gz+gDcY X-Received: by 2002:a17:902:46e:: with SMTP id 101-v6mr8262373ple.39.1532241741880; Sat, 21 Jul 2018 23:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532241741; cv=none; d=google.com; s=arc-20160816; b=gkrq5kC8Q8wDRnfm6q1eFN4qzLJy5xZ2pjbd55U9JlHUudl2J7u7OkAjcCue3o8vhK 1LhgO0O58hsTRoYaIjEPnrbJr2pd4HyClIuSEJa0O2dz3R4UPnI0upyLjl/FHS8243oC NuL61NZIOWlYMZxaPKyLkQAZbhVoHCuRFNCsqZWQA0vbH+JFO5NT6qSUFf0K4X+LARwE D/XWk6xAM/xI5ypoYa/03x49ey9Jnr/sKVLIBlaq5lxA5G6xvwMoJ9bk2agkwft9GdA8 m4KrkijHchQD+iRxn8TwBR2vd19RTO78Bt9kegPUOWyNC03oaYUrf+Z0BAFxr+zq1HBj VFkA== 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=feLREJgwltw4mcFaH0WTIusuSvP7ep0v5ggcD4jsp88=; b=S7qmNjZGxWL1nIfJVoSk9JXJlGSh/0OmxjDCf7xVi2ZFQdvu8x5/AWgWXIQJjrfT7Y /1KRoNY0jwQDMsnK8ELnmFcFvxF1rwPDU1uheqK+dgfZRrw0DlGydeyKJBKcMc/vDp8K 9c8XaYXH/lBui0G5bJP9oRUDZ2QeqVs/zBLw/J2YRLDnxw/11zG+wgg8e5TcYrn/5+Nd 3hOVHUzlLNT0CQgGbCs78hIqP6acpn/8o+lzigjavQom6qDTcjNAYL7WBkbTDZuEz8p5 x8jyUaoylds14B0m64bQ9MMDjyKprQQJiMWbFHtXKT/zKiHGe2W9w2ufovLx7DdP6YW9 Vlcw== 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 g80-v6si5893725pfk.53.2018.07.21.23.42.06; Sat, 21 Jul 2018 23:42:21 -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 S1728008AbeGVHgo (ORCPT + 99 others); Sun, 22 Jul 2018 03:36:44 -0400 Received: from mail.bootlin.com ([62.4.15.54]:57973 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727768AbeGVHgo (ORCPT ); Sun, 22 Jul 2018 03:36:44 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 5565F209BC; Sun, 22 Jul 2018 08:41:06 +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.105.99]) by mail.bootlin.com (Postfix) with ESMTPSA id 4CDDD2097A; Sun, 22 Jul 2018 08:40:08 +0200 (CEST) Date: Sun, 22 Jul 2018 08:40:06 +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 26/35] mtd: rawnand: atmel: convert driver to nand_scan() Message-ID: <20180722084006.513e0e45@bbrezillon> In-Reply-To: <20180720151527.16038-27-miquel.raynal@bootlin.com> References: <20180720151527.16038-1-miquel.raynal@bootlin.com> <20180720151527.16038-27-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:18 +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/atmel/nand-controller.c | 83 ++++++++++++++-------------- > 1 file changed, 40 insertions(+), 43 deletions(-) > > diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c > index 855cc7729c43..0bc7e2abc885 100644 > --- a/drivers/mtd/nand/raw/atmel/nand-controller.c > +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c > @@ -202,7 +202,7 @@ struct atmel_nand_controller_ops { > int (*remove)(struct atmel_nand_controller *nc); > void (*nand_init)(struct atmel_nand_controller *nc, > struct atmel_nand *nand); > - int (*ecc_init)(struct atmel_nand *nand); > + int (*ecc_init)(struct nand_chip *chip); > int (*setup_data_interface)(struct atmel_nand *nand, int csline, > const struct nand_data_interface *conf); > }; > @@ -1133,9 +1133,8 @@ static int atmel_nand_pmecc_init(struct nand_chip *chip) > return 0; > } > > -static int atmel_nand_ecc_init(struct atmel_nand *nand) > +static int atmel_nand_ecc_init(struct nand_chip *chip) > { > - struct nand_chip *chip = &nand->base; > struct atmel_nand_controller *nc; > int ret; > > @@ -1170,12 +1169,11 @@ static int atmel_nand_ecc_init(struct atmel_nand *nand) > return 0; > } > > -static int atmel_hsmc_nand_ecc_init(struct atmel_nand *nand) > +static int atmel_hsmc_nand_ecc_init(struct nand_chip *chip) > { > - struct nand_chip *chip = &nand->base; > int ret; > > - ret = atmel_nand_ecc_init(nand); > + ret = atmel_nand_ecc_init(chip); > if (ret) > return ret; > > @@ -1558,22 +1556,6 @@ static void atmel_hsmc_nand_init(struct atmel_nand_controller *nc, > chip->select_chip = atmel_hsmc_nand_select_chip; > } > > -static int atmel_nand_detect(struct atmel_nand *nand) > -{ > - struct nand_chip *chip = &nand->base; > - struct mtd_info *mtd = nand_to_mtd(chip); > - struct atmel_nand_controller *nc; > - int ret; > - > - nc = to_nand_controller(chip->controller); > - > - ret = nand_scan_ident(mtd, nand->numcs, NULL); > - if (ret) > - dev_err(nc->dev, "nand_scan_ident() failed: %d\n", ret); > - > - return ret; > -} > - > static int atmel_nand_unregister(struct atmel_nand *nand) > { > struct nand_chip *chip = &nand->base; > @@ -1595,7 +1577,6 @@ static int atmel_nand_register(struct atmel_nand *nand) > struct nand_chip *chip = &nand->base; > struct mtd_info *mtd = nand_to_mtd(chip); > struct atmel_nand_controller *nc; > - int ret; > > nc = to_nand_controller(chip->controller); > > @@ -1626,21 +1607,6 @@ static int atmel_nand_register(struct atmel_nand *nand) > } > } > > - ret = nand_scan_tail(mtd); > - if (ret) { > - dev_err(nc->dev, "nand_scan_tail() failed: %d\n", ret); > - return ret; > - } > - > - ret = mtd_device_register(mtd, NULL, 0); > - if (ret) { > - dev_err(nc->dev, "Failed to register mtd device: %d\n", ret); > - nand_cleanup(chip); > - return ret; > - } > - > - list_add_tail(&nand->node, &nc->chips); > - You can move all the code in atmel_nand_register() directly in atmel_nand_controller_add_nand() + rename atmel_nand_unregister() into atmel_nand_controller_remove_nand(). This should be done in a separate patch so that the transition to nand_scan() is easier to review. > return 0; > } > > @@ -1755,6 +1721,8 @@ static int > atmel_nand_controller_add_nand(struct atmel_nand_controller *nc, > struct atmel_nand *nand) > { > + struct nand_chip *chip = &nand->base; > + struct mtd_info *mtd = nand_to_mtd(chip); > int ret; > > /* No card inserted, skip this NAND. */ > @@ -1765,15 +1733,30 @@ atmel_nand_controller_add_nand(struct atmel_nand_controller *nc, > > nc->caps->ops->nand_init(nc, nand); > > - ret = atmel_nand_detect(nand); > - if (ret) > + ret = nand_scan(mtd, nand->numcs); > + if (ret) { > + dev_err(nc->dev, "NAND scan failed: %d\n", ret); > return ret; > + } > > - ret = nc->caps->ops->ecc_init(nand); > + ret = atmel_nand_register(nand); > if (ret) > - return ret; > + goto cleanup_nand; > + > + ret = mtd_device_register(mtd, NULL, 0); > + if (ret) { > + dev_err(nc->dev, "Failed to register mtd device: %d\n", ret); > + goto cleanup_nand; > + } > + > + list_add_tail(&nand->node, &nc->chips); > + > + return 0; > + > +cleanup_nand: > + nand_cleanup(chip); > > - return atmel_nand_register(nand); > + return ret; > } > > static int > @@ -1958,6 +1941,19 @@ static const struct of_device_id atmel_matrix_of_ids[] = { > { /* sentinel */ }, > }; > > +static int atmel_nand_attach_chip(struct nand_chip *chip) > +{ > + struct atmel_nand_controller *nc; > + > + nc = to_nand_controller(chip->controller); > + > + return nc->caps->ops->ecc_init(chip); > +} > + > +static const struct nand_controller_ops atmel_nand_controller_ops = { > + .attach_chip = atmel_nand_attach_chip, > +}; > + > static int atmel_nand_controller_init(struct atmel_nand_controller *nc, > struct platform_device *pdev, > const struct atmel_nand_controller_caps *caps) > @@ -1967,6 +1963,7 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc, > int ret; > > nand_controller_init(&nc->base); > + nc->base.ops = &atmel_nand_controller_ops; > INIT_LIST_HEAD(&nc->chips); > nc->dev = dev; > nc->caps = caps;