]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/mtd/chips/cfi_cmdset_0001.c
mtd: Remove obsolete <mtd/compatmac.h> include
[net-next-2.6.git] / drivers / mtd / chips / cfi_cmdset_0001.c
index 5fbf29e1e64fcfc9aa7a55ece397670bb79d683a..9e2b7e9e0ad91b4871423cf2f449c1b63329cb10 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/mtd/xip.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/mtd.h>
-#include <linux/mtd/compatmac.h>
 #include <linux/mtd/cfi.h>
 
 /* #define CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE */
@@ -63,6 +62,8 @@ static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
 static void cfi_intelext_sync (struct mtd_info *);
 static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
 static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
+static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
+                                 uint64_t len);
 #ifdef CONFIG_MTD_OTP
 static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
@@ -448,6 +449,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
        mtd->sync    = cfi_intelext_sync;
        mtd->lock    = cfi_intelext_lock;
        mtd->unlock  = cfi_intelext_unlock;
+       mtd->is_locked = cfi_intelext_is_locked;
        mtd->suspend = cfi_intelext_suspend;
        mtd->resume  = cfi_intelext_resume;
        mtd->flags   = MTD_CAP_NORFLASH;
@@ -615,10 +617,8 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
        return mtd;
 
  setup_err:
-       if(mtd) {
-               kfree(mtd->eraseregions);
-               kfree(mtd);
-       }
+       kfree(mtd->eraseregions);
+       kfree(mtd);
        kfree(cfi->cmdset_priv);
        return NULL;
 }
@@ -719,7 +719,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
                chip = &newcfi->chips[0];
                for (i = 0; i < cfi->numchips; i++) {
                        shared[i].writing = shared[i].erasing = NULL;
-                       spin_lock_init(&shared[i].lock);
+                       mutex_init(&shared[i].lock);
                        for (j = 0; j < numparts; j++) {
                                *chip = cfi->chips[i];
                                chip->start += j << partshift;
@@ -727,8 +727,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
                                /* those should be reset too since
                                   they create memory references. */
                                init_waitqueue_head(&chip->wq);
-                               spin_lock_init(&chip->_spinlock);
-                               chip->mutex = &chip->_spinlock;
+                               mutex_init(&chip->mutex);
                                chip++;
                        }
                }
@@ -774,9 +773,9 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
                        if (chip->priv && map_word_andequal(map, status, status_PWS, status_PWS))
                                break;
 
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        cfi_udelay(1);
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
                        /* Someone else might have been playing with it. */
                        return -EAGAIN;
                }
@@ -823,9 +822,9 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
                                return -EIO;
                        }
 
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        cfi_udelay(1);
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
                        /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING.
                           So we can just loop here. */
                }
@@ -852,10 +851,10 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
        sleep:
                set_current_state(TASK_UNINTERRUPTIBLE);
                add_wait_queue(&chip->wq, &wait);
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                schedule();
                remove_wait_queue(&chip->wq, &wait);
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
                return -EAGAIN;
        }
 }
@@ -889,7 +888,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
                 */
                struct flchip_shared *shared = chip->priv;
                struct flchip *contender;
