From patchwork Wed Mar 7 14:12:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Parsons X-Patchwork-Id: 145285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6B30FB6F98 for ; Thu, 8 Mar 2012 01:13:44 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1S5HbB-0000Eb-Pl; Wed, 07 Mar 2012 14:12:13 +0000 Received: from nm8.bullet.mail.ird.yahoo.com ([77.238.189.23]) by merlin.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1S5Hb8-0000DP-Nf for linux-mtd@lists.infradead.org; Wed, 07 Mar 2012 14:12:11 +0000 Received: from [77.238.189.52] by nm8.bullet.mail.ird.yahoo.com with NNFMP; 07 Mar 2012 14:12:09 -0000 Received: from [212.82.108.112] by tm5.bullet.mail.ird.yahoo.com with NNFMP; 07 Mar 2012 14:12:09 -0000 Received: from [127.0.0.1] by omp1021.mail.ird.yahoo.com with NNFMP; 07 Mar 2012 14:12:09 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 421467.27461.bm@omp1021.mail.ird.yahoo.com Received: (qmail 39356 invoked by uid 60001); 7 Mar 2012 14:12:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1331129528; bh=brRGDK5Yk4VlZWcUwXTYH8A/OppZuozx2o22y32/+aU=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding; b=cpI8PSpyZ1vjWuAmMMnVWmfcR4CUvg42qc/wlP57SFvTESLZBXj5L8JLTTJlo03arRiWDblRdcSjV2CYeE7+EBg1gNG/hlCDYoW5VSpfjLKTUCkMEcCsOpNKz2nk+P+3QSVUg5K259tVrpzDm+16aSQoIZC7bVNCSiBsf/8IyBQ= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding; b=JxDLZl9x0eNwdglGEHzNIp2PPBlOx8aVTw9OySRiQm7mO1MkNnhq+daSATYEd+kMiU2SVDnmy6Wh10HPVwhiZiohZ/rD7SkfnGKYAfIhByv4wUcyeoPoGCmXLNAlyojiTm4epO/8KmdTZ1CLgtICEn9VvK/UrG6up9mf450lr0o=; X-YMail-OSG: u_USI_MVM1kcJ3CCBf_Ee05dkA599YjP9rOvhPSuvsv0A_Y t_s_nzRTQCsD.KC.NAQJpmjUkkGQLxgXELBdobjXPtNXK6o66QHoeAoyv90. ixngtj0wtQ1NhWbfOm6qvpZaT3p4qx0.eKKycnSm0czcq6mn63LAZfZxd_ez tc.ADZyrBgnpvEzyUMWib7UEccVPnJaq92P3pC.JzHDvyKO.hJZcYFj3oB7i 8ZCdMEyXH0r.9ADUkNvwD6WR1dGO.zA4Py2jxmkzmfz3it8xLWu6XjunJq9f SuLlclHex5wBufUOt9hahSATZxMaHjteGjEQB.tNhbMM3.8kLOYoOYk8A14H UYrg2xgeOfiuHkYShO6zNObNL.EVt.xBPJBSlu0XFGqdttF1zqOJ1b4kUes3 TdFyVltZjp5SKci9XghM6Z2icxOrnvQ5G5Ys.PFzXqiD8xMpT3ntccZ..2Xm WR.6PBn4- Received: from [31.185.155.94] by web29009.mail.ird.yahoo.com via HTTP; Wed, 07 Mar 2012 14:12:08 GMT X-Mailer: YahooMailClassic/15.0.5 YahooMailWebService/0.8.116.338427 Message-ID: <1331129528.38705.YahooMailClassic@web29009.mail.ird.yahoo.com> Date: Wed, 7 Mar 2012 14:12:08 +0000 (GMT) From: Paul Parsons Subject: [PATCH 3/6] mtd: maps: physmap: Add reference counter to set_vpp() To: linux-mtd@lists.infradead.org MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lost.distance[at]yahoo.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [77.238.189.23 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 Cc: dwmw2@infradead.org, joakim.tjernlund@transmode.se, philipp.zabel@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 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 This patch is part of a set which fixes unnecessary flash erase and write errors resulting from the MTD CFI driver turning off vpp while an erase is in progress. This patch allows physmap_set_vpp() calls to be nested by adding a reference counter. omap1_set_vpp() already used a reference counter. Since it is called from physmap_set_vpp(), omap1_set_vpp() can now be simplified. simtec_nor_vpp() already disabled hard interrupts. Since it is called from physmap_set_vpp(), simtec_nor_vpp() can now be simplified. Signed-off-by: Paul Parsons diff -uprN clean-3.3-rc6/arch/arm/mach-omap1/flash.c linux-3.3-rc6/arch/arm/mach-omap1/flash.c --- clean-3.3-rc6/arch/arm/mach-omap1/flash.c 2012-03-04 01:08:09.000000000 +0000 +++ linux-3.3-rc6/arch/arm/mach-omap1/flash.c 2012-03-06 16:38:29.787134295 +0000 @@ -15,20 +15,12 @@ void omap1_set_vpp(struct platform_device *pdev, int enable) { - static int count; u32 l; - if (enable) { - if (count++ == 0) { - l = omap_readl(EMIFS_CONFIG); - l |= OMAP_EMIFS_CONFIG_WP; - omap_writel(l, EMIFS_CONFIG); - } - } else { - if (count && (--count == 0)) { - l = omap_readl(EMIFS_CONFIG); - l &= ~OMAP_EMIFS_CONFIG_WP; - omap_writel(l, EMIFS_CONFIG); - } - } + l = omap_readl(EMIFS_CONFIG); + if (enable) + l |= OMAP_EMIFS_CONFIG_WP; + else + l &= ~OMAP_EMIFS_CONFIG_WP; + omap_writel(l, EMIFS_CONFIG); } diff -uprN clean-3.3-rc6/arch/arm/mach-s3c2410/nor-simtec.c linux-3.3-rc6/arch/arm/mach-s3c2410/nor-simtec.c --- clean-3.3-rc6/arch/arm/mach-s3c2410/nor-simtec.c 2012-03-04 01:08:09.000000000 +0000 +++ linux-3.3-rc6/arch/arm/mach-s3c2410/nor-simtec.c 2012-03-06 16:38:29.787134295 +0000 @@ -35,9 +35,7 @@ static void simtec_nor_vpp(struct platform_device *pdev, int vpp) { unsigned int val; - unsigned long flags; - local_irq_save(flags); val = __raw_readb(BAST_VA_CTRL3); printk(KERN_DEBUG "%s(%d)\n", __func__, vpp); @@ -48,7 +46,6 @@ static void simtec_nor_vpp(struct platfo val &= ~BAST_CPLD_CTRL3_ROMWEN; __raw_writeb(val, BAST_VA_CTRL3); - local_irq_restore(flags); } static struct physmap_flash_data simtec_nor_pdata = { diff -uprN clean-3.3-rc6/drivers/mtd/maps/physmap.c linux-3.3-rc6/drivers/mtd/maps/physmap.c --- clean-3.3-rc6/drivers/mtd/maps/physmap.c 2012-03-04 01:08:09.000000000 +0000 +++ linux-3.3-rc6/drivers/mtd/maps/physmap.c 2012-03-06 16:38:29.795134347 +0000 @@ -27,6 +27,8 @@ struct physmap_flash_info { struct mtd_info *mtd[MAX_RESOURCES]; struct mtd_info *cmtd; struct map_info map[MAX_RESOURCES]; + spinlock_t vpp_lock; + int vpp_refcnt; }; static int physmap_flash_remove(struct platform_device *dev) @@ -63,12 +65,26 @@ static void physmap_set_vpp(struct map_i { struct platform_device *pdev; struct physmap_flash_data *physmap_data; + struct physmap_flash_info *info; + unsigned long flags; pdev = (struct platform_device *)map->map_priv_1; physmap_data = pdev->dev.platform_data; - if (physmap_data->set_vpp) - physmap_data->set_vpp(pdev, state); + if (!physmap_data->set_vpp) + return; + + info = platform_get_drvdata(pdev); + + spin_lock_irqsave(&info->vpp_lock, flags); + if (state) { + if (++info->vpp_refcnt == 1) /* first nested 'on' */ + physmap_data->set_vpp(pdev, 1); + } else { + if (--info->vpp_refcnt == 0) /* last nested 'off' */ + physmap_data->set_vpp(pdev, 0); + } + spin_unlock_irqrestore(&info->vpp_lock, flags); } static const char *rom_probe_types[] = { @@ -172,6 +188,8 @@ static int physmap_flash_probe(struct pl if (err) goto err_out; + spin_lock_init(&info->vpp_lock); + part_types = physmap_data->part_probe_types ? : part_probe_types; mtd_device_parse_register(info->cmtd, part_types, 0,