Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2992026imm; Fri, 20 Jul 2018 08:18:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe4AQ9Bp1B4XgYb6pL2OS6iiaUnbIAkp42a9AoYWr1dbFuIuShtXIrhzCB6/jDand/GiFct X-Received: by 2002:a65:665a:: with SMTP id z26-v6mr2427762pgv.193.1532099917259; Fri, 20 Jul 2018 08:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532099917; cv=none; d=google.com; s=arc-20160816; b=QreCV7rV/MyoWDgRWpV8x/mGu17NDnpilRBq9MTKK8sdWjLnR81Ja8Y02jrXlRCOiq tFfUAGBtMgv+OK8P0JZOkqZCrtgKp1INCiTGskf3Meqf2jp4ng/rcmryTxnX3DNIUoxw xjVVEWjkjgIbuxxf9nvNmG/WqroPwW+ltnUs7598ibzRxYwBVh5EJ7rcH2uH3PH/FuEp p6nod7OFqQmJHBh24YsT+mM73hqU6J7+foBOtd5vhsomnI4aISPJhIwuLQJiA3M3LqMN kWP+Ufd63MZfK6qcgzr3k4DpB+Vt0J76mWYVhncVSROQSRqs9nPpvRhI/KJxES9DMS56 vTSQ== 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=1ImII/OVurtg5RiNbEPTEKndmIsYjN69/4XFFSQfaFY=; b=0Q7u4pnEXsYNnH6GQkVfKe49klmthsY80julpvCPJOBZtSTqBfbzjVQth0OZ1HtSNr mPtrx/10EkJk5QP8avgh+HPeYOXm6Q4XTanUnURNJsjTnHjngOOvHIXBIIGNkdfb6ISm F9GpKetct9wxHwU3nECys6HQKYPJImlOaEnXTwcXR9vnV1rCe40Ykt8lsAzgv1EeRXft wrSEI1Sk1m1HfYa5Wr9OTLsGx4huJEfaSNfxxS2r5ImVYj6u8Mxsf5p0BeVyImnhtTjX 9R02r0I+1E02MQmxYR1qWVn7XIcwV/Ah6OhP8Ioh8OzmJzOrXtOYiov3rVtQqVOO+iwL X93w== 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 m141-v6si2026866pfd.310.2018.07.20.08.18.22; Fri, 20 Jul 2018 08:18:37 -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 S2388327AbeGTQF5 (ORCPT + 99 others); Fri, 20 Jul 2018 12:05:57 -0400 Received: from mail.bootlin.com ([62.4.15.54]:54570 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388101AbeGTQEr (ORCPT ); Fri, 20 Jul 2018 12:04:47 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 3F908209CF; Fri, 20 Jul 2018 17:16:01 +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 32169209C0; Fri, 20 Jul 2018 17:15:45 +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 29/35] mtd: rawnand: docg4: convert driver to nand_scan() Date: Fri, 20 Jul 2018 17:15:21 +0200 Message-Id: <20180720151527.16038-30-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/docg4.c | 55 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/drivers/mtd/nand/raw/docg4.c b/drivers/mtd/nand/raw/docg4.c index 4dccdfba6140..fec4353ff4ef 100644 --- a/drivers/mtd/nand/raw/docg4.c +++ b/drivers/mtd/nand/raw/docg4.c @@ -1227,10 +1227,9 @@ static void __init init_mtd_structs(struct mtd_info *mtd) * required within a nand driver because they are performed by the nand * infrastructure code as part of nand_scan(). In this case they need * to be initialized here because we skip call to nand_scan_ident() (the - * first half of nand_scan()). The call to nand_scan_ident() is skipped - * because for this device the chip id is not read in the manner of a - * standard nand device. Unfortunately, nand_scan_ident() does other - * things as well, such as call nand_set_defaults(). + * first half of nand_scan()). The call to nand_scan_ident() could be + * skipped because for this device the chip id is not read in the manner + * of a standard nand device. */ struct nand_chip *nand = mtd_to_nand(mtd); @@ -1315,6 +1314,27 @@ static int __init read_id_reg(struct mtd_info *mtd) static char const *part_probes[] = { "cmdlinepart", "saftlpart", NULL }; +static int docg4_attach_chip(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + struct docg4_priv *doc = (struct docg4_priv *)(chip + 1); + + init_mtd_structs(mtd); + + /* Initialize kernel BCH algorithm */ + doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY); + if (!doc->bch) + return -EINVAL; + + reset(mtd); + + return read_id_reg(mtd); +} + +static const struct nand_controller_ops docg4_controller_ops = { + .attach_chip = docg4_attach_chip, +}; + static int __init probe_docg4(struct platform_device *pdev) { struct mtd_info *mtd; @@ -1350,26 +1370,16 @@ static int __init probe_docg4(struct platform_device *pdev) mtd->dev.parent = &pdev->dev; doc->virtadr = virtadr; doc->dev = dev; - - init_mtd_structs(mtd); - - /* initialize kernel bch algorithm */ - doc->bch = init_bch(DOCG4_M, DOCG4_T, DOCG4_PRIMITIVE_POLY); - if (doc->bch == NULL) { - retval = -EINVAL; - goto free_nand; - } - platform_set_drvdata(pdev, doc); - reset(mtd); - retval = read_id_reg(mtd); - if (retval == -ENODEV) { - dev_warn(dev, "No diskonchip G4 device found.\n"); - goto free_bch; - } - - retval = nand_scan_tail(mtd); + /* + * Asking for 0 chips is useless here but it warns the user that the use + * of the nand_scan() function is a bit abused here because the + * initialization is actually a bit specific and re-handled again in the + * ->attach_chip() hook. It will probably leak some memory though. + */ + nand->dummy_controller.ops = &docg4_controller_ops; + retval = nand_scan(mtd, 0); if (retval) goto free_bch; @@ -1389,7 +1399,6 @@ static int __init probe_docg4(struct platform_device *pdev) nand_cleanup(nand); free_bch: free_bch(doc->bch); -free_nand: kfree(nand); unmap: iounmap(virtadr); -- 2.14.1