From patchwork Tue Jul 3 22:00:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10505565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3AE2260225 for ; Tue, 3 Jul 2018 23:22:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29823286E1 for ; Tue, 3 Jul 2018 23:22:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C92F28BAA; Tue, 3 Jul 2018 23:22:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BB166286E1 for ; Tue, 3 Jul 2018 23:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=jwBrgDw3U7rd7JTA+X+5WXAb4almZGpfqBgIFRbW48A=; b=JZnQ0pEfiaPg0+nyN4X/shFgGH KjOSE0h2gm2AuSAKzwICAwHZvRN+bRNJ+q9F6P57omqYsGM+QGzwAxFYQTeDEL7fhKKxU69TssuHy 7sSFAI6ua5byVtKSyfRjy++BtrUrIsCyTKKsW9Dt7t2vMu+1M4VL1Kr3y44kKdA+fUUyxOGxui6bJ O6+7Sy9GAVe+h7QlwxMdNnNnIS1XXUKdmu90v03PQeVk0PxYDWrkQtcQLvBXTnzxH/XJuq8qZQuDv yfkbMxrSocMt4UF+TumgEMVQasOgecdCiSmzLLBe0A8lrFNCz0iZ5XKNp8dZj5JVhYUnUZXTpHQjZ sDJo55RA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1faUdJ-0004Zw-Ux; Tue, 03 Jul 2018 23:22:53 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1faUMa-0008Gg-He; Tue, 03 Jul 2018 23:05:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=eXyitexx1R9knD4dOw6V6c0s60n2Dub20/o5C4+Qqf8=; b=h+TvOy11BOEuPOeHdgY2SM3NI W4UgQnw4fek77uUHijrlXkGnkpzbxDuv7uGhp7MnY3EA22See2aRgQ+KXl2A8mqPa0y1amrtBhiZo 8Q3j+qQ0Kz1X4Mh/C+tK3rWQxibKbOVdK5Zmk0p23/+aqDuwNfBz1CsN/pMK8xC98zLKupSvkGoU+ Y3tt7BExRXVO7Z0tkuF8N6crR2iVxLSfjMB6M+TeMxgratvmy1+ppSVpcQfEUKfmgO9y/8AR0IsWl f5RpSKlrA8vx0t02U7kRc645wFlsGM29Of4ujQouItm+CGgOKghpf9x4rkozXrSvkd0wMY1QosNvV mPttnO9TQ==; Received: from mail.bootlin.com ([62.4.15.54]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1faTMX-0007OQ-Oc; Tue, 03 Jul 2018 22:01:31 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 5A130208EF; Wed, 4 Jul 2018 00:01:22 +0200 (CEST) Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id E6609207DA; Wed, 4 Jul 2018 00:01:20 +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 Subject: [PATCH v2 28/32] mtd: rawnand: docg4: convert driver to nand_scan() Date: Wed, 4 Jul 2018 00:00:25 +0200 Message-Id: <20180703220029.19565-29-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703220029.19565-1-miquel.raynal@bootlin.com> References: <20180703220029.19565-1-miquel.raynal@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180703_180130_094094_5E80EAC4 X-CRM114-Status: GOOD ( 19.11 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bcm-kernel-feedback-list@broadcom.com, linux-mediatek@lists.infradead.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 51 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/drivers/mtd/nand/raw/docg4.c b/drivers/mtd/nand/raw/docg4.c index bb96cb33cd6b..50954c74e960 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,23 @@ 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 int __init probe_docg4(struct platform_device *pdev) { struct mtd_info *mtd; @@ -1350,26 +1366,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->controller->attach_chip = docg4_attach_chip; + retval = nand_scan(mtd, 0); if (retval) goto free_bch; @@ -1389,7 +1395,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);