-               spin_lock(&shared->lock);
+               mutex_lock(&shared->lock);
                contender = shared->writing;
                if (contender && contender != chip) {
                        /*
@@ -901,45 +900,45 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
                         * it'll happily send us to sleep.  In any case, when
                         * get_chip returns success we're clear to go ahead.
                         */
-                       ret = spin_trylock(contender->mutex);
-                       spin_unlock(&shared->lock);
+                       ret = mutex_trylock(&contender->mutex);
+                       mutex_unlock(&shared->lock);
                        if (!ret)
                                goto retry;
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        ret = chip_ready(map, contender, contender->start, mode);
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
 
                        if (ret == -EAGAIN) {
-                               spin_unlock(contender->mutex);
+                               mutex_unlock(&contender->mutex);
                                goto retry;
                        }
                        if (ret) {
-                               spin_unlock(contender->mutex);
+                               mutex_unlock(&contender->mutex);
                                return ret;
                        }
-                       spin_lock(&shared->lock);
+                       mutex_lock(&shared->lock);
 
                        /* We should not own chip if it is already
                         * in FL_SYNCING state. Put contender and retry. */
                        if (chip->state == FL_SYNCING) {
                                put_chip(map, contender, contender->start);
-                               spin_unlock(contender->mutex);
+                               mutex_unlock(&contender->mutex);
                                goto retry;
                        }
-                       spin_unlock(contender->mutex);
+                       mutex_unlock(&contender->mutex);
                }
 
                /* Check if we already have suspended erase
                 * on this chip. Sleep. */
                if (mode == FL_ERASING && shared->erasing
                    && shared->erasing->oldstate == FL_ERASING) {
-                       spin_unlock(&shared->lock);
+                       mutex_unlock(&shared->lock);
                        set_current_state(TASK_UNINTERRUPTIBLE);
                        add_wait_queue(&chip->wq, &wait);
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        schedule();
                        remove_wait_queue(&chip->wq, &wait);
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
                        goto retry;
                }
 
@@ -947,7 +946,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
                shared->writing = chip;
                if (mode == FL_ERASING)
                        shared->erasing = chip;
-               spin_unlock(&shared->lock);
+               mutex_unlock(&shared->lock);
        }
        ret = chip_ready(map, chip, adr, mode);
        if (ret == -EAGAIN)
