update flash locking code
authorGabor Juhos <juhosg@openwrt.org>
Sat, 6 Jun 2009 15:56:03 +0000 (15:56 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Sat, 6 Jun 2009 15:56:03 +0000 (15:56 +0000)
SVN-Revision: 16359

target/linux/ar71xx/files/arch/mips/ar71xx/ar71xx.c
target/linux/ar71xx/files/arch/mips/ar71xx/mach-ap83.c
target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/ar71xx.h
target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/platform.h
target/linux/ar71xx/files/drivers/mtd/maps/ar91xx_flash.c

index ea7ae143bd47a53ec46bb7f389caab44d70b5928..a13c928125951e59db4204a2b04c50adea821018 100644 (file)
@@ -17,7 +17,6 @@
 #include <asm/mach-ar71xx/ar71xx.h>
 
 static DEFINE_MUTEX(ar71xx_flash_mutex);
-static int ar71xx_flash_lock_enabled;
 
 void __iomem *ar71xx_ddr_base;
 EXPORT_SYMBOL_GPL(ar71xx_ddr_base);
@@ -102,21 +101,14 @@ void ar71xx_ddr_flush(u32 reg)
 }
 EXPORT_SYMBOL_GPL(ar71xx_ddr_flush);
 
-void  __init ar71xx_flash_lock_enable(void)
-{
-       ar71xx_flash_lock_enabled = 1;
-}
-
 void ar71xx_flash_acquire(void)
 {
-       if (ar71xx_flash_lock_enabled)
-               mutex_lock(&ar71xx_flash_mutex);
+       mutex_lock(&ar71xx_flash_mutex);
 }
 EXPORT_SYMBOL_GPL(ar71xx_flash_acquire);
 
 void ar71xx_flash_release(void)
 {
-       if (ar71xx_flash_lock_enabled)
-               mutex_unlock(&ar71xx_flash_mutex);
+       mutex_unlock(&ar71xx_flash_mutex);
 }
 EXPORT_SYMBOL_GPL(ar71xx_flash_release);
index c88f68a41fdfa47a77ce82d73e9618935ddd8315..8564b01a62796abc11df97e0e6d61220dd4f221d 100644 (file)
@@ -221,7 +221,7 @@ static void __init ap83_generic_setup(void)
 
 static void __init ap83_040_setup(void)
 {
-       ar71xx_flash_lock_enable();
+       ap83_flash_data.is_shared=1;
        ap83_generic_setup();
        platform_device_register(&ap83_040_spi_device);
 }
index 19a546e56e4bd1ab3d2acb17f34e2229b0c8a13f..51afcecb52ce879edec37eaa70e3a328ee1210da 100644 (file)
@@ -422,7 +422,6 @@ void ar71xx_device_start(u32 mask);
 #define SPI_IOC_CS2            SPI_IOC_CS(2)
 #define SPI_IOC_CS_ALL         (SPI_IOC_CS0 | SPI_IOC_CS1 | SPI_IOC_CS2)
 
-void ar71xx_flash_lock_enable(void) __init;
 void ar71xx_flash_acquire(void);
 void ar71xx_flash_release(void);
 
index b008abd8d384367dae2c87943c6c719454dcae31..5644fc956b23022ae3b304ce1cb1355d376a2dc3 100644 (file)
@@ -55,6 +55,7 @@ struct ar71xx_spi_platform_data {
 
 struct ar91xx_flash_platform_data {
        unsigned int            width;
+       u8                      is_shared:1;
 #ifdef CONFIG_MTD_PARTITIONS
        unsigned int            nr_parts;
        struct mtd_partition    *parts;
index e83a1477f03a244d09d6570fcd04e4713742ccd3..7ee831c12de639ec12c4d3f2efd0fe1f0d6c9a28 100644 (file)
@@ -60,6 +60,41 @@ static void ar91xx_flash_write(struct map_info *map, map_word d,
        mb();
 }
 
+static map_word ar91xx_flash_read_lock(struct map_info *map, unsigned long ofs)
+{
+       map_word ret;
+
+       ar71xx_flash_acquire();
+       ret = ar91xx_flash_read(map, ofs);
+       ar71xx_flash_release();
+
+       return ret;
+}
+
+static void ar91xx_flash_write_lock(struct map_info *map, map_word d,
+                              unsigned long ofs)
+{
+       ar71xx_flash_acquire();
+       ar91xx_flash_write(map, d, ofs);
+       ar71xx_flash_release();
+}
+
+static void ar91xx_flash_copy_from_lock(struct map_info *map, void *to,
+                                       unsigned long from, ssize_t len)
+{
+       ar71xx_flash_acquire();
+       inline_map_copy_from(map, to, from, len);
+       ar71xx_flash_release();
+}
+
+static void ar91xx_flash_copy_to_lock(struct map_info *map, unsigned long to,
+                                     const void *from, ssize_t len)
+{
+       ar71xx_flash_acquire();
+       inline_map_copy_to(map, to, from, len);
+       ar71xx_flash_release();
+}
+
 static int ar91xx_flash_remove(struct platform_device *pdev)
 {
        struct ar91xx_flash_platform_data *pdata;
@@ -152,8 +187,15 @@ static int ar91xx_flash_probe(struct platform_device *pdev)
        }
 
        simple_map_init(&info->map);
-       info->map.read = ar91xx_flash_read;
-       info->map.write = ar91xx_flash_write;
+       if (pdata->is_shared) {
+               info->map.read = ar91xx_flash_read_lock;
+               info->map.write = ar91xx_flash_write_lock;
+               info->map.copy_from = ar91xx_flash_copy_from_lock;
+               info->map.copy_to = ar91xx_flash_copy_to_lock;
+       } else {
+               info->map.read = ar91xx_flash_read;
+               info->map.write = ar91xx_flash_write;
+       }
 
        probe_type = rom_probe_types;
        for (; info->mtd == NULL && *probe_type != NULL; probe_type++)