I have new e-mail address. Thanks to Kaloz ;)
[openwrt.git] / target / linux / adm5120-2.6 / files / drivers / mtd / maps / adm5120-flash.c
index a60e6e5..0a2590e 100644 (file)
@@ -4,7 +4,7 @@
  *  Platform driver for NOR flash devices on ADM5120 based boards
  *
  *  Copyright (C) 2007 OpenWrt.org
- *  Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
+ *  Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
  *
  *  This file was derived from: drivers/mtd/map/physmap.c
  *     Copyright (C) 2003 MontaVista Software Inc.
 #define DRV_DESC       "ADM5120 flash MAP driver"
 #define MAX_PARSED_PARTS 8
 
-#define MAP_DBG(m, f, a...)    printk(KERN_DEBUG "%s: " f, (m->name) , ## a)
+#ifdef ADM5120_FLASH_DEBUG
+#define MAP_DBG(m, f, a...)    printk(KERN_INFO "%s: " f, (m->name) , ## a)
+#else
+#define MAP_DBG(m, f, a...)    do {} while (0)
+#endif
 #define MAP_ERR(m, f, a...)    printk(KERN_ERR "%s: " f, (m->name) , ## a)
 #define MAP_INFO(m, f, a...)   printk(KERN_INFO "%s: " f, (m->name) , ## a)
 
 struct adm5120_map_info {
        struct map_info map;
        void            (*switch_bank)(unsigned);
-       unsigned long   chip_size;
+       unsigned long   window_size;
 };
 
 struct adm5120_flash_info {
@@ -145,7 +149,7 @@ static void adm5120_flash_switchbank(struct map_info *map,
        if (bank > 1)
                BUG();
 
-       MAP_DBG(map, "ofs=%lu, switching to bank %u\n", ofs, bank);
+       MAP_DBG(map, "switching to bank %u, ofs=%lX\n", bank, ofs);
        amap->switch_bank(bank);
 }
 
@@ -154,14 +158,14 @@ static map_word adm5120_flash_read(struct map_info *map, unsigned long ofs)
        struct adm5120_map_info *amap = map_to_amap(map);
        map_word ret;
 
-       MAP_DBG(map, "reading from ofs %lu\n", ofs);
+       MAP_DBG(map, "reading from ofs %lX\n", ofs);
 
-       if (ofs >= amap->chip_size)
+       if (ofs >= amap->window_size)
                return map_word_ff(map);
 
        FLASH_LOCK();
        adm5120_flash_switchbank(map, ofs);
-       ret = inline_map_read(map, (ofs & BANK_OFFS_MASK));
+       ret = inline_map_read(map, (ofs & (amap->window_size-1)));
        FLASH_UNLOCK();
 
        return ret;
@@ -172,14 +176,14 @@ static void adm5120_flash_write(struct map_info *map, const map_word datum,
 {
        struct adm5120_map_info *amap = map_to_amap(map);
 
-       MAP_DBG(map,"writing to ofs %lu\n", ofs);
+       MAP_DBG(map,"writing to ofs %lX\n", ofs);
 
-       if (ofs > amap->chip_size)
+       if (ofs > amap->window_size)
                return;
 
        FLASH_LOCK();
        adm5120_flash_switchbank(map, ofs);
-       inline_map_write(map, datum, (ofs & BANK_OFFS_MASK));
+       inline_map_write(map, datum, (ofs & (amap->window_size-1)));
        FLASH_UNLOCK();
 }
 
@@ -190,26 +194,24 @@ static void adm5120_flash_copy_from(struct map_info *map, void *to,
        char *p;
        ssize_t t;
 
-       MAP_DBG(map, "copying %lu byte(s) from %lu to %lX\n",
-               (unsigned long)len, from, (unsigned long)to);
+       MAP_DBG(map, "copy_from, to=%lX, from=%lX, len=%lX\n",
+               (unsigned long)to, from, (unsigned long)len);
 
-       if (from > amap->chip_size)
+       if (from > amap->window_size)
                return;
 
        p = (char *)to;
        while (len > 0) {
-               if (len > BANK_SIZE - (from & BANK_OFFS_MASK))
-                       t = BANK_SIZE - (from & BANK_OFFS_MASK);
-               else
-                       t = len;
-
-               MAP_DBG(map, "copying %lu byte(s) from %lu to %lX\n",
-                       (unsigned long)t, (from & BANK_OFFS_MASK),
-                       (unsigned long)p);
+               t = len;
+               if ((from < BANK_SIZE) && ((from+len) > BANK_SIZE))
+                       t = BANK_SIZE-from;
 
                FLASH_LOCK();
+               MAP_DBG(map, "copying %lu byte(s) from %lX to %lX\n",
+                       (unsigned long)t, (from & (amap->window_size-1)),
+                       (unsigned long)p);
                adm5120_flash_switchbank(map, from);
-               inline_map_copy_from(map, to, (from & BANK_OFFS_MASK), t);
+               inline_map_copy_from(map, p, (from & (amap->window_size-1)), t);
                FLASH_UNLOCK();
                p += t;
                from += t;
@@ -265,8 +267,8 @@ static int adm5120_flash_initinfo(struct adm5120_flash_info *info,
        /* get memory window size */
        t = SWITCH_READ(SWITCH_REG_MEMCTRL) >> fdesc->srs_shift;
        t &= MEMCTRL_SRS_MASK;
-       info->amap.chip_size = flash_sizes[t];
-       if (info->amap.chip_size == 0) {
+       info->amap.window_size = flash_sizes[t];
+       if (info->amap.window_size == 0) {
                MAP_ERR(map, "invalid flash size detected\n");
                goto err_out;
        }
@@ -296,7 +298,7 @@ static int adm5120_flash_initinfo(struct adm5120_flash_info *info,
 
        MAP_INFO(map, "probing at 0x%lX, size:%ldKiB, width:%d bits\n",
                (unsigned long)map->phys,
-               (unsigned long)info->amap.chip_size >> 10,
+               (unsigned long)info->amap.window_size >> 10,
                map->bankwidth*8);
 
        return 0;
@@ -314,7 +316,7 @@ static void adm5120_flash_initbanks(struct adm5120_flash_info *info)
                return;
 
        if (info->amap.switch_bank) {
-               info->amap.chip_size = info->mtd->size;
+               info->amap.window_size = info->mtd->size;
                return;
        }
 
@@ -322,7 +324,7 @@ static void adm5120_flash_initbanks(struct adm5120_flash_info *info)
                (unsigned long)map->size >> 10,
                (unsigned long)info->mtd->size >> 10);
 
-       info->mtd->size = info->amap.chip_size;
+       info->mtd->size = info->amap.window_size;
 }
 
 #ifdef CONFIG_MTD_PARTITIONS
@@ -469,13 +471,13 @@ static int adm5120_flash_probe(struct platform_device *dev)
 
        adm5120_flash_initbanks(info);
 
-       if (info->mtd->size < info->amap.chip_size) {
+       if (info->mtd->size < info->amap.window_size) {
                /* readjust resources */
                iounmap(map->virt);
                release_resource(info->res);
                kfree(info->res);
 
-               info->amap.chip_size = info->mtd->size;
+               info->amap.window_size = info->mtd->size;
                map->size = info->mtd->size;
                MAP_INFO(map, "reducing map size to %ldKiB\n",
                        (unsigned long)map->size >> 10);
@@ -485,7 +487,7 @@ static int adm5120_flash_probe(struct platform_device *dev)
        }
 
        MAP_INFO(map, "found at 0x%lX, size:%ldKiB, width:%d bits\n",
-               (unsigned long)map->phys, (unsigned long)map->size >> 10,
+               (unsigned long)map->phys, (unsigned long)info->mtd->size >> 10,
                map->bankwidth*8);
 
        info->mtd->owner = THIS_MODULE;
@@ -568,5 +570,5 @@ module_init(adm5120_flash_init);
 module_exit(adm5120_flash_exit);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Gabor Juhos <juhosg@freemail.hu>");
+MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
 MODULE_DESCRIPTION(DRV_DESC);
This page took 0.027709 seconds and 4 git commands to generate.