summaryrefslogtreecommitdiff
path: root/drivers/mtd/cfi_flash.c
diff options
context:
space:
mode:
authorJens Gehrlein <sew_s@tqs.de>2008-12-16 17:25:55 +0100
committerStefan Roese <sr@denx.de>2009-01-26 10:50:13 +0100
commit0f8e851e897b535959a0781171910cd97f33c30c (patch)
treec592c555c5ea4f5b3a8b61de047c67b614a1757f /drivers/mtd/cfi_flash.c
parenta7292871a79cc48d98e3a708dd3c3b81580db6ef (diff)
CFI: increase performance of function find_sector()
Tested on TQM5200S-BD with Samsung K8P2815UQB Signed-off-by: Jens Gehrlein <sew_s@tqs.de> Signed-off-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'drivers/mtd/cfi_flash.c')
-rw-r--r--drivers/mtd/cfi_flash.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 1bd0e2b99a..bc5e1514e4 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -774,17 +774,26 @@ static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
}
}
-/* loop through the sectors from the highest address when the passed
- * address is greater or equal to the sector address we have a match
+/*
+ * Loop through the sector table starting from the previously found sector.
+ * Searches forwards or backwards, dependent on the passed address.
*/
static flash_sect_t find_sector (flash_info_t * info, ulong addr)
{
- flash_sect_t sector;
+ static flash_sect_t saved_sector = 0; /* previously found sector */
+ flash_sect_t sector = saved_sector;
- for (sector = info->sector_count - 1; sector >= 0; sector--) {
- if (addr >= info->start[sector])
- break;
- }
+ while ((info->start[sector] < addr)
+ && (sector < info->sector_count - 1))
+ sector++;
+ while ((info->start[sector] > addr) && (sector > 0))
+ /*
+ * also decrements the sector in case of an overshot
+ * in the first loop
+ */
+ sector--;
+
+ saved_sector = sector;
return sector;
}