From patchwork Fri May 14 06:14:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 52550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 523B8B7E7C for ; Fri, 14 May 2010 16:15:58 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1OCoAI-000357-AO; Fri, 14 May 2010 06:14:30 +0000 Received: from mail-pz0-f198.google.com ([209.85.222.198]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1OCoAC-0002XM-2L; Fri, 14 May 2010 06:14:24 +0000 Received: by pzk36 with SMTP id 36so1399492pzk.24 for ; Thu, 13 May 2010 23:14:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=PfTvEBjKMNQav6rnpV84PKpZGMW3Q2mOwDZ1rO53WPE=; b=An+lleivWO3Rlof8OW06z9YOjjMHjtqRy/Y3wOhuaIUeAqybdUvxVjtoytbNaZyKQo qhNbqfZZQwori2bNyl5oeyqiNKsZ8sHnZzrl9wB7sAaNRbCJBmezq/qWgNt42UIgrDCB F9gaVr2zSXzFP/gnV9N8KMUq6l7rxHZe9NylM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=rlom0iPbC0HqzT5IYdgUOqN6v+mJeADxNwlgFtT3PJeEWcuDVd9KL8cJXxhyt10Goe zWENDOhQpJjRw3/Jh35+90gA7NNp4UDZO6Ea2dmSr+JvEHCmOU81l/VO5aXrCuDrlqrY S3iajg4/vLrvbWbqdAsJxJg8PgcqxOgaExKOQ= MIME-Version: 1.0 Received: by 10.142.1.29 with SMTP id 29mr370076wfa.337.1273817662826; Thu, 13 May 2010 23:14:22 -0700 (PDT) Received: by 10.142.252.16 with HTTP; Thu, 13 May 2010 23:14:22 -0700 (PDT) Date: Fri, 14 May 2010 14:14:22 +0800 Message-ID: Subject: [PATCH 04/20] mtd: pxa3xx_nand: make scan procedure more clear From: Haojian Zhuang To: Marc Kleine-Budde , David Woodhouse , David Woodhouse , Eric Miao , linux-arm-kernel , linux-mtd@lists.infradead.org X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100514_021424_325336_DF253853 X-CRM114-Status: GOOD ( 15.09 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.222.198 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is freemail (haojian.zhuang[at]gmail.com) -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From 3c64457df23b222c7f53b7d8f0601606b95b1ad6 Mon Sep 17 00:00:00 2001 From: Lei Wen Date: Mon, 22 Mar 2010 10:35:49 +0800 Subject: [PATCH] mtd: pxa3xx_nand: make scan procedure more clear Signed-off-by: Lei Wen Signed-off-by: Haojian Zhuang --- drivers/mtd/nand/pxa3xx_nand.c | 66 +++++++++++++++++++++++---------------- 1 files changed, 39 insertions(+), 27 deletions(-) info->clk = clk_get(&pdev->dev, NULL); @@ -1201,16 +1194,9 @@ static int __devinit pxa3xx_nand_probe(struct platform_device *pdev) } pxa3xx_nand_init_mtd(mtd, info); + platform_set_drvdata(pdev, info); - platform_set_drvdata(pdev, mtd); - - if (nand_scan(mtd, 1)) { - dev_err(&pdev->dev, "failed to scan nand\n"); - ret = -ENXIO; - goto fail_free_irq; - } - - return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts); + return 0; fail_free_irq: free_irq(irq, info); @@ -1235,8 +1221,8 @@ fail_free_mtd: static int pxa3xx_nand_remove(struct platform_device *pdev) { - struct mtd_info *mtd = platform_get_drvdata(pdev); - struct pxa3xx_nand_info *info = mtd->priv; + struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); + struct mtd_info *mtd = info->mtd; struct resource *r; int irq; @@ -1265,11 +1251,37 @@ static int pxa3xx_nand_remove(struct platform_device *pdev) return 0; } +static int __devinit pxa3xx_nand_probe(struct platform_device *pdev) +{ + struct pxa3xx_nand_platform_data *pdata; + struct pxa3xx_nand_info *info; + int ret; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "no platform data defined\n"); + return -ENODEV; + } + + ret = alloc_nand_resource(pdev); + if (ret) + return ret; + + info = platform_get_drvdata(pdev); + if (nand_scan(info->mtd, 1)) { + dev_err(&pdev->dev, "failed to scan nand\n"); + pxa3xx_nand_remove(pdev); + return -ENODEV; + } + + return add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); +} + #ifdef CONFIG_PM static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state) { - struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev); - struct pxa3xx_nand_info *info = mtd->priv; + struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); + struct mtd_info *mtd = info->mtd; if (info->state != STATE_READY) { dev_err(&pdev->dev, "driver busy, state = %d\n", info->state); @@ -1281,8 +1293,8 @@ static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state) static int pxa3xx_nand_resume(struct platform_device *pdev) { - struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev); - struct pxa3xx_nand_info *info = mtd->priv; + struct pxa3xx_nand_info *info = platform_get_drvdata(pdev); + struct mtd_info *mtd = info->mtd; nand_writel(info, NDTR0CS0, info->ndtr0cs0); nand_writel(info, NDTR1CS0, info->ndtr1cs0); diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 2dfe6d9..0ef9bf9 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c @@ -160,6 +160,7 @@ struct pxa3xx_nand_info { unsigned int buf_start; unsigned int buf_count; + struct mtd_info *mtd; /* DMA information */ int drcmr_dat; int drcmr_cmd; @@ -1096,21 +1097,13 @@ static void pxa3xx_nand_init_mtd(struct mtd_info *mtd, this->chip_delay = 25; } -static int __devinit pxa3xx_nand_probe(struct platform_device *pdev) +static int alloc_nand_resource(struct platform_device *pdev) { - struct pxa3xx_nand_platform_data *pdata; + struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data; struct pxa3xx_nand_info *info; - struct nand_chip *this; struct mtd_info *mtd; struct resource *r; - int ret = 0, irq; - - pdata = pdev->dev.platform_data; - - if (!pdata) { - dev_err(&pdev->dev, "no platform data defined\n"); - return -ENODEV; - } + int ret, irq; mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct pxa3xx_nand_info), GFP_KERNEL); @@ -1122,8 +1115,8 @@ static int __devinit pxa3xx_nand_probe(struct platform_device *pdev) info = (struct pxa3xx_nand_info *)(&mtd[1]); info->pdev = pdev; - this = &info->nand_chip; mtd->priv = info; + info->mtd = mtd; mtd->owner = THIS_MODULE;