Skip to content

Commit 876fe76

Browse files
lostdistanceDavid Woodhouse
authored andcommitted
mtd: maps: physmap: Add reference counter to set_vpp()
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 <lost.distance@yahoo.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent e7d9377 commit 876fe76

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎arch/arm/mach-omap1/flash.c‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@
1515

1616
void omap1_set_vpp(struct platform_device *pdev, int enable)
1717
{
18-
static int count;
1918
u32 l;
2019

21-
if (enable) {
22-
if (count++ == 0) {
23-
l = omap_readl(EMIFS_CONFIG);
24-
l |= OMAP_EMIFS_CONFIG_WP;
25-
omap_writel(l, EMIFS_CONFIG);
26-
}
27-
} else {
28-
if (count && (--count == 0)) {
29-
l = omap_readl(EMIFS_CONFIG);
30-
l &= ~OMAP_EMIFS_CONFIG_WP;
31-
omap_writel(l, EMIFS_CONFIG);
32-
}
33-
}
20+
l = omap_readl(EMIFS_CONFIG);
21+
if (enable)
22+
l |= OMAP_EMIFS_CONFIG_WP;
23+
else
24+
l &= ~OMAP_EMIFS_CONFIG_WP;
25+
omap_writel(l, EMIFS_CONFIG);
3426
}

‎arch/arm/mach-s3c2410/nor-simtec.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
static void simtec_nor_vpp(struct platform_device *pdev, int vpp)
3636
{
3737
unsigned int val;
38-
unsigned long flags;
3938

40-
local_irq_save(flags);
4139
val = __raw_readb(BAST_VA_CTRL3);
4240

4341
printk(KERN_DEBUG "%s(%d)\n", __func__, vpp);
@@ -48,7 +46,6 @@ static void simtec_nor_vpp(struct platform_device *pdev, int vpp)
4846
val &= ~BAST_CPLD_CTRL3_ROMWEN;
4947

5048
__raw_writeb(val, BAST_VA_CTRL3);
51-
local_irq_restore(flags);
5249
}
5350

5451
static struct physmap_flash_data simtec_nor_pdata = {

‎drivers/mtd/maps/physmap.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct physmap_flash_info {
2727
struct mtd_info *mtd[MAX_RESOURCES];
2828
struct mtd_info *cmtd;
2929
struct map_info map[MAX_RESOURCES];
30+
spinlock_t vpp_lock;
31+
int vpp_refcnt;
3032
};
3133

3234
static int physmap_flash_remove(struct platform_device *dev)
@@ -63,12 +65,26 @@ static void physmap_set_vpp(struct map_info *map, int state)
6365
{
6466
struct platform_device *pdev;
6567
struct physmap_flash_data *physmap_data;
68+
struct physmap_flash_info *info;
69+
unsigned long flags;
6670

6771
pdev = (struct platform_device *)map->map_priv_1;
6872
physmap_data = pdev->dev.platform_data;
6973

70-
if (physmap_data->set_vpp)
71-
physmap_data->set_vpp(pdev, state);
74+
if (!physmap_data->set_vpp)
75+
return;
76+
77+
info = platform_get_drvdata(pdev);
78+
79+
spin_lock_irqsave(&info->vpp_lock, flags);
80+
if (state) {
81+
if (++info->vpp_refcnt == 1) /* first nested 'on' */
82+
physmap_data->set_vpp(pdev, 1);
83+
} else {
84+
if (--info->vpp_refcnt == 0) /* last nested 'off' */
85+
physmap_data->set_vpp(pdev, 0);
86+
}
87+
spin_unlock_irqrestore(&info->vpp_lock, flags);
7288
}
7389

7490
static const char *rom_probe_types[] = {
@@ -172,6 +188,8 @@ static int physmap_flash_probe(struct platform_device *dev)
172188
if (err)
173189
goto err_out;
174190

191+
spin_lock_init(&info->vpp_lock);
192+
175193
part_types = physmap_data->part_probe_types ? : part_probe_types;
176194

177195
mtd_device_parse_register(info->cmtd, part_types, 0,

0 commit comments

Comments
 (0)