Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2991378imm; Fri, 20 Jul 2018 08:17:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeyTijC+LIOTlfkwNC4cBBKJN3iIYeko7hTF0TPXM2LYK7Dfnn/WOa95OxDqRQ3lqGTwx4h X-Received: by 2002:a65:620b:: with SMTP id d11-v6mr2493884pgv.429.1532099879615; Fri, 20 Jul 2018 08:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532099879; cv=none; d=google.com; s=arc-20160816; b=CFop+XEZ2rzSvyUzGhMtUsvD1pOPDQtoB+Qt+25jdHVm1/sqn1ocim7INZr6sg1Sny GIvhvsnsAYur4yECFK/IAGOSxLb5t668mSf/XS9igi8JWDcQkzovQ3nYx1Yqfa7JnqCD Pv+sIAJZ/v3GVzulxJTX7QYrXxU7t6ydUn832UW5e6P8ivTVog3XRNVYVxjZrBCGwzJE WMZXDFmQK15AIMa+CWGR/aGJnpylVEh2gJvHNO/WuBEqMqp5CXjGIseN+tpd/GhhNDni bOlFqjArsHlR2Hp3+qhcTSvMulDiOXsMiiuPloi31jlCS07cyiZkCliPA75TNe0Pu3Ue R02A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=fbAEeduPiXC56WwagHtDuWNIzj02ltCFI28gaDd/IZk=; b=X8Gqp1QYQ6Cu/6DEYEUjfaNpRY2VSa8LU0tcADF2EI/c0YhNw4LZoDXd9wIKvOU87F NH6g86bH8KhPGCbi7k7fHfAEEUB4CuAqJyEZpV07X9AkK4wLMob9NCrdPsllfIPOhuid 9QUs7N5TvZkezqLtAVWGZEIg9E7GdxERWtzSZtY+NLpVyjQBMTEZ2ZtQ96hN3rPxeW7D Swu+ETY5cqm2ezbimMKCCWbDuO93KLzGQ1Oxt3worQDLYMyjM7Agy4lQf6IYMRSipzLu JWd1igSyYjiYmjACRNPHe4190VP4Ihfybx9F68ZArdDhlPHiLoe4a7g2vvP7VosUV1UO cPvQ== 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 m37-v6si1886644plg.340.2018.07.20.08.17.44; Fri, 20 Jul 2018 08:17:59 -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 S2388171AbeGTQEt (ORCPT + 99 others); Fri, 20 Jul 2018 12:04:49 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54542 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388059AbeGTQEr (ORCPT ); Fri, 20 Jul 2018 12:04:47 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 8B0FC209A2; Fri, 20 Jul 2018 17:16:00 +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 localhost.localdomain (AAubervilliers-681-1-78-122.w90-88.abo.wanadoo.fr [90.88.20.122]) by mail.bootlin.com (Postfix) with ESMTPSA id 782D1209B7; Fri, 20 Jul 2018 17:15:43 +0200 (CEST) From: Miquel Raynal To: Wenyou Yang , Josh Wu , Tudor Ambarus , Boris Brezillon , Miquel Raynal , 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 Cc: 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: [PATCH v4 26/35] mtd: rawnand: atmel: convert driver to nand_scan() Date: Fri, 20 Jul 2018 17:15:18 +0200 Message-Id: <20180720151527.16038-27-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180720151527.16038-1-miquel.raynal@bootlin.com> References: <20180720151527.16038-1-miquel.raynal@bootlin.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); - 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; -- 2.14.1