* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org>
*/
+#include <linux/config.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/blktrans.h>
-#include <linux/mutex.h>
-
static struct mtdblk_dev {
struct mtd_info *mtd;
int count;
- struct mutex cache_mutex;
+ struct semaphore cache_sem;
unsigned char *cache_data;
unsigned long cache_offset;
unsigned int cache_size;
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&wait_q, &wait);
- ret = mtd->erase(mtd, &erase);
+ ret = MTD_ERASE(mtd, &erase);
if (ret) {
set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait);
* Next, writhe data to flash.
*/
- ret = mtd->write(mtd, pos, len, &retlen, buf);
+ ret = MTD_WRITE (mtd, pos, len, &retlen, buf);
if (ret)
return ret;
if (retlen != len)
mtd->name, pos, len);
if (!sect_size)
- return mtd->write(mtd, pos, len, &retlen, buf);
+ return MTD_WRITE (mtd, pos, len, &retlen, buf);
while (len > 0) {
unsigned long sect_start = (pos/sect_size)*sect_size;
mtdblk->cache_offset != sect_start) {
/* fill the cache with the current sector */
mtdblk->cache_state = STATE_EMPTY;
- ret = mtd->read(mtd, sect_start, sect_size,
- &retlen, mtdblk->cache_data);
+ ret = MTD_READ(mtd, sect_start, sect_size, &retlen, mtdblk->cache_data);
if (ret)
return ret;
if (retlen != sect_size)
mtd->name, pos, len);
if (!sect_size)
- return mtd->read(mtd, pos, len, &retlen, buf);
+ return MTD_READ (mtd, pos, len, &retlen, buf);
while (len > 0) {
unsigned long sect_start = (pos/sect_size)*sect_size;
mtdblk->cache_offset == sect_start) {
memcpy (buf, mtdblk->cache_data + offset, size);
} else {
- ret = mtd->read(mtd, pos, size, &retlen, buf);
+ ret = MTD_READ (mtd, pos, size, &retlen, buf);
if (ret)
return ret;
if (retlen != size)
mtdblk->count = 1;
mtdblk->mtd = mtd;
- mutex_init(&mtdblk->cache_mutex);
+ init_MUTEX (&mtdblk->cache_sem);
mtdblk->cache_state = STATE_EMPTY;
- if ( !(mtdblk->mtd->flags & MTD_NO_ERASE) && mtdblk->mtd->erasesize) {
+ if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
+ mtdblk->mtd->erasesize) {
mtdblk->cache_size = mtdblk->mtd->erasesize;
mtdblk->cache_data = NULL;
}
DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n");
- mutex_lock(&mtdblk->cache_mutex);
+ down(&mtdblk->cache_sem);
write_cached_data(mtdblk);
- mutex_unlock(&mtdblk->cache_mutex);
+ up(&mtdblk->cache_sem);
if (!--mtdblk->count) {
/* It was the last usage. Free the device */
{
struct mtdblk_dev *mtdblk = mtdblks[dev->devnum];
- mutex_lock(&mtdblk->cache_mutex);
+ down(&mtdblk->cache_sem);
write_cached_data(mtdblk);
- mutex_unlock(&mtdblk->cache_mutex);
+ up(&mtdblk->cache_sem);
if (mtdblk->mtd->sync)
mtdblk->mtd->sync(mtdblk->mtd);