@@ -962,19 +961,19 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
 
        if (chip->priv) {
                struct flchip_shared *shared = chip->priv;
-               spin_lock(&shared->lock);
+               mutex_lock(&shared->lock);
                if (shared->writing == chip && chip->oldstate == FL_READY) {
                        /* We own the ability to write, but we're done */
                        shared->writing = shared->erasing;
                        if (shared->writing && shared->writing != chip) {
                                /* give back ownership to who we loaned it from */
                                struct flchip *loaner = shared->writing;
-                               spin_lock(loaner->mutex);
-                               spin_unlock(&shared->lock);
-                               spin_unlock(chip->mutex);
+                               mutex_lock(&loaner->mutex);
+                               mutex_unlock(&shared->lock);
+                               mutex_unlock(&chip->mutex);
                                put_chip(map, loaner, loaner->start);
-                               spin_lock(chip->mutex);
-                               spin_unlock(loaner->mutex);
+                               mutex_lock(&chip->mutex);
+                               mutex_unlock(&loaner->mutex);
                                wake_up(&chip->wq);
                                return;
                        }
@@ -988,11 +987,11 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
                         * Don't let the switch below mess things up since
                         * we don't have ownership to resume anything.
                         */
-                       spin_unlock(&shared->lock);
+                       mutex_unlock(&shared->lock);
                        wake_up(&chip->wq);
                        return;
                }
-               spin_unlock(&shared->lock);
+               mutex_unlock(&shared->lock);
        }
 
        switch(chip->oldstate) {
@@ -1144,7 +1143,7 @@ static int __xipram xip_wait_for_operation(
                        (void) map_read(map, adr);
                        xip_iprefetch();
                        local_irq_enable();
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        xip_iprefetch();
                        cond_resched();
 
@@ -1154,15 +1153,15 @@ static int __xipram xip_wait_for_operation(
                         * a suspended erase state.  If so let's wait
                         * until it's done.
                         */
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
                        while (chip->state != newstate) {
                                DECLARE_WAITQUEUE(wait, current);
                                set_current_state(TASK_UNINTERRUPTIBLE);
                                add_wait_queue(&chip->wq, &wait);
-                               spin_unlock(chip->mutex);
+                               mutex_unlock(&chip->mutex);
                                schedule();
                                remove_wait_queue(&chip->wq, &wait);
-                               spin_lock(chip->mutex);
+                               mutex_lock(&chip->mutex);
                        }
                        /* Disallow XIP again */
                        local_irq_disable();
@@ -1218,10 +1217,10 @@ static int inval_cache_and_wait_for_operation(
        int chip_state = chip->state;
        unsigned int timeo, sleep_time, reset_timeo;
 
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        if (inval_len)
                INVALIDATE_CACHED_RANGE(map, inval_adr, inval_len);
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
 
        timeo = chip_op_time_max;
        if (!timeo)
@@ -1241,7 +1240,7 @@ static int inval_cache_and_wait_for_operation(
                }
 
                /* OK Still waiting. Drop the lock, wait a while and retry. */
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                if (sleep_time >= 1000000/HZ) {
                        /*
                         * Half of the normal delay still remaining
@@ -1256,17 +1255,17 @@ static int inval_cache_and_wait_for_operation(
                        cond_resched();
                        timeo--;
                }
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
 
                while (chip->state != chip_state) {
                        /* Someone's suspended the operation: sleep */
                        DECLARE_WAITQUEUE(wait, current);
                        set_current_state(TASK_UNINTERRUPTIBLE);
                        add_wait_queue(&chip->wq, &wait);
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        schedule();
                        remove_wait_queue(&chip->wq, &wait);
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
                }
                if (chip->erase_suspended && chip_state == FL_ERASING)  {
                        /* Erase suspend occured while sleep: reset timeout */
@@ -1302,7 +1301,7 @@ static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t a
        /* Ensure cmd read/writes are aligned. */
        cmd_addr = adr & ~(map_bankwidth(map)-1);
 
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
 
        ret = get_chip(map, chip, cmd_addr, FL_POINT);
 
@@ -1313,7 +1312,7 @@ static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t a
                chip->state = FL_POINT;
                chip->ref_point_counter++;
        }
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
 
        return ret;
 }
@@ -1398,7 +1397,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
                else
                        thislen = len;
 
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
                if (chip->state == FL_POINT) {
                        chip->ref_point_counter--;
                        if(chip->ref_point_counter == 0)
@@ -1407,7 +1406,7 @@ static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
                        printk(KERN_ERR "%s: Warning: unpoint called on non pointed region\n", map->name); /* Should this give an error? */
 
                put_chip(map, chip, chip->start);
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
 
                len -= thislen;
                ofs = 0;
@@ -1426,10 +1425,10 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
        /* Ensure cmd read/writes are aligned. */
        cmd_addr = adr & ~(map_bankwidth(map)-1);
 
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, cmd_addr, FL_READY);
        if (ret) {
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                return ret;
        }
 
@@ -1443,7 +1442,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
 
        put_chip(map, chip, cmd_addr);
 
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        return 0;
 }
 
@@ -1506,10 +1505,10 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
                return -EINVAL;
        }
 
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, adr, mode);
        if (ret) {
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                return ret;
        }
 
@@ -1555,7 +1554,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 
        xip_enable(map, chip, adr);
  out:  put_chip(map, chip, adr);
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        return ret;
 }
 
@@ -1664,10 +1663,10 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
        /* Let's determine this according to the interleave only once */
        write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0xe8) : CMD(0xe9);
 
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, cmd_adr, FL_WRITING);
        if (ret) {
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                return ret;
        }
 
@@ -1798,7 +1797,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
 
        xip_enable(map, chip, cmd_adr);
  out:  put_chip(map, chip, cmd_adr);
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        return ret;
 }
 
@@ -1877,10 +1876,10 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
        adr += chip->start;
 
  retry:
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, adr, FL_ERASING);
        if (ret) {
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                return ret;
        }
 
@@ -1936,7 +1935,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
                } else if (chipstatus & 0x20 && retries--) {
                        printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);
                        put_chip(map, chip, adr);
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                        goto retry;
                } else {
                        printk(KERN_ERR "%s: block erase failed at 0x%08lx (status 0x%lx)\n", map->name, adr, chipstatus);
@@ -1948,7 +1947,7 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
 
        xip_enable(map, chip, adr);
  out:  put_chip(map, chip, adr);
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        return ret;
 }
 
