From 1e23d73705f8f63a4d64581e2f6b144af24068b6 Mon Sep 17 00:00:00 2001 From: nbd Date: Tue, 17 Jul 2012 11:35:28 -0400 Subject: [PATCH 089/123] 401-mtd-physmap-add-lock-unlock Import of the above patch from openwrt trunk, as of this commit: ---------- commit c1d79f64eed0a7ac36b5b9bca52275b397bec424 Author: nbd Date: Mon Jul 16 16:26:51 2012 +0000 uboot-ar71xx: fix compile on recent mac os x versions git-svn-id: svn://svn.openwrt.org/openwrt/trunk@32750 3c298f89-4303-0410-b956-a3cf2f4a3e73 ---------- Path to patch in the repo is: target/linux/ar71xx/patches-3.3 Repo is: git://nbd.name/openwrt.git Signed-off-by: Paul Gortmaker --- drivers/mtd/maps/physmap.c | 67 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/physmap.h | 2 ++ 2 files changed, 69 insertions(+) diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 21b0b71..4828866 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c @@ -31,6 +31,66 @@ struct physmap_flash_info { int vpp_refcnt; }; +static struct platform_device *physmap_map2pdev(struct map_info *map) +{ + return (struct platform_device *) map->map_priv_1; +} + +static void physmap_lock(struct map_info *map) +{ + struct platform_device *pdev; + struct physmap_flash_data *physmap_data; + + pdev = physmap_map2pdev(map); + physmap_data = pdev->dev.platform_data; + physmap_data->lock(pdev); +} + +static void physmap_unlock(struct map_info *map) +{ + struct platform_device *pdev; + struct physmap_flash_data *physmap_data; + + pdev = physmap_map2pdev(map); + physmap_data = pdev->dev.platform_data; + physmap_data->unlock(pdev); +} + +static map_word physmap_flash_read_lock(struct map_info *map, unsigned long ofs) +{ + map_word ret; + + physmap_lock(map); + ret = inline_map_read(map, ofs); + physmap_unlock(map); + + return ret; +} + +static void physmap_flash_write_lock(struct map_info *map, map_word d, + unsigned long ofs) +{ + physmap_lock(map); + inline_map_write(map, d, ofs); + physmap_unlock(map); +} + +static void physmap_flash_copy_from_lock(struct map_info *map, void *to, + unsigned long from, ssize_t len) +{ + physmap_lock(map); + inline_map_copy_from(map, to, from, len); + physmap_unlock(map); +} + +static void physmap_flash_copy_to_lock(struct map_info *map, unsigned long to, + const void *from, ssize_t len) +{ + physmap_lock(map); + inline_map_copy_to(map, to, from, len); + physmap_unlock(map); +} + static int physmap_flash_remove(struct platform_device *dev) { struct physmap_flash_info *info; @@ -157,6 +217,13 @@ static int physmap_flash_probe(struct platform_device *dev) simple_map_init(&info->map[i]); + if (physmap_data->lock && physmap_data->unlock) { + info->map[i].read = physmap_flash_read_lock; + info->map[i].write = physmap_flash_write_lock; + info->map[i].copy_from = physmap_flash_copy_from_lock; + info->map[i].copy_to = physmap_flash_copy_to_lock; + } + probe_type = rom_probe_types; if (physmap_data->probe_type == NULL) { for (; info->mtd[i] == NULL && *probe_type != NULL; probe_type++) diff --git a/include/linux/mtd/physmap.h b/include/linux/mtd/physmap.h index d2887e7..0b1a3ac 100644 --- a/include/linux/mtd/physmap.h +++ b/include/linux/mtd/physmap.h @@ -25,6 +25,8 @@ struct physmap_flash_data { unsigned int width; int (*init)(struct platform_device *); void (*exit)(struct platform_device *); + void (*lock)(struct platform_device *); + void (*unlock)(struct platform_device *); void (*set_vpp)(struct platform_device *, int); unsigned int nr_parts; unsigned int pfow_base; -- 1.7.9.7