mtd: cfi: add writebufsize initialization
[deliverable/linux.git] / drivers / mtd / chips / cfi_cmdset_0001.c
index 62f3ea9de848cabfb481014ca0b6176893da5a0f..a8c3e1c9b02a78a64a79f5701abac9d1ba29a3e4 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 *);
@@ -161,7 +162,7 @@ static void cfi_tell_features(struct cfi_pri_intelext *extp)
 #endif
 
 /* Atmel chips don't use the same PRI format as Intel chips */
-static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
+static void fixup_convert_atmel_pri(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -201,7 +202,7 @@ static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param)
        cfi->cfiq->BufWriteTimeoutMax = 0;
 }
 
-static void fixup_at49bv640dx_lock(struct mtd_info *mtd, void *param)
+static void fixup_at49bv640dx_lock(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -213,7 +214,7 @@ static void fixup_at49bv640dx_lock(struct mtd_info *mtd, void *param)
 
 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
 /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */
-static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
+static void fixup_intel_strataflash(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -226,7 +227,7 @@ static void fixup_intel_strataflash(struct mtd_info *mtd, void* param)
 #endif
 
 #ifdef CMDSET0001_DISABLE_WRITE_SUSPEND
-static void fixup_no_write_suspend(struct mtd_info *mtd, void* param)
+static void fixup_no_write_suspend(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -239,7 +240,7 @@ static void fixup_no_write_suspend(struct mtd_info *mtd, void* param)
 }
 #endif
 
-static void fixup_st_m28w320ct(struct mtd_info *mtd, void* param)
+static void fixup_st_m28w320ct(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -248,7 +249,7 @@ static void fixup_st_m28w320ct(struct mtd_info *mtd, void* param)
        cfi->cfiq->BufWriteTimeoutMax = 0;      /* Not supported */
 }
 
-static void fixup_st_m28w320cb(struct mtd_info *mtd, void* param)
+static void fixup_st_m28w320cb(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -258,7 +259,7 @@ static void fixup_st_m28w320cb(struct mtd_info *mtd, void* param)
                (cfi->cfiq->EraseRegionInfo[1] & 0xffff0000) | 0x3e;
 };
 
-static void fixup_use_point(struct mtd_info *mtd, void *param)
+static void fixup_use_point(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        if (!mtd->point && map_is_linear(map)) {
@@ -267,7 +268,7 @@ static void fixup_use_point(struct mtd_info *mtd, void *param)
        }
 }
 
-static void fixup_use_write_buffers(struct mtd_info *mtd, void *param)
+static void fixup_use_write_buffers(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -281,7 +282,7 @@ static void fixup_use_write_buffers(struct mtd_info *mtd, void *param)
 /*
  * Some chips power-up with all sectors locked by default.
  */
-static void fixup_unlock_powerup_lock(struct mtd_info *mtd, void *param)
+static void fixup_unlock_powerup_lock(struct mtd_info *mtd)
 {
        struct map_info *map = mtd->priv;
        struct cfi_private *cfi = map->fldrv_priv;
@@ -294,31 +295,31 @@ static void fixup_unlock_powerup_lock(struct mtd_info *mtd, void *param)
 }
 
 static struct cfi_fixup cfi_fixup_table[] = {
-       { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
-       { CFI_MFR_ATMEL, AT49BV640D, fixup_at49bv640dx_lock, NULL },
-       { CFI_MFR_ATMEL, AT49BV640DT, fixup_at49bv640dx_lock, NULL },
+       { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri },
+       { CFI_MFR_ATMEL, AT49BV640D, fixup_at49bv640dx_lock },
+       { CFI_MFR_ATMEL, AT49BV640DT, fixup_at49bv640dx_lock },
 #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE
-       { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL },
+       { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash },
 #endif
 #ifdef CMDSET0001_DISABLE_WRITE_SUSPEND
-       { CFI_MFR_ANY, CFI_ID_ANY, fixup_no_write_suspend, NULL },
+       { CFI_MFR_ANY, CFI_ID_ANY, fixup_no_write_suspend },
 #endif
 #if !FORCE_WORD_WRITE
-       { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL },
+       { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers },
 #endif
-       { CFI_MFR_ST, 0x00ba, /* M28W320CT */ fixup_st_m28w320ct, NULL },
-       { CFI_MFR_ST, 0x00bb, /* M28W320CB */ fixup_st_m28w320cb, NULL },
-       { CFI_MFR_INTEL, CFI_ID_ANY, fixup_unlock_powerup_lock, NULL, },
-       { 0, 0, NULL, NULL }
+       { CFI_MFR_ST, 0x00ba, /* M28W320CT */ fixup_st_m28w320ct },
+       { CFI_MFR_ST, 0x00bb, /* M28W320CB */ fixup_st_m28w320cb },
+       { CFI_MFR_INTEL, CFI_ID_ANY, fixup_unlock_powerup_lock },
+       { 0, 0, NULL }
 };
 
 static struct cfi_fixup jedec_fixup_table[] = {
-       { CFI_MFR_INTEL, I82802AB,   fixup_use_fwh_lock, NULL, },
-       { CFI_MFR_INTEL, I82802AC,   fixup_use_fwh_lock, NULL, },
-       { CFI_MFR_ST,    M50LPW080,  fixup_use_fwh_lock, NULL, },
-       { CFI_MFR_ST,    M50FLW080A, fixup_use_fwh_lock, NULL, },
-       { CFI_MFR_ST,    M50FLW080B, fixup_use_fwh_lock, NULL, },
-       { 0, 0, NULL, NULL }
+       { CFI_MFR_INTEL, I82802AB,   fixup_use_fwh_lock },
+       { CFI_MFR_INTEL, I82802AC,   fixup_use_fwh_lock },
+       { CFI_MFR_ST,    M50LPW080,  fixup_use_fwh_lock },
+       { CFI_MFR_ST,    M50FLW080A, fixup_use_fwh_lock },
+       { CFI_MFR_ST,    M50FLW080B, fixup_use_fwh_lock },
+       { 0, 0, NULL }
 };
 static struct cfi_fixup fixup_table[] = {
        /* The CFI vendor ids and the JEDEC vendor IDs appear
@@ -326,8 +327,8 @@ static struct cfi_fixup fixup_table[] = {
         * well.  This table is to pick all cases where
         * we know that is the case.
         */
-       { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_point, NULL },
-       { 0, 0, NULL, NULL }
+       { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_point },
+       { 0, 0, NULL }
 };
 
 static void cfi_fixup_major_minor(struct cfi_private *cfi,
@@ -448,11 +449,13 @@ 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;
        mtd->name    = map->name;
        mtd->writesize = 1;
+       mtd->writebufsize = 1 << cfi->cfiq->MaxBufWriteSize;
 
        mtd->reboot_notifier.notifier_call = cfi_intelext_reboot;
 
@@ -717,7 +720,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;
@@ -886,7 +889,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) {
                        /*
@@ -899,7 +902,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
                         * get_chip returns success we're clear to go ahead.
                         */
                        ret = mutex_trylock(&contender->mutex);
-                       spin_unlock(&shared->lock);
+                       mutex_unlock(&shared->lock);
                        if (!ret)
                                goto retry;
                        mutex_unlock(&chip->mutex);
@@ -914,7 +917,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
                                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. */
@@ -930,7 +933,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
                 * 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);
                        mutex_unlock(&chip->mutex);
@@ -944,7 +947,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)
@@ -959,7 +962,7 @@ 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;
@@ -967,7 +970,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
                                /* give back ownership to who we loaned it from */
                                struct flchip *loaner = shared->writing;
                                mutex_lock(&loaner->mutex);
-                               spin_unlock(&shared->lock);
+                               mutex_unlock(&shared->lock);
                                mutex_unlock(&chip->mutex);
                                put_chip(map, loaner, loaner->start);
                                mutex_lock(&chip->mutex);
@@ -985,11 +988,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) {
@@ -1494,7 +1497,7 @@ static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip,
 
        switch (mode) {
        case FL_WRITING:
-               write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0x40) : CMD(0x41);
+               write_cmd = (cfi->cfiq->P_ID != P_ID_INTEL_PERFORMANCE) ? CMD(0x40) : CMD(0x41);
                break;
        case FL_OTP_WRITE:
                write_cmd = CMD(0xc0);
@@ -1659,7 +1662,7 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
        cmd_adr = adr & ~(wbufsize-1);
 
        /* Let's determine this according to the interleave only once */
-       write_cmd = (cfi->cfiq->P_ID != 0x0200) ? CMD(0xe8) : CMD(0xe9);
+       write_cmd = (cfi->cfiq->P_ID != P_ID_INTEL_PERFORMANCE) ? CMD(0xe8) : CMD(0xe9);
 
        mutex_lock(&chip->mutex);
        ret = get_chip(map, chip, cmd_adr, FL_WRITING);
@@ -2139,6 +2142,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,
This page took 0.031658 seconds and 5 git commands to generate.