@@ -1981,7 +1980,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
        for (i=0; !ret && i<cfi->numchips; i++) {
                chip = &cfi->chips[i];
 
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
                ret = get_chip(map, chip, chip->start, FL_SYNCING);
 
                if (!ret) {
@@ -1992,7 +1991,7 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
                         * with the chip now anyway.
                         */
                }
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
        }
 
        /* Unlock the chips again */
@@ -2000,14 +1999,14 @@ static void cfi_intelext_sync (struct mtd_info *mtd)
        for (i--; i >=0; i--) {
                chip = &cfi->chips[i];
 
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
 
                if (chip->state == FL_SYNCING) {
                        chip->state = chip->oldstate;
                        chip->oldstate = FL_READY;
                        wake_up(&chip->wq);
                }
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
        }
 }
 
@@ -2053,10 +2052,10 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
 
        adr += chip->start;
 
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, adr, FL_LOCKING);
        if (ret) {
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                return ret;
        }
 
@@ -2090,7 +2089,7 @@ static int __xipram do_xxlock_oneblock(struct map_info *map, struct flchip *chip
 
        xip_enable(map, chip, adr);
 out:   put_chip(map, chip, adr);
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        return ret;
 }
 
@@ -2142,6 +2141,13 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
        return ret;
 }
 
+static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
+                                 uint64_t len)
+{
+       return cfi_varsize_frob(mtd, do_getlockstatus_oneblock,
+                               ofs, len, NULL) ? 1 : 0;
+}
+
 #ifdef CONFIG_MTD_OTP
 
 typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
@@ -2155,10 +2161,10 @@ do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,
        struct cfi_private *cfi = map->fldrv_priv;
        int ret;
 
-       spin_lock(chip->mutex);
+       mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);
        if (ret) {
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
                return ret;
        }
 
@@ -2177,7 +2183,7 @@ do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,
        INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);
 
        put_chip(map, chip, chip->start);
-       spin_unlock(chip->mutex);
+       mutex_unlock(&chip->mutex);
        return 0;
 }
 
@@ -2452,7 +2458,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
        for (i=0; !ret && i<cfi->numchips; i++) {
                chip = &cfi->chips[i];
 
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
 
                switch (chip->state) {
                case FL_READY:
@@ -2484,7 +2490,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
                case FL_PM_SUSPENDED:
                        break;
                }
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
        }
 
        /* Unlock the chips again */
@@ -2493,7 +2499,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
                for (i--; i >=0; i--) {
                        chip = &cfi->chips[i];
 
-                       spin_lock(chip->mutex);
+                       mutex_lock(&chip->mutex);
 
                        if (chip->state == FL_PM_SUSPENDED) {
                                /* No need to force it into a known state here,
@@ -2503,7 +2509,7 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
                                chip->oldstate = FL_READY;
                                wake_up(&chip->wq);
                        }
-                       spin_unlock(chip->mutex);
+                       mutex_unlock(&chip->mutex);
                }
        }
 
@@ -2544,7 +2550,7 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
 
                chip = &cfi->chips[i];
 
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
 
                /* Go to known state. Chip may have been power cycled */
                if (chip->state == FL_PM_SUSPENDED) {
@@ -2553,7 +2559,7 @@ static void cfi_intelext_resume(struct mtd_info *mtd)
                        wake_up(&chip->wq);
                }
 
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
        }
 
        if ((mtd->flags & MTD_POWERUP_LOCK)
@@ -2573,14 +2579,14 @@ static int cfi_intelext_reset(struct mtd_info *mtd)
                /* force the completion of any ongoing operation
                   and switch to array mode so any bootloader in
                   flash is accessible for soft reboot. */
-               spin_lock(chip->mutex);
+               mutex_lock(&chip->mutex);
                ret = get_chip(map, chip, chip->start, FL_SHUTDOWN);
                if (!ret) {
                        map_write(map, CMD(0xff), chip->start);
                        chip->state = FL_SHUTDOWN;
                        put_chip(map, chip, chip->start);
                }
-               spin_unlock(chip->mutex);
+               mutex_unlock(&chip->mutex);
        }
 
        return 0;